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%) |
This comment has been minimized.
This comment has been minimized.
Replace `Unique` in `Box` with a `(NonNull, PhantomData)` wrapper
|
The answer is no, the 2nd try run cancels the first. |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (ee81c60): 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 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -2.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 500.549s -> 509.726s (1.83%) |
|
I guess that's better? It's not really what I expected to happen but okay |
|
@bors try jobs=test-aarch64-apple-1,test-x86_64-msvc-1 |
This comment has been minimized.
This comment has been minimized.
Replace `Unique` in `Box` with a `(NonNull, PhantomData)` wrapper try-job: test-aarch64-apple-1 try-job: test-x86_64-msvc-1
|
Awesome, I think this is ready then ^^ |
This comment has been minimized.
This comment has been minimized.
ef1b81a to
2eaee0e
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2eaee0e to
d4e40bb
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d4e40bb to
b8cac6b
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
b8cac6b to
616dab6
Compare
|
☔ The latest upstream changes (presumably #163609) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
There was a problem hiding this comment.
Left a bunch of nits, thinking-out-loud, and questions.
Overall, looking at the size of the test diffs, parts of those diffs being unexpected, and the not-totally-clean perf run, I think it would be better if this PR did much less drive-by refactoring. Let's first land BoxRaw with identical API to Unique, so that all Box code remains the same w.r.t. source code structure, MIR scopes, MIR optimizations, etc. -- the diff is large enough with just this renaming. Any simplification enabled by having the dedicated type in the same module are better done in follow-up PRs where the effects of each change can be isolated.
@rustbot author
| } | ||
| impl<T: ?Sized> Clone for BoxRaw<T> { | ||
| #[inline] | ||
| fn clone(&self) -> Self { | ||
| *self | ||
| } | ||
| } | ||
| impl<T: ?Sized> Copy for BoxRaw<T> {} |
There was a problem hiding this comment.
nit: having all of this without any blank lines looks cramped and unconventional to me. Probably the one-line marker trait impls can be smushed together, but I'd put blank lines between struct / impl Clone and between impl Clone / marker impls.
There was a problem hiding this comment.
I just noticed, the Clone/Copy impls are actually unused I think 😅
| unsafe impl<T: ?Sized + Send> Send for BoxRaw<T> {} | ||
| unsafe impl<T: ?Sized + Sync> Sync for BoxRaw<T> {} | ||
| impl<T: ?Sized + core::panic::UnwindSafe> core::panic::UnwindSafe for BoxRaw<T> {} | ||
| impl<T: ?Sized, U: ?Sized> CoerceUnsized<BoxRaw<U>> for BoxRaw<T> where T: Unsize<U> {} | ||
| impl<T: ?Sized, U: ?Sized> DispatchFromDyn<BoxRaw<U>> for BoxRaw<T> where T: Unsize<U> {} |
There was a problem hiding this comment.
I notice that Unique has a slightly weaker bound on the corresponding impls (PointeeSized as opposed to ?Sized which I believe means MetaSized). I don't think this makes a difference for Box, but I've been surprised before.
There was a problem hiding this comment.
Box has the same bound (?Sized), so I don't think this makes a difference. I'll throw the weaker bound on there to check if it makes a difference for compile times (since new-solver is apparently hyper-sensitive to everything)
| // - Casting `[u8]` to `str` is correct | ||
| // - The empty byte slice is valid UTF-8 | ||
| unsafe { | ||
| let ptr: *mut [u8] = NonNull::<[u8; 0]>::dangling().as_ptr(); |
There was a problem hiding this comment.
(Note: this comment applies to a refactoring I'd rather not do in this PR, but keeping it here for the sake of follow-up PRs.)
Why the round-trip NonNull -> raw -> NonNull? Unfortunately NonNull::cast doesn't work for [u8] -> str, but it seems simpler to start with ptr::dangling().
There was a problem hiding this comment.
ptr::dangling does the same thing (call NonNull::dangling). I didn't want to regress this impl again by introducing a call... I suspect this will always be ugly
| unsafe { | ||
| let ptr: *mut [u8] = NonNull::<[u8; 0]>::dangling().as_ptr(); |
There was a problem hiding this comment.
(Note: this comment applies to a refactoring I'd rather not do in this PR, but keeping it here for the sake of follow-up PRs.)
I think this unsafe block has too large scope. The let ptr ... part isn't unsafe at all. But the NonNull::new_unchecked technically has a precondition not mentioned in the safety comment. I'd suggest splitting this up into two steps:
- Construct the
NonNull<str>(onlynew_uncheckedneeds unsafe) - Construct the
Box(BoxRaw { ... })where most of the current safety comments apply
There was a problem hiding this comment.
ideally this would just use Box<[u8]> default and use the boxed from utf8 unchecked function, but that involves a lot of unnecessary round trips that regress debug mode
| _4 = const std::ptr::Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} is !null }}, _marker: PhantomData::<[bool; 0]> }}; | ||
| _4 = const NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: pattern_type!(*const [bool] is !null) }}; |
There was a problem hiding this comment.
Hm, this change is a bit unexpected to me. I think it's because the change to impl Default for Box<[T]> makes the unsizing happen earlier:
- Before:
NonNull<[T; 0]>::dangling()is used inUnique<[T; 0]>::dangling()is coerced toUnique<[T]> - Now:
NonNull<[T; 0]>is coerced toNonNull<[T]>because it's used inBoxRawstruct literal with expected typeBoxRaw<[T]>
I'm not sure if that's better or worse. I think it's probably marginally better to unsize later, but mostly I'd like to make sure I understand what's happening. Can you try changing impl Default to stick closer to the original version (create BoxRaw<[T; 0]> and then unsize) to check this theory?
There was a problem hiding this comment.
Hm, that's interesting, I intended to match the old function as closely as possible. I'll try to make it match more closely and rerun perf
| goto -> bb4; | ||
| } | ||
|
|
||
| bb4: { | ||
| StorageDead(_2); |
There was a problem hiding this comment.
Needing an extra block here seems unfortunate. I guess it's a consequence of the corresponding StorageLive statements not being in the same block any more? But I don't know why they aren't. Any ideas?
There was a problem hiding this comment.
I guess mir-opt prefers the old code, which accessed the nonnull field twice, instead of my ahead of time ptr = self.0.pointer? strange, will see if separate accesses give better codegen
| } | ||
| scope 18 (inlined <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next) { | ||
| let mut _22: std::option::Option<std::convert::Infallible>; | ||
| let mut _22: std::option::Option<!>; |
There was a problem hiding this comment.
I don't understand how this PR possibly could've caused this change, that's concerning.
There was a problem hiding this comment.
those tests weren't getting run (was fixed recently), this should fix itself when i rebase
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