Open HertzDevil opened 1 year ago
I'm wondering if there's any benefit from having limit
nilable vs. using a high value (Int32::MAX
?) as default.
Right inside the body of #caller
, sure, but no stdlib API does that at the method signature
Well there could just be two separate signatures with no explicit default value: caller()
and caller(Int)
.
I just tried this and for non-release builds the top of the stack will invariably contain the same stack frames leading all the way to the unwinding method itself, so #caller(Int)
may not be as intuitive as it seems. (Recall that unwinding the stack doesn't need debug information, but detecting Exception::CallStack.skip
ped frames does.)
Sometimes, only the top few entries of the stack trace are needed, for example in https://forum.crystal-lang.org/t/memory-profiling/4888 where we do not print the entries at the bottom. When the stack is very deep, most of the time in
caller.first(n)
would be spent on retrieving the entries at the bottom, but surely we could simply stop unwinding the call stack after the firstn
entries. So IMO#caller
should take an optional limit argument:Note that
caller(n)
may be shorter thencaller.first(n)
if some stack entries are omitted due toException::CallStack.skip
. To actually stop the unwinding:The
interpreter_call_stack_unwind
primitive will also need to understand this limit parameter.