Skip to content

Commit 454bc12

Browse files
committed
checkImplication: Return CheckImplicationResult
The function checkImplication returns a CheckImplicationResult instead of a ProofState. This follows a principle from domain-driven design: the function indicates its own result (CheckImplicationResult) instead of telling the caller what to do next (ProofState). The code is more flexible because checkImplication now does not need to know anything about the caller.
1 parent cfe274a commit 454bc12

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

kore/src/Kore/Strategies/Goal.hs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Kore.Strategies.Goal
99
, ClaimExtractor (..)
1010
, TransitionRuleTemplate (..)
1111
, WithConfiguration (..)
12+
, CheckImplicationResult (..)
1213
, extractClaims
1314
, unprovenNodes
1415
, proven
@@ -542,9 +543,8 @@ data TransitionRuleTemplate monad goal =
542543
{ simplifyTemplate
543544
:: goal -> Strategy.TransitionT (Rule goal) monad goal
544545
, checkImplicationTemplate
545-
:: (forall x. x -> ProofState x)
546-
-> goal
547-
-> Strategy.TransitionT (Rule goal) monad (ProofState goal)
546+
:: goal
547+
-> Strategy.TransitionT (Rule goal) monad (CheckImplicationResult goal)
548548
, isTriviallyValidTemplate :: goal -> Bool
549549
, deriveParTemplate
550550
:: [Rule goal]
@@ -624,11 +624,19 @@ transitionRuleTemplate
624624
$ GoalRemainder <$> simplifyTemplate goal
625625

626626
transitionRuleWorker CheckImplication (Goal goal) =
627-
Profile.timeStrategy "Goal.CheckImplication"
628-
$ checkImplicationTemplate Goal goal
627+
Profile.timeStrategy "Goal.CheckImplication" $ do
628+
result <- checkImplicationTemplate goal
629+
case result of
630+
NotImpliedStuck a -> pure (GoalStuck a)
631+
Implied -> pure Proven
632+
NotImplied a -> pure (Goal a)
629633
transitionRuleWorker CheckImplication (GoalRemainder goal) =
630-
Profile.timeStrategy "Goal.CheckImplicationRemainder"
631-
$ checkImplicationTemplate GoalRemainder goal
634+
Profile.timeStrategy "Goal.CheckImplicationRemainder" $ do
635+
result <- checkImplicationTemplate goal
636+
case result of
637+
NotImpliedStuck a -> pure (GoalStuck a)
638+
Implied -> pure Proven
639+
NotImplied a -> pure (GoalRemainder a)
632640

633641
transitionRuleWorker TriviallyValid (Goal goal)
634642
| isTriviallyValidTemplate goal =
@@ -756,28 +764,44 @@ allPathFollowupStep claims axiomGroups =
756764
, TriviallyValid
757765
]
758766

767+
{- | The result of checking the direct implication of a proof goal.
768+
769+
As an optimization, 'checkImplication' returns 'NotImpliedStuck' when the
770+
implication between /terms/ is valid, but the implication between side
771+
conditions does not hold.
772+
773+
-}
774+
data CheckImplicationResult a
775+
= Implied
776+
-- ^ The implication is valid.
777+
| NotImplied !a
778+
-- ^ The implication is not valid.
779+
| NotImpliedStuck !a
780+
-- ^ The implication between /terms/ is valid, but the implication between
781+
-- side-conditions is not valid.
782+
deriving (Functor)
783+
759784
-- | Remove the destination of the goal.
760785
checkImplication
761786
:: forall goal m
762787
. MonadSimplify m
763788
=> MonadCatch m
764789
=> Lens' goal (RulePattern VariableName)
765-
-> (forall x. x -> ProofState x)
766790
-> goal
767-
-> Strategy.TransitionT (Rule goal) m (ProofState goal)
768-
checkImplication lensRulePattern mkState goal =
791+
-> Strategy.TransitionT (Rule goal) m (CheckImplicationResult goal)
792+
checkImplication lensRulePattern goal =
769793
goal
770794
& Lens.traverseOf lensRulePattern (Compose . checkImplicationWorker)
771795
& getCompose
772796
& lift
773797
where
774798
checkImplicationWorker
775799
:: RulePattern VariableName
776-
-> m (ProofState (RulePattern VariableName))
800+
-> m (CheckImplicationResult (RulePattern VariableName))
777801
checkImplicationWorker (snd . Step.refreshRule mempty -> rulePattern) =
778802
do
779803
removal <- removalPatterns destination configuration existentials
780-
when (isTop removal) (succeed . mkState $ rulePattern)
804+
when (isTop removal) (succeed . NotImplied $ rulePattern)
781805
let configAndRemoval = fmap (configuration <*) removal
782806
sideCondition =
783807
Pattern.withoutTerm configuration
@@ -786,11 +810,11 @@ checkImplication lensRulePattern mkState goal =
786810
simplifyConditionsWithSmt
787811
sideCondition
788812
configAndRemoval
789-
when (isBottom simplifiedRemoval) (succeed Proven)
813+
when (isBottom simplifiedRemoval) (succeed Implied)
790814
let stuckConfiguration = OrPattern.toPattern simplifiedRemoval
791815
rulePattern
792816
& Lens.set RulePattern.leftPattern stuckConfiguration
793-
& GoalStuck
817+
& NotImpliedStuck
794818
& pure
795819
& run
796820
& withConfiguration configuration

kore/test/Test/Kore/Strategies/AllPath/AllPath.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,11 @@ instance Diff (Goal.Rule Goal)
378378

379379
-- | The destination-removal rule for our unit test goal.
380380
checkImplication
381-
:: (Goal -> ProofState)
382-
-> Goal
383-
-> Strategy.TransitionT (Goal.Rule Goal) m ProofState
384-
checkImplication constr (src, dst) =
385-
return . constr $ (difference src dst, dst)
381+
:: Goal
382+
-> Strategy.TransitionT (Goal.Rule Goal) m
383+
(Goal.CheckImplicationResult Goal)
384+
checkImplication (src, dst) =
385+
return . Goal.NotImplied $ (difference src dst, dst)
386386

387387
-- | The goal is trivially valid when the members are equal.
388388
isTriviallyValid :: Goal -> Bool

0 commit comments

Comments
 (0)