Skip to content

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

Merged
merged 1 commit into from
May 16, 2021

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Apr 25, 2021

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.

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.
@rust-highfive
Copy link
Contributor

r? @varkor

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 25, 2021
@tmiasko
Copy link
Contributor Author

tmiasko commented Apr 25, 2021

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

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 25, 2021
@bors
Copy link
Collaborator

bors commented Apr 25, 2021

⌛ Trying commit eaddc8f with merge 7c6cf24dbb417e698304066497ff26a10b194fdd...

@bors
Copy link
Collaborator

bors commented Apr 25, 2021

☀️ Try build successful - checks-actions
Build commit: 7c6cf24dbb417e698304066497ff26a10b194fdd (7c6cf24dbb417e698304066497ff26a10b194fdd)

@rust-timer
Copy link
Collaborator

Queued 7c6cf24dbb417e698304066497ff26a10b194fdd with parent 06f0adb, future comparison URL.

@rust-timer
Copy link
Collaborator

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 rollup- to bors.

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
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 25, 2021
@varkor
Copy link
Member

varkor commented May 1, 2021

@tmiasko: do you have any idea about how to adjust this to avoid the performance hit?

@varkor varkor added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 1, 2021
@tmiasko
Copy link
Contributor Author

tmiasko commented May 5, 2021

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 5, 2021
@varkor
Copy link
Member

varkor commented May 16, 2021

@bors r+

@bors
Copy link
Collaborator

bors commented May 16, 2021

📌 Commit eaddc8f has been approved by varkor

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 16, 2021
@bors
Copy link
Collaborator

bors commented May 16, 2021

⌛ Testing commit eaddc8f with merge f8e1e92...

@bors
Copy link
Collaborator

bors commented May 16, 2021

☀️ Test successful - checks-actions
Approved by: varkor
Pushing f8e1e92 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 16, 2021
@bors bors merged commit f8e1e92 into rust-lang:master May 16, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 16, 2021
@tmiasko tmiasko deleted the static-initializer branch May 16, 2021 17:59
@jonas-schievink jonas-schievink added the beta-nominated Nominated for backporting to the compiler in the beta channel. label May 30, 2021
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 30, 2021
@apiraino
Copy link
Contributor

apiraino commented Jun 4, 2021

beta backport decision on hold (see Zulip discussion) (possibly we will decline the backport and let this patch land on next stable)

@apiraino
Copy link
Contributor

Beta backport declined as per compiler team on Zulip, patch will land on next stable. Seems in the end this behaviour (at least under certain conditions) has always been broken.

@rustbot label -beta-nominated

@rustbot rustbot removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no MIR available for DefId
8 participants