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

"Unreferencable" annotation to improve packing of booleans (and enums) #2159

Closed
eira-fransham opened this issue Sep 20, 2017 · 2 comments
Closed
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@eira-fransham
Copy link

At the moment it's impossible for the compiler to reduce the bits-per-field of a struct containing booleans or small enums to less than 8, since that's the granularity of pointers and the language must assume that any field can have a reference taken to it. I suggest an annotation for structs and enums (and/or fields) that disallows users from referencing fields, forcing them to move out to the stack first. As an extension, this could be done automatically when possible, but sometimes it must be strictly illegal, such as when returning a borrow from a function. This would mean that a 2-variant enum would need a minimum of 1 bit to be represented, and stuff like bitfields could be created as a struct with bool fields, zero-cost.

The name is bikesheddable, since you can reference the value as long as it is stored on the stack (where it would be padded out to 1 byte minimum like usual).

@glaebhoerl
Copy link
Contributor

Related to #311

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the RFC. label Dec 6, 2017
@Centril
Copy link
Contributor

Centril commented Feb 23, 2018

Closing in favor of #311.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

3 participants