Skip to content

Commit f761aa8

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents 254095a + 228cbbf commit f761aa8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+8889
-12825
lines changed

cli/asc.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -662,15 +662,16 @@ exports.main = function main(argv, options, callback) {
662662
add("remove-unused-brs");
663663
add("remove-unused-names");
664664
add("optimize-instructions");
665-
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
665+
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
666666
add("pick-load-signs");
667+
add("simplify-globals-optimizing"); // differs
667668
}
668669
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
669670
add("precompute-propagate");
670671
} else {
671672
add("precompute");
672673
}
673-
// this will be done later
674+
// this will be done later (1)
674675
// if (optimizeLevel >= 2 || shrinkLevel >= 2) {
675676
// add("code-pushing");
676677
// }
@@ -691,15 +692,19 @@ exports.main = function main(argv, options, callback) {
691692
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
692693
add("code-folding");
693694
}
695+
if (optimizeLevel >= 2 || shrinkLevel >= 1) { // differs
696+
add("simplify-globals-optimizing");
697+
}
694698
add("merge-blocks");
695699
add("remove-unused-brs");
696700
add("remove-unused-names");
697701
add("merge-blocks");
698-
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
699-
add("precompute-propagate");
700-
} else {
701-
add("precompute");
702-
}
702+
// make this later & move to (2)
703+
// if (optimizeLevel >= 3 || shrinkLevel >= 2) {
704+
// add("precompute-propagate");
705+
// } else {
706+
// add("precompute");
707+
// }
703708
add("optimize-instructions");
704709
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
705710
add("rse");
@@ -720,6 +725,13 @@ exports.main = function main(argv, options, callback) {
720725
} else {
721726
add("simplify-globals");
722727
}
728+
// moved from (2)
729+
// it works better after globals optimizations like simplify-globals, inlining-optimizing and etc
730+
if (optimizeLevel >= 2 || shrinkLevel >= 1) { // differs
731+
add("precompute-propagate");
732+
} else {
733+
add("precompute");
734+
}
723735
// replace indirect calls with direct, reduce arity and
724736
// inline this calls if possible
725737
add("directize"); // differs
@@ -731,40 +743,44 @@ exports.main = function main(argv, options, callback) {
731743
}
732744
if (optimizeLevel >= 2 || shrinkLevel >= 1) { // differs
733745
add("rse");
734-
add("vacuum");
735-
736746
// rearrange / reduce switch cases again
737747
add("remove-unused-brs");
738-
add("remove-unused-names");
739-
add("merge-blocks");
740748
add("vacuum");
741749

742750
// replace indirect calls with direct and inline if possible again.
743751
add("directize");
744752
add("inlining-optimizing");
745753
// move some code after early return which potentially could reduce computations
746754
// do this after CFG cleanup (originally it was done before)
755+
// moved from (1)
747756
add("code-pushing");
748757

749758
// this quite expensive so do this only for highest opt level
759+
add("simplify-globals-optimizing");
750760
if (optimizeLevel >= 3) {
751761
add("simplify-locals-nostructure");
752-
add("reorder-locals");
753762
add("vacuum");
763+
764+
add("precompute-propagate");
765+
add("simplify-locals-nostructure");
766+
add("vacuum");
767+
768+
add("reorder-locals");
769+
} else {
770+
add("simplify-globals-optimizing");
754771
}
755-
// finally optimize all remaining peepholes
756-
add("simplify-globals-optimizing");
757772
add("optimize-instructions");
758773
}
759774
// remove unused elements of table and pack / reduce memory
760775
add("duplicate-function-elimination"); // differs
761776
add("remove-unused-nonfunction-module-elements"); // differs
762777
add("memory-packing");
763778
add("remove-unused-module-elements"); // differs
764-
if (optimizeLevel >= 3 || shrinkLevel >= 1) { // differs. was optimizeLevel >= 2
765-
add("generate-stack-ir");
766-
add("optimize-stack-ir");
767-
}
779+
// It seems stack-ir unuseful for our needs.
780+
// if (optimizeLevel >= 3 || shrinkLevel >= 1) { // differs. was optimizeLevel >= 2
781+
// add("generate-stack-ir");
782+
// add("optimize-stack-ir");
783+
// }
768784
}
769785

770786
// Append additional passes if requested and execute

