@aster-cloud/aster-lang-ts 1.5.0 → 2.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/CHANGELOG.md +48 -0
- package/dist/scripts/aster.js +5 -12
- package/dist/scripts/aster.js.map +1 -1
- package/dist/scripts/emit-classfiles.js +3 -1
- package/dist/scripts/emit-classfiles.js.map +1 -1
- package/dist/scripts/generate-core-ir-types.d.ts +16 -0
- package/dist/scripts/generate-core-ir-types.d.ts.map +1 -0
- package/dist/scripts/generate-core-ir-types.js +116 -0
- package/dist/scripts/generate-core-ir-types.js.map +1 -0
- package/dist/scripts/golden.js +1 -1
- package/dist/scripts/golden.js.map +1 -1
- package/dist/src/ast/ast_visitor.d.ts +27 -27
- package/dist/src/ast/ast_visitor.d.ts.map +1 -1
- package/dist/src/ast/ast_visitor.js.map +1 -1
- package/dist/src/browser.d.ts +7 -0
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +6 -1
- package/dist/src/browser.js.map +1 -1
- package/dist/src/cli/policy-converter.js +6 -10
- package/dist/src/cli/policy-converter.js.map +1 -1
- package/dist/src/cli/utils/core-ir-file.d.ts +8 -0
- package/dist/src/cli/utils/core-ir-file.d.ts.map +1 -0
- package/dist/src/cli/utils/core-ir-file.js +29 -0
- package/dist/src/cli/utils/core-ir-file.js.map +1 -0
- package/dist/src/cnl-printer.d.ts.map +1 -1
- package/dist/src/cnl-printer.js +13 -3
- package/dist/src/cnl-printer.js.map +1 -1
- package/dist/src/compile-pipeline.js +1 -1
- package/dist/src/compile-pipeline.js.map +1 -1
- package/dist/src/config/lexicons/diagnostic-overlays.generated.d.ts.map +1 -1
- package/dist/src/config/lexicons/diagnostic-overlays.generated.js +18 -6
- package/dist/src/config/lexicons/diagnostic-overlays.generated.js.map +1 -1
- package/dist/src/core/canonical-decimal.d.ts +3 -0
- package/dist/src/core/canonical-decimal.d.ts.map +1 -0
- package/dist/src/core/canonical-decimal.js +19 -0
- package/dist/src/core/canonical-decimal.js.map +1 -0
- package/dist/src/core/canonical-json.d.ts +59 -0
- package/dist/src/core/canonical-json.d.ts.map +1 -0
- package/dist/src/core/canonical-json.js +250 -0
- package/dist/src/core/canonical-json.js.map +1 -0
- package/dist/src/core/core-ir-v2.generated.d.ts +807 -0
- package/dist/src/core/core-ir-v2.generated.d.ts.map +1 -0
- package/dist/src/core/core-ir-v2.generated.js +6 -0
- package/dist/src/core/core-ir-v2.generated.js.map +1 -0
- package/dist/src/core/core-ir-v2.schema.generated.d.ts +6 -0
- package/dist/src/core/core-ir-v2.schema.generated.d.ts.map +1 -0
- package/dist/src/core/core-ir-v2.schema.generated.js +2636 -0
- package/dist/src/core/core-ir-v2.schema.generated.js.map +1 -0
- package/dist/src/core/core_ir.d.ts +27 -11
- package/dist/src/core/core_ir.d.ts.map +1 -1
- package/dist/src/core/core_ir.js +118 -63
- package/dist/src/core/core_ir.js.map +1 -1
- package/dist/src/core/index.d.ts +4 -3
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +3 -2
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/inferred_fields.d.ts +9 -11
- package/dist/src/core/inferred_fields.d.ts.map +1 -1
- package/dist/src/core/inferred_fields.js +7 -28
- package/dist/src/core/inferred_fields.js.map +1 -1
- package/dist/src/core/interpreter.js +16 -35
- package/dist/src/core/interpreter.js.map +1 -1
- package/dist/src/core/pretty_core.d.ts.map +1 -1
- package/dist/src/core/pretty_core.js +6 -10
- package/dist/src/core/pretty_core.js.map +1 -1
- package/dist/src/core/read-core-ir.d.ts +15 -0
- package/dist/src/core/read-core-ir.d.ts.map +1 -0
- package/dist/src/core/read-core-ir.js +69 -0
- package/dist/src/core/read-core-ir.js.map +1 -0
- package/dist/src/core/resolution-mark.d.ts +3 -4
- package/dist/src/core/resolution-mark.d.ts.map +1 -1
- package/dist/src/core/resolution-mark.js +2 -3
- package/dist/src/core/resolution-mark.js.map +1 -1
- package/dist/src/core/resolve-typed-references.d.ts.map +1 -1
- package/dist/src/core/resolve-typed-references.js +11 -27
- package/dist/src/core/resolve-typed-references.js.map +1 -1
- package/dist/src/core/serialize-core-ir.d.ts +13 -0
- package/dist/src/core/serialize-core-ir.d.ts.map +1 -0
- package/dist/src/core/serialize-core-ir.js +125 -0
- package/dist/src/core/serialize-core-ir.js.map +1 -0
- package/dist/src/core/visitor.d.ts.map +1 -1
- package/dist/src/core/visitor.js +4 -1
- package/dist/src/core/visitor.js.map +1 -1
- package/dist/src/diagnostics/error_codes.d.ts +2 -0
- package/dist/src/diagnostics/error_codes.d.ts.map +1 -1
- package/dist/src/diagnostics/error_codes.js +16 -0
- package/dist/src/diagnostics/error_codes.js.map +1 -1
- package/dist/src/effects/declared-effects.d.ts +17 -0
- package/dist/src/effects/declared-effects.d.ts.map +1 -0
- package/dist/src/effects/declared-effects.js +27 -0
- package/dist/src/effects/declared-effects.js.map +1 -0
- package/dist/src/effects/effect_inference.d.ts.map +1 -1
- package/dist/src/effects/effect_inference.js +14 -10
- package/dist/src/effects/effect_inference.js.map +1 -1
- package/dist/src/effects/effect_inference_browser.d.ts.map +1 -1
- package/dist/src/effects/effect_inference_browser.js +14 -9
- package/dist/src/effects/effect_inference_browser.js.map +1 -1
- package/dist/src/frontend/keyword-translator.d.ts.map +1 -1
- package/dist/src/frontend/keyword-translator.js +3 -0
- package/dist/src/frontend/keyword-translator.js.map +1 -1
- package/dist/src/frontend/lexer.d.ts.map +1 -1
- package/dist/src/frontend/lexer.js +7 -3
- package/dist/src/frontend/lexer.js.map +1 -1
- package/dist/src/frontend/resolve-declarations.d.ts.map +1 -1
- package/dist/src/frontend/resolve-declarations.js +3 -23
- package/dist/src/frontend/resolve-declarations.js.map +1 -1
- package/dist/src/governance/controls-registry.data.js +2 -2
- package/dist/src/governance/controls-registry.data.js.map +1 -1
- package/dist/src/governance/input-refs.js +5 -8
- package/dist/src/governance/input-refs.js.map +1 -1
- package/dist/src/index.d.ts +5 -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/jvm/emitter.d.ts.map +1 -1
- package/dist/src/jvm/emitter.js +20 -29
- package/dist/src/jvm/emitter.js.map +1 -1
- package/dist/src/lower_to_core.d.ts +2 -1
- package/dist/src/lower_to_core.d.ts.map +1 -1
- package/dist/src/lower_to_core.js +150 -300
- package/dist/src/lower_to_core.js.map +1 -1
- package/dist/src/lsp/pii_diagnostics.d.ts.map +1 -1
- package/dist/src/lsp/pii_diagnostics.js +3 -8
- package/dist/src/lsp/pii_diagnostics.js.map +1 -1
- package/dist/src/mapping/mapping-ir.d.ts +3 -3
- package/dist/src/mapping/mapping-ir.js +3 -3
- package/dist/src/nodeid/node-id-map.d.ts +6 -15
- package/dist/src/nodeid/node-id-map.d.ts.map +1 -1
- package/dist/src/nodeid/node-id-map.js +6 -15
- package/dist/src/nodeid/node-id-map.js.map +1 -1
- package/dist/src/parser/constraint-parser.js +25 -6
- package/dist/src/parser/constraint-parser.js.map +1 -1
- package/dist/src/parser/decl-parser.d.ts.map +1 -1
- package/dist/src/parser/decl-parser.js +30 -59
- package/dist/src/parser/decl-parser.js.map +1 -1
- package/dist/src/parser/expr-stmt-parser.d.ts.map +1 -1
- package/dist/src/parser/expr-stmt-parser.js +3 -2
- package/dist/src/parser/expr-stmt-parser.js.map +1 -1
- package/dist/src/parser/field-variant-parser.d.ts.map +1 -1
- package/dist/src/parser/field-variant-parser.js +6 -0
- package/dist/src/parser/field-variant-parser.js.map +1 -1
- package/dist/src/parser/parse-issue.d.ts +2 -0
- package/dist/src/parser/parse-issue.d.ts.map +1 -1
- package/dist/src/parser/parse-issue.js +2 -0
- package/dist/src/parser/parse-issue.js.map +1 -1
- package/dist/src/parser/type-parser.d.ts +1 -1
- package/dist/src/parser/type-parser.d.ts.map +1 -1
- package/dist/src/parser/type-parser.js +19 -2
- package/dist/src/parser/type-parser.js.map +1 -1
- package/dist/src/stability/stability_gate.d.ts +1 -1
- package/dist/src/stability/stability_gate.d.ts.map +1 -1
- package/dist/src/stability/stability_gate.js +2 -26
- package/dist/src/stability/stability_gate.js.map +1 -1
- package/dist/src/typecheck/async.d.ts.map +1 -1
- package/dist/src/typecheck/async.js +4 -1
- package/dist/src/typecheck/async.js.map +1 -1
- package/dist/src/typecheck/browser.d.ts.map +1 -1
- package/dist/src/typecheck/browser.js +4 -3
- package/dist/src/typecheck/browser.js.map +1 -1
- package/dist/src/typecheck/capabilities.d.ts.map +1 -1
- package/dist/src/typecheck/capabilities.js +3 -2
- package/dist/src/typecheck/capabilities.js.map +1 -1
- package/dist/src/typecheck/context.d.ts +5 -5
- package/dist/src/typecheck/context.d.ts.map +1 -1
- package/dist/src/typecheck/context.js.map +1 -1
- package/dist/src/typecheck/diagnostics.d.ts +2 -2
- package/dist/src/typecheck/diagnostics.d.ts.map +1 -1
- package/dist/src/typecheck/diagnostics.js.map +1 -1
- package/dist/src/typecheck/effects.js +7 -7
- package/dist/src/typecheck/effects.js.map +1 -1
- package/dist/src/typecheck/expression.d.ts +4 -4
- package/dist/src/typecheck/expression.d.ts.map +1 -1
- package/dist/src/typecheck/expression.js +1 -1
- package/dist/src/typecheck/expression.js.map +1 -1
- package/dist/src/typecheck/generics.d.ts +2 -2
- package/dist/src/typecheck/generics.d.ts.map +1 -1
- package/dist/src/typecheck/generics.js +23 -12
- package/dist/src/typecheck/generics.js.map +1 -1
- package/dist/src/typecheck/governance.d.ts +1 -1
- package/dist/src/typecheck/governance.d.ts.map +1 -1
- package/dist/src/typecheck/governance.js +1 -1
- package/dist/src/typecheck/governance.js.map +1 -1
- package/dist/src/typecheck/module.d.ts.map +1 -1
- package/dist/src/typecheck/module.js +7 -6
- package/dist/src/typecheck/module.js.map +1 -1
- package/dist/src/typecheck/pattern.d.ts +2 -2
- package/dist/src/typecheck/pattern.d.ts.map +1 -1
- package/dist/src/typecheck/pattern.js +12 -46
- package/dist/src/typecheck/pattern.js.map +1 -1
- package/dist/src/typecheck/pure.d.ts +19 -19
- package/dist/src/typecheck/pure.d.ts.map +1 -1
- package/dist/src/typecheck/pure.js.map +1 -1
- package/dist/src/typecheck/statement.d.ts +6 -6
- package/dist/src/typecheck/statement.d.ts.map +1 -1
- package/dist/src/typecheck/statement.js +17 -20
- package/dist/src/typecheck/statement.js.map +1 -1
- package/dist/src/typecheck/symbol_table.d.ts +2 -2
- package/dist/src/typecheck/symbol_table.d.ts.map +1 -1
- package/dist/src/typecheck/symbol_table.js.map +1 -1
- package/dist/src/typecheck/type_system.d.ts +4 -4
- package/dist/src/typecheck/type_system.d.ts.map +1 -1
- package/dist/src/typecheck/type_system.js +1 -1
- package/dist/src/typecheck/type_system.js.map +1 -1
- package/dist/src/typecheck/workflow.d.ts +3 -3
- package/dist/src/typecheck/workflow.d.ts.map +1 -1
- package/dist/src/typecheck/workflow.js.map +1 -1
- package/dist/src/typecheck-pii.d.ts.map +1 -1
- package/dist/src/typecheck-pii.js +2 -13
- package/dist/src/typecheck-pii.js.map +1 -1
- package/dist/src/types.d.ts +160 -172
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/version.d.ts +3 -3
- package/dist/src/version.js +3 -3
- package/dist/test/helpers/core-ir-v2.d.ts +5 -0
- package/dist/test/helpers/core-ir-v2.d.ts.map +1 -0
- package/dist/test/helpers/core-ir-v2.js +123 -0
- package/dist/test/helpers/core-ir-v2.js.map +1 -0
- package/dist/test/helpers/locales-core-ir.d.ts +7 -0
- package/dist/test/helpers/locales-core-ir.d.ts.map +1 -0
- package/dist/test/helpers/locales-core-ir.js +15 -0
- package/dist/test/helpers/locales-core-ir.js.map +1 -0
- package/dist/test/helpers/test-factories.d.ts +5 -5
- package/dist/test/helpers/test-factories.d.ts.map +1 -1
- package/dist/test/helpers/test-factories.js +9 -8
- package/dist/test/helpers/test-factories.js.map +1 -1
- package/dist/test/integration/pipeline/pipeline.test.js +1 -1
- package/dist/test/integration/pipeline/pipeline.test.js.map +1 -1
- package/dist/test/integration/vocabulary-resolution.test.js +1 -1
- package/dist/test/integration/vocabulary-resolution.test.js.map +1 -1
- package/dist/test/regression/type-checker-golden.test.js +1 -1
- package/dist/test/regression/type-checker-golden.test.js.map +1 -1
- package/dist/test/type-checker/pii-propagation.test.js +7 -6
- package/dist/test/type-checker/pii-propagation.test.js.map +1 -1
- package/dist/test/types/core-ir-v2.test-d.d.ts +28 -0
- package/dist/test/types/core-ir-v2.test-d.d.ts.map +1 -0
- package/dist/test/types/core-ir-v2.test-d.js +5 -0
- package/dist/test/types/core-ir-v2.test-d.js.map +1 -0
- package/dist/test/unit/browser/typecheck-browser-pii-failure.test.js +4 -3
- package/dist/test/unit/browser/typecheck-browser-pii-failure.test.js.map +1 -1
- package/dist/test/unit/canonicalizer/article-declaration-names.test.js +1 -1
- package/dist/test/unit/canonicalizer/article-declaration-names.test.js.map +1 -1
- package/dist/test/unit/canonicalizer/chinese-function-syntax.test.js +2 -1
- package/dist/test/unit/canonicalizer/chinese-function-syntax.test.js.map +1 -1
- package/dist/test/unit/core/canonical-json.test.d.ts +2 -0
- package/dist/test/unit/core/canonical-json.test.d.ts.map +1 -0
- package/dist/test/unit/core/canonical-json.test.js +38 -0
- package/dist/test/unit/core/canonical-json.test.js.map +1 -0
- package/dist/test/unit/core/caseless-pattern-name.test.js +6 -8
- package/dist/test/unit/core/caseless-pattern-name.test.js.map +1 -1
- package/dist/test/unit/core/core-ir-conformance.test.d.ts +2 -0
- package/dist/test/unit/core/core-ir-conformance.test.d.ts.map +1 -0
- package/dist/test/unit/core/core-ir-conformance.test.js +39 -0
- package/dist/test/unit/core/core-ir-conformance.test.js.map +1 -0
- package/dist/test/unit/core/core-ir-schema-parity.test.d.ts +2 -0
- package/dist/test/unit/core/core-ir-schema-parity.test.d.ts.map +1 -0
- package/dist/test/unit/core/core-ir-schema-parity.test.js +25 -0
- package/dist/test/unit/core/core-ir-schema-parity.test.js.map +1 -0
- package/dist/test/unit/core/core-ir-v2-outputs.test.d.ts +2 -0
- package/dist/test/unit/core/core-ir-v2-outputs.test.d.ts.map +1 -0
- package/dist/test/unit/core/core-ir-v2-outputs.test.js +128 -0
- package/dist/test/unit/core/core-ir-v2-outputs.test.js.map +1 -0
- package/dist/test/unit/core/read-core-ir.test.d.ts +2 -0
- package/dist/test/unit/core/read-core-ir.test.d.ts.map +1 -0
- package/dist/test/unit/core/read-core-ir.test.js +129 -0
- package/dist/test/unit/core/read-core-ir.test.js.map +1 -0
- package/dist/test/unit/core/resolve-typed-references.test.js +19 -16
- package/dist/test/unit/core/resolve-typed-references.test.js.map +1 -1
- package/dist/test/unit/diagnostics/lowering-diagnostics-parity.test.js +5 -5
- package/dist/test/unit/diagnostics/lowering-diagnostics-parity.test.js.map +1 -1
- package/dist/test/unit/diagnostics/parse-diagnostics-parity.test.js +3 -2
- package/dist/test/unit/diagnostics/parse-diagnostics-parity.test.js.map +1 -1
- package/dist/test/unit/effect/effect-inference.test.js +17 -13
- package/dist/test/unit/effect/effect-inference.test.js.map +1 -1
- package/dist/test/unit/emitter/emitter.test.js +47 -46
- package/dist/test/unit/emitter/emitter.test.js.map +1 -1
- package/dist/test/unit/formatter-corpus-roundtrip.test.js +5 -1
- package/dist/test/unit/formatter-corpus-roundtrip.test.js.map +1 -1
- package/dist/test/unit/formatter-roundtrip.test.js +5 -4
- package/dist/test/unit/formatter-roundtrip.test.js.map +1 -1
- package/dist/test/unit/frontend/resolve-declarations.test.js +13 -14
- package/dist/test/unit/frontend/resolve-declarations.test.js.map +1 -1
- package/dist/test/unit/governance/governance-check.test.js +1 -1
- package/dist/test/unit/governance/governance-check.test.js.map +1 -1
- package/dist/test/unit/governance/input-refs-parity.test.js +1 -1
- package/dist/test/unit/governance/input-refs-parity.test.js.map +1 -1
- package/dist/test/unit/governance/input-refs.test.js +2 -2
- package/dist/test/unit/governance/input-refs.test.js.map +1 -1
- package/dist/test/unit/governance/no-profile-ir-unchanged.test.js +6 -6
- package/dist/test/unit/governance/no-profile-ir-unchanged.test.js.map +1 -1
- package/dist/test/unit/governance/profile-check.test.js +14 -6
- package/dist/test/unit/governance/profile-check.test.js.map +1 -1
- package/dist/test/unit/interpreter/interpreter.test.js +23 -21
- package/dist/test/unit/interpreter/interpreter.test.js.map +1 -1
- package/dist/test/unit/interpreter/scope-writeback.test.js +28 -27
- package/dist/test/unit/interpreter/scope-writeback.test.js.map +1 -1
- package/dist/test/unit/keyword-aliases.test.js +1 -1
- package/dist/test/unit/lowering/core-ir-v2.test.d.ts +2 -0
- package/dist/test/unit/lowering/core-ir-v2.test.d.ts.map +1 -0
- package/dist/test/unit/lowering/core-ir-v2.test.js +253 -0
- package/dist/test/unit/lowering/core-ir-v2.test.js.map +1 -0
- package/dist/test/unit/lowering/lowering.test.js +19 -14
- package/dist/test/unit/lowering/lowering.test.js.map +1 -1
- package/dist/test/unit/lsp/pii-diagnostics.test.js +33 -30
- package/dist/test/unit/lsp/pii-diagnostics.test.js.map +1 -1
- package/dist/test/unit/lsp/utils.test.js +5 -4
- package/dist/test/unit/lsp/utils.test.js.map +1 -1
- package/dist/test/unit/parser/effect-unknown-name.test.js +7 -7
- package/dist/test/unit/parser/effect-unknown-name.test.js.map +1 -1
- package/dist/test/unit/parser/entry-annotations.test.js +2 -1
- package/dist/test/unit/parser/entry-annotations.test.js.map +1 -1
- package/dist/test/unit/parser/func-type.test.js +3 -3
- package/dist/test/unit/parser/func-type.test.js.map +1 -1
- package/dist/test/unit/parser/governance-sugar.test.js +4 -4
- package/dist/test/unit/parser/governance-sugar.test.js.map +1 -1
- package/dist/test/unit/parser/parser.test.js +5 -4
- package/dist/test/unit/parser/parser.test.js.map +1 -1
- package/dist/test/unit/rule-call-checks.test.js +2 -1
- package/dist/test/unit/rule-call-checks.test.js.map +1 -1
- package/dist/test/unit/typecheck/async-discipline-extended.test.js +11 -10
- package/dist/test/unit/typecheck/async-discipline-extended.test.js.map +1 -1
- package/dist/test/unit/typecheck/effect-prefix-injection.test.js +3 -2
- package/dist/test/unit/typecheck/effect-prefix-injection.test.js.map +1 -1
- package/dist/test/unit/typecheck/function-return-inference.test.js +33 -32
- package/dist/test/unit/typecheck/function-return-inference.test.js.map +1 -1
- package/dist/test/unit/typecheck/pii-cross-runtime-conformance.test.js +5 -4
- package/dist/test/unit/typecheck/pii-cross-runtime-conformance.test.js.map +1 -1
- package/dist/test/unit/typecheck/regression-fixes.test.js +110 -112
- package/dist/test/unit/typecheck/regression-fixes.test.js.map +1 -1
- package/dist/test/unit/typecheck/symbol-table.test.js +3 -2
- package/dist/test/unit/typecheck/symbol-table.test.js.map +1 -1
- package/dist/test/unit/typecheck/type-system-extended.test.js +6 -5
- package/dist/test/unit/typecheck/type-system-extended.test.js.map +1 -1
- package/dist/test/unit/typecheck/type-system.test.js +20 -19
- package/dist/test/unit/typecheck/type-system.test.js.map +1 -1
- package/dist/test/unit/typecheck/typecheck-advanced.test.js +19 -18
- package/dist/test/unit/typecheck/typecheck-advanced.test.js.map +1 -1
- package/dist/test/unit/typecheck/untyped-field-dynamic.test.js +6 -4
- package/dist/test/unit/typecheck/untyped-field-dynamic.test.js.map +1 -1
- package/dist/test/unit/version.test.js +3 -3
- package/package.json +4 -3
- package/dist/src/core/core_ir_json.d.ts +0 -62
- package/dist/src/core/core_ir_json.d.ts.map +0 -1
- package/dist/src/core/core_ir_json.js +0 -81
- package/dist/src/core/core_ir_json.js.map +0 -1
- package/dist/test/unit/core_ir_json/core_ir_json.test.d.ts +0 -2
- package/dist/test/unit/core_ir_json/core_ir_json.test.d.ts.map +0 -1
- package/dist/test/unit/core_ir_json/core_ir_json.test.js +0 -218
- package/dist/test/unit/core_ir_json/core_ir_json.test.js.map +0 -1
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
* - 规范化的模式匹配
|
|
17
17
|
* - 简化的效果标注
|
|
18
18
|
*/
|
|
19
|
-
import { Core } from './core/core_ir.js';
|
|
20
|
-
import {
|
|
19
|
+
import { Core as CoreIR } from './core/core_ir.js';
|
|
20
|
+
import { canonicalDecimalFromLiteral } from './core/canonical-decimal.js';
|
|
21
21
|
import { markForResolution, withResolvedOrigin } from './core/resolution-mark.js';
|
|
22
22
|
import { KEYWORD_CTORS } from './frontend/resolution-choice.js';
|
|
23
|
-
import {
|
|
23
|
+
import { inferCapabilityFromName } from './config/semantic.js';
|
|
24
24
|
import { Diagnostics } from './diagnostics/diagnostics.js';
|
|
25
25
|
import { DefaultAstVisitor } from './ast/ast_visitor.js';
|
|
26
26
|
import { DefaultCoreVisitor, createVisitorContext } from './core/visitor.js';
|
|
@@ -35,19 +35,17 @@ function extractMetadata(node) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @param astNode - AST 节点(用于提取元数据)
|
|
42
|
-
* @returns 附加了元数据的 Core IR 节点
|
|
38
|
+
* 把 AST 节点的源码位置挂到 Core IR 节点上(ADR 0055 #17:每个带 kind 的节点都必带 origin)。
|
|
39
|
+
* AST 节点没有 span 时依次尝试 fallback(例如推断类型用其形参 / 函数的位置);都没有时保留
|
|
40
|
+
* 构造时的 NO_ORIGIN,由 every_node_has_origin 测试兜底发现。
|
|
43
41
|
*/
|
|
44
|
-
function withOrigin(coreNode, astNode) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
function withOrigin(coreNode, astNode, ...fallback) {
|
|
43
|
+
for (const source of [astNode, ...fallback]) {
|
|
44
|
+
const { span, file } = extractMetadata(source);
|
|
45
|
+
if (span) {
|
|
46
|
+
coreNode.origin = spanToOrigin(span, file);
|
|
47
|
+
return coreNode;
|
|
48
|
+
}
|
|
51
49
|
}
|
|
52
50
|
return coreNode;
|
|
53
51
|
}
|
|
@@ -59,134 +57,64 @@ function canonicalOf(name, resolved) {
|
|
|
59
57
|
}
|
|
60
58
|
/**
|
|
61
59
|
* 在已附加的 origin 上记录 R1 的原写法与角色(仅 written !== canonical 时)。
|
|
62
|
-
* 无 R1
|
|
60
|
+
* 无 R1 结果时原样返回,保证未解析的 AST 降级结果不变。
|
|
63
61
|
*/
|
|
64
62
|
function withResolution(coreNode, resolved) {
|
|
65
63
|
if (!resolved)
|
|
66
64
|
return coreNode;
|
|
67
|
-
|
|
68
|
-
if (origin && origin !== coreNode.origin) {
|
|
69
|
-
coreNode.origin = origin;
|
|
70
|
-
}
|
|
65
|
+
coreNode.origin = withResolvedOrigin(coreNode.origin, resolved.written, resolved.canonical, resolved.role);
|
|
71
66
|
return coreNode;
|
|
72
67
|
}
|
|
73
68
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @param coreFunc - Core IR Func 节点
|
|
77
|
-
* @param astFunc - AST Func 节点
|
|
78
|
-
* @returns 附加了能力元数据的 Core IR Func 节点
|
|
79
|
-
*/
|
|
80
|
-
function withEffectCaps(coreFunc, astFunc) {
|
|
81
|
-
const mutableFunc = coreFunc;
|
|
82
|
-
mutableFunc.effectCaps = [...astFunc.effectCaps];
|
|
83
|
-
mutableFunc.effectCapsExplicit = astFunc.effectCapsExplicit;
|
|
84
|
-
return coreFunc;
|
|
85
|
-
}
|
|
86
|
-
function withFuncPiiMetadata(coreFunc) {
|
|
87
|
-
const metadata = aggregateFuncPii(coreFunc);
|
|
88
|
-
if (!metadata)
|
|
89
|
-
return coreFunc;
|
|
90
|
-
const mutable = coreFunc;
|
|
91
|
-
mutable.piiLevel = metadata.level;
|
|
92
|
-
mutable.piiCategories = [...metadata.categories];
|
|
93
|
-
return coreFunc;
|
|
94
|
-
}
|
|
95
|
-
const PII_LEVEL_ORDER = { L1: 1, L2: 2, L3: 3 };
|
|
96
|
-
function aggregateFuncPii(func) {
|
|
97
|
-
let summary = null;
|
|
98
|
-
for (const param of func.params) {
|
|
99
|
-
summary = mergeFuncPiiMeta(summary, extractPiiFromType(param.type));
|
|
100
|
-
}
|
|
101
|
-
return mergeFuncPiiMeta(summary, extractPiiFromType(func.ret));
|
|
102
|
-
}
|
|
103
|
-
function extractPiiFromType(type) {
|
|
104
|
-
if (!type)
|
|
105
|
-
return null;
|
|
106
|
-
switch (type.kind) {
|
|
107
|
-
case 'PiiType': {
|
|
108
|
-
const categories = type.category ? [type.category] : [];
|
|
109
|
-
const baseMeta = extractPiiFromType(type.baseType);
|
|
110
|
-
const current = { level: type.sensitivity, categories };
|
|
111
|
-
return mergeFuncPiiMeta(current, baseMeta);
|
|
112
|
-
}
|
|
113
|
-
case 'Result':
|
|
114
|
-
return mergeFuncPiiMeta(extractPiiFromType(type.ok), extractPiiFromType(type.err));
|
|
115
|
-
case 'Maybe':
|
|
116
|
-
case 'Option':
|
|
117
|
-
case 'List':
|
|
118
|
-
return extractPiiFromType(type.type);
|
|
119
|
-
case 'Map':
|
|
120
|
-
return mergeFuncPiiMeta(extractPiiFromType(type.key), extractPiiFromType(type.val));
|
|
121
|
-
case 'FuncType': {
|
|
122
|
-
let meta = null;
|
|
123
|
-
for (const param of type.params ?? []) {
|
|
124
|
-
meta = mergeFuncPiiMeta(meta, extractPiiFromType(param));
|
|
125
|
-
}
|
|
126
|
-
return mergeFuncPiiMeta(meta, extractPiiFromType(type.ret));
|
|
127
|
-
}
|
|
128
|
-
case 'TypeApp': {
|
|
129
|
-
let meta = null;
|
|
130
|
-
for (const arg of type.args ?? []) {
|
|
131
|
-
meta = mergeFuncPiiMeta(meta, extractPiiFromType(arg));
|
|
132
|
-
}
|
|
133
|
-
return meta;
|
|
134
|
-
}
|
|
135
|
-
default:
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function mergeFuncPiiMeta(left, right) {
|
|
140
|
-
if (!left)
|
|
141
|
-
return right;
|
|
142
|
-
if (!right)
|
|
143
|
-
return left;
|
|
144
|
-
return {
|
|
145
|
-
level: pickHigherPiiLevel(left.level, right.level),
|
|
146
|
-
categories: mergeCategories(left.categories, right.categories),
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function pickHigherPiiLevel(left, right) {
|
|
150
|
-
const leftRank = PII_LEVEL_ORDER[left] ?? 0;
|
|
151
|
-
const rightRank = PII_LEVEL_ORDER[right] ?? 0;
|
|
152
|
-
return leftRank >= rightRank ? left : right;
|
|
153
|
-
}
|
|
154
|
-
function mergeCategories(left, right) {
|
|
155
|
-
const seen = new Set();
|
|
156
|
-
for (const item of left) {
|
|
157
|
-
if (item)
|
|
158
|
-
seen.add(item);
|
|
159
|
-
}
|
|
160
|
-
for (const item of right) {
|
|
161
|
-
if (item)
|
|
162
|
-
seen.add(item);
|
|
163
|
-
}
|
|
164
|
-
return Array.from(seen);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 将 AST Constraint 转换为 Core IR Constraint。
|
|
168
|
-
*
|
|
169
|
-
* @param constraints - AST 约束列表
|
|
170
|
-
* @returns Core IR 约束列表
|
|
69
|
+
* 约束(ADR 0055 #4):Range 两端是规范十进制串,取自字面量原文;每个约束带自己的 origin。
|
|
171
70
|
*/
|
|
172
71
|
function lowerConstraints(constraints) {
|
|
173
|
-
|
|
174
|
-
return [];
|
|
175
|
-
}
|
|
176
|
-
return constraints.map(c => {
|
|
72
|
+
return (constraints ?? []).map(c => {
|
|
177
73
|
switch (c.kind) {
|
|
178
74
|
case 'Required':
|
|
179
|
-
return
|
|
75
|
+
return withOrigin(CoreIR.Required(), c);
|
|
180
76
|
case 'Range':
|
|
181
|
-
return
|
|
77
|
+
return withOrigin(CoreIR.Range(rangeBound(c.minRaw, c.min), rangeBound(c.maxRaw, c.max)), c);
|
|
182
78
|
case 'Pattern':
|
|
183
|
-
return
|
|
184
|
-
default:
|
|
185
|
-
|
|
186
|
-
|
|
79
|
+
return withOrigin(CoreIR.Pattern(c.regexp), c);
|
|
80
|
+
default: {
|
|
81
|
+
const never = c;
|
|
82
|
+
throw new Error(`未处理的约束:${JSON.stringify(never)}`);
|
|
83
|
+
}
|
|
187
84
|
}
|
|
188
85
|
});
|
|
189
86
|
}
|
|
87
|
+
/** Range 的一端:优先用字面量原文;只有数值(无原文,如测试手工构造的 AST)时取其十进制表示。 */
|
|
88
|
+
function rangeBound(raw, value) {
|
|
89
|
+
if (raw !== undefined)
|
|
90
|
+
return canonicalDecimalFromLiteral(raw);
|
|
91
|
+
return value === undefined ? null : canonicalDecimalFromLiteral(String(value));
|
|
92
|
+
}
|
|
93
|
+
/** 注解(ADR 0055 #3):args 保持源码顺序;位置参数已由解析器命名为 $0、$1…。 */
|
|
94
|
+
function lowerAnnotations(annotations) {
|
|
95
|
+
return (annotations ?? []).map(a => ({
|
|
96
|
+
name: a.name,
|
|
97
|
+
args: (a.args ?? []).map(arg => ({ name: arg.name, value: arg.value })),
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Func.effects(ADR 0055 #5,控制器裁决):只保留授权型具体效应 io / cpu(小写)与已声明的效应变量,
|
|
102
|
+
* 按首次声明顺序去重;pure、async 与未知效应名不授权任何效应,不写入。
|
|
103
|
+
* 内建名优先于效应参数:`<IO>` 这类与内建同名的效应参数由类型检查报 E213。
|
|
104
|
+
*/
|
|
105
|
+
function lowerEffects(effects, effectParams) {
|
|
106
|
+
const params = new Set(effectParams);
|
|
107
|
+
const out = [];
|
|
108
|
+
for (const e of effects) {
|
|
109
|
+
const lower = e.toLowerCase();
|
|
110
|
+
const name = AUTHORIZING_EFFECTS.has(lower) ? lower : params.has(e) ? e : undefined;
|
|
111
|
+
if (name !== undefined && !out.includes(name))
|
|
112
|
+
out.push(name);
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
/** 授权型具体效应名(schema `$defs/BuiltinEffect`)。 */
|
|
117
|
+
const AUTHORIZING_EFFECTS = new Set(['io', 'cpu']);
|
|
190
118
|
/**
|
|
191
119
|
* 将 AST Module 降级为 Core IR Module。
|
|
192
120
|
*
|
|
@@ -207,27 +135,17 @@ function lowerConstraints(constraints) {
|
|
|
207
135
|
*/
|
|
208
136
|
export function lowerModule(ast) {
|
|
209
137
|
const decls = ast.decls.map(lowerDecl);
|
|
210
|
-
const m =
|
|
138
|
+
const m = CoreIR.Module(ast.name, decls, ast.profile ?? null);
|
|
211
139
|
return withOrigin(m, ast);
|
|
212
140
|
}
|
|
213
141
|
function lowerDecl(d) {
|
|
214
142
|
switch (d.kind) {
|
|
215
143
|
case 'Import':
|
|
216
|
-
return withOrigin(
|
|
144
|
+
return withOrigin(CoreIR.Import(d.name, d.asName || null, d.version ?? null), d);
|
|
217
145
|
case 'Data':
|
|
218
|
-
return withResolution(withOrigin(
|
|
219
|
-
const field = {
|
|
220
|
-
name: canonicalOf(f.name, f.resolved),
|
|
221
|
-
type: lowerType(f.type),
|
|
222
|
-
constraints: lowerConstraints(f.constraints),
|
|
223
|
-
};
|
|
224
|
-
// 无类型字段记入旁路表而非 Core IR,保持 IR/golden/跨引擎指纹不变
|
|
225
|
-
if (f.typeInferred)
|
|
226
|
-
markFieldTypeInferred(field);
|
|
227
|
-
return field;
|
|
228
|
-
})), d), d.resolved);
|
|
146
|
+
return withResolution(withOrigin(CoreIR.Data(canonicalOf(d.name, d.resolved), d.fields.map(f => CoreIR.Field(canonicalOf(f.name, f.resolved), lowerType(f.type, NO_TYPE_VARS, f), lowerConstraints(f.constraints), f.typeInferred === true))), d), d.resolved);
|
|
229
147
|
case 'Enum':
|
|
230
|
-
return withResolution(withOrigin(
|
|
148
|
+
return withResolution(withOrigin(CoreIR.Enum(canonicalOf(d.name, d.resolved), d.variants.map((v, i) => canonicalOf(v, d.resolvedVariants?.[i]))), d), d.resolved);
|
|
231
149
|
case 'Func':
|
|
232
150
|
return lowerFunc(d);
|
|
233
151
|
default: {
|
|
@@ -240,78 +158,53 @@ function lowerDecl(d) {
|
|
|
240
158
|
}
|
|
241
159
|
function lowerFunc(f) {
|
|
242
160
|
const tvars = new Set(f.typeParams ?? []);
|
|
243
|
-
const params = f.params.map(p => (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
// 已知效果转为枚举;效应变量保留到声明列表。
|
|
251
|
-
// 未知效果名(如 teleport)与 aster-lang-core 一致(#304):不报错,名字原样保留在 IR 的
|
|
252
|
-
// effects / declaredEffects 中(core 的 effects 同样透传),检查阶段按 pure 处理——
|
|
253
|
-
// 各检查点只认 IO / CPU,效果推断经 normalizeEffectRef 把未知名折算为 PURE。
|
|
254
|
-
const effectParamSet = new Set(f.effectParams ?? []);
|
|
255
|
-
const declaredEffects = [];
|
|
256
|
-
const effects = [];
|
|
257
|
-
for (const e of f.effects ?? []) {
|
|
258
|
-
const known = parseEffect(e.toLowerCase());
|
|
259
|
-
if (known === null && effectParamSet.has(e)) {
|
|
260
|
-
declaredEffects.push({ kind: 'EffectVar', name: e });
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
const effect = known ?? e;
|
|
264
|
-
effects.push(effect);
|
|
265
|
-
declaredEffects.push(effect);
|
|
266
|
-
}
|
|
267
|
-
const body = f.body ? lowerBlock(f.body) : Core.Block([]);
|
|
268
|
-
const out = Core.Func(canonicalOf(f.name, f.resolved), f.typeParams ?? [], params, ret, effects, body, f.effectCaps, f.effectCapsExplicit, f.effectParams, declaredEffects, f.annotations ?? []);
|
|
269
|
-
if (f.retTypeInferred) {
|
|
270
|
-
out.retTypeInferred = true;
|
|
271
|
-
}
|
|
272
|
-
// 传递能力与 PII 元数据,并附带源位置信息
|
|
273
|
-
const enriched = withFuncPiiMetadata(withEffectCaps(out, f));
|
|
274
|
-
return withResolution(withOrigin(enriched, f), f.resolved);
|
|
161
|
+
const params = f.params.map(p => CoreIR.Param(p.name, lowerType(p.type, tvars, p), lowerConstraints(p.constraints), p.typeInferred === true));
|
|
162
|
+
const ret = lowerType(f.retType, tvars, f);
|
|
163
|
+
const effectParams = f.effectParams ?? [];
|
|
164
|
+
const body = f.body ? lowerBlock(f.body) : withOrigin(CoreIR.Block([]), f);
|
|
165
|
+
const out = CoreIR.Func(canonicalOf(f.name, f.resolved), f.typeParams ?? [], params, ret, lowerEffects(f.effects ?? [], effectParams), body, f.effectCaps, f.effectCapsExplicit, effectParams, lowerAnnotations(f.annotations));
|
|
166
|
+
out.retTypeInferred = f.retTypeInferred === true;
|
|
167
|
+
return withResolution(withOrigin(out, f), f.resolved);
|
|
275
168
|
}
|
|
276
169
|
function lowerBlock(b) {
|
|
277
|
-
return withOrigin(
|
|
170
|
+
return withOrigin(CoreIR.Block(b.statements.map(lowerStmt)), b);
|
|
278
171
|
}
|
|
279
172
|
function lowerStmt(s) {
|
|
280
173
|
switch (s.kind) {
|
|
281
174
|
case 'Let':
|
|
282
|
-
return withOrigin(
|
|
175
|
+
return withOrigin(CoreIR.Let(s.name, lowerExpr(s.expr)), s);
|
|
283
176
|
case 'Set': {
|
|
284
177
|
// Set 目标属于 FIELD_REF,R1 不解析:保留原写法交给 R2
|
|
285
|
-
const set = withOrigin(
|
|
178
|
+
const set = withOrigin(CoreIR.Set(s.name, lowerExpr(s.expr)), s);
|
|
286
179
|
markForResolution(set, { written: s.name });
|
|
287
180
|
return set;
|
|
288
181
|
}
|
|
289
182
|
case 'Return':
|
|
290
|
-
return withOrigin(
|
|
183
|
+
return withOrigin(CoreIR.Return(lowerExpr(s.expr)), s);
|
|
291
184
|
case 'If':
|
|
292
|
-
return withOrigin(
|
|
185
|
+
return withOrigin(CoreIR.If(lowerExpr(s.cond), lowerBlock(s.thenBlock), s.elseBlock ? lowerBlock(s.elseBlock) : null), s);
|
|
293
186
|
// Scope sugar lowering placeholder: if a Block starts with a special marker, we could emit Scope. For now none.
|
|
294
187
|
case 'Match':
|
|
295
|
-
return withOrigin(
|
|
188
|
+
return withOrigin(CoreIR.Match(lowerExpr(s.expr), s.cases.map(c => withOrigin(CoreIR.Case(lowerPattern(c.pattern), lowerCaseBody(c.body)), c))), s);
|
|
296
189
|
case 'Start':
|
|
297
|
-
return withOrigin(
|
|
190
|
+
return withOrigin(CoreIR.Start(s.name, lowerExpr(s.expr)), s);
|
|
298
191
|
case 'Wait':
|
|
299
|
-
return withOrigin(
|
|
192
|
+
return withOrigin(CoreIR.Wait(s.names), s);
|
|
300
193
|
case 'workflow':
|
|
301
194
|
return lowerWorkflow(s);
|
|
302
195
|
case 'Block':
|
|
303
|
-
return withOrigin(
|
|
196
|
+
return withOrigin(CoreIR.Scope(s.statements.map(lowerStmt)), s);
|
|
304
197
|
case 'Call':
|
|
305
198
|
// 裸表达式语句(`File.write("...").`):求值并丢弃结果,降为 `Let _ be <call>`。
|
|
306
199
|
//
|
|
307
200
|
// ★内层 Call 也必须挂 origin。原实现只给外层 Let 包了 withOrigin,内层
|
|
308
|
-
// `
|
|
201
|
+
// `CoreIR.Call(...)` 直接构造 → 该表达式**没有位置信息**。
|
|
309
202
|
// 后果:ADR 0032 的 trace 锚点与 ADR 0037 的 OriginMap 都按位置定位,
|
|
310
203
|
// 一个无 origin 的节点在「点击源码 ↔ 高亮 IR」里**不可达**——不报错,
|
|
311
204
|
// 只是这段代码从双向导航里静默消失。
|
|
312
205
|
// (实测 eff_valid_all_caps.aster:真正的 Let 有 expr.origin,
|
|
313
206
|
// 合成的 Let "_" 没有,与 Java 侧跨引擎分叉。)
|
|
314
|
-
return withOrigin(
|
|
207
|
+
return withOrigin(CoreIR.Let('_', withOrigin(CoreIR.Call(lowerExpr(s.target), s.args.map(lowerExpr)), s)), s);
|
|
315
208
|
default: {
|
|
316
209
|
// Parser now prohibits bare expressions, so this should never be reached
|
|
317
210
|
const { span } = extractMetadata(s);
|
|
@@ -329,14 +222,14 @@ function lowerWorkflow(stmt) {
|
|
|
329
222
|
const effectCaps = mergeCapabilitySets(steps.map(step => step.effectCaps));
|
|
330
223
|
const retry = stmt.retry
|
|
331
224
|
? { maxAttempts: stmt.retry.maxAttempts, backoff: stmt.retry.backoff }
|
|
332
|
-
:
|
|
333
|
-
const timeout = stmt.timeout ? { milliseconds: stmt.timeout.milliseconds } :
|
|
334
|
-
const workflow =
|
|
225
|
+
: null;
|
|
226
|
+
const timeout = stmt.timeout ? { milliseconds: stmt.timeout.milliseconds } : null;
|
|
227
|
+
const workflow = CoreIR.Workflow(steps, effectCaps, retry, timeout);
|
|
335
228
|
return withOrigin(workflow, stmt);
|
|
336
229
|
}
|
|
337
230
|
function lowerStep(stmt, prevStep) {
|
|
338
231
|
const body = lowerBlock(stmt.body);
|
|
339
|
-
const compensate = stmt.compensate ? lowerBlock(stmt.compensate) :
|
|
232
|
+
const compensate = stmt.compensate ? lowerBlock(stmt.compensate) : null;
|
|
340
233
|
const effectCaps = mergeCapabilitySets([
|
|
341
234
|
collectCapabilitiesFromBlock(body),
|
|
342
235
|
...(compensate ? [collectCapabilitiesFromBlock(compensate)] : []),
|
|
@@ -347,7 +240,7 @@ function lowerStep(stmt, prevStep) {
|
|
|
347
240
|
: prevStep
|
|
348
241
|
? [prevStep]
|
|
349
242
|
: [];
|
|
350
|
-
const step =
|
|
243
|
+
const step = CoreIR.Step(stmt.name, body, effectCaps, compensate, dependencies);
|
|
351
244
|
return withOrigin(step, stmt);
|
|
352
245
|
}
|
|
353
246
|
function mergeCapabilitySets(lists) {
|
|
@@ -386,7 +279,7 @@ function collectCapabilitiesFromBlock(block) {
|
|
|
386
279
|
function lowerCaseBody(body) {
|
|
387
280
|
// Body can be a Return node or a Block
|
|
388
281
|
if (body.kind === 'Return') {
|
|
389
|
-
return withOrigin(
|
|
282
|
+
return withOrigin(CoreIR.Return(lowerExpr(body.expr)), body);
|
|
390
283
|
}
|
|
391
284
|
return lowerBlock(body);
|
|
392
285
|
}
|
|
@@ -474,8 +367,8 @@ function splitUfcsReceiver(target, unresolvedTarget) {
|
|
|
474
367
|
// 注:Java 侧给接收者/方法名的是各自更精确的子 span;此处沿用整体 span,
|
|
475
368
|
// 跨引擎在 `file+line` 口径下一致(同一行),strict 口径下的列差属既有
|
|
476
369
|
// col 口径问题,不在本次范围。
|
|
477
|
-
const receiver =
|
|
478
|
-
const method =
|
|
370
|
+
const receiver = CoreIR.Name(head);
|
|
371
|
+
const method = CoreIR.Name(full.slice(dot + 1));
|
|
479
372
|
const span = target.origin;
|
|
480
373
|
if (span !== undefined) {
|
|
481
374
|
receiver.origin = span;
|
|
@@ -493,19 +386,20 @@ function lowerExpr(e) {
|
|
|
493
386
|
case 'Name':
|
|
494
387
|
return lowerName(e);
|
|
495
388
|
case 'Bool':
|
|
496
|
-
return withOrigin(
|
|
389
|
+
return withOrigin(CoreIR.Bool(e.value), e);
|
|
497
390
|
case 'Int':
|
|
498
|
-
return withOrigin(
|
|
391
|
+
return withOrigin(CoreIR.Int(e.value), e);
|
|
499
392
|
case 'Long':
|
|
500
|
-
return withOrigin(
|
|
393
|
+
return withOrigin(CoreIR.Long(e.value), e);
|
|
501
394
|
case 'Double':
|
|
502
|
-
|
|
395
|
+
// ADR 0055 #18:规范十进制串取自字面量原文,不经二进制浮点(手工构造、没有原文的 AST 退回其数值)
|
|
396
|
+
return withOrigin(CoreIR.Double(canonicalDecimalFromLiteral(e.raw ?? String(e.value))), e);
|
|
503
397
|
case 'Decimal':
|
|
504
|
-
return withOrigin(
|
|
398
|
+
return withOrigin(CoreIR.Decimal(e.value), e);
|
|
505
399
|
case 'String':
|
|
506
|
-
return withOrigin(
|
|
400
|
+
return withOrigin(CoreIR.String(e.value), e);
|
|
507
401
|
case 'Null':
|
|
508
|
-
return withOrigin(
|
|
402
|
+
return withOrigin(CoreIR.Null(), e);
|
|
509
403
|
case 'Call': {
|
|
510
404
|
// ★内置变体的调用形式归一(aster-lang-ts#124):`Some(x)` / `Ok(x)` / `Err(x)` /
|
|
511
405
|
// `None()` 与关键字形式 `some of x` 必须降到**完全相同**的 Core IR 节点。
|
|
@@ -525,14 +419,14 @@ function lowerExpr(e) {
|
|
|
525
419
|
const ctor = e.target.name;
|
|
526
420
|
if (e.args.length === 1) {
|
|
527
421
|
if (ctor === 'Some')
|
|
528
|
-
return withOrigin(
|
|
422
|
+
return withOrigin(CoreIR.Some(lowerExpr(e.args[0])), e);
|
|
529
423
|
if (ctor === 'Ok')
|
|
530
|
-
return withOrigin(
|
|
424
|
+
return withOrigin(CoreIR.Ok(lowerExpr(e.args[0])), e);
|
|
531
425
|
if (ctor === 'Err')
|
|
532
|
-
return withOrigin(
|
|
426
|
+
return withOrigin(CoreIR.Err(lowerExpr(e.args[0])), e);
|
|
533
427
|
}
|
|
534
428
|
if (ctor === 'None' && e.args.length === 0) {
|
|
535
|
-
return withOrigin(
|
|
429
|
+
return withOrigin(CoreIR.None(), e);
|
|
536
430
|
}
|
|
537
431
|
}
|
|
538
432
|
// ★UFCS(接收者转参数):`value.sum(1, 2)` → `sum(value, 1, 2)`。
|
|
@@ -556,28 +450,28 @@ function lowerExpr(e) {
|
|
|
556
450
|
const loweredArgs = e.args.map(lowerExpr);
|
|
557
451
|
const ufcs = splitUfcsReceiver(target, e.target.kind === 'Name' && !e.target.resolved);
|
|
558
452
|
if (ufcs) {
|
|
559
|
-
return withOrigin(
|
|
453
|
+
return withOrigin(CoreIR.Call(ufcs.method, [ufcs.receiver, ...loweredArgs]), e);
|
|
560
454
|
}
|
|
561
|
-
return withOrigin(
|
|
455
|
+
return withOrigin(CoreIR.Call(target, loweredArgs), e);
|
|
562
456
|
}
|
|
563
457
|
case 'Construct':
|
|
564
|
-
return withResolution(withOrigin(
|
|
458
|
+
return withResolution(withOrigin(CoreIR.Construct(canonicalOf(e.typeName, e.resolved), e.fields.map(f => ({ name: canonicalOf(f.name, f.resolved), expr: lowerExpr(f.expr) }))), e), e.resolved);
|
|
565
459
|
case 'Ok':
|
|
566
|
-
return withOrigin(
|
|
460
|
+
return withOrigin(CoreIR.Ok(lowerExpr(e.expr)), e);
|
|
567
461
|
case 'Err':
|
|
568
|
-
return withOrigin(
|
|
462
|
+
return withOrigin(CoreIR.Err(lowerExpr(e.expr)), e);
|
|
569
463
|
case 'Some':
|
|
570
|
-
return withOrigin(
|
|
464
|
+
return withOrigin(CoreIR.Some(lowerExpr(e.expr)), e);
|
|
571
465
|
case 'None':
|
|
572
|
-
return withOrigin(
|
|
466
|
+
return withOrigin(CoreIR.None(), e);
|
|
573
467
|
case 'Await':
|
|
574
|
-
return withOrigin(
|
|
468
|
+
return withOrigin(CoreIR.Await(lowerExpr(e.expr)), e);
|
|
575
469
|
case 'IfExpr':
|
|
576
470
|
// ADR 0019 G2b:表达式级 if → Core IR IfExpr(三分支递归 lower)。
|
|
577
|
-
return withOrigin(
|
|
471
|
+
return withOrigin(CoreIR.IfExpr(lowerExpr(e.cond), lowerExpr(e.thenE), lowerExpr(e.elseE)), e);
|
|
578
472
|
case 'ListLit':
|
|
579
473
|
// ADR 0024 C0:列表字面量 → Core IR ListLit(元素递归 lower)。
|
|
580
|
-
return withOrigin(
|
|
474
|
+
return withOrigin(CoreIR.ListLit(e.elements.map(lowerExpr)), e);
|
|
581
475
|
case 'Lambda': {
|
|
582
476
|
// 捕获变量收集:只收**自由变量**(引用了、但在 lambda 内部没被绑定的名字)。
|
|
583
477
|
//
|
|
@@ -661,22 +555,10 @@ function lowerExpr(e) {
|
|
|
661
555
|
}
|
|
662
556
|
new CaptureVisitor().visitBlock(e.body, undefined);
|
|
663
557
|
const captures = Array.from(names);
|
|
664
|
-
const coreParams = e.params.map(p =>
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
markLambdaParamTypeInferred(param);
|
|
669
|
-
return param;
|
|
670
|
-
});
|
|
671
|
-
const ret = lowerType(e.retType);
|
|
672
|
-
const lambda = {
|
|
673
|
-
kind: 'Lambda',
|
|
674
|
-
params: coreParams,
|
|
675
|
-
retType: ret, // BaseLambda expects retType
|
|
676
|
-
ret, // Core.Lambda also has ret
|
|
677
|
-
body: lowerBlock(e.body),
|
|
678
|
-
captures,
|
|
679
|
-
};
|
|
558
|
+
const coreParams = e.params.map(p => CoreIR.Param(p.name, lowerType(p.type, NO_TYPE_VARS, p), [],
|
|
559
|
+
// 解析器对未标注类型的 lambda 参数同样写入 typeInferred(Parameter),BaseParameter 未声明该字段
|
|
560
|
+
p.typeInferred === true));
|
|
561
|
+
const lambda = CoreIR.Lambda(coreParams, lowerType(e.retType, NO_TYPE_VARS, e), lowerBlock(e.body), captures);
|
|
680
562
|
return withOrigin(lambda, e);
|
|
681
563
|
}
|
|
682
564
|
default: {
|
|
@@ -690,14 +572,17 @@ function lowerExpr(e) {
|
|
|
690
572
|
function lowerPattern(p) {
|
|
691
573
|
switch (p.kind) {
|
|
692
574
|
case 'PatternNull':
|
|
693
|
-
return withOrigin(
|
|
575
|
+
return withOrigin(CoreIR.PatNull(), p);
|
|
694
576
|
case 'PatternInt':
|
|
695
|
-
return withOrigin(
|
|
577
|
+
return withOrigin(CoreIR.PatInt(p.value), p);
|
|
696
578
|
case 'PatternCtor':
|
|
697
579
|
return lowerPatternCtor(p);
|
|
698
580
|
case 'PatternName': {
|
|
581
|
+
// 裸的关键词构造器(`When None`)是 0 参变体模式(ADR 0055 #16),与 Java 的裸名构造器同形
|
|
582
|
+
if (KEYWORD_CTORS.has(p.name))
|
|
583
|
+
return withOrigin(CoreIR.PatCtor(p.name, []), p);
|
|
699
584
|
// 模式名可能是期望枚举下的成员(ADR 0051 裁决 R12),由 R2 判定
|
|
700
|
-
const pat = withOrigin(
|
|
585
|
+
const pat = withOrigin(CoreIR.PatName(p.name), p);
|
|
701
586
|
markForResolution(pat, { written: p.name });
|
|
702
587
|
return pat;
|
|
703
588
|
}
|
|
@@ -709,9 +594,14 @@ function lowerPattern(p) {
|
|
|
709
594
|
}
|
|
710
595
|
}
|
|
711
596
|
}
|
|
597
|
+
/**
|
|
598
|
+
* 构造器模式(ADR 0055 #15):只用 args。`Ok(x)` 的各个名字与 Java AstBuilder 一样作为嵌套的名字模式
|
|
599
|
+
* 降级(各取自己的 span,没有时取构造器位置),由 R2 判定成员还是绑定;嵌套模式(AST 的 args)照常降级。
|
|
600
|
+
*/
|
|
712
601
|
function lowerPatternCtor(p) {
|
|
713
|
-
const
|
|
714
|
-
const
|
|
602
|
+
const named = (p.names ?? []).map((n, i) => ({ kind: 'PatternName', name: n, span: p.nameSpans?.[i] ?? p.span }));
|
|
603
|
+
const args = [...named, ...(p.args ?? [])].map(pp => lowerPattern(pp));
|
|
604
|
+
const pat = withResolution(withOrigin(CoreIR.PatCtor(canonicalOf(p.typeName, p.resolved), args), p), p.resolved);
|
|
715
605
|
// 主语类型在 R1 未知的用户构造器留给 R2;关键词构造器不查词汇
|
|
716
606
|
if (!p.resolved && !KEYWORD_CTORS.has(p.typeName))
|
|
717
607
|
markForResolution(pat, { written: p.typeName });
|
|
@@ -722,7 +612,7 @@ function lowerPatternCtor(p) {
|
|
|
722
612
|
* 并记下 R1 的角色;R1 未决定的点分名(字段路径、限定调用)同样交给 R2。
|
|
723
613
|
*/
|
|
724
614
|
function lowerName(e) {
|
|
725
|
-
const node = withResolution(withOrigin(
|
|
615
|
+
const node = withResolution(withOrigin(CoreIR.Name(canonicalOf(e.name, e.resolved)), e), e.resolved);
|
|
726
616
|
if (!e.name.includes('.')) {
|
|
727
617
|
markForResolution(node, e.resolved ? { written: e.name, r1Role: e.resolved.role } : { written: e.name });
|
|
728
618
|
}
|
|
@@ -732,39 +622,43 @@ function lowerName(e) {
|
|
|
732
622
|
return node;
|
|
733
623
|
}
|
|
734
624
|
function spanToOrigin(span, file) {
|
|
735
|
-
|
|
736
|
-
return null;
|
|
737
|
-
const origin = {
|
|
738
|
-
start: span.start,
|
|
739
|
-
end: span.end,
|
|
740
|
-
};
|
|
741
|
-
if (file !== null) {
|
|
742
|
-
origin.file = file;
|
|
743
|
-
}
|
|
744
|
-
return origin;
|
|
625
|
+
return { file, start: span.start, end: span.end, written: null, role: null };
|
|
745
626
|
}
|
|
746
|
-
|
|
627
|
+
const NO_TYPE_VARS = new Set();
|
|
628
|
+
/**
|
|
629
|
+
* 类型降级。`vars` 为函数声明的类型参数:其中的名字降为 TypeVar。每个类型节点都带 origin
|
|
630
|
+
* (ADR 0055 #17):取类型自身的 span,没有时(解析器合成的推断类型)取 fallback 节点的位置。
|
|
631
|
+
* 签名中被改写的写法照常记录 written / role(ADR 0051 §4)。
|
|
632
|
+
*/
|
|
633
|
+
function lowerType(t, vars, ...fallback) {
|
|
634
|
+
const sub = (x) => lowerType(x, vars, t, ...fallback);
|
|
635
|
+
const at = (node) => withOrigin(node, t, ...fallback);
|
|
747
636
|
switch (t.kind) {
|
|
748
637
|
case 'TypeName':
|
|
749
|
-
return
|
|
638
|
+
return vars.has(t.name)
|
|
639
|
+
? at(CoreIR.TypeVar(t.name))
|
|
640
|
+
: withResolution(at(CoreIR.TypeName(canonicalOf(t.name, t.resolved))), t.resolved);
|
|
750
641
|
case 'TypeVar':
|
|
751
|
-
return
|
|
642
|
+
return at(CoreIR.TypeVar(t.name));
|
|
643
|
+
case 'EffectVar':
|
|
644
|
+
// v2 没有效应变量类型节点(schema Type 联合不含 EffectVar);解析器不产出它,手工 AST 按类型变量处理
|
|
645
|
+
return at(CoreIR.TypeVar(t.name));
|
|
752
646
|
case 'TypeApp':
|
|
753
|
-
return withResolution(
|
|
647
|
+
return withResolution(at(CoreIR.TypeApp(canonicalOf(t.base, t.resolved), t.args.map(sub))), t.resolved);
|
|
754
648
|
case 'Maybe':
|
|
755
|
-
return
|
|
649
|
+
return at(CoreIR.Maybe(sub(t.type)));
|
|
756
650
|
case 'Option':
|
|
757
|
-
return
|
|
651
|
+
return at(CoreIR.Option(sub(t.type)));
|
|
758
652
|
case 'Result':
|
|
759
|
-
return
|
|
653
|
+
return at(CoreIR.Result(sub(t.ok), sub(t.err)));
|
|
760
654
|
case 'List':
|
|
761
|
-
return
|
|
655
|
+
return at(CoreIR.List(sub(t.type)));
|
|
762
656
|
case 'Map':
|
|
763
|
-
return
|
|
657
|
+
return at(CoreIR.Map(sub(t.key), sub(t.val)));
|
|
764
658
|
case 'TypePii':
|
|
765
|
-
return
|
|
659
|
+
return at(CoreIR.Pii(sub(t.baseType), t.sensitivity, t.category));
|
|
766
660
|
case 'FuncType':
|
|
767
|
-
return
|
|
661
|
+
return at(CoreIR.FuncType(t.params.map(sub), sub(t.ret)));
|
|
768
662
|
default: {
|
|
769
663
|
const { span } = extractMetadata(t);
|
|
770
664
|
const kind = t.kind;
|
|
@@ -773,48 +667,4 @@ function lowerType(t) {
|
|
|
773
667
|
}
|
|
774
668
|
}
|
|
775
669
|
}
|
|
776
|
-
/**
|
|
777
|
-
* 函数签名类型名的解析记录(ADR 0051 §4,与 Java 对齐):签名类型平时不带 origin,
|
|
778
|
-
* 仅当写法被改写(written !== canonical)时才附加带 written/role 的 origin,
|
|
779
|
-
* 因此无词汇或规范名直写的签名 IR 保持逐字节不变。
|
|
780
|
-
*/
|
|
781
|
-
function withSignatureResolution(coreNode, astNode, resolved) {
|
|
782
|
-
if (!resolved || resolved.written === resolved.canonical)
|
|
783
|
-
return coreNode;
|
|
784
|
-
return withResolution(withOrigin(coreNode, astNode), resolved);
|
|
785
|
-
}
|
|
786
|
-
function lowerTypeWithVars(t, vars) {
|
|
787
|
-
switch (t.kind) {
|
|
788
|
-
case 'TypeName':
|
|
789
|
-
return vars.has(t.name)
|
|
790
|
-
? { kind: 'TypeVar', name: t.name }
|
|
791
|
-
: withSignatureResolution(Core.TypeName(canonicalOf(t.name, t.resolved)), t, t.resolved);
|
|
792
|
-
case 'EffectVar':
|
|
793
|
-
return { kind: 'EffectVar', name: t.name };
|
|
794
|
-
case 'Maybe':
|
|
795
|
-
return Core.Maybe(lowerTypeWithVars(t.type, vars));
|
|
796
|
-
case 'Option':
|
|
797
|
-
return Core.Option(lowerTypeWithVars(t.type, vars));
|
|
798
|
-
case 'Result':
|
|
799
|
-
return Core.Result(lowerTypeWithVars(t.ok, vars), lowerTypeWithVars(t.err, vars));
|
|
800
|
-
case 'List':
|
|
801
|
-
return Core.List(lowerTypeWithVars(t.type, vars));
|
|
802
|
-
case 'Map':
|
|
803
|
-
return Core.Map(lowerTypeWithVars(t.key, vars), lowerTypeWithVars(t.val, vars));
|
|
804
|
-
case 'TypeApp':
|
|
805
|
-
return withSignatureResolution({
|
|
806
|
-
kind: 'TypeApp',
|
|
807
|
-
base: canonicalOf(t.base, t.resolved),
|
|
808
|
-
args: t.args.map(tt => lowerTypeWithVars(tt, vars)),
|
|
809
|
-
}, t, t.resolved);
|
|
810
|
-
case 'TypeVar':
|
|
811
|
-
return { kind: 'TypeVar', name: t.name };
|
|
812
|
-
case 'TypePii':
|
|
813
|
-
return Core.Pii(lowerTypeWithVars(t.baseType, vars), t.sensitivity, t.category);
|
|
814
|
-
case 'FuncType':
|
|
815
|
-
return Core.FuncType(t.params.map(p => lowerTypeWithVars(p, vars)), lowerTypeWithVars(t.ret, vars));
|
|
816
|
-
default:
|
|
817
|
-
return lowerType(t);
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
670
|
//# sourceMappingURL=lower_to_core.js.map
|