Repository navigation
Replace Unique in Box with a (NonNull, PhantomData) wrapper - #162849
Conversation
This comment has been minimized.
This comment has been minimized.
fa0d259 to
4824152
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
4824152 to
cab6a85
Compare
This comment has been minimized.
This comment has been minimized.
cab6a85 to
b647fd5
Compare
|
cc @rust-lang/miri Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@hanna-kruppe do you want to take this one too? r? hanna-kruppe Reroll libs if not, please (sorry, should have asked before marking the PR as ready) |
|
ignore rustbot, all changes outside libs were to test files ^^ |
|
|
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Replace `Unique` in `Box` with a `(NonNull, PhantomData)` wrapper
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (5b25bbf): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -2.9%, secondary 1.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 0.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.3%, secondary -0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 498.333s -> 498.695s (0.07%) |
| // of this box and `layout` would fit that allocation. We also are the only ones | ||
| // responsible for doing this deallocation and know that the pointer must be valid. | ||
| unsafe { | ||
| self.1.deallocate(From::from(ptr.cast()), layout); | ||
| self.1.deallocate(ptr.cast().as_non_null_ptr(), layout); |
There was a problem hiding this comment.
Test diff would be even smaller if this line was unchanged and the From impl used as_non_null_ptr (like the impl From<Unique> for NonNull does).
|
Ah right, I did this initially but then I got rid of it. When I error: implementation has missing stability attribute
--> library/alloc/src/boxed.rs:283:1
|
283 | impl<T: ?Sized> From<BoxRaw<T>> for NonNull<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^But when I do that, I get error: an `#[unstable]` annotation here has no effect
--> library/alloc/src/boxed.rs:283:1
|
283 | #[unstable(feature = "box_internals", issue = "none")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information
= note: `#[deny(ineffective_unstable_trait_impl)]` on by defaultI think this is just broken |
#[inline]
fn non_null_from_box_raw<T: ?Sized>(ptr: BoxRaw<T>) -> NonNull<T> {
ptr.as_non_null_ptr()
}I can do this, but that seems kinda silly |
|
Yeah that seems broken, please file a bug for the stability attribute problem.
|
|
I see a few other impls involving unstable types |
8687763 to
cc516cc
Compare
|
I see exactly one such place, but sure @rustbot ready |
|
You're gonna have to bless a bunch of tests again (miri and mir-opt at least) |
|
😭 |
cc516cc to
5d260fd
Compare
|
Great, thanks! I don't see anything worrying in the test diffs any more, and the last perf run was neutral except for two tiny rustdoc regressions that I'm inclined to believe are noise or otherwise negligible consequence of having a new type at all. @bors r+ rollup=iffy |
| #[expect(ineffective_unstable_trait_impl, reason = "See #164109")] | ||
| #[unstable(feature = "box_internals", issue = "none")] | ||
| impl<T: ?Sized> From<BoxRaw<T>> for NonNull<T> { | ||
| fn from(value: BoxRaw<T>) -> Self { | ||
| value.as_non_null_ptr() | ||
| } | ||
| } |
There was a problem hiding this comment.
Maybe this is just me missing something (haven't read all the linked discussion) but I don't understand why this implementation needs to exist. It is easier to just use as_non_null_ptr in Box's drop impl.
There was a problem hiding this comment.
We found that this code is so sensitive to minimal changes that Hanna suggested I just copy the structure of the code 1-to-1. This can be changed in a follow-up
There was a problem hiding this comment.
This impl and a bunch of other API surface on BoxRaw isn't expected to remain for long. But doing that kind of cleanup at the same time as the main point of this PR caused more & less obvious test diffs as well as more rustc-perf effects. So I suggested landing this like this first (which might take a while too -- I would be surprised if this lands cleanly on first try), and do the cleanup in one or several follow up PRs.
edit: too slow :)
There was a problem hiding this comment.
I actually did use as_non_null_ptr before this comment: #162849 (review)
There was a problem hiding this comment.
My next 2 PRs, which I'll write in parallel, will be to remove BoxRaw (flattening the fields of Box) and Unique. The former will be pretty invasive (and might end up just not working reasonably well), so yay
Rollup merge of #162849 - maxdexh:nuke-unique-in-box, r=hanna-kruppe Replace `Unique` in `Box` with a `(NonNull, PhantomData)` wrapper Follow-up to #162804 See [zulip](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Can.20we.20nuke.20.60Unique.60.3F/with/624141418). This is only the first step in actually refactoring `Box`, and is essentially just a rename. The layout of `Box` stays as-is for now, due to #162850. Needs perf run
|
Note This PR was benchmarked as part of triage of its containing rollup: triage URL. Finished benchmarking commit (9404582): comparison URL. Overall result: ❌ regressions - please read:Our benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesThis perf run didn't have relevant results for this metric. Binary sizeResults (primary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Artifact size: 407.22 MiB -> 406.59 MiB (-0.15%) |
|
Tiny doc regressions on hyper and syn. Changes around @rustbot label: +perf-regression-triaged |
…uwer Rollup of 3 pull requests Successful merges: - rust-lang/rust#164092 (miri subtree update) - rust-lang/rust#162849 (Replace `Unique` in `Box` with a `(NonNull, PhantomData)` wrapper) - rust-lang/rust#163900 (Disable default cc optimizations in shell.nix)
View all comments
Follow-up to #162804
See zulip.
This is only the first step in actually refactoring
Box, and is essentially just a rename.The layout of
Boxstays as-is for now, due to #162850.Needs perf run