Skip to content

Commit

Permalink
Add Exception::CallStack.empty (#15017)
Browse files Browse the repository at this point in the history
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)).
  • Loading branch information
straight-shoota authored Sep 21, 2024
1 parent c74f6bc commit b679b56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/compiler/crystal/semantic/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class Crystal::Call
property? uses_with_scope = false

class RetryLookupWithLiterals < ::Exception
@@dummy_call_stack = Exception::CallStack.new

def initialize
self.callstack = @@dummy_call_stack
self.callstack = Exception::CallStack.empty
end
end

Expand Down
7 changes: 5 additions & 2 deletions src/exception/call_stack.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ struct Exception::CallStack
@callstack : Array(Void*)
@backtrace : Array(String)?

def initialize
@callstack = CallStack.unwind
def initialize(@callstack : Array(Void*) = CallStack.unwind)
end

def self.empty
new([] of Void*)
end

def printable_backtrace : Array(String)
Expand Down

0 comments on commit b679b56

Please sign in to comment.