Skip to content

Commit b10d59d

Browse files
authored
Remove the TRAVERSE_CALLS option in the ConstantExpressionRunner (#6449)
The implementation of calls with this option was incorrect because it cleared the locals before evaluating the call arguments. The likely explanation for why this was never noticed is that there are no users of this option, especially since it is exposed in the C and JS APIs but not used internally. Rather than try to fix the implementation, just remove the option.
1 parent 88eabaa commit b10d59d

File tree

7 files changed

+2
-79
lines changed

7 files changed

+2
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Current Trunk
2222
to configure which features to enable in the parser.
2323
- The build-time option to use legacy WasmGC opcodes is removed.
2424
- The strings in `string.const` instructions must now be valid WTF-8.
25+
- The `TraverseCalls` flag for `ExpressionRunner` is removed.
2526

2627
v117
2728
----

src/binaryen-c.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6322,10 +6322,6 @@ ExpressionRunnerFlags ExpressionRunnerFlagsPreserveSideeffects() {
63226322
return CExpressionRunner::FlagValues::PRESERVE_SIDEEFFECTS;
63236323
}
63246324

6325-
ExpressionRunnerFlags ExpressionRunnerFlagsTraverseCalls() {
6326-
return CExpressionRunner::FlagValues::TRAVERSE_CALLS;
6327-
}
6328-
63296325
ExpressionRunnerRef ExpressionRunnerCreate(BinaryenModuleRef module,
63306326
ExpressionRunnerFlags flags,
63316327
BinaryenIndex maxDepth,

src/binaryen-c.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,12 +3495,6 @@ BINARYEN_API ExpressionRunnerFlags ExpressionRunnerFlagsDefault();
34953495
// so subsequent code keeps functioning.
34963496
BINARYEN_API ExpressionRunnerFlags ExpressionRunnerFlagsPreserveSideeffects();
34973497

3498-
// Traverse through function calls, attempting to compute their concrete value.
3499-
// Must not be used in function-parallel scenarios, where the called function
3500-
// might be concurrently modified, leading to undefined behavior. Traversing
3501-
// another function reuses all of this runner's flags.
3502-
BINARYEN_API ExpressionRunnerFlags ExpressionRunnerFlagsTraverseCalls();
3503-
35043498
// Creates an ExpressionRunner instance
35053499
BINARYEN_API ExpressionRunnerRef
35063500
ExpressionRunnerCreate(BinaryenModuleRef module,

src/js/binaryen.js-post.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ function initializeConstants() {
638638
Module['ExpressionRunner']['Flags'] = {
639639
'Default': Module['_ExpressionRunnerFlagsDefault'](),
640640
'PreserveSideeffects': Module['_ExpressionRunnerFlagsPreserveSideeffects'](),
641-
'TraverseCalls': Module['_ExpressionRunnerFlagsTraverseCalls']()
642641
};
643642
}
644643

src/wasm-interpreter.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,10 +2211,6 @@ class ConstantExpressionRunner : public ExpressionRunner<SubType> {
22112211
// the expression if it also sets a local, which must be preserved in this
22122212
// scenario so subsequent code keeps functioning.
22132213
PRESERVE_SIDEEFFECTS = 1 << 0,
2214-
// Traverse through function calls, attempting to compute their concrete
2215-
// value. Must not be used in function-parallel scenarios, where the called
2216-
// function might be concurrently modified, leading to undefined behavior.
2217-
TRAVERSE_CALLS = 1 << 1
22182214
};
22192215

22202216
// Flags indicating special requirements, for example whether we are just
@@ -2322,35 +2318,6 @@ class ConstantExpressionRunner : public ExpressionRunner<SubType> {
23222318
Flow visitCall(Call* curr) {
23232319
NOTE_ENTER("Call");
23242320
NOTE_NAME(curr->target);
2325-
// Traverse into functions using the same mode, which we can also do
2326-
// when replacing as long as the function does not have any side effects.
2327-
// Might yield something useful for simple functions like `clamp`, sometimes
2328-
// even if arguments are only partially constant or not constant at all.
2329-
if ((flags & FlagValues::TRAVERSE_CALLS) != 0 && this->module != nullptr) {
2330-
auto* func = this->module->getFunction(curr->target);
2331-
if (!func->imported()) {
2332-
if (func->getResults().isConcrete()) {
2333-
auto numOperands = curr->operands.size();
2334-
assert(numOperands == func->getNumParams());
2335-
auto prevLocalValues = localValues;
2336-
localValues.clear();
2337-
for (Index i = 0; i < numOperands; ++i) {
2338-
auto argFlow = ExpressionRunner<SubType>::visit(curr->operands[i]);
2339-
if (!argFlow.breaking()) {
2340-
assert(argFlow.values.isConcrete());
2341-
localValues[i] = argFlow.values;
2342-
}
2343-
}
2344-
auto retFlow = ExpressionRunner<SubType>::visit(func->body);
2345-
localValues = prevLocalValues;
2346-
if (retFlow.breakTo == RETURN_FLOW) {
2347-
return Flow(retFlow.values);
2348-
} else if (!retFlow.breaking()) {
2349-
return retFlow;
2350-
}
2351-
}
2352-
}
2353-
}
23542321
return Flow(NONCONSTANT_FLOW);
23552322
}
23562323
Flow visitCallIndirect(CallIndirect* curr) {

test/binaryen.js/expressionrunner.js

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var Flags = binaryen.ExpressionRunner.Flags;
22
console.log("// ExpressionRunner.Flags.Default = " + Flags.Default);
33
console.log("// ExpressionRunner.Flags.PreserveSideeffects = " + Flags.PreserveSideeffects);
4-
console.log("// ExpressionRunner.Flags.TraverseCalls = " + Flags.TraverseCalls);
54

65
function assertDeepEqual(x, y) {
76
if (typeof x === "object") {
@@ -139,39 +138,7 @@ assertDeepEqual(
139138
}
140139
);
141140

142-
// Should traverse into (simple) functions if requested
143-
runner = new binaryen.ExpressionRunner(module, Flags.TraverseCalls);
144-
module.addFunction("add", binaryen.createType([ binaryen.i32, binaryen.i32 ]), binaryen.i32, [],
145-
module.block(null, [
146-
module.i32.add(
147-
module.local.get(0, binaryen.i32),
148-
module.local.get(1, binaryen.i32)
149-
)
150-
], binaryen.i32)
151-
);
152-
assert(runner.setLocalValue(0, module.i32.const(1)));
153-
expr = runner.runAndDispose(
154-
module.i32.add(
155-
module.i32.add(
156-
module.local.get(0, binaryen.i32),
157-
module.call("add", [
158-
module.i32.const(2),
159-
module.i32.const(4)
160-
], binaryen.i32)
161-
),
162-
module.local.get(0, binaryen.i32)
163-
)
164-
);
165-
assertDeepEqual(
166-
binaryen.getExpressionInfo(expr),
167-
{
168-
id: binaryen.ExpressionIds.Const,
169-
type: binaryen.i32,
170-
value: 8
171-
}
172-
);
173-
174-
// Should not attempt to traverse into functions if not explicitly set
141+
// Should not attempt to traverse into functions
175142
runner = new binaryen.ExpressionRunner(module);
176143
expr = runner.runAndDispose(
177144
module.i32.add(
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
// ExpressionRunner.Flags.Default = 0
22
// ExpressionRunner.Flags.PreserveSideeffects = 1
3-
// ExpressionRunner.Flags.TraverseCalls = 2

0 commit comments

Comments
 (0)