Skip to content

Commit 4d38789

Browse files
committed
Do not run StackCompressor and StackLimitEvader on EOF.
1 parent 44c0697 commit 4d38789

30 files changed

+90
-16
lines changed

libyul/optimiser/StackCompressor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,14 @@ std::tuple<bool, Block> StackCompressor::run(
249249
);
250250
bool usesOptimizedCodeGenerator = false;
251251
bool simulateFunctionsWithJumps = true;
252-
size_t reachableStackDepth = 16;
253252
if (auto evmDialect = dynamic_cast<EVMDialect const*>(_object.dialect()))
254253
{
254+
yulAssert(!evmDialect->eofVersion().has_value(), "StackCompressor does not support EOF.");
255255
usesOptimizedCodeGenerator =
256256
_optimizeStackAllocation &&
257257
evmDialect->evmVersion().canOverchargeGasForCall() &&
258258
evmDialect->providesObjectAccess();
259259
simulateFunctionsWithJumps = !evmDialect->eofVersion().has_value();
260-
reachableStackDepth = evmDialect->reachableStackDepth();
261260
}
262261
bool allowMSizeOptimization = !MSizeFinder::containsMSize(*_object.dialect(), _object.code()->root());
263262
Block astRoot = std::get<Block>(ASTCopier{}(_object.code()->root()));
@@ -272,7 +271,7 @@ std::tuple<bool, Block> StackCompressor::run(
272271
eliminateVariablesOptimizedCodegen(
273272
*_object.dialect(),
274273
astRoot,
275-
StackLayoutGenerator::reportStackTooDeep(*cfg, simulateFunctionsWithJumps, reachableStackDepth),
274+
StackLayoutGenerator::reportStackTooDeep(*cfg, simulateFunctionsWithJumps, 16u),
276275
allowMSizeOptimization
277276
);
278277
}