lib/loader/index.d.ts

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,70 @@ interface ASUtil {
1919
_start(): void;
2020
/** Allocates a new string in the module's memory and returns a reference (pointer) to it. */
2121
__allocString(str: string): number;
22-
/** Reads (copies) the value of a string from the module's memory. */
23-
__getString(ptr: number): string;
2422
/** Allocates a new array in the module's memory and returns a reference (pointer) to it. */
2523
__allocArray(id: number, values: ArrayLike<number>): number;
24+
25+
/** Reads (copies) the value of a string from the module's memory. */
26+
__getString(ptr: number): string;
2627
/** Reads (copies) the values of an array from the module's memory. */
2728
__getArray(ptr: number): number[];
2829
/** Gets a view on the values of an array in the module's memory. */
2930
__getArrayView(ptr: number): ArrayBufferView;
30-
/** Reads the values of Int8Array from the module's memory. */
31+
32+
/** Reads (copies) the values of Int8Array from the module's memory. */
3133
__getInt8Array(ptr: number): Int8Array;
32-
/** Reads the values of Uint8Array from the module's memory. */
34+
/** Reads (copies) the values of Uint8Array from the module's memory. */
3335
__getUint8Array(ptr: number): Uint8Array;
34-
/** Reads the values of Uint8Array from the module's memory. */
36+
/** Reads (copies) the values of Uint8Array from the module's memory. */
3537
__getUint8ClampedArray(ptr: number): Uint8ClampedArray;
36-
/** Reads the values of Int16Array from the module's memory. */
38+
/** Reads (copies) the values of Int16Array from the module's memory. */
3739
__getInt16Array(ptr: number): Int16Array;
38-
/** Reads the values of Uint16Array from the module's memory. */
40+
/** Reads (copies) the values of Uint16Array from the module's memory. */
3941
__getUint16Array(ptr: number): Uint16Array;
40-
/** Reads the values of Int32Array from the module's memory. */
42+
/** Reads (copies) the values of Int32Array from the module's memory. */
4143
__getInt32Array(ptr: number): Int32Array;
42-
/** Reads the values of Uint32Array from the module's memory. */
44+
/** Reads (copies) the values of Uint32Array from the module's memory. */
4345
__getUint32Array(ptr: number): Uint32Array;
44-
/** Reads the values of Int32Array from the module's memory. */
46+
/** Reads (copies) the values of Int32Array from the module's memory. */
4547
__getInt64Array?(ptr: number): BigInt64Array;
46-
/** Reads the values of Uint32Array from the module's memory. */
48+
/** Reads (copies) the values of Uint32Array from the module's memory. */
4749
__getUint64Array?(ptr: number): BigUint64Array;
48-
/** Reads the values of Float32Array from the module's memory. */
50+
/** Reads (copies) the values of Float32Array from the module's memory. */
4951
__getFloat32Array(ptr: number): Float32Array;
50-
/** Reads the values of Float64Array from the module's memory. */
52+
/** Reads (copies) the values of Float64Array from the module's memory. */
5153
__getFloat64Array(ptr: number): Float64Array;
54+
55+
/** Reads the values of Int8Array from the module's memory. */
56+
__getInt8ArrayView(ptr: number): Int8Array;
57+
/** Reads the values of Uint8Array from the module's memory. */
58+
__getUint8ArrayView(ptr: number): Uint8Array;
59+
/** Reads the values of Uint8Array from the module's memory. */
60+
__getUint8ClampedArrayView(ptr: number): Uint8ClampedArray;
61+
/** Reads the values of Int16Array from the module's memory. */
62+
__getInt16ArrayView(ptr: number): Int16Array;
63+
/** Reads the values of Uint16Array from the module's memory. */
64+
__getUint16ArrayView(ptr: number): Uint16Array;
65+
/** Reads the values of Int32Array from the module's memory. */
66+
__getInt32ArrayView(ptr: number): Int32Array;
67+
/** Reads the values of Uint32Array from the module's memory. */
68+
__getUint32ArrayView(ptr: number): Uint32Array;
69+
/** Reads the values of Int32Array from the module's memory. */
70+
__getInt64ArrayView?(ptr: number): BigInt64Array;
71+
/** Reads the values of Uint32Array from the module's memory. */
72+
__getUint64ArrayView?(ptr: number): BigUint64Array;
73+
/** Reads the values of Float32Array from the module's memory. */
74+
__getFloat32ArrayView(ptr: number): Float32Array;
75+
/** Reads the values of Float64Array from the module's memory. */
76+
__getFloat64ArrayView(ptr: number): Float64Array;
77+
5278
/** Reads (copies) the data of an ArrayBuffer from the module's memory. */
5379
__getArrayBuffer(ptr: number): ArrayBuffer;
5480
/** Retains a reference to a managed object externally, making sure that it doesn't become collected prematurely. Returns the pointer. */
5581
__retain(ptr: number): number;
5682
/** Releases a previously retained reference to a managed object, allowing the runtime to collect it once its reference count reaches zero. */
5783
__release(ptr: number): void;
84+
/** Resets base pointer to initial offset. Uses only for stub runtime. */
85+
__reset?(): void;
5886
/** Allocates an instance of the class represented by the specified id. */
5987
__alloc(size: number, id: number): number;
6088
/** Tests whether a managed object is an instance of the class represented by the specified base id. */

lib/loader/index.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,37 +217,52 @@ function postInstantiate(baseModule, instance) {
217217

218218
baseModule.__getArrayBuffer = __getArrayBuffer;
219219

220-
function getTypedArrayImpl(Type, alignLog2, ptr) {
220+
function getTypedArrayView(Type, alignLog2, ptr) {
221221
const buffer = memory.buffer;
222222
const U32 = new Uint32Array(buffer);
223223
const bufPtr = U32[ptr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2];
224224
return new Type(buffer, bufPtr, U32[bufPtr + SIZE_OFFSET >>> 2] >>> alignLog2);
225225
}
226226

227+
function getTypedArray(Type, alignLog2, ptr) {
228+
return new Type(getTypedArrayView(Type, alignLog2, ptr));
229+
}
230+
227231
/** Gets a view on the values of a known-to-be Int8Array in the module's memory. */
228-
baseModule.__getInt8Array = getTypedArrayImpl.bind(null, Int8Array, 0);
232+
baseModule.__getInt8Array = getTypedArray.bind(null, Int8Array, 0);
233+
baseModule.__getInt8ArrayView = getTypedArrayView.bind(null, Int8Array, 0);
229234
/** Gets a view on the values of a known-to-be Uint8Array in the module's memory. */
230-
baseModule.__getUint8Array = getTypedArrayImpl.bind(null, Uint8Array, 0);
235+
baseModule.__getUint8Array = getTypedArray.bind(null, Uint8Array, 0);
236+
baseModule.__getUint8ArrayView = getTypedArrayView.bind(null, Uint8Array, 0);
231237
/** Gets a view on the values of a known-to-be Uint8ClampedArray in the module's memory. */
232-
baseModule.__getUint8ClampedArray = getTypedArrayImpl.bind(null, Uint8ClampedArray, 0);
238+
baseModule.__getUint8ClampedArray = getTypedArray.bind(null, Uint8ClampedArray, 0);
239+
baseModule.__getUint8ClampedArrayView = getTypedArrayView.bind(null, Uint8ClampedArray, 0);
233240
/** Gets a view on the values of a known-to-be Int16Array in the module's memory. */
234-
baseModule.__getInt16Array = getTypedArrayImpl.bind(null, Int16Array, 1);
241+
baseModule.__getInt16Array = getTypedArray.bind(null, Int16Array, 1);
242+
baseModule.__getInt16ArrayView = getTypedArrayView.bind(null, Int16Array, 1);
235243
/** Gets a view on the values of a known-to-be Uint16Array in the module's memory. */
236-
baseModule.__getUint16Array = getTypedArrayImpl.bind(null, Uint16Array, 1);
244+
baseModule.__getUint16Array = getTypedArray.bind(null, Uint16Array, 1);
245+
baseModule.__getUint16ArrayView = getTypedArrayView.bind(null, Uint16Array, 1);
237246
/** Gets a view on the values of a known-to-be Int32Array in the module's memory. */
238-
baseModule.__getInt32Array = getTypedArrayImpl.bind(null, Int32Array, 2);
247+
baseModule.__getInt32Array = getTypedArray.bind(null, Int32Array, 2);
248+
baseModule.__getInt32ArrayView = getTypedArrayView.bind(null, Int32Array, 2);
239249
/** Gets a view on the values of a known-to-be Uint32Array in the module's memory. */
240-
baseModule.__getUint32Array = getTypedArrayImpl.bind(null, Uint32Array, 2);
250+
baseModule.__getUint32Array = getTypedArray.bind(null, Uint32Array, 2);
251+
baseModule.__getUint32ArrayView = getTypedArrayView.bind(null, Uint32Array, 2);
241252
if (BIGINT) {
242253
/** Gets a view on the values of a known-to-be-Int64Array in the module's memory. */
243-
baseModule.__getInt64Array = getTypedArrayImpl.bind(null, BigInt64Array, 3);
254+
baseModule.__getInt64Array = getTypedArray.bind(null, BigInt64Array, 3);
255+
baseModule.__getInt64ArrayView = getTypedArrayView.bind(null, BigInt64Array, 3);
244256
/** Gets a view on the values of a known-to-be-Uint64Array in the module's memory. */
245-
baseModule.__getUint64Array = getTypedArrayImpl.bind(null, BigUint64Array, 3);
257+
baseModule.__getUint64Array = getTypedArray.bind(null, BigUint64Array, 3);
258+
baseModule.__getUint64ArrayView = getTypedArrayView.bind(null, BigUint64Array, 3);
246259
}
247260
/** Gets a view on the values of a known-to-be Float32Array in the module's memory. */
248-
baseModule.__getFloat32Array = getTypedArrayImpl.bind(null, Float32Array, 2);
261+
baseModule.__getFloat32Array = getTypedArray.bind(null, Float32Array, 2);
262+
baseModule.__getFloat32ArrayView = getTypedArrayView.bind(null, Float32Array, 2);
249263
/** Gets a view on the values of a known-to-be Float64Array in the module's memory. */
250-
baseModule.__getFloat64Array = getTypedArrayImpl.bind(null, Float64Array, 3);
264+
baseModule.__getFloat64Array = getTypedArray.bind(null, Float64Array, 3);
265+
baseModule.__getFloat64ArrayView = getTypedArrayView.bind(null, Float64Array, 3);
251266

252267
/** Tests whether an object is an instance of the class represented by the specified base id. */
253268
function __instanceof(ptr, baseId) {

lib/loader/tests/build/untouched.wasm

104 Bytes
Binary file not shown.

lib/loader/tests/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ assert.strictEqual(module.__getString(module.COLOR), "red");
9595
let ref = module.__retain(module.__allocArray(module.UINT32ARRAY_ID, arr));
9696
assert(module.__instanceof(ref, module.UINT32ARRAY_ID));
9797
assert.deepEqual(module.__getUint32Array(ref), new Uint32Array(arr));
98+
assert.deepEqual(module.__getUint32ArrayView(ref), new Uint32Array(arr));
9899
assert.deepEqual(module.__getArray(ref), arr);
99100
module.__release(ref);
100101
try { module.__release(ref); assert(false); } catch (e) {};
@@ -106,6 +107,7 @@ assert.strictEqual(module.__getString(module.COLOR), "red");
106107
let ref = module.__retain(module.__allocArray(module.FLOAT32ARRAY_ID, arr));
107108
assert(module.__instanceof(ref, module.FLOAT32ARRAY_ID));
108109
assert.deepEqual(module.__getFloat32Array(ref), new Float32Array(arr));
110+
assert.deepEqual(module.__getFloat32ArrayView(ref), new Float32Array(arr));
109111
assert.deepEqual(module.__getArray(ref), arr);
110112
module.__release(ref);
111113
try { module.__release(ref); assert(false); } catch (e) {};
@@ -154,7 +156,7 @@ module.dotrace(42);
154156

155157
// should be able to mutate an array in place using getArrayView
156158
{
157-
let ptr = module.__retain(module.__allocArray(module.FLOAT32ARRAY_ID, [ 1, 2, 3]));
159+
let ptr = module.__retain(module.__allocArray(module.FLOAT32ARRAY_ID, [1, 2, 3]));
158160
let view = module.__getArrayView(ptr);
159161
assert.deepEqual(view, new Float32Array([1, 2, 3]));
160162
module.modifyFloat32Array(ptr, 0, 4);
@@ -165,12 +167,15 @@ module.dotrace(42);
165167
// should be able to mutate an array in place using getFloat32Array
166168
{
167169
let ptr = module.newFloat32Array(3); // returns are pre-retained
168-
let view = module.__getFloat32Array(ptr);
170+
let view = module.__getFloat32ArrayView(ptr);
171+
let arr = module.__getFloat32Array(ptr);
169172
assert.deepEqual(view, new Float32Array([0, 0, 0]));
173+
assert.deepEqual(arr, new Float32Array([0, 0, 0]));
170174
module.modifyFloat32Array(ptr, 0, 3);
171175
module.modifyFloat32Array(ptr, 1, 2);
172176
module.modifyFloat32Array(ptr, 2, 1);
173177
assert.deepEqual(view, new Float32Array([3, 2, 1]));
178+
assert.deepEqual(arr, new Float32Array([0, 0, 0]));
174179
module.__release(ptr);
175180
}
176181

std/assembly/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ declare class String {
14171417
endsWith(other: string): bool;
14181418
indexOf(other: string, fromIndex?: i32): i32;
14191419
lastIndexOf(other: string, fromIndex?: i32): i32;
1420+
localeCompare(other: string): i32;
14201421
includes(other: string): bool;
14211422
startsWith(other: string): bool;
14221423
substr(start: i32, length?: i32): string;

std/assembly/rt/index-stub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { __alloc, __retain, __release, __collect } from "rt/stub";
1+
export { __alloc, __retain, __release, __collect, __reset } from "rt/stub";
22
export { __rtti_base } from "rt";

std/assembly/rt/pure.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,3 @@ export function __retain(ptr: usize): usize {
260260
export function __release(ptr: usize): void {
261261
if (ptr > __heap_base) decrement(changetype<Block>(ptr - BLOCK_OVERHEAD));
262262
}
263-
264-
// @ts-ignore: decorator
265-
@global @unsafe
266-
export function __reset(): void {
267-
}

0 commit comments

Comments
 (0)