@@ -22,7 +22,7 @@ import Control.Monad
22
22
import Control.Monad.IO.Class
23
23
import Control.Monad.Trans.Except (catchE , except , runExcept , runExceptT , throwE , withExceptT )
24
24
import Crypto.Hash (SHA256 (.. ), hashWith )
25
- import Data.Bifunctor (second )
25
+ import Data.Bifunctor (first , second )
26
26
import Data.Foldable
27
27
import Data.List (singleton )
28
28
import Data.Map.Strict (Map )
@@ -38,7 +38,7 @@ import GHC.Records
38
38
import Numeric.Natural
39
39
40
40
import Booster.CLOptions (RewriteOptions (.. ))
41
- import Booster.Definition.Attributes.Base (UniqueId , getUniqueId , uniqueId )
41
+ import Booster.Definition.Attributes.Base (getUniqueId , uniqueId )
42
42
import Booster.Definition.Base (KoreDefinition (.. ))
43
43
import Booster.Definition.Base qualified as Definition (RewriteRule (.. ))
44
44
import Booster.LLVM as LLVM (API )
@@ -49,6 +49,7 @@ import Booster.Pattern.Base qualified as Pattern
49
49
import Booster.Pattern.Implies (runImplies )
50
50
import Booster.Pattern.Pretty
51
51
import Booster.Pattern.Rewrite (
52
+ AppliedRuleMetadata (.. ),
52
53
RewriteConfig (.. ),
53
54
RewriteFailed (.. ),
54
55
RewriteResult (.. ),
@@ -57,7 +58,9 @@ import Booster.Pattern.Rewrite (
57
58
)
58
59
import Booster.Pattern.Substitution qualified as Substitution
59
60
import Booster.Pattern.Util (
61
+ externaliseRuleMarker ,
60
62
freeVariables ,
63
+ modifyVarName ,
61
64
sortOfPattern ,
62
65
sortOfTerm ,
63
66
)
@@ -479,11 +482,13 @@ execResponse req (d, traces, rr) unsupported = case rr of
479
482
{ reason = RpcTypes. Branching
480
483
, depth
481
484
, logs
482
- , state = toExecState p unsupported Nothing
485
+ , state = toExecState p Nothing unsupported
483
486
, nextStates =
484
- Just $
485
- map (\ (_, muid, p') -> toExecState p' unsupported (Just muid)) $
486
- toList nexts
487
+ Just
488
+ $ map
489
+ ( \ (rewritten, ruleMetadata) -> toExecState rewritten (Just ruleMetadata) unsupported
490
+ )
491
+ $ toList nexts
487
492
, rule = Nothing
488
493
, unknownPredicate = Nothing
489
494
}
@@ -494,7 +499,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
494
499
{ reason = RpcTypes. Stuck
495
500
, depth
496
501
, logs
497
- , state = toExecState p unsupported Nothing
502
+ , state = toExecState p Nothing unsupported
498
503
, nextStates = Nothing
499
504
, rule = Nothing
500
505
, unknownPredicate = Nothing
@@ -506,7 +511,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
506
511
{ reason = RpcTypes. Vacuous
507
512
, depth
508
513
, logs
509
- , state = toExecState p unsupported Nothing
514
+ , state = toExecState p Nothing unsupported
510
515
, nextStates = Nothing
511
516
, rule = Nothing
512
517
, unknownPredicate = Nothing
@@ -518,8 +523,8 @@ execResponse req (d, traces, rr) unsupported = case rr of
518
523
{ reason = RpcTypes. CutPointRule
519
524
, depth
520
525
, logs
521
- , state = toExecState p unsupported Nothing
522
- , nextStates = Just [toExecState next unsupported Nothing ]
526
+ , state = toExecState p Nothing unsupported
527
+ , nextStates = Just [toExecState next Nothing unsupported ]
523
528
, rule = Just lbl
524
529
, unknownPredicate = Nothing
525
530
}
@@ -530,7 +535,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
530
535
{ reason = RpcTypes. TerminalRule
531
536
, depth
532
537
, logs
533
- , state = toExecState p unsupported Nothing
538
+ , state = toExecState p Nothing unsupported
534
539
, nextStates = Nothing
535
540
, rule = Just lbl
536
541
, unknownPredicate = Nothing
@@ -542,7 +547,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
542
547
{ reason = RpcTypes. DepthBound
543
548
, depth
544
549
, logs
545
- , state = toExecState p unsupported Nothing
550
+ , state = toExecState p Nothing unsupported
546
551
, nextStates = Nothing
547
552
, rule = Nothing
548
553
, unknownPredicate = Nothing
@@ -559,7 +564,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
559
564
(logSuccessfulRewrites, logFailedRewrites)
560
565
(RewriteStepFailed failure)
561
566
in logs <|> abortRewriteLog
562
- , state = toExecState p unsupported Nothing
567
+ , state = toExecState p Nothing unsupported
563
568
, nextStates = Nothing
564
569
, rule = Nothing
565
570
, unknownPredicate = Nothing
@@ -582,23 +587,37 @@ execResponse req (d, traces, rr) unsupported = case rr of
582
587
xs@ (_ : _) -> Just xs
583
588
584
589
toExecState ::
585
- Pattern -> [Syntax. KorePattern ] -> Maybe UniqueId -> RpcTypes. ExecuteState
586
- toExecState pat unsupported muid =
590
+ Pattern ->
591
+ Maybe AppliedRuleMetadata ->
592
+ [Syntax. KorePattern ] ->
587
593
RpcTypes. ExecuteState
588
- { term = addHeader t
589
- , predicate = addHeader <$> addUnsupported p
590
- , substitution = addHeader <$> s
591
- , ruleSubstitution = Nothing
592
- , rulePredicate = Nothing
593
- , ruleId = getUniqueId <$> muid
594
- }
595
- where
596
- (t, p, s) = externalisePattern pat
597
- termSort = externaliseSort $ sortOfPattern pat
598
- allUnsupported = Syntax. KJAnd termSort unsupported
599
- addUnsupported
600
- | null unsupported = id
601
- | otherwise = maybe (Just allUnsupported) (Just . Syntax. KJAnd termSort . (: unsupported))
594
+ toExecState
595
+ pat
596
+ mRuleMetadata
597
+ unsupported =
598
+ RpcTypes. ExecuteState
599
+ { term = addHeader t
600
+ , predicate = addHeader <$> addUnsupported p
601
+ , substitution = addHeader <$> s
602
+ , ruleSubstitution = addHeader <$> mruleSubstExt
603
+ , rulePredicate = addHeader <$> mrulePredExt
604
+ , ruleId = getUniqueId . ruleUniqueId <$> mRuleMetadata
605
+ }
606
+ where
607
+ mrulePredExt = externalisePredicate termSort . rulePredicate <$> mRuleMetadata
608
+ mruleSubstExt =
609
+ Syntax. KJAnd termSort
610
+ . map
611
+ (uncurry (externaliseSubstitution termSort) . first (modifyVarName externaliseRuleMarker))
612
+ . Map. toList
613
+ . ruleSubstitution
614
+ <$> mRuleMetadata
615
+ (t, p, s) = externalisePattern pat
616
+ termSort = externaliseSort $ sortOfPattern pat
617
+ allUnsupported = Syntax. KJAnd termSort unsupported
618
+ addUnsupported
619
+ | null unsupported = id
620
+ | otherwise = maybe (Just allUnsupported) (Just . Syntax. KJAnd termSort . (: unsupported))
602
621
603
622
mkLogRewriteTrace ::
604
623
(Bool , Bool ) ->
@@ -639,6 +658,11 @@ mkLogRewriteTrace
639
658
{ reason = " Uncertain about a condition in rule"
640
659
, _ruleId = Just $ getUniqueId (uniqueId $ Definition. attributes r)
641
660
}
661
+ RewriteRemainderPredicate rs _ _ ->
662
+ Failure
663
+ { reason = " Uncertain about the remainder after applying a rule"
664
+ , _ruleId = Just $ getUniqueId (uniqueId $ Definition. attributes (head rs))
665
+ }
642
666
DefinednessUnclear r _ undefReasons ->
643
667
Failure
644
668
{ reason = " Uncertain about definedness of rule because of: " <> pack (show undefReasons)
0 commit comments