Skip to content

Commit d166857

Browse files
committed
get round round_16_80 typechecking
1 parent ac8e511 commit d166857

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

heapster-saw/examples/sha512_mr_solver.saw

+14-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ heapster_typecheck_fun env "round_00_15"
2323
\ arg5:int64_ptr<>, arg6:int64_ptr<>, arg7:int64_ptr<>, arg8:int64_ptr<>, \
2424
\ arg9:int64_ptr<>, ret:true";
2525

26-
heapster_set_debug_level env 1;
26+
// heapster_set_debug_level env 1;
2727

2828
heapster_typecheck_fun env "round_16_80"
2929
"(). arg0:int64<>, arg1:int64<>, \
@@ -39,10 +39,14 @@ heapster_typecheck_fun env "round_16_80"
3939
/*
4040
heapster_set_translation_checks env false;
4141
heapster_typecheck_fun env "processBlock"
42-
"(num:bv 64). arg0:array(W,0,<8,*8,fieldsh(int64<>)), \
43-
\ arg1:array(R,0,<16*num,*8,fieldsh(int64<>)) -o \
44-
\ arg0:array(W,0,<8,*8,fieldsh(int64<>)), \
45-
\ arg1:array(R,0,<16*num,*8,fieldsh(int64<>)), ret:true";
42+
"(num:bv 64). arg0:int64_ptr<>, arg1:int64_ptr<>, arg2:int64_ptr<>, \
43+
\ arg3:int64_ptr<>, arg4:int64_ptr<>, arg5:int64_ptr<>, \
44+
\ arg6:int64_ptr<>, arg7:int64_ptr<>, \
45+
\ arg8:array(R,0,<16*num,*8,fieldsh(int64<>)) -o \
46+
\ arg0:int64_ptr<>, arg1:int64_ptr<>, arg2:int64_ptr<>, \
47+
\ arg3:int64_ptr<>, arg4:int64_ptr<>, arg5:int64_ptr<>, \
48+
\ arg6:int64_ptr<>, arg7:int64_ptr<>, \
49+
\ arg8:array(R,0,<16*num,*8,fieldsh(int64<>)), ret:true";
4650

4751
heapster_set_translation_checks env false;
4852
heapster_typecheck_fun env "processBlocks"
@@ -52,6 +56,7 @@ heapster_typecheck_fun env "processBlocks"
5256
\ arg0:array(W,0,<8,*8,fieldsh(int64<>)), \
5357
\ arg1:array(R,0,<16*num,*8,fieldsh(int64<>)), \
5458
\ arg2:true, ret:true";
59+
*/
5560

5661
heapster_export_coq env "sha512_mr_solver_gen.v";
5762

@@ -73,12 +78,12 @@ let run_test name test expected =
7378

7479
round_00_15 <- parse_core_mod "SHA512" "round_00_15";
7580
round_16_80 <- parse_core_mod "SHA512" "round_16_80";
76-
processBlock <- parse_core_mod "SHA512" "processBlock";
77-
processBlocks <- parse_core_mod "SHA512" "processBlocks";
81+
// processBlock <- parse_core_mod "SHA512" "processBlock";
82+
// processBlocks <- parse_core_mod "SHA512" "processBlocks";
7883

7984
// Test that every function refines itself
80-
run_test "processBlocks |= processBlocks" (mr_solver processBlocks processBlocks) true;
81-
run_test "processBlock |= processBlock" (mr_solver processBlock processBlock) true;
85+
// run_test "processBlocks |= processBlocks" (mr_solver processBlocks processBlocks) true;
86+
// run_test "processBlock |= processBlock" (mr_solver processBlock processBlock) true;
8287
// run_test "round_16_80 |= round_16_80" (mr_solver round_16_80 round_16_80) true;
8388
// run_test "round_00_15 |= round_00_15" (mr_solver round_00_15 round_00_15) true;
8489

@@ -98,4 +103,3 @@ monadify_term {{ round_00_15_spec }};
98103

99104
run_test "round_00_15 |= round_00_15_spec" (mr_solver round_00_15 {{ round_00_15_spec }}) true;
100105
run_test "round_16_80 |= round_16_80_spec" (mr_solver_debug 0 round_16_80 {{ round_16_80_spec }}) true;
101-
*/

heapster-saw/src/Verifier/SAW/Heapster/Permissions.hs

+22-12
Original file line numberDiff line numberDiff line change
@@ -8040,10 +8040,14 @@ detVarsClauseAddLHSVar :: ExprVar a -> DetVarsClause -> DetVarsClause
80408040
detVarsClauseAddLHSVar n (DetVarsClause lhs rhs) =
80418041
DetVarsClause (NameSet.insert n lhs) rhs
80428042

