watr 4.6.10 → 4.7.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.
@@ -2,7 +2,11 @@
2
2
  * Converts a WebAssembly Text Format (WAT) tree to a WebAssembly binary format (WASM).
3
3
  *
4
4
  * @param {string|Array} nodes - The WAT tree or string to be compiled to WASM binary.
5
- * @returns {Uint8Array} The compiled WASM binary data.
5
+ * @returns {Uint8Array} The compiled WASM binary. When the WAT carries
6
+ * `@metadata.code.<type>` annotations, the result also exposes a `.metadata`
7
+ * property — `{ [type]: [[absoluteByteOffset, data], ...] }`, each offset the
8
+ * instruction's position in the final binary. That's the hook a source-map
9
+ * emitter needs to correlate generated wasm back to its source.
6
10
  */
7
11
  export default function compile(nodes: string | any[]): Uint8Array;
8
12
  //# sourceMappingURL=compile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AAuCA;;;;;GAKG;AACH,uCAHW,MAAM,QAAM,GACV,UAAU,CA8NtB"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AAuCA;;;;;;;;;GASG;AACH,uCAPW,MAAM,QAAM,GACV,UAAU,CAkRtB"}
@@ -1,16 +1,4 @@
1
- /**
2
- * Optimize AST.
3
- *
4
- * @param {Array|string} ast - AST or WAT source
5
- * @param {boolean|string|Object} [opts=true] - Optimization options
6
- * @returns {Array} Optimized AST
7
- *
8
- * @example
9
- * optimize(ast) // all optimizations
10
- * optimize(ast, 'treeshake') // only treeshake
11
- * optimize(ast, { fold: true }) // explicit
12
- */
13
- export default function optimize(ast: any[] | string, opts?: boolean | string | any): any[];
1
+ export default function optimize(ast: any, opts?: boolean): any;
14
2
  /**
15
3
  * Recursively count AST nodes — fast size heuristic without compiling.
16
4
  * @param {any} node
@@ -68,42 +56,36 @@ export function strength(ast: any[]): any[];
68
56
  */
69
57
  export function branch(ast: any[]): any[];
70
58
  export function propagate(ast: any): any;
59
+ export function inline(ast: any, { simdOnly }?: {
60
+ simdOnly?: boolean;
61
+ }): any;
62
+ export function inlineOnce(ast: any): any;
71
63
  /**
72
- * Inline tiny functions (single expression, no locals, no params or simple params).
73
- * @param {Array} ast
74
- * @returns {Array}
75
- */
76
- export function inline(ast: any[]): any[];
77
- /**
78
- * Inline functions that are called from exactly one place into their lone caller,
79
- * then delete them. Unlike {@link inline} (which duplicates tiny stateless bodies),
80
- * this never duplicates code and never inflates: each inlined function drops a
81
- * function-section entry, a type-section entry (if now unused), and a `call`
82
- * instruction, paying back only a `block`/`local.set` wrapper. This is what
83
- * `wasm-opt -Oz` does collapsing helper chains down to a couple of functions —
84
- * and it's the bulk of the gap between hand-tuned WASM and naive codegen.
85
- *
86
- * A function `$f` qualifies when it is, all of:
87
- * • named, with named params and locals (numeric indices can't be safely renamed);
88
- * • referenced exactly once across the whole module, by a plain `call` (no
89
- * `return_call`, `ref.func`, `elem`, `export`, or `start` reference, and not
90
- * recursive);
91
- * • single-result or void (a multi-value result can't be modeled as `(block (result …))`);
92
- * • free of numeric (depth-relative) branch labels — those would shift under the
93
- * extra block nesting — and of `return_call*` in its body.
64
+ * Devirtualize `call_indirect` through NaN-boxed closure values with a statically
65
+ * known candidate set. `let f = c ? a : b; … f(x)` emits a select of two i64
66
+ * closure constants into an f64 local; every call site then derives the table
67
+ * slot from that local's bits:
68
+ * (i32.wrap_i64 (i64.and (i64.shr_u (i64.reinterpret_f64 (local.get $f))
69
+ * (i64.const 32)) (i64.const 32767)))
70
+ * When EVERY write to $f in the function is such a constant set (≤2 candidates),
71
+ * each call site becomes a guarded direct call
72
+ * (if (result …) (i64.eq (i64.reinterpret_f64 (local.get $f)) (i64.const C1))
73
+ * (then (call $tramp1 …args)) (else <next guard | original call_indirect>))
74
+ * with the ORIGINAL call_indirect kept as the final arm, so unknown flows
75
+ * (zero-init paths the analysis can't see) behave exactly as before: the rewrite
76
+ * is a pure branch-predicted fast path, ~25% on callback loops, and the direct
77
+ * calls participate in inlining. A trivially-constant slot ((i32.const N) after
78
+ * fold) becomes a bare direct call with no guard.
94
79
  *
95
- * `(call $f a0 a1 …)` becomes
96
- * (block $__inlN (result T)?
97
- * (local.set $__inlN_p0 a0) (local.set $__inlN_p1 a1) … ;; args evaluated once, in order
98
- * …body, params/locals renamed to $__inlN_*, `return X` `br $__inlN X`…)
99
- * and the renamed params+locals are appended to the caller's `local` decls; the
100
- * body's own block/loop/if labels are renamed too so they can't shadow the caller's.
101
- * Runs to a fixpoint so helper chains fully collapse.
102
- *
103
- * @param {Array} ast
104
- * @returns {Array}
80
+ * Soundness: the guard compares the SAME bits the slot extraction reads, so
81
+ * whichever constant flows to the call dispatches identically in both forms;
82
+ * candidates that don't resolve to an elem entry (or whose target's signature
83
+ * differs from the call's type would-be runtime trap) disable the site. Any
84
+ * table mutation op in the module disables the pass entirely. The function
85
+ * table is exported for host-side closure invocation (reads); host mutation of
86
+ * it is outside the ABI contract, same as the closure-constant model itself.
105
87
  */
