-
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
Add an (perma-)unstable option to disable vtable vptr #114974
Conversation
This flag is intended for evaluation of trait upcasting space cost for embedded use cases.
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
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.
What happens when you try to do upcasting and you have -Zno-trait-vptr
enabled?
@@ -152,7 +152,7 @@ fn prepare_vtable_segments_inner<'tcx, T>( | |||
while let Some((inner_most_trait_ref, emit_vptr, mut siblings)) = stack.pop() { | |||
segment_visitor(VtblSegment::TraitOwnEntries { | |||
trait_ref: inner_most_trait_ref, | |||
emit_vptr, | |||
emit_vptr: emit_vptr && !tcx.sess.opts.unstable_opts.no_trait_vptr, | |||
})?; | |||
|
|||
// If we've emitted (fed to `segment_visitor`) a trait that has methods present in the vtable, |
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.
Maybe move the &&
down here? And it could use a comment.
It'll be UB if you upcast to any supertrait that's not the first. |
@bors r+ rollup |
…llaumeGomez Rollup of 3 pull requests Successful merges: - rust-lang#114974 (Add an (perma-)unstable option to disable vtable vptr) - rust-lang#115261 (replace outdated github username 'ozkanonur') - rust-lang#115266 (Unify CSS color formats a bit more) r? `@ghost` `@rustbot` modify labels: rollup
This flag is intended for evaluation of trait upcasting space cost for embedded use cases.
Compared to the approach in #112355, this option provides a way to evaluate end-to-end cost of trait upcasting. Rationale: #112355 (comment)
How this flag should be used (after merge)
Build your project with and without
-Zno-trait-vptr
flag. If you are using cargo, setRUSTFLAGS="-Zno-trait-vptr"
in the environment variable. You probably also want to use-Zbuild-std
or the binary built may be broken. Save both binaries somewhere.Evaluate the space cost
The option has a direct and indirect impact on vtable space usage. Directly, it gets rid of the trait vptr entry needed to store a pointer to a vtable of a supertrait. (IMO) this is a small saving usually. The larger saving usually comes with the indirect saving by eliminating the vtable of the supertrait (and its parent).
Both impacts only affects vtables (notably the number of functions monomorphized should not change, however where vtable reside can depend on your relocation model. If the relocation model is static, then vtable is rodata (usually stored in Flash/ROM together with text in embedded scenario). If the binary is relocatable, however, the vtable will live in
.data
(more specifically,.data.rel.ro
), and this will need to reside in RAM (which may be a more scarce resource in some cases), together with dynamic relocation info living in readonly segment.For evaluation, you should run
size
on both binaries, with and without the flag.size
would output three columns,text
,data
,bss
and the sumdec
(and it's hex version). As explained above, bothtext
anddata
may change.bss
shouldn't usually change. It'll be useful to see: