-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Allow dropping dyn Trait
principal
#126660
Allow dropping dyn Trait
principal
#126660
Conversation
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
e2bb040
to
5fc4a79
Compare
cc @compiler-errors |
I'll let @lcnr do the judgement call of whether this needs a lang FCP or if types suffices. Thanks for picking this back up! |
sorry for the delay! nominating for lang, to let them decide whether they mind delegating this to t-types. We simply reuse the vtable of the parent trait when dropping the principal. This relies on all vtables to have the same header used for dropping and Also, please extend the test to also check |
Is there a Miri test that does this? This may run afoul of Miri's vtable validity check, which is supposed to ensure that the vtable has the same principal as the dyn trait type indicates.
vtables are entirely an implementation detail. In the op.sem they don't even exist in-memory, just as abstract opaque concepts (similar to function pointers). So we're free to do whatever here. But it does mean we have to define the validity of wide pointers such that it's okay for the vtable to have a principal even if the type does not. |
The Miri subtree was changed cc @rust-lang/miri |
Done |
I don't understand how this new test can pass, it seems like it should fail this check... |
This comment has been minimized.
This comment has been minimized.
5d95660
to
3d0856e
Compare
Miri test looks good, thanks! |
does that mean this also requires an opsem FCP? I would expect that this sort of type pruning is definitely sound. I would expect that shrinking the size of the pointee is totally safe and we can't assume that all vtables for the same type are equal. |
cc @rust-lang/lang the nomination is for
|
Also worth noting that keeping the same vtable is not a guarantee and in fact in Miri you will get a different vtable for the "None" principal. I assume this could be done at runtime as well.
Keeping the same vtable means runtime will see pointer equalities that are impossible to obtain in Miri - but we have that elsewhere, too, e.g. with deduplication of identical consts.
|
@rustbot labels -I-lang-nominated We discussed this today in lang triage. This sounded right to us, in terms of making the language more consistent. We discussed whether we were closing any meaningful doors here and couldn't really find any. This seems in particular consistent with the direction that we set with dyn trait upcasting. We'll of course do this as a dual FCP with T-types. |
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
This seems entirely reasonable to me -- it's basically like every trait has the supertrait ε and you can go from @rfcbot reviewed |
☔ The latest upstream changes (presumably #130473) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping @nikomatsakis @pnkfelix @tmandry for remaining checkboxes. |
@rfcbot reviewed |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@rfcbot reviewed |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
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.
we still use data_a.principal_def_id() == data_b.principal_def_id()
in coerce_dyn_star
, can you add a test for that
… r=compiler-errors Allow dropping dyn principal Revival of rust-lang#126660, which was a revival of rust-lang#114679. Fixes rust-lang#126313. Allows dropping principal when coercing trait objects, e.g. `dyn Debug + Send` -> `dyn Send`. cc `@compiler-errors` `@Jules-Bertholet` r? `@lcnr`
Superseded by #131857 -- should this PR be closed? |
Rollup merge of rust-lang#131857 - WaffleLapkin:dyn-drop-principal-3, r=compiler-errors Allow dropping dyn principal Revival of rust-lang#126660, which was a revival of rust-lang#114679. Fixes rust-lang#126313. Allows dropping principal when coercing trait objects, e.g. `dyn Debug + Send` -> `dyn Send`. cc `@compiler-errors` `@Jules-Bertholet` r? `@lcnr`
Redux of #114679, fixes #126313
This allows the following examples to compile:
This makes the language more consistent, as we already allow:
The PR includes a test case, in
tests/ui/traits/dyn-drop-principal.rs
.Documentation
dyn
upcasting coercions, of any kind, are currently entirely undocumented in the reference. A future reference PR should address this.@rustbot label T-lang T-types needs-fcp A-coercions A-trait-objects