Commit 6f17f7e
Return MatchIndeterminate (not MatchFailed) for mixed-determinacy matches in Eval and Implies modes (#4152)
The booster matcher's job is to return the truth — terms either
*definitely* cannot match (`MatchFailed`) or *cannot be decided* without
further simplification (`MatchIndeterminate`) — and leave it to the
caller to decide what to do with an indeterminate verdict. In `Eval` and
`Implies` modes the matcher previously short-circuited to a decisive
`MatchFailed` in several cases where the two terms could in fact
simplify or instantiate to something equivalent, so the deferral never
reached the caller. The unifying principle applied here: a decisive
`MatchFailed` is sound only when the mismatch is between *rigid* shapes
or sorts that cannot change under evaluation or instantiation; every
other mismatch must defer.
This matters most for function-equation evaluation:
`handleFunctionEquation` routes `FailedMatch _ -> continue` but
`IndeterminateMatch{} -> abort`. A spurious decisive `MatchFailed`
caused the evaluator to silently skip a higher-priority equation and
commit to a lower-priority catch-all, violating the priority contract
function equations rely on. For `Implies`, the indeterminate verdict
lets the existing simplify-LHS / simplify-RHS retry ladder in
`Pattern.Implies` attempt the discharge and report a residual non-match
as `indeterminate` rather than a decisive `valid:false`. Simplification
behaviour is unchanged — `handleSimplificationEquation` routes both
verdicts to `continue`.
**Behavioural changes (each previously a decisive `MatchFailed`, now
`addIndeterminate`):**
- `bindVariable`: a pattern variable rebinding to two terms that are not
both constructor-like (e.g. a domain value and a function application),
in all modes — matching what `Rewrite` already did.
- `match1`: a `FunctionApplication` pattern against a concrete
structured subject (`DomainValue`/`Injection`/`KMap`/`KList`/`KSet`) in
`Eval` — falls through to the shared catch-all.
- `match1`: an `Injection` pattern against a builtin collection
(`KMap`/`KList`/`KSet`) in `Eval`, making both directions of this pair
indeterminate (the reverse direction already was).
- `matchVar`: a pattern variable against a subject whose static sort is
not a subsort of the variable's, when the subject is a
`FunctionApplication` or `Var` and the two sorts share a subsort (the
subject can still narrow). Sort-disjoint pairs and rigid subjects keep
the decisive `DifferentSorts` failure.
- `matchInj`: an injection-vs-injection pair with differing sources
where a child on the wider-sorted side can narrow (a subject variable
child, or a pattern function child). Rigid children at incompatible
sorts keep the decisive failure.
**Refactor (no behaviour change):**
- `match1` is inverted to defer-by-default: the table now ends in one
generic `addIndeterminate` fall-through — the always-sound outcome — and
every row above it justifies something stronger (\and decomposition,
variable binding, same-category descent, or decisive failure). The
decisive cross-category rule is a single guarded row over a new
`isRigidCategory` predicate, making the rigidity principle executable
rather than commentary. The table shrinks from ~108 rows to 18.
`bindVariable` and `matchInj` no longer inspect their now-dead
`MatchType` argument.
**Tests:**
- Matcher-level cases pinning the post-fix contract in `MatchEval`,
`MatchImplies`, and `MatchRewrite`, plus a paired
function/simplification soundness-regression test in `ApplyEquations`
(`test_soundnessGap`) showing a high-priority indeterminate match
correctly aborts function-equation evaluation rather than falling
through to a lower-priority rule.
- A new exhaustive dispatch-class grid test (`MatchDispatch`) pinning
the result class (`S`/`F`/`I`) of all 3 × 9 × 9 = 243 (mode,
pattern-constructor, subject-constructor) combinations, so any future
`match1` change surfaces as a reviewable grid-cell diff.
**Validation:**
- Full booster unit-test suite passes (979 tests). The behavioural tests
were authored to fail against the pre-fix matcher and turn green only
with the `Match.hs` changes applied; the `MatchDispatch` grid was first
pinned on `master` and shows exactly the eight `Eval` cells
(`Injection`-vs-collection and `FunctionApplication`-vs-rigid) that this
branch flips from `F` to `I`.
- Tested downstream on KMIR, KEVM, and Kontrol and saw that it does not
cause any proofs to fail or performance regressions.
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent eb2da06 commit 6f17f7e
6 files changed
Lines changed: 425 additions & 151 deletions
File tree
- booster
- library/Booster/Pattern
- unit-tests/Test/Booster/Pattern
Large diffs are not rendered by default.
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
320 | 321 | | |
321 | 322 | | |
322 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
323 | 361 | | |
324 | 362 | | |
325 | 363 | | |
| |||
399 | 437 | | |
400 | 438 | | |
401 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
402 | 481 | | |
403 | 482 | | |
404 | 483 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 71 | | |
74 | 72 | | |
75 | 73 | | |
| |||
97 | 95 | | |
98 | 96 | | |
99 | 97 | | |
100 | | - | |
101 | | - | |
| 98 | + | |
| 99 | + | |
102 | 100 | | |
103 | 101 | | |
104 | 102 | | |
| |||
115 | 113 | | |
116 | 114 | | |
117 | 115 | | |
118 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
119 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
120 | 130 | | |
121 | 131 | | |
122 | 132 | | |
| |||
306 | 316 | | |
307 | 317 | | |
308 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
309 | 422 | | |
310 | 423 | | |
311 | 424 | | |
| |||
323 | 436 | | |
324 | 437 | | |
325 | 438 | | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
326 | 456 | | |
327 | 457 | | |
328 | 458 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
129 | | - | |
130 | | - | |
131 | | - | |
| 130 | + | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
185 | 189 | | |
186 | 190 | | |
187 | 191 | | |
| |||
213 | 217 | | |
214 | 218 | | |
215 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
216 | 258 | | |
217 | 259 | | |
218 | 260 | | |
| |||
517 | 559 | | |
518 | 560 | | |
519 | 561 | | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
520 | 575 | | |
521 | 576 | | |
522 | 577 | | |
| |||
0 commit comments