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

Take a single root node in range_search #71523

Merged
merged 1 commit into from
Apr 25, 2020

Conversation

Mark-Simulacrum
Copy link
Member

The unsafe code can be justified within range_search, as it makes sure to not
overlap the returned references, but from the callers perspective it's an
entirely safe algorithm and there's no need for the caller to know about the
duplication.

cc @ssomers
r? @Amanieu

The unsafe code can be justified within range_search, as it makes sure to not
overlap the returned references, but from the callers perspective it's an
entirely safe algorithm and there's no need for the caller to know about the
duplication.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 24, 2020
@ssomers
Copy link
Contributor

ssomers commented Apr 24, 2020

By the way, I was wondering why it wasn't marked unsafe. Not only could you monkey around by passing in different root, it still returns two mutable handles into the same tree and you can invalidate one handle by changing the tree through the other. Not that I think sprinkling more unsafe words helps readability.

What would help readability, I think, is moving the function out of the fat map.rs file into search.rs. Although if you pass a RangeFull as range, it acts like the first_leaf_edge/last_leaf_edge functions in navigate.rs.

Comment on lines +2062 to +2063
// We duplicate the root NodeRef here -- we will never access it in a way
// that overlaps references obtained from the root.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand that sentence (but I don't have to). In an emptied tree, range_search will return two references to the same and only edge. Is that no overlap?

@Mark-Simulacrum
Copy link
Member Author

Yeah, I think the justification here may not be perfect -- but I do think this is the right move. In particular, it seems like the risk of "well you could invalidate the tree" is sort of always true -- we detach the handles from the root node pretty frequently -- and I wouldn't want to add a bunch of unsafe everywhere, for sure not until we have the unsafe-in-unsafe-fns lint.

@Amanieu
Copy link
Member

Amanieu commented Apr 24, 2020

I personally think that the entirety of the internal btree code should just be unsafe, so I don't feel too strongly about this.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 24, 2020

📌 Commit e6cf6a7 has been approved by Amanieu

@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 24, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 25, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#71364 (Ignore -Zprofile when building compiler_builtins)
 - rust-lang#71494 (Fix span of while (let) expressions after lowering)
 - rust-lang#71517 ( Quick and dirty fix of the unused_braces lint)
 - rust-lang#71523 (Take a single root node in range_search)
 - rust-lang#71533 (Revert PR 70566 for const validation fix)

Failed merges:

r? @ghost
@bors bors merged commit 62b3624 into rust-lang:master Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants