-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Modify GenericArg and Term structs to use strict provenance rules #119955
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @WaffleLapkin (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
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.
This generally looks good, but I have a few nitpicks :)
@@ -123,20 +142,22 @@ impl<'tcx> From<ty::Term<'tcx>> for GenericArg<'tcx> { | |||
impl<'tcx> GenericArg<'tcx> { | |||
#[inline] | |||
pub fn unpack(self) -> GenericArgKind<'tcx> { | |||
let ptr = self.ptr.get(); | |||
let ptr_without_tag = unsafe { |
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.
I think the name ptr
is fine, no need to specify "without tag"
@@ -123,20 +142,22 @@ impl<'tcx> From<ty::Term<'tcx>> for GenericArg<'tcx> { | |||
impl<'tcx> GenericArg<'tcx> { | |||
#[inline] | |||
pub fn unpack(self) -> GenericArgKind<'tcx> { | |||
let ptr = self.ptr.get(); | |||
let ptr_without_tag = unsafe { | |||
self.ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() & !TAG_MASK)).as_ptr() |
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.
self.ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() & !TAG_MASK)).as_ptr() | |
self.ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() & !TAG_MASK)) |
no need to leave NonNull
(see below)
REGION_TAG => GenericArgKind::Lifetime(ty::Region(Interned::new_unchecked( | ||
&*((ptr & !TAG_MASK) as *const ty::RegionKind<'tcx>), | ||
&*(ptr_without_tag as *const ty::RegionKind<'tcx>), |
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.
&*(ptr_without_tag as *const ty::RegionKind<'tcx>), | |
ptr.cast::<ty::RegionKind<'tcx>>().as_ref(), |
and similarly for others
I've marked this as
S-waiting-on-author
|
@rustbot review |
Could not assign reviewer from: |
This comment has been minimized.
This comment has been minimized.
} | ||
}; | ||
|
||
GenericArg { ptr: unsafe { NonZeroUsize::new_unchecked(ptr | tag) }, marker: PhantomData } | ||
GenericArg { | ||
ptr: unsafe { ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() | tag)) }, |
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.
There is a BitOr<usize>
impl for NonZeroUsize
, so you can just
ptr: unsafe { ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() | tag)) }, | |
ptr: ptr.map_addr(|addr| addr | tag), |
REGION_TAG => GenericArgKind::Lifetime(ty::Region(Interned::new_unchecked( | ||
&*((ptr & !TAG_MASK) as *const ty::RegionKind<'tcx>), | ||
&*(ptr.cast::<ty::RegionKind<'tcx>>().as_ref()), |
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.
I don't think residing here and later is needed
&*(ptr.cast::<ty::RegionKind<'tcx>>().as_ref()), | |
ptr.cast::<ty::RegionKind<'tcx>>().as_ref() |
compiler/rustc_middle/src/ty/mod.rs
Outdated
} | ||
}; | ||
|
||
Term { ptr: unsafe { NonZeroUsize::new_unchecked(ptr | tag) }, marker: PhantomData } | ||
Term { | ||
ptr: unsafe { ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() | tag)) }, |
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.
ptr: unsafe { ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() | tag)) }, | |
ptr: ptr.map_addr(|addr| addr | tag), |
@rustbot review |
@bors r+ rollup |
@rustbot review |
Modify GenericArg and Term structs to use strict provenance rules This is the first PR to solve issue rust-lang#119217 . In this PR, I have modified the GenericArg struct to use the `NonNull` struct as the pointer instead of `NonZeroUsize`. The change were tested by running `./x test compiler/rustc_middle`. Resolves rust-lang#119217 r? `@WaffleLapkin`
Modify GenericArg and Term structs to use strict provenance rules This is the first PR to solve issue rust-lang#119217 . In this PR, I have modified the GenericArg struct to use the `NonNull` struct as the pointer instead of `NonZeroUsize`. The change were tested by running `./x test compiler/rustc_middle`. Resolves rust-lang#119217 r? ``@WaffleLapkin``
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#119172 (Detect `NulInCStr` error earlier.) - rust-lang#119833 (Make tcx optional from StableMIR run macro and extend it to accept closures) - rust-lang#119955 (Modify GenericArg and Term structs to use strict provenance rules) - rust-lang#120021 (don't store const var origins for known vars) - rust-lang#120038 (Don't create a separate "basename" when naming and opening a MIR dump file) - rust-lang#120057 (Don't ICE when deducing future output if other errors already occurred) - rust-lang#120073 (Remove spastorino from users_on_vacation) r? `@ghost` `@rustbot` modify labels: rollup
@kamalesh0406 please use full paths for |
@rustbot review |
Let's try again |
☀️ Test successful - checks-actions |
Finished benchmarking commit (d93fecc): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 661.843s -> 662.638s (0.12%) |
This is the first PR to solve issue #119217 . In this PR, I have modified the GenericArg struct to use the
NonNull
struct as the pointer instead ofNonZeroUsize
. The change were tested by running./x test compiler/rustc_middle
.Resolves #119217
r? @WaffleLapkin