8043+
newtype SeenDetVarsClauses :: CrucibleType -> * where
8044+
SeenDetVarsClauses :: [DetVarsClause] -> SeenDetVarsClauses tp
8045+
80438046
-- | Generic function to compute the 'DetVarsClause's for a permission
80448047
class GetDetVarsClauses a where
80458048
getDetVarsClauses ::
8046-
a -> ReaderT (PermSet ps) (State (NameSet CrucibleType)) [DetVarsClause]
8049+
a -> ReaderT (PermSet ps) (State (NameMap SeenDetVarsClauses))
8050+
[DetVarsClause]
80478051

80488052
instance GetDetVarsClauses a => GetDetVarsClauses [a] where
80498053
getDetVarsClauses l = concat <$> mapM getDetVarsClauses l
@@ -8055,11 +8059,13 @@ instance GetDetVarsClauses (ExprVar a) where
80558059
getDetVarsClauses x =
80568060
do seen_vars <- get
80578061
perms <- ask
8058-
if NameSet.member x seen_vars then return [] else
8059-
do modify (NameSet.insert x)
8060-
perm_clauses <- getDetVarsClauses (perms ^. varPerm x)
8061-
return (DetVarsClause NameSet.empty (SomeName x) :
8062-
map (detVarsClauseAddLHSVar x) perm_clauses)
8062+
perm_clauses <- case NameMap.lookup x seen_vars of
8063+
Just (SeenDetVarsClauses perm_clauses) -> return perm_clauses
8064+
Nothing -> do perm_clauses <- getDetVarsClauses (perms ^. varPerm x)
8065+
modify (NameMap.insert x (SeenDetVarsClauses perm_clauses))
8066+
return perm_clauses
8067+
return (DetVarsClause NameSet.empty (SomeName x) :
8068+
map (detVarsClauseAddLHSVar x) perm_clauses)
80638069

80648070
instance GetDetVarsClauses (PermExpr a) where
80658071
getDetVarsClauses e
@@ -8131,7 +8137,7 @@ instance GetDetVarsClauses (LLVMFieldShape w) where
81318137
-- | Compute the 'DetVarsClause's for a block permission with the given shape
81328138
getShapeDetVarsClauses ::
81338139
(1 <= w, KnownNat w) => PermExpr (LLVMShapeType w) ->
8134-
ReaderT (PermSet ps) (State (NameSet CrucibleType)) [DetVarsClause]
8140+
ReaderT (PermSet ps) (State (NameMap SeenDetVarsClauses)) [DetVarsClause]
81358141
getShapeDetVarsClauses (PExpr_Var x) =
81368142
getDetVarsClauses x
81378143
getShapeDetVarsClauses (PExpr_NamedShape _ _ _ args) =
@@ -8157,20 +8163,23 @@ getShapeDetVarsClauses _ = return []
81578163
-- is always a uniquely determined value of @y@ for any proof of @exists y.x:p@.
81588164
determinedVars :: PermSet ps -> RAssign ExprVar ns -> [SomeName CrucibleType]
81598165
determinedVars top_perms vars =
8160-
let vars_set = NameSet.fromList $ mapToList SomeName vars
8166+
let vars_map = NameMap.fromList $
8167+
mapToList (\v -> NameAndElem v (SeenDetVarsClauses [])) vars
8168+
vars_set = NameSet.fromList $ mapToList SomeName vars
81618169
multigraph =
81628170
evalState (runReaderT (getDetVarsClauses (distPermsToValuePerms $
81638171
varPermsMulti vars top_perms))
81648172
top_perms)
8165-
vars_set in
8173+
vars_map in
81668174
evalState (determinedVarsForGraph multigraph) vars_set
81678175
where
81688176
-- Find all variables that are not already marked as determined in our
81698177
-- NameSet state but that are determined given the current determined
8170-
-- variables, mark these variables as determiend, and then repeat, returning
8178+
-- variables, mark these variables as determined, and then repeat, returning
81718179
-- all variables that are found in order
81728180
determinedVarsForGraph :: [DetVarsClause] ->
8173-
State (NameSet CrucibleType) [SomeName CrucibleType]
8181+
State (NameSet CrucibleType)
8182+
[SomeName CrucibleType]
81748183
determinedVarsForGraph graph =
81758184
do det_vars <- concat <$> mapM determinedVarsForClause graph
81768185
if det_vars == [] then return [] else
@@ -8179,7 +8188,8 @@ determinedVars top_perms vars =
81798188
-- If the LHS of a clause has become determined but its RHS is not, return
81808189
-- its RHS, otherwise return nothing
81818190
determinedVarsForClause :: DetVarsClause ->
8182-
State (NameSet CrucibleType) [SomeName CrucibleType]
8191+
State (NameSet CrucibleType)
8192+
[SomeName CrucibleType]
81838193
determinedVarsForClause (DetVarsClause lhs_vars (SomeName rhs_var)) =
81848194
do det_vars <- get
81858195
if not (NameSet.member rhs_var det_vars) &&

0 commit comments

Comments
 (0)