Skip to content

Commit dc797a4

Browse files
authored
fix: Push to the inline stack after compiling arguments (#2527)
1 parent 08a6b96 commit dc797a4

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

Diff for: NOTICE

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ under the licensing terms detailed in LICENSE:
5252
* Ruixiang Chen <[email protected]>
5353
* Daniel Salvadori <[email protected]>
5454
* Jairus Tanaka <[email protected]>
55+
* CountBleck <[email protected]>
5556

5657
Portions of this software are derived from third-party works licensed under
5758
the following terms:

Diff for: src/compiler.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6447,15 +6447,16 @@ export class Compiler extends DiagnosticEmitter {
64476447
reportNode.range, instance.internalName
64486448
);
64496449
} else {
6450-
inlineStack.push(instance);
64516450
let parameterTypes = signature.parameterTypes;
64526451
assert(numArguments <= parameterTypes.length);
6453-
// compile argument expressions
6452+
// compile argument expressions *before* pushing to the inline stack
6453+
// otherwise, the arguments may not be inlined, e.g. `abc(abc(123))`
64546454
let args = new Array<ExpressionRef>(numArguments);
64556455
for (let i = 0; i < numArguments; ++i) {
64566456
args[i] = this.compileExpression(argumentExpressions[i], parameterTypes[i], Constraints.CONV_IMPLICIT);
64576457
}
64586458
// make the inlined call
6459+
inlineStack.push(instance);
64596460
let expr = this.makeCallInline(instance, args, thisArg, (constraints & Constraints.WILL_DROP) != 0);
64606461
inlineStack.pop();
64616462
return expr;

Diff for: tests/compiler/inlining.debug.wat

+14-6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@
153153
i32.const 1
154154
i32.eq
155155
drop
156+
i32.const 1
157+
local.set $var$2
158+
local.get $var$2
159+
local.set $var$2
160+
local.get $var$2
161+
i32.const 1
162+
i32.eq
163+
drop
156164
i32.const 2
157165
local.set $var$2
158166
local.get $var$2
@@ -203,7 +211,7 @@
203211
if
204212
i32.const 0
205213
i32.const 32
206-
i32.const 68
214+
i32.const 69
207215
i32.const 3
208216
call $~lib/builtins/abort
209217
unreachable
@@ -235,7 +243,7 @@
235243
if
236244
i32.const 0
237245
i32.const 32
238-
i32.const 71
246+
i32.const 72
239247
i32.const 3
240248
call $~lib/builtins/abort
241249
unreachable
@@ -2416,7 +2424,7 @@
24162424
if
24172425
i32.const 0
24182426
i32.const 32
2419-
i32.const 95
2427+
i32.const 96
24202428
i32.const 3
24212429
call $~lib/builtins/abort
24222430
unreachable
@@ -2429,7 +2437,7 @@
24292437
if
24302438
i32.const 0
24312439
i32.const 32
2432-
i32.const 96
2440+
i32.const 97
24332441
i32.const 3
24342442
call $~lib/builtins/abort
24352443
unreachable
@@ -2442,7 +2450,7 @@
24422450
if
24432451
i32.const 0
24442452
i32.const 32
2445-
i32.const 97
2453+
i32.const 98
24462454
i32.const 3
24472455
call $~lib/builtins/abort
24482456
unreachable
@@ -2455,7 +2463,7 @@
24552463
if
24562464
i32.const 0
24572465
i32.const 32
2458-
i32.const 98
2466+
i32.const 99
24592467
i32.const 3
24602468
call $~lib/builtins/abort
24612469
unreachable

Diff for: tests/compiler/inlining.release.wat

+4-4
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@
15501550
if
15511551
i32.const 0
15521552
i32.const 1056
1553-
i32.const 95
1553+
i32.const 96
15541554
i32.const 3
15551555
call $~lib/builtins/abort
15561556
unreachable
@@ -1562,7 +1562,7 @@
15621562
if
15631563
i32.const 0
15641564
i32.const 1056
1565-
i32.const 96
1565+
i32.const 97
15661566
i32.const 3
15671567
call $~lib/builtins/abort
15681568
unreachable
@@ -1574,7 +1574,7 @@
15741574
if
15751575
i32.const 0
15761576
i32.const 1056
1577-
i32.const 97
1577+
i32.const 98
15781578
i32.const 3
15791579
call $~lib/builtins/abort
15801580
unreachable
@@ -1586,7 +1586,7 @@
15861586
if
15871587
i32.const 0
15881588
i32.const 1056
1589-
i32.const 98
1589+
i32.const 99
15901590
i32.const 3
15911591
call $~lib/builtins/abort
15921592
unreachable

Diff for: tests/compiler/inlining.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function test_funcs(): void {
6262
assert(func_ii(43) == 3);
6363
assert(func_ii_opt() == 0);
6464
assert(func_ii_opt(1) == 1);
65+
assert(func_ii_opt(func_ii_opt(1)) == 1);
6566
assert(func_ii_loc(2) == 3);
6667
assert(func_ii_loc(3) == 4);
6768
func_iv(0);

0 commit comments

Comments
 (0)