-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #88552 - nbdd0121:vtable, r=nagisa
Stop allocating vtable entries for non-object-safe methods Current a vtable entry is allocated for all associated fns, even if the method is not object-safe: https://godbolt.org/z/h7vx6f35T As a result, each vtable for `Iterator`' currently consumes 74 `usize`s. This PR stops allocating vtable entries for those methods, reducing vtable size of each `Iterator` vtable to 7 `usize`s. Note that this PR introduces will cause more invocations of `is_vtable_safe_method`. So a perf run might be needed. If result isn't favorable then we might need to query-ify `is_vtable_safe_method`.
- Loading branch information
Showing
8 changed files
with
109 additions
and
42 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,18 @@ | ||
// build-fail | ||
#![feature(rustc_attrs)] | ||
|
||
// Ensure that non-object-safe methods in Iterator does not generate | ||
// vtable entries. | ||
|
||
#[rustc_dump_vtable] | ||
trait A: Iterator {} | ||
//~^ error Vtable | ||
|
||
impl<T> A for T where T: Iterator {} | ||
|
||
fn foo(_a: &mut dyn A<Item=u8>) { | ||
} | ||
|
||
fn main() { | ||
foo(&mut vec![0, 1, 2, 3].into_iter()); | ||
} |
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,16 @@ | ||
error: Vtable entries for `<std::vec::IntoIter<u8> as A>`: [ | ||
MetadataDropInPlace, | ||
MetadataSize, | ||
MetadataAlign, | ||
Method(<std::vec::IntoIter<u8> as Iterator>::next), | ||
Method(<std::vec::IntoIter<u8> as Iterator>::size_hint), | ||
Method(<std::vec::IntoIter<u8> as Iterator>::advance_by), | ||
Method(<std::vec::IntoIter<u8> as Iterator>::nth), | ||
] | ||
--> $DIR/vtable-non-object-safe.rs:8:1 | ||
| | ||
LL | trait A: Iterator {} | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
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