jaclang 0.8.7__py3-none-any.whl → 0.8.8__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.
- jaclang/cli/cli.py +13 -27
- jaclang/cli/cmdreg.py +44 -0
- jaclang/compiler/constant.py +0 -1
- jaclang/compiler/jac.lark +3 -6
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +213 -34
- jaclang/compiler/passes/main/__init__.py +2 -4
- jaclang/compiler/passes/main/def_use_pass.py +0 -4
- jaclang/compiler/passes/main/predynamo_pass.py +221 -0
- jaclang/compiler/passes/main/pyast_gen_pass.py +70 -52
- jaclang/compiler/passes/main/pyast_load_pass.py +52 -20
- jaclang/compiler/passes/main/sym_tab_build_pass.py +1 -1
- jaclang/compiler/passes/main/tests/fixtures/checker/import_sym.jac +2 -0
- jaclang/compiler/passes/main/tests/fixtures/checker/import_sym_test.jac +6 -0
- jaclang/compiler/passes/main/tests/fixtures/checker/imported_sym.jac +5 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_arg_param_match.jac +37 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_arity.jac +18 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_cat_is_animal.jac +18 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_float.jac +7 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_param_types.jac +11 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_self_type.jac +9 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_sym_inherit.jac +42 -0
- jaclang/compiler/passes/main/tests/fixtures/predynamo_fix3.jac +43 -0
- jaclang/compiler/passes/main/tests/fixtures/predynamo_where_assign.jac +13 -0
- jaclang/compiler/passes/main/tests/fixtures/predynamo_where_return.jac +11 -0
- jaclang/compiler/passes/main/tests/test_checker_pass.py +191 -0
- jaclang/compiler/passes/main/tests/test_predynamo_pass.py +57 -0
- jaclang/compiler/passes/main/type_checker_pass.py +29 -73
- jaclang/compiler/passes/tool/doc_ir_gen_pass.py +204 -44
- jaclang/compiler/passes/tool/jac_formatter_pass.py +119 -69
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +3 -3
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +4 -5
- jaclang/compiler/passes/tool/tests/fixtures/tagbreak.jac +171 -11
- jaclang/compiler/passes/transform.py +12 -8
- jaclang/compiler/program.py +14 -6
- jaclang/compiler/tests/fixtures/jac_import_py_files.py +4 -0
- jaclang/compiler/tests/fixtures/jac_module.jac +3 -0
- jaclang/compiler/tests/fixtures/multiple_syntax_errors.jac +10 -0
- jaclang/compiler/tests/fixtures/python_module.py +1 -0
- jaclang/compiler/tests/test_importer.py +39 -0
- jaclang/compiler/tests/test_parser.py +49 -0
- jaclang/compiler/type_system/type_evaluator.py +351 -67
- jaclang/compiler/type_system/type_utils.py +246 -0
- jaclang/compiler/type_system/types.py +58 -2
- jaclang/compiler/unitree.py +79 -94
- jaclang/langserve/engine.jac +138 -159
- jaclang/langserve/server.jac +25 -1
- jaclang/langserve/tests/fixtures/circle.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_pure.test.jac +3 -3
- jaclang/langserve/tests/fixtures/completion_test_err.jac +10 -0
- jaclang/langserve/tests/server_test/circle_template.jac +80 -0
- jaclang/langserve/tests/server_test/glob_template.jac +4 -0
- jaclang/langserve/tests/server_test/test_lang_serve.py +154 -309
- jaclang/langserve/tests/server_test/utils.py +153 -116
- jaclang/langserve/tests/test_server.py +21 -84
- jaclang/langserve/utils.jac +12 -15
- jaclang/runtimelib/machine.py +7 -0
- jaclang/runtimelib/meta_importer.py +27 -1
- jaclang/runtimelib/tests/fixtures/custom_access_validation.jac +1 -1
- jaclang/runtimelib/tests/fixtures/savable_object.jac +2 -2
- jaclang/settings.py +18 -14
- jaclang/tests/fixtures/abc_check.jac +3 -3
- jaclang/tests/fixtures/arch_rel_import_creation.jac +12 -12
- jaclang/tests/fixtures/chandra_bugs2.jac +3 -3
- jaclang/tests/fixtures/create_dynamic_archetype.jac +13 -13
- jaclang/tests/fixtures/maxfail_run_test.jac +4 -4
- jaclang/tests/fixtures/params/param_syntax_err.jac +9 -0
- jaclang/tests/fixtures/params/test_complex_params.jac +42 -0
- jaclang/tests/fixtures/params/test_failing_kwonly.jac +207 -0
- jaclang/tests/fixtures/params/test_failing_posonly.jac +116 -0
- jaclang/tests/fixtures/params/test_failing_varargs.jac +300 -0
- jaclang/tests/fixtures/params/test_kwonly_params.jac +29 -0
- jaclang/tests/fixtures/py2jac_params.py +8 -0
- jaclang/tests/fixtures/run_test.jac +4 -4
- jaclang/tests/test_cli.py +37 -1
- jaclang/tests/test_language.py +74 -16
- jaclang/utils/helpers.py +47 -2
- jaclang/utils/module_resolver.py +10 -0
- jaclang/utils/test.py +8 -0
- jaclang/utils/treeprinter.py +0 -18
- {jaclang-0.8.7.dist-info → jaclang-0.8.8.dist-info}/METADATA +1 -2
- {jaclang-0.8.7.dist-info → jaclang-0.8.8.dist-info}/RECORD +85 -60
- {jaclang-0.8.7.dist-info → jaclang-0.8.8.dist-info}/WHEEL +1 -1
- jaclang/compiler/passes/main/inheritance_pass.py +0 -131
- jaclang/langserve/dev_engine.jac +0 -645
- jaclang/langserve/dev_server.jac +0 -201
- jaclang/langserve/tests/server_test/code_test.py +0 -0
- {jaclang-0.8.7.dist-info → jaclang-0.8.8.dist-info}/entry_points.txt +0 -0
|
@@ -1000,6 +1000,9 @@ class PyastGenPass(UniPass):
|
|
|
1000
1000
|
pass
|
|
1001
1001
|
|
|
1002
1002
|
def exit_func_signature(self, node: uni.FuncSignature) -> None:
|
|
1003
|
+
posonlyargs = [i.gen.py_ast[0] for i in node.posonly_params]
|
|
1004
|
+
vararg = node.varargs.gen.py_ast[0] if node.varargs else None
|
|
1005
|
+
kwarg = node.kwargs.gen.py_ast[0] if node.kwargs else None
|
|
1003
1006
|
params = (
|
|
1004
1007
|
[self.sync(ast3.arg(arg="self", annotation=None))]
|
|
1005
1008
|
if (abl := node.parent)
|
|
@@ -1009,29 +1012,33 @@ class PyastGenPass(UniPass):
|
|
|
1009
1012
|
and not node.is_in_py_class
|
|
1010
1013
|
else []
|
|
1011
1014
|
)
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1015
|
+
if posonlyargs:
|
|
1016
|
+
posonlyargs = params + posonlyargs
|
|
1017
|
+
params = [i.gen.py_ast[0] for i in node.params]
|
|
1018
|
+
else:
|
|
1019
|
+
params = params + [i.gen.py_ast[0] for i in node.params]
|
|
1020
|
+
defaults = []
|
|
1021
|
+
for i in [*node.posonly_params, *node.params]:
|
|
1022
|
+
if i.value:
|
|
1023
|
+
defaults.append(cast(ast3.expr, i.value.gen.py_ast[0]))
|
|
1024
|
+
kwonly_args = [i.gen.py_ast[0] for i in node.kwonlyargs]
|
|
1025
|
+
# kw_defaults must be the same length as kwonlyargs
|
|
1026
|
+
# it will have None for args that don't have defaults
|
|
1027
|
+
kw_defaults: list[ast3.expr | None] = []
|
|
1028
|
+
for i in node.kwonlyargs:
|
|
1029
|
+
if i.value:
|
|
1030
|
+
kw_defaults.append(cast(ast3.expr, i.value.gen.py_ast[0]))
|
|
1019
1031
|
else:
|
|
1020
|
-
(
|
|
1021
|
-
params.append(i.gen.py_ast[0])
|
|
1022
|
-
if isinstance(i.gen.py_ast[0], ast3.arg)
|
|
1023
|
-
else self.ice("This list should only be Args")
|
|
1024
|
-
)
|
|
1025
|
-
defaults = [x.value.gen.py_ast[0] for x in node.params if x.value]
|
|
1032
|
+
kw_defaults.append(None)
|
|
1026
1033
|
node.gen.py_ast = [
|
|
1027
1034
|
self.sync(
|
|
1028
1035
|
ast3.arguments(
|
|
1029
|
-
posonlyargs=[],
|
|
1036
|
+
posonlyargs=[cast(ast3.arg, param) for param in posonlyargs],
|
|
1030
1037
|
args=[cast(ast3.arg, param) for param in params],
|
|
1031
|
-
kwonlyargs=
|
|
1038
|
+
kwonlyargs=kwonly_args,
|
|
1032
1039
|
vararg=cast(ast3.arg, vararg) if vararg else None,
|
|
1033
1040
|
kwarg=cast(ast3.arg, kwarg) if kwarg else None,
|
|
1034
|
-
kw_defaults=
|
|
1041
|
+
kw_defaults=kw_defaults,
|
|
1035
1042
|
defaults=[cast(ast3.expr, default) for default in defaults],
|
|
1036
1043
|
)
|
|
1037
1044
|
)
|
|
@@ -1467,20 +1474,23 @@ class PyastGenPass(UniPass):
|
|
|
1467
1474
|
]
|
|
1468
1475
|
|
|
1469
1476
|
def exit_assert_stmt(self, node: uni.AssertStmt) -> None:
|
|
1470
|
-
node.
|
|
1471
|
-
self.
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1477
|
+
if isinstance(node.parent, uni.Test):
|
|
1478
|
+
self.assert_helper(node)
|
|
1479
|
+
else:
|
|
1480
|
+
node.gen.py_ast = [
|
|
1481
|
+
self.sync(
|
|
1482
|
+
ast3.Assert(
|
|
1483
|
+
test=cast(ast3.expr, node.condition.gen.py_ast[0]),
|
|
1484
|
+
msg=(
|
|
1485
|
+
cast(ast3.expr, node.error_msg.gen.py_ast[0])
|
|
1486
|
+
if node.error_msg
|
|
1487
|
+
else None
|
|
1488
|
+
),
|
|
1489
|
+
)
|
|
1479
1490
|
)
|
|
1480
|
-
|
|
1481
|
-
]
|
|
1491
|
+
]
|
|
1482
1492
|
|
|
1483
|
-
def
|
|
1493
|
+
def assert_helper(self, node: uni.AssertStmt) -> None:
|
|
1484
1494
|
"""Sub objects.
|
|
1485
1495
|
|
|
1486
1496
|
target: ExprType,
|
|
@@ -1536,16 +1546,16 @@ class PyastGenPass(UniPass):
|
|
|
1536
1546
|
|
|
1537
1547
|
# By default the check expression will become assertTrue(<expr>), unless any pattern detected.
|
|
1538
1548
|
assert_func_name = "assertTrue"
|
|
1539
|
-
assert_args_list = node.
|
|
1549
|
+
assert_args_list = node.condition.gen.py_ast
|
|
1540
1550
|
|
|
1541
1551
|
# Compare operations. Note that We're only considering the compare
|
|
1542
1552
|
# operation with a single operation ie. a < b < c is ignored here.
|
|
1543
1553
|
if (
|
|
1544
|
-
isinstance(node.
|
|
1545
|
-
and isinstance(node.
|
|
1546
|
-
and len(node.
|
|
1554
|
+
isinstance(node.condition, uni.CompareExpr)
|
|
1555
|
+
and isinstance(node.condition.gen.py_ast[0], ast3.Compare)
|
|
1556
|
+
and len(node.condition.ops) == 1
|
|
1547
1557
|
):
|
|
1548
|
-
expr: uni.CompareExpr = node.
|
|
1558
|
+
expr: uni.CompareExpr = node.condition
|
|
1549
1559
|
opty: uni.Token = expr.ops[0]
|
|
1550
1560
|
|
|
1551
1561
|
optype2fn = {
|
|
@@ -1579,10 +1589,10 @@ class PyastGenPass(UniPass):
|
|
|
1579
1589
|
assert_args_list.pop()
|
|
1580
1590
|
|
|
1581
1591
|
# Check if 'isinstance' is called.
|
|
1582
|
-
elif isinstance(node.
|
|
1583
|
-
node.
|
|
1592
|
+
elif isinstance(node.condition, uni.FuncCall) and isinstance(
|
|
1593
|
+
node.condition.gen.py_ast[0], ast3.Call
|
|
1584
1594
|
):
|
|
1585
|
-
res = check_node_isinstance_call(node.
|
|
1595
|
+
res = check_node_isinstance_call(node.condition)
|
|
1586
1596
|
if res.isit:
|
|
1587
1597
|
# These assertions will make mypy happy.
|
|
1588
1598
|
assert isinstance(res.inst, ast3.AST)
|
|
@@ -1592,12 +1602,12 @@ class PyastGenPass(UniPass):
|
|
|
1592
1602
|
|
|
1593
1603
|
# Check if 'not isinstance(<expr>, <expr>)' is called.
|
|
1594
1604
|
elif (
|
|
1595
|
-
isinstance(node.
|
|
1596
|
-
and isinstance(node.
|
|
1597
|
-
and isinstance(node.
|
|
1598
|
-
and isinstance(node.
|
|
1605
|
+
isinstance(node.condition, uni.UnaryExpr)
|
|
1606
|
+
and isinstance(node.condition, uni.UnaryExpr)
|
|
1607
|
+
and isinstance(node.condition.operand, uni.FuncCall)
|
|
1608
|
+
and isinstance(node.condition.operand, uni.UnaryExpr)
|
|
1599
1609
|
):
|
|
1600
|
-
res = check_node_isinstance_call(node.
|
|
1610
|
+
res = check_node_isinstance_call(node.condition.operand)
|
|
1601
1611
|
if res.isit:
|
|
1602
1612
|
# These assertions will make mypy happy.
|
|
1603
1613
|
assert isinstance(res.inst, ast3.AST)
|
|
@@ -1610,14 +1620,14 @@ class PyastGenPass(UniPass):
|
|
|
1610
1620
|
# the almost equal functionality (snice there is no almost equal operator in jac and never needed ig.).
|
|
1611
1621
|
|
|
1612
1622
|
# Check if 'almostEqual' is called.
|
|
1613
|
-
if isinstance(node.
|
|
1614
|
-
node.
|
|
1623
|
+
if isinstance(node.condition, uni.FuncCall) and isinstance(
|
|
1624
|
+
node.condition.gen.py_ast[0], ast3.Call
|
|
1615
1625
|
):
|
|
1616
|
-
func = node.
|
|
1626
|
+
func = node.condition.target
|
|
1617
1627
|
if isinstance(func, uni.Name) and func.value == "almostEqual":
|
|
1618
1628
|
assert_func_name = "assertAlmostEqual"
|
|
1619
1629
|
assert_args_list = []
|
|
1620
|
-
for param in node.
|
|
1630
|
+
for param in node.condition.params:
|
|
1621
1631
|
assert_args_list.append(param.gen.py_ast[0])
|
|
1622
1632
|
|
|
1623
1633
|
# assert_func_expr = "Con.JAC_CHECK.value.assertXXX"
|
|
@@ -2718,14 +2728,22 @@ class PyastGenPass(UniPass):
|
|
|
2718
2728
|
keywords=[],
|
|
2719
2729
|
)
|
|
2720
2730
|
)
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2731
|
+
if node.is_async:
|
|
2732
|
+
pynode = self.sync(
|
|
2733
|
+
ast3.Call(
|
|
2734
|
+
func=self.jaclib_obj("arefs"),
|
|
2735
|
+
args=[pynode],
|
|
2736
|
+
keywords=[],
|
|
2737
|
+
)
|
|
2738
|
+
)
|
|
2739
|
+
else:
|
|
2740
|
+
pynode = self.sync(
|
|
2741
|
+
ast3.Call(
|
|
2742
|
+
func=self.jaclib_obj("refs"),
|
|
2743
|
+
args=[pynode],
|
|
2744
|
+
keywords=[],
|
|
2745
|
+
)
|
|
2727
2746
|
)
|
|
2728
|
-
)
|
|
2729
2747
|
|
|
2730
2748
|
node.gen.py_ast = [pynode]
|
|
2731
2749
|
|
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import ast as py_ast
|
|
18
18
|
import os
|
|
19
|
-
from typing import Optional, Sequence, TYPE_CHECKING, TypeAlias, TypeVar
|
|
19
|
+
from typing import Optional, Sequence, TYPE_CHECKING, TypeAlias, TypeVar, cast
|
|
20
20
|
|
|
21
21
|
import jaclang.compiler.unitree as uni
|
|
22
22
|
from jaclang.compiler.constant import Tokens as Tok
|
|
@@ -2091,6 +2091,7 @@ class PyastBuildPass(Transform[uni.PythonModuleAst, uni.Module]):
|
|
|
2091
2091
|
"""Process python node.
|
|
2092
2092
|
|
|
2093
2093
|
class arguments(AST):
|
|
2094
|
+
posonlyargs: list[arg]
|
|
2094
2095
|
args: list[arg]
|
|
2095
2096
|
vararg: arg | None
|
|
2096
2097
|
kwonlyargs: list[arg]
|
|
@@ -2098,9 +2099,23 @@ class PyastBuildPass(Transform[uni.PythonModuleAst, uni.Module]):
|
|
|
2098
2099
|
kwarg: arg | None
|
|
2099
2100
|
defaults: list[expr]
|
|
2100
2101
|
"""
|
|
2101
|
-
|
|
2102
|
+
|
|
2103
|
+
def _apply_kind(params: list, kind: uni.ParamKind) -> list:
|
|
2104
|
+
for param in params:
|
|
2105
|
+
cast(uni.ParamVar, param).param_kind = kind
|
|
2106
|
+
return params
|
|
2107
|
+
|
|
2108
|
+
posonlyargs = _apply_kind(
|
|
2109
|
+
[self.convert(arg) for arg in node.posonlyargs], uni.ParamKind.POSONLY
|
|
2110
|
+
)
|
|
2111
|
+
args = _apply_kind(
|
|
2112
|
+
[self.convert(arg) for arg in node.args], uni.ParamKind.NORMAL
|
|
2113
|
+
)
|
|
2114
|
+
|
|
2102
2115
|
vararg = self.convert(node.vararg) if node.vararg else None
|
|
2116
|
+
|
|
2103
2117
|
if vararg and isinstance(vararg, uni.ParamVar):
|
|
2118
|
+
vararg.param_kind = uni.ParamKind.VARARG
|
|
2104
2119
|
vararg.unpack = uni.Token(
|
|
2105
2120
|
orig_src=self.orig_src,
|
|
2106
2121
|
name=Tok.STAR_MUL,
|
|
@@ -2113,7 +2128,10 @@ class PyastBuildPass(Transform[uni.PythonModuleAst, uni.Module]):
|
|
|
2113
2128
|
pos_end=0,
|
|
2114
2129
|
)
|
|
2115
2130
|
vararg.add_kids_left([vararg.unpack])
|
|
2116
|
-
|
|
2131
|
+
|
|
2132
|
+
kwonlyargs = _apply_kind(
|
|
2133
|
+
[self.convert(arg) for arg in node.kwonlyargs], uni.ParamKind.KWONLY
|
|
2134
|
+
)
|
|
2117
2135
|
for i in range(len(kwonlyargs)):
|
|
2118
2136
|
kwa = kwonlyargs[i]
|
|
2119
2137
|
kwd = node.kw_defaults[i]
|
|
@@ -2127,6 +2145,7 @@ class PyastBuildPass(Transform[uni.PythonModuleAst, uni.Module]):
|
|
|
2127
2145
|
kwa.add_kids_right([kwa.value])
|
|
2128
2146
|
kwarg = self.convert(node.kwarg) if node.kwarg else None
|
|
2129
2147
|
if kwarg and isinstance(kwarg, uni.ParamVar):
|
|
2148
|
+
kwarg.param_kind = uni.ParamKind.KWARG
|
|
2130
2149
|
kwarg.unpack = uni.Token(
|
|
2131
2150
|
orig_src=self.orig_src,
|
|
2132
2151
|
name=Tok.STAR_POW,
|
|
@@ -2140,29 +2159,42 @@ class PyastBuildPass(Transform[uni.PythonModuleAst, uni.Module]):
|
|
|
2140
2159
|
)
|
|
2141
2160
|
kwarg.add_kids_left([kwarg.unpack])
|
|
2142
2161
|
defaults = [self.convert(expr) for expr in node.defaults]
|
|
2143
|
-
|
|
2144
|
-
for
|
|
2145
|
-
if
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
if
|
|
2157
|
-
|
|
2162
|
+
# iterate reverse to match from the end
|
|
2163
|
+
for para in [*posonlyargs, *args][::-1]:
|
|
2164
|
+
if not defaults:
|
|
2165
|
+
break
|
|
2166
|
+
default = defaults.pop()
|
|
2167
|
+
if (
|
|
2168
|
+
default
|
|
2169
|
+
and isinstance(para, uni.ParamVar)
|
|
2170
|
+
and isinstance(default, uni.Expr)
|
|
2171
|
+
):
|
|
2172
|
+
para.value = default
|
|
2173
|
+
para.add_kids_right([para.value])
|
|
2174
|
+
|
|
2175
|
+
if kwonlyargs or args or posonlyargs or vararg or kwarg:
|
|
2176
|
+
kids = []
|
|
2177
|
+
kids.extend(posonlyargs) if posonlyargs else None
|
|
2178
|
+
kids.extend(args) if args else None
|
|
2179
|
+
kids.append(vararg) if vararg else None
|
|
2180
|
+
kids.extend(kwonlyargs) if kwonlyargs else None
|
|
2181
|
+
kids.append(kwarg) if kwarg else None
|
|
2158
2182
|
return uni.FuncSignature(
|
|
2159
|
-
|
|
2183
|
+
posonly_params=posonlyargs,
|
|
2184
|
+
params=args,
|
|
2185
|
+
varargs=vararg,
|
|
2186
|
+
kwonlyargs=kwonlyargs,
|
|
2187
|
+
kwargs=kwarg,
|
|
2160
2188
|
return_type=None,
|
|
2161
|
-
kid=
|
|
2189
|
+
kid=kids,
|
|
2162
2190
|
)
|
|
2163
2191
|
else:
|
|
2164
2192
|
return uni.FuncSignature(
|
|
2193
|
+
posonly_params=posonlyargs,
|
|
2165
2194
|
params=[],
|
|
2195
|
+
varargs=vararg,
|
|
2196
|
+
kwonlyargs=kwonlyargs,
|
|
2197
|
+
kwargs=kwarg,
|
|
2166
2198
|
return_type=None,
|
|
2167
2199
|
kid=[self.operator(Tok.LPAREN, "("), self.operator(Tok.RPAREN, ")")],
|
|
2168
2200
|
)
|
|
@@ -75,7 +75,7 @@ class SymTabBuildPass(UniPass):
|
|
|
75
75
|
def exit_module_path(self, node: uni.ModulePath) -> None:
|
|
76
76
|
if node.alias:
|
|
77
77
|
node.alias.sym_tab.def_insert(node.alias, single_decl="import")
|
|
78
|
-
elif node.path
|
|
78
|
+
elif node.path:
|
|
79
79
|
if node.parent_of_type(uni.Import) and not (
|
|
80
80
|
node.parent_of_type(uni.Import).from_loc
|
|
81
81
|
and node.parent_of_type(uni.Import).is_jac
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
class Foo {
|
|
3
|
+
def bar(self: Foo, a:int) -> None {}
|
|
4
|
+
static def baz(self: int, a: int) -> None {}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
def foo(a: int, b: int, /, c:int, d:int, *args:int, e:int, f:int, **kwargs:int) -> None {}
|
|
8
|
+
def bar(a: int, b: int, /, c:int, d:int, e:int, f:int) -> None {}
|
|
9
|
+
def baz(a: int, *, b:int) -> None {}
|
|
10
|
+
|
|
11
|
+
with entry {
|
|
12
|
+
f = Foo();
|
|
13
|
+
|
|
14
|
+
f.bar();
|
|
15
|
+
f.bar(1);
|
|
16
|
+
f.bar(1, 2);
|
|
17
|
+
|
|
18
|
+
f.baz();
|
|
19
|
+
f.baz(1);
|
|
20
|
+
f.baz(1, 2);
|
|
21
|
+
|
|
22
|
+
foo(1, 2, 3, d=4, e=5, f=6, g=7, h=8); # c is positional and d is named
|
|
23
|
+
foo(1, 2, 3, 4, 5, 6, 7, 8, e=5, f=6); # marching extra with *args
|
|
24
|
+
foo(1, 2, d=3, e=4, f=5, c=4); # order does not matter for named
|
|
25
|
+
|
|
26
|
+
foo(1, 2, 3, d=4, e=5, g=7, h=8); # missing argument 'f'
|
|
27
|
+
foo(1, b=2, c=3, d=4, e=5, f=6); # b is positional only
|
|
28
|
+
|
|
29
|
+
bar(1, 2, 3, 4, 5, f=6);
|
|
30
|
+
bar(1, 2, 3, 4, 5, 6, 7, 8, 9); # too many args
|
|
31
|
+
bar(1, 2, 3, 4, 5, 6, c=3); # already matched
|
|
32
|
+
bar(1, 2, 3, 4, 5, 6, h=1); # h is not matched
|
|
33
|
+
|
|
34
|
+
baz(a=1, b=2);
|
|
35
|
+
baz(1, b=2); # a can be both positional and keyword
|
|
36
|
+
baz(1, 2); # 'b' can only be keyword arg
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
class Foo {
|
|
3
|
+
def first_is_self(self: Foo) -> None {}
|
|
4
|
+
|
|
5
|
+
def with_default_args(self: Foo, a:int, b:int=42) -> None {}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
with entry {
|
|
10
|
+
f = Foo();
|
|
11
|
+
f.first_is_self(); # <-- Ok
|
|
12
|
+
f.first_is_self(f); # <-- Error
|
|
13
|
+
|
|
14
|
+
f.with_default_args(1); # <-- Ok
|
|
15
|
+
f.with_default_args(1, 2); # <-- Ok
|
|
16
|
+
f.with_default_args(1, 2, 3); # <-- Error
|
|
17
|
+
f.with_default_args(); # <-- Error
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
obj Animal {}
|
|
3
|
+
obj Cat(Animal) {}
|
|
4
|
+
obj Lion(Cat) {}
|
|
5
|
+
|
|
6
|
+
obj NotAnimal {}
|
|
7
|
+
|
|
8
|
+
def animal_func(a: Animal) -> None {}
|
|
9
|
+
|
|
10
|
+
with entry {
|
|
11
|
+
cat: Cat = Cat();
|
|
12
|
+
lion: Lion = Lion();
|
|
13
|
+
not_animal: NotAnimal = NotAnimal();
|
|
14
|
+
|
|
15
|
+
animal_func(cat); # <-- Ok
|
|
16
|
+
animal_func(lion); # <-- Ok
|
|
17
|
+
animal_func(not_animal); # <-- Error
|
|
18
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
# -----------------------------------------------------------------------------
|
|
3
|
+
# Simple Inheritance
|
|
4
|
+
# -----------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
node Parent {
|
|
7
|
+
has val: int = 42;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
node Child (Parent) {
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
with entry {
|
|
16
|
+
c = Child();
|
|
17
|
+
c.val = 42; # <-- Ok
|
|
18
|
+
c.val = "str"; # <-- Error
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# -----------------------------------------------------------------------------
|
|
23
|
+
# A Complex Inheritance
|
|
24
|
+
# -----------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
node Animal {
|
|
27
|
+
has name: str;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
node Cat(Animal) {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
node Lion(Cat) {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
with entry {
|
|
38
|
+
l = Lion();
|
|
39
|
+
|
|
40
|
+
l.name = "Simba"; # <-- Ok
|
|
41
|
+
l.name = 42; # <-- Error
|
|
42
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import torch;
|
|
2
|
+
class Cfg {
|
|
3
|
+
def __init__(self: Cfg, max_position_embeddings: Any = 8, has_original: Any = False) {
|
|
4
|
+
self.max_position_embeddings = max_position_embeddings;
|
|
5
|
+
if has_original {
|
|
6
|
+
self.original_max_position_embeddings = (max_position_embeddings // 2);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class ToyModel(torch.nn.Module) {
|
|
11
|
+
def __init__(self: ToyModel, cfg: Cfg) {
|
|
12
|
+
super.init();
|
|
13
|
+
self.config = cfg;
|
|
14
|
+
self.long_inv_freq = torch.tensor([10.0, 20.0, 30.0]);
|
|
15
|
+
self.original_inv_freq = torch.tensor([1.0, 2.0, 3.0]);
|
|
16
|
+
}
|
|
17
|
+
def rope_init_fn(self: ToyModel, cfg: Any, device: Any, seq_len: int) {
|
|
18
|
+
return (torch.arange(1, 4, dtype=torch.float32, device=device), None);
|
|
19
|
+
}
|
|
20
|
+
def _longrope_frequency_update(
|
|
21
|
+
self: ToyModel,
|
|
22
|
+
position_ids: Any,
|
|
23
|
+
device: Any = 'cpu'
|
|
24
|
+
) {
|
|
25
|
+
seq_len = (torch.max(position_ids) + 1);
|
|
26
|
+
if hasattr(self.config, 'original_max_position_embeddings') {
|
|
27
|
+
original_max_position_embeddings = self.config.original_max_position_embeddings;
|
|
28
|
+
} else {
|
|
29
|
+
original_max_position_embeddings = self.config.max_position_embeddings;
|
|
30
|
+
}
|
|
31
|
+
if (seq_len > original_max_position_embeddings) {
|
|
32
|
+
self.register_buffer('inv_freq', self.long_inv_freq, persistent=False);
|
|
33
|
+
} else {
|
|
34
|
+
self.register_buffer(
|
|
35
|
+
'inv_freq',
|
|
36
|
+
self.original_inv_freq.to(device),
|
|
37
|
+
persistent=False
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return self.inv_freq;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|