Skip to content

Commit

Permalink
Handle TError in constrant guard translator (#1935)
Browse files Browse the repository at this point in the history
When using constraint guards in instantiations of parameterized modules,
Cryptol may replace impossible constraints with `TError`. To support
this behavior, this change adds a case to
`importNumericConstraintAsBool` that translates those `TError` constraints
to `False`. This is consistent with
[`checkProp` in Cryptol](https://github.com/GaloisInc/cryptol/blob/3973b15236ace5c11fdfabbf811d97daee7885ed/src/Cryptol/Eval.hs#L247),
which is the Cryptol function that handles evaluation of constraint
guard constraints.
  • Loading branch information
bboston7 authored Sep 7, 2023
1 parent 4c0985c commit ed0af53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions cryptol-saw-core/src/Verifier/SAW/Cryptol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ importNumericConstraintAsBool sc env prop =
rhs' <- importType sc env rhs
scAnd sc lhs' rhs'
C.TCon (C.PC C.PTrue) [] -> scBool sc True
C.TCon (C.TError _) _ -> scBool sc False
C.TUser _ _ t -> importNumericConstraintAsBool sc env t
_ -> panic
"importNumericConstraintAsBool"
Expand Down
6 changes: 5 additions & 1 deletion intTests/test_constraint_guards/Parameterized.cry
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ parameter

// Constraint guard with type dependent on module parameter value
v : [gamma]
v | () => 0
v | (gamma == 3) => 0
// Cryptol replaces this next constraint with `TError 3 == 2` when
// instantiating `Instantiated.cry`
| (gamma == 2) => 1
| () => 2

0 comments on commit ed0af53

Please sign in to comment.