-
Notifications
You must be signed in to change notification settings - Fork 59
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
update the docs for layout guarantees of option-like enums #538
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Restricting the definition of an option-like enum based on the type of the single field is quite strange to me. Because I'd think that excludes
Option<T>
from the definition, becauseT
could beusize
or any type without guaranteed discriminant elision.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.
Option<usize>
is indeed excluded.Option<NonZeroUsize>
is included.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.
@saethlin does this answer your question? I don't think I quite understood the comment, TBH.
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.
Whoops, I didn't notice you'd responded.
The text here is just confusing to me, because what I'm imagining is a reader saying "Is this an option-like enum?":
Because by the text above,
Thing<T>
is not "an option-like enum" because its single field does not guarantee discriminant elision. This would be though:...but directly below this the reference already says that
Option<T>
is an example of an option-like enum.🤷
I think you're making an assumption that the reader will interpret words a bit differently when a generic parameter is included. If other can confirm that they have read this and don't find the wording confusing I'm happy to be overruled.
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.
For this reason, in my type-layout docs PR, I chose to separate the idea of "Is an enum for which discriminant elision may apply" (in my text, called a discriminant elision elible) and "A field of this type is subject to discriminant elision" (called elision candidate type). When the two are combined is when the result is guaranteed.
I also note explicitly that the determiniation is post-mono. and explicitly call out both
Option<T>
andResult<T,E>
.So the first
Thing<T>
would be a discriminant elision eligible enum, and its elision candidate field is of typeT
. if we then substitute inT=NonZeroUsize
, the layout guarantees would apply, but substituing inT=usize
, and it would not.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.
I am implicitly assuming that we are talking about a fully monomorphic type here. It doesn't make sense to ask about the layout of a generic type. I can make that more explicit (though this may come at the cost of readability). I don't see how splitting this concept into two separate concepts is helpful.