Skip to content

Commit 2b4ef4b

Browse files
committed
use inferencebarrier instead of invokelatest for 1-arg @assert
This version would be better as per this comment: <#55739 (review)> I confirmed this still allows us to avoid invalidations reported at #55583.
1 parent a993cd8 commit 2b4ef4b

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
@@ -232,12 +232,14 @@ macro assert(ex, msgs...)
232232
msg = msg # pass-through
233233
elseif !isempty(msgs) && (isa(msg, Expr) || isa(msg, Symbol))
234234
# message is an expression needing evaluating
235-
msg = :(Main.Base.invokelatest(Main.Base.string, $(esc(msg))))
235+
# N.B. To reduce the risk of invalidation caused by the complex callstack involved
236+
# with `string`, use `inferencebarrier` here to hide this `string` from the compiler.
237+
msg = :(Main.Base.inferencebarrier(Main.Base.string)($(esc(msg))))
236238
elseif isdefined(Main, :Base) && isdefined(Main.Base, :string) && applicable(Main.Base.string, msg)
237239
msg = Main.Base.string(msg)
238240
else
239241
# string() might not be defined during bootstrap
240-
msg = :(Main.Base.invokelatest(_assert_tostring, $(Expr(:quote,msg))))
242+
msg = :(Main.Base.inferencebarrier(_assert_tostring)($(Expr(:quote,msg))))
241243
end
242244
return :($(esc(ex)) ? $(nothing) : throw(AssertionError($msg)))
243245
end

0 commit comments

Comments
 (0)