Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Make ruleOfProp return a Maybe instead of calling error.
Browse files Browse the repository at this point in the history
This is to facilitate a fix for GaloisInc/saw-script#319.
  • Loading branch information
Brian Huffman committed Dec 9, 2020
1 parent 6a70bf3 commit b18f1a8
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions saw-core/src/Verifier/SAW/Rewriter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -299,27 +299,30 @@ ruleOfTerm t =
ruleOfTerms :: Term -> Term -> RewriteRule
ruleOfTerms l r = RewriteRule { ctxt = [], lhs = l, rhs = r }

-- | Converts a parameterized equality predicate to a RewriteRule.
ruleOfProp :: Term -> RewriteRule
-- | Converts a parameterized equality predicate to a RewriteRule,
-- returning 'Nothing' if the predicate is not an equation.
ruleOfProp :: Term -> Maybe RewriteRule
ruleOfProp (R.asPi -> Just (_, ty, body)) =
let rule = ruleOfProp body in rule { ctxt = ty : ctxt rule }
do rule <- ruleOfProp body
Just $ rule { ctxt = ty : ctxt rule }
ruleOfProp (R.asLambda -> Just (_, ty, body)) =
let rule = ruleOfProp body in rule { ctxt = ty : ctxt rule }
do rule <- ruleOfProp body
Just $ rule { ctxt = ty : ctxt rule }
ruleOfProp (R.asApplyAll -> (R.isGlobalDef eqIdent' -> Just (), [_, x, y])) =
RewriteRule { ctxt = [], lhs = x, rhs = y }
Just $ RewriteRule { ctxt = [], lhs = x, rhs = y }
ruleOfProp (R.asApplyAll -> (R.isGlobalDef ecEqIdent -> Just (), [_, _, x, y])) =
RewriteRule { ctxt = [], lhs = x, rhs = y }
Just $ RewriteRule { ctxt = [], lhs = x, rhs = y }
ruleOfProp (R.asApplyAll -> (R.isGlobalDef bvEqIdent -> Just (), [_, x, y])) =
RewriteRule { ctxt = [], lhs = x, rhs = y }
Just $ RewriteRule { ctxt = [], lhs = x, rhs = y }
ruleOfProp (R.asApplyAll -> (R.isGlobalDef boolEqIdent -> Just (), [x, y])) =
RewriteRule { ctxt = [], lhs = x, rhs = y }
Just $ RewriteRule { ctxt = [], lhs = x, rhs = y }
ruleOfProp (R.asApplyAll -> (R.isGlobalDef vecEqIdent -> Just (), [_, _, _, x, y])) =
RewriteRule { ctxt = [], lhs = x, rhs = y }
Just $ RewriteRule { ctxt = [], lhs = x, rhs = y }
ruleOfProp (unwrapTermF -> Constant _ body) = ruleOfProp body
ruleOfProp (R.asEq -> Just (_, x, y)) =
RewriteRule { ctxt = [], lhs = x, rhs = y }
Just $ RewriteRule { ctxt = [], lhs = x, rhs = y }
ruleOfProp (R.asEqTrue -> Just body) = ruleOfProp body
ruleOfProp t = error $ "ruleOfProp: Predicate not an equation: " ++ scPrettyTerm defaultPPOpts t
ruleOfProp _ = Nothing

-- | Generate a rewrite rule from the type of an identifier, using 'ruleOfTerm'
scEqRewriteRule :: SharedContext -> Ident -> IO RewriteRule
Expand Down

0 comments on commit b18f1a8

Please sign in to comment.