Skip to content

Add Exception::CallStack.empty#15017

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota:refactor/exception_callstack.empty
Sep 21, 2024
Merged

Add Exception::CallStack.empty#15017
straight-shoota merged 1 commit intocrystal-lang:masterfrom
straight-shoota:refactor/exception_callstack.empty

Conversation

@straight-shoota
Copy link
Member

This is a follow-up on #15002 which explicitly assigns a dummy callstack to RetryLookupWithLiterals for performance reasons.
CallStack.empty is intended to make this use case a bit more ergonomical. It doesn't require allocating a dummy instance with fake data. Instead, it's an explicitly empty callstack. This makes this mechanism easier to re-use in other places (ref #11658 (comment)).

@straight-shoota straight-shoota added this to the 1.14.0 milestone Sep 20, 2024
@straight-shoota straight-shoota merged commit b679b56 into crystal-lang:master Sep 21, 2024
@straight-shoota straight-shoota deleted the refactor/exception_callstack.empty branch September 21, 2024 11:01
@oprypin
Copy link
Member

oprypin commented Sep 21, 2024

Worth noting that this changes the behavior. Previously the same instance was used but now a new one is created every time.

@straight-shoota
Copy link
Member Author

straight-shoota commented Sep 21, 2024

Exception::CallStack is a struct, so same instance should not have much significance. Or am I missing something...? 🤔
It's a new Array allocation, though.

@beta-ziliani
Copy link
Member

yeah it seems the empty array could be cached (and ask users of .empty to not modify it)

@straight-shoota
Copy link
Member Author

straight-shoota commented Sep 23, 2024

CallStack#@callstack is never modified. It's not even directly accessible from the public API.

I think it should better be a Slice. But unfortunately, changing this a bit tricky because it involves the compiler primitive interpreter_call_stack_unwind. Should still be doable, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants