-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ghost values in all language backends
This patch: * Factors out the machinery needed to track ghost state into into the `SAWScript.Crucible.Common.Override` and `SAWScript.Builtins` modules. Nothing about ghost state is specific to any language backend, so it deserves to live in a non-LLVM–specific location. * Adds `jvm_ghost_value` and `mir_ghost_value` commands, which behave exactly like the LLVM backend's `llvm_ghost_value` command does, but for the JVM and MIR backends, respectively. * Adds a `test_mir_ghost` test case in SAWScript and the remote API to ensure that everything works as expected. Fixes #1929.
- Loading branch information
1 parent
3ad4957
commit 4232a42
Showing
34 changed files
with
467 additions
and
351 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
Binary file not shown.
This file contains 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,13 @@ | ||
all: test.linked-mir.json | ||
|
||
test.linked-mir.json: test.rs | ||
saw-rustc $< | ||
$(MAKE) remove-unused-build-artifacts | ||
|
||
.PHONY: remove-unused-build-artifacts | ||
remove-unused-build-artifacts: | ||
rm -f test libtest.mir libtest.rlib | ||
|
||
.PHONY: clean | ||
clean: remove-unused-build-artifacts | ||
rm -f test.linked-mir.json |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,9 @@ | ||
pub fn next() -> u32 { | ||
unimplemented!("This should be overridden") | ||
} | ||
|
||
pub fn example() -> u32 { | ||
next(); | ||
next(); | ||
next() | ||
} |
This file contains 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,28 @@ | ||
enable_experimental; | ||
|
||
let next_spec counter = do { | ||
n <- mir_fresh_var "n" mir_u32; | ||
mir_ghost_value counter n; | ||
|
||
mir_execute_func []; | ||
|
||
mir_ghost_value counter {{n+1}}; | ||
mir_return (mir_term {{n}}); | ||
}; | ||
|
||
let example_spec counter = do { | ||
n <- mir_fresh_var "nm" mir_u32; | ||
mir_precond {{n < 2}}; | ||
mir_ghost_value counter n; | ||
|
||
mir_execute_func []; | ||
|
||
mir_ghost_value counter {{n+3}}; | ||
mir_return (mir_term {{n+2}}); | ||
}; | ||
|
||
counter <- declare_ghost_state "ctr"; | ||
m <- mir_load_module "test.linked-mir.json"; | ||
|
||
next <- mir_unsafe_assume_spec m "test::next" (next_spec counter); | ||
mir_verify m "test::example" [next] false (example_spec counter) z3; |
This file contains 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,3 @@ | ||
set -e | ||
|
||
$SAW test.saw |
This file contains 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 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
1 change: 1 addition & 0 deletions
1
saw-remote-api/python/tests/saw/test-files/mir_ghost.linked-mir.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,9 @@ | ||
pub fn next() -> u32 { | ||
unimplemented!("This should be overridden") | ||
} | ||
|
||
pub fn example() -> u32 { | ||
next(); | ||
next(); | ||
next() | ||
} |
This file contains 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,53 @@ | ||
import unittest | ||
from pathlib import Path | ||
|
||
from saw_client import * | ||
from saw_client.crucible import cry_f | ||
from saw_client.mir import Contract, GhostVariable, u32 | ||
|
||
|
||
class NextContract(Contract): | ||
def __init__(self, counter: GhostVariable) -> None: | ||
super().__init__() | ||
self.counter = counter | ||
|
||
def specification(self) -> None: | ||
n = self.fresh_var(u32, 'n') | ||
self.ghost_value(self.counter, n) | ||
|
||
self.execute_func() | ||
|
||
self.ghost_value(self.counter, cry_f('{n} + 1')) | ||
self.returns(n) | ||
|
||
|
||
class ExampleContract(Contract): | ||
def __init__(self, counter: GhostVariable) -> None: | ||
super().__init__() | ||
self.counter = counter | ||
|
||
def specification(self) -> None: | ||
n = self.fresh_var(u32, 'n') | ||
self.precondition_f('{n} < 2') | ||
self.ghost_value(self.counter, n) | ||
|
||
self.execute_func() | ||
self.ghost_value(self.counter, cry_f('{n} + 3')) | ||
self.returns_f('{n} + 2') | ||
|
||
|
||
class MIRGhostTest(unittest.TestCase): | ||
def test_mir_ghost(self): | ||
connect(reset_server=True) | ||
if __name__ == "__main__": view(LogResults()) | ||
json_name = str(Path('tests', 'saw', 'test-files', 'mir_ghost.linked-mir.json')) | ||
mod = mir_load_module(json_name) | ||
|
||
counter = create_ghost_variable('ctr'); | ||
next_ov = mir_assume(mod, 'mir_ghost::next', NextContract(counter)) | ||
example_result = mir_verify(mod, 'mir_ghost::example', ExampleContract(counter), lemmas=[next_ov]) | ||
self.assertIs(example_result.is_success(), True) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains 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 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 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 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.