diff --git a/std/assembly/array.ts b/std/assembly/array.ts index 1771618b..2fcdf6fd 100644 --- a/std/assembly/array.ts +++ b/std/assembly/array.ts @@ -35,8 +35,6 @@ export class Array extends ArrayBufferView { // length is modified in a way that a null value would exist. Otherwise, the compiler wouldn't be // able to guarantee type-safety anymore. For lack of a better word, such an array is "holey". - // Also note that capacity, not length, indicates the actual retained contents. - private length_: i32; static isArray(value: U): bool { @@ -69,14 +67,23 @@ export class Array extends ArrayBufferView { return this.length_; } - set length(length: i32) { + set length(newLength: i32) { + var oldLength = this.length_; if (isReference()) { if (!isNullable()) { - if (length > this.length_) throw new Error(E_HOLEYARRAY); + if (newLength > oldLength) throw new Error(E_HOLEYARRAY); } } - ensureSize(changetype(this), length, alignof()); - this.length_ = length; + ensureSize(changetype(this), newLength, alignof()); + if (isManaged()) { // release no longer used refs + if (oldLength > newLength) { + let dataStart = this.dataStart; + do __release(load(dataStart + (--oldLength << alignof()))); + while (oldLength > newLength); + // no need to zero memory on shrink -> is zeroed on grow + } + } + this.length_ = newLength; } every(fn: (value: T, index: i32, array: Array) => bool): bool { @@ -195,12 +202,7 @@ export class Array extends ArrayBufferView { var newLength = length + 1; ensureSize(changetype(this), newLength, alignof()); if (isManaged()) { - let offset = this.dataStart + (length << alignof()); - let oldRef: usize = load(offset); - if (changetype(value) != oldRef) { - store(offset, __retain(changetype(value))); - __release(oldRef); - } + store(this.dataStart + (length << alignof()), __retain(changetype(value))); } else { store(this.dataStart + (length << alignof()), value); } @@ -247,23 +249,35 @@ export class Array extends ArrayBufferView { var count = min(last - from, len - to); if (isManaged()) { - // TODO: retain/release + consider intersection, only releasing what's removed - ERROR("not implemented"); - } else { - if (from < to && to < (from + count)) { + if (from < to && to < (from + count)) { // right to left from += count - 1; to += count - 1; while (count) { - store(dataStart + (to << alignof()), load(dataStart + (from << alignof()))); + let oldRef: usize = load(dataStart + (to << alignof())); + let newRef: usize = load(dataStart + (from << alignof())); + if (newRef != oldRef) { + store(dataStart + (to << alignof()), __retain(newRef)); + __release(oldRef); + } --from, --to, --count; } - } else { - memory.copy( - dataStart + (to << alignof()), - dataStart + (from << alignof()), - count << alignof() - ); + } else { // left to right + while (count) { + let oldRef: usize = load(dataStart + (to << alignof())); + let newRef: usize = load(dataStart + (from << alignof())); + if (newRef != oldRef) { + store(dataStart + (to << alignof()), __retain(newRef)); + __release(oldRef); + } + ++from, ++to, --count; + } } + } else { + memory.copy( // is memmove + dataStart + (to << alignof()), + dataStart + (from << alignof()), + count << alignof() + ); } return this; } @@ -273,7 +287,7 @@ export class Array extends ArrayBufferView { if (length < 1) throw new RangeError(E_EMPTYARRAY); var element = load(this.dataStart + ((--length) << alignof())); this.length_ = length; - return element; + return element; // no need to retain -> is moved } forEach(fn: (value: T, index: i32, array: Array) => void): void { @@ -345,7 +359,7 @@ export class Array extends ArrayBufferView { null ); this.length_ = lastIndex; - return element; + return element; // no need to retain -> is moved } some(fn: (value: T, index: i32, array: Array) => bool): bool { @@ -408,7 +422,7 @@ export class Array extends ArrayBufferView { store(resultStart + (i << alignof()), load(thisBase + (i << alignof())) ); - // element is moved, so refcount doesn't change + // no need to retain -> is moved } } else { memory.copy( @@ -713,7 +727,7 @@ export class Array extends ArrayBufferView { @unsafe private __visit_impl(cookie: u32): void { if (isManaged()) { let cur = this.dataStart; - let end = cur + this.dataLength; + let end = cur + (this.length_ << alignof()); while (cur < end) { let val = load(cur); if (val) __visit(val, cookie); diff --git a/tests/compiler/assert-nonnull.optimized.wat b/tests/compiler/assert-nonnull.optimized.wat index 416aa0f0..ed5bd823 100644 --- a/tests/compiler/assert-nonnull.optimized.wat +++ b/tests/compiler/assert-nonnull.optimized.wat @@ -64,7 +64,7 @@ if i32.const 24 i32.const 136 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -78,7 +78,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -105,7 +105,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/assert-nonnull.untouched.wat b/tests/compiler/assert-nonnull.untouched.wat index 57d33b37..780007f7 100644 --- a/tests/compiler/assert-nonnull.untouched.wat +++ b/tests/compiler/assert-nonnull.untouched.wat @@ -106,7 +106,7 @@ if i32.const 24 i32.const 136 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -120,7 +120,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -168,7 +168,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/retain-release-sanity.optimized.wat b/tests/compiler/retain-release-sanity.optimized.wat index c87cc3af..1aaa5944 100644 --- a/tests/compiler/retain-release-sanity.optimized.wat +++ b/tests/compiler/retain-release-sanity.optimized.wat @@ -2015,7 +2015,7 @@ if i32.const 424 i32.const 376 - i32.const 273 + i32.const 287 i32.const 20 call $~lib/builtins/abort unreachable @@ -2038,7 +2038,6 @@ (func $~lib/array/Array<~lib/string/String>#push (; 32 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) - (local $3 i32) i32.const 584 call $~lib/rt/pure/__retain drop @@ -2056,19 +2055,9 @@ i32.const 2 i32.shl i32.add - local.tee $1 - i32.load - local.tee $3 i32.const 584 - i32.ne - if - local.get $1 - i32.const 584 - call $~lib/rt/pure/__retain - i32.store - local.get $3 - call $~lib/rt/pure/__release - end + call $~lib/rt/pure/__retain + i32.store local.get $0 local.get $2 i32.store offset=12 @@ -2738,7 +2727,9 @@ i32.load offset=4 local.tee $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $0 loop $continue|0 diff --git a/tests/compiler/retain-release-sanity.untouched.wat b/tests/compiler/retain-release-sanity.untouched.wat index 4567ba53..529966f6 100644 --- a/tests/compiler/retain-release-sanity.untouched.wat +++ b/tests/compiler/retain-release-sanity.untouched.wat @@ -3782,7 +3782,7 @@ if i32.const 424 i32.const 376 - i32.const 273 + i32.const 287 i32.const 20 call $~lib/builtins/abort unreachable @@ -3824,7 +3824,7 @@ if i32.const 472 i32.const 376 - i32.const 58 + i32.const 56 i32.const 20 call $~lib/builtins/abort unreachable @@ -3855,7 +3855,7 @@ if i32.const 472 i32.const 376 - i32.const 58 + i32.const 56 i32.const 20 call $~lib/builtins/abort unreachable @@ -3869,7 +3869,6 @@ (local $2 i32) (local $3 i32) (local $4 i32) - (local $5 i32) local.get $1 call $~lib/rt/pure/__retain drop @@ -3890,29 +3889,17 @@ i32.const 2 i32.shl i32.add - local.set $4 - local.get $4 - i32.load - local.set $5 local.get $1 - local.get $5 - i32.ne - if - local.get $4 - local.get $1 - call $~lib/rt/pure/__retain - i32.store - local.get $5 - call $~lib/rt/pure/__release - end + call $~lib/rt/pure/__retain + i32.store local.get $0 local.get $3 i32.store offset=12 local.get $3 - local.set $5 + local.set $4 local.get $1 call $~lib/rt/pure/__release - local.get $5 + local.get $4 ) (func $~lib/string/String#get:length (; 37 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -4728,7 +4715,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -4764,7 +4753,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index e480a43b..0effe66d 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -26,7 +26,7 @@ if i32.const 24 i32.const 136 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -40,7 +40,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -63,7 +63,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array-access.untouched.wat b/tests/compiler/std/array-access.untouched.wat index cc1f1ae2..ee37d0f1 100644 --- a/tests/compiler/std/array-access.untouched.wat +++ b/tests/compiler/std/array-access.untouched.wat @@ -43,7 +43,7 @@ if i32.const 24 i32.const 136 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -57,7 +57,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -85,7 +85,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -134,7 +134,7 @@ if i32.const 24 i32.const 136 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -148,7 +148,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -374,7 +374,7 @@ if i32.const 24 i32.const 136 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -388,7 +388,7 @@ if i32.const 184 i32.const 136 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array-literal.optimized.wat b/tests/compiler/std/array-literal.optimized.wat index 3bdd0d17..f1827972 100644 --- a/tests/compiler/std/array-literal.optimized.wat +++ b/tests/compiler/std/array-literal.optimized.wat @@ -47,7 +47,7 @@ if i32.const 136 i32.const 192 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -68,7 +68,7 @@ if i32.const 136 i32.const 192 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -2170,7 +2170,9 @@ i32.load offset=4 local.tee $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $0 loop $continue|0 diff --git a/tests/compiler/std/array-literal.untouched.wat b/tests/compiler/std/array-literal.untouched.wat index a42ca1e6..a5bdca6c 100644 --- a/tests/compiler/std/array-literal.untouched.wat +++ b/tests/compiler/std/array-literal.untouched.wat @@ -70,7 +70,7 @@ if i32.const 136 i32.const 192 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -102,7 +102,7 @@ if i32.const 136 i32.const 192 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -4009,7 +4009,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -4045,7 +4047,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 921ccc02..6fe95033 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -2367,7 +2367,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -2521,7 +2521,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -2858,7 +2858,7 @@ if i32.const 872 i32.const 488 - i32.const 273 + i32.const 287 i32.const 20 call $~lib/builtins/abort unreachable @@ -2905,7 +2905,7 @@ call $~lib/rt/pure/__release i32.const 272 i32.const 488 - i32.const 215 + i32.const 217 i32.const 59 call $~lib/builtins/abort unreachable @@ -2942,9 +2942,6 @@ (func $~lib/array/Array#copyWithin (; 50 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (local $4 i32) (local $5 i32) - local.get $0 - i32.load offset=4 - local.set $5 local.get $3 local.get $0 i32.load offset=12 @@ -2954,6 +2951,9 @@ i32.lt_s select local.set $3 + local.get $0 + i32.load offset=4 + local.tee $5 local.get $1 i32.const 0 i32.lt_s @@ -2975,7 +2975,10 @@ i32.lt_s select end - local.set $1 + local.tee $1 + i32.const 2 + i32.shl + i32.add local.get $2 i32.const 0 i32.lt_s @@ -2997,7 +3000,11 @@ i32.lt_s select end - local.set $2 + local.tee $2 + i32.const 2 + i32.shl + local.get $5 + i32.add local.get $3 i32.const 0 i32.lt_s @@ -3021,84 +3028,18 @@ end local.get $2 i32.sub - local.tee $3 + local.tee $2 local.get $4 local.get $1 i32.sub - local.tee $4 - local.get $3 - local.get $4 - i32.lt_s - select - local.set $3 - local.get $1 - local.get $2 - local.get $3 - i32.add - i32.lt_s - i32.const 0 + local.tee $1 local.get $2 local.get $1 i32.lt_s select - if - local.get $3 - i32.const 1 - i32.sub - local.tee $4 - local.get $2 - i32.add - local.set $2 - local.get $1 - local.get $4 - i32.add - local.set $1 - loop $continue|0 - local.get $3 - if - local.get $1 - i32.const 2 - i32.shl - local.get $5 - i32.add - local.get $2 - i32.const 2 - i32.shl - local.get $5 - i32.add - i32.load - i32.store - local.get $2 - i32.const 1 - i32.sub - local.set $2 - local.get $1 - i32.const 1 - i32.sub - local.set $1 - local.get $3 - i32.const 1 - i32.sub - local.set $3 - br $continue|0 - end - end - else - local.get $1 - i32.const 2 - i32.shl - local.get $5 - i32.add - local.get $2 - i32.const 2 - i32.shl - local.get $5 - i32.add - local.get $3 - i32.const 2 - i32.shl - call $~lib/memory/memory.copy - end + i32.const 2 + i32.shl + call $~lib/memory/memory.copy local.get $0 call $~lib/rt/pure/__retain ) @@ -3144,7 +3085,7 @@ if i32.const 872 i32.const 488 - i32.const 334 + i32.const 348 i32.const 20 call $~lib/builtins/abort unreachable @@ -3985,7 +3926,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -5397,7 +5338,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -5911,7 +5852,7 @@ if i32.const 272 i32.const 488 - i32.const 47 + i32.const 45 i32.const 61 call $~lib/builtins/abort unreachable @@ -6187,7 +6128,7 @@ call $~lib/rt/pure/__release i32.const 4040 i32.const 488 - i32.const 114 + i32.const 121 i32.const 38 call $~lib/builtins/abort unreachable @@ -6443,7 +6384,7 @@ if i32.const 4040 i32.const 488 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -6457,7 +6398,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -6636,7 +6577,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -17031,7 +16972,9 @@ i32.load offset=4 local.tee $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $0 loop $continue|0 diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index b1e44bc6..aa775d7f 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -4243,7 +4243,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -4448,7 +4448,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -4856,7 +4856,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -4877,7 +4877,7 @@ if i32.const 872 i32.const 488 - i32.const 273 + i32.const 287 i32.const 20 call $~lib/builtins/abort unreachable @@ -4933,7 +4933,7 @@ block i32.const 272 i32.const 488 - i32.const 215 + i32.const 217 i32.const 59 call $~lib/builtins/abort unreachable @@ -5087,79 +5087,20 @@ i32.lt_s select local.set $11 - local.get $9 + local.get $4 local.get $8 - i32.lt_s - if (result i32) - local.get $8 - local.get $9 - local.get $11 - i32.add - i32.lt_s - else - i32.const 0 - end - if - local.get $9 - local.get $11 - i32.const 1 - i32.sub - i32.add - local.set $9 - local.get $8 - local.get $11 - i32.const 1 - i32.sub - i32.add - local.set $8 - block $break|0 - loop $continue|0 - local.get $11 - if - local.get $4 - local.get $8 - i32.const 2 - i32.shl - i32.add - local.get $4 - local.get $9 - i32.const 2 - i32.shl - i32.add - i32.load - i32.store - local.get $9 - i32.const 1 - i32.sub - local.set $9 - local.get $8 - i32.const 1 - i32.sub - local.set $8 - local.get $11 - i32.const 1 - i32.sub - local.set $11 - br $continue|0 - end - end - end - else - local.get $4 - local.get $8 - i32.const 2 - i32.shl - i32.add - local.get $4 - local.get $9 - i32.const 2 - i32.shl - i32.add - local.get $11 - i32.const 2 - i32.shl - call $~lib/memory/memory.copy - end + i32.const 2 + i32.shl + i32.add + local.get $4 + local.get $9 + i32.const 2 + i32.shl + i32.add + local.get $11 + i32.const 2 + i32.shl + call $~lib/memory/memory.copy local.get $0 call $~lib/rt/pure/__retain ) @@ -5296,7 +5237,7 @@ if i32.const 872 i32.const 488 - i32.const 334 + i32.const 348 i32.const 20 call $~lib/builtins/abort unreachable @@ -6337,7 +6278,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -8288,7 +8229,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -9390,7 +9331,7 @@ if i32.const 272 i32.const 488 - i32.const 47 + i32.const 45 i32.const 61 call $~lib/builtins/abort unreachable @@ -9669,7 +9610,7 @@ if i32.const 272 i32.const 488 - i32.const 47 + i32.const 45 i32.const 61 call $~lib/builtins/abort unreachable @@ -9739,7 +9680,7 @@ block i32.const 4040 i32.const 488 - i32.const 114 + i32.const 121 i32.const 38 call $~lib/builtins/abort unreachable @@ -10033,7 +9974,7 @@ if i32.const 4040 i32.const 488 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -10047,7 +9988,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -10161,7 +10102,7 @@ if i32.const 272 i32.const 488 - i32.const 47 + i32.const 45 i32.const 61 call $~lib/builtins/abort unreachable @@ -10246,7 +10187,7 @@ block i32.const 4040 i32.const 488 - i32.const 114 + i32.const 121 i32.const 38 call $~lib/builtins/abort unreachable @@ -10534,7 +10475,7 @@ if i32.const 4040 i32.const 488 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -10548,7 +10489,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -10853,7 +10794,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -11356,7 +11297,7 @@ if i32.const 272 i32.const 488 - i32.const 47 + i32.const 45 i32.const 61 call $~lib/builtins/abort unreachable @@ -11632,7 +11573,7 @@ block i32.const 4040 i32.const 488 - i32.const 114 + i32.const 121 i32.const 38 call $~lib/builtins/abort unreachable @@ -11898,7 +11839,7 @@ if i32.const 4040 i32.const 488 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -11912,7 +11853,7 @@ if i32.const 176 i32.const 488 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -24186,7 +24127,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -24222,7 +24165,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -24258,7 +24203,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -24294,7 +24241,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -24339,7 +24288,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -24384,7 +24335,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -24420,7 +24373,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 @@ -24456,7 +24411,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 diff --git a/tests/compiler/std/static-array.optimized.wat b/tests/compiler/std/static-array.optimized.wat index da87c808..0fc9400f 100644 --- a/tests/compiler/std/static-array.optimized.wat +++ b/tests/compiler/std/static-array.optimized.wat @@ -37,7 +37,7 @@ if i32.const 320 i32.const 376 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -624,7 +624,7 @@ if i32.const 320 i32.const 376 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -668,7 +668,7 @@ if i32.const 320 i32.const 376 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -712,7 +712,7 @@ if i32.const 320 i32.const 376 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/static-array.untouched.wat b/tests/compiler/std/static-array.untouched.wat index b061cafb..afc869cb 100644 --- a/tests/compiler/std/static-array.untouched.wat +++ b/tests/compiler/std/static-array.untouched.wat @@ -59,7 +59,7 @@ if i32.const 320 i32.const 376 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -1999,7 +1999,7 @@ if i32.const 320 i32.const 376 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -2067,7 +2067,7 @@ if i32.const 320 i32.const 376 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -2135,7 +2135,7 @@ if i32.const 320 i32.const 376 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index bcc96242..4b0ca1c2 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -3751,7 +3751,6 @@ (func $~lib/array/Array<~lib/string/String>#push (; 57 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) - (local $4 i32) local.get $1 call $~lib/rt/pure/__retain drop @@ -3769,19 +3768,9 @@ i32.const 2 i32.shl i32.add - local.tee $2 - i32.load - local.tee $4 local.get $1 - i32.ne - if - local.get $2 - local.get $1 - call $~lib/rt/pure/__retain - i32.store - local.get $4 - call $~lib/rt/pure/__release - end + call $~lib/rt/pure/__retain + i32.store local.get $0 local.get $3 i32.store offset=12 @@ -4018,7 +4007,7 @@ if i32.const 2296 i32.const 2248 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -4032,7 +4021,7 @@ if i32.const 232 i32.const 2248 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -9166,7 +9155,9 @@ i32.load offset=4 local.tee $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $0 loop $continue|0 diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index fd7f3f21..d9868054 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -5943,7 +5943,6 @@ (local $2 i32) (local $3 i32) (local $4 i32) - (local $5 i32) local.get $1 call $~lib/rt/pure/__retain drop @@ -5964,29 +5963,17 @@ i32.const 2 i32.shl i32.add - local.set $4 - local.get $4 - i32.load - local.set $5 local.get $1 - local.get $5 - i32.ne - if - local.get $4 - local.get $1 - call $~lib/rt/pure/__retain - i32.store - local.get $5 - call $~lib/rt/pure/__release - end + call $~lib/rt/pure/__retain + i32.store local.get $0 local.get $3 i32.store offset=12 local.get $3 - local.set $5 + local.set $4 local.get $1 call $~lib/rt/pure/__release - local.get $5 + local.get $4 ) (func $~lib/string/String#split (; 61 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) @@ -6331,7 +6318,7 @@ if i32.const 2296 i32.const 2248 - i32.const 99 + i32.const 106 i32.const 45 call $~lib/builtins/abort unreachable @@ -6345,7 +6332,7 @@ if i32.const 232 i32.const 2248 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -12448,7 +12435,9 @@ local.set $2 local.get $2 local.get $0 - i32.load offset=8 + i32.load offset=12 + i32.const 2 + i32.shl i32.add local.set $3 block $break|0 diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 93e7c6aa..931f9eaa 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -3354,7 +3354,7 @@ if i32.const 336 i32.const 512 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -3605,7 +3605,7 @@ if i32.const 336 i32.const 512 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index c24bf736..0e620958 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -5439,7 +5439,7 @@ if i32.const 336 i32.const 512 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable @@ -5766,7 +5766,7 @@ if i32.const 336 i32.const 512 - i32.const 102 + i32.const 109 i32.const 61 call $~lib/builtins/abort unreachable