Skip to content

Commit 1c6f64a

Browse files
committed
Use left-to-right rule recognition style without top-level pattern-matching
1 parent 743cce7 commit 1c6f64a

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

saw-core/src/Verifier/SAW/Rewriter.hs

+26-31
Original file line numberDiff line numberDiff line change
@@ -359,37 +359,32 @@ ruleOfTerms l r = mkRewriteRule [] l r False Nothing
359359
-- | Converts a parameterized equality predicate to a RewriteRule,
360360
-- returning 'Nothing' if the predicate is not an equation.
361361
ruleOfProp :: SharedContext -> Term -> Maybe a -> IO (Maybe (RewriteRule a))
362-
ruleOfProp sc term ann
363-
| Just (_, ty, body) <- R.asPi term =
364-
do rule <- ruleOfProp sc body ann
365-
pure $ (\r -> r { ctxt = ty : ctxt r }) <$> rule
366-
| Just (_, ty, body) <- R.asLambda term =
367-
do rule <- ruleOfProp sc body ann
368-
pure $ (\r -> r { ctxt = ty : ctxt r }) <$> rule
369-
| (R.isGlobalDef ecEqIdent -> Just (), [_, _, x, y]) <- R.asApplyAll term =
370-
pure $ Just $ mkRewriteRule [] x y False ann
371-
| (R.isGlobalDef bvEqIdent -> Just (), [_, x, y]) <- R.asApplyAll term =
372-
pure $ Just $ mkRewriteRule [] x y False ann
373-
| (R.isGlobalDef equalNatIdent -> Just (), [x, y]) <- R.asApplyAll term =
374-
pure $ Just $ mkRewriteRule [] x y False ann
375-
| (R.isGlobalDef boolEqIdent -> Just (), [x, y]) <- R.asApplyAll term =
376-
pure $ Just $ mkRewriteRule [] x y False ann
377-
| (R.isGlobalDef vecEqIdent -> Just (), [_, _, _, x, y]) <- R.asApplyAll term =
378-
pure $ Just $ mkRewriteRule [] x y False ann
379-
| (R.isGlobalDef arrayEqIdent -> Just (), [_, _, x, y]) <- R.asApplyAll term =
380-
pure $ Just $ mkRewriteRule [] x y False ann
381-
| (R.isGlobalDef intEqIdent -> Just (), [x, y]) <- R.asApplyAll term =
382-
pure $ Just $ mkRewriteRule [] x y False ann
383-
| (R.isGlobalDef intModEqIdent -> Just (), [_, x, y]) <- R.asApplyAll term =
384-
pure $ Just $ mkRewriteRule [] x y False ann
385-
| Constant _ (Just body) <- unwrapTermF term = ruleOfProp sc body ann
386-
| Just (_, x, y) <- R.asEq term =
387-
pure $ Just $ mkRewriteRule [] x y False ann
388-
| Just body <- R.asEqTrue term = ruleOfProp sc body ann
389-
| (R.asConstant -> Just (_, Just body), as) <- R.asApplyAll term =
390-
do app <- scApplyAllBeta sc body as
391-
ruleOfProp sc app ann
392-
| otherwise = pure Nothing
362+
ruleOfProp sc term ann =
363+
case term of
364+
(R.asPi -> Just (_, ty, body)) ->
365+
do rule <- ruleOfProp sc body ann
366+
pure $ (\r -> r { ctxt = ty : ctxt r }) <$> rule
367+
(R.asLambda -> Just (_, ty, body)) ->
368+
do rule <- ruleOfProp sc body ann
369+
pure $ (\r -> r { ctxt = ty : ctxt r }) <$> rule
370+
(R.asApplyAll -> (R.isGlobalDef ecEqIdent -> Just (), [_, _, x, y])) -> eqRule x y
371+
(R.asApplyAll -> (R.isGlobalDef bvEqIdent -> Just (), [_, x, y])) -> eqRule x y
372+
(R.asApplyAll -> (R.isGlobalDef equalNatIdent -> Just (), [x, y])) -> eqRule x y
373+
(R.asApplyAll -> (R.isGlobalDef boolEqIdent -> Just (), [x, y])) -> eqRule x y
374+
(R.asApplyAll -> (R.isGlobalDef vecEqIdent -> Just (), [_, _, _, x, y])) -> eqRule x y
375+
(R.asApplyAll -> (R.isGlobalDef arrayEqIdent -> Just (), [_, _, x, y])) -> eqRule x y
376+
(R.asApplyAll -> (R.isGlobalDef intEqIdent -> Just (), [x, y])) -> eqRule x y
377+
(R.asApplyAll -> (R.isGlobalDef intModEqIdent -> Just (), [_, x, y])) -> eqRule x y
378+
(unwrapTermF -> Constant _ (Just body)) -> ruleOfProp sc body ann
379+
(R.asEq -> Just (_, x, y)) -> eqRule x y
380+
(R.asEqTrue -> Just body) -> ruleOfProp sc body ann
381+
(R.asApplyAll -> (R.asConstant -> Just (_, Just body), args)) ->
382+
do app <- scApplyAllBeta sc body args
383+
ruleOfProp sc app ann
384+
_ -> pure Nothing
385+
386+
where
387+
eqRule x y = pure $ Just $ mkRewriteRule [] x y False ann
393388

394389
-- | Generate a rewrite rule from the type of an identifier, using 'ruleOfTerm'
395390
scEqRewriteRule :: SharedContext -> Ident -> IO (RewriteRule a)

0 commit comments

Comments
 (0)