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

Layout of uninhabited types #165

Closed
gnzlbg opened this issue Jul 8, 2019 · 4 comments
Closed

Layout of uninhabited types #165

gnzlbg opened this issue Jul 8, 2019 · 4 comments
Labels
A-layout Topic: Related to data structure layout (`#[repr]`) A-uninhabited-types Topic: Related to uninhabited types like ! and exhaustiveness C-open-question Category: An open question that we should revisit

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Jul 8, 2019

We don't define the layout of uninhabited types anywhere.

We probably want to define that ! and enum Void {} have zero size, but as pointed out in #37, (!, i32) is uninhabited but does not have zero-size.

We should probably expand the struct, enum, union, and array sections with a sub-section about when are these types uninhabited, and what their layout is in this case.

@gnzlbg gnzlbg added the A-layout Topic: Related to data structure layout (`#[repr]`) label Jul 8, 2019
@hanna-kruppe
Copy link

We should describe when types are considered uninhabited, but I don't see any reason to special case layout of uninhabited types: there is no general relation between inhabitedness and (mentioning everything that anyone ever proposed as part of layout):

  • size (as you noted)
  • alignment
  • offsets of fields
  • call ABI, necessarily (passing values of uninhabited type is UB, so their call ABI is irrelevant)

So the layout rules should largely be the same for inhabited and uninhabited types. The one possible exception is that perhaps the niche for uninhabited types becomes maximal, but we'd have to be careful there for the same reasons e.g. (!, i32) is not a ZST (the i32 portion can be written and potentially also read).

@RalfJung
Copy link
Member

I think for Rust, "uninhabited" is a particular "call ABI": https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/layout/enum.Abi.html#variant.Uninhabited.

We should describe when types are considered uninhabited

Agreed. We should also define the term precisely, because there are many kinds of "uninhabited" in Rust. Some types have "uninhabited" call ABI, some have no value satisfying the validity invariant, some have no value satisfying the safety invariant.

@RalfJung RalfJung added C-open-question Category: An open question that we should revisit A-uninhabited-types Topic: Related to uninhabited types like ! and exhaustiveness labels Aug 14, 2019
@JakobDegen
Copy link
Contributor

Closing this as broadly decided. Someone could ask T-lang to guarantee a size of zero if that isn't documented yet

@RalfJung
Copy link
Member

RalfJung commented Aug 8, 2023

I'll open a new issue for the sub-question of enums with uninhabited variants.

EDIT: #443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Topic: Related to data structure layout (`#[repr]`) A-uninhabited-types Topic: Related to uninhabited types like ! and exhaustiveness C-open-question Category: An open question that we should revisit
Projects
None yet
Development

No branches or pull requests

4 participants