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

Fix two bugs in SAWCore's handing of infinite streams #1773

Merged
merged 2 commits into from
Dec 6, 2022
Merged

Conversation

RyanGlScott
Copy link
Contributor

This fixes two bugs that caused infinite SAWCore streams to misbehave:

saw-core: Fix handling of atWithDefault for infinite bit sequences

When calling atWithDefault n d v i, d should be returned if i is greater than or equal to n. atWithDefault is implemented as a primitive, so we must ensure that this is done in saw-core's atWithDefaultOp function. While atWithDefaultOp was handling this correctly for generic infinite sequences, it was not correctly handling the special case of infinite bit sequences. This led to the issues reported in #1768.

This patch fixes #1768 by introducing a bpBvAtWithDefault combinator that implements the defaulting behavior above in terms of bpBvAt. I've added a test case to demonstrate that the test case from #1768 now works as expected.

saw-core-what4: Build muxes of symbolic indexes in big-endian order

SAWCore assumes the invariant that when indexing into an infinite stream using a symbolic index, the mux tree constructed over the index will test each bit in big-endian order. This is the responsibility of the selectV function found in saw-core, saw-core-sbv, and saw-core-what4. All of these functions save for saw-core-what4's selectV were upholding this invariant, as saw-core-what4's was testing each bit in little-endian order, resulting in the oddities observed in #1703.

This corrects the mistake in saw-core-what4's implementation, fixing #1703. It also leaves some more documentation to make the fact that each selectV should be proceeding in big-endian order more apparent.

Copy link
Contributor

@chameco chameco left a comment

Choose a reason for hiding this comment

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

LGTM

@RyanGlScott RyanGlScott added the PR: ready to merge Magic flag for pull requests to ask Mergify to merge given an approval and a successful CI run label Dec 5, 2022
When calling `atWithDefault n d v i`, `d` should be returned if `i` is greater
than or equal to `n`. `atWithDefault` is implemented as a primitive, so we must
ensure that this is done in `saw-core`'s `atWithDefaultOp` function. While
`atWithDefaultOp` was handling this correctly for generic infinite sequences, it
was _not_ correctly handling the special case of infinite bit sequences. This
led to the issues reported in #1768.

This patch fixes #1768 by introducing a `bpBvAtWithDefault` combinator that
implements the defaulting behavior above in terms of `bpBvAt`. I've added a test
case to demonstrate that the test case from #1768 now works as expected.
SAWCore assumes the invariant that when indexing into an infinite stream using
a symbolic index, the mux tree constructed over the index will test each bit in
big-endian order. This is the responsibility of the `selectV` function found in
`saw-core`, `saw-core-sbv`, and `saw-core-what4`. All of these functions save
for `saw-core-what4`'s `selectV` were upholding this invariant, as
`saw-core-what4`'s was testing each bit in little-endian order, resulting in
the oddities observed in #1703.

This corrects the mistake in `saw-core-what4'`s implementation, fixing #1703.
It also leaves some more documentation to make the fact that each `selectV`
should be proceeding in big-endian order more apparent.
@mergify mergify bot merged commit f9b6194 into master Dec 6, 2022
@mergify mergify bot deleted the T1768 branch December 6, 2022 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: ready to merge Magic flag for pull requests to ask Mergify to merge given an approval and a successful CI run
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SBV error: invalid function declaration reference, unknown function -1 AND w4 error: arithmetic underflow
2 participants