Skip to content
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

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

kamalesh0406
Copy link
Contributor

@kamalesh0406 kamalesh0406 commented Jan 14, 2024

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 of NonZeroUsize. The change were tested by running ./x test compiler/rustc_middle.

Resolves #119217

r? @WaffleLapkin

@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2024

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 14, 2024
Copy link
Member

@WaffleLapkin WaffleLapkin left a 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 {
Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&*(ptr_without_tag as *const ty::RegionKind<'tcx>),
ptr.cast::<ty::RegionKind<'tcx>>().as_ref(),

and similarly for others

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 14, 2024
@WaffleLapkin
Copy link
Member

I've marked this as S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. , once this is ready for review, please use @rustbot review (learn more about rustbot commands).

@kamalesh0406
Copy link
Contributor Author

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 14, 2024
@kamalesh0406 kamalesh0406 changed the title Modify GenericArg to use NonNull ptr Modify GenericArg and Term structs to use strict provenance rules Jan 15, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2024

Could not assign reviewer from: WaffleLapkin.
User(s) WaffleLapkin are either the PR author, already assigned, or on vacation, and there are no other candidates.
Use r? to specify someone else to assign.

@rust-log-analyzer

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)) },
Copy link
Member

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

Suggested change
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()),
Copy link
Member

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

Suggested change
&*(ptr.cast::<ty::RegionKind<'tcx>>().as_ref()),
ptr.cast::<ty::RegionKind<'tcx>>().as_ref()

}
};

Term { ptr: unsafe { NonZeroUsize::new_unchecked(ptr | tag) }, marker: PhantomData }
Term {
ptr: unsafe { ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() | tag)) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ptr: unsafe { ptr.map_addr(|addr| NonZeroUsize::new_unchecked(addr.get() | tag)) },
ptr: ptr.map_addr(|addr| addr | tag),

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 15, 2024
@kamalesh0406
Copy link
Contributor Author

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 15, 2024
@WaffleLapkin
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 17, 2024

📌 Commit cd90143 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 17, 2024
@kamalesh0406
Copy link
Contributor Author

@rustbot review

@bors
Copy link
Contributor

bors commented Jan 18, 2024

📌 Commit dcc13b2 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 18, 2024
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 18, 2024
@WaffleLapkin WaffleLapkin removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 18, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 18, 2024
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`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 18, 2024
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``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 18, 2024
…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
@matthiaskrgr
Copy link
Member

@bors r- #120088 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 18, 2024
@WaffleLapkin
Copy link
Member

WaffleLapkin commented Jan 18, 2024

@kamalesh0406 please use full paths for DynSend/DynSync, instead of imports to prevent the unused imports failure.

@kamalesh0406
Copy link
Contributor Author

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 19, 2024
@WaffleLapkin
Copy link
Member

Let's try again
@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Jan 24, 2024

📌 Commit d0dea83 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 24, 2024
@bors
Copy link
Contributor

bors commented Jan 25, 2024

⌛ Testing commit d0dea83 with merge d93fecc...

@bors
Copy link
Contributor

bors commented Jan 25, 2024

☀️ Test successful - checks-actions
Approved by: WaffleLapkin
Pushing d93fecc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 25, 2024
@bors bors merged commit d93fecc into rust-lang:master Jan 25, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 25, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d93fecc): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
5.5% [5.5%, 5.5%] 1
Regressions ❌
(secondary)
3.0% [3.0%, 3.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.6% [-4.6%, -4.6%] 1
All ❌✅ (primary) 5.5% [5.5%, 5.5%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 661.843s -> 662.638s (0.12%)
Artifact size: 308.29 MiB -> 308.19 MiB (-0.03%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[strict provenance] make compiler's Term and GenericArg conform
8 participants