jaclang 0.8.7__py3-none-any.whl → 0.8.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of jaclang might be problematic. Click here for more details.

Files changed (99) hide show
  1. jaclang/cli/cli.py +77 -29
  2. jaclang/cli/cmdreg.py +44 -0
  3. jaclang/compiler/constant.py +6 -2
  4. jaclang/compiler/jac.lark +37 -47
  5. jaclang/compiler/larkparse/jac_parser.py +2 -2
  6. jaclang/compiler/parser.py +356 -61
  7. jaclang/compiler/passes/main/__init__.py +2 -4
  8. jaclang/compiler/passes/main/def_use_pass.py +1 -4
  9. jaclang/compiler/passes/main/predynamo_pass.py +221 -0
  10. jaclang/compiler/passes/main/pyast_gen_pass.py +221 -135
  11. jaclang/compiler/passes/main/pyast_load_pass.py +54 -20
  12. jaclang/compiler/passes/main/sym_tab_build_pass.py +1 -1
  13. jaclang/compiler/passes/main/tests/fixtures/checker/import_sym.jac +2 -0
  14. jaclang/compiler/passes/main/tests/fixtures/checker/import_sym_test.jac +6 -0
  15. jaclang/compiler/passes/main/tests/fixtures/checker/imported_sym.jac +5 -0
  16. jaclang/compiler/passes/main/tests/fixtures/checker_arg_param_match.jac +37 -0
  17. jaclang/compiler/passes/main/tests/fixtures/checker_arity.jac +18 -0
  18. jaclang/compiler/passes/main/tests/fixtures/checker_cat_is_animal.jac +18 -0
  19. jaclang/compiler/passes/main/tests/fixtures/checker_float.jac +7 -0
  20. jaclang/compiler/passes/main/tests/fixtures/checker_param_types.jac +11 -0
  21. jaclang/compiler/passes/main/tests/fixtures/checker_self_type.jac +9 -0
  22. jaclang/compiler/passes/main/tests/fixtures/checker_sym_inherit.jac +42 -0
  23. jaclang/compiler/passes/main/tests/fixtures/predynamo_fix3.jac +43 -0
  24. jaclang/compiler/passes/main/tests/fixtures/predynamo_where_assign.jac +13 -0
  25. jaclang/compiler/passes/main/tests/fixtures/predynamo_where_return.jac +11 -0
  26. jaclang/compiler/passes/main/tests/test_checker_pass.py +190 -0
  27. jaclang/compiler/passes/main/tests/test_predynamo_pass.py +56 -0
  28. jaclang/compiler/passes/main/type_checker_pass.py +29 -73
  29. jaclang/compiler/passes/tool/doc_ir_gen_pass.py +302 -58
  30. jaclang/compiler/passes/tool/jac_formatter_pass.py +119 -69
  31. jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +3 -3
  32. jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +4 -5
  33. jaclang/compiler/passes/tool/tests/fixtures/import_fmt.jac +7 -1
  34. jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +276 -10
  35. jaclang/compiler/passes/transform.py +12 -8
  36. jaclang/compiler/program.py +19 -7
  37. jaclang/compiler/tests/fixtures/jac_import_py_files.py +4 -0
  38. jaclang/compiler/tests/fixtures/jac_module.jac +3 -0
  39. jaclang/compiler/tests/fixtures/multiple_syntax_errors.jac +10 -0
  40. jaclang/compiler/tests/fixtures/python_module.py +1 -0
  41. jaclang/compiler/tests/test_importer.py +39 -0
  42. jaclang/compiler/tests/test_parser.py +49 -0
  43. jaclang/compiler/type_system/type_evaluator.jac +959 -0
  44. jaclang/compiler/type_system/type_utils.py +246 -0
  45. jaclang/compiler/type_system/types.py +58 -2
  46. jaclang/compiler/unitree.py +102 -107
  47. jaclang/langserve/engine.jac +138 -159
  48. jaclang/langserve/server.jac +25 -1
  49. jaclang/langserve/tests/fixtures/circle.jac +3 -3
  50. jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
  51. jaclang/langserve/tests/fixtures/circle_pure.test.jac +3 -3
  52. jaclang/langserve/tests/fixtures/completion_test_err.jac +10 -0
  53. jaclang/langserve/tests/server_test/circle_template.jac +80 -0
  54. jaclang/langserve/tests/server_test/glob_template.jac +4 -0
  55. jaclang/langserve/tests/server_test/test_lang_serve.py +154 -309
  56. jaclang/langserve/tests/server_test/utils.py +153 -116
  57. jaclang/langserve/tests/test_server.py +21 -84
  58. jaclang/langserve/utils.jac +12 -15
  59. jaclang/lib.py +17 -0
  60. jaclang/runtimelib/archetype.py +25 -25
  61. jaclang/runtimelib/constructs.py +2 -2
  62. jaclang/runtimelib/machine.py +63 -46
  63. jaclang/runtimelib/meta_importer.py +27 -1
  64. jaclang/runtimelib/tests/fixtures/custom_access_validation.jac +1 -1
  65. jaclang/runtimelib/tests/fixtures/savable_object.jac +2 -2
  66. jaclang/settings.py +19 -16
  67. jaclang/tests/fixtures/abc_check.jac +3 -3
  68. jaclang/tests/fixtures/arch_rel_import_creation.jac +12 -12
  69. jaclang/tests/fixtures/attr_pattern_case.jac +18 -0
  70. jaclang/tests/fixtures/chandra_bugs2.jac +3 -3
  71. jaclang/tests/fixtures/create_dynamic_archetype.jac +13 -13
  72. jaclang/tests/fixtures/funccall_genexpr.jac +7 -0
  73. jaclang/tests/fixtures/funccall_genexpr.py +5 -0
  74. jaclang/tests/fixtures/maxfail_run_test.jac +4 -4
  75. jaclang/tests/fixtures/params/param_syntax_err.jac +9 -0
  76. jaclang/tests/fixtures/params/test_complex_params.jac +42 -0
  77. jaclang/tests/fixtures/params/test_failing_kwonly.jac +207 -0
  78. jaclang/tests/fixtures/params/test_failing_posonly.jac +116 -0
  79. jaclang/tests/fixtures/params/test_failing_varargs.jac +300 -0
  80. jaclang/tests/fixtures/params/test_kwonly_params.jac +29 -0
  81. jaclang/tests/fixtures/py2jac_params.py +8 -0
  82. jaclang/tests/fixtures/run_test.jac +4 -4
  83. jaclang/tests/test_cli.py +159 -7
  84. jaclang/tests/test_language.py +213 -38
  85. jaclang/tests/test_reference.py +3 -1
  86. jaclang/utils/helpers.py +67 -6
  87. jaclang/utils/module_resolver.py +10 -0
  88. jaclang/utils/test.py +8 -0
  89. jaclang/utils/tests/test_lang_tools.py +4 -15
  90. jaclang/utils/treeprinter.py +0 -18
  91. {jaclang-0.8.7.dist-info → jaclang-0.8.9.dist-info}/METADATA +1 -2
  92. {jaclang-0.8.7.dist-info → jaclang-0.8.9.dist-info}/RECORD +95 -65
  93. {jaclang-0.8.7.dist-info → jaclang-0.8.9.dist-info}/WHEEL +1 -1
  94. jaclang/compiler/passes/main/inheritance_pass.py +0 -131
  95. jaclang/compiler/type_system/type_evaluator.py +0 -560
  96. jaclang/langserve/dev_engine.jac +0 -645
  97. jaclang/langserve/dev_server.jac +0 -201
  98. /jaclang/{langserve/tests/server_test/code_test.py → tests/fixtures/py2jac_empty.py} +0 -0
  99. {jaclang-0.8.7.dist-info → jaclang-0.8.9.dist-info}/entry_points.txt +0 -0
