-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Replace owning_ref
with a safer datastructure
#97770
Conversation
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
owning_ref
by a safer datastructureowning_ref
with a safer datastructure
a1ca731
to
f62788b
Compare
This comment has been minimized.
This comment has been minimized.
f62788b
to
88ae661
Compare
This comment has been minimized.
This comment has been minimized.
The owned slice represents an owned value with a view into that owned slice. For example, it might own a `Vec<i32>` of `[1, 2]`, but only deref to `[2]`. It's almost entirely written using safe code, except for one unsafe block to calculate a pointer difference.
`owning_ref` of a `Box<T>` has soundness problems because it stores pointers to a box that is then invalidated. Instead, use the safer `owned_slice`, which presents a more specialized abstraction. This doesn't change the general layout or indirection of the structure, but only the datastructure used as a wrapper.
`owning_ref` has soundness problems when used with `Box<T>`, and the previous commit replaced its usages with a better abstraction. This means that we can now get rid of it.
88ae661
to
99419ea
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 99419ea with merge c79658f2ae2271230d400d079a30d01d842d33be... |
☀️ Try build successful - checks-actions |
Queued c79658f2ae2271230d400d079a30d01d842d33be with parent fee3a45, future comparison URL. |
Finished benchmarking commit (c79658f2ae2271230d400d079a30d01d842d33be): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Footnotes |
That's not great, but I think I can optimize this. |
Hmm, using it with Though, now that I think about it, it might be a better idea to add a |
Could also use |
Would it make sense to remove the |
Yes. Under stacked borrows (currently), box does not obey the rules of stable deref. |
Allocating on the heap is the standard way to ensure address stability, and |
I believe rustc only uses owning ref with |
This |
No, it is either an memmap2::Mmap or an Vec depending on the target:
|
In pub type MetadataRef = OwningRef<Box<dyn Erased + Send + Sync>, [u8]>; Here a box is used |
Right. The |
I'll block this on the hope that we can make box aliasable, therefore making this PR useless. If that doesn't happen, I'd add an AliasableBox and use that with the owning_ref here. |
Ping from triage:
@Nilstrieb What is the status of this PR? If you're not moving forward with this please close it. |
I'll close it for now, I might pick it up in the future again depending on what happens with box. |
owning_ref
has soundness problems when used together withBox<T>
, since moving a box invalidates all pointers to it under stacked borrows.It's only used in once place, in metadata handling, where it's used to have a subslice view into an owned slice. So this pull request adds a new datastructure, this kind of
owned_slice
, which gives a subslice view into an owned slice with almost no unsafe code, that passes miri in strict mode.I replaced the only usage of
owning_ref
with this new datastructure, and then subsequently removedowning_ref
fromrustc_data_structures
.