@@ -872,50 +872,52 @@ applyEquation term rule = fmap (either Failure Success) $ runExceptT $ do
872
872
$ " Substitution:"
873
873
<+> (hsep $ intersperse " ," $ map (\ (k, v) -> pretty k <+> " ->" <+> pretty v) $ Map. toList subst)
874
874
875
- -- check required conditions, using substitution
875
+ -- instantiate the requires clause with the obtained substitution
876
876
let required =
877
877
concatMap
878
878
(splitBoolPredicates . coerce . substituteInTerm subst . coerce)
879
879
rule. requires
880
880
-- If the required condition is _syntactically_ present in
881
881
-- the prior (known constraints), we don't check it.
882
882
knownPredicates <- (. predicates) <$> lift getState
883
- let (knownTrue, toCheck) = partition (`Set.member` knownPredicates) required
884
- unless (null knownTrue) $
885
- logMessage $
886
- renderOneLineText $
887
- " Known true side conditions (won't check):" <+> hsep (intersperse " ," $ map pretty knownTrue)
883
+ toCheck <- lift $ filterOutKnownConstraints knownPredicates required
884
+
885
+ -- check the filtered requires clause conditions
886
+ unclearConditions <- catMaybes <$> mapM (checkConstraint ConditionFalse ) toCheck
888
887
889
888
-- unclear conditions may have been simplified and
890
- -- could now be syntactically present in the path constraints, check again
891
- -- FIXME: factor this filtering out into a function ans use above
892
- unclearConditions' <- catMaybes <$> mapM (checkConstraint ConditionFalse ) toCheck
893
- let (newKnownTrue, stillUnclear) = partition (`Set.member` knownPredicates) unclearConditions'
894
- unless (null newKnownTrue) $
895
- logMessage $
896
- renderOneLineText $
897
- " Known true side conditions (won't check):" <+> hsep (intersperse " ," $ map pretty knownTrue)
898
-
899
- case stillUnclear of
900
- [] -> do
901
- -- check ensured conditions, filter any
902
- -- true ones, prune if any is false
903
- let ensured =
904
- concatMap
905
- (splitBoolPredicates . substituteInPredicate subst)
906
- (Set. toList rule. ensures)
907
- ensuredConditions <-
908
- -- throws if an ensured condition found to be false
909
- catMaybes <$> mapM (checkConstraint EnsuresFalse ) ensured
910
- lift $ pushConstraints $ Set. fromList ensuredConditions
911
- pure $ substituteInTerm subst rule. rhs
912
- unclearConditions -> do
913
- withContext " failure" $
914
- logMessage $
915
- renderOneLineText $
916
- " Uncertain about a condition(s) in rule:" <+> hsep (intersperse " ," $ map pretty unclearConditions)
917
- throwE $ IndeterminateCondition unclearConditions
889
+ -- could now be syntactically present in the path constraints, filter again
890
+ stillUnclear <- lift $ filterOutKnownConstraints knownPredicates unclearConditions
891
+
892
+ -- abort if any of the conditions is still unclear at that point
893
+ unless (null stillUnclear) $ do
894
+ withContext " failure" $
895
+ logMessage $
896
+ renderOneLineText $
897
+ " Uncertain about a condition(s) in rule:" <+> hsep (intersperse " ," $ map pretty stillUnclear)
898
+ throwE $ IndeterminateCondition unclearConditions
899
+
900
+ -- check ensured conditions, filter any
901
+ -- true ones, prune if any is false
902
+ let ensured =
903
+ concatMap
904
+ (splitBoolPredicates . substituteInPredicate subst)
905
+ (Set. toList rule. ensures)
906
+ ensuredConditions <-
907
+ -- throws if an ensured condition found to be false
908
+ catMaybes <$> mapM (checkConstraint EnsuresFalse ) ensured
909
+ lift $ pushConstraints $ Set. fromList ensuredConditions
910
+ pure $ substituteInTerm subst rule. rhs
918
911
where
912
+ filterOutKnownConstraints :: Set Predicate -> [Predicate ] -> EquationT io [Predicate ]
913
+ filterOutKnownConstraints priorKnowledge constraitns = do
914
+ let (knownTrue, toCheck) = partition (`Set.member` priorKnowledge) constraitns
915
+ unless (null knownTrue) $
916
+ logMessage $
917
+ renderOneLineText $
918
+ " Known true side conditions (won't check):" <+> hsep (intersperse " ," $ map pretty knownTrue)
919
+ pure toCheck
920
+
919
921
-- Simplify given predicate in a nested EquationT execution.
920
922
-- Call 'whenBottom' if it is Bottom, return Nothing if it is Top,
921
923
-- otherwise return the simplified remaining predicate.
0 commit comments