@elaraai/east 0.0.1-beta.9 → 1.0.0
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.
- package/LICENSE.md +15 -666
- package/README.md +113 -88
- package/dist/src/analyze.d.ts +3 -0
- package/dist/src/analyze.d.ts.map +1 -1
- package/dist/src/analyze.js +223 -111
- package/dist/src/analyze.js.map +1 -1
- package/dist/src/analyze.spec.d.ts +2 -0
- package/dist/src/analyze.spec.d.ts.map +1 -0
- package/dist/src/analyze.spec.js +445 -0
- package/dist/src/analyze.spec.js.map +1 -0
- package/dist/src/ast.d.ts +54 -35
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast_to_ir.coerce_to.spec.d.ts +15 -0
- package/dist/src/ast_to_ir.coerce_to.spec.d.ts.map +1 -0
- package/dist/src/ast_to_ir.coerce_to.spec.js +420 -0
- package/dist/src/ast_to_ir.coerce_to.spec.js.map +1 -0
- package/dist/src/ast_to_ir.d.ts +18 -4
- package/dist/src/ast_to_ir.d.ts.map +1 -1
- package/dist/src/ast_to_ir.js +233 -178
- package/dist/src/ast_to_ir.js.map +1 -1
- package/dist/src/builtins.d.ts +1 -1
- package/dist/src/builtins.d.ts.map +1 -1
- package/dist/src/builtins.js +194 -2
- package/dist/src/builtins.js.map +1 -1
- package/dist/src/comparison.d.ts +2 -2
- package/dist/src/comparison.d.ts.map +1 -1
- package/dist/src/comparison.js +115 -40
- package/dist/src/comparison.js.map +1 -1
- package/dist/src/comparison.spec.d.ts +2 -0
- package/dist/src/comparison.spec.d.ts.map +1 -0
- package/dist/src/comparison.spec.js +1200 -0
- package/dist/src/comparison.spec.js.map +1 -0
- package/dist/src/compile.d.ts +31 -9
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +1048 -548
- package/dist/src/compile.js.map +1 -1
- package/dist/src/containers/matrix.d.ts +15 -0
- package/dist/src/containers/matrix.d.ts.map +1 -0
- package/dist/src/containers/matrix.js +15 -0
- package/dist/src/containers/matrix.js.map +1 -0
- package/dist/src/containers/ref.d.ts.map +1 -1
- package/dist/src/containers/ref.js +1 -1
- package/dist/src/containers/ref.js.map +1 -1
- package/dist/src/containers/sortedmap.spec.d.ts +2 -0
- package/dist/src/containers/sortedmap.spec.d.ts.map +1 -0
- package/dist/src/containers/sortedmap.spec.js +180 -0
- package/dist/src/containers/sortedmap.spec.js.map +1 -0
- package/dist/src/containers/sortedset.spec.d.ts +2 -0
- package/dist/src/containers/sortedset.spec.d.ts.map +1 -0
- package/dist/src/containers/sortedset.spec.js +228 -0
- package/dist/src/containers/sortedset.spec.js.map +1 -0
- package/dist/src/containers/variant.d.ts.map +1 -1
- package/dist/src/containers/variant.js +1 -1
- package/dist/src/containers/variant.js.map +1 -1
- package/dist/src/containers/variant.spec.d.ts +2 -0
- package/dist/src/containers/variant.spec.d.ts.map +1 -0
- package/dist/src/containers/variant.spec.js +217 -0
- package/dist/src/containers/variant.spec.js.map +1 -0
- package/dist/src/datetime_format/parse.spec.d.ts +6 -0
- package/dist/src/datetime_format/parse.spec.d.ts.map +1 -0
- package/dist/src/datetime_format/parse.spec.js +379 -0
- package/dist/src/datetime_format/parse.spec.js.map +1 -0
- package/dist/src/datetime_format/print.spec.d.ts +6 -0
- package/dist/src/datetime_format/print.spec.d.ts.map +1 -0
- package/dist/src/datetime_format/print.spec.js +257 -0
- package/dist/src/datetime_format/print.spec.js.map +1 -0
- package/dist/src/datetime_format/tokenize.spec.d.ts +2 -0
- package/dist/src/datetime_format/tokenize.spec.d.ts.map +1 -0
- package/dist/src/datetime_format/tokenize.spec.js +508 -0
- package/dist/src/datetime_format/tokenize.spec.js.map +1 -0
- package/dist/src/datetime_format/types.d.ts +23 -23
- package/dist/src/default.d.ts.map +1 -1
- package/dist/src/default.js +33 -0
- package/dist/src/default.js.map +1 -1
- package/dist/src/default.spec.d.ts +2 -0
- package/dist/src/default.spec.d.ts.map +1 -0
- package/dist/src/default.spec.js +178 -0
- package/dist/src/default.spec.js.map +1 -0
- package/dist/src/eastir.d.ts +7 -0
- package/dist/src/eastir.d.ts.map +1 -1
- package/dist/src/eastir.js +55 -7
- package/dist/src/eastir.js.map +1 -1
- package/dist/src/error.d.ts +14 -4
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/error.js +28 -3
- package/dist/src/error.js.map +1 -1
- package/dist/src/example.d.ts +87 -0
- package/dist/src/example.d.ts.map +1 -0
- package/dist/src/example.js +18 -0
- package/dist/src/example.js.map +1 -0
- package/dist/src/expr/array.d.ts +43 -1
- package/dist/src/expr/array.d.ts.map +1 -1
- package/dist/src/expr/array.js +103 -53
- package/dist/src/expr/array.js.map +1 -1
- package/dist/src/expr/ast.d.ts +1 -1
- package/dist/src/expr/ast.d.ts.map +1 -1
- package/dist/src/expr/ast.js +112 -54
- package/dist/src/expr/ast.js.map +1 -1
- package/dist/src/expr/asyncfunction.d.ts.map +1 -1
- package/dist/src/expr/asyncfunction.js +6 -4
- package/dist/src/expr/asyncfunction.js.map +1 -1
- package/dist/src/expr/blob.d.ts +48 -0
- package/dist/src/expr/blob.d.ts.map +1 -1
- package/dist/src/expr/blob.js +63 -8
- package/dist/src/expr/blob.js.map +1 -1
- package/dist/src/expr/block.d.ts +213 -12
- package/dist/src/expr/block.d.ts.map +1 -1
- package/dist/src/expr/block.js +796 -293
- package/dist/src/expr/block.js.map +1 -1
- package/dist/src/expr/boolean.d.ts +44 -0
- package/dist/src/expr/boolean.d.ts.map +1 -1
- package/dist/src/expr/boolean.js +58 -6
- package/dist/src/expr/boolean.js.map +1 -1
- package/dist/src/expr/datetime.d.ts +135 -0
- package/dist/src/expr/datetime.d.ts.map +1 -1
- package/dist/src/expr/datetime.js +184 -34
- package/dist/src/expr/datetime.js.map +1 -1
- package/dist/src/expr/dict.d.ts +47 -2
- package/dist/src/expr/dict.d.ts.map +1 -1
- package/dist/src/expr/dict.js +122 -61
- package/dist/src/expr/dict.js.map +1 -1
- package/dist/src/expr/expr.d.ts +3 -1
- package/dist/src/expr/expr.d.ts.map +1 -1
- package/dist/src/expr/expr.js +4 -3
- package/dist/src/expr/expr.js.map +1 -1
- package/dist/src/expr/float.d.ts +153 -0
- package/dist/src/expr/float.d.ts.map +1 -1
- package/dist/src/expr/float.js +191 -17
- package/dist/src/expr/float.js.map +1 -1
- package/dist/src/expr/function.d.ts +7 -2
- package/dist/src/expr/function.d.ts.map +1 -1
- package/dist/src/expr/function.js +6 -4
- package/dist/src/expr/function.js.map +1 -1
- package/dist/src/expr/index.d.ts +186 -2
- package/dist/src/expr/index.d.ts.map +1 -1
- package/dist/src/expr/index.js +183 -2
- package/dist/src/expr/index.js.map +1 -1
- package/dist/src/expr/integer.d.ts +180 -0
- package/dist/src/expr/integer.d.ts.map +1 -1
- package/dist/src/expr/integer.js +189 -18
- package/dist/src/expr/integer.js.map +1 -1
- package/dist/src/expr/libs/array.js +3 -3
- package/dist/src/expr/libs/array.js.map +1 -1
- package/dist/src/expr/libs/blob.js +3 -3
- package/dist/src/expr/libs/blob.js.map +1 -1
- package/dist/src/expr/libs/dict.js +1 -1
- package/dist/src/expr/libs/dict.js.map +1 -1
- package/dist/src/expr/libs/matrix.d.ts +17 -0
- package/dist/src/expr/libs/matrix.d.ts.map +1 -0
- package/dist/src/expr/libs/matrix.js +60 -0
- package/dist/src/expr/libs/matrix.js.map +1 -0
- package/dist/src/expr/libs/set.js +1 -1
- package/dist/src/expr/libs/set.js.map +1 -1
- package/dist/src/expr/libs/string.d.ts.map +1 -1
- package/dist/src/expr/libs/string.js +2 -1
- package/dist/src/expr/libs/string.js.map +1 -1
- package/dist/src/expr/libs/vector.d.ts +16 -0
- package/dist/src/expr/libs/vector.d.ts.map +1 -0
- package/dist/src/expr/libs/vector.js +44 -0
- package/dist/src/expr/libs/vector.js.map +1 -0
- package/dist/src/expr/matrix.d.ts +109 -0
- package/dist/src/expr/matrix.d.ts.map +1 -0
- package/dist/src/expr/matrix.js +224 -0
- package/dist/src/expr/matrix.js.map +1 -0
- package/dist/src/expr/recursive.d.ts +83 -0
- package/dist/src/expr/recursive.d.ts.map +1 -0
- package/dist/src/expr/recursive.js +99 -0
- package/dist/src/expr/recursive.js.map +1 -0
- package/dist/src/expr/ref.js +5 -5
- package/dist/src/expr/ref.js.map +1 -1
- package/dist/src/expr/set.d.ts +44 -2
- package/dist/src/expr/set.d.ts.map +1 -1
- package/dist/src/expr/set.js +102 -52
- package/dist/src/expr/set.js.map +1 -1
- package/dist/src/expr/string.d.ts +134 -0
- package/dist/src/expr/string.d.ts.map +1 -1
- package/dist/src/expr/string.js +173 -23
- package/dist/src/expr/string.js.map +1 -1
- package/dist/src/expr/struct.d.ts +1 -1
- package/dist/src/expr/struct.d.ts.map +1 -1
- package/dist/src/expr/struct.js +2 -2
- package/dist/src/expr/struct.js.map +1 -1
- package/dist/src/expr/types.d.ts +12 -9
- package/dist/src/expr/types.d.ts.map +1 -1
- package/dist/src/expr/variant.d.ts +108 -11
- package/dist/src/expr/variant.d.ts.map +1 -1
- package/dist/src/expr/variant.js +76 -38
- package/dist/src/expr/variant.js.map +1 -1
- package/dist/src/expr/vector.d.ts +102 -0
- package/dist/src/expr/vector.d.ts.map +1 -0
- package/dist/src/expr/vector.js +202 -0
- package/dist/src/expr/vector.js.map +1 -0
- package/dist/src/fuzz.d.ts +36 -2
- package/dist/src/fuzz.d.ts.map +1 -1
- package/dist/src/fuzz.js +409 -77
- package/dist/src/fuzz.js.map +1 -1
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal.d.ts +12 -2
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +13 -2
- package/dist/src/internal.js.map +1 -1
- package/dist/src/ir.d.ts +1754 -1484
- package/dist/src/ir.d.ts.map +1 -1
- package/dist/src/ir.js +51 -34
- package/dist/src/ir.js.map +1 -1
- package/dist/src/ir.spec.d.ts +2 -0
- package/dist/src/ir.spec.d.ts.map +1 -0
- package/dist/src/ir.spec.js +35 -0
- package/dist/src/ir.spec.js.map +1 -0
- package/dist/src/location.d.ts +56 -17
- package/dist/src/location.d.ts.map +1 -1
- package/dist/src/location.js +226 -29
- package/dist/src/location.js.map +1 -1
- package/dist/src/location.spec.d.ts +2 -0
- package/dist/src/location.spec.d.ts.map +1 -0
- package/dist/src/location.spec.js +102 -0
- package/dist/src/location.spec.js.map +1 -0
- package/dist/src/patch/apply.d.ts +15 -0
- package/dist/src/patch/apply.d.ts.map +1 -0
- package/dist/src/patch/apply.js +352 -0
- package/dist/src/patch/apply.js.map +1 -0
- package/dist/src/patch/compose.d.ts +15 -0
- package/dist/src/patch/compose.d.ts.map +1 -0
- package/dist/src/patch/compose.js +448 -0
- package/dist/src/patch/compose.js.map +1 -0
- package/dist/src/patch/diff.d.ts +15 -0
- package/dist/src/patch/diff.d.ts.map +1 -0
- package/dist/src/patch/diff.js +347 -0
- package/dist/src/patch/diff.js.map +1 -0
- package/dist/src/patch/fuzz.d.ts +73 -0
- package/dist/src/patch/fuzz.d.ts.map +1 -0
- package/dist/src/patch/fuzz.js +159 -0
- package/dist/src/patch/fuzz.js.map +1 -0
- package/dist/src/patch/index.d.ts +32 -0
- package/dist/src/patch/index.d.ts.map +1 -0
- package/dist/src/patch/index.js +48 -0
- package/dist/src/patch/index.js.map +1 -0
- package/dist/src/patch/invert.d.ts +15 -0
- package/dist/src/patch/invert.d.ts.map +1 -0
- package/dist/src/patch/invert.js +284 -0
- package/dist/src/patch/invert.js.map +1 -0
- package/dist/src/patch/merge.d.ts +56 -0
- package/dist/src/patch/merge.d.ts.map +1 -0
- package/dist/src/patch/merge.js +586 -0
- package/dist/src/patch/merge.js.map +1 -0
- package/dist/src/patch/merge.spec.d.ts +2 -0
- package/dist/src/patch/merge.spec.d.ts.map +1 -0
- package/dist/src/patch/merge.spec.js +1139 -0
- package/dist/src/patch/merge.spec.js.map +1 -0
- package/dist/src/patch/patch.spec.d.ts +2 -0
- package/dist/src/patch/patch.spec.d.ts.map +1 -0
- package/dist/src/patch/patch.spec.js +452 -0
- package/dist/src/patch/patch.spec.js.map +1 -0
- package/dist/src/patch/path.d.ts +115 -0
- package/dist/src/patch/path.d.ts.map +1 -0
- package/dist/src/patch/path.js +192 -0
- package/dist/src/patch/path.js.map +1 -0
- package/dist/src/patch/path.spec.d.ts +6 -0
- package/dist/src/patch/path.spec.d.ts.map +1 -0
- package/dist/src/patch/path.spec.js +322 -0
- package/dist/src/patch/path.spec.js.map +1 -0
- package/dist/src/patch/prune.d.ts +77 -0
- package/dist/src/patch/prune.d.ts.map +1 -0
- package/dist/src/patch/prune.js +115 -0
- package/dist/src/patch/prune.js.map +1 -0
- package/dist/src/patch/prune.spec.d.ts +6 -0
- package/dist/src/patch/prune.spec.d.ts.map +1 -0
- package/dist/src/patch/prune.spec.js +473 -0
- package/dist/src/patch/prune.spec.js.map +1 -0
- package/dist/src/patch/type_of_patch.d.ts +25 -0
- package/dist/src/patch/type_of_patch.d.ts.map +1 -0
- package/dist/src/patch/type_of_patch.js +144 -0
- package/dist/src/patch/type_of_patch.js.map +1 -0
- package/dist/src/patch/types.d.ts +220 -0
- package/dist/src/patch/types.d.ts.map +1 -0
- package/dist/src/patch/types.js +62 -0
- package/dist/src/patch/types.js.map +1 -0
- package/dist/src/patch/validate.d.ts +44 -0
- package/dist/src/patch/validate.d.ts.map +1 -0
- package/dist/src/patch/validate.js +190 -0
- package/dist/src/patch/validate.js.map +1 -0
- package/dist/src/patch/validate.spec.d.ts +6 -0
- package/dist/src/patch/validate.spec.d.ts.map +1 -0
- package/dist/src/patch/validate.spec.js +225 -0
- package/dist/src/patch/validate.spec.js.map +1 -0
- package/dist/src/patch/walk.d.ts +121 -0
- package/dist/src/patch/walk.d.ts.map +1 -0
- package/dist/src/patch/walk.js +385 -0
- package/dist/src/patch/walk.js.map +1 -0
- package/dist/src/patch/walk.spec.d.ts +6 -0
- package/dist/src/patch/walk.spec.d.ts.map +1 -0
- package/dist/src/patch/walk.spec.js +621 -0
- package/dist/src/patch/walk.spec.js.map +1 -0
- package/dist/src/platform.d.ts +6 -0
- package/dist/src/platform.d.ts.map +1 -1
- package/dist/src/platform.spec.d.ts +2 -0
- package/dist/src/platform.spec.d.ts.map +1 -0
- package/dist/src/platform.spec.js +330 -0
- package/dist/src/platform.spec.js.map +1 -0
- package/dist/src/serialization/beast.d.ts.map +1 -1
- package/dist/src/serialization/beast.js +12 -0
- package/dist/src/serialization/beast.js.map +1 -1
- package/dist/src/serialization/beast.spec.d.ts +6 -0
- package/dist/src/serialization/beast.spec.d.ts.map +1 -0
- package/dist/src/serialization/beast.spec.js +406 -0
- package/dist/src/serialization/beast.spec.js.map +1 -0
- package/dist/src/serialization/beast2/index.d.ts +50 -0
- package/dist/src/serialization/beast2/index.d.ts.map +1 -0
- package/dist/src/serialization/beast2/index.js +756 -0
- package/dist/src/serialization/beast2/index.js.map +1 -0
- package/dist/src/serialization/beast2/index.spec.d.ts +6 -0
- package/dist/src/serialization/beast2/index.spec.d.ts.map +1 -0
- package/dist/src/serialization/beast2/index.spec.js +528 -0
- package/dist/src/serialization/beast2/index.spec.js.map +1 -0
- package/dist/src/serialization/beast2/sourcemap-table.d.ts +29 -0
- package/dist/src/serialization/beast2/sourcemap-table.d.ts.map +1 -0
- package/dist/src/serialization/beast2/sourcemap-table.js +82 -0
- package/dist/src/serialization/beast2/sourcemap-table.js.map +1 -0
- package/dist/src/serialization/beast2/string-table.d.ts +16 -0
- package/dist/src/serialization/beast2/string-table.d.ts.map +1 -0
- package/dist/src/serialization/beast2/string-table.js +38 -0
- package/dist/src/serialization/beast2/string-table.js.map +1 -0
- package/dist/src/serialization/beast2/type-table.d.ts +86 -0
- package/dist/src/serialization/beast2/type-table.d.ts.map +1 -0
- package/dist/src/serialization/beast2/type-table.js +618 -0
- package/dist/src/serialization/beast2/type-table.js.map +1 -0
- package/dist/src/serialization/beast2/value-table.d.ts +40 -0
- package/dist/src/serialization/beast2/value-table.d.ts.map +1 -0
- package/dist/src/serialization/beast2/value-table.js +157 -0
- package/dist/src/serialization/beast2/value-table.js.map +1 -0
- package/dist/src/serialization/binary-utils.d.ts +33 -0
- package/dist/src/serialization/binary-utils.d.ts.map +1 -1
- package/dist/src/serialization/binary-utils.js +157 -0
- package/dist/src/serialization/binary-utils.js.map +1 -1
- package/dist/src/serialization/csv.d.ts +17 -17
- package/dist/src/serialization/csv.d.ts.map +1 -1
- package/dist/src/serialization/csv.js +10 -8
- package/dist/src/serialization/csv.js.map +1 -1
- package/dist/src/serialization/csv.spec.d.ts +2 -0
- package/dist/src/serialization/csv.spec.d.ts.map +1 -0
- package/dist/src/serialization/csv.spec.js +556 -0
- package/dist/src/serialization/csv.spec.js.map +1 -0
- package/dist/src/serialization/east-inferred.spec.d.ts +2 -0
- package/dist/src/serialization/east-inferred.spec.d.ts.map +1 -0
- package/dist/src/serialization/east-inferred.spec.js +322 -0
- package/dist/src/serialization/east-inferred.spec.js.map +1 -0
- package/dist/src/serialization/east.d.ts +1 -1
- package/dist/src/serialization/east.d.ts.map +1 -1
- package/dist/src/serialization/east.js +178 -26
- package/dist/src/serialization/east.js.map +1 -1
- package/dist/src/serialization/east.spec.d.ts +2 -0
- package/dist/src/serialization/east.spec.d.ts.map +1 -0
- package/dist/src/serialization/east.spec.js +1548 -0
- package/dist/src/serialization/east.spec.js.map +1 -0
- package/dist/src/serialization/index.d.ts +1 -2
- package/dist/src/serialization/index.d.ts.map +1 -1
- package/dist/src/serialization/index.js +1 -2
- package/dist/src/serialization/index.js.map +1 -1
- package/dist/src/serialization/json.d.ts +1 -1
- package/dist/src/serialization/json.d.ts.map +1 -1
- package/dist/src/serialization/json.js +123 -24
- package/dist/src/serialization/json.js.map +1 -1
- package/dist/src/serialization/json.spec.d.ts +2 -0
- package/dist/src/serialization/json.spec.d.ts.map +1 -0
- package/dist/src/serialization/json.spec.js +1297 -0
- package/dist/src/serialization/json.spec.js.map +1 -0
- package/dist/src/type_of_type.d.ts +72 -35
- package/dist/src/type_of_type.d.ts.map +1 -1
- package/dist/src/type_of_type.is_data.spec.d.ts +6 -0
- package/dist/src/type_of_type.is_data.spec.d.ts.map +1 -0
- package/dist/src/type_of_type.is_data.spec.js +221 -0
- package/dist/src/type_of_type.is_data.spec.js.map +1 -0
- package/dist/src/type_of_type.js +355 -80
- package/dist/src/type_of_type.js.map +1 -1
- package/dist/src/type_of_type.to_etv.spec.d.ts +6 -0
- package/dist/src/type_of_type.to_etv.spec.d.ts.map +1 -0
- package/dist/src/type_of_type.to_etv.spec.js +263 -0
- package/dist/src/type_of_type.to_etv.spec.js.map +1 -0
- package/dist/src/types.d.ts +82 -12
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.error.spec.d.ts +2 -0
- package/dist/src/types.error.spec.d.ts.map +1 -0
- package/dist/src/types.error.spec.js +665 -0
- package/dist/src/types.error.spec.js.map +1 -0
- package/dist/src/types.js +663 -156
- package/dist/src/types.js.map +1 -1
- package/dist/src/types.spec.d.ts +2 -0
- package/dist/src/types.spec.d.ts.map +1 -0
- package/dist/src/types.spec.js +946 -0
- package/dist/src/types.spec.js.map +1 -0
- package/dist/src/walker.d.ts +65 -0
- package/dist/src/walker.d.ts.map +1 -0
- package/dist/src/walker.js +165 -0
- package/dist/src/walker.js.map +1 -0
- package/dist/src/walker.spec.d.ts +6 -0
- package/dist/src/walker.spec.d.ts.map +1 -0
- package/dist/src/walker.spec.js +109 -0
- package/dist/src/walker.spec.js.map +1 -0
- package/package.json +16 -38
- package/dist/src/serialization/beast2-stream.d.ts +0 -38
- package/dist/src/serialization/beast2-stream.d.ts.map +0 -1
- package/dist/src/serialization/beast2-stream.js +0 -670
- package/dist/src/serialization/beast2-stream.js.map +0 -1
- package/dist/src/serialization/beast2.d.ts +0 -41
- package/dist/src/serialization/beast2.d.ts.map +0 -1
- package/dist/src/serialization/beast2.js +0 -495
- package/dist/src/serialization/beast2.js.map +0 -1
package/dist/src/type_of_type.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
|
-
import { ArrayType, BlobType, BooleanType, DateTimeType, FloatType, IntegerType, NullType, printType, RecursiveType, StringType, StructType, VariantType } from "./types.js";
|
|
5
|
+
import { ArrayType, BlobType, BooleanType, DateTimeType, FloatType, IntegerType, NullType, NeverType, printType, RecursiveType, StringType, StructType, VariantType, RefType, SetType, DictType, FunctionType, AsyncFunctionType, VectorType, MatrixType, type_id_symbol, getTypeId, isPrimitiveType } from "./types.js";
|
|
6
6
|
import { isVariant, variant } from "./containers/variant.js";
|
|
7
|
-
import { equalFor } from "./comparison.js";
|
|
8
7
|
/** The type of primitive literal values in IR.
|
|
9
8
|
* Used to represent the values in ValueIR nodes.
|
|
10
9
|
*/
|
|
@@ -37,7 +36,7 @@ export const EastTypeType = RecursiveType(type => VariantType({
|
|
|
37
36
|
"Dict": StructType({ key: type, value: type }),
|
|
38
37
|
"Struct": ArrayType(StructType({ name: StringType, type: type })),
|
|
39
38
|
"Variant": ArrayType(StructType({ name: StringType, type: type })),
|
|
40
|
-
"Recursive": IntegerType,
|
|
39
|
+
"Recursive": VariantType({ ref: IntegerType, wrapper: StructType({ id: IntegerType, inner: type }) }),
|
|
41
40
|
"Function": StructType({
|
|
42
41
|
inputs: ArrayType(type),
|
|
43
42
|
output: type,
|
|
@@ -45,37 +44,47 @@ export const EastTypeType = RecursiveType(type => VariantType({
|
|
|
45
44
|
"AsyncFunction": StructType({
|
|
46
45
|
inputs: ArrayType(type),
|
|
47
46
|
output: type,
|
|
48
|
-
})
|
|
47
|
+
}),
|
|
48
|
+
"Vector": type,
|
|
49
|
+
"Matrix": type,
|
|
49
50
|
}));
|
|
50
|
-
// Cache
|
|
51
|
-
|
|
51
|
+
// Cache keyed by type_id. Only caches top-level (non-recursive-context) calls.
|
|
52
|
+
// With type interning in types.ts, structurally identical EastType objects share
|
|
53
|
+
// the same type_id, so this cache ensures identity-based dedup of EastTypeValues.
|
|
54
|
+
const toEastTypeValueCache = new Map();
|
|
52
55
|
export function toEastTypeValue(type, stack = [], is_recursive = false) {
|
|
53
56
|
if (typeof type === "string") {
|
|
54
|
-
// Used for generics (type parameters)
|
|
55
57
|
return type;
|
|
56
58
|
}
|
|
57
59
|
if (isVariant(type)) {
|
|
58
|
-
|
|
60
|
+
return type;
|
|
59
61
|
}
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
// Cache when no RecursiveType is on the stack. Inside a Recursive scope,
|
|
63
|
+
// results contain ref(id) values that must stay inside their enclosing wrapper.
|
|
64
|
+
// Outside, RecursiveTypes are fetched from cache as complete wrapper({id, inner}) values.
|
|
65
|
+
// This ensures ref(id) only appears inside wrapper inner types, never standalone.
|
|
66
|
+
const typeId = getTypeId(type);
|
|
67
|
+
const hasRecursiveOnStack = !isPrimitiveType(type) && stack.some((s) => s.type === "Recursive");
|
|
68
|
+
const canCache = typeId !== undefined && !hasRecursiveOnStack;
|
|
69
|
+
if (canCache) {
|
|
70
|
+
const cached = toEastTypeValueCache.get(typeId);
|
|
64
71
|
if (cached !== undefined)
|
|
65
72
|
return cached;
|
|
66
|
-
const result = toEastTypeValueImpl(type, stack, is_recursive);
|
|
67
|
-
toEastTypeValueCache.set(type, result);
|
|
68
|
-
return result;
|
|
69
73
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const result = toEastTypeValueImpl(type, stack, is_recursive);
|
|
75
|
+
// Always stamp the ETV with the type_id (needed for type table dedup via tidMap).
|
|
76
|
+
// Only cache the result when outside a recursive scope.
|
|
77
|
+
if (typeId !== undefined) {
|
|
78
|
+
result[type_id_symbol] = typeId;
|
|
79
|
+
}
|
|
80
|
+
if (canCache) {
|
|
81
|
+
toEastTypeValueCache.set(typeId, result);
|
|
78
82
|
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function toEastTypeValueImpl(type, stack, _is_recursive) {
|
|
86
|
+
// Note: self-reference detection for Recursive types is handled in the
|
|
87
|
+
// type.type === "Recursive" branch below (stack.indexOf check).
|
|
79
88
|
if (type.type === "Never") {
|
|
80
89
|
return variant("Never", null);
|
|
81
90
|
}
|
|
@@ -140,7 +149,16 @@ function toEastTypeValueImpl(type, stack, is_recursive) {
|
|
|
140
149
|
return ret;
|
|
141
150
|
}
|
|
142
151
|
else if (type.type === "Recursive") {
|
|
143
|
-
|
|
152
|
+
const tid = getTypeId(type);
|
|
153
|
+
// Self-reference: this RecursiveType is already on the stack.
|
|
154
|
+
if (stack.indexOf(type) !== -1) {
|
|
155
|
+
return variant("Recursive", variant("ref", BigInt(tid)));
|
|
156
|
+
}
|
|
157
|
+
// First encounter: push, recurse into inner, produce wrapper.
|
|
158
|
+
stack.push(type);
|
|
159
|
+
const inner = toEastTypeValueImpl(type.node, stack, false);
|
|
160
|
+
stack.pop();
|
|
161
|
+
return variant("Recursive", variant("wrapper", { id: BigInt(tid), inner }));
|
|
144
162
|
}
|
|
145
163
|
else if (type.type === "Function") {
|
|
146
164
|
stack.push(type);
|
|
@@ -160,11 +178,120 @@ function toEastTypeValueImpl(type, stack, is_recursive) {
|
|
|
160
178
|
stack.pop();
|
|
161
179
|
return ret;
|
|
162
180
|
}
|
|
181
|
+
else if (type.type === "Vector") {
|
|
182
|
+
stack.push(type);
|
|
183
|
+
const ret = variant("Vector", toEastTypeValue(type.element, stack, false));
|
|
184
|
+
stack.pop();
|
|
185
|
+
return ret;
|
|
186
|
+
}
|
|
187
|
+
else if (type.type === "Matrix") {
|
|
188
|
+
stack.push(type);
|
|
189
|
+
const ret = variant("Matrix", toEastTypeValue(type.element, stack, false));
|
|
190
|
+
stack.pop();
|
|
191
|
+
return ret;
|
|
192
|
+
}
|
|
163
193
|
else {
|
|
164
194
|
throw new Error(`Unknown type: ${printType(type)}`);
|
|
165
195
|
}
|
|
166
196
|
}
|
|
167
197
|
export const EastTypeValueType = toEastTypeValue(EastTypeType);
|
|
198
|
+
/**
|
|
199
|
+
* Inverse of {@link toEastTypeValue}: rebuild a static {@link EastType} from
|
|
200
|
+
* its runtime {@link EastTypeValue} variant form.
|
|
201
|
+
*
|
|
202
|
+
* @remarks
|
|
203
|
+
* Mirror of `toEastTypeValueImpl` in reverse. Used by callers who hold a
|
|
204
|
+
* runtime EastTypeValue (e.g. from a generic platform-fn impl factory) but
|
|
205
|
+
* need to invoke an EastType-only API like {@link PatchType}.
|
|
206
|
+
*
|
|
207
|
+
* Recursive types are reassembled via the `wrapper`/`ref` shape east emits:
|
|
208
|
+
* a `wrapper` carries `{id, inner}` (we recurse into `inner` and reconstruct
|
|
209
|
+
* the `RecursiveType`), and a `ref(id)` is a back-reference into an
|
|
210
|
+
* already-being-reconstructed scope.
|
|
211
|
+
*
|
|
212
|
+
* The conversion preserves type equality via east's interning: feeding the
|
|
213
|
+
* result back through {@link toEastTypeValue} produces the same identity as
|
|
214
|
+
* the input.
|
|
215
|
+
*/
|
|
216
|
+
export function fromEastTypeValue(t) {
|
|
217
|
+
const ctx = new Map();
|
|
218
|
+
return fromImpl(t, ctx);
|
|
219
|
+
}
|
|
220
|
+
function fromImpl(t, ctx) {
|
|
221
|
+
const tag = t.type;
|
|
222
|
+
if (tag === "Never")
|
|
223
|
+
return NeverType;
|
|
224
|
+
if (tag === "Null")
|
|
225
|
+
return NullType;
|
|
226
|
+
if (tag === "Boolean")
|
|
227
|
+
return BooleanType;
|
|
228
|
+
if (tag === "Integer")
|
|
229
|
+
return IntegerType;
|
|
230
|
+
if (tag === "Float")
|
|
231
|
+
return FloatType;
|
|
232
|
+
if (tag === "String")
|
|
233
|
+
return StringType;
|
|
234
|
+
if (tag === "DateTime")
|
|
235
|
+
return DateTimeType;
|
|
236
|
+
if (tag === "Blob")
|
|
237
|
+
return BlobType;
|
|
238
|
+
if (tag === "Ref")
|
|
239
|
+
return RefType(fromImpl(t.value, ctx));
|
|
240
|
+
if (tag === "Array")
|
|
241
|
+
return ArrayType(fromImpl(t.value, ctx));
|
|
242
|
+
if (tag === "Set")
|
|
243
|
+
return SetType(fromImpl(t.value, ctx));
|
|
244
|
+
if (tag === "Vector")
|
|
245
|
+
return VectorType(fromImpl(t.value, ctx));
|
|
246
|
+
if (tag === "Matrix")
|
|
247
|
+
return MatrixType(fromImpl(t.value, ctx));
|
|
248
|
+
if (tag === "Dict") {
|
|
249
|
+
const v = t.value;
|
|
250
|
+
return DictType(fromImpl(v.key, ctx), fromImpl(v.value, ctx));
|
|
251
|
+
}
|
|
252
|
+
if (tag === "Struct") {
|
|
253
|
+
const fields = t.value;
|
|
254
|
+
const obj = {};
|
|
255
|
+
for (const f of fields)
|
|
256
|
+
obj[f.name] = fromImpl(f.type, ctx);
|
|
257
|
+
return StructType(obj);
|
|
258
|
+
}
|
|
259
|
+
if (tag === "Variant") {
|
|
260
|
+
const cases = t.value;
|
|
261
|
+
const obj = {};
|
|
262
|
+
for (const c of cases)
|
|
263
|
+
obj[c.name] = fromImpl(c.type, ctx);
|
|
264
|
+
return VariantType(obj);
|
|
265
|
+
}
|
|
266
|
+
if (tag === "Function") {
|
|
267
|
+
const v = t.value;
|
|
268
|
+
return FunctionType(v.inputs.map(i => fromImpl(i, ctx)), fromImpl(v.output, ctx));
|
|
269
|
+
}
|
|
270
|
+
if (tag === "AsyncFunction") {
|
|
271
|
+
const v = t.value;
|
|
272
|
+
return AsyncFunctionType(v.inputs.map(i => fromImpl(i, ctx)), fromImpl(v.output, ctx));
|
|
273
|
+
}
|
|
274
|
+
if (tag === "Recursive") {
|
|
275
|
+
// Recursive carries either `wrapper({id, inner})` or `ref(id)`.
|
|
276
|
+
const inner = t.value;
|
|
277
|
+
if (inner.type === "ref") {
|
|
278
|
+
const id = inner.value;
|
|
279
|
+
const cached = ctx.get(id);
|
|
280
|
+
if (!cached)
|
|
281
|
+
throw new Error(`fromEastTypeValue: unresolved Recursive ref(${id})`);
|
|
282
|
+
return cached;
|
|
283
|
+
}
|
|
284
|
+
// wrapper — reconstruct the RecursiveType, registering its id in ctx
|
|
285
|
+
// before recursing so a back-ref inside the body resolves to it.
|
|
286
|
+
const w = inner.value;
|
|
287
|
+
const rec = RecursiveType(_self => {
|
|
288
|
+
ctx.set(w.id, _self);
|
|
289
|
+
return fromImpl(w.inner, ctx);
|
|
290
|
+
});
|
|
291
|
+
return rec;
|
|
292
|
+
}
|
|
293
|
+
throw new Error(`fromEastTypeValue: unhandled tag "${tag}"`);
|
|
294
|
+
}
|
|
168
295
|
/**
|
|
169
296
|
* Compares two EastTypeValue instances for type equality.
|
|
170
297
|
*
|
|
@@ -175,28 +302,146 @@ export const EastTypeValueType = toEastTypeValue(EastTypeType);
|
|
|
175
302
|
* @remarks
|
|
176
303
|
* This is the {@link EastTypeValue} version of {@link isTypeEqual}.
|
|
177
304
|
*/
|
|
178
|
-
const
|
|
179
|
-
|
|
305
|
+
const isTypeValueEqualCache = new Map();
|
|
306
|
+
/**
|
|
307
|
+
* Check structural equality of two EastTypeValues.
|
|
308
|
+
* Handles Recursive ref/wrapper equivalence: ref(N) and wrapper({id=N, inner})
|
|
309
|
+
* denote the same recursive type when N matches.
|
|
310
|
+
*/
|
|
180
311
|
export function isTypeValueEqual(t1, t2) {
|
|
181
312
|
// Fast path: reference equality
|
|
182
313
|
if (t1 === t2)
|
|
183
314
|
return true;
|
|
315
|
+
// Fast path: type_id equality
|
|
316
|
+
const tid1 = getTypeId(t1);
|
|
317
|
+
const tid2 = getTypeId(t2);
|
|
318
|
+
if (tid1 !== undefined && tid1 === tid2)
|
|
319
|
+
return true;
|
|
320
|
+
// Recursive ref/wrapper equivalence: ref(N) and wrapper({id=N, inner})
|
|
321
|
+
// denote the same recursive type when ids match.
|
|
322
|
+
if (t1.type === "Recursive" && t2.type === "Recursive") {
|
|
323
|
+
const v1 = t1.value;
|
|
324
|
+
const v2 = t2.value;
|
|
325
|
+
const id1 = v1.type === "ref" ? v1.value : v1.type === "wrapper" ? v1.value.id : undefined;
|
|
326
|
+
const id2 = v2.type === "ref" ? v2.value : v2.type === "wrapper" ? v2.value.id : undefined;
|
|
327
|
+
if (id1 !== undefined && id2 !== undefined && id1 === id2)
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
184
330
|
// Check cache
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
331
|
+
if (tid1 !== undefined && tid2 !== undefined) {
|
|
332
|
+
const innerCache = isTypeValueEqualCache.get(tid1);
|
|
333
|
+
if (innerCache) {
|
|
334
|
+
const cached = innerCache.get(tid2);
|
|
335
|
+
if (cached !== undefined)
|
|
336
|
+
return cached;
|
|
337
|
+
}
|
|
338
|
+
const result = isTypeValueEqualImpl(t1, t2);
|
|
339
|
+
let cache = isTypeValueEqualCache.get(tid1);
|
|
340
|
+
if (!cache) {
|
|
341
|
+
cache = new Map();
|
|
342
|
+
isTypeValueEqualCache.set(tid1, cache);
|
|
343
|
+
}
|
|
344
|
+
cache.set(tid2, result);
|
|
345
|
+
return result;
|
|
190
346
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
347
|
+
return isTypeValueEqualImpl(t1, t2);
|
|
348
|
+
}
|
|
349
|
+
/** Structural comparison that uses isTypeValueEqual for children (handles ref/wrapper). */
|
|
350
|
+
function isTypeValueEqualImpl(t1, t2) {
|
|
351
|
+
if (t1.type !== t2.type)
|
|
352
|
+
return false;
|
|
353
|
+
switch (t1.type) {
|
|
354
|
+
case "Never":
|
|
355
|
+
case "Null":
|
|
356
|
+
case "Boolean":
|
|
357
|
+
case "Integer":
|
|
358
|
+
case "Float":
|
|
359
|
+
case "String":
|
|
360
|
+
case "DateTime":
|
|
361
|
+
case "Blob":
|
|
362
|
+
return true;
|
|
363
|
+
case "Ref":
|
|
364
|
+
case "Array":
|
|
365
|
+
case "Vector":
|
|
366
|
+
case "Matrix":
|
|
367
|
+
return isTypeValueEqual(t1.value, t2.value);
|
|
368
|
+
case "Set":
|
|
369
|
+
return isTypeValueEqual(t1.value, t2.value);
|
|
370
|
+
case "Dict":
|
|
371
|
+
return isTypeValueEqual(t1.value.key, t2.value.key) &&
|
|
372
|
+
isTypeValueEqual(t1.value.value, t2.value.value);
|
|
373
|
+
case "Struct": {
|
|
374
|
+
const f1 = t1.value;
|
|
375
|
+
const f2 = t2.value;
|
|
376
|
+
if (f1.length !== f2.length)
|
|
377
|
+
return false;
|
|
378
|
+
for (let i = 0; i < f1.length; i++) {
|
|
379
|
+
if (f1[i].name !== f2[i].name)
|
|
380
|
+
return false;
|
|
381
|
+
if (!isTypeValueEqual(f1[i].type, f2[i].type))
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
case "Variant": {
|
|
387
|
+
const c1 = t1.value;
|
|
388
|
+
const c2 = t2.value;
|
|
389
|
+
if (c1.length !== c2.length)
|
|
390
|
+
return false;
|
|
391
|
+
for (let i = 0; i < c1.length; i++) {
|
|
392
|
+
if (c1[i].name !== c2[i].name)
|
|
393
|
+
return false;
|
|
394
|
+
if (!isTypeValueEqual(c1[i].type, c2[i].type))
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
case "Function":
|
|
400
|
+
case "AsyncFunction": {
|
|
401
|
+
const fn1 = t1.value;
|
|
402
|
+
const fn2 = t2.value;
|
|
403
|
+
if (fn1.inputs.length !== fn2.inputs.length)
|
|
404
|
+
return false;
|
|
405
|
+
for (let i = 0; i < fn1.inputs.length; i++) {
|
|
406
|
+
if (!isTypeValueEqual(fn1.inputs[i], fn2.inputs[i]))
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
return isTypeValueEqual(fn1.output, fn2.output);
|
|
410
|
+
}
|
|
411
|
+
case "Recursive": {
|
|
412
|
+
const v1 = t1.value;
|
|
413
|
+
const v2 = t2.value;
|
|
414
|
+
const id1 = v1.type === "ref" ? v1.value : v1.type === "wrapper" ? v1.value.id : undefined;
|
|
415
|
+
const id2 = v2.type === "ref" ? v2.value : v2.type === "wrapper" ? v2.value.id : undefined;
|
|
416
|
+
// Same id → same recursive type (fast path, works within one process)
|
|
417
|
+
if (id1 !== undefined && id2 !== undefined && id1 === id2)
|
|
418
|
+
return true;
|
|
419
|
+
// Both refs with different ids → different recursive scopes
|
|
420
|
+
if (v1.type === "ref" && v2.type === "ref")
|
|
421
|
+
return false;
|
|
422
|
+
// Both wrappers with different ids: structural comparison (alpha-equivalence).
|
|
423
|
+
// Types from different processes have different ids for the same structure.
|
|
424
|
+
// Pre-seed cache so inner ref(id1) ≡ ref(id2) during recursion.
|
|
425
|
+
if (v1.type === "wrapper" && v2.type === "wrapper") {
|
|
426
|
+
const refT1 = { type: "Recursive", value: { type: "ref", value: id1 } };
|
|
427
|
+
const refT2 = { type: "Recursive", value: { type: "ref", value: id2 } };
|
|
428
|
+
const refTid1 = getTypeId(refT1);
|
|
429
|
+
const refTid2 = getTypeId(refT2);
|
|
430
|
+
if (refTid1 !== undefined && refTid2 !== undefined) {
|
|
431
|
+
let c = isTypeValueEqualCache.get(refTid1);
|
|
432
|
+
if (!c) {
|
|
433
|
+
c = new Map();
|
|
434
|
+
isTypeValueEqualCache.set(refTid1, c);
|
|
435
|
+
}
|
|
436
|
+
c.set(refTid2, true);
|
|
437
|
+
}
|
|
438
|
+
return isTypeValueEqual(v1.value.inner, v2.value.inner);
|
|
439
|
+
}
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
default:
|
|
443
|
+
return false;
|
|
197
444
|
}
|
|
198
|
-
cache.set(t2, result);
|
|
199
|
-
return result;
|
|
200
445
|
}
|
|
201
446
|
/**
|
|
202
447
|
* Checks if one EastTypeValue is a subtype of another.
|
|
@@ -216,7 +461,7 @@ export function isTypeValueEqual(t1, t2) {
|
|
|
216
461
|
* - {@link FunctionType} and {@link AsyncFunctionType} use contravariant inputs and covariant outputs (and FunctionType is a subtype of AsyncFunctionType if their signatures match)
|
|
217
462
|
*/
|
|
218
463
|
// Cache for memoizing isSubtypeValue results (top-level calls only)
|
|
219
|
-
const isSubtypeValueCache = new
|
|
464
|
+
const isSubtypeValueCache = new Map();
|
|
220
465
|
export function isSubtypeValue(t1, t2, stack1 = [], stack2 = []) {
|
|
221
466
|
// Handle string type parameters (used for generics)
|
|
222
467
|
if (typeof t1 === "string" || typeof t2 === "string") {
|
|
@@ -225,54 +470,57 @@ export function isSubtypeValue(t1, t2, stack1 = [], stack2 = []) {
|
|
|
225
470
|
// Fast path: reference equality (reflexivity - every type is subtype of itself)
|
|
226
471
|
if (t1 === t2)
|
|
227
472
|
return true;
|
|
473
|
+
// Fast path: type_id equality
|
|
474
|
+
const tid1 = getTypeId(t1);
|
|
475
|
+
const tid2 = getTypeId(t2);
|
|
476
|
+
if (tid1 !== undefined && tid1 === tid2)
|
|
477
|
+
return true;
|
|
228
478
|
// Memoization for top-level calls (empty stacks)
|
|
229
479
|
const isTopLevel = stack1.length === 0 && stack2.length === 0;
|
|
230
|
-
if (isTopLevel) {
|
|
231
|
-
const innerCache = isSubtypeValueCache.get(
|
|
480
|
+
if (isTopLevel && tid1 !== undefined && tid2 !== undefined) {
|
|
481
|
+
const innerCache = isSubtypeValueCache.get(tid1);
|
|
232
482
|
if (innerCache) {
|
|
233
|
-
const cached = innerCache.get(
|
|
483
|
+
const cached = innerCache.get(tid2);
|
|
234
484
|
if (cached !== undefined)
|
|
235
485
|
return cached;
|
|
236
486
|
}
|
|
237
487
|
const result = isSubtypeValueImpl(t1, t2, stack1, stack2);
|
|
238
|
-
|
|
239
|
-
let cache = isSubtypeValueCache.get(t1);
|
|
488
|
+
let cache = isSubtypeValueCache.get(tid1);
|
|
240
489
|
if (!cache) {
|
|
241
|
-
cache = new
|
|
242
|
-
isSubtypeValueCache.set(
|
|
490
|
+
cache = new Map();
|
|
491
|
+
isSubtypeValueCache.set(tid1, cache);
|
|
243
492
|
}
|
|
244
|
-
cache.set(
|
|
493
|
+
cache.set(tid2, result);
|
|
245
494
|
return result;
|
|
246
495
|
}
|
|
247
496
|
return isSubtypeValueImpl(t1, t2, stack1, stack2);
|
|
248
497
|
}
|
|
249
498
|
function isSubtypeValueImpl(t1, t2, stack1, stack2) {
|
|
250
|
-
//
|
|
251
|
-
if (t1.type === "Recursive") {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
499
|
+
// Recursive wrappers: push inner to context map, recurse into inner type
|
|
500
|
+
if (t1.type === "Recursive" && t1.value.type === "wrapper") {
|
|
501
|
+
stack1.push(t1);
|
|
502
|
+
const result = isSubtypeValueImpl(t1.value.value.inner, t2, stack1, stack2);
|
|
503
|
+
stack1.pop();
|
|
504
|
+
return result;
|
|
505
|
+
}
|
|
506
|
+
if (t2.type === "Recursive" && t2.value.type === "wrapper") {
|
|
507
|
+
stack2.push(t2);
|
|
508
|
+
const result = isSubtypeValueImpl(t1, t2.value.value.inner, stack1, stack2);
|
|
509
|
+
stack2.pop();
|
|
510
|
+
return result;
|
|
511
|
+
}
|
|
512
|
+
// Equi-recursive type subtyping for self-references (id-based)
|
|
513
|
+
if (t1.type === "Recursive" && t1.value.type === "ref") {
|
|
514
|
+
if (t2.type === "Recursive" && t2.value.type === "ref") {
|
|
515
|
+
// Both are refs — they're equal if they reference the same type_id
|
|
516
|
+
return t1.value.value === t2.value.value;
|
|
263
517
|
}
|
|
264
518
|
else {
|
|
265
|
-
// Recursive cannot fit in non-recursive (infinite cannot fit in finite)
|
|
266
519
|
return false;
|
|
267
520
|
}
|
|
268
521
|
}
|
|
269
|
-
else if (t2.type === "Recursive") {
|
|
270
|
-
|
|
271
|
-
const r2 = stack2[stack2.length - Number(t2.value)];
|
|
272
|
-
if (r2 === undefined) {
|
|
273
|
-
throw new Error(`Invalid Recursive type reference: ${t2.value} at depth ${stack2.length}`);
|
|
274
|
-
}
|
|
275
|
-
return isSubtypeValue(t1, r2, stack1, stack2.slice(0, stack2.length - Number(t2.value)));
|
|
522
|
+
else if (t2.type === "Recursive" && t2.value.type === "ref") {
|
|
523
|
+
return false;
|
|
276
524
|
}
|
|
277
525
|
// Never is subtype of everything
|
|
278
526
|
if (t1.type === "Never") {
|
|
@@ -301,6 +549,14 @@ function isSubtypeValueImpl(t1, t2, stack1, stack2) {
|
|
|
301
549
|
if (t1.type === "Array" && t2.type === "Array") {
|
|
302
550
|
return isTypeValueEqual(t1.value, t2.value);
|
|
303
551
|
}
|
|
552
|
+
// Vector type - invariant (mutable)
|
|
553
|
+
if (t1.type === "Vector" && t2.type === "Vector") {
|
|
554
|
+
return isTypeValueEqual(t1.value, t2.value);
|
|
555
|
+
}
|
|
556
|
+
// Matrix type - invariant (mutable)
|
|
557
|
+
if (t1.type === "Matrix" && t2.type === "Matrix") {
|
|
558
|
+
return isTypeValueEqual(t1.value, t2.value);
|
|
559
|
+
}
|
|
304
560
|
// Set type - invariant (mutable)
|
|
305
561
|
if (t1.type === "Set" && t2.type === "Set") {
|
|
306
562
|
return isTypeValueEqual(t1.value, t2.value);
|
|
@@ -405,24 +661,28 @@ function isSubtypeValueImpl(t1, t2, stack1, stack2) {
|
|
|
405
661
|
return false;
|
|
406
662
|
}
|
|
407
663
|
// Cache for memoizing expandTypeValue results (top-level calls only)
|
|
408
|
-
const expandTypeValueCache = new
|
|
664
|
+
const expandTypeValueCache = new Map();
|
|
409
665
|
/** Expand recursive types one level deeper, if necessary */
|
|
410
666
|
export function expandTypeValue(type, root = type, depth = 0n) {
|
|
411
667
|
// Fast path: primitive types cannot contain recursive references
|
|
412
668
|
if (type.type === "Never" || type.type === "Null" || type.type === "Boolean" ||
|
|
413
669
|
type.type === "Integer" || type.type === "Float" || type.type === "String" ||
|
|
414
|
-
type.type === "DateTime" || type.type === "Blob"
|
|
670
|
+
type.type === "DateTime" || type.type === "Blob" ||
|
|
671
|
+
type.type === "Vector" || type.type === "Matrix") {
|
|
415
672
|
return type;
|
|
416
673
|
}
|
|
417
674
|
// Memoization for top-level calls
|
|
418
675
|
const isTopLevel = root === type && depth === 0n;
|
|
419
676
|
if (isTopLevel) {
|
|
420
|
-
const
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
677
|
+
const tid = getTypeId(type);
|
|
678
|
+
if (tid !== undefined) {
|
|
679
|
+
const cached = expandTypeValueCache.get(tid);
|
|
680
|
+
if (cached !== undefined)
|
|
681
|
+
return cached;
|
|
682
|
+
const result = expandTypeValueImpl(type, root, depth);
|
|
683
|
+
expandTypeValueCache.set(tid, result);
|
|
684
|
+
return result;
|
|
685
|
+
}
|
|
426
686
|
}
|
|
427
687
|
return expandTypeValueImpl(type, root, depth);
|
|
428
688
|
}
|
|
@@ -433,6 +693,12 @@ function expandTypeValueImpl(type, root, depth) {
|
|
|
433
693
|
else if (type.type === "Array") {
|
|
434
694
|
return variant("Array", expandTypeValue(type.value, root, depth + 1n));
|
|
435
695
|
}
|
|
696
|
+
else if (type.type === "Vector") {
|
|
697
|
+
return variant("Vector", expandTypeValue(type.value, root, depth + 1n));
|
|
698
|
+
}
|
|
699
|
+
else if (type.type === "Matrix") {
|
|
700
|
+
return variant("Matrix", expandTypeValue(type.value, root, depth + 1n));
|
|
701
|
+
}
|
|
436
702
|
else if (type.type === "Dict") {
|
|
437
703
|
return variant("Dict", {
|
|
438
704
|
key: type.value.key,
|
|
@@ -463,10 +729,14 @@ function expandTypeValueImpl(type, root, depth) {
|
|
|
463
729
|
output: expandTypeValue(type.value.output, root, depth + 1n),
|
|
464
730
|
});
|
|
465
731
|
}
|
|
466
|
-
else if (type.type === "Recursive" && depth === type.value) {
|
|
467
|
-
// Unfold once
|
|
732
|
+
else if (type.type === "Recursive" && type.value.type === "ref" && depth === type.value.value) {
|
|
733
|
+
// Unfold once (self-reference at matching depth)
|
|
468
734
|
return root;
|
|
469
735
|
}
|
|
736
|
+
else if (type.type === "Recursive" && type.value.type === "wrapper") {
|
|
737
|
+
// Recursive wrapper: expand the inner type
|
|
738
|
+
return variant("Recursive", variant("wrapper", { id: type.value.value.id, inner: expandTypeValue(type.value.value.inner, root, depth) }));
|
|
739
|
+
}
|
|
470
740
|
else {
|
|
471
741
|
return type;
|
|
472
742
|
}
|
|
@@ -486,7 +756,9 @@ export function isDataTypeValue(type, depth = 0) {
|
|
|
486
756
|
// checked this type in the current path, so it's safe (would have returned
|
|
487
757
|
// false already if it contained functions)
|
|
488
758
|
if (type.type === "Recursive") {
|
|
489
|
-
|
|
759
|
+
if (type.value.type === "wrapper")
|
|
760
|
+
return isDataTypeValue(type.value.value.inner, depth);
|
|
761
|
+
return true; // Self-reference — already checked in current path
|
|
490
762
|
}
|
|
491
763
|
// Function types are not data types
|
|
492
764
|
if (type.type === "Function" || type.type === "AsyncFunction") {
|
|
@@ -505,6 +777,9 @@ export function isDataTypeValue(type, depth = 0) {
|
|
|
505
777
|
if (type.type === "Array") {
|
|
506
778
|
return isDataTypeValue(type.value, depth + 1);
|
|
507
779
|
}
|
|
780
|
+
if (type.type === "Vector" || type.type === "Matrix") {
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
508
783
|
if (type.type === "Set") {
|
|
509
784
|
// Set keys are checked at construction time to be immutable data types
|
|
510
785
|
return true;
|