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

Make use of [wrapping_]byte_{add,sub} #100819

Merged
merged 1 commit into from
Aug 29, 2022

Conversation

WaffleLapkin
Copy link
Member

These new methods trivially replace old .cast().wrapping_offset().cast() & similar code.
Note that arith_offset and wrapping_offset are the same thing.

r? @scottmcm

split off from #100746

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 20, 2022
@rustbot
Copy link
Collaborator

rustbot commented Aug 20, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 20, 2022
@@ -64,7 +64,7 @@ macro_rules! iterator {
// backwards by `n`. `n` must not exceed `self.len()`.
macro_rules! zst_shrink {
($self: ident, $n: ident) => {
$self.end = ($self.end as * $raw_mut u8).wrapping_offset(-$n) as * $raw_mut T;
$self.end = $self.end.wrapping_byte_offset(-$n);
Copy link
Member

Choose a reason for hiding this comment

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

This change is fine, but I definitely look at it and wonder if it can be

Suggested change
$self.end = $self.end.wrapping_byte_offset(-$n);
$self.end = $self.end.wrapping_byte_sub($n);

since it's explicitly shrink.

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't done this originally because ($n): isize, but I've just checked and it seems that this is only called with literals and smt as isize so this change makes sense.

@scottmcm
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 22, 2022

📌 Commit b2326ae96398eb936351a7364dc9526730f4814a has been approved by scottmcm

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 Aug 22, 2022
@bors
Copy link
Contributor

bors commented Aug 22, 2022

☔ The latest upstream changes (presumably #100881) made this pull request unmergeable. Please resolve the merge conflicts.

@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 Aug 22, 2022
...replacing `.cast().wrapping_offset().cast()` & similar code.
@WaffleLapkin
Copy link
Member Author

rebased to make merge conflicts go away

@scottmcm
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 23, 2022

📌 Commit 53565b2 has been approved by scottmcm

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 Aug 23, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 23, 2022
… r=scottmcm

Make use of `[wrapping_]byte_{add,sub}`

These new methods trivially replace old `.cast().wrapping_offset().cast()` & similar code.
Note that [`arith_offset`](https://doc.rust-lang.org/std/intrinsics/fn.arith_offset.html) and `wrapping_offset` are the same thing.

r? `@scottmcm`

_split off from #100746_
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 24, 2022
… r=scottmcm

Make use of `[wrapping_]byte_{add,sub}`

These new methods trivially replace old `.cast().wrapping_offset().cast()` & similar code.
Note that [`arith_offset`](https://doc.rust-lang.org/std/intrinsics/fn.arith_offset.html) and `wrapping_offset` are the same thing.

r? ``@scottmcm``

_split off from #100746_
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 24, 2022
… r=scottmcm

Make use of `[wrapping_]byte_{add,sub}`

These new methods trivially replace old `.cast().wrapping_offset().cast()` & similar code.
Note that [`arith_offset`](https://doc.rust-lang.org/std/intrinsics/fn.arith_offset.html) and `wrapping_offset` are the same thing.

r? ```@scottmcm```

_split off from #100746_
@matthiaskrgr
Copy link
Member

@bors rollup=iffy #100947 (comment)
(this is just a shot into the dark, feel free to roll it back)

@WaffleLapkin
Copy link
Member Author

Can this PR be un-rollup=iffy-ed? Same as #100811 (comment), I don't think it could cause the hang, given that it basically changes nothing.

@matthiaskrgr
Copy link
Member

@bors rollup=maybe

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 29, 2022
… r=scottmcm

Make use of `[wrapping_]byte_{add,sub}`

These new methods trivially replace old `.cast().wrapping_offset().cast()` & similar code.
Note that [`arith_offset`](https://doc.rust-lang.org/std/intrinsics/fn.arith_offset.html) and `wrapping_offset` are the same thing.

r? `@scottmcm`

_split off from #100746_
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 29, 2022
Rollup of 8 pull requests

Successful merges:

 - rust-lang#98304 (Add MaybeUninit memset test)
 - rust-lang#98801 (Add a `File::create_new` constructor)
 - rust-lang#99821 (Remove separate indexing of early-bound regions)
 - rust-lang#100239 (remove an ineffective check in const_prop)
 - rust-lang#100337 (Stabilize `std::io::read_to_string`)
 - rust-lang#100819 (Make use of `[wrapping_]byte_{add,sub}`)
 - rust-lang#100934 (Remove a panicking branch from `fmt::builders::PadAdapter`)
 - rust-lang#101000 (Separate CountIsStar from CountIsParam in rustc_parse_format.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 395ce34 into rust-lang:master Aug 29, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 29, 2022
Comment on lines -270 to +269
self.end = unsafe { arith_offset(self.end as *const i8, -1) as *mut T };
self.end = self.ptr.wrapping_byte_sub(1);
Copy link
Member

Choose a reason for hiding this comment

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

Is this right? It's using self.ptr instead of self.end

Copy link
Member

Choose a reason for hiding this comment

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

Indeed this is wrong; should be fixed by #101237.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm sorry 🥲

@RalfJung
Copy link
Member

I think there's a bug in this PR -- see #101235.

@RalfJung RalfJung mentioned this pull request Aug 31, 2022
RalfJung added a commit to RalfJung/rust that referenced this pull request Aug 31, 2022
fix into_iter on ZST

Fixes rust-lang#101235
Thanks to `@ChrisDenton` for [spotting the problem](rust-lang#100819 (review)).
@WaffleLapkin WaffleLapkin deleted the use_ptr_byte_methods branch September 1, 2022 10:36
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 6, 2022
…leftovers, r=scottmcm

Some more cleanup in `core`

- remove some integer casts from slice iter (proposed in rust-lang#100819 (comment))
- replace `as usize` casts with `usize::from` in slice sort (proposed in rust-lang#100822 (comment))

r? `@scottmcm`
workingjubilee pushed a commit to tcdi/postgrestd that referenced this pull request Sep 15, 2022
fix into_iter on ZST

Fixes rust-lang/rust#101235
Thanks to `@ChrisDenton` for [spotting the problem](rust-lang/rust#100819 (review)).
workingjubilee pushed a commit to tcdi/postgrestd that referenced this pull request Sep 15, 2022
…, r=scottmcm

Some more cleanup in `core`

- remove some integer casts from slice iter (proposed in rust-lang/rust#100819 (comment))
- replace `as usize` casts with `usize::from` in slice sort (proposed in rust-lang/rust#100822 (comment))

r? `@scottmcm`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants