-
Notifications
You must be signed in to change notification settings - Fork 13.7k
When determining if a trait has no entries for the purposes of omitting vptrs from subtrait vtables, consider its transitive supertraits' entries, instead of just its own entries. #145807
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
base: master
Are you sure you want to change the base?
Conversation
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Only consider auto traits empty for the purposes of omitting vptrs from subtrait vtables.
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (b128140): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 6.0%, secondary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 468.54s -> 466.319s (-0.47%) |
@@ -153,16 +153,26 @@ fn prepare_vtable_segments_inner<'tcx, T>( | |||
|
|||
// emit innermost item, move to next sibling and stop there if possible, otherwise jump to outer level. | |||
while let Some((inner_most_trait_ref, emit_vptr, mut siblings)) = stack.pop() { | |||
let has_entries = has_own_existential_vtable_entries(tcx, inner_most_trait_ref.def_id); |
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.
If you would like to look at if any of the supertraits (including the trait itself) has entries, you can do something like:
let has_entries = elaborate::supertrait_def_ids(tcx, inner_most_trait_ref.def_id).any(|def_id| has_own_existential_vtable_entries(tcx, def_id));
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.
Nice! This is a much better solution
…om subtrait vtables
bae9ed3
to
904e83c
Compare
When determining if a non-first supertrait vptr can be omitted from a subtrait vtable, check if the supertrait or any of its (transitive) supertraits have methods, instead of only checking if the supertrait itself has methods.
This fixes the soundness issue where a vptr would be omitted for a supertrait with no methods but that itself had a supertrait with methods, while still optimizing the case where the supertrait is "truly" empty (it has no own vtable entries, and none of its (transitive) supertraits have any own vtable entries).
Fixes #145752
Old description:
Treat all non-auto traits as non-empty (possibly having methods) for purposes of determining if we need to emit a vptr for a non-direct supertrait (and for new "sibling" entries after a direct or non-direct supertrait).This fixes (I believe) the soundness issue,
but regresses vtable sizes and possibly upcasting perf in some cases when using trait hierarchies with empty non-auto traits (seetests/ui/traits/vtable/multiple-markers.stderr
) since we use vptrs in some cases where we could re-use the vtable.Fixes #145752
Re-opens (not anymore) #114942
Should not affect #131813 (i.e. the soundness issue is still fixed,
though the relevant vtables in the)trait Evil
example will be larger nowcc implementation history #131864 #113856
It should be possible to check if a trait has any methods from itself or supertraits (instead of just from itself), but to fix the immediate soundness issue, just assume any non-auto trait could have methods. A more optimistic check can be implemented later (or if someone does it soon it could just supercede this PR 😄).Done in latest push@rustbot label A-dyn-trait F-trait_upcasting