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

Normalize Cryptol types on import #1790

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
6 changes: 4 additions & 2 deletions cryptol-saw-core/src/Verifier/SAW/Cryptol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import qualified Cryptol.Eval.Value as V
import qualified Cryptol.Eval.Concrete as V
import Cryptol.Eval.Type (evalValType)
import qualified Cryptol.TypeCheck.AST as C
import qualified Cryptol.TypeCheck.SimpType as ST
import qualified Cryptol.TypeCheck.Subst as C (Subst, apSubst, listSubst, singleTParamSubst)
import qualified Cryptol.ModuleSystem.Name as C
(asPrim, asParamName, nameUnique, nameIdent, nameInfo, NameInfo(..))
Expand Down Expand Up @@ -230,10 +231,11 @@ importPC sc pc =
C.PFLiteral -> panic "importPC PFLiteral" []
C.PValidFloat -> panic "importPC PValidFloat" []

-- | Translate size types to SAW values of type Num, value types to SAW types of sort 0.
-- | Normalize according to Cryptol's rules, then translate size types to SAW
-- values of type Num and value types to SAW types of sort 0.
importType :: SharedContext -> Env -> C.Type -> IO Term
importType sc env ty =
case ty of
case ST.tRebuild ty of
C.TVar tvar ->
case tvar of
C.TVFree{} {- Int Kind (Set TVar) Doc -} -> unimplemented "TVFree"
Expand Down
7 changes: 7 additions & 0 deletions intTests/test_join_split/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This test addresses the issue resolved in [#1790](https://github.com/GaloisInc/saw-script/pull/1790).

In this script, we prove the same theorem - that ```join`{each=32, parts=4, a=Bool} (split x) == x``` - twice; once purely via `z3`, and once via manual rewriting, trying to use the former to prove the latter.

Lack of type normalization introduces reflexive type coercions in the SAWCore representation of the expression under proof. The manual proof proceeds by eliminating any extant reflexive coercions, then attempting to use the `z3`-proven theorem as a simplification. When no coercions existed in the first place, the simplification applies cleanly. When coercions existed, the simplification does not apply cleanly, since we eliminated them from the goal, but not from the simplification.

Since this proof is possible to resolve in its entirety via evaluation/appeal to `z3`, we need to maintain the core `join` and `split` functions uninterpreted when manually massaging (via `goal_normalize` and `goal_eval_unint`) the goal into a `trivial`ly resolvable form.
10 changes: 10 additions & 0 deletions intTests/test_join_split/join_split.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enable_experimental; // for `goal_normalize`

join_split_thm_z3 <- prove_print z3 {{ \x -> join`{each=32, parts=4, a=Bool} (split x) == x }};

join_split_thm_manual <- prove_print (do {
goal_normalize ["ecJoin", "ecSplit"];
simplify (addsimp join_split_thm_z3 empty_ss);
goal_eval_unint ["ecJoin", "ecSplit"];
trivial;
}) {{ \x -> join`{each=32, parts=4, a=Bool} (split x) == x }};
3 changes: 3 additions & 0 deletions intTests/test_join_split/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

$SAW join_split.saw