@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,121 @@
|
|
|
1
|
+
import { IrBackendKind } from './legality.js';
|
|
2
|
+
import { IrBinop, IrInstr, IrType, IrUnop } from '../nodes.js';
|
|
3
|
+
import { BlockType, Instr } from '../types.js';
|
|
4
|
+
import { IrClassLowering, IrClosureLowering, IrObjectStructLowering, IrRefCellLowering, IrUnionLowering, IrVecLowering, LinearVecLowering } from './handles.js';
|
|
5
|
+
type VecLayout = IrVecLowering | LinearVecLowering;
|
|
6
|
+
/**
|
|
7
|
+
* #1584: the trait is generic over its SINK type `S`. `WasmGcEmitter` /
|
|
8
|
+
* `LinearEmitter` use `S = Instr[]` (the default — every pre-#1584 caller is
|
|
9
|
+
* unchanged). `BytecodeEmitter` uses `S = BytecodeSink` (a flat opcode stream).
|
|
10
|
+
* The sink abstraction is the ONE representation-specific seam the #1715 finding
|
|
11
|
+
* identified; this generic parameter realizes it.
|
|
12
|
+
*
|
|
13
|
+
* Two sink operations belong to the trait (not the per-node primitives) because
|
|
14
|
+
* `lower.ts` itself touches the sink directly:
|
|
15
|
+
* - `newSink()` — the sink factory `lower.ts` uses to build `if`-arm buffers
|
|
16
|
+
* (it builds each arm into its own sink, then hands both to `emitIf`).
|
|
17
|
+
* - `pushRaw(out, instr)` — the raw-`Instr` escape hatch (#1584 contract
|
|
18
|
+
* §0a-1). `lower.ts` still has ~119 inline pushes for op families not yet
|
|
19
|
+
* migrated behind the trait. On WasmGC these append to the `Instr[]`; on the
|
|
20
|
+
* bytecode sink they hit an unrealized op family and throw (the
|
|
21
|
+
* not-yet-migrated boundary, surfaced loudly). As each family migrates
|
|
22
|
+
* (§2a), its sites move from `pushRaw` to a typed primitive.
|
|
23
|
+
*/
|
|
24
|
+
export interface BackendEmitter<S = Instr[]> {
|
|
25
|
+
/** Backend identity used by the IR legality verifier at the emit boundary. */
|
|
26
|
+
readonly backend: IrBackendKind;
|
|
27
|
+
/** Create a fresh empty sink (for `if`-arm buffers built by lower.ts). */
|
|
28
|
+
newSink(): S;
|
|
29
|
+
/** Raw-`Instr` escape hatch for op families not yet routed through the trait. */
|
|
30
|
+
pushRaw(out: S, instr: Instr): void;
|
|
31
|
+
/**
|
|
32
|
+
* vec ref on stack -> i32 length. The caller appends `f64.convert_i32_s`
|
|
33
|
+
* when the IR result type is f64 (that is an IR-result-type coercion, not
|
|
34
|
+
* a backend op, so it stays in lower.ts).
|
|
35
|
+
*/
|
|
36
|
+
emitVecLen(layout: VecLayout, out: S): void;
|
|
37
|
+
/**
|
|
38
|
+
* vec ref on stack -> data-region handle. WasmGC leaves a `(ref $arr)`;
|
|
39
|
+
* a linear backend would leave an `i32` base pointer. Both feed
|
|
40
|
+
* `emitElemGet`, which closes the abstraction so `lower.ts` never reasons
|
|
41
|
+
* about what is on the stack between the two calls.
|
|
42
|
+
*/
|
|
43
|
+
emitVecDataPtr(layout: VecLayout, out: S): void;
|
|
44
|
+
/** data-region handle + i32 index on stack -> element value. */
|
|
45
|
+
emitElemGet(layout: VecLayout, out: S): void;
|
|
46
|
+
/**
|
|
47
|
+
* #1804 — N element values on the stack (e0 deepest … eN top) -> a fully
|
|
48
|
+
* built vec ref. WasmGC: `array.new_fixed $arr N`, stash the data ref in
|
|
49
|
+
* `dataScratchLocal`, push `i32.const N` (length, field 0), re-load the data
|
|
50
|
+
* ref (field 1), `struct.new $vec`. Linear: bump-allocate
|
|
51
|
+
* `[header][len=N][cap=N][e0…eN]` and leave the base i32 (or `notImplemented`).
|
|
52
|
+
* `dataScratchLocal` is a function-local index of the array's ValType,
|
|
53
|
+
* allocated lazily by `lower.ts`.
|
|
54
|
+
*/
|
|
55
|
+
emitVecNewFixed(layout: VecLayout, count: number, dataScratchLocal: number, out: S): void;
|
|
56
|
+
/** Emit a `const` IR instr's literal op(s). Delegates to the shared free fn. */
|
|
57
|
+
emitConst(instr: Extract<IrInstr, {
|
|
58
|
+
kind: "const";
|
|
59
|
+
}>, funcName: string, out: S): void;
|
|
60
|
+
/** Pass-through binary op (`f64.add`, `i32.eq`, `i32.and`, ...). Bitwise
|
|
61
|
+
* `js.*` ops are lowered earlier in lower.ts and never reach here. */
|
|
62
|
+
emitBinary(op: IrBinop, out: S): void;
|
|
63
|
+
/** Pass-through unary op. */
|
|
64
|
+
emitUnary(op: IrUnop, out: S): void;
|
|
65
|
+
emitLocalGet(index: number, out: S): void;
|
|
66
|
+
emitLocalSet(index: number, out: S): void;
|
|
67
|
+
emitLocalTee(index: number, out: S): void;
|
|
68
|
+
emitGlobalGet(index: number, out: S): void;
|
|
69
|
+
emitGlobalSet(index: number, out: S): void;
|
|
70
|
+
emitDrop(out: S): void;
|
|
71
|
+
emitSelect(out: S): void;
|
|
72
|
+
emitReturn(out: S): void;
|
|
73
|
+
emitUnreachable(out: S): void;
|
|
74
|
+
/** Structured if. then/else are already lowered into their own sink. */
|
|
75
|
+
emitIf(blockType: BlockType, then: S, els: S, out: S): void;
|
|
76
|
+
emitBr(depth: number, out: S): void;
|
|
77
|
+
emitBrIf(depth: number, out: S): void;
|
|
78
|
+
/** Wrap `body` in a structured block; `body` was built via `newSink()`. */
|
|
79
|
+
emitBlock(blockType: BlockType, body: S, out: S): void;
|
|
80
|
+
/** Wrap `body` in a structured loop; `body` was built via `newSink()`. */
|
|
81
|
+
emitLoop(blockType: BlockType, body: S, out: S): void;
|
|
82
|
+
emitBox?(layout: IrUnionLowering, out: Instr[]): void;
|
|
83
|
+
emitUnbox?(layout: IrUnionLowering, out: Instr[]): void;
|
|
84
|
+
emitTagLoad?(layout: IrUnionLowering, out: Instr[]): void;
|
|
85
|
+
emitNull?(irType: IrType, out: Instr[]): void;
|
|
86
|
+
emitToExternref?(out: Instr[]): void;
|
|
87
|
+
emitFromExternref?(layout: {
|
|
88
|
+
typeIdx: number;
|
|
89
|
+
} | IrType, out: Instr[]): void;
|
|
90
|
+
emitFuncRef?(funcIdx: number, out: Instr[]): void;
|
|
91
|
+
emitClosureNew?(layout: IrClosureLowering, captureCount: number, out: Instr[]): void;
|
|
92
|
+
emitClosureFuncGet?(layout: IrClosureLowering, out: Instr[]): void;
|
|
93
|
+
emitCaptureGet?(layout: IrClosureLowering, index: number, out: Instr[]): void;
|
|
94
|
+
emitRefCellNew?(layout: IrRefCellLowering, out: Instr[]): void;
|
|
95
|
+
emitRefCellGet?(layout: IrRefCellLowering, out: Instr[]): void;
|
|
96
|
+
emitRefCellSet?(layout: IrRefCellLowering, out: Instr[]): void;
|
|
97
|
+
/** Direct call to compiled function `funcIdx`. Args already on the stack. */
|
|
98
|
+
emitCall(funcIdx: number, out: S): void;
|
|
99
|
+
/** Indirect call through a typed funcref already on the stack. */
|
|
100
|
+
emitCallRef(funcTypeIdx: number, out: S): void;
|
|
101
|
+
/** Allocate an aggregate from `fieldCount` values already on the stack
|
|
102
|
+
* (canonical field order, field0 deepest); leaves the new struct ref. */
|
|
103
|
+
emitAggregateNew(layout: IrObjectStructLowering, fieldCount: number, out: S): void;
|
|
104
|
+
/** struct ref on stack -> the named field's value. */
|
|
105
|
+
emitFieldGet(layout: IrObjectStructLowering | IrClassLowering, name: string, out: S): void;
|
|
106
|
+
/** struct ref + value on stack -> writes the named field (void). */
|
|
107
|
+
emitFieldSet(layout: IrObjectStructLowering | IrClassLowering, name: string, out: S): void;
|
|
108
|
+
/** Throw the exception value already on the stack via the `__exn` tag. */
|
|
109
|
+
emitThrow(tagIdx: number, out: S): void;
|
|
110
|
+
/** Re-throw the currently-caught exception (`depth` levels out; lower.ts
|
|
111
|
+
* only emits depth 0 today). */
|
|
112
|
+
emitRethrow(depth: number, out: S): void;
|
|
113
|
+
/** Structured try. `body` / each catch `body` / `catchAll` are pre-lowered
|
|
114
|
+
* into their own sinks (built via `newSink()`). `catches[i].tagIdx` selects
|
|
115
|
+
* the handler by exception tag. */
|
|
116
|
+
emitTry(blockType: BlockType, body: S, catches: {
|
|
117
|
+
tagIdx: number;
|
|
118
|
+
body: S;
|
|
119
|
+
}[], catchAll: S | undefined, out: S): void;
|
|
120
|
+
}
|
|
121
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ValType } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Information about a tagged-union struct type emitted into the WasmGC module.
|
|
4
|
+
* See `passes/tagged-union-types.ts` for the registry that produces these.
|
|
5
|
+
*/
|
|
6
|
+
export interface IrUnionLowering {
|
|
7
|
+
/** WasmGC type index of the `$union_<members>` struct. */
|
|
8
|
+
readonly typeIdx: number;
|
|
9
|
+
/** Field index of the `$tag` i32 discriminator. */
|
|
10
|
+
readonly tagFieldIdx: number;
|
|
11
|
+
/** Field index of the `$val` field carrying the member scalar. */
|
|
12
|
+
readonly valFieldIdx: number;
|
|
13
|
+
/** Canonical tag value (i32 constant) for each ValType kind. */
|
|
14
|
+
tagFor(member: ValType): number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Information about a heap-allocated scalar box -- see
|
|
18
|
+
* `IrType { kind: "boxed", inner }`. Resolved lazily by the lowering pass.
|
|
19
|
+
*/
|
|
20
|
+
export interface IrBoxedLowering {
|
|
21
|
+
/** WasmGC type index of the `$box_<inner>` struct. */
|
|
22
|
+
readonly typeIdx: number;
|
|
23
|
+
/** Field index of the inner `$val`. */
|
|
24
|
+
readonly valFieldIdx: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Information about a registered WasmGC struct that backs an
|
|
28
|
+
* `IrType.object` shape. The resolver memoizes one of these per shape.
|
|
29
|
+
*
|
|
30
|
+
* `fieldIdx(name)` returns the WasmGC struct's field index for the given
|
|
31
|
+
* shape field name (in the shape's canonical order). It throws when the
|
|
32
|
+
* name is not a member of the shape -- the lowerer catches via the
|
|
33
|
+
* surrounding try/catch and emits a clean fall-back error.
|
|
34
|
+
*/
|
|
35
|
+
export interface IrObjectStructLowering {
|
|
36
|
+
/** WasmGC type index of the registered struct. */
|
|
37
|
+
readonly typeIdx: number;
|
|
38
|
+
/** Field index for each field name in the shape's canonical order. */
|
|
39
|
+
fieldIdx(name: string): number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Slice 3 (#1169c): WasmGC type info for a closure value. Two structs
|
|
43
|
+
* are involved per closure construction site:
|
|
44
|
+
* - The SUPERTYPE struct (`structTypeIdx`): contains only the funcref
|
|
45
|
+
* field. Carried by the IrType.closure ValType so all closures
|
|
46
|
+
* sharing a signature have the same Wasm-level type.
|
|
47
|
+
* - The SUBTYPE struct (resolved via `resolveClosureSubtype`): adds
|
|
48
|
+
* the capture fields. Constructed at the closure's creation site
|
|
49
|
+
* (`struct.new <subtype>`) and `ref.cast`-ed inside the lifted
|
|
50
|
+
* body to read captures.
|
|
51
|
+
*
|
|
52
|
+
* `funcTypeIdx` is the lifted function's Wasm func type
|
|
53
|
+
* `(ref $base, ...sig.params) -> sig.returnType` -- used by `call_ref`
|
|
54
|
+
* at the call site.
|
|
55
|
+
*/
|
|
56
|
+
export interface IrClosureLowering {
|
|
57
|
+
readonly structTypeIdx: number;
|
|
58
|
+
readonly funcFieldIdx: number;
|
|
59
|
+
/** Field index for capture position `i` (0-based). Valid only for subtype lowerings. */
|
|
60
|
+
capFieldIdx(index: number): number;
|
|
61
|
+
readonly funcTypeIdx: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Slice 3 (#1169c): WasmGC type info for a ref cell over a primitive
|
|
65
|
+
* value type. Single-field struct `(struct (field $value (mut T)))`.
|
|
66
|
+
*/
|
|
67
|
+
export interface IrRefCellLowering {
|
|
68
|
+
readonly typeIdx: number;
|
|
69
|
+
readonly fieldIdx: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Slice 6 (#1169e): WasmGC type info for a vec struct (the runtime layout
|
|
73
|
+
* for `Array<T>` / tuple types). The struct is `{ length: i32, data: (ref
|
|
74
|
+
* $arr) }` where `$arr` is the element array type. This interface is the
|
|
75
|
+
* lowerer's contract for emitting `vec.len` and `vec.get` against a known
|
|
76
|
+
* vec value's IrType.
|
|
77
|
+
*
|
|
78
|
+
* - `vecStructTypeIdx` Wasm struct type index of the vec.
|
|
79
|
+
* - `lengthFieldIdx` field index of the i32 length (typically 0).
|
|
80
|
+
* - `dataFieldIdx` field index of the data array ref (typically 1).
|
|
81
|
+
* - `arrayTypeIdx` Wasm array type index of the data array.
|
|
82
|
+
* - `elementValType` element ValType -- used by `vec.get` to lower
|
|
83
|
+
* the result and (recursively, via the resolver)
|
|
84
|
+
* to widen the element to the loop variable's
|
|
85
|
+
* declared type when needed.
|
|
86
|
+
*/
|
|
87
|
+
export interface IrVecLowering {
|
|
88
|
+
readonly vecStructTypeIdx: number;
|
|
89
|
+
readonly lengthFieldIdx: number;
|
|
90
|
+
readonly dataFieldIdx: number;
|
|
91
|
+
readonly arrayTypeIdx: number;
|
|
92
|
+
readonly elementValType: ValType;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Slice 4 (#1169d): WasmGC type info for a class declared in the
|
|
96
|
+
* compilation unit. The class's struct + constructor + method funcs
|
|
97
|
+
* are all registered by the legacy `collectClassDeclaration` pass before
|
|
98
|
+
* the IR runs; this interface just exposes them by name.
|
|
99
|
+
*
|
|
100
|
+
* - `structTypeIdx` Wasm struct type index for the class
|
|
101
|
+
* - `fieldIdx(name)` Wasm struct field index for a user field name
|
|
102
|
+
* (the legacy `__tag` prefix at field 0 is
|
|
103
|
+
* accounted for here so the IR doesn't need to
|
|
104
|
+
* reason about it).
|
|
105
|
+
* - `constructorFuncName` legacy-registered name of the constructor
|
|
106
|
+
* function (`<className>_new`); the resolver's
|
|
107
|
+
* `resolveFunc` maps it to the funcIdx.
|
|
108
|
+
* - `methodFuncName(name)` legacy-registered name of an instance method
|
|
109
|
+
* (`<className>_<methodName>`); the resolver's
|
|
110
|
+
* `resolveFunc` maps it to the funcIdx.
|
|
111
|
+
*/
|
|
112
|
+
export interface IrClassLowering {
|
|
113
|
+
readonly structTypeIdx: number;
|
|
114
|
+
fieldIdx(name: string): number;
|
|
115
|
+
readonly constructorFuncName: string;
|
|
116
|
+
methodFuncName(name: string): string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* #1714: linear-memory layout handle for a vec (array). Sibling to
|
|
120
|
+
* {@link IrVecLowering} (the WasmGC handle). The linear backend stores an
|
|
121
|
+
* array as a base `i32` pointer to `[header 8B][len:u32 @+8][cap:u32
|
|
122
|
+
* @+12][elements @+16…]` (see `src/codegen-linear/runtime.ts:339`), so the
|
|
123
|
+
* only representation detail the emitter needs is the element ValType (for
|
|
124
|
+
* stride + load op). Field offsets are fixed by the layout, not per-instance.
|
|
125
|
+
*
|
|
126
|
+
* This is the "different handle shape the linear resolver returns" that the
|
|
127
|
+
* #1713 spec §7 anticipated. The `BackendEmitter` vec methods accept
|
|
128
|
+
* `IrVecLowering | LinearVecLowering`; each emitter narrows to its own shape.
|
|
129
|
+
*/
|
|
130
|
+
export interface LinearVecLowering {
|
|
131
|
+
/** Element ValType — drives stride (4 vs 8) and the load op. */
|
|
132
|
+
readonly elementValType: ValType;
|
|
133
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IrFunction } from '../nodes.js';
|
|
2
|
+
export type IrBackendKind = "wasmgc" | "linear" | "bytecode";
|
|
3
|
+
export interface IrBackendLegalityError {
|
|
4
|
+
readonly message: string;
|
|
5
|
+
readonly func: string;
|
|
6
|
+
readonly block?: number;
|
|
7
|
+
readonly instr?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function verifyIrBackendLegality(func: IrFunction, backend: IrBackendKind): IrBackendLegalityError[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Instr } from '../types.js';
|
|
2
|
+
import { BackendEmitter } from './emitter.js';
|
|
3
|
+
import { LinearVecLowering } from './handles.js';
|
|
4
|
+
/**
|
|
5
|
+
* #1714: a BackendEmitter that lowers the vec primitives to LINEAR memory.
|
|
6
|
+
* Only the three vec methods are implemented; the rest fail loudly.
|
|
7
|
+
*/
|
|
8
|
+
export declare class LinearEmitter implements BackendEmitter<Instr[]> {
|
|
9
|
+
readonly backend: "linear";
|
|
10
|
+
newSink(): Instr[];
|
|
11
|
+
pushRaw(out: Instr[], instr: Instr): void;
|
|
12
|
+
emitVecLen(layout: LinearVecLowering, out: Instr[]): void;
|
|
13
|
+
emitVecDataPtr(layout: LinearVecLowering, out: Instr[]): void;
|
|
14
|
+
emitElemGet(layout: LinearVecLowering, out: Instr[]): void;
|
|
15
|
+
emitVecNewFixed(): void;
|
|
16
|
+
emitConst(): void;
|
|
17
|
+
emitBinary(): void;
|
|
18
|
+
emitUnary(): void;
|
|
19
|
+
emitLocalGet(): void;
|
|
20
|
+
emitLocalSet(): void;
|
|
21
|
+
emitLocalTee(): void;
|
|
22
|
+
emitGlobalGet(): void;
|
|
23
|
+
emitGlobalSet(): void;
|
|
24
|
+
emitDrop(): void;
|
|
25
|
+
emitSelect(): void;
|
|
26
|
+
emitReturn(): void;
|
|
27
|
+
emitUnreachable(): void;
|
|
28
|
+
emitIf(): void;
|
|
29
|
+
emitBr(): void;
|
|
30
|
+
emitBrIf(): void;
|
|
31
|
+
emitBlock(): void;
|
|
32
|
+
emitLoop(): void;
|
|
33
|
+
emitThrow(): void;
|
|
34
|
+
emitRethrow(): void;
|
|
35
|
+
emitTry(): void;
|
|
36
|
+
emitAggregateNew(): void;
|
|
37
|
+
emitFieldGet(): void;
|
|
38
|
+
emitFieldSet(): void;
|
|
39
|
+
emitCall(): void;
|
|
40
|
+
emitCallRef(): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IrBinop, IrInstr, IrUnop } from '../nodes.js';
|
|
2
|
+
import { BlockType, Instr } from '../types.js';
|
|
3
|
+
import { BackendEmitter } from './emitter.js';
|
|
4
|
+
import { IrClassLowering, IrObjectStructLowering, IrVecLowering } from './handles.js';
|
|
5
|
+
export declare class WasmGcEmitter implements BackendEmitter<Instr[]> {
|
|
6
|
+
readonly backend: "wasmgc";
|
|
7
|
+
newSink(): Instr[];
|
|
8
|
+
pushRaw(out: Instr[], instr: Instr): void;
|
|
9
|
+
emitVecLen(layout: IrVecLowering, out: Instr[]): void;
|
|
10
|
+
emitVecDataPtr(layout: IrVecLowering, out: Instr[]): void;
|
|
11
|
+
emitElemGet(layout: IrVecLowering, out: Instr[]): void;
|
|
12
|
+
emitVecNewFixed(layout: IrVecLowering, count: number, dataScratchLocal: number, out: Instr[]): void;
|
|
13
|
+
emitConst(instr: Extract<IrInstr, {
|
|
14
|
+
kind: "const";
|
|
15
|
+
}>, funcName: string, out: Instr[]): void;
|
|
16
|
+
emitBinary(op: IrBinop, out: Instr[]): void;
|
|
17
|
+
emitUnary(op: IrUnop, out: Instr[]): void;
|
|
18
|
+
emitLocalGet(index: number, out: Instr[]): void;
|
|
19
|
+
emitLocalSet(index: number, out: Instr[]): void;
|
|
20
|
+
emitLocalTee(index: number, out: Instr[]): void;
|
|
21
|
+
emitGlobalGet(index: number, out: Instr[]): void;
|
|
22
|
+
emitGlobalSet(index: number, out: Instr[]): void;
|
|
23
|
+
emitDrop(out: Instr[]): void;
|
|
24
|
+
emitSelect(out: Instr[]): void;
|
|
25
|
+
emitReturn(out: Instr[]): void;
|
|
26
|
+
emitUnreachable(out: Instr[]): void;
|
|
27
|
+
emitIf(blockType: BlockType, then: Instr[], els: Instr[], out: Instr[]): void;
|
|
28
|
+
emitBr(depth: number, out: Instr[]): void;
|
|
29
|
+
emitBrIf(depth: number, out: Instr[]): void;
|
|
30
|
+
emitBlock(blockType: BlockType, body: Instr[], out: Instr[]): void;
|
|
31
|
+
emitLoop(blockType: BlockType, body: Instr[], out: Instr[]): void;
|
|
32
|
+
emitCall(funcIdx: number, out: Instr[]): void;
|
|
33
|
+
emitCallRef(funcTypeIdx: number, out: Instr[]): void;
|
|
34
|
+
emitAggregateNew(layout: IrObjectStructLowering, _fieldCount: number, out: Instr[]): void;
|
|
35
|
+
emitFieldGet(layout: IrObjectStructLowering | IrClassLowering, name: string, out: Instr[]): void;
|
|
36
|
+
emitFieldSet(layout: IrObjectStructLowering | IrClassLowering, name: string, out: Instr[]): void;
|
|
37
|
+
emitThrow(tagIdx: number, out: Instr[]): void;
|
|
38
|
+
emitRethrow(depth: number, out: Instr[]): void;
|
|
39
|
+
emitTry(blockType: BlockType, body: Instr[], catches: {
|
|
40
|
+
tagIdx: number;
|
|
41
|
+
body: Instr[];
|
|
42
|
+
}[], catchAll: Instr[] | undefined, out: Instr[]): void;
|
|
43
|
+
}
|