-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add invokelatest
barrier to string(...)
in @assert
#55739
Add invokelatest
barrier to string(...)
in @assert
#55739
Conversation
Great! This fixes the Master with JuliaPackaging/LazyArtifacts.jl#1
Full detail:
This PR with JuliaPackaging/LazyArtifacts.jl#1
More info & improvement at #55740 |
This change protects `@assert` from invalidations to `Base.string(...)` which are fairly easy to trigger. Perhaps the worst offender right now is `using StyledStrings` which invalidates `string(::Expr)`, which unfortunately leads to invalidation of almost `@assert`s (without an explicit message)
08d381a
to
ad3abc2
Compare
I think this is a great idea. The 1-arg |
This change protects `@assert` from invalidations to `Base.string(...)` by adding an `invokelatest` barrier. A common source of invalidations right now is `print(io, join(args...))`. The problem is: 1. Inference concludes that `join(::Any...)` returns `Union{String,AnnotatedString}` 2. The `print` call is union-split to `String` and `AnnotatedString` 3. This code is now invalidated when StyledStrings defines `print(io, ::AnnotatedString)` The invalidation chain for `@assert` is similar: ` @Assert 1 == 1` calls into `string(::Expr)` which calls into `print(io, join(args::Any...))`. Unfortunately that leads to the invalidation of almost all `@assert`s without an explicit error message Similar to #55583 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we want to do invokelatest here, as it could do some very weird things if Core.Compiler runs into an asserts if the resulting string code then does anything unexpected. Should we try to separate that so that Core.Compiler uses a slightly different asserts macro?
We could also use invokeinworld with tls_world_age, or an inferencebarrier to achieve similar effects? |
This version would be better as per this comment: <#55739 (review)> I confirmed this still allows us to avoid invalidations reported at #55583.
This version would be better as per this comment: <#55739 (review)> I confirmed this still allows us to avoid invalidations reported at #55583.
This version would be better as per this comment: <#55739 (review)> I confirmed this still allows us to avoid invalidations reported at #55583.
…55783) This version would be better as per this comment: <#55739 (review)> I confirmed this still allows us to avoid invalidations reported at #55583.
This change protects `@assert` from invalidations to `Base.string(...)` by adding an `invokelatest` barrier. A common source of invalidations right now is `print(io, join(args...))`. The problem is: 1. Inference concludes that `join(::Any...)` returns `Union{String,AnnotatedString}` 2. The `print` call is union-split to `String` and `AnnotatedString` 3. This code is now invalidated when StyledStrings defines `print(io, ::AnnotatedString)` The invalidation chain for `@assert` is similar: ` @Assert 1 == 1` calls into `string(::Expr)` which calls into `print(io, join(args::Any...))`. Unfortunately that leads to the invalidation of almost all `@assert`s without an explicit error message Similar to #55583 (comment) (cherry picked from commit 945517b)
…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)
…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)
Backported PRs: - [x] #55773 <!-- Add compat entry for `Base.donotdelete` --> - [x] #41244 <!-- Fix shell `cd` error when working dir has been deleted --> - [x] #55795 <!-- fix #52986, regression in `@doc` of macro without REPL loaded --> - [x] #55829 <!-- [Dates] Make test more robust against non-UTC timezones --> - [x] #55641 <!-- fall back to slower stat filesize if optimized filesize fails --> - [x] #55744 <!-- fix #45494, error in ssa conversion with complex type decl --> - [x] #55783 <!-- use `inferencebarrier` instead of `invokelatest` for 1-arg `@assert` --> - [x] #55739 <!-- Add `invokelatest` barrier to `string(...)` in `@assert` --> Need manual backport: - [ ] #55798 <!-- Broadcast binary ops involving strided triangular --> Contains multiple commits, manual intervention needed: - [ ] #55509 <!-- Fix cong implementation to be properly random and not just cycling. --> - [ ] #55569 <!-- Add a docs section about loading/precomp/ttfx time tuning --> - [ ] #55824 <!-- Replace regex package module checks with actual code checks --> Non-merged PRs with backport label: - [ ] #55845 <!-- privatize annotated string API, take two --> - [ ] #55828 <!-- Fix some corner cases of `isapprox` with unsigned integers --> - [ ] #55813 <!-- Check for conflicting `@ccallable` name before JIT registration --> - [ ] #55743 <!-- doc: heap snapshot viewing --> - [ ] #55741 <!-- Change annotations to use a NamedTuple --> - [ ] #55534 <!-- Set stdlib sources as read-only during installation --> - [ ] #55499 <!-- propagate the terminal's `displaysize` to the `IOContext` used by the REPL --> - [ ] #55458 <!-- Allow for generically extracting unannotated string --> - [ ] #55457 <!-- Make AnnotateChar equality consider annotations --> - [ ] #55453 <!-- Privatise the annotations API, for StyledStrings --> - [ ] #55355 <!-- relocation: account for trailing path separator in depot paths --> - [ ] #55220 <!-- `isfile_casesensitive` fixes on Windows --> - [ ] #55169 <!-- `propertynames` for SVD respects private argument --> - [ ] #54457 <!-- Make `String(::Memory)` copy --> - [ ] #53957 <!-- tweak how filtering is done for what packages should be precompiled --> - [ ] #51479 <!-- prevent code loading from lookin in the versioned environment when building Julia --> - [ ] #50813 <!-- More doctests for Sockets and capitalization fix --> - [ ] #50157 <!-- improve docs for `@inbounds` and `Base.@propagate_inbounds` -->
This change protects
@assert
from invalidations toBase.string(...)
by adding aninvokelatest
barrier.A common source of invalidations right now is
print(io, join(args...))
. The problem is:join(::Any...)
returnsUnion{String,AnnotatedString}
print
call is union-split toString
andAnnotatedString
print(io, ::AnnotatedString)
The invalidation chain for
@assert
is similar:@assert 1 == 1
calls intostring(::Expr)
which calls intoprint(io, join(args::Any...))
. Unfortunately that leads to the invalidation of almost all@assert
s without an explicit error messageSimilar to #55583 (comment)