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

simplify extractbits_exprt representation #8246

Merged
merged 1 commit into from
May 6, 2024
Merged

Conversation

kroening
Copy link
Member

@kroening kroening commented Mar 19, 2024

The current representation of extractbits_exprt stores both the upper and lower indices of the range that is to be extracted, and their difference plus one in form of the width of the type of the expression.

This removes the upper index, as it can be deduced from the lower index and the width of the result. The key benefit is reducing burden on the user of the class, who a) doesn't have to remember which index comes first, and b) doesn't have to do the calculation of the upper index.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@kroening kroening force-pushed the extractbits-width branch 3 times, most recently from 2f964a7 to 71827f4 Compare March 19, 2024 22:43
The current representation of extractbits_exprt stores both the upper and
lower indices of the range that is to be extracted, and their difference
plus one in form of the width of the type of the expression.

This removes the upper index, as it can be deduced from the lower index and
the width of the result.  The key benefit is reducing burden on the user of
the class, who a) doesn't have to remember which index comes first, and b)
doesn't have to do the calculation of the upper index.
@kroening kroening force-pushed the extractbits-width branch from 71827f4 to 97cb8a3 Compare March 19, 2024 23:17
Copy link

codecov bot commented Mar 19, 2024

Codecov Report

Attention: Patch coverage is 91.75258% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 79.64%. Comparing base (baaccb6) to head (97cb8a3).

Files Patch % Lines
src/solvers/floatbv/float_bv.cpp 78.57% 3 Missing ⚠️
src/util/lower_byte_operators.cpp 62.50% 3 Missing ⚠️
src/ansi-c/expr2c.cpp 85.71% 1 Missing ⚠️
src/util/simplify_expr_int.cpp 94.44% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8246   +/-   ##
========================================
  Coverage    79.64%   79.64%           
========================================
  Files         1684     1684           
  Lines       195661   195622   -39     
========================================
- Hits        155837   155809   -28     
+ Misses       39824    39813   -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tautschnig tautschnig added the Version 6 Pull requests and issues requiring a major version bump label Mar 20, 2024
@tautschnig
Copy link
Collaborator

Labelling "Version 6" as we need to get this merged before the release (or otherwise alongside a goto-program-version-bump) for it would result in incompatibility with previously compiled goto binaries.

@kroening
Copy link
Member Author

Labelling "Version 6" as we need to get this merged before the release (or otherwise alongside a goto-program-version-bump) for it would result in incompatibility with previously compiled goto binaries.

I don't think we have a way to get this expression into a goto program.

@peterschrammel peterschrammel removed their assignment May 1, 2024
Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

That does simplify things doesn't it?

dest += convert_with_precedence(upper, precedence);
}
else
dest += "?";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this result in syntactically invalid C being generated? If so, is that a problem and would it be better to throw some kind of error or have an invariant?

Copy link
Member Author

Choose a reason for hiding this comment

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

The expr2X functions are designed to generate some string when given an unknown expression -- this should be added to the documentation.

DATA_INVARIANT(
lower_as_int <= upper_as_int,
"upper bound must be greater or equal to lower bound");

Copy link
Collaborator

Choose a reason for hiding this comment

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

Removing invariants because that case is simply not possible seems like a good thing.

@martin-cs martin-cs removed their assignment May 5, 2024
@kroening kroening merged commit 4f5b402 into develop May 6, 2024
40 checks passed
@kroening kroening deleted the extractbits-width branch May 6, 2024 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Version 6 Pull requests and issues requiring a major version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants