Implement MaybeDangling compiler support#150447
Implement MaybeDangling compiler support#150447WaffleLapkin wants to merge 6 commits intorust-lang:mainfrom
MaybeDangling compiler support#150447Conversation
aebfd56 to
63e07cf
Compare
This comment has been minimized.
This comment has been minimized.
63e07cf to
c40ca7d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6d96bdb to
d71787d
Compare
This comment has been minimized.
This comment has been minimized.
f6fafff to
baa9118
Compare
This comment has been minimized.
This comment has been minimized.
baa9118 to
c135ac1
Compare
This comment has been minimized.
This comment has been minimized.
c135ac1 to
f399322
Compare
8bbf80d to
a72a3f3
Compare
This comment has been minimized.
This comment has been minimized.
a72a3f3 to
42ce338
Compare
This comment has been minimized.
This comment has been minimized.
51a5c77 to
efc351d
Compare
|
@RalfJung this is finally ready for review :) Let me know if you'd prefer the |
This comment has been minimized.
This comment has been minimized.
efc351d to
8102f65
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. |
|
This PR can result in stable code using ManuallyDrop getting less optimization, right? |
|
@theemathas yes. Importantly also less UB ^^' |
|
Indeed, that is the intent of this PR. ;) Note that this PR does not guarantee the absence of those optimizations on stable. It only guarantees it for code that uses |
395a073 to
62cbdee
Compare
compiler/rustc_ty_utils/src/abi.rs
Outdated
| // Handle safe Rust thin and wide pointers. | ||
| /// Returns argument attributes for a scalar argument. | ||
| /// | ||
| /// `drop_target_pointee` is used to special-case the argument of `ptr::drop_in_place`, |
There was a problem hiding this comment.
| /// `drop_target_pointee` is used to special-case the argument of `ptr::drop_in_place`, | |
| /// `drop_target_pointee`, if set, causes the scalar, if it is a pointer, to be treated as a mutable | |
| /// reference to the given type. This is used to special-case the argument of `ptr::drop_in_place`, |
This is unlike before where that treatment only happened if the scalar was by itself not already a safe pointer -- right?
There was a problem hiding this comment.
if it is a pointer
that is not quite correct, we have an assertion that it's a pointer, not a check.
This is unlike before where that treatment only happened if the scalar was by itself not already a
safepointer -- right?
Yes, before it happened if the scalar was a pointer, and specifically a raw one.
There was a problem hiding this comment.
Okay, please make the docs whatever the correct thing is then. :)
There was a problem hiding this comment.
I've tried to clarify the docs, is this better?
| /// Indicates whether the type is `FieldRepresentingType`. | ||
| const IS_FIELD_REPRESENTING_TYPE = 1 << 13; | ||
| /// Indicates whether the type is `MaybeDangling<_>`. | ||
| const IS_MAYBE_DANGLING = 1 << 14; |
There was a problem hiding this comment.
Most of these are mutually exclusive so it is a huge waste of bits to have a separate bit for each of them... 🤷 that's pre-existing though, not for this PR to fix.
Make `size`/`align` always correct rather than conditionally on the `safe` field. This makes it less error prone and easier to work with for `MaybeDangling` / potential future pointer kinds like `Aligned<_>`.
Instead of defaulting to `None` it now defaults to `Align::ONE` i.e. no alignment restriction. Codegen test changes are due to us now skipping `align 1` annotations (they are useless; not skipping them makes all the raw pointers gain an `align 1` annotation which doesn't seem any good)
62cbdee to
24012bc
Compare
24012bc to
f308311
Compare
|
@bors try @rust-timer queue |
|
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
|
⌛ Trying commit f308311 with merge e147e93… To cancel the try build, run the command Workflow: https://github.com/rust-lang/rust/actions/runs/22619884618 |
Implement `MaybeDangling` compiler support
|
The job Click to see the possible cause of the failure (guessed by this bot) |
View all comments
Tracking issue: #118166
cc @RalfJung