Skip to content

Commit d378e7c

Browse files
committed
4100 Abort booster rewrite when matching subject variables
As demonstrated in #4100, booster should not report `stuck` when attempting to rewrite a term with variables that are required in a rule match. Specifically, a subject variable may lead to branching with the rule content matches ending up as path conditions in the different branches. Previously, booster would discard such cases as match failures and report `stuck` since no rule was applied. This PR changes the behaviour to aborting the rewrite when a subject variable needs to be matched by anything but a rule variable.
1 parent 5fb452a commit d378e7c

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

booster/library/Booster/Pattern/Match.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ match1 _ t1@DomainValue{} t2@KSet{}
216216
match1 _ t1@DomainValue{} t2@ConsApplication{} = failWith $ DifferentSymbols t1 t2
217217
match1 _ t1@DomainValue{} t2@FunctionApplication{} = addIndeterminate t1 t2
218218
-- match with var on the RHS must be indeterminate when evaluating functions. see: https://github.com/runtimeverification/hs-backend-booster/issues/231
219+
match1 Eval t1@DomainValue{} t2@Var{} = addIndeterminate t1 t2
220+
-- match with var on RHS is specially marked at the moment but must abort the rewriting (or lead to branching), see https://github.com/runtimeverification/haskell-backend/issues/4100
219221
match1 Rewrite t1@DomainValue{} (Var t2) = failWith $ SubjectVariableMatch t1 t2
220222
match1 Implies t1@DomainValue{} (Var t2) = failWith $ SubjectVariableMatch t1 t2
221-
match1 Eval t1@DomainValue{} t2@Var{} = addIndeterminate t1 t2
222223
match1 Eval t1@Injection{} t2@AndTerm{} = addIndeterminate t1 t2
223224
match1 _ t1@Injection{} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
224225
match1 _ t1@Injection{} t2@DomainValue{} = failWith $ DifferentSymbols t1 t2
@@ -228,6 +229,7 @@ match1 _ t1@Injection{} t2@KList{}
228229
match1 _ t1@Injection{} t2@KSet{} = failWith $ DifferentSymbols t1 t2
229230
match1 _ t1@Injection{} t2@ConsApplication{} = failWith $ DifferentSymbols t1 t2
230231
match1 _ t1@Injection{} t2@FunctionApplication{} = addIndeterminate t1 t2
232+
match1 Rewrite t1@Injection{} (Var t2) = failWith $ SubjectVariableMatch t1 t2
231233
match1 _ t1@Injection{} t2@Var{} = addIndeterminate t1 t2
232234
match1 Eval t1@KMap{} t2@AndTerm{} = addIndeterminate t1 t2
233235
match1 _ t1@KMap{} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b

booster/library/Booster/Pattern/Rewrite.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import Booster.Pattern.Base
6464
import Booster.Pattern.Bool
6565
import Booster.Pattern.Index qualified as Idx
6666
import Booster.Pattern.Match (
67-
FailReason (ArgLengthsDiffer, SubsortingError),
67+
FailReason (ArgLengthsDiffer, SubjectVariableMatch, SubsortingError),
6868
MatchResult (MatchFailed, MatchIndeterminate, MatchSuccess),
6969
MatchType (Rewrite),
7070
SortError,
@@ -392,6 +392,10 @@ applyRule pat@Pattern{ceilConditions} rule =
392392
withContext CtxError $
393393
logPretty' @mods err
394394
failRewrite $ InternalMatchError $ renderText $ pretty' @mods err
395+
MatchFailed err@(SubjectVariableMatch t v) -> do
396+
withContext CtxError $
397+
logPretty' @mods err
398+
failRewrite $ RuleApplicationUnclear rule pat.term $ NE.singleton (t, Var v)
395399
MatchFailed reason -> do
396400
withContext CtxFailure $ logPretty' @mods reason
397401
returnNotApplied

booster/unit-tests/Test/Booster/Pattern/Rewrite.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test_rewriteStep =
4141
"Rewriting"
4242
[ errorCases
4343
, rewriteSuccess
44-
, unifyNotMatch
44+
, subjectVariables
4545
, definednessUnclear
4646
, rewriteStuck
4747
, rulePriority
@@ -176,7 +176,7 @@ testConf = do
176176
----------------------------------------
177177
errorCases
178178
, rewriteSuccess
179-
, unifyNotMatch
179+
, subjectVariables
180180
, definednessUnclear
181181
, rewriteStuck
182182
, rulePriority ::
@@ -207,10 +207,11 @@ rewriteSuccess =
207207
`rewritesTo` ( "con1-f1"
208208
, [trm| kCell{}( kseq{}( inj{SomeSort{}, SortKItem{}}( f1{}( \dv{SomeSort{}}("thing") ) ), ConfigVar:SortK{}) ) |]
209209
)
210-
unifyNotMatch =
211-
testCase "Stuck case when subject has variables" $
212-
getsStuck
213-
[trm| kCell{}( kseq{}( inj{SomeSort{}, SortKItem{}}( con3{}( X:SomeSort{}, \dv{SomeSort{}}("thing") ) ), ConfigVar:SortK{}) ) |]
210+
subjectVariables =
211+
testCase "Aborts case when subject has variables" $ do
212+
let t = [trm| kCell{}( kseq{}( inj{SomeSort{}, SortKItem{}}( con3{}( X:SomeSort{}, \dv{SomeSort{}}("thing") ) ), ConfigVar:SortK{}) ) |]
213+
t `failsWith`
214+
RuleApplicationUnclear rule3 t (NE.singleton ([trm| \dv{SomeSort{}}("otherThing")|], [trm| X:SomeSort{} |]))
214215
definednessUnclear =
215216
testCase "con4 rewrite to f2 might become undefined" $ do
216217
let pcon4 =

0 commit comments

Comments
 (0)