Skip to content

Commit

Permalink
Change array permissions to contain shapes (#1484)
Browse files Browse the repository at this point in the history
* fixed the IRT description generation to match the recent change that made the translation of bitvector permissions to just be bitvectors

* updated xor_swap_rust example to use the Rust type in the SAW script

* added a case to the Rust to Heapster translator to handle function types with no return value

* whoops, forgot to update the bitcode file for xor_swap_rust

* bugfix in the Rust to Heapster translator: empty return types need to be converted to unit, not to the empty struct

* tweaked the error message for when Rust types do not translate correctly to the expected LLVM type

* started adding support for string literals by moving all creation of a HeapsterEnv into a single function which iterates through the globals and adds those it can handle

* added a formatting example in Rust, and started defining the necessary types for it

* started trying to figure out how Rust stores string literals in its generated LLVM files

* fixed the prtty-printing for constant values

* changed TrueEnum::fmt to use the fmt method rather than the write! macro

* whoops, changed the fmt method for TrueEnum back to using the write! macro, because that seems to be the proper way to do things

* whoops, forgot to add the repr(u64) pragma to the TrueEnum type

* added a type-checking command for TrueEnum::fmt

* moved some OpenTerm operators from SAWTranslation.hs to OpenTerm.hs

* added llvmReadBlockOfShape

* more work trying to translate globals

* got string literals translated, but now there is some translation bug...

* whoops, translating a shape always yields exactly one term

* added helper function exprLLVMTypeBytes

* added support for Rust slice types

* whoops, combined the two cases for translating shared vs mutable references into one

* updated funPerm3FromArgLayout to handle layouts with existential permissions

* updated the rust_data example to use string literals

* added mapM and mapBVVecM

* added support for proving array permissions from other array permissions with different fields using the SImpl_LLVMArrayContents rule; to get the translation of the SImpl_LLVMArrayContents to work correctly, I had to change local implications to not use strict tuples, which in turn required changing the translation of lowned permissions (which are themselves local implications) to not use strict tuples as well

* added more definitions to the arrays example now that the implication prover can map array permission contents

* moved the LLVM globals code to a new file LLVMGlobalConst.hs

* fixed the translation of LLVM array constants to generate SAW core BVVecs instead of SAW core Vecs

* regenerated Coq files for saw-core-coq

* added support for the Crucible BVZext and BVTrunc instructions, and fixed up that for BVSext

* added heapster_init_env_debug and heapster_init_env_from_file_debug commands

* small tweaks to rust_data.saw to get it to work

* added another formatting example that we cannot handle yet...

* RecurseFlag to Permissions.hs; added requireNamedPerm

* widening now unfolds defined and recursive permissions

* whoops, forgot to insert a bindM into the translation of SImpl_LLVMArrayContents

* removed the old gen_block_perms hints that are no longer used anyway from arrays.saw

* changed tupleTypeTrans to no longer having the trailing unit type on tuples of 2 or more types; updated foldList and unfoldList in the SAW core Prelude to fit this new approach; regenerated the resulting Coq files

* small tweak to the expression type-checker to type-check the bodies of existential shapes as arbitrary expressions

* expanded the translation of Rust slices to allow multiple fields

* updated mbox proof script to work with the recent changes, though not all the mbox proofs work...

* started updating the mbox proofs, but I got stuck...

* moved formatting-related types in the rust_data example to their own section

* finished updating mbox proofs

* generalized array permissions and array shapes to use shapes for their cells instead of lists of fields

* updated examples to match the change to the SAW translation

* updated the IRT translation to match the updates to the SAW translation

* updated to use the new array permission with a shape for the cells

* started updating the permission implication prover with the new array permissions

* added support for array permissions in lowned permissions; fixed a few small bugs

* more work moving two arrays with shapes for their cells

* wrote implElimLLVMBlockForOffset; rewrote proveVarLLVMField in terms of implGetLLVMPermForOffset

* trying to get the newly-writte Implication.hs to compile...

* finally got Implication.hs to compile

* added support for the new LOwnedPermArray constructor

* small tweak to avoid warning

* updated parser and type-checker for the new array permissions

* whoops, fixed some compilation errors in Widening.hs that were obscured by other files

* fixed typo in comment

* removed comments

* removed a use of the now outdated LLVMArrayField type

* fixed error message

* udpated SAWTranslation.hs to compile with the new approach to array permissions

* changed updBVVec to not require a proof that the index is in the array

* updated IRTTranslation.hs to support the new form of the array permission

* updated the arrays.saw example to use the new form of array permission

* whoops, fixed a bug in proveVarLLVMField; also added some extra debugging information

* incorporated unfolding into implGetLLVMPermForOffset; fixed llvmPermIndicesForOffset, which was implemented incorrectly; added some debugging info

* whoops, should not have commented out the cases for eliminating blocks with field or array shape

* changed typeTransF to a helper function that prints more debug info on error

* whoops, fixed the translation of SImpl_ElimLLVMBlockField

* updated the linked_list example to use the new array permission

* whoops, used the wrong variant of implGetConjM in one of the proveVarLLVMBlocks1 cases; also added more debug info to some of the lower-level implication prover combinators

* updated the parsing for array shapes to more closely match the conventions for array permissions

* clarified the fact that the cell type translation of an array permission translation is really the translation of the memblock permission to the first cell of the array, and fixed a translation bug related to this issue

* fixed a bug in the SImpl_ElimLLVMBlockArray: that rule should only work when the input block permission has the same size as the resulting array shape

* updated the generated Coq files

* updated array permissions in the examples to use the new array permission syntax

* fixed a bug in implElimLLVMBlockForOffset, which was not handling non-conjunctive permissions returned by implElimLLVMBlock; added pretty-printing and typing information for the names bound by local implications

* fixed a subtle bug in offsetLLVMPermTrans applied to the translations of defined permissions

* fixed the pretty-printer for array shapes to use the < and * prefixes

* whoops, I accidentally swapped the input and output permissions of the local implication used to prove array contents!

* Changed the SImpl_LLVMArrayCopy and SImpl_LLVMArrayBorrow rules to generate the sub-array being borrowed, and to only take the borrows from the larger array that could overlap with the sub-array; Added cases to prove field permissions from arrays of smaller strides; added more debug information

* whoops, llvmMakeSubArray was keeping the borrows the could be disjoint from the sub-array instead of those the could overlap with it

* changed the way tagged union shapes are proved to always try to prove a tag first, thereby reducing the cases in which they bottom out into general disjunctions

* re-imagined how solveForPermListImpl works, by having solveForPermListImplBlock delete all the BVRanges of perms on the left-hand size from the BVRange of the right-hande side, and then creating blocks with existentially-quantified shapes for those ranges

* removed the checks that the block perm has the proper length in llvmBlockPermToField and llvmBlockPermToArray, because these do not take the current partial substitution into account

* commented out proof in rust_data_proofs.v that no longer works

* *almost* got a use of the write! macro to work in the rust_data exmample

* wrapped an overly long line

* whoops, removed duplicate functions that were accidentally added during the recent merge

* wrapped an overly long line

* changed widening to drop permissions on unreachable variables

* oops, finished updating the examples to use the correct syntax

* commented out some parts of the proofs for sum_inc_ptr in the arrays example that no longer work

* wrapped some of the lines in rust_data.saw

* whoops, updated the ArgumentV1 type incorrectly in the last commit
  • Loading branch information
Eddy Westbrook authored Oct 19, 2021
1 parent d3773e4 commit 156e9d6
Show file tree
Hide file tree
Showing 21 changed files with 2,396 additions and 2,017 deletions.
10 changes: 5 additions & 5 deletions heapster-saw/examples/arrays.saw
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env <- heapster_init_env_from_file "arrays.sawcore" "arrays.bc";
heapster_define_perm env "int64" " " "llvmptr 64" "exists x:bv 64.eq(llvmword(x))";
heapster_define_perm env "int8" " " "llvmptr 8" "exists x:bv 8.eq(llvmword(x))";

heapster_define_perm env "int64array" "len:bv 64" "llvmptr 64" "array(0,<len,*8,[(W,0) |-> int64<>])";
heapster_define_perm env "int64array" "len:bv 64" "llvmptr 64" "array(W,0,<len,*8,fieldsh(int64<>))";


heapster_typecheck_fun env "contains0_rec_"
Expand Down Expand Up @@ -42,13 +42,13 @@ heapster_typecheck_fun env "filter_and_sum_pos"
\ arg0:int64array<len>, arg1:true, ret:int64<>";

heapster_typecheck_fun env "sum_2d"
"(l1:bv 64,l2:bv 64). arg0:array(0,<l1,*8,[(W,0) |-> array(0,<l2,*8,[(W,0) |-> int64<>])]), \
"(l1:bv 64,l2:bv 64). arg0:array(W,0,<l1,*8,fieldsh(array(W,0,<l2,*8,fieldsh(int64<>)))), \
\ arg1:eq(llvmword(l1)), arg2:eq(llvmword(l2)) -o \
\ arg0:array(0,<l1,*8,[(W,0) |-> array(0,<l2,*8,[(W,0) |-> int64<>])]), \
\ arg0:array(W,0,<l1,*8,fieldsh(array(W,0,<l2,*8,fieldsh(int64<>)))), \
\ arg1:true, arg2:true, ret:int64<>";

heapster_typecheck_fun env "sum_inc_ptr"
"(len:bv 64). arg0:array(0,<len,*1,[(W,0,8) |-> int8<>]), arg1:eq(llvmword(len)) -o \
\ arg0:array(0,<len,*1,[(W,0,8) |-> int8<>]), arg1:true, ret:int64<>";
"(len:bv 64). arg0:array(W,0,<len,*1,fieldsh(8,int8<>)), arg1:eq(llvmword(len)) -o \
\ arg0:array(W,0,<len,*1,fieldsh(8,int8<>)), arg1:true, ret:int64<>";

heapster_export_coq env "arrays_gen.v";
10 changes: 7 additions & 3 deletions heapster-saw/examples/arrays_proofs.v
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,22 @@ Proof.
unfold noErrorsSpec, sum_inc_ptr_invar.
time "no_errors_sum_inc_ptr" prove_refinement.
all: try assumption.
(*
- assert (isBvult 64 a2 a1).
+ apply isBvule_to_isBvult_or_eq in e_assuming.
destruct e_assuming; [assumption |].
apply bvEq_bvSub_r in H.
symmetry in H; contradiction.
(* symmetry in H; contradiction. *) admit.
+ rewrite H in e_maybe; discriminate e_maybe.
- apply isBvult_to_isBvule_suc; assumption.
- repeat rewrite bvSub_eq_bvAdd_neg.
rewrite bvAdd_assoc; f_equal.
rewrite bvNeg_bvAdd_distrib; reflexivity.
- apply isBvule_zero_n.
- symmetry; apply bvSub_n_zero.
Qed.
*)
Admitted.
(* Qed. *)


Definition sum_inc_ptr_spec len : BVVec 64 len (bitvector 8) -> bitvector 64 :=
Expand All @@ -186,6 +189,7 @@ Proof.
3: prove_refinement_eauto; [| apply refinesM_returnM ].
7: prove_refinement_eauto; [| apply refinesM_returnM ].
(* same as no_errors_sum_inc_ptr *)
(*
- assert (isBvult 64 a2 a1).
+ apply isBvule_to_isBvult_or_eq in e_forall.
destruct e_forall; [assumption |].
Expand All @@ -206,5 +210,5 @@ Proof.
(* unique to this proof *)
- rewrite bvAdd_id_l.
repeat f_equal.
admit.
admit. *)
Admitted.
2 changes: 1 addition & 1 deletion heapster-saw/examples/clearbufs.saw
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ heapster_define_reachability_perm env "Bufs"
"x:llvmptr 64" "llvmptr 64"
"exists len:(bv 64).ptr((W,0) |-> Bufs<x>) * \
\ ptr((W,8) |-> eq(llvmword(len))) * \
\ array(16, <len, *8, [(W,0) |-> int64<>])"
\ array(W, 16, <len, *8, fieldsh(int64<>))"
"Mbox_def" "foldMbox" "unfoldMbox" "transMbox";

heapster_block_entry_hint env "clearbufs" 3
Expand Down
2 changes: 1 addition & 1 deletion heapster-saw/examples/linked_list.saw
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ heapster_typecheck_fun env "is_elem"

heapster_assume_fun env "malloc"
"(sz:bv 64). arg0:eq(llvmword(8*sz)) -o \
\ arg0:true, ret:array(0,<sz,*8,[(W,0) |-> true])"
\ arg0:true, ret:array(W,0,<sz,*8,fieldsh(true))"
"mallocSpec";

heapster_typecheck_fun env "any"
Expand Down
32 changes: 16 additions & 16 deletions heapster-saw/examples/mbox.saw
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ heapster_define_perm env "int32" " " "llvmptr 32" "exists x:bv 32.eq(llvmword(x)

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

heapster_define_perm env "state_t" " " "llvmptr 64" "array(0, <16, *1, [(W,0) |-> int64<>])";
heapster_define_perm env "state_t" " " "llvmptr 64" "array(W, 0, <16, *1, fieldsh(int64<>))";

heapster_define_perm env "aes_sw_ctx"
"rw1:rwmodality, rw2:rwmodality"
"llvmptr 64"
"array(0, <240, *1, [(rw1,0) |-> int64<>]) * ptr((rw2, 1920) |-> int64<>)";
"array(rw1, 0, <240, *1, fieldsh (int64<>)) * ptr((rw2, 1920) |-> int64<>)";

heapster_define_reachability_perm env "mbox"
"rw:rwmodality, x:llvmptr 64"
"llvmptr 64"
"ptr((rw,0) |-> int64<>) * ptr((rw,8) |-> int64<>) * ptr((rw,16) |-> mbox<rw,x>) * \
\ array(24, <128, *1, [(rw,0,8) |-> int8<>])"
\ array(W, 24, <128, *1, fieldsh(8,int8<>))"
"Mbox_def" "foldMbox" "unfoldMbox" "transMbox";

// heapster_define_perm env "mbox_nonnull"
Expand All @@ -44,7 +44,7 @@ heapster_define_reachability_perm env "mbox"
heapster_define_perm env "byte_array"
"rw:rwmodality, len:bv 64"
"llvmptr 64"
"array(0, <len, *1, [(rw,0,8) |-> int8<>])";
"array(W, 0, <len, *1, fieldsh(8,int8<>))";

heapster_define_perm env "boolean" " " "llvmptr 1" "exists x:bv 1.eq(llvmword(x))";

Expand Down Expand Up @@ -98,7 +98,7 @@ heapster_assume_fun env "mbox_new"

heapster_assume_fun env "mbox_free"
"(). arg0:ptr((W,0) |-> true) * ptr((W,8) |-> true) * ptr((W,16) |-> true) * \
\ array(24, <128, *1, [(W,0,8) |-> int8<>]) -o \
\ array(W, 24, <128, *1, fieldsh(8,int8<>)) -o \
\ arg0:true, ret:int32<>"
"mboxFreeSpec";

Expand Down Expand Up @@ -132,25 +132,25 @@ heapster_typecheck_fun env "mbox_eq"
heapster_block_entry_hint env "mbox_from_buffer" 24
"top1:bv 64, top2:llvmptr 64, top3:llvmptr 64"
"frm:llvmframe 64, ghost0:llvmptr 64, ghost1:bv 64"
"top1:true, top2:array(0, <top1, *1, [(W,0,8) |-> int8<>]), \
"top1:true, top2:array(W, 0, <top1, *1, fieldsh(8, int8<>)), \
\ top3:eq(llvmword(top1)), arg0:ptr((W,0) |-> true), \
\ arg1:ptr((W,0) |-> eq(top2)), arg2:ptr((W,0) |-> eq(llvmword(top1))), \
\ arg3:ptr((W,0) |-> mbox<W, ghost0>), arg4:ptr((W,0) |-> eq(ghost0)), \
\ arg5:ptr((W,0) |-> eq(llvmword(ghost1))), arg6:ptr((W,0) |-> true), \
\ frm:llvmframe [arg6:8, arg5:8, arg4:8, arg3:8, arg2:8, arg1:8, arg0:8], \
\ ghost0:ptr((W,0) |-> int64<>) * ptr((W,8) |-> int64<>) * \
\ ptr((W,16) |-> mbox<W, llvmword(0)>) * array(24, <128, *1, [(W,0,8) |-> int8<>]), \
\ ptr((W,16) |-> mbox<W, llvmword(0)>) * array(W, 24, <128, *1, fieldsh(8, int8<>)), \
\ ghost1:true";

heapster_typecheck_fun env "mbox_from_buffer"
"(len:bv 64). arg0:array(0,<len,*1,[(W,0,8) |-> int8<>]), arg1:eq(llvmword(len)) -o \
\ arg0:array(0,<len,*1,[(W,0,8) |-> int8<>]), arg1:true, ret:mbox<W,llvmword(0)>";
"(len:bv 64). arg0:array(W, 0,<len,*1,fieldsh(8, int8<>)), arg1:eq(llvmword(len)) -o \
\ arg0:array(W, 0,<len,*1,fieldsh(8, int8<>)), arg1:true, ret:mbox<W,llvmword(0)>";


heapster_block_entry_hint env "mbox_to_buffer" 32
"top1:bv 64, top2:llvmptr 64, top3:llvmptr 64, top4:llvmptr 64, top5:llvmptr 64"
"frm:llvmframe 64, ghost0:llvmptr 64"
"top1:true, top2:array(0, <top1, *1, [(W,0,8) |-> int8<>]), \
"top1:true, top2:array(W, 0, <top1, *1, fieldsh(8, int8<>)), \
\ top3:eq(llvmword(top1)), top4:mbox<W,ghost0>, \
\ top5:int64<>, arg0:ptr((W,0) |-> true), \
\ arg1:ptr((W,0) |-> eq(top2)), arg2:ptr((W,0) |-> eq(top3)), \
Expand All @@ -160,16 +160,16 @@ heapster_block_entry_hint env "mbox_to_buffer" 32
\ ghost0:mbox<W,llvmword(0)>";

heapster_typecheck_fun env "mbox_to_buffer"
"(len:bv 64). arg0:array(0,<len,*1,[(W,0,8) |-> int8<>]), \
"(len:bv 64). arg0:array(W, 0,<len,*1,fieldsh(8, int8<>)), \
\ arg1:eq(llvmword(len)), arg2:mbox<W, llvmword(0)>, arg3:int64<> -o \
\ arg0:array(0,<len,*1,[(W,0,8) |-> int8<>]), \
\ arg0:array(W, 0,<len,*1,fieldsh(8, int8<>)), \
\ arg1:true, arg2:mbox<W,llvmword(0)>, arg3:true, ret:int64<>";


heapster_typecheck_fun env "mbox_to_buffer_rec"
"(len:bv 64). arg0:array(0,<len,*1,[(W,0,8) |-> int8<>]), \
"(len:bv 64). arg0:array(W, 0,<len,*1,fieldsh(8, int8<>)), \
\ arg1:eq(llvmword(len)), arg2:mbox<W,llvmword(0)> -o \
\ arg0:array(0,<len,*1,[(W,0,8) |-> int8<>]), \
\ arg0:array(W, 0,<len,*1,fieldsh(8, int8<>)), \
\ arg1:true, arg2:mbox<W,llvmword(0)>, ret:true";

// heapster_typecheck_fun env "mbox_to_buffer_rec"
Expand Down Expand Up @@ -203,7 +203,7 @@ heapster_block_entry_hint env "mbox_concat_chains" 16
\ arg0:ptr((W,0) |-> eq(x0)), arg1:ptr((W,0) |-> eq(top2)), \
\ frm:llvmframe [arg1:8, arg0:8], \
\ x0:ptr((W,0) |-> int64<>) * ptr((W,8) |-> int64<>) * \
\ ptr((W,16) |-> mbox<W,llvmword(0)>) * array(24, <128, *1, [(W,0,8) |-> int8<>])";
\ ptr((W,16) |-> mbox<W,llvmword(0)>) * array(W, 24, <128, *1, fieldsh(8, int8<>))";

heapster_typecheck_fun env "mbox_concat_chains"
"(). arg0:mbox<W,llvmword(0)>, arg1:mbox<W,llvmword(0)> -o \
Expand Down Expand Up @@ -260,7 +260,7 @@ heapster_block_entry_hint env "mbox_randomize" 16
"top1:llvmptr 64"
"frm:llvmframe 64"
"top1:ptr((W,0) |-> int64<>) * ptr((W,8) |-> int64<>) * \
\ ptr((W,16) |-> mbox<W,llvmword(0)>) * array(24, <128, *1, [(W,0,8) |-> int8<>]), \
\ ptr((W,16) |-> mbox<W,llvmword(0)>) * array(W, 24, <128, *1, fieldsh(8, int8<>)), \
\ arg0:ptr((W,0,32) |-> true), arg1:ptr((W,0) |-> eq(top1)), arg2:ptr((W,0) |-> int64<>), \
\ frm:llvmframe [arg2:8, arg1:8, arg0:4]";

Expand Down
7 changes: 5 additions & 2 deletions heapster-saw/examples/memcpy.saw
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ env <- heapster_init_env_from_file "memcpy.sawcore" "memcpy.bc";
heapster_define_perm env "int64" " " "llvmptr 64" "exists x:bv 64.eq(llvmword(x))";

heapster_assume_fun env "llvm.memcpy.p0i8.p0i8.i64"
"(rw:rwmodality, l1:lifetime, l2:lifetime, sh:llvmshape 64, b:llvmblock 64, len:bv 64). \
\ arg0:[l1]memblock(W,0,len,sh), arg1:[l2]memblock(rw,0,len,eqsh(b)), arg2:eq(llvmword(len)) -o \
"(rw:rwmodality, l1:lifetime, l2:lifetime, sh:llvmshape 64, \
\ b:llvmblock 64, len:bv 64). \
\ arg0:[l1]memblock(W,0,len,sh), arg1:[l2]memblock(rw,0,len,eqsh(b)), \
\ arg2:eq(llvmword(len)) -o \
\ arg0:[l1]memblock(W,0,len,eqsh(b)), arg1:[l2]memblock(rw,0,len,eqsh(b))"
"\\ (X:sort 0) (len:Vec 64 Bool) (x:X) (_:#()) -> returnM (#() * #()) ((),())";


heapster_typecheck_fun env "copy_int"
"().arg0:int64<> -o ret:int64<>";

Expand Down
82 changes: 64 additions & 18 deletions heapster-saw/examples/rust_data.saw
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ heapster_define_rust_type env "pub enum Option<X> { None, Some (X) }";
// we don't yet have implications on array cells
//heapster_define_llvmshape env "str" 64 "" "exsh len:bv 64.arraysh(len,1,[(8,int8<>)])";
heapster_define_llvmshape env "str" 64 ""
"exsh len:bv 64.arraysh(len,1,[(8,exists x:bv 8.eq(llvmword(x)))])";
"exsh len:bv 64.arraysh(<len,*1,fieldsh(8,int8<>))";
//heapster_define_rust_type env "type str = [u8];";

// The String type
heapster_define_llvmshape env "String" 64 ""
"exsh cap:bv 64. ptrsh(arraysh(cap,1,[(8,int8<>)])); \
"exsh cap:bv 64. ptrsh(arraysh(<cap,*1,fieldsh(8,int8<>))); \
\ fieldsh(int64<>);fieldsh(eq(llvmword(cap)))";

// List type
Expand Down Expand Up @@ -76,8 +76,12 @@ heapster_define_rust_type env "pub struct ThreeValues(u32,u32,u32);";
heapster_define_rust_type env "pub struct FourValues(u32,u32,u32,u32);";
heapster_define_rust_type env "pub struct FiveValues(u32,u32,u32,u32,u32);";

// The StrStruct type
heapster_define_rust_type env "pub struct StrStruct(String);";

// MixedStruct type
// heapster_define_llvmshape env "MixedStruct" 64 "" "String<>;fieldsh(64,int64<>);fieldsh(64,int64<>)";
// heapster_define_llvmshape env "MixedStruct" 64 ""
// "String<>;fieldsh(64,int64<>);fieldsh(64,int64<>)";
heapster_define_rust_type env
"pub struct MixedStruct { pub s: String, pub i1: u64, pub i2: u64, }";

Expand Down Expand Up @@ -145,7 +149,8 @@ heapster_define_rust_type env
heapster_define_rust_type_qual env "fmt" "pub struct Error { }";

// fmt::Result type
// FIXME: there seems to be some optimization in Rust that lays out fmt::Result as a 1-bit value
// FIXME: there seems to be some optimization in Rust that lays out fmt::Result
// as a 1-bit value
heapster_define_llvmshape env "fmt::Result" 64 ""
"fieldsh(1,eq(llvmword(0))) orsh fieldsh(1,eq(llvmword(1)))";
//heapster_define_rust_type_qual env "fmt"
Expand Down Expand Up @@ -179,9 +184,14 @@ heapster_define_rust_type_qual env "fmt"

// fmt::ArgumentV1 type
heapster_define_rust_type_qual env "fmt"
"pub struct ArgumentV1<'a> { \
\ value: &'a Void, \
\ formatter: for <'b> fn(&'b Void, &'b mut fmt::Formatter) -> fmt::Result, }";
"pub struct ArgumentV1 { value: Box<Void>, formatter: Box<Void> }";

// FIXME: this is the correct type, but Heapster cannot yet handle lifetime
// arguments for types
// heapster_define_rust_type_qual env "fmt"
// "pub struct ArgumentV1<'a> { \
// \ value: &'a Void, \
// \ formatter: for <'b> fn(&'b Void, &'b mut fmt::Formatter) -> fmt::Result, }";

// fmt::Arguments type
//heapster_define_rust_type_qual env "fmt"
Expand All @@ -190,6 +200,12 @@ heapster_define_rust_type_qual env "fmt"
// \ args: &'a [fmt::ArgumentV1<'a>], }";


heapster_define_rust_type_qual env "fmt"
"pub struct Arguments { pieces: Box<Void>, pieces_len:u64, \
\ fmt: Box<Void>, fmt_len: u64, args: Box<Void>, \
\ arg_len:u64, }";


/***
*** Assumed Functions
***/
Expand All @@ -207,13 +223,16 @@ heapster_assume_fun_rename env exchange_malloc_sym "exchange_malloc"

// memcpy
heapster_assume_fun env "llvm.memcpy.p0i8.p0i8.i64"
"(rw:rwmodality, l1:lifetime, l2:lifetime, sh:llvmshape 64, b:llvmblock 64, len:bv 64). \
\ arg0:[l1]memblock(W,0,len,sh), arg1:[l2]memblock(rw,0,len,eqsh(b)), arg2:eq(llvmword(len)) -o \
"(rw:rwmodality, l1:lifetime, l2:lifetime, sh:llvmshape 64, \
\ b:llvmblock 64, len:bv 64). \
\ arg0:[l1]memblock(W,0,len,sh), arg1:[l2]memblock(rw,0,len,eqsh(b)), \
\ arg2:eq(llvmword(len)) -o \
\ arg0:[l1]memblock(W,0,len,eqsh(b)), arg1:[l2]memblock(rw,0,len,eqsh(b))"
"\\ (X:sort 0) (len:Vec 64 Bool) (x:X) (_:#()) -> returnM (#() * #()) ((),())";

// <str as alloc::string::ToString>::to_string
to_string_str <- heapster_find_symbol env "$LT$str$u20$as$u20$alloc..string..ToString$GT$9to_string";
to_string_str <- heapster_find_symbol env
"$LT$str$u20$as$u20$alloc..string..ToString$GT$9to_string";
// NOTE: this is the more incorrect version, with no lifetime argument and no shapes
//heapster_assume_fun_rename env to_string_str "to_string_str"
// "(len:bv 64). arg0:memblock(W,0,24,emptysh),
Expand All @@ -230,7 +249,7 @@ to_string_str <- heapster_find_symbol env "$LT$str$u20$as$u20$alloc..string..ToS
// NOTE: this is the incorrect version, with no lifetime argument
heapster_assume_fun_rename env to_string_str "to_string_str"
"(len:bv 64). arg0:memblock(W,0,24,emptysh), \
\ arg1:array(0,<len,*1,[(R,0,8) |-> int8<>]), \
\ arg1:array(R,0,<len,*1,fieldsh(8,int8<>)), \
\ arg2:eq(llvmword(len)) -o \
\ arg0:memblock(W,0,24,String<>)"
"\\ (len:Vec 64 Bool) (_:#()) (str:BVVec 64 len (Vec 8 Bool)) -> \
Expand Down Expand Up @@ -286,10 +305,28 @@ heapster_assume_fun_rename_prim env String__fmt_sym "String__fmt"
*/


// ArgumentV1::new
//ArgumentV1_new <- heapster_find_symbol env "10ArgumentV13new";
//heapster_assume_fun_rename_prim env ArgumentV1_new "ArgumentV1_new"
// "<'a,'b,T> fn (x: &'b T, f: fn(&T, &mut fmt::Formatter) -> fmt::Result) \
// \ -> fmt::ArgumentV1<'b>";
//ArgumentV1_new_String <- heapster_find_symbol env
// "_ZN4core3fmt10ArgumentV13new17hdf7e5958686d74c0E";
//heapster_assume_fun_rename_prim env ArgumentV1_new_String "ArgumentV1_new_String"
// "<'a,'b> fn (x: &'b String, \
// \ f: for<'c,'d> fn (&'c String, &'d mut fmt::Formatter) -> fmt::Result) \
// \ -> fmt::ArgumentV1<'b>";
//heapster_assume_fun_rename_prim env ArgumentV1_new_String "ArgumentV1_new_String"
// "<'a,'b> fn (x: &'b String, f: Box<Void>) -> fmt::ArgumentV1<'b>";
//heapster_assume_fun_rename_prim env ArgumentV1_new_String "ArgumentV1_new_String"
// "<'a,'b> fn (x: &'b String, f: Box<Void>) -> fmt::ArgumentV1";

// Arguments::new_v1
Arguments__new_v1_sym <- heapster_find_symbol env "3fmt9Arguments6new_v1";
//heapster_assume_fun_rename_prim env Arguments__new_v1_sym "Arguments__new"
// "<'a> fn (pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a>";
// "<'a> fn (pieces: &'a [&'a str], args: &'a [fmt::ArgumentV1<'a>]) -> fmt::Arguments<'a>";
heapster_assume_fun_rename_prim env Arguments__new_v1_sym "Arguments__new"
"<'a> fn (pieces: &'a [&'a str], args: &'a [fmt::ArgumentV1]) -> fmt::Arguments";

// Formatter::write_str
Formatter__write_str_sym <- heapster_find_symbol env "9Formatter9write_str";
Expand Down Expand Up @@ -340,12 +377,20 @@ mixed_struct_get_i2 <- heapster_find_symbol env "11MixedStruct6get_i2";
heapster_typecheck_fun_rename env mixed_struct_get_i2 "MixedStruct_get_i2"
"<'a> fn (m:&'a MixedStruct) -> u64";

// MixedStruct::fmt
mixed_struct_fmt <- heapster_find_trait_method_symbol env
"core::fmt::Display::fmt<MixedStruct>";
heapster_typecheck_fun_rename env mixed_struct_fmt "MixedStruct_fmt"
"<'a, 'b> fn(&'a MixedStruct, f: &'b mut fmt::Formatter) -> fmt::Result";

cycle_true_enum_sym <- heapster_find_symbol env "15cycle_true_enum";
// NOTE: This typecheck requires full(er) support for disjunctive shapes, which Heapster currently lacks
// NOTE: This typecheck requires full(er) support for disjunctive shapes, which
// Heapster currently lacks
// heapster_typecheck_fun_rename env cycle_true_enum_sym "cycle_true_enum"
// "<'a> fn (te:&'a TrueEnum) -> TrueEnum";

TrueEnum__fmt_sym <- heapster_find_trait_method_symbol env "core::fmt::Display::fmt<TrueEnum>";
TrueEnum__fmt_sym <- heapster_find_trait_method_symbol env
"core::fmt::Display::fmt<TrueEnum>";
heapster_typecheck_fun_rename env TrueEnum__fmt_sym "TrueEnum__fmt"
"<'a, 'b> fn (&'a TrueEnum, f: &'b mut fmt::Formatter) -> fmt::Result";

Expand Down Expand Up @@ -390,11 +435,12 @@ str_struct_new <- heapster_find_symbol env "9StrStruct3new";
// \\ ptr((W,8) |-> int64<>) * ptr((W,16) |-> eq(llvmword(len')))";

// FIXME: this is the correct version, with the String shape
//heapster_typecheck_fun_rename env str_struct_new "str_struct_new"
// "(len:bv 64).arg0:memblock(W,0,24,emptysh), \
// \ arg1:array(0,<len,*1,[(R,0,8) |-> int8<>]), \
// \ arg2:eq(llvmword(len)) -o arg0:memblock(W,0,24,String<>)";
heapster_typecheck_fun_rename env str_struct_new "str_struct_new"
"(len:bv 64). arg0:memblock(W,0,24,emptysh), \
\ arg1:array(0,<len,*1,[(R,0,8) |-> int8<>]), \
\ arg2:eq(llvmword(len)) -o \
\ arg0:memblock(W,0,24,String<>)";
"<'a> fn (name:&'a str) -> StrStruct<>";

bintree_is_leaf_sym <- heapster_find_symbol env "15bintree_is_leaf";
heapster_typecheck_fun_rename env bintree_is_leaf_sym "bintree_is_leaf"
Expand Down
4 changes: 3 additions & 1 deletion heapster-saw/examples/rust_data_proofs.v
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Import SAWCorePrelude.

(* Print str_struct_new__tuple_fun. *)

Lemma no_errors_str_struct_new : refinesFun str_struct_new (fun _ _ _ => noErrorsSpec).
(* FIXME: need to handle mapBVVecM for this one to work!
Lemma no_errors_str_struct_new : refinesFun str_struct_new (fun _ _ _ _ => noErrorsSpec).
Proof.
unfold str_struct_new, str_struct_new__tuple_fun, noErrorsSpec, llvm__x2ememcpy__x2ep0i8__x2ep0i8__x2ei64, to_string_str.
prove_refinement.
Expand All @@ -44,3 +45,4 @@ Proof.
unfold str_struct_new, str_struct_new__tuple_fun, noErrorsSpec, llvm__x2ememcpy__x2ep0i8__x2ep0i8__x2ei64, to_string_str.
prove_refinement.
Qed.
*)
Loading

0 comments on commit 156e9d6

Please sign in to comment.