-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
prune ill-conceived BTreeMap iter_mut assertion and test its mutability #67459
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
I also wondered why so much effort went into setting up a slice for an immutable map, and there's only one genuine use:
|
cc @RalfJung |
Added more unit testing |
☔ The latest upstream changes (presumably #67540) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
Back then I tried to keep the code as close as possible to how it was, so I didn't mess with the slices. But if we can get rid of them and thus get rid of the entirely awful |
There are at least two argument for keeping off my "radical" slice slashing experiment:
Still, I think it's probably best to keep the slices, but precondition out shared roots. It eliminates |
Well, and who's sure the current code is correct? ;)
I was wondering about the |
So it's not correct, and returning a temporary is the full story because in that case we're not going to mutate the key nor the key slice. |
No, no, no, that last point doesn't make sense either. Must reboot myself and find sanity. |
Sorry for the confusion. Slightly saner self says:
|
The new commit here only brings more and smarter testing, I haven't put back any assertion. |
39af96f
to
5c3d8cc
Compare
if mem::align_of::<K>() > mem::align_of::<LeafNode<(), ()>>() && self.is_shared_root() { | ||
// aligned, the offset of a correctly typed `keys_start` might be outside | ||
// the bounds of the allocated header! So we do an alignment check first, | ||
// that will be evaluated at compile-time, and only do any run-time check |
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.
Should be "alignment and size check" now, I guess?
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.
I think it's clear enough. In my mind, it's about the "alignment" of the keys_start field, so both the alignment of the struct and the offset of the field within the struct (which we measure through struct size). I guess "alignment" is a stretch here, but "alignment and size" is a bit of an implementation detail.
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.
The check literally looks at alignment and size, so it seems odd to call it an "alignment check". And of course this is an implementation detail, we are knee-deep inside a private method's unsafe code here.
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.
I meant that the sentence that brings the important point across about compile-time vs. run-time checks shouldn't elaborate or repeat the steps too much.
In any case, I have now substantially rearranged points.
The PR now seems fine to me, modulo nits. I assume you ran tests with debug assertions enabled?
I really like the simplest alternative, but why can that work? You have not gotten rid of a single caller of |
Meanwhile Miri and 32/64 bit Linux & Windows all pass |
Looking good, thanks a lot! @bors r+ |
📌 Commit e3c814e has been approved by |
prune ill-conceived BTreeMap iter_mut assertion and test its mutability Proposal to deal with rust-lang#67438 (and I'm more sure now that this is the right thing to do). Passes testing with miri.
Rollup of 12 pull requests Successful merges: - #67112 (Refactor expression parsing thoroughly) - #67192 (Various const eval and pattern matching ICE fixes) - #67287 (typeck: note other end-point when checking range pats) - #67459 (prune ill-conceived BTreeMap iter_mut assertion and test its mutability) - #67576 (reuse `capacity` variable in slice::repeat) - #67602 (Use issue = "none" instead of "0" in intrinsics) - #67614 (Set callbacks globally) - #67617 (Remove `compiler_builtins_lib` documentation) - #67629 (Remove redundant link texts) - #67632 (Convert collapsed to shortcut reference links) - #67633 (Update .mailmap) - #67635 (Document safety of Path casting) Failed merges: r? @ghost
⌛ Testing commit e3c814e with merge 54d8ccd5c7c02f9bd56cfac8200c38e1fbcefa8d... |
Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
💔 Test failed - checks-azure |
Seems spurious. @bors retry |
There's something still not quite right:
But also, since Miri confirms that doing this is fine, doesn't that mean that the effort in |
prune ill-conceived BTreeMap iter_mut assertion and test its mutability Proposal to deal with #67438 (and I'm more sure now that this is the right thing to do). Passes testing with miri.
☀️ Test successful - checks-azure |
Simplify into_key_slice_mut Remove a rare and tiny but superfluous run-time check from into_key_slice_mut. In rust-lang#67459, I wrote that "`get_mut` [...] does visit `into_key_slice_mut`" and that was wrong. No function that operates on a map that (still) has a shared root ever dives into `into_key_slice_mut`. So it's more clear to remove the (previously existing, and always incomplete) code it has for dealing with shared roots, as well as a petty performance improvement for those using exotically aligned key types. ~~Also, some testing of the `range` function initially added to rust-lang#67686 but hardly related.~~ r? @RalfJung
Proposal to deal with #67438 (and I'm more sure now that this is the right thing to do).
Passes testing with miri.