106
- export function inlineOnce(ast: any[]): any[];
88
+ export function devirt(ast: any): any;
107
89
  /**
108
90
  * Normalize options to a { passName: bool } map. An explicit object is kept
109
91
  * as-is (preserving `log`/`verbose`), with any unmentioned pass filled to its
@@ -1 +1 @@
1
- {"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AAs2FA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SAmE/B;AAh6FD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAIlB;AA8CD;;;;;GAKG;AACH,6CAgJC;AAuMD;;;;GAIG;AACH,wCAuBC;AAoMD;;;;GAIG;AACH,4CAqBC;AA+CD;;;;;GAKG;AACH,8CAmDC;AA7QD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CAuCC;AAggBD,yCAoCC;AAID;;;;GAIG;AACH,0CAgGC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,8CAmOC;AAyzCD;;;;;;;;GAQG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAc/B;AAvBD,qEAAqE;AACrE,uBAA8D;AAljC9D;;;;;GAKG;AACH,0CAgDC;AAwED;;;;GAIG;AACH,4CAQC;AA4BD;;;;;;;;;;;GAWG;AACH,2CAyDC;AAID,2EAA2E;AAC3E,sCAgEC;AAID;;;;GAIG;AACH,4CAyCC;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,2CAiDC;AAID;;;;;GAKG;AACH,4CAqBC;AAID;;;;;;GAMG;AACH,wCAmBC;AAID;;;;;GAKG;AACH,4CAiDC;AAoCD;;;;;GAKG;AACH,0CA8DC;AAiWD,uCAyBC;AAtXD;;;;;GAKG;AACH,8CAyEC;AAoID;;;;GAIG;AACH,4CAyDC;AAqBD;;;;;GAKG;AACH,iDAgBC;AA9qCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,+CAiFC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDAyFC"}
1
+ {"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AAyxHA,gEAyFC;AA9zHD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAIlB;AA8CD;;;;;GAKG;AACH,6CAgJC;AAwUD;;;;GAIG;AACH,wCAkDC;AA0YD;;;;GAIG;AACH,4CAqBC;AA+CD;;;;;GAKG;AACH,8CAmDC;AAndD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CAwDC;AAID;;;;GAIG;AACH,0CA6CC;AAuyBD,yCAqCC;AAmND;;QAqEC;AAySD,0CAgJC;AArbD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,sCAwOC;AAghDD;;;;;;;;GAQG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAc/B;AAvBD,qEAAqE;AACrE,uBAA8D;AArlC9D;;;;;GAKG;AACH,0CA8DC;AA+ED;;;;GAIG;AACH,4CAQC;AAiCD;;;;;;;;;;;GAWG;AACH,2CAyDC;AAID,2EAA2E;AAC3E,sCAgEC;AAID;;;;GAIG;AACH,4CAyCC;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,2CAiDC;AAID;;;;;GAKG;AACH,4CAqBC;AAID;;;;;;GAMG;AACH,wCAmBC;AAID;;;;;GAKG;AACH,4CAiDC;AAoCD;;;;;GAKG;AACH,0CA8DC;AAwWD,uCAyBC;AA7XD;;;;;GAKG;AACH,8CAyEC;AA2ID;;;;GAIG;AACH,4CAyDC;AAqBD;;;;;GAKG;AACH,iDAgBC;AA/sCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,+CAiFC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDAyFC"}