-
Notifications
You must be signed in to change notification settings - Fork 13.4k
pointee_info_at: fix logic for recursing into enums #132745
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1011,25 +1011,41 @@ where | |
} | ||
|
||
_ => { | ||
let mut data_variant = match this.variants { | ||
let mut data_variant = match &this.variants { | ||
// Within the discriminant field, only the niche itself is | ||
// always initialized, so we only check for a pointer at its | ||
// offset. | ||
// | ||
// If the niche is a pointer, it's either valid (according | ||
// to its type), or null (which the niche field's scalar | ||
// validity range encodes). This allows using | ||
// `dereferenceable_or_null` for e.g., `Option<&T>`, and | ||
// this will continue to work as long as we don't start | ||
// using more niches than just null (e.g., the first page of | ||
// the address space, or unaligned pointers). | ||
// Our goal here is to check whether this represents a | ||
// "dereferenceable or null" pointer, so we need to ensure | ||
// that there is only one other variant, and it must be null. | ||
// Below, we will then check whether the pointer is indeed | ||
// dereferenceable. | ||
Variants::Multiple { | ||
tag_encoding: TagEncoding::Niche { untagged_variant, .. }, | ||
tag_encoding: | ||
TagEncoding::Niche { untagged_variant, niche_variants, niche_start }, | ||
tag_field, | ||
variants, | ||
.. | ||
} if this.fields.offset(tag_field) == offset => { | ||
Some(this.for_variant(cx, untagged_variant)) | ||
} if variants.len() == 2 && this.fields.offset(*tag_field) == offset => { | ||
let tagged_variant = if untagged_variant.as_u32() == 0 { | ||
VariantIdx::from_u32(1) | ||
} else { | ||
VariantIdx::from_u32(0) | ||
}; | ||
assert_eq!(tagged_variant, *niche_variants.start()); | ||
if *niche_start == 0 { | ||
// The other variant is encoded as "null", so we can recurse searching for | ||
// a pointer here. This relies on the fact that the codegen backend | ||
// only adds "dereferenceable" if there's also a "nonnull" proof, | ||
// and that null is aligned for all alignments so it's okay to forward | ||
// the pointer's alignment. | ||
Some(this.for_variant(cx, *untagged_variant)) | ||
} else { | ||
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. IIUC, this align will always be 1. I adjusted align at #131739, and I think it's sound. 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. How about adding a 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. No,
Notice the I don't see why adding a "dereferenceable" field would help. The entire 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. Perhaps my comment was a bit misplaced. See https://github.com/rust-lang/rust/pull/131739/files#diff-a93329b2efc9dabaf147bfdb806fb52501ed7889eb08e26e1a2714bb43862531R22-R39. In this case, we need to drop 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. I don't think that's worth the effort. We shouldn't implement complicated logic like that unless it actually has real-world benefit. In particular, I think it is actually impossible for stable code to even potentially benefit from this. |
||
} | ||
} | ||
Variants::Multiple { .. } => None, | ||
_ => Some(this), | ||
}; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.