Skip to content

Commit 0dcbe78

Browse files
committed
Collect failing sub-derviations from call-modeless-judgment-form and friends
1 parent 905b8b7 commit 0dcbe78

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

redex-lib/redex/private/modeless-jf.rkt

+25-16
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,13 @@
245245
;; hash[rulename -o> (listof modeless-jf-clause?)]
246246
;; compiled-pattern
247247
;; derivation
248-
;; -> match or #f
248+
;; boolean
249+
;; fail: (list/c derivation?) -> any/c
250+
;; -> match or any/c
251+
;; a list of derivations indicates the list of sub-derivations that did not match.
249252
(define (call-modeless-judgment-form lang jf-name modeless-jf-clause-table contract-cp deriv
250-
only-check-contracts?)
253+
only-check-contracts?
254+
[fail (λ _ #f)])
251255
(match deriv
252256
[(derivation (cons deriv-jf-name jf-args) rule-name sub-derivations)
253257
(cond
@@ -262,16 +266,16 @@
262266
rules
263267
jf-args
264268
sub-derivations
265-
(λ () #f))]
269+
fail)]
266270
[else
267271
(define known-rules (sort (hash-keys modeless-jf-clause-table) string<?))
268272
(error jf-name "unknown rule in derivation\n rule: ~.s\n known rules:~a"
269273
rule-name
270274
(apply string-append
271275
(for/list ([rule (in-list known-rules)])
272276
(format "\n ~s" rule))))]))]
273-
[else #f])]
274-
[_ #f]))
277+
[else (fail (list deriv))])]
278+
[_ (fail (list deriv))]))
275279

276280
(define (modeless-judgment-form-check-contract jf-name contract-cp jf-args)
277281
(when contract-cp
@@ -300,9 +304,9 @@
300304
first-set-of-args
301305
maybe-more-args)))))
302306

303-
(define (modeless-jf-process-rule-candidates lang candidates jf-args sub-derivations fail)
307+
(define (modeless-jf-process-rule-candidates lang candidates jf-args sub-derivations fail [bad-derivs '()])
304308
(match candidates
305-
[`() (fail)]
309+
[`() (fail (cons sub-derivations bad-derivs))]
306310
[(cons (modeless-jf-clause conclusion-compiled-pattern
307311
conclusion-ids-to-duplicate
308312
premises-compiled-pattern
@@ -313,12 +317,13 @@
313317
premise-jf-procs)
314318
more-candidates)
315319
(define conc-mtch (match-pattern conclusion-compiled-pattern jf-args))
316-
(define (fail-to-next-candidate)
320+
(define (fail-to-next-candidate bad-subderivs)
317321
(modeless-jf-process-rule-candidates lang
318322
more-candidates
319323
jf-args
320324
sub-derivations
321-
fail))
325+
fail
326+
(append bad-subderivs bad-derivs)))
322327
(cond
323328
[conc-mtch
324329
(define sub-derivations-arguments-term-list
@@ -363,9 +368,10 @@
363368
(mtch-bindings sub-derivations-mtch)
364369
premises-repeat-names
365370
premise-jf-procs
366-
#t)))
367-
(fail-to-next-candidate)])]
368-
[else (fail-to-next-candidate)])]))
371+
#t
372+
(λ _ #f))))
373+
(fail-to-next-candidate '())])]
374+
[else (fail-to-next-candidate '())])]))
369375

370376

371377
(define (modeless-jf-process-other-conditions lang
@@ -376,7 +382,8 @@
376382
premise-jf-procs
377383
fail)
378384
(match conc+sub-bindings
379-
[`() (fail)]
385+
; TODO: Should this include some additional subderivations?
386+
[`() (fail '())]
380387
[(cons conc+sub-binding conc+sub-bindings)
381388
(cond
382389
[(and (not-failure-value? (other-conditions conc+sub-binding))
@@ -385,7 +392,8 @@
385392
conc+sub-binding
386393
premises-repeat-names
387394
premise-jf-procs
388-
#f))
395+
#f
396+
fail))
389397
#t]
390398
[else
391399
(modeless-jf-process-other-conditions lang
@@ -406,7 +414,8 @@
406414
conc+sub-binding
407415
premises-repeat-names
408416
premise-jf-procs
409-
contract-checking-only?)
417+
contract-checking-only?
418+
fail)
410419
(let loop ([premise-jf-procs premise-jf-procs]
411420
[premises-repeat-names premises-repeat-names]
412421
[sub-derivations sub-derivations])
@@ -430,7 +439,7 @@
430439
(cond
431440
[(premise-jf-proc sub-derivation contract-checking-only?)
432441
(n-loop (- n 1) sub-derivations)]
433-
[else #f])]
442+
[else (fail sub-derivation)])]
434443
[_ #f])]))])))
435444

436445
(struct modeless-jf-clause (conclusion-compiled-pattern

0 commit comments

Comments
 (0)