generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 29
Add bitvector types (bv8, bv16, bv32, bv64) to Laurel #701
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
Open
tautschnig
wants to merge
3
commits into
main
Choose a base branch
from
tautschnig/laurel-bv-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
49 changes: 49 additions & 0 deletions
49
StrataTest/Languages/Laurel/Examples/Fundamentals/T19_BitvectorTypes.lean
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
|
|
||
| import StrataTest.Util.TestDiagnostics | ||
| import StrataTest.Languages.Laurel.TestExamples | ||
|
|
||
| open StrataTest.Util | ||
|
|
||
| namespace Strata | ||
| namespace Laurel | ||
|
|
||
| def bvProgram := r" | ||
| // Bitvector types in procedure signatures and variable declarations. | ||
|
|
||
| // Parameters and return types | ||
| procedure identity32(x: bv32) returns (r: bv32) { | ||
| r := x | ||
| }; | ||
|
|
||
| procedure identity8(x: bv8) returns (r: bv8) { | ||
| r := x | ||
| }; | ||
|
|
||
| // Local variable with bv type | ||
| procedure localBv() returns (r: bv16) { | ||
| var x: bv16 := r; | ||
| r := x | ||
| }; | ||
|
|
||
| // Opaque procedure returning bv64 — caller gets typed result | ||
| procedure opaqueBv64() returns (r: bv64); | ||
| procedure callOpaque() returns (r: bv64) { | ||
| r := opaqueBv64() | ||
| }; | ||
|
|
||
| // Mixed bv and int parameters | ||
| procedure mixedTypes(a: bv32, b: int) returns (r: int) { | ||
| r := b | ||
| }; | ||
| " | ||
|
|
||
| #guard_msgs(drop info, error) in | ||
| #eval testInputWithOffset "BitvectorTypes" bvProgram 14 processLaurelFile | ||
|
|
||
| end Laurel | ||
| end Strata |
14 changes: 14 additions & 0 deletions
14
StrataTest/Languages/Laurel/tests/test_bitvector_types.lr.st
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Bitvector types through the GOTO/CBMC pipeline. | ||
|
|
||
| procedure identity32(x: bv32) returns (r: bv32) { | ||
| r := x | ||
| }; | ||
|
|
||
| procedure identity8(x: bv8) returns (r: bv8) { | ||
| r := x | ||
| }; | ||
|
|
||
| procedure localBv() returns (r: bv16) { | ||
| var x: bv16 := r; | ||
| r := x | ||
| }; |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Could we abstract over the amount of bits? Also, I think the right default SMT encoding is to use an
intwith constraints, not an SMT bitvector. Until Core supports that, can we really define this with the correct verification behavior in Laurel? Right now I think the front-ends can't use these types because of the default SMT bitvector behavior, so it seems confusing to add them.Also, should we think about this end-to-end? How will users indicate what SMT encoding they want to use for particular variables? Can we infer the probably best encoding based on which operators the variables are applied to? My guess would be that a good heuristic is that if no bit specific operators are used, use an int and otherwise a bv.
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.
In principle we could, but then Core has hard-coded bit widths only (I don't know why). So it would require a change in Core first.
Why do you believe this to be the case?
I have a changed queued up to add transforms between constrained types and bitvectors, but then it only makes sense to add that if we have tests (#656) and language support (this PR) in the first place.
I'd love to conduct all these experiments, but it seems impossible to do them when we don't have the necessary infrastructure in place first.