Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

[Bug] [SYM-PR2] Crash happens when trying to raise a python module to jac #506

Open
mgtm98 opened this issue Jul 12, 2024 · 0 comments
Open
Assignees

Comments

@mgtm98
Copy link
Collaborator

mgtm98 commented Jul 12, 2024

Describe the bug

When trying to raise site-packages/openai/__init__.py the following crash happens

Error while running ast tool ir, check args: ModulePath should have a name spec. Impossible.
Traceback (most recent call last):
  File "/home/mgtm98/miniconda3/bin/jac", line 8, in <module>
    sys.exit(start_cli())
             ^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/cli/cli.py", line 438, in start_cli
    ret = command.call(**args_dict)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/cli/cmdreg.py", line 25, in call
    return self.func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/cli/cli.py", line 273, in tool
    raise e
  File "/home/mgtm98/jaclang/jaclang/cli/cli.py", line 268, in tool
    print(getattr(AstTool(), tool)(args))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/utils/lang_tools.py", line 237, in ir
    ir = jac_file_to_pass(
         ^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/compile.py", line 33, in jac_file_to_pass
    return jac_str_to_pass(
           ^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/compile.py", line 55, in jac_str_to_pass
    ast_ret = i(input_ir=ast_ret.ir, prior=ast_ret)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/ir_pass.py", line 23, in __init__
    Transform.__init__(self, input_ir, prior)
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/transform.py", line 47, in __init__
    self.ir = self.transform(ir=input_ir)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/ir_pass.py", line 115, in transform
    self.after_pass()
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/main/import_pass.py", line 304, in after_pass
    PyastBuildPass(
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/main/pyast_load_pass.py", line 25, in __init__
    Pass.__init__(self, input_ir=input_ir, prior=None)
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/ir_pass.py", line 23, in __init__
    Transform.__init__(self, input_ir, prior)
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/transform.py", line 47, in __init__
    self.ir = self.transform(ir=input_ir)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/main/pyast_load_pass.py", line 56, in transform
    self.ir: ast.Module = self.proc_module(ir.ast)
                          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/main/pyast_load_pass.py", line 106, in proc_module
    elements: list[ast.AstNode] = [self.convert(i) for i in node.body]
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/main/pyast_load_pass.py", line 106, in <listcomp>
    elements: list[ast.AstNode] = [self.convert(i) for i in node.body]
                                   ^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/main/pyast_load_pass.py", line 44, in convert
    ret = getattr(self, f"proc_{pascal_to_snake(type(node).__name__)}")(node)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/passes/main/pyast_load_pass.py", line 1510, in proc_import_from
    path = ast.ModulePath(
           ^^^^^^^^^^^^^^^
  File "/home/mgtm98/jaclang/jaclang/compiler/absyntree.py", line 921, in __init__
    raise ValueError("ModulePath should have a name spec. Impossible.")
ValueError: ModulePath should have a name spec. Impossible.

Is this a regression?

The code used to work before as the code for raising a Python module was inside a try-except block but then I decided to remove it to expose all the issues with py raise. A possible fix for this is adding it inside a try-except block again but I don't prefer that.

            if expected_file not in py_mod_map:
                with open(expected_file, "r", encoding="utf-8") as f:
                    py_mod_map[expected_file] = (
                        PyastBuildPass(
                            input_ir=ast.PythonModuleAst(
                                py_ast.parse(f.read()), mod_path=expected_file
                            ),
                        ).ir,
                        [i],
                    )
                    SubNodeTabPass(prior=self, input_ir=py_mod_map[expected_file][0])
                    py_mod_map[expected_file][0].py_lib = True
            else:
                py_mod_map[expected_file][1].append(i)

Expected behaviour

All the python modules should be raised to jac without any issues

To Reproduce

jac tool ir ast jaclang/examples/rpg_game/jac_impl/jac_impl_5/main.jac
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants