Skip to content

Commit 50acba1

Browse files
committed
fix assertion bug in injectClosedLocals
1 parent f4d82ea commit 50acba1

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

src/compiler.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -6043,7 +6043,7 @@ export class Compiler extends DiagnosticEmitter {
60436043
switch (target.kind) {
60446044
case ElementKind.LOCAL: {
60456045
let local = <Local>target;
6046-
if (local.closureContextOffset >= 0) {
6046+
if (local.closureContextOffset > 0) {
60476047
// TODO: ability to update closed over locals
60486048
this.error(
60496049
DiagnosticCode.Not_implemented,
@@ -6439,12 +6439,13 @@ export class Compiler extends DiagnosticEmitter {
64396439
for (let i = 0, k = _values.length; i < k; ++i) {
64406440
let local = unchecked(_values[i]);
64416441
let nativeType = local.type.toNativeType();
6442+
assert(local.closureContextOffset > 0);
64426443
exprs[i] = module.store(
64436444
local.type.byteSize,
64446445
module.local_get(closureContextLocal.index, this.options.nativeSizeType),
64456446
module.local_get(local.index, nativeType),
64466447
nativeType,
6447-
assert(local.closureContextOffset >= 0)
6448+
local.closureContextOffset
64486449
);
64496450
}
64506451
return module.block(null, exprs);
@@ -8454,7 +8455,7 @@ export class Compiler extends DiagnosticEmitter {
84548455
let localType = local.type;
84558456
assert(localType != Type.void);
84568457
var localClosureContextOffset = local.closureContextOffset;
8457-
if (localClosureContextOffset >= 0) {
8458+
if (localClosureContextOffset > 0) {
84588459
let contextLocal = assert(flow.lookupLocal(CommonNames.this_));
84598460

84608461
// TODO: replace this with a class field access, once we are able to construct the class before

src/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3277,7 +3277,7 @@ export class Local extends VariableLikeElement {
32773277
/** Declaration reference. */
32783278
declaration: VariableLikeDeclarationStatement = parent.program.makeNativeVariableDeclaration(name),
32793279
/** Offset of this variable within closure context, if it's value is held there */
3280-
public closureContextOffset: usize = -1,
3280+
public closureContextOffset: usize = 0,
32813281
) {
32823282
super(
32833283
ElementKind.LOCAL,

tests/compiler/closure.optimized.wat

+12-12
Original file line numberDiff line numberDiff line change
@@ -1203,13 +1203,13 @@
12031203
i32.store
12041204
local.get $0
12051205
i32.const 11
1206-
i32.store offset=1
1206+
i32.store offset=4
12071207
local.get $0
12081208
i32.const 4
1209-
i32.store offset=1
1209+
i32.store offset=8
12101210
local.get $0
12111211
i32.const 7
1212-
i32.store offset=1
1212+
i32.store offset=12
12131213
local.get $0
12141214
i32.const 4
12151215
i32.shr_s
@@ -1242,10 +1242,10 @@
12421242
i32.store
12431243
local.get $0
12441244
i32.const 1
1245-
i32.store offset=1
1245+
i32.store offset=4
12461246
local.get $0
12471247
i32.const 7
1248-
i32.store offset=1
1248+
i32.store offset=8
12491249
local.get $0
12501250
local.get $1
12511251
local.get $0
@@ -1284,7 +1284,7 @@
12841284
i32.store
12851285
local.get $0
12861286
i32.const 1
1287-
i32.store offset=1
1287+
i32.store offset=4
12881288
local.get $0
12891289
i32.const 4
12901290
i32.shr_s
@@ -1337,7 +1337,7 @@
13371337
i32.store
13381338
local.get $0
13391339
i32.const 2
1340-
i32.store offset=1
1340+
i32.store offset=4
13411341
local.get $0
13421342
i32.const 4
13431343
i32.shr_s
@@ -1379,7 +1379,7 @@
13791379
i32.store
13801380
local.get $0
13811381
i32.const 0
1382-
i32.store offset=1
1382+
i32.store offset=4
13831383
local.get $0
13841384
i32.const 4
13851385
i32.shr_s
@@ -1421,7 +1421,7 @@
14211421
i32.store
14221422
local.get $0
14231423
i32.const 0
1424-
i32.store offset=1
1424+
i32.store offset=4
14251425
local.get $0
14261426
i32.const 4
14271427
i32.shr_s
@@ -1518,13 +1518,13 @@
15181518
i32.store
15191519
local.get $0
15201520
i32.const 1
1521-
i32.store offset=1
1521+
i32.store offset=4
15221522
local.get $0
15231523
i32.const 1
1524-
i32.store offset=1
1524+
i32.store offset=8
15251525
local.get $0
15261526
i32.const 1
1527-
i32.store offset=1
1527+
i32.store offset=12
15281528
local.get $0
15291529
i32.const 4
15301530
i32.shr_s

tests/compiler/closure.untouched.wat

+12-12
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@
15611561
local.set $3
15621562
local.get $3
15631563
local.get $1
1564-
i32.store offset=1
1564+
i32.store offset=4
15651565
local.get $3
15661566
i32.const 4
15671567
i32.shr_s
@@ -1612,7 +1612,7 @@
16121612
local.set $2
16131613
local.get $2
16141614
local.get $0
1615-
i32.store offset=1
1615+
i32.store offset=4
16161616
local.get $2
16171617
i32.const 4
16181618
i32.shr_s
@@ -1663,7 +1663,7 @@
16631663
local.set $2
16641664
local.get $2
16651665
local.get $0
1666-
i32.store offset=1
1666+
i32.store offset=4
16671667
local.get $2
16681668
i32.const 4
16691669
i32.shr_s
@@ -1755,13 +1755,13 @@
17551755
local.set $8
17561756
local.get $8
17571757
local.get $2
1758-
i32.store offset=1
1758+
i32.store offset=4
17591759
local.get $8
17601760
local.get $3
1761-
i32.store offset=1
1761+
i32.store offset=8
17621762
local.get $8
17631763
local.get $1
1764-
i32.store offset=1
1764+
i32.store offset=12
17651765
local.get $8
17661766
i32.const 4
17671767
i32.shr_s
@@ -1887,10 +1887,10 @@
18871887
local.set $4
18881888
local.get $4
18891889
local.get $0
1890-
i32.store offset=1
1890+
i32.store offset=4
18911891
local.get $4
18921892
local.get $1
1893-
i32.store offset=1
1893+
i32.store offset=8
18941894
local.get $4
18951895
local.get $2
18961896
i32.const 1
@@ -1944,7 +1944,7 @@
19441944
local.set $3
19451945
local.get $3
19461946
local.get $0
1947-
i32.store offset=1
1947+
i32.store offset=4
19481948
local.get $3
19491949
i32.const 4
19501950
i32.shr_s
@@ -2091,13 +2091,13 @@
20912091
local.set $4
20922092
local.get $4
20932093
local.get $0
2094-
i32.store offset=1
2094+
i32.store offset=4
20952095
local.get $4
20962096
local.get $1
2097-
i32.store offset=1
2097+
i32.store offset=8
20982098
local.get $4
20992099
local.get $2
2100-
i32.store offset=1
2100+
i32.store offset=12
21012101
local.get $4
21022102
i32.const 4
21032103
i32.shr_s

0 commit comments

Comments
 (0)