@@ -4,7 +4,9 @@ License : NCSA
44-}
55module Kore.Reachability.Claim
66 ( Claim (.. )
7+ , ApplyResult (.. )
78 , AppliedRule (.. )
9+ , retractApplyRemainder
810 , strategy
911 , TransitionRule
1012 , Prim
@@ -110,7 +112,6 @@ import Kore.Log.WarnStuckClaimState
110112import Kore.Reachability.ClaimState hiding
111113 ( claimState
112114 )
113- import qualified Kore.Reachability.ClaimState as ClaimState
114115import Kore.Reachability.Prim
115116import Kore.Rewriting.RewritingVariable
116117import Kore.Step.AxiomPattern
@@ -182,30 +183,32 @@ class Claim claim where
182183 => claim
183184 -> Strategy. TransitionT (AppliedRule claim ) m claim
184185
185- {- TODO (thomas.tuegel): applyClaims and applyAxioms should return:
186-
187- > data ApplyResult claim
188- > = ApplyRewritten !claim
189- > | ApplyRemainder !claim
190-
191- Rationale: ClaimState is part of the implementation of transitionRule, that
192- is: these functions have hidden knowledge of how transitionRule works
193- because they tell it what to do next. Instead, they should report their
194- result and leave the decision up to transitionRule.
195-
196- -}
197186 applyClaims
198187 :: MonadSimplify m
199188 => [claim ]
200189 -> claim
201- -> Strategy. TransitionT (AppliedRule claim ) m (ClaimState claim )
190+ -> Strategy. TransitionT (AppliedRule claim ) m (ApplyResult claim )
202191
203192 applyAxioms
204193 :: MonadSimplify m
205194 => [[Rule claim ]]
206195 -> claim
207- -> Strategy. TransitionT (AppliedRule claim ) m (ClaimState claim )
196+ -> Strategy. TransitionT (AppliedRule claim ) m (ApplyResult claim )
197+
198+ {- | 'ApplyResult' is the result of a rewriting step, like 'applyClaims' or 'applyAxioms'.
208199
200+ Both 'ApplyRewritten' and 'ApplyRemainder' wrap a newly formed claim.
201+ Its left hand side is constructed from either the application of rewrite rules,
202+ or, respectively, from the remainder resulting after this procedure.
203+ -}
204+ data ApplyResult claim
205+ = ApplyRewritten ! claim
206+ | ApplyRemainder ! claim
207+ deriving (Show , Eq )
208+ deriving (Functor )
209+
210+ {- | 'AppliedRule' represents the rule applied during a rewriting step.
211+ -}
209212data AppliedRule claim
210213 = AppliedAxiom (Rule claim )
211214 | AppliedClaim claim
@@ -271,7 +274,7 @@ deriveSeqClaim
271274 -> (ClaimPattern -> claim )
272275 -> [claim ]
273276 -> claim
274- -> Strategy. TransitionT (AppliedRule claim ) m (ClaimState claim )
277+ -> Strategy. TransitionT (AppliedRule claim ) m (ApplyResult claim )
275278deriveSeqClaim lensClaimPattern mkClaim claims claim =
276279 getCompose
277280 $ Lens. forOf lensClaimPattern claim
@@ -336,32 +339,30 @@ transitionRule claims axiomGroups = transitionRuleWorker
336339 | otherwise -> pure (Claimed a)
337340 | otherwise = pure claimState
338341
339- -- TODO (virgil): Wrap the results in GoalRemainder/GoalRewritten here.
340- --
341- -- thomas.tuegel: "Here" is in ApplyClaims and ApplyAxioms.
342- --
343- -- Note that in most transitions it is obvious what is being transformed
344- -- into what, e.g. that a `ResetGoal` transition transforms
345- -- `GoalRewritten` into `Goal`. However, here we're taking a `Goal`
346- -- and transforming it into `GoalRewritten` and `GoalRemainder` in an
347- -- opaque way. I think that there's no good reason for wrapping the
348- -- results in `derivePar` as opposed to here.
349-
350342 transitionRuleWorker ApplyClaims (Claimed claim) =
351343 applyClaims claims claim
344+ >>= return . applyResultToClaimState
352345 transitionRuleWorker ApplyClaims claimState = pure claimState
353346
354347 transitionRuleWorker ApplyAxioms claimState
355348 | Just claim <- retractRewritable claimState =
356349 applyAxioms axiomGroups claim
350+ >>= return . applyResultToClaimState
357351 | otherwise = pure claimState
358352
353+ applyResultToClaimState (ApplyRewritten a) = Rewritten a
354+ applyResultToClaimState (ApplyRemainder a) = Remaining a
355+
359356retractSimplifiable :: ClaimState a -> Maybe a
360357retractSimplifiable (Claimed a) = Just a
361358retractSimplifiable (Rewritten a) = Just a
362359retractSimplifiable (Remaining a) = Just a
363360retractSimplifiable _ = Nothing
364361
362+ retractApplyRemainder :: ApplyResult a -> Maybe a
363+ retractApplyRemainder (ApplyRemainder a) = Just a
364+ retractApplyRemainder _ = Nothing
365+
365366isRemainder :: ClaimState a -> Bool
366367isRemainder (Remaining _) = True
367368isRemainder _ = False
@@ -650,7 +651,7 @@ derivePar'
650651 -> (RewriteRule RewritingVariableName -> Rule claim )
651652 -> [RewriteRule RewritingVariableName ]
652653 -> claim
653- -> Strategy. TransitionT (AppliedRule claim ) m (ClaimState claim )
654+ -> Strategy. TransitionT (AppliedRule claim ) m (ApplyResult claim )
654655derivePar' lensRulePattern mkRule =
655656 deriveWith lensRulePattern mkRule
656657 $ Step. applyRewriteRulesParallel Unification. unificationProcedure
@@ -669,7 +670,7 @@ deriveWith
669670 -> Deriver m
670671 -> [RewriteRule RewritingVariableName ]
671672 -> claim
672- -> Strategy. TransitionT (AppliedRule claim ) m (ClaimState claim )
673+ -> Strategy. TransitionT (AppliedRule claim ) m (ApplyResult claim )
673674deriveWith lensClaimPattern mkRule takeStep rewrites claim =
674675 getCompose
675676 $ Lens. forOf lensClaimPattern claim
@@ -694,7 +695,7 @@ deriveSeq'
694695 -> (RewriteRule RewritingVariableName -> Rule claim )
695696 -> [RewriteRule RewritingVariableName ]
696697 -> claim
697- -> Strategy. TransitionT (AppliedRule claim ) m (ClaimState claim )
698+ -> Strategy. TransitionT (AppliedRule claim ) m (ApplyResult claim )
698699deriveSeq' lensRulePattern mkRule =
699700 deriveWith lensRulePattern mkRule . flip
700701 $ Step. applyRewriteRulesSequence Unification. unificationProcedure
@@ -704,7 +705,7 @@ deriveResults
704705 => (Step. UnifiedRule representation -> AppliedRule claim )
705706 -> Step. Results representation
706707 -> Strategy. TransitionT (AppliedRule claim ) simplifier
707- (ClaimState. ClaimState (Pattern RewritingVariableName ))
708+ (ApplyResult (Pattern RewritingVariableName ))
708709-- TODO (thomas.tuegel): Remove claim argument.
709710deriveResults fromAppliedRule Results { results, remainders } =
710711 addResults <|> addRemainders
@@ -715,13 +716,10 @@ deriveResults fromAppliedRule Results { results, remainders } =
715716 addResult Result { appliedRule, result } = do
716717 addRule appliedRule
717718 case Foldable. toList result of
718- [] ->
719- -- If the rule returns \bottom, the claim is proven on the
720- -- current branch.
721- pure Proven
719+ [] -> addRewritten Pattern. bottom
722720 configs -> Foldable. asum (addRewritten <$> configs)
723721
724- addRewritten = pure . Rewritten
725- addRemainder = pure . Remaining
722+ addRewritten = pure . ApplyRewritten
723+ addRemainder = pure . ApplyRemainder
726724
727725 addRule = Transition. addRule . fromAppliedRule
0 commit comments