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

Unify unit variables in heapster #1546

Merged
merged 29 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bf73229
First pass adding code to unify all unit-typed variables in Implicati…
jpaykin Dec 21, 2021
9780c93
Unifying unit variables in TypedCrucible
jpaykin Dec 28, 2021
049cbbb
Merge branch 'master' into heapster/unify-unit-variables
jpaykin Dec 28, 2021
f3aa22f
Adding debugging infrastructure
jpaykin Jan 4, 2022
e812e23
Modifying handleUnitVars to operate on a given list of names
jpaykin Jan 5, 2022
60e7f09
Ensure we dont add an x:eq(x) constraint in handleUnitVar
jpaykin Jan 6, 2022
40015bf
Handling unit-typed existential variables
jpaykin Jan 6, 2022
186d12f
Unifying unit-typed existential variables
jpaykin Jan 8, 2022
cfe2c62
Adding debugging/trace info
jpaykin Jan 12, 2022
203cec4
Modified recombinePerm to drop extraneous permissions x:eq(())
jpaykin Jan 13, 2022
89c15fc
Additional debugging infrastructure
jpaykin Jan 14, 2022
9dea2c1
Attempt to fix bug by moving an instance of recombinePerm back to imp…
jpaykin Jan 18, 2022
01bdf35
changed some recombinePerms back to implPopM to fix a bug in implCast…
Jan 19, 2022
54b7b08
changed how proveVarsImplVarEVars casts its output permissions to han…
Jan 19, 2022
9da9680
removed debug tracing from the iter_linked_list.saw example
Jan 19, 2022
8605772
fixed up the mbox_len_spec_ref proof to handle recent Heapster changes
Jan 19, 2022
c0e20f4
Merge branch 'master' into heapster/unify-unit-variables
jpaykin Jan 21, 2022
42c940c
Added new test case for unit-typed environment permissions; still WIP
jpaykin Jan 22, 2022
68be84f
Updating new test case for global variables using unit-typed permissions
jpaykin Jan 28, 2022
9a45a83
Merge branch 'master' into heapster/unify-unit-variables
jpaykin Jan 28, 2022
803f515
Updated comments in global_var example
jpaykin Jan 28, 2022
3636890
Clean up pass
jpaykin Jan 28, 2022
955078a
Merge branch 'heapster/unify-unit-variables' of github.com:GaloisInc/…
jpaykin Jan 28, 2022
ab2122f
Cleaning up code
jpaykin Jan 28, 2022
8fd8409
Fixed bug in neeedVars function
jpaykin Jan 28, 2022
7070117
Removed excess debugging statements
jpaykin Jan 28, 2022
049b730
Fixed bug in change to neededVars for named permissions
jpaykin Jan 28, 2022
0c525b3
Updating FIXME comment in Permissions.hs
jpaykin Jan 28, 2022
99e5932
Fixed whitespace typo
jpaykin Jan 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions heapster-saw/examples/_CoqProject
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ exp_explosion_gen.v
exp_explosion_proofs.v
mbox_gen.v
mbox_proofs.v
global_var_gen.v
global_var_proofs.v
sha512_gen.v
#sha512_proofs.v
Binary file added heapster-saw/examples/global_var.bc
Binary file not shown.
56 changes: 56 additions & 0 deletions heapster-saw/examples/global_var.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <stdlib.h>
#include <stdint.h>

/* A very simple acquire/release lock for some shared data */

int64_t shared_data = 0;
int64_t lock = 0;

/* A spin lock; returns 1 after acquireing lock, otherwise runs forever.
(Not robust to concurrent semantics) */
int64_t acquire_lock(int64_t** data) {
while (lock != 0) {
continue;
}
lock = 1;
*data = &shared_data;
return 1;
}

/* To be called after a thread is done accessing the shared data. */
void release_lock(void) {
lock = 0;
return;
}


int64_t acquire_release_acquire_release(void) {

int64_t* data;
acquire_lock(&data);
*data = 42;
release_lock();

acquire_lock(&data);
if (data == NULL) {
return -1;
}
int64_t val = *data;
release_lock();
return val;
}

int64_t acquire_release_fail(void) {
int64_t* data;
acquire_lock(&data);
*data = 42;
release_lock();

*data = 84;

// shared data should still be 42
acquire_lock(&data);
int64_t val = *data;
release_lock();
return val;
}
73 changes: 73 additions & 0 deletions heapster-saw/examples/global_var.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
enable_experimental;
env <- heapster_init_env_from_file "global_var.sawcore" "global_var.bc";

// Integer types
heapster_define_perm env "int64" " " "llvmptr 64" "exists x:bv 64.eq(llvmword(x))";


// Demonstrates one technique for dealing with global variables and environment
// permissions like locks



// A heapster type for the lock global variable"
//
// The rwmodality makes the permission not copyable when provided the write
// modality.
//
// When extracted to Coq, u:has_lock_perm<W> and u:can_lock_perm<W> are
// bitvectors representing the value stored in the shared_data variable
heapster_define_opaque_perm env "has_lock_perm"
"rw:rwmodality, dat:llvmptr 64"
"unit"
"Vec 64 Bool";

