@loopdive/js2 0.57.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 +1425 -0
- package/LICENSE +189 -0
- package/README.md +451 -0
- package/dist/checker/index.d.ts +117 -0
- package/dist/checker/language-service.d.ts +39 -0
- package/dist/checker/node-capability-map.d.ts +63 -0
- package/dist/checker/type-mapper.d.ts +84 -0
- package/dist/cjs-rewrite.d.ts +19 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +363 -0
- package/dist/codegen/accessor-driver.d.ts +97 -0
- package/dist/codegen/any-helpers.d.ts +72 -0
- package/dist/codegen/array-element-typing.d.ts +46 -0
- package/dist/codegen/array-holes.d.ts +69 -0
- package/dist/codegen/array-methods.d.ts +68 -0
- package/dist/codegen/array-object-proto.d.ts +64 -0
- package/dist/codegen/array-reduce-fusion.d.ts +31 -0
- package/dist/codegen/array-to-primitive.d.ts +28 -0
- package/dist/codegen/async-cps.d.ts +239 -0
- package/dist/codegen/async-scheduler.d.ts +349 -0
- package/dist/codegen/binary-ops.d.ts +78 -0
- package/dist/codegen/binding-info.d.ts +31 -0
- package/dist/codegen/builtin-scaffold.d.ts +98 -0
- package/dist/codegen/builtin-static-globals.d.ts +8 -0
- package/dist/codegen/builtin-tags.d.ts +189 -0
- package/dist/codegen/case-convert-native.d.ts +12 -0
- package/dist/codegen/case-tables.d.ts +4 -0
- package/dist/codegen/class-bodies.d.ts +41 -0
- package/dist/codegen/class-member-keys.d.ts +33 -0
- package/dist/codegen/class-to-primitive.d.ts +39 -0
- package/dist/codegen/closed-method-dispatch.d.ts +42 -0
- package/dist/codegen/closures.d.ts +285 -0
- package/dist/codegen/coercion-engine.d.ts +154 -0
- package/dist/codegen/coercion-plan.d.ts +29 -0
- package/dist/codegen/context/bodies.d.ts +4 -0
- package/dist/codegen/context/create-context.d.ts +4 -0
- package/dist/codegen/context/errors.d.ts +39 -0
- package/dist/codegen/context/locals.d.ts +69 -0
- package/dist/codegen/context/source-pos.d.ts +5 -0
- package/dist/codegen/context/speculative.d.ts +95 -0
- package/dist/codegen/context/types.d.ts +1936 -0
- package/dist/codegen/custom-iterable.d.ts +34 -0
- package/dist/codegen/dataview-native.d.ts +51 -0
- package/dist/codegen/date-parse-native.d.ts +13 -0
- package/dist/codegen/dead-elimination.d.ts +26 -0
- package/dist/codegen/declarations.d.ts +147 -0
- package/dist/codegen/deno-api.d.ts +11 -0
- package/dist/codegen/destructuring-params.d.ts +102 -0
- package/dist/codegen/dyn-read.d.ts +26 -0
- package/dist/codegen/eval-tiering.d.ts +19 -0
- package/dist/codegen/expressions/assignment.d.ts +61 -0
- package/dist/codegen/expressions/builtins.d.ts +26 -0
- package/dist/codegen/expressions/calls-closures.d.ts +54 -0
- package/dist/codegen/expressions/calls-guards.d.ts +49 -0
- package/dist/codegen/expressions/calls-optional.d.ts +4 -0
- package/dist/codegen/expressions/calls.d.ts +83 -0
- package/dist/codegen/expressions/eval-inline.d.ts +24 -0
- package/dist/codegen/expressions/extern.d.ts +67 -0
- package/dist/codegen/expressions/fnctor-prototype.d.ts +52 -0
- package/dist/codegen/expressions/helpers.d.ts +212 -0
- package/dist/codegen/expressions/identifiers.d.ts +57 -0
- package/dist/codegen/expressions/late-imports.d.ts +81 -0
- package/dist/codegen/expressions/logical-ops.d.ts +18 -0
- package/dist/codegen/expressions/misc.d.ts +27 -0
- package/dist/codegen/expressions/new-super.d.ts +25 -0
- package/dist/codegen/expressions/promise-subclass.d.ts +38 -0
- package/dist/codegen/expressions/proto-override.d.ts +63 -0
- package/dist/codegen/expressions/unary-updates.d.ts +21 -0
- package/dist/codegen/expressions/unary.d.ts +6 -0
- package/dist/codegen/expressions.d.ts +31 -0
- package/dist/codegen/fallback-telemetry.d.ts +53 -0
- package/dist/codegen/fixups.d.ts +80 -0
- package/dist/codegen/fmod.d.ts +10 -0
- package/dist/codegen/fnctor-escape-gate.d.ts +92 -0
- package/dist/codegen/function-body.d.ts +52 -0
- package/dist/codegen/generators-native.d.ts +92 -0
- package/dist/codegen/helpers/body-references-own-this.d.ts +22 -0
- package/dist/codegen/helpers/body-uses-arguments.d.ts +12 -0
- package/dist/codegen/helpers/is-strict-function.d.ts +52 -0
- package/dist/codegen/host-import-allowlist.d.ts +140 -0
- package/dist/codegen/index.d.ts +500 -0
- package/dist/codegen/ir-tail-call.d.ts +8 -0
- package/dist/codegen/iterator-native.d.ts +44 -0
- package/dist/codegen/json-codec-native.d.ts +78 -0
- package/dist/codegen/json-runtime.d.ts +35 -0
- package/dist/codegen/json-standalone.d.ts +25 -0
- package/dist/codegen/linear-uint8-analysis.d.ts +46 -0
- package/dist/codegen/linear-uint8-arena.d.ts +7 -0
- package/dist/codegen/linear-uint8-codegen.d.ts +103 -0
- package/dist/codegen/linear-uint8-signatures.d.ts +26 -0
- package/dist/codegen/literals.d.ts +115 -0
- package/dist/codegen/map-runtime.d.ts +142 -0
- package/dist/codegen/math-helpers.d.ts +7 -0
- package/dist/codegen/member-get-dispatch.d.ts +42 -0
- package/dist/codegen/member-set-dispatch.d.ts +28 -0
- package/dist/codegen/native-proto.d.ts +98 -0
- package/dist/codegen/native-regex.d.ts +158 -0
- package/dist/codegen/native-strings.d.ts +146 -0
- package/dist/codegen/new-target.d.ts +30 -0
- package/dist/codegen/node-fs-api.d.ts +47 -0
- package/dist/codegen/number-format-native.d.ts +9 -0
- package/dist/codegen/number-ryu.d.ts +27 -0
- package/dist/codegen/object-ops.d.ts +94 -0
- package/dist/codegen/object-runtime.d.ts +171 -0
- package/dist/codegen/parse-number-native.d.ts +10 -0
- package/dist/codegen/peephole.d.ts +6 -0
- package/dist/codegen/property-access.d.ts +294 -0
- package/dist/codegen/raw-wasi-api.d.ts +13 -0
- package/dist/codegen/regex/bytecode.d.ts +140 -0
- package/dist/codegen/regex/casefold.d.ts +41 -0
- package/dist/codegen/regex/compile.d.ts +51 -0
- package/dist/codegen/regex/parse.d.ts +76 -0
- package/dist/codegen/regex/unicode.d.ts +42 -0
- package/dist/codegen/regex/vm.d.ts +24 -0
- package/dist/codegen/regexp-standalone.d.ts +350 -0
- package/dist/codegen/registry/error-types.d.ts +38 -0
- package/dist/codegen/registry/imports.d.ts +46 -0
- package/dist/codegen/registry/types.d.ts +59 -0
- package/dist/codegen/set-algebra.d.ts +17 -0
- package/dist/codegen/set-runtime.d.ts +74 -0
- package/dist/codegen/shared.d.ts +111 -0
- package/dist/codegen/stack-balance.d.ts +43 -0
- package/dist/codegen/statements/control-flow.d.ts +25 -0
- package/dist/codegen/statements/destructuring.d.ts +177 -0
- package/dist/codegen/statements/exceptions.d.ts +11 -0
- package/dist/codegen/statements/functions.d.ts +1 -0
- package/dist/codegen/statements/index.d.ts +1 -0
- package/dist/codegen/statements/loops.d.ts +7 -0
- package/dist/codegen/statements/nested-declarations.d.ts +78 -0
- package/dist/codegen/statements/shared.d.ts +38 -0
- package/dist/codegen/statements/tdz.d.ts +43 -0
- package/dist/codegen/statements/variables.d.ts +3 -0
- package/dist/codegen/statements.d.ts +9 -0
- package/dist/codegen/string-builder.d.ts +131 -0
- package/dist/codegen/string-ops.d.ts +87 -0
- package/dist/codegen/struct-accessor-closure.d.ts +36 -0
- package/dist/codegen/symbol-native.d.ts +55 -0
- package/dist/codegen/temporal-native.d.ts +8 -0
- package/dist/codegen/timsort.d.ts +2 -0
- package/dist/codegen/type-coercion.d.ts +123 -0
- package/dist/codegen/typeof-delete.d.ts +38 -0
- package/dist/codegen/uri-encoding-native.d.ts +33 -0
- package/dist/codegen/value-tags.d.ts +74 -0
- package/dist/codegen/walk-instructions.d.ts +20 -0
- package/dist/codegen/weak-collections-runtime.d.ts +16 -0
- package/dist/codegen/with-scope.d.ts +106 -0
- package/dist/codegen-linear/c-abi.d.ts +74 -0
- package/dist/codegen-linear/context.d.ts +86 -0
- package/dist/codegen-linear/index.d.ts +28 -0
- package/dist/codegen-linear/layout.d.ts +39 -0
- package/dist/codegen-linear/runtime.d.ts +161 -0
- package/dist/codegen-linear/simd.d.ts +7 -0
- package/dist/compiler/define-substitution.d.ts +27 -0
- package/dist/compiler/early-errors/assignment.d.ts +26 -0
- package/dist/compiler/early-errors/context.d.ts +17 -0
- package/dist/compiler/early-errors/duplicates.d.ts +20 -0
- package/dist/compiler/early-errors/index.d.ts +11 -0
- package/dist/compiler/early-errors/labels.d.ts +13 -0
- package/dist/compiler/early-errors/module-rules.d.ts +36 -0
- package/dist/compiler/early-errors/node-checks.d.ts +7 -0
- package/dist/compiler/early-errors/predicates.d.ts +140 -0
- package/dist/compiler/early-errors/tdz.d.ts +17 -0
- package/dist/compiler/import-manifest.d.ts +18 -0
- package/dist/compiler/output.d.ts +46 -0
- package/dist/compiler/validation.d.ts +45 -0
- package/dist/compiler.d.ts +48 -0
- package/dist/define-substitution-BcUeKC2A.js +109 -0
- package/dist/emit/binary.d.ts +50 -0
- package/dist/emit/c-header.d.ts +23 -0
- package/dist/emit/canonical-recgroup.d.ts +86 -0
- package/dist/emit/encoder.d.ts +28 -0
- package/dist/emit/object.d.ts +14 -0
- package/dist/emit/opcodes.d.ts +464 -0
- package/dist/emit/sourcemap.d.ts +33 -0
- package/dist/emit/wat.d.ts +6 -0
- package/dist/env.d.ts +46 -0
- package/dist/import-resolver.d.ts +68 -0
- package/dist/index.d.ts +486 -0
- package/dist/index.js +755 -0
- package/dist/ir/alloc-registry.d.ts +75 -0
- package/dist/ir/analysis/encoding.d.ts +38 -0
- package/dist/ir/analysis/escape.d.ts +32 -0
- package/dist/ir/analysis/lattice.d.ts +72 -0
- package/dist/ir/analysis/ownership.d.ts +31 -0
- package/dist/ir/analysis/stack-alloc.d.ts +20 -0
- package/dist/ir/backend/bytecode-emitter.d.ts +237 -0
- package/dist/ir/backend/bytecode-vm.d.ts +74 -0
- package/dist/ir/backend/emitter.d.ts +121 -0
- package/dist/ir/backend/handles.d.ts +133 -0
- package/dist/ir/backend/legality.d.ts +9 -0
- package/dist/ir/backend/linear-emitter.d.ts +41 -0
- package/dist/ir/backend/wasmgc-emitter.d.ts +43 -0
- package/dist/ir/builder.d.ts +401 -0
- package/dist/ir/from-ast.d.ts +192 -0
- package/dist/ir/index.d.ts +16 -0
- package/dist/ir/integration.d.ts +27 -0
- package/dist/ir/lower.d.ts +203 -0
- package/dist/ir/nodes.d.ts +1452 -0
- package/dist/ir/passes/alloc-discipline.d.ts +19 -0
- package/dist/ir/passes/constant-fold.d.ts +7 -0
- package/dist/ir/passes/dead-code.d.ts +18 -0
- package/dist/ir/passes/inline-small.d.ts +7 -0
- package/dist/ir/passes/monomorphize.d.ts +21 -0
- package/dist/ir/passes/simplify-cfg.d.ts +19 -0
- package/dist/ir/passes/tagged-union-types.d.ts +45 -0
- package/dist/ir/passes/tagged-unions.d.ts +22 -0
- package/dist/ir/propagate.d.ts +135 -0
- package/dist/ir/select.d.ts +81 -0
- package/dist/ir/types.d.ts +832 -0
- package/dist/ir/verify-alloc.d.ts +18 -0
- package/dist/ir/verify.d.ts +7 -0
- package/dist/link/index.d.ts +11 -0
- package/dist/link/isolation.d.ts +24 -0
- package/dist/link/linker.d.ts +37 -0
- package/dist/link/reader.d.ts +158 -0
- package/dist/link/resolver.d.ts +19 -0
- package/dist/optimize.d.ts +54 -0
- package/dist/optimize.js +262 -0
- package/dist/position-map.d.ts +64 -0
- package/dist/process-stdin-prelude.d.ts +16 -0
- package/dist/resolve.d.ts +82 -0
- package/dist/runtime/builtins.d.ts +1 -0
- package/dist/runtime-C-4q_KwU.js +164438 -0
- package/dist/runtime-containment.d.ts +6 -0
- package/dist/runtime-eval.d.ts +132 -0
- package/dist/runtime-instantiate.d.ts +16 -0
- package/dist/runtime.d.ts +128 -0
- package/dist/runtime.js +12 -0
- package/dist/shape-inference.d.ts +20 -0
- package/dist/treeshake.d.ts +17 -0
- package/dist/ts-api.d.ts +30 -0
- package/dist/wit-generator.d.ts +18 -0
- package/package.json +187 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { IrBinop, IrBlockId, IrClassShape, IrClosureSignature, IrConst, IrFuncRef, IrFunction, IrGlobalRef, IrInstr, IrObjectShape, IrTerminator, IrType, IrUnop, IrValueId } from './nodes.js';
|
|
2
|
+
import { AllocSiteRegistry } from './alloc-registry.js';
|
|
3
|
+
import { Instr, ValType } from './types.js';
|
|
4
|
+
export declare class IrFunctionBuilder {
|
|
5
|
+
private readonly name;
|
|
6
|
+
private readonly resultTypes;
|
|
7
|
+
private readonly exported;
|
|
8
|
+
private readonly allocRegistry?;
|
|
9
|
+
private readonly allocator;
|
|
10
|
+
private readonly params;
|
|
11
|
+
private readonly finished;
|
|
12
|
+
private readonly valueTypes;
|
|
13
|
+
private current;
|
|
14
|
+
private nextBlockId;
|
|
15
|
+
private readonly reserved;
|
|
16
|
+
private readonly slotDefs;
|
|
17
|
+
private bodyBuffer;
|
|
18
|
+
private funcKind;
|
|
19
|
+
private generatorBufferSlot;
|
|
20
|
+
constructor(name: string, resultTypes: readonly IrType[], exported?: boolean, allocRegistry?: AllocSiteRegistry | undefined);
|
|
21
|
+
/**
|
|
22
|
+
* #1586: mint a stable allocation-site id for a value-creating instr. Returns
|
|
23
|
+
* `undefined` when no registry is wired (test builders), in which case the
|
|
24
|
+
* instr's `alloc` field stays absent — lowering ignores it either way.
|
|
25
|
+
*/
|
|
26
|
+
private allocId;
|
|
27
|
+
addParam(name: string, type: IrType): IrValueId;
|
|
28
|
+
openBlock(blockArgTypes?: readonly IrType[]): IrBlockId;
|
|
29
|
+
/**
|
|
30
|
+
* Allocate a block ID without opening it — for forward references in a
|
|
31
|
+
* terminator that must branch to a block we haven't emitted yet. The caller
|
|
32
|
+
* MUST later activate it with `openReservedBlock(id)` before `finish()`.
|
|
33
|
+
*/
|
|
34
|
+
reserveBlockId(): IrBlockId;
|
|
35
|
+
/**
|
|
36
|
+
* Activate a previously reserved block ID as the current open block.
|
|
37
|
+
*/
|
|
38
|
+
openReservedBlock(id: IrBlockId, blockArgTypes?: readonly IrType[]): void;
|
|
39
|
+
private makeOpen;
|
|
40
|
+
blockArg(slot: number): IrValueId;
|
|
41
|
+
terminate(terminator: IrTerminator): void;
|
|
42
|
+
emitConst(value: IrConst, resultType: IrType): IrValueId;
|
|
43
|
+
emitCall(target: IrFuncRef, args: readonly IrValueId[], resultType: IrType | null): IrValueId | null;
|
|
44
|
+
emitGlobalGet(target: IrGlobalRef, resultType: IrType): IrValueId;
|
|
45
|
+
emitGlobalSet(target: IrGlobalRef, value: IrValueId): void;
|
|
46
|
+
emitBinary(op: IrBinop, lhs: IrValueId, rhs: IrValueId, resultType: IrType): IrValueId;
|
|
47
|
+
emitUnary(op: IrUnop, rand: IrValueId, resultType: IrType): IrValueId;
|
|
48
|
+
emitSelect(condition: IrValueId, whenTrue: IrValueId, whenFalse: IrValueId, resultType: IrType): IrValueId;
|
|
49
|
+
/**
|
|
50
|
+
* (#1392) Emit `unary("ref.is_null", val)` — tests a Wasm reference for
|
|
51
|
+
* null. Result is `i32` (1 if null, 0 otherwise). The architect-spec
|
|
52
|
+
* name `emitRefIsNull` mirrors the existing `emitUnary` /
|
|
53
|
+
* `emitBinary` / `emitSelect` family and surfaces the underlying op
|
|
54
|
+
* at the call site so #1375's optional-chain lowering reads naturally
|
|
55
|
+
* (`cx.builder.emitRefIsNull(recv)`).
|
|
56
|
+
*
|
|
57
|
+
* `val`'s IrType MUST be a `val`-kind wrapping a Wasm reference type
|
|
58
|
+
* (`ref` / `ref_null` / `externref` / `funcref`); the verifier and the
|
|
59
|
+
* Wasm validator together reject other operand shapes.
|
|
60
|
+
*/
|
|
61
|
+
emitRefIsNull(val: IrValueId): IrValueId;
|
|
62
|
+
/**
|
|
63
|
+
* (#1392) Emit a value-producing short-circuiting if/else. Both `then`
|
|
64
|
+
* and `else` are pre-collected instruction buffers (typically built
|
|
65
|
+
* via `collectBodyInstrs(...)`); the lowerer emits a Wasm
|
|
66
|
+
* `if (result T) ... else ... end` so only the matching branch
|
|
67
|
+
* executes.
|
|
68
|
+
*
|
|
69
|
+
* `thenValue` / `elseValue` are SSA value IDs DEFINED INSIDE the
|
|
70
|
+
* corresponding arm — the lowerer emits each arm's instruction tree
|
|
71
|
+
* and leaves the carrier value on the Wasm stack at end-of-arm; the
|
|
72
|
+
* post-block `local.set` binds the if-instr's result to whichever
|
|
73
|
+
* carrier ran.
|
|
74
|
+
*/
|
|
75
|
+
emitIfElse(args: {
|
|
76
|
+
cond: IrValueId;
|
|
77
|
+
then: readonly IrInstr[];
|
|
78
|
+
thenValue: IrValueId;
|
|
79
|
+
else: readonly IrInstr[];
|
|
80
|
+
elseValue: IrValueId;
|
|
81
|
+
resultType: IrType;
|
|
82
|
+
}): IrValueId;
|
|
83
|
+
emitStringConst(value: string): IrValueId;
|
|
84
|
+
emitStringConcat(lhs: IrValueId, rhs: IrValueId): IrValueId;
|
|
85
|
+
emitStringEq(lhs: IrValueId, rhs: IrValueId, negate: boolean): IrValueId;
|
|
86
|
+
emitStringLen(value: IrValueId): IrValueId;
|
|
87
|
+
/**
|
|
88
|
+
* Emit `object.new` to materialize an object literal. The caller is
|
|
89
|
+
* responsible for canonicalizing `shape.fields` (sorted ascending by
|
|
90
|
+
* name) and for ensuring `values[i]` matches `shape.fields[i].type`.
|
|
91
|
+
* The arity check is enforced here so a stray slice-2 selector miss
|
|
92
|
+
* surfaces immediately instead of as a malformed Wasm struct.new.
|
|
93
|
+
*/
|
|
94
|
+
emitObjectNew(shape: IrObjectShape, values: readonly IrValueId[]): IrValueId;
|
|
95
|
+
/**
|
|
96
|
+
* Emit `object.get` to read a named field. Caller passes the field's
|
|
97
|
+
* declared IrType so the SSA def's static type matches the shape's
|
|
98
|
+
* field type without a second lookup at lowering time.
|
|
99
|
+
*/
|
|
100
|
+
emitObjectGet(value: IrValueId, name: string, resultType: IrType): IrValueId;
|
|
101
|
+
/**
|
|
102
|
+
* Emit `object.set` to write a named field. Void result.
|
|
103
|
+
*/
|
|
104
|
+
emitObjectSet(value: IrValueId, name: string, newValue: IrValueId): void;
|
|
105
|
+
/**
|
|
106
|
+
* Materialize a closure value. Caller is responsible for ensuring
|
|
107
|
+
* `captureFieldTypes[i]` matches the IR type of the SSA value at
|
|
108
|
+
* `captures[i]`. The arity check below catches mistakes early.
|
|
109
|
+
*/
|
|
110
|
+
emitClosureNew(liftedFunc: IrFuncRef, signature: IrClosureSignature, captureFieldTypes: readonly IrType[], captures: readonly IrValueId[]): IrValueId;
|
|
111
|
+
/**
|
|
112
|
+
* Read a capture field from the implicit `__self` closure struct.
|
|
113
|
+
* Caller passes the field's IrType so the SSA def's static type is
|
|
114
|
+
* stable without a second resolver lookup at lowering time.
|
|
115
|
+
*/
|
|
116
|
+
emitClosureCap(self: IrValueId, index: number, resultType: IrType): IrValueId;
|
|
117
|
+
/**
|
|
118
|
+
* Invoke a closure value. Caller passes `resultType` (= signature.returnType)
|
|
119
|
+
* for the SSA def.
|
|
120
|
+
*/
|
|
121
|
+
emitClosureCall(callee: IrValueId, args: readonly IrValueId[], resultType: IrType): IrValueId;
|
|
122
|
+
/**
|
|
123
|
+
* Wrap a primitive value in a fresh ref cell. The SSA def's type is
|
|
124
|
+
* `{ kind: "boxed", inner }`. #1926 — the `boxed` IrType carries an IrType
|
|
125
|
+
* `inner`, so the ValType arg is wrapped with `irVal` here; the resolver
|
|
126
|
+
* unwraps it back to the ValType at lowering time.
|
|
127
|
+
*/
|
|
128
|
+
emitRefCellNew(value: IrValueId, inner: ValType): IrValueId;
|
|
129
|
+
/**
|
|
130
|
+
* Read the inner value out of a ref cell. The SSA def's type is the cell's
|
|
131
|
+
* `inner` IrType. #1926 — `inner` is now the `boxed` IrType's `inner`
|
|
132
|
+
* field (an IrType), passed straight through as the result type. Callers
|
|
133
|
+
* pass the same `inner` they used for the matching `boxed` cell (for V1
|
|
134
|
+
* primitive cells this is `irVal(scalar)`, so the result type is
|
|
135
|
+
* `{ kind: "val", val: scalar }` exactly as before).
|
|
136
|
+
*/
|
|
137
|
+
emitRefCellGet(cell: IrValueId, inner: IrType): IrValueId;
|
|
138
|
+
/**
|
|
139
|
+
* Write a new value through the ref cell. Void result.
|
|
140
|
+
*/
|
|
141
|
+
emitRefCellSet(cell: IrValueId, value: IrValueId): void;
|
|
142
|
+
/**
|
|
143
|
+
* Phase 1 escape hatch — emit raw backend ops with a stated stack delta.
|
|
144
|
+
* Verifier requires stackDelta to match the effective push count.
|
|
145
|
+
*/
|
|
146
|
+
emitRawWasm(ops: readonly Instr[], stackDelta: number): void;
|
|
147
|
+
/**
|
|
148
|
+
* Emit `class.new` to construct a class instance via the legacy-registered
|
|
149
|
+
* `<className>_new` constructor. Caller is responsible for ensuring
|
|
150
|
+
* `args[i]` matches `shape.constructorParams[i]`. The arity check below
|
|
151
|
+
* catches mistakes early.
|
|
152
|
+
*/
|
|
153
|
+
emitClassNew(shape: IrClassShape, args: readonly IrValueId[]): IrValueId;
|
|
154
|
+
/**
|
|
155
|
+
* Emit `class.get` to read a named field on a class instance. Caller
|
|
156
|
+
* passes the field's IrType (looked up against the receiver's shape) so
|
|
157
|
+
* the SSA def's static type matches without a second resolver lookup.
|
|
158
|
+
*/
|
|
159
|
+
emitClassGet(value: IrValueId, fieldName: string, resultType: IrType): IrValueId;
|
|
160
|
+
/**
|
|
161
|
+
* Emit `class.set` to write a named field on a class instance. Void
|
|
162
|
+
* result. The receiver's shape must contain `fieldName`; arity / type
|
|
163
|
+
* checks happen at the AST→IR layer.
|
|
164
|
+
*/
|
|
165
|
+
emitClassSet(value: IrValueId, fieldName: string, newValue: IrValueId): void;
|
|
166
|
+
/**
|
|
167
|
+
* Emit `class.call` to invoke an instance method. `resultType` is the
|
|
168
|
+
* method descriptor's `returnType` (or `null` for void). Returns `null`
|
|
169
|
+
* for void methods — callers using the result in expression position
|
|
170
|
+
* must reject `null` themselves.
|
|
171
|
+
*/
|
|
172
|
+
emitClassCall(receiver: IrValueId, methodName: string, args: readonly IrValueId[], resultType: IrType | null): IrValueId | null;
|
|
173
|
+
/**
|
|
174
|
+
* Slice 10 (#1169i) — emit `extern.new` for `new ExternClass(args)`.
|
|
175
|
+
* Result type is `{ kind: "extern", className }` — opaque externref
|
|
176
|
+
* carrying the class identity statically.
|
|
177
|
+
*/
|
|
178
|
+
emitExternNew(className: string, args: readonly IrValueId[]): IrValueId;
|
|
179
|
+
/**
|
|
180
|
+
* Slice 10 (#1169i) — emit `extern.call` for `<recv>.<method>(args)` on
|
|
181
|
+
* an extern-class receiver. `resultType` is the method's registered
|
|
182
|
+
* result IrType (or `null` for void). Returns `null` for void methods.
|
|
183
|
+
*/
|
|
184
|
+
emitExternCall(className: string, method: string, receiver: IrValueId, args: readonly IrValueId[], resultType: IrType | null): IrValueId | null;
|
|
185
|
+
/**
|
|
186
|
+
* Slice 10 (#1169i) — emit `extern.prop` for a property read on an
|
|
187
|
+
* extern-class receiver.
|
|
188
|
+
*/
|
|
189
|
+
emitExternProp(className: string, property: string, receiver: IrValueId, resultType: IrType): IrValueId;
|
|
190
|
+
/**
|
|
191
|
+
* Slice 10 (#1169i) — emit `extern.propSet` for a property write on an
|
|
192
|
+
* extern-class receiver. Void result.
|
|
193
|
+
*/
|
|
194
|
+
emitExternPropSet(className: string, property: string, receiver: IrValueId, value: IrValueId): void;
|
|
195
|
+
/**
|
|
196
|
+
* Slice 10 (#1169i) — emit `extern.regex` for a `/pattern/flags`
|
|
197
|
+
* RegExp literal. Result is `{ kind: "extern", className: "RegExp" }`
|
|
198
|
+
* (opaque externref handle to the RegExp instance).
|
|
199
|
+
*/
|
|
200
|
+
emitRegExpLiteral(pattern: string, flags: string): IrValueId;
|
|
201
|
+
typeOf(value: IrValueId): IrType;
|
|
202
|
+
finish(closureSubtype?: {
|
|
203
|
+
readonly signature: IrClosureSignature;
|
|
204
|
+
readonly captureFieldTypes: readonly IrType[];
|
|
205
|
+
}): IrFunction;
|
|
206
|
+
/**
|
|
207
|
+
* Slice 7a (#1169f): set the function kind. Must be called before any
|
|
208
|
+
* `gen.push` / `gen.epilogue` is emitted. Idempotent — subsequent calls
|
|
209
|
+
* with the same value are no-ops; calls with a different value throw.
|
|
210
|
+
*/
|
|
211
|
+
setFuncKind(kind: "regular" | "generator" | "async"): void;
|
|
212
|
+
/**
|
|
213
|
+
* Slice 7a (#1169f): record the slot index of the `__gen_buffer`
|
|
214
|
+
* Wasm-local. Called from the generator-prologue emitter in from-ast
|
|
215
|
+
* after `declareSlot("__gen_buffer", { kind: "externref" })` allocates
|
|
216
|
+
* the slot. The lowerer reads this when expanding `gen.push` /
|
|
217
|
+
* `gen.epilogue`.
|
|
218
|
+
*/
|
|
219
|
+
setGeneratorBufferSlot(slotIndex: number): void;
|
|
220
|
+
/** Emit a `gen.push` instr — push a yielded value onto the buffer. */
|
|
221
|
+
emitGenPush(value: IrValueId): void;
|
|
222
|
+
/**
|
|
223
|
+
* Emit a `gen.epilogue` instr — produce the Generator-like object via
|
|
224
|
+
* `__create_generator(buffer, pendingThrow)`. Returns the SSA value of
|
|
225
|
+
* the resulting externref (the Generator object), suitable for use in a
|
|
226
|
+
* `return [result]` terminator.
|
|
227
|
+
*/
|
|
228
|
+
emitGenEpilogue(): IrValueId;
|
|
229
|
+
/**
|
|
230
|
+
* Slice 7b (#1169f): emit a `gen.yieldStar` instr — drain the inner
|
|
231
|
+
* iterable into the outer generator's buffer via
|
|
232
|
+
* `__gen_yield_star(buf, inner)`. The caller MUST coerce `inner` to
|
|
233
|
+
* externref upstream (e.g. via `emitCoerceToExternref`) — the host
|
|
234
|
+
* import expects an externref in arg position 1.
|
|
235
|
+
*/
|
|
236
|
+
emitGenYieldStar(inner: IrValueId): void;
|
|
237
|
+
private requireBlock;
|
|
238
|
+
/**
|
|
239
|
+
* Slice 6 (#1169e): single push site for IR instrs. Routes to either the
|
|
240
|
+
* current open block's instr list or — if a body buffer is active — into
|
|
241
|
+
* that buffer instead. The for-of-body builder uses this redirection so
|
|
242
|
+
* its lowered statements end up in `IrInstrForOfVec.body` rather than in
|
|
243
|
+
* the surrounding block's instr list.
|
|
244
|
+
*/
|
|
245
|
+
private pushInstr;
|
|
246
|
+
/**
|
|
247
|
+
* Allocate a Wasm-local slot for cross-iteration mutable state. Returns
|
|
248
|
+
* the slot's stable index, usable with `slot.read` / `slot.write`.
|
|
249
|
+
* `type` must be a primitive ValType (no struct refs in slice 6).
|
|
250
|
+
*/
|
|
251
|
+
declareSlot(name: string, type: ValType): number;
|
|
252
|
+
/** Read a slot by its index. Returns the SSA value of the load. */
|
|
253
|
+
emitSlotRead(slotIndex: number): IrValueId;
|
|
254
|
+
/**
|
|
255
|
+
* Slice 6 part 4 refactor (#1185): read a slot but tag the SSA def
|
|
256
|
+
* with a caller-supplied IrType instead of `irVal(slot.type)`.
|
|
257
|
+
* The Wasm-level value produced is identical — `slot.read` lowers
|
|
258
|
+
* to a single `local.get` either way — so this is purely a
|
|
259
|
+
* type-system rewrite. The caller is responsible for ensuring
|
|
260
|
+
* `asType` is interconvertible with `irVal(slot.type)` at the
|
|
261
|
+
* Wasm level (e.g. `IrType.string` and `(ref $AnyString)` are
|
|
262
|
+
* interconvertible in native-strings mode).
|
|
263
|
+
*
|
|
264
|
+
* Used by the slot-binding `asType` widening in `lowerExpr`'s
|
|
265
|
+
* identifier handler — see the `slot` arm of `ScopeBinding`.
|
|
266
|
+
*/
|
|
267
|
+
emitSlotReadAs(slotIndex: number, asType: IrType): IrValueId;
|
|
268
|
+
/** Write a value to a slot by its index. */
|
|
269
|
+
emitSlotWrite(slotIndex: number, value: IrValueId): void;
|
|
270
|
+
/** Read `vec.length` (returned as f64 to match JS Number semantics). */
|
|
271
|
+
emitVecLen(vec: IrValueId): IrValueId;
|
|
272
|
+
/**
|
|
273
|
+
* Index into a vec's data array. `indexI32` MUST be an i32-typed SSA value
|
|
274
|
+
* (not f64). `elemType` is the element's IrType, and the result carries it.
|
|
275
|
+
*/
|
|
276
|
+
emitVecGet(vec: IrValueId, indexI32: IrValueId, elemType: IrType): IrValueId;
|
|
277
|
+
/**
|
|
278
|
+
* #1804 — construct a fixed-length vec from element SSA values. `elementType`
|
|
279
|
+
* is the shared element IrType; `vecRefType` is the vec ref IrType the
|
|
280
|
+
* caller obtained from the resolver (`resolveVecForElement`) and becomes the
|
|
281
|
+
* result's type so downstream `vec.get`/`.length`/`for-of` reads resolve.
|
|
282
|
+
*/
|
|
283
|
+
emitVecNewFixed(elements: readonly IrValueId[], elementType: IrType, vecRefType: IrType): IrValueId;
|
|
284
|
+
/**
|
|
285
|
+
* Run a callback that emits the loop body's IR instrs into a side buffer.
|
|
286
|
+
* The callback typically calls `lowerStmt` on each TS body statement;
|
|
287
|
+
* those calls go through `lowerExpr` etc. and produce IR via the normal
|
|
288
|
+
* builder methods, which route into the side buffer instead of the
|
|
289
|
+
* current block.
|
|
290
|
+
*
|
|
291
|
+
* Returns the captured body instrs.
|
|
292
|
+
*/
|
|
293
|
+
collectBodyInstrs(emit: () => void): IrInstr[];
|
|
294
|
+
emitForOfVec(args: {
|
|
295
|
+
vec: IrValueId;
|
|
296
|
+
elementType: IrType;
|
|
297
|
+
counterSlot: number;
|
|
298
|
+
lengthSlot: number;
|
|
299
|
+
vecSlot: number;
|
|
300
|
+
dataSlot: number;
|
|
301
|
+
elementSlot: number;
|
|
302
|
+
body: readonly IrInstr[];
|
|
303
|
+
}): void;
|
|
304
|
+
/**
|
|
305
|
+
* Coerce a reference-typed IR value to externref. Caller is responsible
|
|
306
|
+
* for ensuring `value` has a reference IrType — numeric ValTypes
|
|
307
|
+
* (i32/f64) cannot be coerced and produce an invalid Wasm body.
|
|
308
|
+
*/
|
|
309
|
+
emitCoerceToExternref(value: IrValueId): IrValueId;
|
|
310
|
+
/**
|
|
311
|
+
* Construct a host iterator handle from an externref iterable.
|
|
312
|
+
* `async: false` calls `__iterator`; `async: true` calls
|
|
313
|
+
* `__async_iterator` (reserved for #1169f, slice 7).
|
|
314
|
+
*/
|
|
315
|
+
emitIterNew(iterable: IrValueId, async: boolean): IrValueId;
|
|
316
|
+
/**
|
|
317
|
+
* Advance the iterator (`iter.next()`). Result is the iterator-result
|
|
318
|
+
* object as externref. Side-effecting — DCE must not eliminate.
|
|
319
|
+
*/
|
|
320
|
+
emitIterNext(iter: IrValueId): IrValueId;
|
|
321
|
+
/** Read `.done` off an iterator-result object. Returns i32 (bool). */
|
|
322
|
+
emitIterDone(resultObj: IrValueId): IrValueId;
|
|
323
|
+
/** Read `.value` off an iterator-result object. Returns externref. */
|
|
324
|
+
emitIterValue(resultObj: IrValueId): IrValueId;
|
|
325
|
+
/** Call `iter.return()`. Void result. */
|
|
326
|
+
emitIterReturn(iter: IrValueId): void;
|
|
327
|
+
emitForOfIter(args: {
|
|
328
|
+
iterable: IrValueId;
|
|
329
|
+
iterSlot: number;
|
|
330
|
+
resultSlot: number;
|
|
331
|
+
elementSlot: number;
|
|
332
|
+
body: readonly IrInstr[];
|
|
333
|
+
}): void;
|
|
334
|
+
/**
|
|
335
|
+
* Emit a `forof.string` declarative instr — the native-strings counter
|
|
336
|
+
* loop over a string. Caller pre-allocates all four slots and passes
|
|
337
|
+
* the body buffer collected via `collectBodyInstrs`. The lowerer is
|
|
338
|
+
* responsible for emitting the `__str_charAt` calls + counter
|
|
339
|
+
* arithmetic; this builder method just records the structured node.
|
|
340
|
+
*/
|
|
341
|
+
emitForOfString(args: {
|
|
342
|
+
str: IrValueId;
|
|
343
|
+
counterSlot: number;
|
|
344
|
+
lengthSlot: number;
|
|
345
|
+
strSlot: number;
|
|
346
|
+
elementSlot: number;
|
|
347
|
+
body: readonly IrInstr[];
|
|
348
|
+
}): void;
|
|
349
|
+
/**
|
|
350
|
+
* Slice 9 (#1169h): emit a `throw` instruction. The `value` MUST be an
|
|
351
|
+
* SSA value of `(externref)` ValType — callers coerce upstream via
|
|
352
|
+
* `emitCoerceToExternref` for ref / object / class / closure values,
|
|
353
|
+
* and via the legacy box helper for f64 / i32 (boxed by the host).
|
|
354
|
+
*
|
|
355
|
+
* The instruction produces no SSA value; control doesn't fall through.
|
|
356
|
+
* The current block must still be terminated by the caller (typically
|
|
357
|
+
* with `unreachable` for top-level throws, or implicitly by the surrounding
|
|
358
|
+
* try-body buffer mechanism).
|
|
359
|
+
*/
|
|
360
|
+
emitThrow(value: IrValueId): void;
|
|
361
|
+
/**
|
|
362
|
+
* Slice 9 (#1169h): emit a `try` instruction with a body, optional catch
|
|
363
|
+
* handler, and optional finally body. Mirrors the for-of declarative
|
|
364
|
+
* shape — the caller pre-collects each buffer via `collectBodyInstrs`.
|
|
365
|
+
* Result is void.
|
|
366
|
+
*/
|
|
367
|
+
emitTry(args: {
|
|
368
|
+
body: readonly IrInstr[];
|
|
369
|
+
catchClause?: {
|
|
370
|
+
payloadSlot: number;
|
|
371
|
+
body: readonly IrInstr[];
|
|
372
|
+
};
|
|
373
|
+
finallyBody?: readonly IrInstr[];
|
|
374
|
+
}): void;
|
|
375
|
+
/**
|
|
376
|
+
* Slice 12 (#1280): emit a `while (cond) body` declarative loop. The
|
|
377
|
+
* caller pre-collects the cond + body buffers via `collectBodyInstrs`
|
|
378
|
+
* and threads through the SSA value emitted by the cond's last
|
|
379
|
+
* instruction. The lowerer emits the canonical
|
|
380
|
+
* `block { loop { <cond>; i32.eqz; br_if 1; <body>; br 0 } }`
|
|
381
|
+
* Wasm pattern.
|
|
382
|
+
*/
|
|
383
|
+
emitWhileLoop(args: {
|
|
384
|
+
cond: readonly IrInstr[];
|
|
385
|
+
condValue: IrValueId;
|
|
386
|
+
body: readonly IrInstr[];
|
|
387
|
+
}): void;
|
|
388
|
+
/**
|
|
389
|
+
* Slice 12 (#1280): emit a `for (init; cond; update) body` declarative
|
|
390
|
+
* loop. `init` is emitted as separate IR instructions BEFORE this
|
|
391
|
+
* instr (a `let i = 0` is just a `lowerVarDecl`, no special encoding
|
|
392
|
+
* needed). The instr carries cond, body, update.
|
|
393
|
+
*/
|
|
394
|
+
emitForLoop(args: {
|
|
395
|
+
cond: readonly IrInstr[];
|
|
396
|
+
condValue: IrValueId;
|
|
397
|
+
body: readonly IrInstr[];
|
|
398
|
+
update: readonly IrInstr[];
|
|
399
|
+
}): void;
|
|
400
|
+
}
|
|
401
|
+
export declare function v(n: number): IrValueId;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { AllocSiteRegistry } from './alloc-registry.js';
|
|
3
|
+
import { IrVecLowering } from './lower.js';
|
|
4
|
+
import { closureSignatureEquals, IrClassShape, IrFunction, IrType, IrUnop } from './nodes.js';
|
|
5
|
+
import { ValType } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Slice 10 (#1169i) — the from-ast view of one extern-class entry. Mirrors
|
|
8
|
+
* `ExternClassInfo` from `src/codegen/context/types.ts` but limits the
|
|
9
|
+
* surface to what the from-ast layer needs to validate `new ExternClass(...)`,
|
|
10
|
+
* `recv.method(...)`, and property access on extern-class receivers.
|
|
11
|
+
*
|
|
12
|
+
* Methods carry the LEGACY-registered signature shape: `params[0]` is the
|
|
13
|
+
* receiver `externref` and `params[1..]` are the user args. The from-ast
|
|
14
|
+
* lowerer slices off the receiver when matching call args against
|
|
15
|
+
* `params.slice(1)`. Slicing here keeps the from-ast logic dispatch-free.
|
|
16
|
+
*/
|
|
17
|
+
export interface IrExternClassMeta {
|
|
18
|
+
readonly className: string;
|
|
19
|
+
readonly constructorParams: readonly ValType[];
|
|
20
|
+
readonly methods: ReadonlyMap<string, {
|
|
21
|
+
readonly params: readonly ValType[];
|
|
22
|
+
readonly results: readonly ValType[];
|
|
23
|
+
}>;
|
|
24
|
+
readonly properties: ReadonlyMap<string, {
|
|
25
|
+
readonly type: ValType;
|
|
26
|
+
readonly readonly: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Slice 6 part 4 refactor (#1185): a narrowed view of `IrLowerResolver`
|
|
31
|
+
* restricted to the methods the AST→IR build phase actually consults.
|
|
32
|
+
* Threading this subset through `LowerCtx` retires per-feature shortcuts
|
|
33
|
+
* (`nativeStrings: boolean`, `anyStrTypeIdx: number`,
|
|
34
|
+
* `inferVecElementValTypeFromContext`, etc.) without forcing the full
|
|
35
|
+
* resolver — including its lazy struct registries that don't exist
|
|
36
|
+
* yet at Phase-1 build time — into the from-ast layer.
|
|
37
|
+
*
|
|
38
|
+
* Phase-1 callable methods only:
|
|
39
|
+
* - `nativeStrings()` — backend mode discriminator
|
|
40
|
+
* - `resolveString()` — `IrType.string` ValType (extern vs native struct ref)
|
|
41
|
+
* - `resolveVec(valType)` — vec struct shape recovery
|
|
42
|
+
*
|
|
43
|
+
* Slice 10 (#1169i) adds:
|
|
44
|
+
* - `getExternClassInfo(name)` — extern-class metadata for slice-10
|
|
45
|
+
* lowering of `new ExternClass(...)`, `recv.method(...)`, and
|
|
46
|
+
* property access on extern-class receivers. Returns undefined if
|
|
47
|
+
* `name` isn't a registered extern class.
|
|
48
|
+
*
|
|
49
|
+
* The full `IrLowerResolver` (in `src/ir/lower.ts`) extends this and
|
|
50
|
+
* adds Phase-3 methods like `resolveObject`, `resolveClass`,
|
|
51
|
+
* `resolveClosure`. Those depend on registries that aren't populated
|
|
52
|
+
* until Phase 3, so from-ast doesn't see them.
|
|
53
|
+
*/
|
|
54
|
+
export interface IrFromAstResolver {
|
|
55
|
+
nativeStrings?(): boolean;
|
|
56
|
+
resolveString?(): ValType;
|
|
57
|
+
resolveVec?(valType: ValType): IrVecLowering | null;
|
|
58
|
+
/**
|
|
59
|
+
* #1804 — register-or-recover the vec struct for an element ValType so
|
|
60
|
+
* `lowerArrayLiteral` can type a constructed `vec.new_fixed`'s result SSA
|
|
61
|
+
* value as `{ kind: "ref", typeIdx: vecStructTypeIdx }`.
|
|
62
|
+
*/
|
|
63
|
+
resolveVecForElement?(elementValType: ValType): IrVecLowering | null;
|
|
64
|
+
/**
|
|
65
|
+
* Slice 10 (#1169i) — return metadata for the named extern class, or
|
|
66
|
+
* `undefined` if no such class is registered.
|
|
67
|
+
*/
|
|
68
|
+
getExternClassInfo?(className: string): IrExternClassMeta | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* #1375 narrow slice — TS-narrowing fast-path for optional chaining.
|
|
71
|
+
* Returns `true` when the TypeScript type of `expr` is provably non-null
|
|
72
|
+
* (i.e. `getNonNullableType(t) === t`). Used by `lowerPropertyAccess`
|
|
73
|
+
* to skip the `?.`-on-nullable-receiver throw when TS has already
|
|
74
|
+
* narrowed away null/undefined — the IR's `isIrTypeNullable` is more
|
|
75
|
+
* conservative (treats `extern` as always nullable), so this gate
|
|
76
|
+
* recovers a small set of well-typed `m?.x` cases where `m: Map<...>`
|
|
77
|
+
* (no `| undefined`) is genuinely non-null at TS level.
|
|
78
|
+
*
|
|
79
|
+
* When unimplemented or returns `undefined`, `lowerPropertyAccess`
|
|
80
|
+
* keeps the existing throw → legacy fallback.
|
|
81
|
+
*/
|
|
82
|
+
isExpressionTsNonNullable?(expr: ts.Expression): boolean | undefined;
|
|
83
|
+
}
|
|
84
|
+
export interface AstToIrOptions {
|
|
85
|
+
readonly exported?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* #1370 Phase B: explicit name for the lowered function. Required for
|
|
88
|
+
* MethodDeclaration (where `.name` is `PropertyName`, not Identifier)
|
|
89
|
+
* and ConstructorDeclaration (which has no name node at all). For
|
|
90
|
+
* top-level FunctionDeclaration this can be omitted; the caller's
|
|
91
|
+
* `fn.name.text` is used as a fallback.
|
|
92
|
+
*/
|
|
93
|
+
readonly funcName?: string;
|
|
94
|
+
/**
|
|
95
|
+
* #1370 Phase B: when set, the lowered function gets an implicit
|
|
96
|
+
* `__self` parameter as its FIRST parameter, and `this` is bound in
|
|
97
|
+
* the body's scope to that parameter's SSA value. Pass when lowering
|
|
98
|
+
* an instance method — the legacy `class-bodies.ts` pre-allocates
|
|
99
|
+
* instance method signatures as `[(ref $structTypeIdx), ...userParams]`
|
|
100
|
+
* (see `class-bodies.ts:301`); the IR-lowered body must mirror that
|
|
101
|
+
* layout exactly so existing legacy callers' `call $methodFuncIdx`
|
|
102
|
+
* ops route to the correct typeIdx.
|
|
103
|
+
*
|
|
104
|
+
* The `IrType` should be `{ kind: "class"; shape }` so `this.field`
|
|
105
|
+
* accesses resolve via `class.get` / `class.set` against the shape's
|
|
106
|
+
* field list.
|
|
107
|
+
*
|
|
108
|
+
* Static methods don't get a `selfParam`; constructors don't either —
|
|
109
|
+
* Phase C synthesises `struct.new + __self` inside the body.
|
|
110
|
+
*/
|
|
111
|
+
readonly selfParam?: {
|
|
112
|
+
readonly type: IrType;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* If present, overrides the IR types for the function's own parameters.
|
|
116
|
+
* Indexed by parameter position. Used when the AST lacks explicit TS
|
|
117
|
+
* type annotations and the Phase-2 propagation pass has inferred types.
|
|
118
|
+
*/
|
|
119
|
+
readonly paramTypeOverrides?: readonly IrType[];
|
|
120
|
+
/**
|
|
121
|
+
* If present, overrides the IR return type. Same rationale as
|
|
122
|
+
* `paramTypeOverrides`.
|
|
123
|
+
*
|
|
124
|
+
* Slice 14 (#1228) — null = void return (zero Wasm result types). The
|
|
125
|
+
* IrFunctionBuilder is constructed with `[]` results and the lowerer
|
|
126
|
+
* accepts bare `return;` and fall-through tails.
|
|
127
|
+
*/
|
|
128
|
+
readonly returnTypeOverride?: IrType | null;
|
|
129
|
+
/**
|
|
130
|
+
* Map from callee function name to that callee's IR types (param +
|
|
131
|
+
* return). Consulted when lowering a CallExpression whose callee is a
|
|
132
|
+
* local function. Missing entries cause the lowerer to throw — the
|
|
133
|
+
* selector's call-graph closure should guarantee every call we reach
|
|
134
|
+
* has an entry.
|
|
135
|
+
*
|
|
136
|
+
* Slice 14 (#1228) — `returnType: IrType | null`. Null means a void
|
|
137
|
+
* callee — calls in expression position (`x = f();`) are spec-illegal
|
|
138
|
+
* for void; calls in statement position (`f();`) are fine.
|
|
139
|
+
*/
|
|
140
|
+
readonly calleeTypes?: ReadonlyMap<string, {
|
|
141
|
+
params: readonly IrType[];
|
|
142
|
+
returnType: IrType | null;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Slice 4 (#1169d): map from class name to that class's IR shape
|
|
146
|
+
* (fields + methods + constructor signature). Consulted when lowering
|
|
147
|
+
* NewExpression / class-receiver PropertyAccess / class-receiver
|
|
148
|
+
* method calls. Missing entries cause the relevant lowering case to
|
|
149
|
+
* throw, falling back to legacy.
|
|
150
|
+
*/
|
|
151
|
+
readonly classShapes?: ReadonlyMap<string, IrClassShape>;
|
|
152
|
+
/**
|
|
153
|
+
* Slice 6 part 4 refactor (#1185): the from-ast view of the IR
|
|
154
|
+
* lowerer's resolver. Replaces the per-feature shortcuts that
|
|
155
|
+
* #1181 / #1182 / #1183 each added (`nativeStrings`,
|
|
156
|
+
* `anyStrTypeIdx`, `inferVecElementValTypeFromContext`).
|
|
157
|
+
*
|
|
158
|
+
* Optional so existing tests / callers that don't need string or
|
|
159
|
+
* vec type resolution can keep working. The `lowerForOfStatement`
|
|
160
|
+
* arms that DO need it (string + vec) throw a clean fall-back-to-
|
|
161
|
+
* legacy error when the resolver is absent or returns `null`.
|
|
162
|
+
*
|
|
163
|
+
* The integration layer (`compileIrPathFunctions`) is the canonical
|
|
164
|
+
* supplier — it builds the resolver (or its subset) eagerly and
|
|
165
|
+
* passes it in.
|
|
166
|
+
*/
|
|
167
|
+
readonly resolver?: IrFromAstResolver;
|
|
168
|
+
/** Optional-chain nullability check (#1281). When absent, `?.` / `?.()` throw to legacy. */
|
|
169
|
+
readonly checker?: ts.TypeChecker;
|
|
170
|
+
/**
|
|
171
|
+
* #1586: module-global allocation-site registry. When supplied, the builder
|
|
172
|
+
* mints a stable `AllocSiteId` for every value-creating instr (object.new,
|
|
173
|
+
* closure.new, string.const, …). Optional — when absent, `alloc` fields stay
|
|
174
|
+
* unset, which is inert at lowering (byte-identical output).
|
|
175
|
+
*/
|
|
176
|
+
readonly allocRegistry?: AllocSiteRegistry;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Slice 3 (#1169c): lowering an outer function may produce additional
|
|
180
|
+
* lifted IR functions (one per nested function declaration / closure
|
|
181
|
+
* expression). The integration layer treats these as synthesized
|
|
182
|
+
* BuiltFns that get fresh funcIdx slots.
|
|
183
|
+
*/
|
|
184
|
+
export interface LoweredFunctionResult {
|
|
185
|
+
readonly main: IrFunction;
|
|
186
|
+
readonly lifted: readonly IrFunction[];
|
|
187
|
+
}
|
|
188
|
+
export declare function lowerFunctionAstToIr(fn: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ConstructorDeclaration, options?: AstToIrOptions): LoweredFunctionResult;
|
|
189
|
+
/** Result-type hints aren't used in Phase 1 (we always know from the op). */
|
|
190
|
+
export type _Unused = IrUnop;
|
|
191
|
+
export declare const _CLOSURE_SIG_EQ_REF: typeof closureSignatureEquals;
|
|
192
|
+
export type _UnusedVal = ValType;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './nodes.js';
|
|
3
|
+
export * from './alloc-registry.js';
|
|
4
|
+
export * from './builder.js';
|
|
5
|
+
export * from './verify.js';
|
|
6
|
+
export * from './verify-alloc.js';
|
|
7
|
+
export * from './lower.js';
|
|
8
|
+
export * from './backend/legality.js';
|
|
9
|
+
export * from './select.js';
|
|
10
|
+
export * from './from-ast.js';
|
|
11
|
+
export * from './integration.js';
|
|
12
|
+
export * from './analysis/encoding.js';
|
|
13
|
+
export * from './analysis/lattice.js';
|
|
14
|
+
export * from './analysis/ownership.js';
|
|
15
|
+
export * from './analysis/stack-alloc.js';
|
|
16
|
+
export * from './analysis/escape.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { CodegenContext } from '../codegen/context/types.js';
|
|
3
|
+
import { IrClassShape, IrType } from './nodes.js';
|
|
4
|
+
import { IrSelection } from './select.js';
|
|
5
|
+
export interface IrIntegrationReport {
|
|
6
|
+
readonly compiled: readonly string[];
|
|
7
|
+
readonly errors: readonly IrIntegrationError[];
|
|
8
|
+
}
|
|
9
|
+
export interface IrIntegrationError {
|
|
10
|
+
readonly func: string;
|
|
11
|
+
readonly message: string;
|
|
12
|
+
readonly kind?: "verify" | "build" | "lower" | "backend-legality";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Per-function IR type overrides sourced from the Phase-2 propagation
|
|
16
|
+
* pass. Indexed by function name. When present for a selected function,
|
|
17
|
+
* these types are used in place of (or alongside) any explicit TS
|
|
18
|
+
* annotations. They are also used to derive the `calleeTypes` map that
|
|
19
|
+
* the AST→IR lowerer consults when lowering `CallExpression`.
|
|
20
|
+
*/
|
|
21
|
+
export interface IrTypeOverrideMap {
|
|
22
|
+
get(name: string): {
|
|
23
|
+
readonly params: readonly IrType[];
|
|
24
|
+
readonly returnType: IrType | null;
|
|
25
|
+
} | undefined;
|
|
26
|
+
}
|
|
27
|
+
export declare function compileIrPathFunctions(ctx: CodegenContext, sourceFile: ts.SourceFile, selection?: IrSelection, overrides?: IrTypeOverrideMap, classShapes?: ReadonlyMap<string, IrClassShape>): IrIntegrationReport;
|