watr 4.6.10 → 4.7.1

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,12 +56,10 @@ export function strength(ast: any[]): any[];
68
56
  */
69
57
  export function branch(ast: any[]): any[];
70
58
  export function propagate(ast: any): any;
71
- /**
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[];
59
+ export function inline(ast: any, { simdOnly, pin }?: {
60
+ simdOnly?: boolean;
61
+ pin?: any;
62
+ }): any;
77
63
  /**
78
64
  * Inline functions that are called from exactly one place into their lone caller,
79
65
  * then delete them. Unlike {@link inline} (which duplicates tiny stateless bodies),
@@ -103,7 +89,35 @@ export function inline(ast: any[]): any[];
103
89
  * @param {Array} ast
104
90
  * @returns {Array}
105
91
  */
106
- export function inlineOnce(ast: any[]): any[];
92
+ export function inlineOnce(ast: any[], { pin }?: {
93
+ pin?: any;
94
+ }): any[];
95
+ /**
96
+ * Devirtualize `call_indirect` through NaN-boxed closure values with a statically
97
+ * known candidate set. `let f = c ? a : b; … f(x)` emits a select of two i64
98
+ * closure constants into an f64 local; every call site then derives the table
99
+ * slot from that local's bits:
100
+ * (i32.wrap_i64 (i64.and (i64.shr_u (i64.reinterpret_f64 (local.get $f))
101
+ * (i64.const 32)) (i64.const 32767)))
102
+ * When EVERY write to $f in the function is such a constant set (≤2 candidates),
103
+ * each call site becomes a guarded direct call —
104
+ * (if (result …) (i64.eq (i64.reinterpret_f64 (local.get $f)) (i64.const C1))
105
+ * (then (call $tramp1 …args)) (else <next guard | original call_indirect>))
106
+ * — with the ORIGINAL call_indirect kept as the final arm, so unknown flows
107
+ * (zero-init paths the analysis can't see) behave exactly as before: the rewrite
108
+ * is a pure branch-predicted fast path, ~25% on callback loops, and the direct
109
+ * calls participate in inlining. A trivially-constant slot ((i32.const N) after
110
+ * fold) becomes a bare direct call with no guard.
111
+ *
112
+ * Soundness: the guard compares the SAME bits the slot extraction reads, so
113
+ * whichever constant flows to the call dispatches identically in both forms;
114
+ * candidates that don't resolve to an elem entry (or whose target's signature
115
+ * differs from the call's type — would-be runtime trap) disable the site. Any
116
+ * table mutation op in the module disables the pass entirely. The function
117
+ * table is exported for host-side closure invocation (reads); host mutation of
118
+ * it is outside the ABI contract, same as the closure-constant model itself.
119
+ */
120
+ export function devirt(ast: any): any;
107
121
  /**
108
122
  * Normalize options to a { passName: bool } map. An explicit object is kept
109
123
  * 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,8CA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