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

Clean up codegen_niche_literal #1486

Merged
merged 3 commits into from
Aug 11, 2022
Merged

Conversation

fzaiser
Copy link
Contributor

@fzaiser fzaiser commented Aug 10, 2022

Description of changes:

Clean up codegen_niche_literal: this does not require generating a separate function, similarly to #1457. I believe (and added assertions to that effect) that this code is only called when the whole type is the same size as the discriminant type and the offset of the discriminant is 0. Hence we can simply transmute the given scalar to the result type.

Resolved issues:

Resolves #1485

Call-outs

This adds a byte extract instruction. I vaguely remember CBMC struggling with this sometimes. But it seems better than casting to a pointer, adding an offset and dereferencing, which is what we used to do.

Testing:

  • How is this change tested? Existing regression tests

  • Is this a refactor change? yes

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@fzaiser fzaiser requested a review from a team as a code owner August 10, 2022 19:57
Copy link
Contributor

@danielsn danielsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup

FieldsShape::Arbitrary { offsets, .. } => offsets[0],
_ => unreachable!("niche encoding must have arbitrary fields"),
};
let niche_offset = layout.fields.offset(*tag_field);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice instead of hardcoding zero

@danielsn danielsn merged commit de71c09 into model-checking:main Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup codegen_niche_literal
2 participants