-
Notifications
You must be signed in to change notification settings - Fork 116
Fix how we handle niche optimization with ZST #1205
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
Conversation
The compiler uses niche optimization when there is only one variant that contains nonzero sized fields. This variant is represented as the dataful variant. However, other variants may have one or more ZST fields that can be deconstructed and referenced in the code. Before this change, we were not generating code for them and it generate type mismatch issues when the user tried to access them. This change ensures that we represent all variants that have any field, so their access is valid.
We should probably turn this into an assert and revert the logic added by model-checking#1057. But this is a much larger change that I prefer creating a separate PR for.
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.
Nice to finally get rid of this warning! Thanks!
subst, | ||
variants, | ||
initial_offset, | ||
ctx.ensure_union( |
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.
Can you add a comment that explains what this is doing?
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.
Sure!
.iter_enumerated() | ||
.filter_map(|(i, case)| { | ||
if case.fields.is_empty() { | ||
// Skip variant types that cannot be referenced. |
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.
Nice!
This PR rules. Just wanted to say that. Nice! |
Description of changes:
The compiler uses niche optimization when there is only one variant that contains nonzero sized fields. This variant is represented as the dataful variant. However, other variants may have one or more ZST fields that can be deconstructed and referenced in the code.
Before this change, we were not generating code for them and it generates type mismatch issues when the user tried to access them. In the testcase I added, it also uncovered an issue that would crash the compiler when the names of the fields of the ZST variant did not match the dataful one.
This change ensures that we represent all variants that have any field, so their access is valid.
Resolved issues:
Resolves #95.
Resolves #277.
Resolves #729
Call-outs:
I enable a
debug_assert
inside projection mismatch for now. I am planning to turn this into an assert and revert the logic added by #1057. But this is a much larger change that I prefer creating a separate PR for.Testing:
How is this change tested? New test + fixme test.
Is this a refactor change? Nope
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.