Skip to content

Commit 88ff0fd

Browse files
cjhopmanmeta-codesync[bot]
authored andcommitted
Add callstack_nth_location
Summary: I wanted this for some testing and it seems fine to generally add it, even though i have no immediate plans to use it. Reviewed By: JakobDegen Differential Revision: D84766605 fbshipit-source-id: 98e341ad0099ec1e5c9134a842f29d0e098e0656
1 parent fb67890 commit 88ff0fd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

starlark/src/eval/runtime/cheap_call_stack.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ impl<'v> CheapCallStack<'v> {
196196
}
197197
}
198198

199+
pub(crate) fn nth_location(&self, n: usize) -> Option<FileSpan> {
200+
if n >= self.count {
201+
None
202+
} else {
203+
self.stack[self.count - 1 - n].location()
204+
}
205+
}
206+
199207
/// `n`-th element from the top of the stack.
200208
pub(crate) fn top_nth_function(&self, n: usize) -> anyhow::Result<Value<'v>> {
201209
self.top_nth_function_opt(n)

starlark/src/eval/runtime/evaluator.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ impl<'v, 'a, 'e: 'a> Evaluator<'v, 'a, 'e> {
452452
self.call_stack.top_location()
453453
}
454454

455+
/// Obtain the nth location on the call-stack. May be [`None`] if the
456+
/// stack is not that deep. n=0 is the top of the stack.
457+
pub fn call_stack_nth_location(&self, n: usize) -> Option<FileSpan> {
458+
self.call_stack.nth_location(n)
459+
}
460+
455461
pub(crate) fn before_stmt_fn(
456462
&mut self,
457463
f: &'a dyn for<'v1, 'a2> Fn(FileSpanRef, bool, &mut Evaluator<'v1, 'a2, 'e>),

0 commit comments

Comments
 (0)