-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Try to find cyclic data dependencies during const-checking #71526
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a75c792
Make type alias private
ecstatic-morse 274c85f
Don't cache result of `in_any_value_of_ty` for locals
ecstatic-morse 1343797
Lazily run dataflow for const qualification
ecstatic-morse 15f95b1
Cycle errors now occur during const-eval, not checking
ecstatic-morse 918dcf2
Find potential const-eval cycles during const-checking
ecstatic-morse 3608535
Cycle errors are caught during const-checking again
ecstatic-morse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -406,14 +406,31 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { | |
); | ||
} | ||
|
||
fn visit_operand(&mut self, op: &Operand<'tcx>, location: Location) { | ||
self.super_operand(op, location); | ||
if let Operand::Constant(c) = op { | ||
if let Some(def_id) = c.check_static_ptr(self.tcx) { | ||
self.check_static(def_id, self.span); | ||
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) { | ||
self.super_constant(constant, location); | ||
|
||
if let ty::ConstKind::Unevaluated(def_id, _, promoted) = constant.literal.val { | ||
assert!(promoted.is_none(), "Const-checking should run before promotion"); | ||
|
||
// If a cyclic data dependency exists within a const initializer, try to find | ||
// it during const-checking. This is important because MIR optimizations could | ||
// eliminate a cycle before const-eval runs. See #71078 for an example of this. | ||
// | ||
// FIXME: This means we don't look for cycles involving associated constants, but we | ||
// should handle fully monomorphized ones here at least. | ||
if self.tcx.trait_of_item(def_id).is_none() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can invoke |
||
let _ = self.tcx.at(self.span).mir_const_qualif(def_id); | ||
} | ||
} | ||
|
||
if let Some(def_id) = constant.check_static_ptr(self.tcx) { | ||
self.check_static(def_id, self.span); | ||
|
||
// NOTE: Because we are allowed to refer to the address of a static within its | ||
// initializer, we don't try to trigger cycle errors every time we see a static. | ||
} | ||
} | ||
|
||
fn visit_projection_elem( | ||
&mut self, | ||
place_local: Local, | ||
|
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.
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.
#71078 isn't actually an example of this, as Ralf notes.
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.
Huh? It isn't? Or are you talking about a comment by Ralf from elsewhere but this PR?