-
Notifications
You must be signed in to change notification settings - Fork 13k
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
enum variant support #89745
Closed
Closed
enum variant support #89745
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 |
---|---|---|
|
@@ -217,12 +217,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | |
match layout.variants { | ||
Variants::Multiple { tag_field, .. } => { | ||
if tag_field == field { | ||
return match layout.ty.kind() { | ||
return match layout.ty.strip_variant_type().kind() { | ||
ty::Adt(def, ..) if def.is_enum() => PathElem::EnumTag, | ||
ty::Variant(ty, ..) => match ty.kind() { | ||
ty::Adt(def, ..) if def.is_enum() => PathElem::EnumTag, | ||
_ => bug!("non-variant type {:?}", layout.ty), | ||
}, | ||
ty::Generator(..) => PathElem::GeneratorTag, | ||
_ => bug!("non-variant type {:?}", layout.ty), | ||
}; | ||
|
@@ -232,7 +228,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | |
} | ||
|
||
// Now we know we are projecting to a field, so figure out which one. | ||
match layout.ty.kind() { | ||
match layout.ty.strip_variant_type().kind() { | ||
// generators and closures. | ||
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => { | ||
let mut name = None; | ||
|
@@ -276,20 +272,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | |
} | ||
} | ||
|
||
ty::Variant(ty, ..) => match ty.kind() { | ||
ty::Adt(def, ..) if def.is_enum() => { | ||
// we might be projecting *to* a variant, or to a field *in* a variant. | ||
match layout.variants { | ||
Variants::Single { index } => { | ||
// Inside a variant | ||
PathElem::Field(def.variants[index].fields[field].ident.name) | ||
} | ||
Variants::Multiple { .. } => bug!("we handled variants above"), | ||
} | ||
} | ||
_ => bug!("unexpected type: {:?}", ty.kind()), | ||
}, | ||
|
||
// other ADTs | ||
ty::Adt(def, _) => PathElem::Field(def.non_enum_variant().fields[field].ident.name), | ||
|
||
|
@@ -513,7 +495,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | |
) -> InterpResult<'tcx, bool> { | ||
// Go over all the primitive types | ||
let ty = value.layout.ty; | ||
match ty.kind() { | ||
match ty.strip_variant_type().kind() { | ||
ty::Bool => { | ||
let value = self.read_scalar(value)?; | ||
try_validation!( | ||
|
@@ -585,17 +567,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | |
self.check_safe_pointer(value, "box")?; | ||
Ok(true) | ||
} | ||
ty::Variant(ty, _) => match ty.kind() { | ||
ty::Adt(def, _) => { | ||
if def.is_box() { | ||
self.check_safe_pointer(value, "box")?; | ||
Ok(true) | ||
} else { | ||
Ok(false) | ||
} | ||
} | ||
_ => bug!("unexpected type: {:?}", ty.kind()), | ||
}, | ||
ty::FnPtr(_sig) => { | ||
let value = try_validation!( | ||
self.ecx.read_immediate(value), | ||
|
@@ -641,6 +612,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | |
| ty::Opaque(..) | ||
| ty::Projection(..) | ||
| ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty), | ||
|
||
ty::Variant(..) => unreachable!(), | ||
} | ||
} | ||
|
||
|
@@ -756,15 +729,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> | |
variant_id: VariantIdx, | ||
new_op: &OpTy<'tcx, M::PointerTag>, | ||
) -> InterpResult<'tcx> { | ||
let name = match old_op.layout.ty.kind() { | ||
let ty = old_op.layout.ty.strip_variant_type(); | ||
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. Variant types don't have variants, so something seems wrong if we see a variant type here. |
||
let name = match ty.kind() { | ||
ty::Adt(adt, _) => PathElem::Variant(adt.variants[variant_id].ident.name), | ||
ty::Variant(ty, ..) => match ty.kind() { | ||
ty::Adt(adt, ..) => PathElem::Variant(adt.variants[variant_id].ident.name), | ||
_ => bug!("unexpected type {:?}", ty.kind()), | ||
}, | ||
// Generators also have variants | ||
ty::Generator(..) => PathElem::GeneratorState(variant_id), | ||
_ => bug!("Unexpected type with variant: {:?}", old_op.layout.ty), | ||
_ => bug!("Unexpected type with variant: {:?}", ty), | ||
}; | ||
self.with_elem(name, move |this| this.visit_value(new_op)) | ||
} | ||
|
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
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
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
Oops, something went wrong.
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.
Variant types should never have
Variants::Multiple
layout so this should be unreachable.Generally I am not very happy with
strip_variant_type
, from a conceptual perspective this rarely seems like the right thing to do -- but maybe my intuition is leading me astray here.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.
strip_variant_type is the correct thing wherever we don't actually handle variant things on generators or adts right now, so here it is indeed wrong, we should not ever encounter adt/generator anymore, but for that
Layout::for_variant
needs to be fixed to return ty::Variant.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.
layout
is the outer layout of the enum here, why should we not encounter adt/generators here?It's the other
match
below in the same function where we should not encounter them any more.