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.
- package/dist/watr.js +1138 -383
- package/dist/watr.min.js +6 -6
- package/dist/watr.wasm +0 -0
- package/package.json +8 -4
- package/src/compile.js +93 -26
- package/src/optimize.js +1359 -394
- package/types/src/compile.d.ts +5 -1
- package/types/src/compile.d.ts.map +1 -1
- package/types/src/optimize.d.ts +28 -46
- package/types/src/optimize.d.ts.map +1 -1
package/types/src/compile.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AAuCA;;;;;;;;;GASG;AACH,uCAPW,MAAM,QAAM,GACV,UAAU,CAkRtB"}
|
package/types/src/optimize.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
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
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
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
|
|
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":"
|
|
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"}
|