Skip to content

Commit 5216f90

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Different error for call stack overflow
Summary: Before this diff "Too many recursion levels" error was used for both: * call stack overflow * equality/comparison evaluation stack overflow Change call stack overflow error to "Starlark call stack overflow" to make error easier to investigate. Reviewed By: bobyangyf Differential Revision: D38705604 fbshipit-source-id: d9cde9799ba1f51eb9c41011d62f18e5a083acb3
1 parent f3a936a commit 5216f90

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

starlark/src/eval/runtime/call_stack.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use crate::codemap::FileSpan;
3737
use crate::codemap::Span;
3838
use crate::errors::Frame;
3939
use crate::eval::runtime::inlined_frame::InlinedFrames;
40-
use crate::values::error::ControlError;
4140
use crate::values::FrozenRef;
4241
use crate::values::Trace;
4342
use crate::values::Tracer;
@@ -157,6 +156,8 @@ impl Debug for CheapFrame<'_> {
157156
enum CallStackError {
158157
#[error("Requested {0}-th top frame, but stack size is {1} (internal error)")]
159158
StackIsTooShallowForNthTopFrame(usize, usize),
159+
#[error("Starlark call stack overflow")]
160+
Overflow,
160161
}
161162

162163
/// Starlark call stack.
@@ -209,7 +210,7 @@ impl<'v> CheapCallStack<'v> {
209210
span: Option<FrozenRef<'static, FrozenFileSpan>>,
210211
) -> anyhow::Result<()> {
211212
if unlikely(self.count >= MAX_CALLSTACK_RECURSION) {
212-
return Err(ControlError::TooManyRecursionLevel.into());
213+
return Err(CallStackError::Overflow.into());
213214
}
214215
self.stack[self.count] = CheapFrame { function, span };
215216
self.count += 1;

starlark/src/tests/call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def rec6(): rec2()
6262
assert::is_true(&f("(f5(1, b=2) == {'b': 2})"));
6363
assert::is_true(&f("(f6(1, 2, 3) == (1, 2, 3))"));
6464
// Recursion limit
65-
assert::fail(&f("rec1()"), "recursion");
66-
assert::fail(&f("rec2()"), "recursion");
65+
assert::fail(&f("rec1()"), "Starlark call stack overflow");
66+
assert::fail(&f("rec2()"), "Starlark call stack overflow");
6767
// multiple argument with the same name should not be allowed
6868
assert::fail("def f(a, a=2): pass", "duplicated parameter");
6969
// Invalid order of parameter

0 commit comments

Comments
 (0)