Skip to content

Commit ad42fbd

Browse files
committed
Return rule substitution
1 parent 391b47c commit ad42fbd

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

booster/library/Booster/JsonRpc.hs

+23-15
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,13 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
604604
{ reason = RpcTypes.Branching
605605
, depth
606606
, logs
607-
, state = toExecState p originalSubstitution unsupported Nothing Nothing
607+
, state = toExecState p originalSubstitution unsupported Nothing Nothing Nothing
608608
, nextStates =
609-
Just $
610-
map
611-
(\(_, muid, p', mrulePred) -> toExecState p' originalSubstitution unsupported (Just muid) mrulePred) $
612-
toList nexts
609+
Just
610+
$ map
611+
( \(_, muid, p', mrulePred, ruleSubst) -> toExecState p' originalSubstitution unsupported (Just muid) mrulePred (Just ruleSubst)
612+
)
613+
$ toList nexts
613614
, rule = Nothing
614615
, unknownPredicate = Nothing
615616
}
@@ -620,7 +621,7 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
620621
{ reason = RpcTypes.Stuck
621622
, depth
622623
, logs
623-
, state = toExecState p originalSubstitution unsupported Nothing Nothing
624+
, state = toExecState p originalSubstitution unsupported Nothing Nothing Nothing
624625
, nextStates = Nothing
625626
, rule = Nothing
626627
, unknownPredicate = Nothing
@@ -632,7 +633,7 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
632633
{ reason = RpcTypes.Vacuous
633634
, depth
634635
, logs
635-
, state = toExecState p originalSubstitution unsupported Nothing Nothing
636+
, state = toExecState p originalSubstitution unsupported Nothing Nothing Nothing
636637
, nextStates = Nothing
637638
, rule = Nothing
638639
, unknownPredicate = Nothing
@@ -644,8 +645,8 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
644645
{ reason = RpcTypes.CutPointRule
645646
, depth
646647
, logs
647-
, state = toExecState p originalSubstitution unsupported Nothing Nothing
648-
, nextStates = Just [toExecState next originalSubstitution unsupported Nothing Nothing]
648+
, state = toExecState p originalSubstitution unsupported Nothing Nothing Nothing
649+
, nextStates = Just [toExecState next originalSubstitution unsupported Nothing Nothing Nothing]
649650
, rule = Just lbl
650651
, unknownPredicate = Nothing
651652
}
@@ -656,7 +657,7 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
656657
{ reason = RpcTypes.TerminalRule
657658
, depth
658659
, logs
659-
, state = toExecState p originalSubstitution unsupported Nothing Nothing
660+
, state = toExecState p originalSubstitution unsupported Nothing Nothing Nothing
660661
, nextStates = Nothing
661662
, rule = Just lbl
662663
, unknownPredicate = Nothing
@@ -668,7 +669,7 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
668669
{ reason = RpcTypes.DepthBound
669670
, depth
670671
, logs
671-
, state = toExecState p originalSubstitution unsupported Nothing Nothing
672+
, state = toExecState p originalSubstitution unsupported Nothing Nothing Nothing
672673
, nextStates = Nothing
673674
, rule = Nothing
674675
, unknownPredicate = Nothing
@@ -685,7 +686,7 @@ execResponse mbDuration req (d, traces, rr) originalSubstitution unsupported = c
685686
(logSuccessfulRewrites, logFailedRewrites)
686687
(RewriteStepFailed failure)
687688
in logs <|> abortRewriteLog
688-
, state = toExecState p originalSubstitution unsupported Nothing Nothing
689+
, state = toExecState p originalSubstitution unsupported Nothing Nothing Nothing
689690
, nextStates = Nothing
690691
, rule = Nothing
691692
, unknownPredicate = Nothing
@@ -716,20 +717,27 @@ toExecState ::
716717
[Syntax.KorePattern] ->
717718
Maybe UniqueId ->
718719
Maybe Predicate ->
720+
Maybe (Map Variable Term) ->
719721
RpcTypes.ExecuteState
720-
toExecState pat sub unsupported muid mrulePredicate =
722+
toExecState pat sub unsupported muid mrulePredicate mruleSubst =
721723
RpcTypes.ExecuteState
722724
{ term = addHeader t
723725
, predicate = addHeader <$> addUnsupported p
724726
, substitution = addHeader <$> s
725-
, ruleSubstitution = Nothing
727+
, ruleSubstitution = addHeader <$> mruleSubstExt
726728
, rulePredicate = addHeader <$> mrulePredExt
727729
, ruleId = getUniqueId <$> muid
728730
}
729731
where
730-
mrulePredExt = externalisePredicate (externaliseSort Pattern.SortBool) <$> mrulePredicate
732+
mrulePredExt = externalisePredicate predicateSort <$> mrulePredicate
733+
mruleSubstExt =
734+
Syntax.KJAnd predicateSort
735+
. map (uncurry $ externaliseSubstitution predicateSort)
736+
. Map.toList
737+
<$> mruleSubst
731738
(t, p, s) = externalisePattern pat sub
732739
termSort = externaliseSort $ sortOfPattern pat
740+
predicateSort = externaliseSort Pattern.SortBool
733741
allUnsupported = Syntax.KJAnd termSort unsupported
734742
addUnsupported
735743
| null unsupported = id

booster/library/Booster/Pattern/Rewrite.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ ruleLabelOrLoc rule =
541541
-- | Different rewrite results (returned from RPC execute endpoint)
542542
data RewriteResult pat
543543
= -- | branch point
544-
RewriteBranch pat (NonEmpty (Text, UniqueId, pat, Maybe Predicate))
544+
RewriteBranch pat (NonEmpty (Text, UniqueId, pat, Maybe Predicate, Substitution))
545545
| -- | no rules could be applied, config is stuck
546546
RewriteStuck pat
547547
| -- | cut point rule, return current (lhs) and single next state
@@ -921,6 +921,7 @@ performRewrite doTracing def mLlvmLibrary mSolver mbMaxDepth cutLabels terminalL
921921
( collapseAndBools $
922922
concatMap (splitBoolPredicates . coerce . substituteInTerm subst . coerce) r.requires
923923
)
924+
, subst
924925
)
925926
)
926927
nextPats'

booster/tools/booster/Proxy.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ respondEither cfg@ProxyConfig{boosterState} booster kore req = case req of
567567
-- this ensures the information from next states in a branch reponse doesn't get lost
568568
pure $
569569
Right
570-
( (Booster.toExecState p sub unsup Nothing Nothing)
570+
( (Booster.toExecState p sub unsup Nothing Nothing Nothing)
571571
{ ruleId = s.ruleId
572572
, ruleSubstitution = s.ruleSubstitution
573573
, rulePredicate = s.rulePredicate

0 commit comments

Comments
 (0)