heapster_define_opaque_perm env "can_lock_perm"
"rw:rwmodality"
"unit"
"Vec 64 Bool";

// Need to axiomatize acquire_lock because it touches the global variables
heapster_assume_fun env
"acquire_lock"

"(u:unit). \
\ arg0:ptr((W,0) |-> true), \
\ u:can_lock_perm<W> \
\ -o \
\ (dat:llvmptr 64). \
\ ret:eq(llvmword(1)), \
\ arg0:ptr((W,0) |-> eq(dat)), \
\ dat:ptr((W,0) |-> int64<>), \
\ u:has_lock_perm<W,dat>"

"acquireLockM";

heapster_assume_fun env
"release_lock"

"(u:unit, dat:llvmptr 64). \
\ u:has_lock_perm<W,dat>, \
\ dat:ptr((W,0) |-> int64<>) \
\ -o \
\ ret:true, \
\ u:can_lock_perm<W>"

"releaseLockM";



heapster_typecheck_fun env
"acquire_release_acquire_release"
"(u:unit). u:can_lock_perm<W> \
\ -o \
\ ret:int64<>, u:can_lock_perm<W>";

heapster_typecheck_fun env
"acquire_release_fail"
"(u:unit). u:can_lock_perm<W> \
\ -o \
\ ret:int64<>, u:can_lock_perm<W>";


heapster_export_coq env "global_var_gen.v";
10 changes: 10 additions & 0 deletions heapster-saw/examples/global_var.sawcore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module GlobalVar where

import Prelude;

acquireLockM : Vec 64 Bool -> CompM (Vec 64 Bool * Vec 64 Bool);
acquireLockM u = returnM (Vec 64 Bool * Vec 64 Bool)
(u,u);

releaseLockM : Vec 64 Bool -> Vec 64 Bool -> CompM (Vec 64 Bool);
releaseLockM u new_u = returnM (Vec 64 Bool) new_u;
56 changes: 56 additions & 0 deletions heapster-saw/examples/global_var_proofs.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
From Coq Require Import Lists.List.
From Coq Require Import String.
From Coq Require Import Vectors.Vector.
From CryptolToCoq Require Import SAWCoreScaffolding.
From CryptolToCoq Require Import SAWCoreVectorsAsCoqVectors.
From CryptolToCoq Require Import SAWCoreBitvectors.
From CryptolToCoq Require Import SAWCorePrelude.
From CryptolToCoq Require Import CompMExtra.



Require Import Examples.global_var_gen.
Import GlobalVar.

Import SAWCorePrelude.

Lemma no_errors_acquire_release_acquire_release :
refinesFun acquire_release_acquire_release (fun _ => noErrorsSpec).
Proof.
unfold acquire_release_acquire_release,
acquire_release_acquire_release__tuple_fun,
noErrorsSpec,
acquireLockM, releaseLockM.
prove_refinement.
Qed.


Definition acquire_release_acquire_release_spec (x : bitvector 64)
: CompM (can_lock_perm * bitvector 64) :=
returnM (intToBv 64 42, intToBv 64 42).

Lemma spec_acquire_release_acquire_release :
refinesFun acquire_release_acquire_release
acquire_release_acquire_release_spec.
Proof.
unfold acquire_release_acquire_release,
acquire_release_acquire_release__tuple_fun,
acquire_release_acquire_release_spec,
acquireLockM, releaseLockM,
projT2.
prove_refinement.
Qed.


Definition errorSpec {A} : CompM A := existsM (fun (s : string) => errorM s).

Lemma errors_acquire_release_fail : refinesFun acquire_release_fail
(fun _ => errorSpec).
Proof.
unfold acquire_release_fail, acquire_release_fail__tuple_fun,
errorSpec,
acquireLockM, releaseLockM,
projT2.
prove_refinement.
Qed.

5 changes: 3 additions & 2 deletions heapster-saw/examples/mbox_proofs.v
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ Proof.
(* Most of the remaining cases are taken care of with just bvAdd_id_l and bvAdd_id_r *)
all: try rewrite bvAdd_id_r; try rewrite bvAdd_id_l; try reflexivity.
(* The remaining case just needs a few more rewrites *)
- rewrite bvAdd_assoc, bvAdd_comm, bvAdd_assoc; reflexivity.
- cbn; rewrite transMbox_Mbox_nil_r; reflexivity.
- simpl. f_equal. rewrite bvAdd_assoc. f_equal. rewrite bvAdd_comm. f_equal.
simpl. rewrite transMbox_Mbox_nil_r. reflexivity.
Time Qed.


Expand Down Expand Up @@ -467,6 +467,7 @@ Proof.
- rewrite e_forall0 in e_maybe0.
discriminate e_maybe0.
(* TODO Add the sort of reasoning in the next two cases back into the automation? *)

- rewrite a in e_maybe1.
discriminate e_maybe1.
- rewrite a1 in e_maybe2.
Expand Down
Loading