@@ -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.
@@ -217,9 +213,10 @@ match1 _ t1@DomainValue{} t2@ConsApplication{}
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
215
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
221
- match1 Rewrite t1@ DomainValue {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
222
- match1 Implies t1@ DomainValue {} (Var t2) = failWith $ SubjectVariableMatch 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
223
220
match1 Eval t1@ Injection {} t2@ AndTerm {} = addIndeterminate t1 t2
224
221
match1 _ t1@ Injection {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
225
222
match1 _ t1@ Injection {} t2@ DomainValue {} = failWith $ DifferentSymbols t1 t2
@@ -229,7 +226,7 @@ match1 _ t1@Injection{} t2@KList{}
229
226
match1 _ t1@ Injection {} t2@ KSet {} = failWith $ DifferentSymbols t1 t2
230
227
match1 _ t1@ Injection {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
231
228
match1 _ t1@ Injection {} t2@ FunctionApplication {} = addIndeterminate t1 t2
232
- match1 Rewrite t1@ Injection {} (Var t2 ) = failWith $ SubjectVariableMatch t1 t2
229
+ match1 Rewrite t1@ Injection {} (Var v2 ) = subjectVariableMatch t1 v2
233
230
match1 _ t1@ Injection {} t2@ Var {} = addIndeterminate t1 t2
234
231
match1 Eval t1@ KMap {} t2@ AndTerm {} = addIndeterminate t1 t2
235
232
match1 _ t1@ KMap {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -241,7 +238,7 @@ match1 _ t1@KMap{} t2@KList{}
241
238
match1 _ t1@ KMap {} t2@ KSet {} = failWith $ DifferentSymbols t1 t2
242
239
match1 _ t1@ KMap {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
243
240
match1 _ t1@ KMap {} t2@ FunctionApplication {} = addIndeterminate t1 t2
244
- match1 Rewrite t1@ KMap {} (Var t2 ) = failWith $ SubjectVariableMatch t1 t2
241
+ match1 Rewrite t1@ KMap {} (Var v2 ) = subjectVariableMatch t1 v2
245
242
match1 _ t1@ KMap {} t2@ Var {} = addIndeterminate t1 t2
246
243
match1 Eval t1@ KList {} t2@ AndTerm {} = addIndeterminate t1 t2
247
244
match1 _ t1@ KList {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -254,7 +251,7 @@ match1 _ t1@(KList def1 heads1 rest1) t2@(KList def2 heads2
254
251
match1 _ t1@ KList {} t2@ KSet {} = failWith $ DifferentSymbols t1 t2
255
252
match1 _ t1@ KList {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
256
253
match1 _ t1@ KList {} t2@ FunctionApplication {} = addIndeterminate t1 t2
257
- match1 Rewrite t1@ KList {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
254
+ match1 Rewrite t1@ KList {} (Var t2) = subjectVariableMatch t1 t2
258
255
match1 _ t1@ KList {} t2@ Var {} = addIndeterminate t1 t2
259
256
match1 Eval t1@ KSet {} t2@ AndTerm {} = addIndeterminate t1 t2
260
257
match1 _ t1@ KSet {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -266,7 +263,7 @@ match1 _ t1@KSet{} t2@KList{}
266
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
267
264
match1 _ t1@ KSet {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
268
265
match1 _ t1@ KSet {} t2@ FunctionApplication {} = addIndeterminate t1 t2
269
- match1 Rewrite t1@ KSet {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
266
+ match1 Rewrite t1@ KSet {} (Var t2) = subjectVariableMatch t1 t2
270
267
match1 _ t1@ KSet {} t2@ Var {} = addIndeterminate t1 t2
271
268
match1 Eval t1@ ConsApplication {} t2@ AndTerm {} = addIndeterminate t1 t2
272
269
match1 _ t1@ ConsApplication {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -278,7 +275,7 @@ match1 _ t1@ConsApplication{} t2@KSet{}
278
275
match1 matchTy (ConsApplication symbol1 sorts1 args1) (ConsApplication symbol2 sorts2 args2) = matchSymbolAplications matchTy symbol1 sorts1 args1 symbol2 sorts2 args2
279
276
match1 Eval (ConsApplication symbol1 sorts1 args1) (FunctionApplication symbol2 sorts2 args2) = matchSymbolAplications Eval symbol1 sorts1 args1 symbol2 sorts2 args2
280
277
match1 _ t1@ ConsApplication {} t2@ FunctionApplication {} = addIndeterminate t1 t2
281
- match1 Rewrite t1@ ConsApplication {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
278
+ match1 Rewrite t1@ ConsApplication {} (Var t2) = subjectVariableMatch t1 t2
282
279
match1 _ t1@ ConsApplication {} t2@ Var {} = addIndeterminate t1 t2
283
280
match1 Eval t1@ FunctionApplication {} t2@ AndTerm {} = addIndeterminate t1 t2
284
281
match1 _ t1@ FunctionApplication {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -296,7 +293,7 @@ match1 Eval (FunctionApplication symbol1 sorts1 args1) (ConsApplication symbo
296
293
match1 _ t1@ FunctionApplication {} t2@ ConsApplication {} = addIndeterminate t1 t2
297
294
match1 Eval (FunctionApplication symbol1 sorts1 args1) (FunctionApplication symbol2 sorts2 args2) = matchSymbolAplications Eval symbol1 sorts1 args1 symbol2 sorts2 args2
298
295
match1 _ t1@ FunctionApplication {} t2@ FunctionApplication {} = addIndeterminate t1 t2
299
- match1 Rewrite t1@ FunctionApplication {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
296
+ match1 Rewrite t1@ FunctionApplication {} (Var t2) = subjectVariableMatch t1 t2
300
297
match1 _ t1@ FunctionApplication {} t2@ Var {} = addIndeterminate t1 t2
301
298
match1 Eval t1@ Var {} t2@ AndTerm {} = addIndeterminate t1 t2
302
299
match1 _ t1@ Var {} (AndTerm t2a t2b) = enqueueRegularProblem t1 t2a >> enqueueRegularProblem t1 t2b
@@ -450,6 +447,12 @@ matchVar
450
447
else Injection termSort variableSort term2
451
448
else failWith $ DifferentSorts (Var var) term2
452
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
+
453
456
{- | pair up the argument lists and return the pairs in the first argument. If the lists
454
457
are of equal length, return Nothing in second, else return the remaining
455
458
terms in the longer list, tagged with their origin).
0 commit comments