Repository navigation
Conversation
|
Disclosure: An LLM was used to help generate the tests and to experiment with early prototypes of the pointee normalization code (though I wrote the code in this PR from scratch). |
This comment has been minimized.
This comment has been minimized.
6510d77 to
509f5d7
Compare
|
This PR changes a file inside Some changes occurred to the CTFE machinery Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
| &ty::UnsafeBinder(inner) => { | ||
| self.check_wide_ptr_meta(meta, inner.skip_binder())?; |
There was a problem hiding this comment.
Shouldn't struct_tail_for_codegen recurse below UnsafeBinder to return the actual tail type?
| // `unsafe<..> X` means `X` is `ManuallyDrop<Y>` or `Copy` (and thus metadata is `()`, because `trait Copy: Sized`). | ||
| let Some(bound_ty) = as_manually_drop(binder.skip_binder()) else { | ||
| return PointeeStep::Metadata(Ty::new_unit(cx)); | ||
| }; |
There was a problem hiding this comment.
unsafe<'a> (MD<A<'a>>, MD<dyn Trait + 'a>) would have metadata type () under this?
The comments doesn't cover mutable refs either.
Overall it feels fragile to rely on details of GuaranteedNoDrop 🤔
| /// If we encounter an `unsafe<..> X` type, then we need to be a bit clever in | ||
| /// the metadata that we return. There are a couple things to consider: | ||
| /// - If we see nested unsafe binders, we combine both into a single under binder, | ||
| /// which may bind some inner metadata ty. | ||
| /// - If we see nested `ManuallyDrop` types, then we just collapse them into as single one. | ||
| /// - If the eventual metadata ty is a `dyn Trait + 'a`, then the metadata is | ||
| /// `DynMetadata<unsafe<'a> ManuallyDrop<dyn Trait + 'a>>`, not `DynMetadata<dyn Trait + 'a>`. | ||
| /// This is because the `unsafe<'a> DynMetadata<dyn Trait + 'a>` doesn't | ||
| /// implement the necessary `Pointee::Metadata` bounds. Furthermore, we can't | ||
| /// return `DynMetadata<unsafe<'a> dyn Trait + 'a>` because that type is not well-formed. | ||
| /// We also don't return `DynMetadata<dyn Trait + 'static>`, because we don't | ||
| /// want to lie about lifetimes lie that. |
There was a problem hiding this comment.
For an unsafe binder containing trait object to be well-formed, the trait object is guaranteed to be wrapped in a ManualDrop, right 🤔 ? So it's quite natural to return DynMetadata<unsafe<'a> MD<dyn Trait + 'a>> for unsafe<'a> MD<dyn Trait + 'a>.
We could phase it as we track all bound regions and peel all wrappers until we reach the tail trait object, then we wrap the tail trait object with MD and bind it.
I'm a little unsure about the collapsing part. unsafe<'a> unsafe<'b> MD<dyn Trait<'a> + 'b> and unsafe<'a, 'b> MD<dyn Trait<'a> + 'b> should mean the same thing. But the collapsing is visible to users via ptr::metadata/from_raw_parts. We can recover both &unsafe<'a> unsafe<'b> MD<dyn Trait<'a> + 'b> and &unsafe<'a, 'b> MD<dyn Trait<'a> + 'b> from DynMetadata<unsafe<'a, 'b> MD<dyn Trait<'a> + 'b>. Is this something we want to support intentionally?
There was a problem hiding this comment.
For an unsafe binder containing trait object to be well-formed, the trait object is guaranteed to be wrapped in a
ManualDrop, right 🤔 ?
I mean, somewhere, yeah. For example, this is WF: unsafe<'a, 'b> MD<(&'b u8, dyn Tr<'a> + 'a)>
So it's quite natural to return
DynMetadata<unsafe<'a> MD<dyn Trait + 'a>>forunsafe<'a> MD<dyn Trait + 'a>. We could phase it as we track all bound regions and peel all wrappers until we reach the tail trait object, then we wrap the tail trait object with MD and bind it.
Yes, basically.
I'm a little unsure about the collapsing part.
unsafe<'a> unsafe<'b> MD<dyn Trait<'a> + 'b>andunsafe<'a, 'b> MD<dyn Trait<'a> + 'b>should mean the same thing.
A minor point on the first: that's not actually WF, because we don't treat unsafe binders as Copy. But, the point still stands that we can nesting.
But the collapsing is visible to users via
ptr::metadata/from_raw_parts. We can recover both&unsafe<'a> unsafe<'b> MD<dyn Trait<'a> + 'b>and&unsafe<'a, 'b> MD<dyn Trait<'a> + 'b>fromDynMetadata<unsafe<'a, 'b> MD<dyn Trait<'a> + 'b>. Is this something we want to support intentionally?
shrug I don't really know. I'm happy to leave a FIXME somewhere, but would rather not try to block this PR on that question. (The goal is to get something working that people can test, and refine the semantics.)
There was a problem hiding this comment.
A minor point on the first: that's not actually WF, because we don't treat unsafe binders as Copy.
Oh, right. Unsafe binders should impl GuaranteedNoDrop though? Then it would be WF. Probably not in the scope of this PR.
I'm happy to leave a FIXME somewhere, but would rather not try to block this PR on that question. (The goal is to get something working that people can test, and refine the semantics.)
make sense :>
|
rust/compiler/rustc_middle/src/ty/layout.rs Lines 992 to 996 in 8d77382 We also need to support seeing through unsafe binders here? |
|
@rustbot author |
…nders lifetimes in RegionEraserAndAnonymizerVisitor.
509f5d7 to
47d68ec
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Based on #166290
Split from #163515
Closes #154871
r? adwinwhite