@@ -79,8 +79,6 @@ data FailReason
79
79
SubsortingError SortError
80
80
| -- | The two terms have differing argument lengths
81
81
ArgLengthsDiffer Term Term
82
- | -- | Not a matching substitution
83
- SubjectVariableMatch Term Variable
84
82
deriving stock (Eq , Show )
85
83
86
84
instance FromModifiersT mods => Pretty (PrettyWithModifiers mods FailReason ) where
@@ -115,8 +113,6 @@ instance FromModifiersT mods => Pretty (PrettyWithModifiers mods FailReason) whe
115
113
pretty $ show err
116
114
ArgLengthsDiffer t1 t2 ->
117
115
hsep [" Argument length differ" , pretty' @ mods t1, pretty' @ mods t2]
118
- SubjectVariableMatch t v ->
119
- hsep [" Cannot match variable in subject:" , pretty' @ mods v, pretty' @ mods t]
120
116
121
117
{- | Attempts to find a simple unifying substitution for the given
122
118
terms.
@@ -216,9 +212,11 @@ match1 _ t1@DomainValue{} t2@KSet{}
216
212
match1 _ t1@ DomainValue {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
217
213
match1 _ t1@ DomainValue {} t2@ FunctionApplication {} = addIndeterminate t1 t2
218
214
-- match with var on the RHS must be indeterminate when evaluating functions. see: https://github.com/runtimeverification/hs-backend-booster/issues/231
219
- match1 Rewrite t1@ DomainValue {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
220
- match1 Implies t1@ DomainValue {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
221
215
match1 Eval t1@ DomainValue {} t2@ Var {} = addIndeterminate t1 t2
216
+ -- match with var on RHS may lead to branching during rewriting, see https://github.com/runtimeverification/haskell-backend/issues/4100
217
+ -- Related cases are currently marked with a special function so they can be identified and changed together later (extending branching functionality)
218
+ match1 Rewrite t1@ DomainValue {} (Var v2) = subjectVariableMatch t1 v2
219
+ match1 Implies t1@ DomainValue {} (Var v2) = subjectVariableMatch t1 v2
222
220
match1 Eval t1@ Injection {} t2@ AndTerm {} = addIndeterminate t1 t2
223
221
match1 _ t1@ Injection {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
224
222
match1 _ t1@ Injection {} t2@ DomainValue {} = failWith $ DifferentSymbols t1 t2
@@ -228,6 +226,7 @@ match1 _ t1@Injection{} t2@KList{}
228
226
match1 _ t1@ Injection {} t2@ KSet {} = failWith $ DifferentSymbols t1 t2
229
227
match1 _ t1@ Injection {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
230
228
match1 _ t1@ Injection {} t2@ FunctionApplication {} = addIndeterminate t1 t2
229
+ match1 Rewrite t1@ Injection {} (Var v2) = subjectVariableMatch t1 v2
231
230
match1 _ t1@ Injection {} t2@ Var {} = addIndeterminate t1 t2
232
231
match1 Eval t1@ KMap {} t2@ AndTerm {} = addIndeterminate t1 t2
233
232
match1 _ t1@ KMap {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -239,7 +238,7 @@ match1 _ t1@KMap{} t2@KList{}
239
238
match1 _ t1@ KMap {} t2@ KSet {} = failWith $ DifferentSymbols t1 t2
240
239
match1 _ t1@ KMap {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
241
240
match1 _ t1@ KMap {} t2@ FunctionApplication {} = addIndeterminate t1 t2
242
- match1 Rewrite t1@ KMap {} (Var t2 ) = failWith $ SubjectVariableMatch t1 t2
241
+ match1 Rewrite t1@ KMap {} (Var v2 ) = subjectVariableMatch t1 v2
243
242
match1 _ t1@ KMap {} t2@ Var {} = addIndeterminate t1 t2
244
243
match1 Eval t1@ KList {} t2@ AndTerm {} = addIndeterminate t1 t2
245
244
match1 _ t1@ KList {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -252,7 +251,7 @@ match1 _ t1@(KList def1 heads1 rest1) t2@(KList def2 heads2
252
251
match1 _ t1@ KList {} t2@ KSet {} = failWith $ DifferentSymbols t1 t2
253
252
match1 _ t1@ KList {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
254
253
match1 _ t1@ KList {} t2@ FunctionApplication {} = addIndeterminate t1 t2
255
- match1 Rewrite t1@ KList {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
254
+ match1 Rewrite t1@ KList {} (Var t2) = subjectVariableMatch t1 t2
256
255
match1 _ t1@ KList {} t2@ Var {} = addIndeterminate t1 t2
257
256
match1 Eval t1@ KSet {} t2@ AndTerm {} = addIndeterminate t1 t2
258
257
match1 _ t1@ KSet {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -264,7 +263,7 @@ match1 _ t1@KSet{} t2@KList{}
264
263
match1 _ t1@ (KSet def1 patElements patRest) t2@ (KSet def2 subjElements subjRest) = if def1 == def2 then matchSets def1 patElements patRest subjElements subjRest else failWith $ DifferentSorts t1 t2
265
264
match1 _ t1@ KSet {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
266
265
match1 _ t1@ KSet {} t2@ FunctionApplication {} = addIndeterminate t1 t2
267
- match1 Rewrite t1@ KSet {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
266
+ match1 Rewrite t1@ KSet {} (Var t2) = subjectVariableMatch t1 t2
268
267
match1 _ t1@ KSet {} t2@ Var {} = addIndeterminate t1 t2
269
268
match1 Eval t1@ ConsApplication {} t2@ AndTerm {} = addIndeterminate t1 t2
270
269
match1 _ t1@ ConsApplication {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -276,7 +275,7 @@ match1 _ t1@ConsApplication{} t2@KSet{}
276
275
match1 matchTy (ConsApplication symbol1 sorts1 args1) (ConsApplication symbol2 sorts2 args2) = matchSymbolAplications matchTy symbol1 sorts1 args1 symbol2 sorts2 args2
277
276
match1 Eval (ConsApplication symbol1 sorts1 args1) (FunctionApplication symbol2 sorts2 args2) = matchSymbolAplications Eval symbol1 sorts1 args1 symbol2 sorts2 args2
278
277
match1 _ t1@ ConsApplication {} t2@ FunctionApplication {} = addIndeterminate t1 t2
279
- match1 Rewrite t1@ ConsApplication {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
278
+ match1 Rewrite t1@ ConsApplication {} (Var t2) = subjectVariableMatch t1 t2
280
279
match1 _ t1@ ConsApplication {} t2@ Var {} = addIndeterminate t1 t2
281
280
match1 Eval t1@ FunctionApplication {} t2@ AndTerm {} = addIndeterminate t1 t2
282
281
match1 _ t1@ FunctionApplication {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -294,7 +293,7 @@ match1 Eval (FunctionApplication symbol1 sorts1 args1) (ConsApplication symbo
294
293
match1 _ t1@ FunctionApplication {} t2@ ConsApplication {} = addIndeterminate t1 t2
295
294
match1 Eval (FunctionApplication symbol1 sorts1 args1) (FunctionApplication symbol2 sorts2 args2) = matchSymbolAplications Eval symbol1 sorts1 args1 symbol2 sorts2 args2
296
295
match1 _ t1@ FunctionApplication {} t2@ FunctionApplication {} = addIndeterminate t1 t2
297
- match1 Rewrite t1@ FunctionApplication {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
296
+ match1 Rewrite t1@ FunctionApplication {} (Var t2) = subjectVariableMatch t1 t2
298
297
match1 _ t1@ FunctionApplication {} t2@ Var {} = addIndeterminate t1 t2
299
298
match1 Eval t1@ Var {} t2@ AndTerm {} = addIndeterminate t1 t2
300
299
match1 _ t1@ Var {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -448,6 +447,12 @@ matchVar
448
447
else Injection termSort variableSort term2
449
448
else failWith $ DifferentSorts (Var var) term2
450
449
450
+ -- Subject variable matches are currently marked as indeterminate.
451
+ -- The code may be extended to collect these as separate conditional
452
+ -- results (for branching).
453
+ subjectVariableMatch :: Term -> Variable -> StateT MatchState (Except MatchResult ) ()
454
+ subjectVariableMatch t v = addIndeterminate t (Var v)
455
+
451
456
{- | pair up the argument lists and return the pairs in the first argument. If the lists
452
457
are of equal length, return Nothing in second, else return the remaining
453
458
terms in the longer list, tagged with their origin).
0 commit comments