Skip to content

Commit 2259c79

Browse files
aviateskKristofferC
authored andcommitted
use inferencebarrier instead of invokelatest for 1-arg @assert (#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)
1 parent c86965b commit 2259c79

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

base/error.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,16 @@ macro assert(ex, msgs...)
223223
msg = msg # pass-through
224224
elseif !isempty(msgs) && (isa(msg, Expr) || isa(msg, Symbol))
225225
# message is an expression needing evaluating
226-
msg = :(Main.Base.invokelatest(Main.Base.string, $(esc(msg))))
226+
# N.B. To reduce the risk of invalidation caused by the complex callstack involved
227+
# with `string`, use `inferencebarrier` here to hide this `string` from the compiler.
228+
msg = :(Main.Base.inferencebarrier(Main.Base.string)($(esc(msg))))
227229
elseif isdefined(Main, :Base) && isdefined(Main.Base, :string) && applicable(Main.Base.string, msg)
228230
msg = Main.Base.string(msg)
229231
else
230232
# string() might not be defined during bootstrap
231233
msg = quote
232234
msg = $(Expr(:quote,msg))
233-
isdefined(Main, :Base) ? Main.Base.invokelatest(Main.Base.string, msg) :
235+
isdefined(Main, :Base) ? Main.Base.inferencebarrier(Main.Base.string, msg) :
234236
(Core.println(msg); "Error during bootstrap. See stdout.")
235237
end
236238
end

0 commit comments

Comments
 (0)