-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Reachable statics have reachable initializers #84549
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
Conversation
Static initializer can read other statics. Initializers are evaluated at compile time, and so their content could become inlined into another crate. Ensure that initializers of reachable statics are also reachable. Previously, when an item incorrectly considered to be unreachable was reached from another crate an attempt would be made to codegen it. The attempt could fail with an ICE (in the case MIR wasn't available to do so) in some circumstances the attempt could also succeed resulting in a local codegen of non-local items, including static ones.
r? @varkor (rust-highfive has picked a reviewer for you, use r? to override) |
In 1.50 and earlier releases the bug could result in static items being codegened multiple times (it seems error prone that mono item collector does that). Since 1.51, I think, the worst outcome is an ICE. The only related bug report I found is #84455. Marking initializer as reachable is far from ideal, since it is an overestimate of what is reachable, but it is most straightforward implementation strategy. @bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit eaddc8f with merge 7c6cf24dbb417e698304066497ff26a10b194fdd... |
☀️ Try build successful - checks-actions |
Queued 7c6cf24dbb417e698304066497ff26a10b194fdd with parent 06f0adb, future comparison URL. |
Finished benchmarking try commit (7c6cf24dbb417e698304066497ff26a10b194fdd): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
@tmiasko: do you have any idea about how to adjust this to avoid the performance hit? |
In the context of existing reachability pass, I don't see how I could make more fine-grained distinction between things that are reachable at runtime and const-eval time. This is somewhat of a pre-existing problem, since we often codegen functions that are only used by const eval. @rustbot label: +S-waiting-on-review -S-waiting-on-author |
@bors r+ |
📌 Commit eaddc8f has been approved by |
☀️ Test successful - checks-actions |
beta backport decision on hold (see Zulip discussion) (possibly we will decline the backport and let this patch land on next stable) |
Static initializer can read other statics. Initializers are evaluated at
compile time, and so their content could become inlined into another
crate. Ensure that initializers of reachable statics are also reachable.
Previously, when an item incorrectly considered to be unreachable was
reached from another crate an attempt would be made to codegen it. The
attempt could fail with an ICE (in the case MIR wasn't available to do
so) in some circumstances the attempt could also succeed resulting in
a local codegen of non-local items, including static ones.
Fixes #84455.