@aster-cloud/aster-lang-ts 1.6.0 → 3.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 +64 -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/generate-naming-rules.d.ts +5 -0
- package/dist/scripts/generate-naming-rules.d.ts.map +1 -0
- package/dist/scripts/generate-naming-rules.js +35 -0
- package/dist/scripts/generate-naming-rules.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/schema.d.ts.map +1 -1
- package/dist/src/browser/schema.js +1 -3
- package/dist/src/browser/schema.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 +7 -4
- 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.d.ts.map +1 -1
- package/dist/src/compile-pipeline.js +2 -3
- 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/config/lexicons/fallback-lexicon.d.ts +1 -1
- package/dist/src/config/lexicons/fallback-lexicon.d.ts.map +1 -1
- package/dist/src/config/lexicons/fallback-lexicon.js +1 -4
- package/dist/src/config/lexicons/fallback-lexicon.js.map +1 -1
- package/dist/src/config/lexicons/overlay-loader.d.ts +0 -13
- package/dist/src/config/lexicons/overlay-loader.d.ts.map +1 -1
- package/dist/src/config/lexicons/overlay-loader.js +0 -18
- package/dist/src/config/lexicons/overlay-loader.js.map +1 -1
- package/dist/src/config/lexicons/types.d.ts +0 -3
- package/dist/src/config/lexicons/types.d.ts.map +1 -1
- package/dist/src/config/lexicons/types.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/lambda-captures.d.ts +14 -0
- package/dist/src/core/lambda-captures.d.ts.map +1 -0
- package/dist/src/core/lambda-captures.js +128 -0
- package/dist/src/core/lambda-captures.js.map +1 -0
- 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/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 -19
- package/dist/src/lower_to_core.d.ts.map +1 -1
- package/dist/src/lower_to_core.js +194 -384
- 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 +17 -10
- 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 +9 -3
- package/dist/src/parser/field-variant-parser.js.map +1 -1
- package/dist/src/parser/naming-rules.d.ts +19 -0
- package/dist/src/parser/naming-rules.d.ts.map +1 -0
- package/dist/src/parser/naming-rules.generated.d.ts +7 -0
- package/dist/src/parser/naming-rules.generated.d.ts.map +1 -0
- package/dist/src/parser/naming-rules.generated.js +392 -0
- package/dist/src/parser/naming-rules.generated.js.map +1 -0
- package/dist/src/parser/naming-rules.js +2 -0
- package/dist/src/parser/naming-rules.js.map +1 -0
- 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-inference.d.ts +29 -70
- package/dist/src/parser/type-inference.d.ts.map +1 -1
- package/dist/src/parser/type-inference.js +82 -212
- package/dist/src/parser/type-inference.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 +31 -21
- package/dist/src/parser/type-parser.js.map +1 -1
- package/dist/src/parser.d.ts.map +1 -1
- package/dist/src/parser.js +2 -5
- package/dist/src/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 +18 -11
- 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/type-inference.d.ts +1 -13
- package/dist/src/types/type-inference.d.ts.map +1 -1
- package/dist/src/types/type-inference.js +1 -2
- package/dist/src/types/type-inference.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/locales-type-inference.d.ts +6 -0
- package/dist/test/helpers/locales-type-inference.d.ts.map +1 -0
- package/dist/test/helpers/locales-type-inference.js +14 -0
- package/dist/test/helpers/locales-type-inference.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/compliance/compliance-smoke.test.js +1 -2
- package/dist/test/integration/compliance/compliance-smoke.test.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 +22 -18
- 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-caps-explicit-only.test.d.ts +2 -0
- package/dist/test/unit/effect/effect-caps-explicit-only.test.d.ts.map +1 -0
- package/dist/test/unit/effect/effect-caps-explicit-only.test.js +73 -0
- package/dist/test/unit/effect/effect-caps-explicit-only.test.js.map +1 -0
- 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/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/lambda-capture-parity.test.js +43 -14
- package/dist/test/unit/lambda-capture-parity.test.js.map +1 -1
- package/dist/test/unit/lexicons/fallback-lexicon.test.d.ts +1 -1
- package/dist/test/unit/lexicons/fallback-lexicon.test.js +2 -4
- package/dist/test/unit/lexicons/fallback-lexicon.test.js.map +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/inferred-type-anchor.test.d.ts +2 -0
- package/dist/test/unit/parser/inferred-type-anchor.test.d.ts.map +1 -0
- package/dist/test/unit/parser/inferred-type-anchor.test.js +83 -0
- package/dist/test/unit/parser/inferred-type-anchor.test.js.map +1 -0
- package/dist/test/unit/parser/naming-rules-parity.test.d.ts +2 -0
- package/dist/test/unit/parser/naming-rules-parity.test.d.ts.map +1 -0
- package/dist/test/unit/parser/naming-rules-parity.test.js +26 -0
- package/dist/test/unit/parser/naming-rules-parity.test.js.map +1 -0
- package/dist/test/unit/parser/parser.test.js +11 -32
- package/dist/test/unit/parser/parser.test.js.map +1 -1
- package/dist/test/unit/parser/type-inference-vectors.test.d.ts +2 -0
- package/dist/test/unit/parser/type-inference-vectors.test.d.ts.map +1 -0
- package/dist/test/unit/parser/type-inference-vectors.test.js +40 -0
- package/dist/test/unit/parser/type-inference-vectors.test.js.map +1 -0
- package/dist/test/unit/parser/type-inference.test.d.ts +2 -1
- package/dist/test/unit/parser/type-inference.test.d.ts.map +1 -1
- package/dist/test/unit/parser/type-inference.test.js +93 -159
- package/dist/test/unit/parser/type-inference.test.js.map +1 -1
- package/dist/test/unit/regex-guard.test.js +6 -6
- package/dist/test/unit/regex-guard.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/config/lexicons/type-inference-rules.d.ts +0 -19
- package/dist/src/config/lexicons/type-inference-rules.d.ts.map +0 -1
- package/dist/src/config/lexicons/type-inference-rules.js +0 -63
- package/dist/src/config/lexicons/type-inference-rules.js.map +0 -1
- 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,13 +16,13 @@
|
|
|
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
|
-
import {
|
|
25
|
+
import { collectLambdaCaptures } from './core/lambda-captures.js';
|
|
26
26
|
import { DefaultCoreVisitor, createVisitorContext } from './core/visitor.js';
|
|
27
27
|
/**
|
|
28
28
|
* 从 AST 节点提取元数据(span 和 file)。
|
|
@@ -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
|
*
|
|
@@ -205,29 +133,46 @@ function lowerConstraints(constraints) {
|
|
|
205
133
|
* @internal 不从包入口导出:未经 R1 的 AST 降级后名字保持原写法(可能是本地化名)。
|
|
206
134
|
* 外部调用方使用 resolveAndLowerChecked(compile-pipeline)或 browser `compile`。
|
|
207
135
|
*/
|
|
136
|
+
/**
|
|
137
|
+
* 降级函数体时可见的局部绑定(形参、此前的 Let / Start、Match 模式绑定、外层 lambda 形参),按块分层。
|
|
138
|
+
* 只用于判定 lambda 的 captures 是否为外层局部(ADR 0056 §4.2,见 core/lambda-captures.ts)。
|
|
139
|
+
* lowering 是同步的,每层都在 finally 中出栈,lowerModule 结束时栈必为空;lowerModule 入口据此拒绝重入。
|
|
140
|
+
*/
|
|
141
|
+
const localScopes = [];
|
|
142
|
+
function inLocalScope(names, fn) {
|
|
143
|
+
localScopes.push(new Set(names));
|
|
144
|
+
try {
|
|
145
|
+
return fn();
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
localScopes.pop();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function bindLocal(name) {
|
|
152
|
+
localScopes[localScopes.length - 1]?.add(name);
|
|
153
|
+
}
|
|
154
|
+
function visibleLocals() {
|
|
155
|
+
const out = new Set();
|
|
156
|
+
for (const scope of localScopes)
|
|
157
|
+
for (const n of scope)
|
|
158
|
+
out.add(n);
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
208
161
|
export function lowerModule(ast) {
|
|
162
|
+
if (localScopes.length > 0)
|
|
163
|
+
throw new Error('lowerModule 不可重入:局部作用域栈非空');
|
|
209
164
|
const decls = ast.decls.map(lowerDecl);
|
|
210
|
-
const m =
|
|
165
|
+
const m = CoreIR.Module(ast.name, decls, ast.profile ?? null);
|
|
211
166
|
return withOrigin(m, ast);
|
|
212
167
|
}
|
|
213
168
|
function lowerDecl(d) {
|
|
214
169
|
switch (d.kind) {
|
|
215
170
|
case 'Import':
|
|
216
|
-
return withOrigin(
|
|
171
|
+
return withOrigin(CoreIR.Import(d.name, d.asName || null, d.version ?? null), d);
|
|
217
172
|
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);
|
|
173
|
+
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
174
|
case 'Enum':
|
|
230
|
-
return withResolution(withOrigin(
|
|
175
|
+
return withResolution(withOrigin(CoreIR.Enum(canonicalOf(d.name, d.resolved), d.variants.map((v, i) => canonicalOf(v, d.resolvedVariants?.[i]))), d), d.resolved);
|
|
231
176
|
case 'Func':
|
|
232
177
|
return lowerFunc(d);
|
|
233
178
|
default: {
|
|
@@ -240,78 +185,62 @@ function lowerDecl(d) {
|
|
|
240
185
|
}
|
|
241
186
|
function lowerFunc(f) {
|
|
242
187
|
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);
|
|
188
|
+
const params = f.params.map(p => CoreIR.Param(p.name, lowerType(p.type, tvars, p), lowerConstraints(p.constraints), p.typeInferred === true));
|
|
189
|
+
const ret = lowerType(f.retType, tvars, f);
|
|
190
|
+
const effectParams = f.effectParams ?? [];
|
|
191
|
+
const body = f.body ? inLocalScope(params.map(p => p.name), () => lowerBlock(f.body)) : withOrigin(CoreIR.Block([]), f);
|
|
192
|
+
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));
|
|
193
|
+
out.retTypeInferred = f.retTypeInferred === true;
|
|
194
|
+
return withResolution(withOrigin(out, f), f.resolved);
|
|
275
195
|
}
|
|
276
196
|
function lowerBlock(b) {
|
|
277
|
-
return withOrigin(
|
|
197
|
+
return withOrigin(CoreIR.Block(lowerStatements(b.statements)), b);
|
|
198
|
+
}
|
|
199
|
+
/** 块内语句在新的一层局部作用域内降级:块内 Let 出块后不可见。 */
|
|
200
|
+
function lowerStatements(statements) {
|
|
201
|
+
return inLocalScope([], () => statements.map(lowerStmt));
|
|
278
202
|
}
|
|
279
203
|
function lowerStmt(s) {
|
|
280
204
|
switch (s.kind) {
|
|
281
|
-
case 'Let':
|
|
282
|
-
|
|
205
|
+
case 'Let': {
|
|
206
|
+
const let_ = withOrigin(CoreIR.Let(s.name, lowerExpr(s.expr)), s);
|
|
207
|
+
bindLocal(s.name);
|
|
208
|
+
return let_;
|
|
209
|
+
}
|
|
283
210
|
case 'Set': {
|
|
284
211
|
// Set 目标属于 FIELD_REF,R1 不解析:保留原写法交给 R2
|
|
285
|
-
const set = withOrigin(
|
|
212
|
+
const set = withOrigin(CoreIR.Set(s.name, lowerExpr(s.expr)), s);
|
|
286
213
|
markForResolution(set, { written: s.name });
|
|
287
214
|
return set;
|
|
288
215
|
}
|
|
289
216
|
case 'Return':
|
|
290
|
-
return withOrigin(
|
|
217
|
+
return withOrigin(CoreIR.Return(lowerExpr(s.expr)), s);
|
|
291
218
|
case 'If':
|
|
292
|
-
return withOrigin(
|
|
219
|
+
return withOrigin(CoreIR.If(lowerExpr(s.cond), lowerBlock(s.thenBlock), s.elseBlock ? lowerBlock(s.elseBlock) : null), s);
|
|
293
220
|
// Scope sugar lowering placeholder: if a Block starts with a special marker, we could emit Scope. For now none.
|
|
294
221
|
case 'Match':
|
|
295
|
-
return withOrigin(
|
|
222
|
+
return withOrigin(CoreIR.Match(lowerExpr(s.expr), s.cases.map(c => withOrigin(CoreIR.Case(lowerPattern(c.pattern), inLocalScope(patternBindings(c.pattern), () => lowerCaseBody(c.body))), c))), s);
|
|
296
223
|
case 'Start':
|
|
297
|
-
|
|
224
|
+
// 与 R1 一致:Start 的任务名先入作用域,此后的 lambda 可以捕获它
|
|
225
|
+
bindLocal(s.name);
|
|
226
|
+
return withOrigin(CoreIR.Start(s.name, lowerExpr(s.expr)), s);
|
|
298
227
|
case 'Wait':
|
|
299
|
-
return withOrigin(
|
|
228
|
+
return withOrigin(CoreIR.Wait(s.names), s);
|
|
300
229
|
case 'workflow':
|
|
301
230
|
return lowerWorkflow(s);
|
|
302
231
|
case 'Block':
|
|
303
|
-
return withOrigin(
|
|
232
|
+
return withOrigin(CoreIR.Scope(lowerStatements(s.statements)), s);
|
|
304
233
|
case 'Call':
|
|
305
234
|
// 裸表达式语句(`File.write("...").`):求值并丢弃结果,降为 `Let _ be <call>`。
|
|
306
235
|
//
|
|
307
236
|
// ★内层 Call 也必须挂 origin。原实现只给外层 Let 包了 withOrigin,内层
|
|
308
|
-
// `
|
|
237
|
+
// `CoreIR.Call(...)` 直接构造 → 该表达式**没有位置信息**。
|
|
309
238
|
// 后果:ADR 0032 的 trace 锚点与 ADR 0037 的 OriginMap 都按位置定位,
|
|
310
239
|
// 一个无 origin 的节点在「点击源码 ↔ 高亮 IR」里**不可达**——不报错,
|
|
311
240
|
// 只是这段代码从双向导航里静默消失。
|
|
312
241
|
// (实测 eff_valid_all_caps.aster:真正的 Let 有 expr.origin,
|
|
313
242
|
// 合成的 Let "_" 没有,与 Java 侧跨引擎分叉。)
|
|
314
|
-
return withOrigin(
|
|
243
|
+
return withOrigin(CoreIR.Let('_', withOrigin(CoreIR.Call(lowerExpr(s.target), s.args.map(lowerExpr)), s)), s);
|
|
315
244
|
default: {
|
|
316
245
|
// Parser now prohibits bare expressions, so this should never be reached
|
|
317
246
|
const { span } = extractMetadata(s);
|
|
@@ -329,14 +258,14 @@ function lowerWorkflow(stmt) {
|
|
|
329
258
|
const effectCaps = mergeCapabilitySets(steps.map(step => step.effectCaps));
|
|
330
259
|
const retry = stmt.retry
|
|
331
260
|
? { maxAttempts: stmt.retry.maxAttempts, backoff: stmt.retry.backoff }
|
|
332
|
-
:
|
|
333
|
-
const timeout = stmt.timeout ? { milliseconds: stmt.timeout.milliseconds } :
|
|
334
|
-
const workflow =
|
|
261
|
+
: null;
|
|
262
|
+
const timeout = stmt.timeout ? { milliseconds: stmt.timeout.milliseconds } : null;
|
|
263
|
+
const workflow = CoreIR.Workflow(steps, effectCaps, retry, timeout);
|
|
335
264
|
return withOrigin(workflow, stmt);
|
|
336
265
|
}
|
|
337
266
|
function lowerStep(stmt, prevStep) {
|
|
338
267
|
const body = lowerBlock(stmt.body);
|
|
339
|
-
const compensate = stmt.compensate ? lowerBlock(stmt.compensate) :
|
|
268
|
+
const compensate = stmt.compensate ? lowerBlock(stmt.compensate) : null;
|
|
340
269
|
const effectCaps = mergeCapabilitySets([
|
|
341
270
|
collectCapabilitiesFromBlock(body),
|
|
342
271
|
...(compensate ? [collectCapabilitiesFromBlock(compensate)] : []),
|
|
@@ -347,7 +276,7 @@ function lowerStep(stmt, prevStep) {
|
|
|
347
276
|
: prevStep
|
|
348
277
|
? [prevStep]
|
|
349
278
|
: [];
|
|
350
|
-
const step =
|
|
279
|
+
const step = CoreIR.Step(stmt.name, body, effectCaps, compensate, dependencies);
|
|
351
280
|
return withOrigin(step, stmt);
|
|
352
281
|
}
|
|
353
282
|
function mergeCapabilitySets(lists) {
|
|
@@ -386,7 +315,7 @@ function collectCapabilitiesFromBlock(block) {
|
|
|
386
315
|
function lowerCaseBody(body) {
|
|
387
316
|
// Body can be a Return node or a Block
|
|
388
317
|
if (body.kind === 'Return') {
|
|
389
|
-
return withOrigin(
|
|
318
|
+
return withOrigin(CoreIR.Return(lowerExpr(body.expr)), body);
|
|
390
319
|
}
|
|
391
320
|
return lowerBlock(body);
|
|
392
321
|
}
|
|
@@ -474,8 +403,8 @@ function splitUfcsReceiver(target, unresolvedTarget) {
|
|
|
474
403
|
// 注:Java 侧给接收者/方法名的是各自更精确的子 span;此处沿用整体 span,
|
|
475
404
|
// 跨引擎在 `file+line` 口径下一致(同一行),strict 口径下的列差属既有
|
|
476
405
|
// col 口径问题,不在本次范围。
|
|
477
|
-
const receiver =
|
|
478
|
-
const method =
|
|
406
|
+
const receiver = CoreIR.Name(head);
|
|
407
|
+
const method = CoreIR.Name(full.slice(dot + 1));
|
|
479
408
|
const span = target.origin;
|
|
480
409
|
if (span !== undefined) {
|
|
481
410
|
receiver.origin = span;
|
|
@@ -493,19 +422,20 @@ function lowerExpr(e) {
|
|
|
493
422
|
case 'Name':
|
|
494
423
|
return lowerName(e);
|
|
495
424
|
case 'Bool':
|
|
496
|
-
return withOrigin(
|
|
425
|
+
return withOrigin(CoreIR.Bool(e.value), e);
|
|
497
426
|
case 'Int':
|
|
498
|
-
return withOrigin(
|
|
427
|
+
return withOrigin(CoreIR.Int(e.value), e);
|
|
499
428
|
case 'Long':
|
|
500
|
-
return withOrigin(
|
|
429
|
+
return withOrigin(CoreIR.Long(e.value), e);
|
|
501
430
|
case 'Double':
|
|
502
|
-
|
|
431
|
+
// ADR 0055 #18:规范十进制串取自字面量原文,不经二进制浮点(手工构造、没有原文的 AST 退回其数值)
|
|
432
|
+
return withOrigin(CoreIR.Double(canonicalDecimalFromLiteral(e.raw ?? String(e.value))), e);
|
|
503
433
|
case 'Decimal':
|
|
504
|
-
return withOrigin(
|
|
434
|
+
return withOrigin(CoreIR.Decimal(e.value), e);
|
|
505
435
|
case 'String':
|
|
506
|
-
return withOrigin(
|
|
436
|
+
return withOrigin(CoreIR.String(e.value), e);
|
|
507
437
|
case 'Null':
|
|
508
|
-
return withOrigin(
|
|
438
|
+
return withOrigin(CoreIR.Null(), e);
|
|
509
439
|
case 'Call': {
|
|
510
440
|
// ★内置变体的调用形式归一(aster-lang-ts#124):`Some(x)` / `Ok(x)` / `Err(x)` /
|
|
511
441
|
// `None()` 与关键字形式 `some of x` 必须降到**完全相同**的 Core IR 节点。
|
|
@@ -525,14 +455,14 @@ function lowerExpr(e) {
|
|
|
525
455
|
const ctor = e.target.name;
|
|
526
456
|
if (e.args.length === 1) {
|
|
527
457
|
if (ctor === 'Some')
|
|
528
|
-
return withOrigin(
|
|
458
|
+
return withOrigin(CoreIR.Some(lowerExpr(e.args[0])), e);
|
|
529
459
|
if (ctor === 'Ok')
|
|
530
|
-
return withOrigin(
|
|
460
|
+
return withOrigin(CoreIR.Ok(lowerExpr(e.args[0])), e);
|
|
531
461
|
if (ctor === 'Err')
|
|
532
|
-
return withOrigin(
|
|
462
|
+
return withOrigin(CoreIR.Err(lowerExpr(e.args[0])), e);
|
|
533
463
|
}
|
|
534
464
|
if (ctor === 'None' && e.args.length === 0) {
|
|
535
|
-
return withOrigin(
|
|
465
|
+
return withOrigin(CoreIR.None(), e);
|
|
536
466
|
}
|
|
537
467
|
}
|
|
538
468
|
// ★UFCS(接收者转参数):`value.sum(1, 2)` → `sum(value, 1, 2)`。
|
|
@@ -556,127 +486,39 @@ function lowerExpr(e) {
|
|
|
556
486
|
const loweredArgs = e.args.map(lowerExpr);
|
|
557
487
|
const ufcs = splitUfcsReceiver(target, e.target.kind === 'Name' && !e.target.resolved);
|
|
558
488
|
if (ufcs) {
|
|
559
|
-
return withOrigin(
|
|
489
|
+
return withOrigin(CoreIR.Call(ufcs.method, [ufcs.receiver, ...loweredArgs]), e);
|
|
560
490
|
}
|
|
561
|
-
return withOrigin(
|
|
491
|
+
return withOrigin(CoreIR.Call(target, loweredArgs), e);
|
|
562
492
|
}
|
|
563
493
|
case 'Construct':
|
|
564
|
-
return withResolution(withOrigin(
|
|
494
|
+
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
495
|
case 'Ok':
|
|
566
|
-
return withOrigin(
|
|
496
|
+
return withOrigin(CoreIR.Ok(lowerExpr(e.expr)), e);
|
|
567
497
|
case 'Err':
|
|
568
|
-
return withOrigin(
|
|
498
|
+
return withOrigin(CoreIR.Err(lowerExpr(e.expr)), e);
|
|
569
499
|
case 'Some':
|
|
570
|
-
return withOrigin(
|
|
500
|
+
return withOrigin(CoreIR.Some(lowerExpr(e.expr)), e);
|
|
571
501
|
case 'None':
|
|
572
|
-
return withOrigin(
|
|
502
|
+
return withOrigin(CoreIR.None(), e);
|
|
573
503
|
case 'Await':
|
|
574
|
-
return withOrigin(
|
|
504
|
+
return withOrigin(CoreIR.Await(lowerExpr(e.expr)), e);
|
|
575
505
|
case 'IfExpr':
|
|
576
506
|
// ADR 0019 G2b:表达式级 if → Core IR IfExpr(三分支递归 lower)。
|
|
577
|
-
return withOrigin(
|
|
507
|
+
return withOrigin(CoreIR.IfExpr(lowerExpr(e.cond), lowerExpr(e.thenE), lowerExpr(e.elseE)), e);
|
|
578
508
|
case 'ListLit':
|
|
579
509
|
// ADR 0024 C0:列表字面量 → Core IR ListLit(元素递归 lower)。
|
|
580
|
-
return withOrigin(
|
|
510
|
+
return withOrigin(CoreIR.ListLit(e.elements.map(lowerExpr)), e);
|
|
581
511
|
case 'Lambda': {
|
|
582
|
-
//
|
|
583
|
-
//
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
//
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
// Return If x then outer else localA.
|
|
593
|
-
//
|
|
594
|
-
// Java → [outer] TS(修前)→ [outer, localA]
|
|
595
|
-
//
|
|
596
|
-
// captures 不是元数据:Truffle 的 Loader 按它建 FrameDescriptor 并按位置
|
|
597
|
-
// 传实参,多算一个名字就多一个槽位、且 NameNodeEnv 解析不到时会返回
|
|
598
|
-
// **名字本身的字符串**——与本轮修掉的 under-capture 是同一套故障机制。
|
|
599
|
-
const scopes = [new Set(e.params.map(p => p.name))];
|
|
600
|
-
const names = new Set();
|
|
601
|
-
const isBound = (n) => scopes.some(s => s.has(n));
|
|
602
|
-
class CaptureVisitor extends DefaultAstVisitor {
|
|
603
|
-
visitBlock(b, ctx) {
|
|
604
|
-
// 块级作用域:进块压栈、出块弹栈(与 Java 的 traverseBlock 同构)。
|
|
605
|
-
scopes.push(new Set());
|
|
606
|
-
try {
|
|
607
|
-
super.visitBlock(b, ctx);
|
|
608
|
-
}
|
|
609
|
-
finally {
|
|
610
|
-
scopes.pop();
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
visitStatement(s, ctx) {
|
|
614
|
-
if (s.kind === 'Match') {
|
|
615
|
-
// ★Match 的模式会**绑定**新名字,这些名字在该 case 体内不是自由变量。
|
|
616
|
-
// 此前只递归不绑定,于是 `When bound, Return bound.` 里的 bound
|
|
617
|
-
// 被当成捕获(Java 侧 CoreLowering:820-832 有 patternBindings,
|
|
618
|
-
// 两侧因此分叉:Java [] vs TS ["bound"])。
|
|
619
|
-
this.visitExpression(s.expr, ctx);
|
|
620
|
-
for (const c of s.cases) {
|
|
621
|
-
scopes.push(patternBindings(c.pattern));
|
|
622
|
-
try {
|
|
623
|
-
if (c.body.kind === 'Return')
|
|
624
|
-
this.visitExpression(c.body.expr, ctx);
|
|
625
|
-
else
|
|
626
|
-
this.visitBlock(c.body, ctx);
|
|
627
|
-
}
|
|
628
|
-
finally {
|
|
629
|
-
scopes.pop();
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
super.visitStatement(s, ctx);
|
|
635
|
-
// ★先递归再绑定:`Let x be x + 1` 里右侧的 x 指的是**外层**的 x,
|
|
636
|
-
// 先绑定会把它误判成已绑定而漏掉这次捕获。
|
|
637
|
-
if (s.kind === 'Let') {
|
|
638
|
-
scopes[scopes.length - 1].add(s.name);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
visitExpression(ex, ctx) {
|
|
642
|
-
if (ex.kind === 'Lambda') {
|
|
643
|
-
// 嵌套 lambda:内层形参在内层作用域内有效;内层引用的外部变量
|
|
644
|
-
// 必须**穿透**记到外层 captures(外层不捕获,内层就拿不到)。
|
|
645
|
-
scopes.push(new Set(ex.params.map(p => p.name)));
|
|
646
|
-
try {
|
|
647
|
-
this.visitBlock(ex.body, ctx);
|
|
648
|
-
}
|
|
649
|
-
finally {
|
|
650
|
-
scopes.pop();
|
|
651
|
-
}
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
// 以 R1 规范名记录捕获(未解析时即原写法;R2 再按其解析结果改写)
|
|
655
|
-
const captured = ex.kind === 'Name' ? canonicalOf(ex.name, ex.resolved) : '';
|
|
656
|
-
if (ex.kind === 'Name' && !isBound(captured) && !captured.includes('.')) {
|
|
657
|
-
names.add(captured);
|
|
658
|
-
}
|
|
659
|
-
super.visitExpression(ex, ctx);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
new CaptureVisitor().visitBlock(e.body, undefined);
|
|
663
|
-
const captures = Array.from(names);
|
|
664
|
-
const coreParams = e.params.map(p => {
|
|
665
|
-
const param = { name: p.name, type: lowerType(p.type) };
|
|
666
|
-
// 解析器对未标注类型的 lambda 参数同样写入 typeInferred(Parameter),BaseParameter 未声明该字段
|
|
667
|
-
if (p.typeInferred)
|
|
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
|
-
};
|
|
512
|
+
// captures 只列外层局部(ADR 0056 §4.2):先取 lambda 所在位置可见的局部,再在 lambda 形参作用域内降级函数体,
|
|
513
|
+
// 最后在降级后的 IR 上判定(方法调用已改写,与 aster-lang-core 一致)
|
|
514
|
+
const outer = visibleLocals();
|
|
515
|
+
const coreParams = e.params.map(p => CoreIR.Param(p.name, lowerType(p.type, NO_TYPE_VARS, p), [],
|
|
516
|
+
// 解析器对未标注类型的 lambda 参数同样写入 typeInferred(Parameter),BaseParameter 未声明该字段
|
|
517
|
+
p.typeInferred === true));
|
|
518
|
+
const paramNames = e.params.map(p => p.name);
|
|
519
|
+
const body = inLocalScope(paramNames, () => lowerBlock(e.body));
|
|
520
|
+
const captures = collectLambdaCaptures(paramNames, body, outer);
|
|
521
|
+
const lambda = CoreIR.Lambda(coreParams, lowerType(e.retType, NO_TYPE_VARS, e), body, captures);
|
|
680
522
|
return withOrigin(lambda, e);
|
|
681
523
|
}
|
|
682
524
|
default: {
|
|
@@ -690,14 +532,17 @@ function lowerExpr(e) {
|
|
|
690
532
|
function lowerPattern(p) {
|
|
691
533
|
switch (p.kind) {
|
|
692
534
|
case 'PatternNull':
|
|
693
|
-
return withOrigin(
|
|
535
|
+
return withOrigin(CoreIR.PatNull(), p);
|
|
694
536
|
case 'PatternInt':
|
|
695
|
-
return withOrigin(
|
|
537
|
+
return withOrigin(CoreIR.PatInt(p.value), p);
|
|
696
538
|
case 'PatternCtor':
|
|
697
539
|
return lowerPatternCtor(p);
|
|
698
540
|
case 'PatternName': {
|
|
541
|
+
// 裸的关键词构造器(`When None`)是 0 参变体模式(ADR 0055 #16),与 Java 的裸名构造器同形
|
|
542
|
+
if (KEYWORD_CTORS.has(p.name))
|
|
543
|
+
return withOrigin(CoreIR.PatCtor(p.name, []), p);
|
|
699
544
|
// 模式名可能是期望枚举下的成员(ADR 0051 裁决 R12),由 R2 判定
|
|
700
|
-
const pat = withOrigin(
|
|
545
|
+
const pat = withOrigin(CoreIR.PatName(p.name), p);
|
|
701
546
|
markForResolution(pat, { written: p.name });
|
|
702
547
|
return pat;
|
|
703
548
|
}
|
|
@@ -709,9 +554,14 @@ function lowerPattern(p) {
|
|
|
709
554
|
}
|
|
710
555
|
}
|
|
711
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* 构造器模式(ADR 0055 #15):只用 args。`Ok(x)` 的各个名字与 Java AstBuilder 一样作为嵌套的名字模式
|
|
559
|
+
* 降级(各取自己的 span,没有时取构造器位置),由 R2 判定成员还是绑定;嵌套模式(AST 的 args)照常降级。
|
|
560
|
+
*/
|
|
712
561
|
function lowerPatternCtor(p) {
|
|
713
|
-
const
|
|
714
|
-
const
|
|
562
|
+
const named = (p.names ?? []).map((n, i) => ({ kind: 'PatternName', name: n, span: p.nameSpans?.[i] ?? p.span }));
|
|
563
|
+
const args = [...named, ...(p.args ?? [])].map(pp => lowerPattern(pp));
|
|
564
|
+
const pat = withResolution(withOrigin(CoreIR.PatCtor(canonicalOf(p.typeName, p.resolved), args), p), p.resolved);
|
|
715
565
|
// 主语类型在 R1 未知的用户构造器留给 R2;关键词构造器不查词汇
|
|
716
566
|
if (!p.resolved && !KEYWORD_CTORS.has(p.typeName))
|
|
717
567
|
markForResolution(pat, { written: p.typeName });
|
|
@@ -722,7 +572,7 @@ function lowerPatternCtor(p) {
|
|
|
722
572
|
* 并记下 R1 的角色;R1 未决定的点分名(字段路径、限定调用)同样交给 R2。
|
|
723
573
|
*/
|
|
724
574
|
function lowerName(e) {
|
|
725
|
-
const node = withResolution(withOrigin(
|
|
575
|
+
const node = withResolution(withOrigin(CoreIR.Name(canonicalOf(e.name, e.resolved)), e), e.resolved);
|
|
726
576
|
if (!e.name.includes('.')) {
|
|
727
577
|
markForResolution(node, e.resolved ? { written: e.name, r1Role: e.resolved.role } : { written: e.name });
|
|
728
578
|
}
|
|
@@ -732,39 +582,43 @@ function lowerName(e) {
|
|
|
732
582
|
return node;
|
|
733
583
|
}
|
|
734
584
|
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;
|
|
585
|
+
return { file, start: span.start, end: span.end, written: null, role: null };
|
|
745
586
|
}
|
|
746
|
-
|
|
587
|
+
const NO_TYPE_VARS = new Set();
|
|
588
|
+
/**
|
|
589
|
+
* 类型降级。`vars` 为函数声明的类型参数:其中的名字降为 TypeVar。每个类型节点都带 origin
|
|
590
|
+
* (ADR 0055 #17):取类型自身的 span,没有时(解析器合成的推断类型)取 fallback 节点的位置。
|
|
591
|
+
* 签名中被改写的写法照常记录 written / role(ADR 0051 §4)。
|
|
592
|
+
*/
|
|
593
|
+
function lowerType(t, vars, ...fallback) {
|
|
594
|
+
const sub = (x) => lowerType(x, vars, t, ...fallback);
|
|
595
|
+
const at = (node) => withOrigin(node, t, ...fallback);
|
|
747
596
|
switch (t.kind) {
|
|
748
597
|
case 'TypeName':
|
|
749
|
-
return
|
|
598
|
+
return vars.has(t.name)
|
|
599
|
+
? at(CoreIR.TypeVar(t.name))
|
|
600
|
+
: withResolution(at(CoreIR.TypeName(canonicalOf(t.name, t.resolved))), t.resolved);
|
|
750
601
|
case 'TypeVar':
|
|
751
|
-
return
|
|
602
|
+
return at(CoreIR.TypeVar(t.name));
|
|
603
|
+
case 'EffectVar':
|
|
604
|
+
// v2 没有效应变量类型节点(schema Type 联合不含 EffectVar);解析器不产出它,手工 AST 按类型变量处理
|
|
605
|
+
return at(CoreIR.TypeVar(t.name));
|
|
752
606
|
case 'TypeApp':
|
|
753
|
-
return withResolution(
|
|
607
|
+
return withResolution(at(CoreIR.TypeApp(canonicalOf(t.base, t.resolved), t.args.map(sub))), t.resolved);
|
|
754
608
|
case 'Maybe':
|
|
755
|
-
return
|
|
609
|
+
return at(CoreIR.Maybe(sub(t.type)));
|
|
756
610
|
case 'Option':
|
|
757
|
-
return
|
|
611
|
+
return at(CoreIR.Option(sub(t.type)));
|
|
758
612
|
case 'Result':
|
|
759
|
-
return
|
|
613
|
+
return at(CoreIR.Result(sub(t.ok), sub(t.err)));
|
|
760
614
|
case 'List':
|
|
761
|
-
return
|
|
615
|
+
return at(CoreIR.List(sub(t.type)));
|
|
762
616
|
case 'Map':
|
|
763
|
-
return
|
|
617
|
+
return at(CoreIR.Map(sub(t.key), sub(t.val)));
|
|
764
618
|
case 'TypePii':
|
|
765
|
-
return
|
|
619
|
+
return at(CoreIR.Pii(sub(t.baseType), t.sensitivity, t.category));
|
|
766
620
|
case 'FuncType':
|
|
767
|
-
return
|
|
621
|
+
return at(CoreIR.FuncType(t.params.map(sub), sub(t.ret)));
|
|
768
622
|
default: {
|
|
769
623
|
const { span } = extractMetadata(t);
|
|
770
624
|
const kind = t.kind;
|
|
@@ -773,48 +627,4 @@ function lowerType(t) {
|
|
|
773
627
|
}
|
|
774
628
|
}
|
|
775
629
|
}
|
|
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
630
|
//# sourceMappingURL=lower_to_core.js.map
|