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

Yeet owning_ref #109971

Merged
merged 9 commits into from
Apr 8, 2023
Merged

Yeet owning_ref #109971

merged 9 commits into from
Apr 8, 2023

Conversation

WaffleLapkin
Copy link
Member

@WaffleLapkin WaffleLapkin commented Apr 5, 2023

Based on the discussions from #109948

This replaces owning_ref with a far simpler & safer abstraction.

Fixes #109974

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
Copy link
Collaborator

rustbot commented Apr 5, 2023

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 5, 2023
@petrochenkov
Copy link
Contributor

Could someone summarize why this type is necessary?
If you have an owned Box or Mmap, why do you need to additionally pack a reference with it?

@Noratrieb
Copy link
Member

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

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 5, 2023
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>,
Copy link
Member

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.

Copy link
Member

@Noratrieb Noratrieb left a 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 😅


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)))
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

No.

Copy link
Contributor

Choose a reason for hiding this comment

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

not with &f either?

Copy link
Member Author

Choose a reason for hiding this comment

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

No.

@noamtashma
Copy link
Contributor

This isn't necessarily relevant to yeeting owning_ref, but this issue caused me to take a look at the nested Box<dyn {Lrc<Box<dyn {?}>}> structure in def_path_hash_map and I think it could be improved further.

It seems that the metadata is only actually used in the form of MetadataRef, so that it's cloneable. If that's true, than we could instead always use the structure of Lrc<dyn Send + Sync>.

In other words, have the owning_slice contain an Lrc<dyn Send + Sync> instead of a Box<dyn Send + Sync>.
Then owning_slice becomes clone, it gains a slice method or equivalent to get a subslice of the existing slice without an extra indirection, and MetadataRef and MetadataBlob become equivalent, which is nice.

Any opinions?

@petrochenkov
Copy link
Contributor

r? @Nilstrieb

@rustbot rustbot assigned Noratrieb and unassigned petrochenkov Apr 6, 2023
@Noratrieb
Copy link
Member

try was cancelled by the push
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 6, 2023

⌛ Trying commit 504c4c4 with merge 8acf625821137194e53ab4dc44492235feb70809...

@WaffleLapkin
Copy link
Member Author

@noamtashma this is certainly possible, but I'm not sure if that actually changes anything, because OwningSlice accesses don't get slower with more indirection (it always stores the pointer to actual data).

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.

@bors
Copy link
Contributor

bors commented Apr 6, 2023

☀️ Try build successful - checks-actions
Build commit: 8acf625821137194e53ab4dc44492235feb70809 (8acf625821137194e53ab4dc44492235feb70809)

@rust-timer

This comment has been minimized.

@Noratrieb
Copy link
Member

Yeet!
@bors r+ rollup=maybe

@bors
Copy link
Contributor

bors commented Apr 6, 2023

📌 Commit 2733c29 has been approved by Nilstrieb

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 Apr 6, 2023
}

impl Borrow<[u8]> for OwnedSlice {
fn borrow(&self) -> &[u8] {
Copy link
Contributor

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.

Copy link
Member

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).

@Noratrieb
Copy link
Member

@bors r-

@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 Apr 6, 2023
@WaffleLapkin
Copy link
Member Author

@bors r=Nilstrieb rollup=maybe

@bors
Copy link
Contributor

bors commented Apr 7, 2023

📌 Commit fbe0591 has been approved by Nilstrieb

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 Apr 7, 2023
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Apr 7, 2023
…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
Noratrieb added a commit to Noratrieb/rust that referenced this pull request Apr 7, 2023
…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
@bors
Copy link
Contributor

bors commented Apr 8, 2023

⌛ Testing commit fbe0591 with merge 0f0dc29...

@bors
Copy link
Contributor

bors commented Apr 8, 2023

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing 0f0dc29 to master...

1 similar comment
@bors
Copy link
Contributor

bors commented Apr 8, 2023

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing 0f0dc29 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 8, 2023
@bors bors merged commit 0f0dc29 into rust-lang:master Apr 8, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 8, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0f0dc29): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This 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.

Cycles

This benchmark run did not return any relevant results for this metric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OwningRef is included in the compiler despite known soundness problems.
10 participants