libyul/optimiser/StackLimitEvader.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ Block StackLimitEvader::run(
132132
evmDialect && evmDialect->providesObjectAccess(),
133133
"StackLimitEvader can only be run on objects using the EVMDialect with object access."
134134
);
135+
yulAssert(
136+
!evmDialect->eofVersion().has_value(),
137+
"StackLimitEvader does not support EOF."
138+
);
135139
auto astRoot = std::get<Block>(ASTCopier{}(_object.code()->root()));
136140
if (evmDialect && evmDialect->evmVersion().canOverchargeGasForCall())
137141
{
@@ -159,6 +163,15 @@ void StackLimitEvader::run(
159163
std::map<YulName, std::vector<StackLayoutGenerator::StackTooDeep>> const& _stackTooDeepErrors
160164
)
161165
{
166+
auto const* evmDialect = dynamic_cast<EVMDialect const*>(&_context.dialect);
167+
yulAssert(
168+
evmDialect && evmDialect->providesObjectAccess(),
169+
"StackLimitEvader can only be run on objects using the EVMDialect with object access."
170+
);
171+
yulAssert(
172+
!evmDialect->eofVersion().has_value(),
173+
"StackLimitEvader does not support EOF."
174+
);
162175
std::map<YulName, std::vector<YulName>> unreachableVariables;
163176
for (auto&& [function, stackTooDeepErrors]: _stackTooDeepErrors)
164177
{
@@ -183,6 +196,10 @@ void StackLimitEvader::run(
183196
evmDialect && evmDialect->providesObjectAccess(),
184197
"StackLimitEvader can only be run on objects using the EVMDialect with object access."
185198
);
199+
yulAssert(
200+
!evmDialect->eofVersion().has_value(),
201+
"StackLimitEvader does not support EOF."
202+
);
186203

187204
std::vector<FunctionCall*> memoryGuardCalls = findFunctionCalls(_astRoot, "memoryguard", *evmDialect);
188205
// Do not optimise, if no ``memoryguard`` call is found.

libyul/optimiser/Suite.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,29 @@ void OptimiserSuite::run(
163163
}
164164
if (usesOptimizedCodeGenerator)
165165
{
166+
if (!evmDialect->eofVersion().has_value())
166167
{
167-
PROFILER_PROBE("StackCompressor", probe);
168-
_object.setCode(std::make_shared<AST>(dialect, std::move(astRoot)));
169-
astRoot = std::get<1>(StackCompressor::run(
170-
_object,
171-
_optimizeStackAllocation,
172-
stackCompressorMaxIterations
173-
));
174-
}
175-
if (evmDialect->providesObjectAccess())
176-
{
177-
PROFILER_PROBE("StackLimitEvader", probe);
178-
_object.setCode(std::make_shared<AST>(dialect, std::move(astRoot)));
179-
astRoot = StackLimitEvader::run(suite.m_context, _object);
168+
{
169+
PROFILER_PROBE("StackCompressor", probe);
170+
_object.setCode(std::make_shared<AST>(dialect, std::move(astRoot)));
171+
astRoot = std::get<1>(StackCompressor::run(
172+
_object,
173+
_optimizeStackAllocation,
174+
stackCompressorMaxIterations
175+
));
176+
}
177+
if (evmDialect->providesObjectAccess())
178+
{
179+
PROFILER_PROBE("StackLimitEvader", probe);
180+
_object.setCode(std::make_shared<AST>(dialect, std::move(astRoot)));
181+
astRoot = StackLimitEvader::run(suite.m_context, _object);
182+
}
180183
}
181184
}
182185
else if (evmDialect->providesObjectAccess() && _optimizeStackAllocation)
183186
{
184187
PROFILER_PROBE("StackLimitEvader", probe);
188+
yulAssert(!evmDialect->eofVersion().has_value(), "");
185189
_object.setCode(std::make_shared<AST>(dialect, std::move(astRoot)));
186190
astRoot = StackLimitEvader::run(suite.m_context, _object);
187191
}

test/libyul/yulOptimizerTests/fakeStackLimitEvader/connected.yul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
sstore(0, f())
2121
let x, y := g()
2222
}
23+
// ====
24+
// bytecodeFormat: legacy
2325
// ----
2426
// step: fakeStackLimitEvader
2527
//

test/libyul/yulOptimizerTests/fakeStackLimitEvader/function_arg.yul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
}
88
sstore(1, h(32))
99
}
10+
// ====
11+
// bytecodeFormat: legacy
1012
// ----
1113
// step: fakeStackLimitEvader
1214
//

test/libyul/yulOptimizerTests/fakeStackLimitEvader/multi_variable_declaration_without_value.yul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
let z, $w
88
}
99
}
10+
// ====
11+
// bytecodeFormat: legacy
1012
// ----
1113
// step: fakeStackLimitEvader
1214
//

test/libyul/yulOptimizerTests/fakeStackLimitEvader/outer_block.yul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
let $x := 42
44
sstore(42, $x)
55
}
6+
// ====
7+
// bytecodeFormat: legacy
68
// ----
79
// step: fakeStackLimitEvader
810
//

test/libyul/yulOptimizerTests/fakeStackLimitEvader/return_leave.yul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
}
1515

1616
}
17+
// ====
18+
// bytecodeFormat: legacy
1719
// ----
1820
// step: fakeStackLimitEvader
1921
//

test/libyul/yulOptimizerTests/fakeStackLimitEvader/return_one.yul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
}
1313

1414
}
15+
// ====
16+
// bytecodeFormat: legacy
1517
// ----
1618
// step: fakeStackLimitEvader
1719
//

test/libyul/yulOptimizerTests/fakeStackLimitEvader/return_one_with_args.yul

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
}
1313

1414
}
15+
// ====
16+
// bytecodeFormat: legacy
1517
// ----
1618
// step: fakeStackLimitEvader
1719
//

0 commit comments

Comments
 (0)