-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
tag/niche terminology cleanup #72497
Conversation
Cc @rust-lang/compiler |
Previous relevant issue: #49938. I think the problem here arose from trying to unify the "tagged" and "niche-filling" representations. When we needed a word to refer to "tag or niche" we ended up with "discr(iminant)" again in some places (despite referring to the encoding of the discriminant, and not the discriminant itself), but we should've called both of them "tag" and be done with it. |
10d7af2
to
2fa9161
Compare
RegularTag { tag_field: Field, tag_type_metadata: &'ll DIType }, | ||
OptimizedTag, |
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.
Does this correspond to Direct
and Niche
encodings? If yes, would it make sense to align terminology here?
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 suspected it might mean something like univariant but I think you're right. Also, instead of NoTag
, maybe we could use Option
around EnumTagInfo
.
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.
If we are not sure, maybe I'll just leave this as-is for now and hope someone else documents it eventually.^^
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.
OptimizedTag
only refers to Niche
encodings. Direct
encodings can be RegularTag
or NoTag
depending on whether enum fallback is happening or not. Univariant enums or structs are always NoTag
.
I do like the idea of using Option<EnumTagInfo>
and eliminating the NoTag
variant.
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.
r=oli-obk,eddyb with this addressed or a fixme left with instructions on what should be done
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.
Direct encodings can be RegularTag or NoTag depending on whether enum fallback is happening or not. Univariant enums or structs are always NoTag.
What is "enum fallback"? If it's "no tag needed because there is just one variant", AFAIK those do not have a TagEncoding
at all, they are Variant::Single
.
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.
@oli-obk I added a FIXME, could you check if that comment makes any sense?
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.
What is "enum fallback"?
It's a windows thing, because windows debuginfo isn't caught up yet
☔ The latest upstream changes (presumably #72768) made this pull request unmergeable. Please resolve the merge conflicts. |
I think this terminology is fine but we should document it in the rustc-dev-guide |
Where in the guide would this fit best? |
@RalfJung maybe folks from @rust-lang/wg-rustc-dev-guide have thoughts, but the glossary might work :) |
I feel like we should (ultimately) have a |
A layout section would be awesome, but if that's not feasible, it would be great to update/add the relevant definitions to the glossary. |
If this is accepted, I am happy to write a paragraph or two about it somewhere, if I am told where. :) The glossary makes sense. But writing an entire chapter on "layout" is a bit too much. |
Would it make sense to add a section to one of the "codegen" chapters? |
So, what is this blocked on? As far as I am concerned, I am waiting for this to be accepted before I put in the work of writing docs. |
My impression was that we were happy with this terminology choice. So the PR just needs review. |
Unnominating this as it was already discussed in our last |
I opened a dev-guide PR: rust-lang/rustc-dev-guide#747 |
r? @oli-obk |
assert_eq!(tag_layout.size, tag_val.layout.size); | ||
assert_eq!(tag_layout.abi.is_signed(), tag_val.layout.abi.is_signed()); | ||
let tag_val = tag_val.to_scalar()?; | ||
trace!("tag value: {:?}", tag_val); | ||
|
||
// Figure out which discriminant and variant this corresponds to. | ||
Ok(match *tag_kind { | ||
DiscriminantKind::Tag => { | ||
Ok(match *tag_encoding { |
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 really wish we could deduplicate this with the codegen_ssa logic. Maybe we need a codegen_miri in addition to codegen_llvm. That backend could then interpret the values immediately instead of generating code. Not sure if that can be pulled off..
Anyway, off topic for this PR
@bors r+ |
📌 Commit 10c8d2a has been approved by |
tag/niche terminology cleanup The term "discriminant" was used in two ways throughout the compiler: * every enum variant has a corresponding discriminant, that can be given explicitly with `Variant = N`. * that discriminant is then encoded in memory to store which variant is active -- but this encoded form of the discriminant was also often called "discriminant", even though it is conceptually quite different (e.g., it can be smaller in size, or even use niche-filling). After discussion with @eddyb, this renames the second term to "tag". The way the tag is encoded can be either `TagEncoding::Direct` (formerly `DiscriminantKind::Tag`) or `TagEncoding::Niche` (formerly `DiscrimianntKind::Niche`). This finally resolves some long-standing confusion I had about the handling of variant indices and discriminants, which surfaced in rust-lang#72419. (There is also a `DiscriminantKind` type in libcore, it remains unaffected. I think this corresponds to the discriminant, not the tag, so that seems all right.) r? @eddyb
tag/niche terminology cleanup The term "discriminant" was used in two ways throughout the compiler: * every enum variant has a corresponding discriminant, that can be given explicitly with `Variant = N`. * that discriminant is then encoded in memory to store which variant is active -- but this encoded form of the discriminant was also often called "discriminant", even though it is conceptually quite different (e.g., it can be smaller in size, or even use niche-filling). After discussion with @eddyb, this renames the second term to "tag". The way the tag is encoded can be either `TagEncoding::Direct` (formerly `DiscriminantKind::Tag`) or `TagEncoding::Niche` (formerly `DiscrimianntKind::Niche`). This finally resolves some long-standing confusion I had about the handling of variant indices and discriminants, which surfaced in rust-lang#72419. (There is also a `DiscriminantKind` type in libcore, it remains unaffected. I think this corresponds to the discriminant, not the tag, so that seems all right.) r? @eddyb
tag/niche terminology cleanup The term "discriminant" was used in two ways throughout the compiler: * every enum variant has a corresponding discriminant, that can be given explicitly with `Variant = N`. * that discriminant is then encoded in memory to store which variant is active -- but this encoded form of the discriminant was also often called "discriminant", even though it is conceptually quite different (e.g., it can be smaller in size, or even use niche-filling). After discussion with @eddyb, this renames the second term to "tag". The way the tag is encoded can be either `TagEncoding::Direct` (formerly `DiscriminantKind::Tag`) or `TagEncoding::Niche` (formerly `DiscrimianntKind::Niche`). This finally resolves some long-standing confusion I had about the handling of variant indices and discriminants, which surfaced in rust-lang#72419. (There is also a `DiscriminantKind` type in libcore, it remains unaffected. I think this corresponds to the discriminant, not the tag, so that seems all right.) r? @eddyb
Rollup of 13 pull requests Successful merges: - rust-lang#70740 (Enabling static-pie for musl) - rust-lang#72331 (Report error when casting an C-like enum implementing Drop) - rust-lang#72486 (Fix asinh of negative values) - rust-lang#72497 (tag/niche terminology cleanup) - rust-lang#72999 (Create self-contained directory and move there some of external binaries/libs) - rust-lang#73130 (Remove const prop for indirects) - rust-lang#73142 (Ensure std benchmarks get tested.) - rust-lang#73305 (Disallow loading crates with non-ascii identifier name.) - rust-lang#73346 (Add rust specific features to print target features) - rust-lang#73362 (Test that bounds checks are elided when slice len is checked up-front) - rust-lang#73459 (Reduce pointer casts in Box::into_boxed_slice) - rust-lang#73464 (Document format correction) - rust-lang#73479 (Minor tweaks to liballoc) Failed merges: r? @ghost
The term "discriminant" was used in two ways throughout the compiler:
Variant = N
.After discussion with @eddyb, this renames the second term to "tag". The way the tag is encoded can be either
TagEncoding::Direct
(formerlyDiscriminantKind::Tag
) orTagEncoding::Niche
(formerlyDiscrimianntKind::Niche
).This finally resolves some long-standing confusion I had about the handling of variant indices and discriminants, which surfaced in #72419.
(There is also a
DiscriminantKind
type in libcore, it remains unaffected. I think this corresponds to the discriminant, not the tag, so that seems all right.)r? @eddyb