forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#113856 - WaffleLapkin:vtablin', r=oli-obk
Refactor vtable encoding and optimize it for the case of multiple marker traits This PR does two things - Refactor `prepare_vtable_segments` (this was motivated by the other change, `prepare_vtable_segments` was quite hard to understand and while trying to edit it I've refactored it) - Mostly remove `loop`s labeled `break`s/`continue`s whenever there is a simpler solution - Also use `?` - Make vtable format a bit more efficient wrt to marker traits - See the tests for an example Fixes rust-lang#113840 cc `@crlf0710` ---- Review wise it's probably best to review each commit individually, as then it's more clear why the refactoring is correct. I can split the last two commits (which change behavior) into a separate PR if it makes reviewing easier
- Loading branch information
Showing
6 changed files
with
198 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Regression test for <https://github.com/rust-lang/rust/issues/113840> | ||
// | ||
// This test makes sure that multiple marker (method-less) traits can reuse the | ||
// same pointer for upcasting. | ||
// | ||
// build-fail | ||
#![crate_type = "lib"] | ||
#![feature(rustc_attrs)] | ||
|
||
// Markers | ||
trait M0 {} | ||
trait M1 {} | ||
trait M2 {} | ||
|
||
// Just a trait with a method | ||
trait T { | ||
fn method(&self) {} | ||
} | ||
|
||
#[rustc_dump_vtable] | ||
trait A: M0 + M1 + M2 + T {} //~ error: vtable entries for `<S as A>`: | ||
|
||
#[rustc_dump_vtable] | ||
trait B: M0 + M1 + T + M2 {} //~ error: vtable entries for `<S as B>`: | ||
|
||
#[rustc_dump_vtable] | ||
trait C: M0 + T + M1 + M2 {} //~ error: vtable entries for `<S as C>`: | ||
|
||
#[rustc_dump_vtable] | ||
trait D: T + M0 + M1 + M2 {} //~ error: vtable entries for `<S as D>`: | ||
|
||
struct S; | ||
|
||
impl M0 for S {} | ||
impl M1 for S {} | ||
impl M2 for S {} | ||
impl T for S {} | ||
impl A for S {} | ||
impl B for S {} | ||
impl C for S {} | ||
impl D for S {} | ||
|
||
pub fn require_vtables() { | ||
fn require_vtables(_: &dyn A, _: &dyn B, _: &dyn C, _: &dyn D) {} | ||
|
||
require_vtables(&S, &S, &S, &S) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
error: vtable entries for `<S as A>`: [ | ||
MetadataDropInPlace, | ||
MetadataSize, | ||
MetadataAlign, | ||
Method(<S as T>::method), | ||
] | ||
--> $DIR/multiple-markers.rs:21:1 | ||
| | ||
LL | trait A: M0 + M1 + M2 + T {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: vtable entries for `<S as B>`: [ | ||
MetadataDropInPlace, | ||
MetadataSize, | ||
MetadataAlign, | ||
Method(<S as T>::method), | ||
TraitVPtr(<S as M2>), | ||
] | ||
--> $DIR/multiple-markers.rs:24:1 | ||
| | ||
LL | trait B: M0 + M1 + T + M2 {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: vtable entries for `<S as C>`: [ | ||
MetadataDropInPlace, | ||
MetadataSize, | ||
MetadataAlign, | ||
Method(<S as T>::method), | ||
TraitVPtr(<S as M1>), | ||
TraitVPtr(<S as M2>), | ||
] | ||
--> $DIR/multiple-markers.rs:27:1 | ||
| | ||
LL | trait C: M0 + T + M1 + M2 {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: vtable entries for `<S as D>`: [ | ||
MetadataDropInPlace, | ||
MetadataSize, | ||
MetadataAlign, | ||
Method(<S as T>::method), | ||
TraitVPtr(<S as M0>), | ||
TraitVPtr(<S as M1>), | ||
TraitVPtr(<S as M2>), | ||
] | ||
--> $DIR/multiple-markers.rs:30:1 | ||
| | ||
LL | trait D: T + M0 + M1 + M2 {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|