-
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
fix Miri visiting generators #60541
Merged
Merged
fix Miri visiting generators #60541
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -147,7 +147,7 @@ macro_rules! make_value_visitor { | |
{ | ||
Ok(()) | ||
} | ||
/// Visits this vale as an aggregate, you are even getting an iterator yielding | ||
/// Visits this value as an aggregate, you are getting an iterator yielding | ||
/// all the fields (still in an `EvalResult`, you have to do error handling yourself). | ||
/// Recurses into the fields. | ||
#[inline(always)] | ||
|
@@ -160,7 +160,8 @@ macro_rules! make_value_visitor { | |
} | ||
|
||
/// Called each time we recurse down to a field of a "product-like" aggregate | ||
/// (structs, tuples, arrays and the like, but not enums), passing in old and new value. | ||
/// (structs, tuples, arrays and the like, but not enums), passing in old (outer) | ||
/// and new (inner) value. | ||
/// This gives the visitor the chance to track the stack of nested fields that | ||
/// we are descending through. | ||
#[inline(always)] | ||
|
@@ -173,18 +174,6 @@ macro_rules! make_value_visitor { | |
self.visit_value(new_val) | ||
} | ||
|
||
/// Called for recursing into the field of a generator. These are not known to be | ||
/// initialized, so we treat them like unions. | ||
#[inline(always)] | ||
fn visit_generator_field( | ||
&mut self, | ||
_old_val: Self::V, | ||
_field: usize, | ||
new_val: Self::V, | ||
) -> EvalResult<'tcx> { | ||
self.visit_union(new_val) | ||
} | ||
|
||
/// Called when recursing into an enum variant. | ||
#[inline(always)] | ||
fn visit_variant( | ||
|
@@ -238,7 +227,7 @@ macro_rules! make_value_visitor { | |
fn walk_value(&mut self, v: Self::V) -> EvalResult<'tcx> | ||
{ | ||
trace!("walk_value: type: {}", v.layout().ty); | ||
// If this is a multi-variant layout, we have find the right one and proceed with | ||
// If this is a multi-variant layout, we have to find the right one and proceed with | ||
// that. | ||
match v.layout().variants { | ||
layout::Variants::Multiple { .. } => { | ||
|
@@ -263,6 +252,13 @@ macro_rules! make_value_visitor { | |
// recurse with the inner type | ||
return self.visit_field(v, 0, Value::from_mem_place(inner)); | ||
}, | ||
ty::Generator(..) => { | ||
// FIXME: Generator layout is lying: it claims a whole bunch of fields exist | ||
// when really many of them can be uninitialized. | ||
// Just treat them as a union for now, until hopefully the layout | ||
// computation is fixed. | ||
return self.visit_union(v); | ||
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. cc @tmandry |
||
} | ||
_ => {}, | ||
}; | ||
|
||
|
@@ -304,34 +300,18 @@ macro_rules! make_value_visitor { | |
// Empty unions are not accepted by rustc. That's great, it means we can | ||
// use that as an unambiguous signal for detecting primitives. Make sure | ||
// we did not miss any primitive. | ||
debug_assert!(fields > 0); | ||
assert!(fields > 0); | ||
self.visit_union(v) | ||
}, | ||
layout::FieldPlacement::Arbitrary { ref offsets, .. } => { | ||
// Special handling needed for generators: All but the first field | ||
// (which is the state) are actually implicitly `MaybeUninit`, i.e., | ||
// they may or may not be initialized, so we cannot visit them. | ||
match v.layout().ty.sty { | ||
ty::Generator(..) => { | ||
let field = v.project_field(self.ecx(), 0)?; | ||
self.visit_aggregate(v, std::iter::once(Ok(field)))?; | ||
for i in 1..offsets.len() { | ||
let field = v.project_field(self.ecx(), i as u64)?; | ||
self.visit_generator_field(v, i, field)?; | ||
} | ||
Ok(()) | ||
} | ||
_ => { | ||
// FIXME: We collect in a vec because otherwise there are lifetime | ||
// errors: Projecting to a field needs access to `ecx`. | ||
let fields: Vec<EvalResult<'tcx, Self::V>> = | ||
(0..offsets.len()).map(|i| { | ||
v.project_field(self.ecx(), i as u64) | ||
}) | ||
.collect(); | ||
self.visit_aggregate(v, fields.into_iter()) | ||
} | ||
} | ||
// FIXME: We collect in a vec because otherwise there are lifetime | ||
// errors: Projecting to a field needs access to `ecx`. | ||
let fields: Vec<EvalResult<'tcx, Self::V>> = | ||
(0..offsets.len()).map(|i| { | ||
v.project_field(self.ecx(), i as u64) | ||
}) | ||
.collect(); | ||
self.visit_aggregate(v, fields.into_iter()) | ||
}, | ||
layout::FieldPlacement::Array { .. } => { | ||
// Let's get an mplace first. | ||
|
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.
sp:
GeneratorState
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.
oopsie fixed in #60569