@@ -9,92 +9,34 @@ Reference:
9
9
  craizy_type_expr branch: type_checker_pass.py
10
10
  """
11
11
 
12
- import ast as py_ast
13
- import os
14
-
15
12
  import jaclang.compiler.unitree as uni
16
13
  from jaclang.compiler.passes import UniPass
17
- from jaclang.compiler.type_system.type_evaluator import TypeEvaluator
18
- from jaclang.runtimelib.utils import read_file_with_encoding
19
-
20
- from .pyast_load_pass import PyastBuildPass
21
- from .sym_tab_build_pass import SymTabBuildPass
14
+ from jaclang.compiler.type_system import types as jtypes
22
15
 
23
16
 
24
17
  class TypeCheckPass(UniPass):
25
18
  """Type checker pass for JacLang."""
26
19
 
27
- # NOTE: This is done in the binder pass of pyright, however I'm doing this
28
- # here, cause this will be the entry point of the type checker and we're not
29
- # relying on the binder pass at the moment and we can go back to binder pass
30
- # in the future if we needed it.
31
- _BUILTINS_STUB_FILE_PATH = os.path.join(
32
- os.path.dirname(__file__),
33
- "../../../vendor/typeshed/stdlib/builtins.pyi",
34
- )
35
-
36
- # Cache the builtins module once it parsed.
37
- _BUILTINS_MODULE: uni.Module | None = None
38
-
39
- # REVIEW: Making the evaluator a static (singleton) variable to make sure only one
40
- # instance is used across mulitple compilation units. This can also be attached to an
41
- # attribute of JacProgram, however the evaluator is a temproary object that we dont
42
- # want bound to the program for long term, Also the program is the one that will be
43
- # dumped in the compiled bundle.
44
- _EVALUATOR: TypeEvaluator | None = None
45
-
46
20
  def before_pass(self) -> None:
47
21
  """Initialize the checker pass."""
48
- self._load_builtins_stub_module()
22
+ self.evaluator = self.prog.get_type_evaluator()
23
+ self.evaluator.diagnostic_callback = self._add_diagnostic
49
24
  self._insert_builtin_symbols()
50
25
 
51
- @property
52
- def evaluator(self) -> TypeEvaluator:
53
- """Return the type evaluator."""
54
- if TypeCheckPass._EVALUATOR is None:
55
- assert TypeCheckPass._BUILTINS_MODULE is not None
56
- TypeCheckPass._EVALUATOR = TypeEvaluator(
57
- builtins_module=TypeCheckPass._BUILTINS_MODULE,
58
- program=self.prog,
59
- )
60
- return TypeCheckPass._EVALUATOR
26
+ def _add_diagnostic(self, node: uni.UniNode, message: str, warning: bool) -> None:
27
+ """Add a diagnostic message to the pass."""
28
+ if warning:
29
+ self.log_warning(message, node)
30
+ else:
31
+ self.log_error(message, node)
61
32
 
62
33
  # --------------------------------------------------------------------------
63
34
  # Internal helper functions
64
35
  # --------------------------------------------------------------------------
65
36
 
66
- def _binding_builtins(self) -> bool:
67
- """Return true if we're binding the builtins stub file."""
68
- return self.ir_in == TypeCheckPass._BUILTINS_MODULE
69
-
70
- def _load_builtins_stub_module(self) -> None:
71
- """Return the builtins stub module.
72
-
73
- This will parse and cache the stub file and return the cached module on
74
- subsequent calls.
75
- """
76
- if self._binding_builtins() or TypeCheckPass._BUILTINS_MODULE is not None:
77
- return
78
-
79
- if not os.path.exists(TypeCheckPass._BUILTINS_STUB_FILE_PATH):
80
- raise FileNotFoundError(
81
- f"Builtins stub file not found at {TypeCheckPass._BUILTINS_STUB_FILE_PATH}"
82
- )
83
-
84
- file_content = read_file_with_encoding(TypeCheckPass._BUILTINS_STUB_FILE_PATH)
85
- uni_source = uni.Source(file_content, TypeCheckPass._BUILTINS_STUB_FILE_PATH)
86
- mod = PyastBuildPass(
87
- ir_in=uni.PythonModuleAst(
88
- py_ast.parse(file_content),
89
- orig_src=uni_source,
90
- ),
91
- prog=self.prog,
92
- ).ir_out
93
- SymTabBuildPass(ir_in=mod, prog=self.prog)
94
- TypeCheckPass._BUILTINS_MODULE = mod
95
-
96
37
  def _insert_builtin_symbols(self) -> None:
