-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Add MaybeDangling to core
#149775
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
Add MaybeDangling to core
#149775
Conversation
This comment has been minimized.
This comment has been minimized.
|
The Miri subtree was changed cc @rust-lang/miri |
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.
Thanks for working on this :-)
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
c7db108 to
95eee60
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
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.
r=me in general with commits squashed, possibly comments addressed (happy to leave specifics up to you)
| /// | ||
| /// Even though the `Box`e's destructor is not run (and thus we don't have a double free bug), this | ||
| /// code is still UB. This is because when moving `boxed` into `forget`, its validity invariants | ||
| /// are asserted, causing UB since the `Box` is dangling. |
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.
Maybe worth clarifying, e.g., "The safety comment is as such wrong, as moving the boxed variable as part of the call is a use"?
| /// **not** dangling -- functions like [`as_ref`] and [`into_inner`] are safe. It is not sound to | ||
| /// return a dangling reference in a `MaybeDangling` to safe code. However, it *is* sound | ||
| /// to hold such values internally inside your code -- and there's no way to do that without | ||
| /// this type. |
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 sounds like there are alternatives to this type, though, right? Is it worth saying something about ManuallyDrop or some other construct that's already stable?
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.
Hm... yeah fair, some other types will use this type and thus get the same effect; in particular, ManuallyDrop.
| /// (and [boxes]) still must be aligned and non-null. | ||
| /// | ||
| /// Additionally note that safe code can still assume that the inner value in a `MaybeDangling` is | ||
| /// **not** dangling -- functions like [`as_ref`] and [`into_inner`] are safe. It is not sound to |
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.
How do we deal with the implicit Drop for the inner type? Should callers who place e.g. a dangling Box inside just be careful to call forget rather than letting it Drop?
|
|
||
| use crate::{mem, ptr}; | ||
|
|
||
| /// Allows wrapped [references] and [boxes] to dangle. |
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.
Can we add a "Not yet actually implemented" or perhaps make maybe_dangling an incomplete lang feature? I worry a bit that as of this PR, from what I can tell, this is UB to use as documented, right? Since the compiler bits aren't there yet.
Co-authored-by: Ralf Jung <post@ralfj.de>
95eee60 to
25476d8
Compare
|
I think I've addressed all the review comments. |
…Simulacrum Add `MaybeDangling` to `core` This is the library part of adding `MaybeDangling`. Note that it doesn't actually do anything described in its docs (yet), I'll make a separate PR for that. Tracking issue: #118166. r? libs cc `@RalfJung`
This comment has been minimized.
This comment has been minimized.
|
💔 Test failed - checks-actions |
- fixup `BTreeMap` gdb provider - fixup `ManuallyDrop` natvis thingy Now that `MaybeUninit` contains `ManuallyDrop` which contains `MaybeDangling` (tbc this is the addition), we need to unwrap one more layer.
25476d8 to
6b4f4f5
Compare
|
@bors try jobs=aarch64-msvc-1 |
This comment has been minimized.
This comment has been minimized.
Add `MaybeDangling` to `core` try-job: aarch64-msvc-1
|
@bors r=Mark-Simulacrum |
|
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing c7aa99f (parent) -> 0850949 (this PR) Test differencesShow 184 test diffs184 doctest diffs were found. These are ignored, as they are noisy. Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 08509492139968a96a005ba811a995e2f1d6a2ac --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (0850949): comparison URL. Overall result: ❌ regressions - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 0.9%, secondary -0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (primary 0.6%, secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 480.868s -> 482.408s (0.32%) |
|
This seems to have caused Miri regressions: rust-lang/miri#4793 |
|
perf triage: Are regressions expected here? Some of those could be noise, it seems like the previous PR had more positive noise (post merge results look better than pre-merge), so this could be just return to normal. The incremental ones look real, though, they have some new deltas in detailed results, for example here for cargo debug. |
This is the library part of adding
MaybeDangling. Note that it doesn't actually do anything described in its docs (yet), I'll make a separate PR for that.Tracking issue: #118166.
r? libs
cc @RalfJung