promotion: don't promote extern statics#157641
Open
sjwang05 wants to merge 1 commit into
Open
Conversation
Collaborator
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
Collaborator
|
r? @oli-obk rustbot has assigned @oli-obk. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
6257168 to
80ac224
Compare
This comment has been minimized.
This comment has been minimized.
80ac224 to
8877f4c
Compare
oli-obk
reviewed
Jun 9, 2026
Comment on lines
+363
to
+371
| if let Some((place_base, ProjectionElem::Deref)) = | ||
| place.as_ref().last_projection() | ||
| && let Some(local) = place_base.as_local() | ||
| && let TempState::Defined { location: loc, .. } = self.temps[local] | ||
| && let Left(stmt) = self.body.stmt_at(loc) | ||
| && let Some((_, Rvalue::Use(Operand::Constant(c), _))) = | ||
| stmt.kind.as_assign() | ||
| && let Some(did) = c.check_static_ptr(self.tcx) | ||
| && self.tcx.is_foreign_item(did) |
Contributor
There was a problem hiding this comment.
having to take this apart during promotion is kind of annoying. I wonder if we have enough information during MIR building to just reject creating reads from foreign statics in const contexts entirely.
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Even though we're allowed to reference extern statics, it's impossible to know the value of an extern static during CTFE when it's used by-value, so we shouldn't try promoting them.
fixes #143174