97
- if self._binding_builtins():
38
+ # Don't insert builtin symbols into the builtin module itself.
39
+ if self.ir_in == self.evaluator.builtins_module:
98
40
  return
99
41
 
100
42
  # TODO: Insert these symbols.
@@ -104,20 +46,34 @@ class TypeCheckPass(UniPass):
104
46
  # '__name__', '__loader__', '__package__', '__spec__', '__path__',
105
47
  # '__file__', '__cached__', '__dict__', '__annotations__',
106
48
  # '__builtins__', '__doc__',
107
- assert (
108
- TypeCheckPass._BUILTINS_MODULE is not None
109
- ), "Builtins module is not loaded"
110
49
  if self.ir_in.parent_scope is not None:
111
50
  self.log_info("Builtins module is already bound, skipping.")
112
51
  return
113
52
  # Review: If we ever assume a module cannot have a parent scope, this will
114
53
  # break that contract.
115
- self.ir_in.parent_scope = TypeCheckPass._BUILTINS_MODULE
54
+ self.ir_in.parent_scope = self.evaluator.builtins_module
116
55
 
117
56
  # --------------------------------------------------------------------------
118
57
  # Ast walker hooks
119
58
  # --------------------------------------------------------------------------
120
59
 
60
+ def enter_ability(self, node: uni.Ability) -> None:
61
+ """Enter an ability node."""
62
+ # If the node has @staticmethod decorator, mark it as static method.
63
+ # this is needed since ast raised from python does not have this info.
64
+ for decor in node.decorators or []:
65
+ ty = self.evaluator.get_type_of_expression(decor)
66
+ if isinstance(ty, jtypes.ClassType) and ty.is_builtin("staticmethod"):
67
+ node.is_static = True
68
+ break
69
+
70
+ def exit_import(self, node: uni.Import) -> None:
71
+ """Exit an import node."""
72
+ if node.from_loc:
73
+ for item in node.items:
74
+ if isinstance(item, uni.ModuleItem):
75
+ self.evaluator.get_type_of_module_item(item)
76
+
121
77
  def exit_assignment(self, node: uni.Assignment) -> None:
122
78
  """Pyright: Checker.visitAssignment(node: AssignmentNode): boolean."""
123
79
  # TODO: In pyright this logic is present at evaluateTypesForAssignmentStatement