Skip to content

Commit

Permalink
use inferencebarrier instead of invokelatest for 1-arg @assert (#…
Browse files Browse the repository at this point in the history
…55783)

This version would be better as per this comment:
<#55739 (review)>
I confirmed this still allows us to avoid invalidations reported at
#55583.

(cherry picked from commit f808606)
  • Loading branch information
aviatesk committed Sep 24, 2024
1 parent c86965b commit 9e82e60
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,16 @@ macro assert(ex, msgs...)
msg = msg # pass-through
elseif !isempty(msgs) && (isa(msg, Expr) || isa(msg, Symbol))
# message is an expression needing evaluating
msg = :(Main.Base.invokelatest(Main.Base.string, $(esc(msg))))
# N.B. To reduce the risk of invalidation caused by the complex callstack involved
# with `string`, use `inferencebarrier` here to hide this `string` from the compiler.
msg = :(Main.Base.inferencebarrier(Main.Base.string)($(esc(msg))))
elseif isdefined(Main, :Base) && isdefined(Main.Base, :string) && applicable(Main.Base.string, msg)
msg = Main.Base.string(msg)
else
# string() might not be defined during bootstrap
msg = quote
msg = $(Expr(:quote,msg))
isdefined(Main, :Base) ? Main.Base.invokelatest(Main.Base.string, msg) :
isdefined(Main, :Base) ? Main.Base.inferencebarrier(Main.Base.string)(msg) :
(Core.println(msg); "Error during bootstrap. See stdout.")
end
end
Expand Down

0 comments on commit 9e82e60

Please sign in to comment.