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

Tracking Issue for rustdoc show-type-layout #113248

Open
1 of 6 tasks
tgross35 opened this issue Jul 1, 2023 · 4 comments
Open
1 of 6 tasks

Tracking Issue for rustdoc show-type-layout #113248

tgross35 opened this issue Jul 1, 2023 · 4 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@tgross35
Copy link
Contributor

tgross35 commented Jul 1, 2023

This is a tracking issue for the rustdoc show-type-layout/show_type_layout feature. This displays the layout layout (size & alignment) of types in the documentation.

This feature was formerly known as document_type_layout

Usage is described at rustdoc unstable features

Zulip thread for discussion: https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/Rustdoc.20.60show-type-layout.60.20feature

Steps

Unresolved Questions

Implementation history

@rustbot label +T-rustdoc

@tgross35 tgross35 added the C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC label Jul 1, 2023
@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jul 1, 2023
@jyn514
Copy link
Member

jyn514 commented Jul 1, 2023

How does this interact with https://doc.rust-lang.org/rustdoc/advanced-features.html#interactions-between-platform-specific-docs? Won't it cause errors or ICEs if you use it on a crate that compiles with rustdoc but not rustc, because you need to run typeck to determine layout?

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jul 2, 2023
Document tracking issue for rustdoc `show-type-layout`

Tracking issue: rust-lang#113248

`@rustbot` label +T-rustdoc +A-docs
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 2, 2023
Document tracking issue for rustdoc `show-type-layout`

Tracking issue: rust-lang#113248

``@rustbot`` label +T-rustdoc +A-docs
@dev-ardi
Copy link
Contributor

For generics I'd say something along the lines of

  • 1024 bytes + size_of::<T> if it contains a normal T
  • 1024 bytes + size_of::<T> * 2 if it contains two T
  • 1024 bytes if T is phantom

Since this is probably not something that you want in all types what about opting in?

#[doc_layout("x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu")]
struct MyStruct {...}

Which gets deduplicated if it happens to be the same?

@jyn514
Copy link
Member

jyn514 commented Jul 29, 2024

i don't think it's true that the layout is some fixed offset like that. if you think about e.g. Option<fn()>, it has a completely different layout than Option<usize> because it doesn't need to store the discriminant.

@dev-ardi
Copy link
Contributor

dev-ardi commented Jul 30, 2024

Heh, that's fair.
What about keeping it simple? It can always be refined later.

#[doc_layout] // Defaults to target that is building it
struct S<T> {
  a: usize,
  b: T,
  c: Option<T>,
  d: SomePrivateStruct<T>,
  e: PhantomData<T>,
  f: SomeOtherZST<T>,
  g: [T; 10],
}

8 bytes + size_of::<T> + size_of::<Option<T> + size_of::<SomePrivateStruct<T>> + size_of::<[T; 10]>

I think that if we make it opt in it's not bad to leak the private structs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants