-
Notifications
You must be signed in to change notification settings - Fork 277
Byte extract lowering: support extracting non-byte-aligned arrays #6488
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: develop
Are you sure you want to change the base?
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #6488 +/- ##
========================================
Coverage 79.00% 79.01%
========================================
Files 1697 1697
Lines 195369 195442 +73
========================================
+ Hits 154350 154421 +71
- Misses 41019 41021 +2
☔ View full report in Codecov by Sentry. |
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 see why this is needed and why it is useful and I cannot see anything wrong with it. However, this kind of code is very prone to "off by one" type errors and is a nightmare to diagnose and fix. So... please can we have a high degree of test coverage? I realise you probably can't measure that until #6486 is merged but when you can, some test cases, maybe a union
of an array of bits and a struct
of some kind?
{ | ||
if(!num_elements.has_value()) | ||
{ | ||
// turn bytes into elements, rounding up | ||
num_elements = (*max_bytes + el_bytes - 1) / el_bytes; | ||
num_elements = (*max_bytes * 8 + element_bits - 1) / element_bits; |
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 vaguely recall some hero going around and replacing all of the (appropriate) instances of 8
with CHAR_BITS
. Should we call on him again?
…-vector Byte extract lowering: refactor lowering of arrays/vectors [blocks: #6488]
b267346
to
e1b0490
Compare
627c2c7
to
9c5b246
Compare
I am reluctant to add more functionality to byte_extract/byte_update, given that these are already the most complicated expressions we have (maybe floating-point stuff can compete). Would it make sense to separate the aspect of "extract some bytes from byte-aligned memory" from "map some non-byte-aligned encoding to a byte-aligned memory layout"? This might also help with the fat pointers. |
I hear you, but I would like to clarify that this PR really only adds functionality to lowering; the propositional back-end will already get this case right (though perhaps has an easier time doing so). It's been a while that I prepared this PR, but I think the reasons it came up were attempts to support more cases of non-det pointers, which just meant that cases that I previously was too lazy to implement were now triggered.
The architecture of the lowering implementation is of such nature, although it might not help that it's all baked into a single file. Any byte-extract or byte-update will first turn the underlying object into a byte array, and will then do all further operations on such a an array of bytes. |
1521a3b
to
36cc2f7
Compare
383258b
to
d42400c
Compare
I am still not convinced of the use-case: there shouldn't be pointers into bit-arrays. |
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.
Isn't this in conflict with #7298?
d42400c
to
41aa047
Compare
Alignment to bytes may be true for ANSI C, but isn't the case for our C front-end (which supports arrays of single bits), and not true for the overall framework in general. This required fixing alignment assumptions both in unpack_array_vector (which turns an arbitrary type into an array of bytes) as well as lower_byte_extract_array_vector (which picks an array/vector of arbitrary subtype from an array of bytes as prepared by unpack_array_vector).
41aa047
to
c8b7465
Compare
Alignment to bytes may be true for ANSI C, but isn't the case for our C front-end (which supports arrays of single bits), and not true for the overall framework in general. This required fixing alignment assumptions both in unpack_array_vector (which turns an arbitrary type into an array of bytes) as well as lower_byte_extract_array_vector (which picks an array/vector of arbitrary subtype from an array of bytes as prepared by unpack_array_vector).
Depends on #6486, which is the first commit in here. Only the second commit is new.