Skip to content
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

Merged
merged 1 commit into from Aug 27, 2023

Conversation

nbdd0121
Copy link
Contributor

@nbdd0121 nbdd0121 commented Aug 18, 2023

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, set RUSTFLAGS="-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 sum dec (and it's hex version). As explained above, both text and data may change. bss shouldn't usually change. It'll be useful to see:

  • Percentage change in text + data (indicating required flash/ROM size)
  • Percentage change in data + bss (indicating required RAM size)

This flag is intended for evaluation of trait upcasting
space cost for embedded use cases.
@rustbot
Copy link
Collaborator

rustbot commented Aug 18, 2023

r? @b-naber

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 18, 2023
Copy link
Member

@compiler-errors compiler-errors left a 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,
Copy link
Member

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.

@nbdd0121
Copy link
Contributor Author

nbdd0121 commented Aug 22, 2023

What happens when you try to do upcasting and you have -Zno-trait-vptr enabled?

It'll be UB if you upcast to any supertrait that's not the first.

@b-naber
Copy link
Contributor

b-naber commented Aug 27, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 27, 2023

📌 Commit a7633b8 has been approved by b-naber

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 27, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 27, 2023
…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
@bors bors merged commit 8dfbc76 into rust-lang:master Aug 27, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Aug 27, 2023
@nbdd0121 nbdd0121 deleted the vtable branch December 31, 2023 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants