Fix how we handle niche optimization with ZST#1205
Merged
celinval merged 6 commits intomodel-checking:mainfrom May 20, 2022
Merged
Fix how we handle niche optimization with ZST#1205celinval merged 6 commits intomodel-checking:mainfrom
celinval merged 6 commits intomodel-checking:mainfrom
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.
zhassan-aws
approved these changes
May 20, 2022
Contributor
zhassan-aws
left a comment
There was a problem hiding this comment.
Nice to finally get rid of this warning! Thanks!
| subst, | ||
| variants, | ||
| initial_offset, | ||
| ctx.ensure_union( |
Contributor
There was a problem hiding this comment.
Can you add a comment that explains what this is doing?
| .iter_enumerated() | ||
| .filter_map(|(i, case)| { | ||
| if case.fields.is_empty() { | ||
| // Skip variant types that cannot be referenced. |
Co-authored-by: Zyad Hassan <88045115+zhassan-aws@users.noreply.github.com>
Contributor
|
This PR rules. Just wanted to say that. Nice! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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_assertinside 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.