@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,19 @@
|
|
|
1
|
+
import { AllocSiteRegistry } from '../alloc-registry.js';
|
|
2
|
+
import { AllocSiteId, IrInstr } from '../nodes.js';
|
|
3
|
+
/**
|
|
4
|
+
* Inline/monomorphize path — a statically-duplicated allocation is a distinct
|
|
5
|
+
* runtime allocation, so its clone gets a FRESH id (kind/type copied from the
|
|
6
|
+
* source site). Returns `instr` unchanged when there is no registry or the
|
|
7
|
+
* instr carries no `alloc`. Only the top-level `alloc` is forked here; nested
|
|
8
|
+
* bodies are handled by recursing through the caller (inline never splices
|
|
9
|
+
* body-bearing instrs — see canInline). For safety this also forks nested
|
|
10
|
+
* allocs when present.
|
|
11
|
+
*/
|
|
12
|
+
export declare function forkAllocInInstr(instr: IrInstr, registry: AllocSiteRegistry | undefined): IrInstr;
|
|
13
|
+
/** Walk an instr + nested bodies, yielding every `alloc` id present. */
|
|
14
|
+
export declare function allocIdsIn(instr: IrInstr): Iterable<AllocSiteId>;
|
|
15
|
+
/**
|
|
16
|
+
* Rule 3 — retire every allocation id carried by `instr` (and nested bodies).
|
|
17
|
+
* No-op when no registry is supplied (test builders never minted ids).
|
|
18
|
+
*/
|
|
19
|
+
export declare function retireAllocsIn(instr: IrInstr, registry: AllocSiteRegistry | undefined): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IrFunction } from '../nodes.js';
|
|
2
|
+
import { AllocSiteRegistry } from '../alloc-registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Fold constant `prim`/`br_if` instructions. Returns the same reference
|
|
5
|
+
* when no changes are made.
|
|
6
|
+
*/
|
|
7
|
+
export declare function constantFold(fn: IrFunction, registry?: AllocSiteRegistry): IrFunction;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IrFunction, IrInstr } from '../nodes.js';
|
|
2
|
+
import { AllocSiteRegistry } from '../alloc-registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Run dead-code elimination on an IR function. Returns the same reference
|
|
5
|
+
* when no changes are made (so integration.ts can detect fixpoint via
|
|
6
|
+
* reference equality).
|
|
7
|
+
*/
|
|
8
|
+
export declare function deadCode(fn: IrFunction, registry?: AllocSiteRegistry): IrFunction;
|
|
9
|
+
/**
|
|
10
|
+
* Side-effecting instructions are always kept regardless of use count.
|
|
11
|
+
*
|
|
12
|
+
* - `raw.wasm` — opaque Wasm ops with unknown effects (spec #1167a mandates
|
|
13
|
+
* this stays live).
|
|
14
|
+
* - `call` — conservatively treated as having side effects. Purity analysis
|
|
15
|
+
* is a later pass.
|
|
16
|
+
* - `global.set` — writes observable state.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isSideEffecting(i: IrInstr): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IrModule } from '../nodes.js';
|
|
2
|
+
import { AllocSiteRegistry } from '../alloc-registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Inline small, non-recursive, single-block callees across the module.
|
|
5
|
+
* Returns the same `IrModule` reference when no function changes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function inlineSmall(mod: IrModule, registry?: AllocSiteRegistry): IrModule;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IrModule, IrType } from '../nodes.js';
|
|
2
|
+
import { AllocSiteRegistry } from '../alloc-registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Signature of an IR-only clone. The caller integrates this into its
|
|
5
|
+
* `calleeTypes` override map so downstream passes see the narrowed types.
|
|
6
|
+
*/
|
|
7
|
+
export interface MonomorphizeCloneSignature {
|
|
8
|
+
readonly params: readonly IrType[];
|
|
9
|
+
readonly returnType: IrType;
|
|
10
|
+
}
|
|
11
|
+
export interface MonomorphizeResult {
|
|
12
|
+
readonly module: IrModule;
|
|
13
|
+
/** Map from clone name → signature. Empty when the pass made no changes. */
|
|
14
|
+
readonly cloneSignatures: ReadonlyMap<string, MonomorphizeCloneSignature>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Monomorphize polymorphic callees across an IR module. Returns the input
|
|
18
|
+
* module unchanged (and an empty signature map) when no profitable clones
|
|
19
|
+
* exist or the growth budget would be exceeded.
|
|
20
|
+
*/
|
|
21
|
+
export declare function monomorphize(mod: IrModule, registry?: AllocSiteRegistry): MonomorphizeResult;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IrFunction } from '../nodes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Merge trivially-linked blocks. Returns the same reference when no
|
|
4
|
+
* changes are made.
|
|
5
|
+
*
|
|
6
|
+
* Pre-conditions (enforced upstream by the CF + DCE pipeline):
|
|
7
|
+
* - `func.blocks[i].id === i` (enforced by verify.ts:41-45).
|
|
8
|
+
* - Unreachable blocks have already been removed by DCE.
|
|
9
|
+
*
|
|
10
|
+
* Merge rule: a block A whose terminator is `br(B)` may absorb B if:
|
|
11
|
+
* (a) B has exactly one predecessor (A itself);
|
|
12
|
+
* (b) A != B (no self-loop);
|
|
13
|
+
* (c) B is not the entry block (blocks[0] must stay at index 0);
|
|
14
|
+
* (d) B has no block args (merging would require arg substitution,
|
|
15
|
+
* which Phase 3a leaves to a future pass — from-ast.ts and CF
|
|
16
|
+
* never introduce block args, so this is a safety guard rather
|
|
17
|
+
* than a real restriction).
|
|
18
|
+
*/
|
|
19
|
+
export declare function simplifyCFG(fn: IrFunction): IrFunction;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IrUnionLowering } from '../lower.js';
|
|
2
|
+
import { StructTypeDef, ValType } from '../types.js';
|
|
3
|
+
/** Canonical tag constants — see module header. */
|
|
4
|
+
export declare const UNION_TAG_F64 = 0;
|
|
5
|
+
export declare const UNION_TAG_I32 = 1;
|
|
6
|
+
export declare const UNION_TAG_NULL = 2;
|
|
7
|
+
export declare const UNION_TAG_STRING = 3;
|
|
8
|
+
/**
|
|
9
|
+
* Field layout within every $union_* struct. Keep this fixed across all
|
|
10
|
+
* unions so tag reads and value reads don't have to dispatch on member set.
|
|
11
|
+
*/
|
|
12
|
+
export declare const UNION_TAG_FIELD_IDX = 0;
|
|
13
|
+
export declare const UNION_VAL_FIELD_IDX = 1;
|
|
14
|
+
/**
|
|
15
|
+
* Minimal module-type sink — any container that can accept a WasmGC struct
|
|
16
|
+
* type and report its index. Concretely the codegen module's
|
|
17
|
+
* `ctx.mod.types`, but keeping the interface narrow makes the registry
|
|
18
|
+
* independently unit-testable.
|
|
19
|
+
*/
|
|
20
|
+
export interface UnionTypeSink {
|
|
21
|
+
/** Append `def` and return its module-wide type index. */
|
|
22
|
+
push(def: StructTypeDef): number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Per-module registry of tagged-union struct types. Call `resolve(members)`
|
|
26
|
+
* to get the `$union_<members>` lowering (registered lazily). Repeated
|
|
27
|
+
* calls with equivalent member sets return the same lowering.
|
|
28
|
+
*/
|
|
29
|
+
export declare class UnionStructRegistry {
|
|
30
|
+
private readonly sink;
|
|
31
|
+
private readonly cache;
|
|
32
|
+
constructor(sink: UnionTypeSink);
|
|
33
|
+
/**
|
|
34
|
+
* Resolve the lowering for a union member set. Returns `null` when the
|
|
35
|
+
* union is not representable under V1 rules (heterogeneous widths, or
|
|
36
|
+
* contains reference-type members).
|
|
37
|
+
*/
|
|
38
|
+
resolve(members: readonly ValType[]): IrUnionLowering | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Canonical tag constant for a ValType that may appear in a union. Kept as
|
|
42
|
+
* a free function so unit tests can exercise it without instantiating the
|
|
43
|
+
* full registry.
|
|
44
|
+
*/
|
|
45
|
+
export declare function tagFor(member: ValType): number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IrModule } from '../nodes.js';
|
|
2
|
+
export interface TaggedUnionsError {
|
|
3
|
+
readonly func: string;
|
|
4
|
+
readonly block: number;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TaggedUnionsResult {
|
|
8
|
+
readonly module: IrModule;
|
|
9
|
+
readonly errors: readonly TaggedUnionsError[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Run the tagged-unions pass. V1: validates that every `box`/`unbox`/
|
|
13
|
+
* `tag.test` operand references a registry-supported union; returns the
|
|
14
|
+
* module unchanged. Errors are reported but non-fatal — the caller decides
|
|
15
|
+
* whether to fall back.
|
|
16
|
+
*/
|
|
17
|
+
export declare function taggedUnions(mod: IrModule): IrModule;
|
|
18
|
+
/**
|
|
19
|
+
* Variant exposed for tests / callers that want the full error list.
|
|
20
|
+
* Most pipeline callers should use `taggedUnions` which discards errors.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runTaggedUnions(mod: IrModule): TaggedUnionsResult;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Atoms are the non-composite lattice elements. `LatticeAtom` excludes
|
|
4
|
+
* `unknown`, `union`, and `dynamic`; those can never be members of a union.
|
|
5
|
+
*
|
|
6
|
+
* #1231 — the `object` atom now carries a recursive structural shape
|
|
7
|
+
* (a name-sorted list of `(name, atom)` field bindings) instead of an
|
|
8
|
+
* opaque `shape: string` discriminator. This lets propagation flow
|
|
9
|
+
* concrete field types end-to-end (e.g. `{x: f64, y: f64}`) so the IR
|
|
10
|
+
* can emit typed structs and skip box/unbox round-trips on property
|
|
11
|
+
* access. The lattice height is bounded via a depth cap of
|
|
12
|
+
* `LATTICE_OBJECT_SHAPE_MAX_DEPTH` (set to 3, matching the legacy
|
|
13
|
+
* `resolveWasmType` depth guard); shapes deeper than the cap widen to
|
|
14
|
+
* `dynamic` so the fixpoint always terminates.
|
|
15
|
+
*/
|
|
16
|
+
export type LatticeAtom = {
|
|
17
|
+
readonly kind: "f64";
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: "i32";
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "u32";
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "bool";
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: "string";
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: "object";
|
|
28
|
+
readonly fields: readonly {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly type: LatticeAtom;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
export type LatticeType = {
|
|
34
|
+
readonly kind: "unknown";
|
|
35
|
+
} | LatticeAtom | {
|
|
36
|
+
readonly kind: "union";
|
|
37
|
+
readonly members: readonly LatticeAtom[];
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: "dynamic";
|
|
40
|
+
};
|
|
41
|
+
/** Maximum union-member count before we widen to `dynamic`. */
|
|
42
|
+
export declare const LATTICE_UNION_MAX_MEMBERS = 4;
|
|
43
|
+
/**
|
|
44
|
+
* Maximum recursive depth of `LatticeAtom.object` shapes. Object shapes
|
|
45
|
+
* deeper than the cap widen to `dynamic` so the propagation lattice has
|
|
46
|
+
* bounded height and the worklist fixpoint terminates. Matches the
|
|
47
|
+
* legacy `resolveWasmType` depth guard at `codegen/index.ts:5255`.
|
|
48
|
+
*/
|
|
49
|
+
export declare const LATTICE_OBJECT_SHAPE_MAX_DEPTH = 3;
|
|
50
|
+
/**
|
|
51
|
+
* #1126 Stage 2 — integer-domain inference flag. Default **OFF** until
|
|
52
|
+
* Stage 3 lands the emitter side. While off, all producer rules below
|
|
53
|
+
* fall back to their pre-#1126 behaviour (`F64` for numeric literals,
|
|
54
|
+
* `DYNAMIC` for bitwise/shift ops, etc.) so this PR cannot change the
|
|
55
|
+
* shape of any compiled function.
|
|
56
|
+
*
|
|
57
|
+
* To opt in locally: `JS2WASM_IR_I32_DOMAIN=1 npm test`.
|
|
58
|
+
*
|
|
59
|
+
* This mirrors the staged-rollout pattern from #1231 (object shapes)
|
|
60
|
+
* and #1238 (pseudo-extern Array). When Stage 3 ships, the default
|
|
61
|
+
* flips to ON and the env var becomes an opt-out (`=0`) emergency hatch.
|
|
62
|
+
*/
|
|
63
|
+
declare function i32DomainEnabled(): boolean;
|
|
64
|
+
export interface TypeMapEntry {
|
|
65
|
+
readonly params: readonly LatticeType[];
|
|
66
|
+
readonly returnType: LatticeType;
|
|
67
|
+
}
|
|
68
|
+
export type TypeMap = ReadonlyMap<string, TypeMapEntry>;
|
|
69
|
+
/**
|
|
70
|
+
* Build a TypeMap over every named top-level function declaration in the
|
|
71
|
+
* source file. Unresolvable types stay at `unknown`. Functions that the
|
|
72
|
+
* selector wouldn't claim anyway (missing body, duplicate names, etc.) are
|
|
73
|
+
* omitted.
|
|
74
|
+
*
|
|
75
|
+
* The TypeMap is only consulted by the selector and the AST→IR lowerer;
|
|
76
|
+
* nothing else depends on it, so the cost is paid once per compilation.
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildTypeMap(sourceFile: ts.SourceFile, checker: ts.TypeChecker): TypeMap;
|
|
79
|
+
declare function typeNodeToLattice(node: ts.TypeNode): LatticeType | null;
|
|
80
|
+
declare function tsTypeToLattice(ty: ts.Type, _checker: ts.TypeChecker): LatticeType;
|
|
81
|
+
/**
|
|
82
|
+
* Structural type of an expression, using the given param/local scope and
|
|
83
|
+
* the current TypeMap iteration state for cross-function return types.
|
|
84
|
+
*
|
|
85
|
+
* Conservative for unsupported nodes → `dynamic`.
|
|
86
|
+
*/
|
|
87
|
+
declare function inferExpr(expr: ts.Expression, scope: ReadonlyMap<string, LatticeType>, entries: ReadonlyMap<string, {
|
|
88
|
+
params: LatticeType[];
|
|
89
|
+
returnType: LatticeType;
|
|
90
|
+
}>): LatticeType;
|
|
91
|
+
declare function join(a: LatticeType, b: LatticeType): LatticeType;
|
|
92
|
+
/** Build a canonical union from a list of atoms (dedupe + sort). */
|
|
93
|
+
declare function makeUnion(members: readonly LatticeAtom[]): LatticeType;
|
|
94
|
+
/**
|
|
95
|
+
* Lower a `LatticeType` to the middle-end `IrType` used by `from-ast.ts`
|
|
96
|
+
* / `lower.ts`. Returns `null` when the lattice value is not representable
|
|
97
|
+
* as a concrete IR type (unknown, dynamic, or a union with members the
|
|
98
|
+
* tagged-union registry doesn't support).
|
|
99
|
+
*
|
|
100
|
+
* V1 union mapping:
|
|
101
|
+
* - `{f64, bool}` → `IrType.union<f64, i32>` (i32 holds bool)
|
|
102
|
+
* - `{f64, string}` → null (heterogeneous-width, deferred)
|
|
103
|
+
* - `{object(A), object(B)}` → null (reference unions, deferred)
|
|
104
|
+
*/
|
|
105
|
+
export declare function lowerTypeToIrType(t: LatticeType): import('./nodes.js').IrType | null;
|
|
106
|
+
export declare const _internals: {
|
|
107
|
+
join: typeof join;
|
|
108
|
+
inferExpr: typeof inferExpr;
|
|
109
|
+
tsTypeToLattice: typeof tsTypeToLattice;
|
|
110
|
+
typeNodeToLattice: typeof typeNodeToLattice;
|
|
111
|
+
makeUnion: typeof makeUnion;
|
|
112
|
+
F64: {
|
|
113
|
+
readonly kind: "f64";
|
|
114
|
+
};
|
|
115
|
+
I32: {
|
|
116
|
+
readonly kind: "i32";
|
|
117
|
+
};
|
|
118
|
+
U32: {
|
|
119
|
+
readonly kind: "u32";
|
|
120
|
+
};
|
|
121
|
+
BOOL: {
|
|
122
|
+
readonly kind: "bool";
|
|
123
|
+
};
|
|
124
|
+
STRING: {
|
|
125
|
+
readonly kind: "string";
|
|
126
|
+
};
|
|
127
|
+
UNKNOWN: {
|
|
128
|
+
readonly kind: "unknown";
|
|
129
|
+
};
|
|
130
|
+
DYNAMIC: {
|
|
131
|
+
readonly kind: "dynamic";
|
|
132
|
+
};
|
|
133
|
+
i32DomainEnabled: typeof i32DomainEnabled;
|
|
134
|
+
};
|
|
135
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { TypeMap } from './propagate.js';
|
|
3
|
+
/**
|
|
4
|
+
* #1169q telemetry — record why a top-level FunctionDeclaration didn't make
|
|
5
|
+
* it into the IR claim set. The intent is to drive the legacy retirement:
|
|
6
|
+
* once the count of unintended fallbacks (excluding deferred features) is
|
|
7
|
+
* zero against the test262 corpus, the legacy expression / statement
|
|
8
|
+
* emitters can be retired.
|
|
9
|
+
*/
|
|
10
|
+
export type IrFallbackReason = "unnamed" | "type-parameters" | "non-export-modifier" | "async-generator" | "async-function" | "return-type-not-resolvable" | "param-type-not-resolvable" | "param-shape-rejected" | "destructuring-param-complex" | "body-shape-rejected" | "external-call" | "call-graph-closure" | "type-resolution-failure" | "class-method" | "deferred-feature";
|
|
11
|
+
export interface IrFallback {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly reason: IrFallbackReason;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* (#1371) Whitelist of `Math.<name>(arg)` unary calls the IR can lower to a
|
|
17
|
+
* plain Wasm `f64.<op>` instruction without any host import. Each entry maps
|
|
18
|
+
* 1:1 to an op in the `IrUnop` extended set (`src/ir/nodes.ts`). Restricting
|
|
19
|
+
* the whitelist to ops with direct Wasm equivalents preserves bit-exact JS
|
|
20
|
+
* semantics:
|
|
21
|
+
* - `Math.round` is intentionally excluded — JS rounds 0.5 → 1 (away from
|
|
22
|
+
* zero) but `f64.nearest` rounds to even, so a 1:1 lowering is unsound.
|
|
23
|
+
* - `Math.min` / `Math.max` are binary and live in `IR_MATH_BINARY_WHITELIST`
|
|
24
|
+
* (deferred — needs an `IrBinop` extension).
|
|
25
|
+
*/
|
|
26
|
+
export declare const IR_MATH_UNARY_WHITELIST: ReadonlySet<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Map a whitelisted `Math.<name>` to its corresponding IR `f64.<op>` tag.
|
|
29
|
+
* Lives next to the whitelist so callers (selector + lowerer) share one
|
|
30
|
+
* source of truth.
|
|
31
|
+
*/
|
|
32
|
+
export declare function mathUnaryToIrOp(name: string): "f64.abs" | "f64.sqrt" | "f64.floor" | "f64.ceil" | "f64.trunc" | null;
|
|
33
|
+
export interface IrSelection {
|
|
34
|
+
readonly funcs: ReadonlySet<string>;
|
|
35
|
+
/** #1370 Phase A — synthetic-name set keyed by `${className}_${methodName}`
|
|
36
|
+
* for instance/static methods, and `${className}_new` for constructors.
|
|
37
|
+
* Populated when class members are IR-eligible. The naming convention
|
|
38
|
+
* matches `ctx.funcMap` (see `class-bodies.ts:216,275,284`) so Phase B
|
|
39
|
+
* can patch pre-allocated function slots by direct lookup.
|
|
40
|
+
*
|
|
41
|
+
* Phase A is selector-only — the `IrSelection.classMembers` is reported
|
|
42
|
+
* but `compileIrPathFunctions` does NOT yet patch class-method bodies.
|
|
43
|
+
* Phase B wires the integration loop. */
|
|
44
|
+
readonly classMembers?: ReadonlySet<string>;
|
|
45
|
+
/** Top-level FunctionDeclaration names that did NOT make it into `funcs`,
|
|
46
|
+
* paired with the rejection reason. Only populated when
|
|
47
|
+
* `IrSelectionOptions.trackFallbacks` is true. */
|
|
48
|
+
readonly fallbacks?: ReadonlyArray<IrFallback>;
|
|
49
|
+
}
|
|
50
|
+
export interface IrSelectionOptions {
|
|
51
|
+
readonly experimentalIR?: boolean;
|
|
52
|
+
/** When true, the returned selection includes a `fallbacks` array listing
|
|
53
|
+
* every top-level FunctionDeclaration that the selector did NOT claim
|
|
54
|
+
* along with the reason it was rejected. Off by default — populating
|
|
55
|
+
* this list adds a small per-function overhead. */
|
|
56
|
+
readonly trackFallbacks?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* (#1373b Slice 1) When true, async functions (no `*`) are eligible to
|
|
59
|
+
* flow through the IR's CPS lowering (Phase C). When false (default),
|
|
60
|
+
* the selector buckets them into the `"async-function"` fallback reason
|
|
61
|
+
* and the legacy direct-codegen path takes over.
|
|
62
|
+
*
|
|
63
|
+
* Even when true, individual async functions are still rejected by the
|
|
64
|
+
* selector if their body uses features the Phase C lowering can't handle
|
|
65
|
+
* yet (try/catch around await — see `isAsyncIrReady`).
|
|
66
|
+
*
|
|
67
|
+
* Threaded from `CodegenContext.supportsAsyncIr` via `integration.ts`.
|
|
68
|
+
*/
|
|
69
|
+
readonly supportsAsyncIr?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* (#1373b Slice 1) Centralised gate for whether the IR path can claim a
|
|
73
|
+
* given async function. The first scaffolding slice hardcodes the answer
|
|
74
|
+
* to `false` regardless of context — only later slices flip this on once
|
|
75
|
+
* the CPS continuation synthesis (Slice 2) is parity-tested.
|
|
76
|
+
*
|
|
77
|
+
* Body-shape checks (try/catch wrapping await, etc.) live here too so the
|
|
78
|
+
* selector and lowerer share a single source of truth on what's accepted.
|
|
79
|
+
*/
|
|
80
|
+
export declare function isAsyncIrReady(options: IrSelectionOptions | undefined, _fn: ts.FunctionLikeDeclaration): boolean;
|
|
81
|
+
export declare function planIrCompilation(sourceFile: ts.SourceFile, options?: IrSelectionOptions, typeMap?: TypeMap): IrSelection;
|