-
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
Yeet owning_ref
#109971
Yeet owning_ref
#109971
Conversation
Turns out - `owning_ref` is unsound due to `Box` aliasing stuff - `rustc` doesn't need 99% of the `owning_ref` API - `rustc` can use a far simpler abstraction that is `OwnedSlice`
(rustbot has picked a reviewer for you, use r? to override) |
Could someone summarize why this type is necessary? |
Metadata handling stores references into subsections of the object file. As we've seen in #97770, metadata handling is very perf sensitive so just storing indices doesn't seem to work. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
pub fn try_slice_owned<O, F, E>(owner: O, slicer: F) -> Result<OwnedSlice, E> | ||
where | ||
O: Send + Sync + 'static, | ||
F: Fn(&O) -> Result<&[u8], E>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FnOnce
, this avoids having to change it in other places and is simply more correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a lovingly simple datastructure, but even lovingly simple datastructures deserve tests 😅
e1af75e
to
504c4c4
Compare
|
||
unsafe { Mmap::map(file) } | ||
.map_err(|e| format!("failed to mmap file '{}': {}", path.display(), e)) | ||
.and_then(|mmap| try_slice_owned(mmap, |mmap| f(mmap))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|mmap| f(mmap)
nit: Can this be replaced with f
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not with &f
either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
This isn't necessarily relevant to yeeting owning_ref, but this issue caused me to take a look at the nested It seems that the metadata is only actually used in the form of In other words, have the Any opinions? |
r? @Nilstrieb |
try was cancelled by the push |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 504c4c4 with merge 8acf625821137194e53ab4dc44492235feb70809... |
@noamtashma this is certainly possible, but I'm not sure if that actually changes anything, because I'd prefer to keep this PR as-is and then try your idea in a follow-up, just so it's easier to review / keep track of. |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
e06f470
to
2733c29
Compare
Yeet! |
} | ||
|
||
impl Borrow<[u8]> for OwnedSlice { | ||
fn borrow(&self) -> &[u8] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be nice to check, that this (and other short fns around) call will be inlined, as rust sometimes forget about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great call, these two functions should all have #[inline]
attributes. I'm not entirely sure where they are all used but given that it's used in metadata loading which is very hot this could be really bad on platforms that aren't compiled with LTO (like our neutral perf run was).
@bors r- |
@bors r=Nilstrieb rollup=maybe |
…strieb Yeet `owning_ref` Based on the discussions from rust-lang#109948 This replaces `owning_ref` with a far simpler & safer abstraction. Fixes rust-lang#109974
…strieb Yeet `owning_ref` Based on the discussions from rust-lang#109948 This replaces `owning_ref` with a far simpler & safer abstraction. Fixes rust-lang#109974
☀️ Test successful - checks-actions |
1 similar comment
☀️ Test successful - checks-actions |
Finished benchmarking commit (0f0dc29): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. |
Based on the discussions from #109948
This replaces
owning_ref
with a far simpler & safer abstraction.Fixes #109974