@@ -953,50 +953,52 @@ applyEquation term rule = withRuleContext rule $ fmap (either Failure Success) $
953
953
$ " Substitution:"
954
954
<+> (hsep $ intersperse " ," $ map (\ (k, v) -> pretty k <+> " ->" <+> pretty v) $ Map. toList subst)
955
955
956
- -- check required conditions, using substitution
956
+ -- instantiate the requires clause with the obtained substitution
957
957
let required =
958
958
concatMap
959
959
(splitBoolPredicates . coerce . substituteInTerm subst . coerce)
960
960
rule. requires
961
961
-- If the required condition is _syntactically_ present in
962
962
-- the prior (known constraints), we don't check it.
963
963
knownPredicates <- (. predicates) <$> lift getState
964
- let (knownTrue, toCheck) = partition (`Set.member` knownPredicates) required
965
- unless (null knownTrue) $
966
- logMessage $
967
- renderOneLineText $
968
- " Known true side conditions (won't check):" <+> hsep (intersperse " ," $ map pretty knownTrue)
964
+ toCheck <- lift $ filterOutKnownConstraints knownPredicates required
965
+
966
+ -- check the filtered requires clause conditions
967
+ unclearConditions <- catMaybes <$> mapM (checkConstraint ConditionFalse ) toCheck
969
968
970
969
-- unclear conditions may have been simplified and
971
- -- could now be syntactically present in the path constraints, check again
972
- -- FIXME: factor this filtering out into a function ans use above
973
- unclearConditions' <- catMaybes <$> mapM (checkConstraint ConditionFalse ) toCheck
974
- let (newKnownTrue, stillUnclear) = partition (`Set.member` knownPredicates) unclearConditions'
975
- unless (null newKnownTrue) $
976
- logMessage $
977
- renderOneLineText $
978
- " Known true side conditions (won't check):" <+> hsep (intersperse " ," $ map pretty knownTrue)
979
-
980
- case stillUnclear of
981
- [] -> do
982
- -- check ensured conditions, filter any
983
- -- true ones, prune if any is false
984
- let ensured =
985
- concatMap
986
- (splitBoolPredicates . substituteInPredicate subst)
987
- (Set. toList rule. ensures)
988
- ensuredConditions <-
989
- -- throws if an ensured condition found to be false
990
- catMaybes <$> mapM (checkConstraint EnsuresFalse ) ensured
991
- lift $ pushConstraints $ Set. fromList ensuredConditions
992
- pure $ substituteInTerm subst rule. rhs
993
- unclearConditions -> do
994
- withContext " failure" $
995
- logMessage $
996
- renderOneLineText $
997
- " Uncertain about a condition(s) in rule:" <+> hsep (intersperse " ," $ map pretty unclearConditions)
998
- throwE $ IndeterminateCondition unclearConditions
970
+ -- could now be syntactically present in the path constraints, filter again
971
+ stillUnclear <- lift $ filterOutKnownConstraints knownPredicates unclearConditions
972
+
973
+ -- abort if any of the conditions is still unclear at that point
974
+ unless (null stillUnclear) $ do
975
+ withContext " failure" $
976
+ logMessage $
977
+ renderOneLineText $
978
+ " Uncertain about a condition(s) in rule:" <+> hsep (intersperse " ," $ map pretty stillUnclear)
979
+ throwE $ IndeterminateCondition unclearConditions
980
+
981
+ -- check ensured conditions, filter any
982
+ -- true ones, prune if any is false
983
+ let ensured =
984
+ concatMap
985
+ (splitBoolPredicates . substituteInPredicate subst)
986
+ (Set. toList rule. ensures)
987
+ ensuredConditions <-
988
+ -- throws if an ensured condition found to be false
989
+ catMaybes <$> mapM (checkConstraint EnsuresFalse ) ensured
990
+ lift $ pushConstraints $ Set. fromList ensuredConditions
991
+ pure $ substituteInTerm subst rule. rhs
999
992
where
993
+ filterOutKnownConstraints :: Set Predicate -> [Predicate ] -> EquationT io [Predicate ]
994
+ filterOutKnownConstraints priorKnowledge constraitns = do
995
+ let (knownTrue, toCheck) = partition (`Set.member` priorKnowledge) constraitns
996
+ unless (null knownTrue) $
997
+ logMessage $
998
+ renderOneLineText $
999
+ " Known true side conditions (won't check):" <+> hsep (intersperse " ," $ map pretty knownTrue)
1000
+ pure toCheck
1001
+
1000
1002
-- Simplify given predicate in a nested EquationT execution.
1001
1003
-- Call 'whenBottom' if it is Bottom, return Nothing if it is Top,
1002
1004
-- otherwise return the simplified remaining predicate.
0 commit comments