add check-redundancy, a parameter that causes redex to print some
debugging information about ambiguous matching (when the ambiguity matters)
This commit is contained in:
parent
a12df9cea6
commit
6cacd57ebc
|
@ -1624,7 +1624,18 @@ See match-a-pattern.rkt for more details
|
||||||
[(null? rhss)
|
[(null? rhss)
|
||||||
(if (null? ans)
|
(if (null? ans)
|
||||||
#f
|
#f
|
||||||
ans)]
|
(begin
|
||||||
|
(when (check-redudancy)
|
||||||
|
(let ([rd (remove-duplicates ans)])
|
||||||
|
(unless (= (length rd) (length ans))
|
||||||
|
(eprintf "found redundancy when matching the non-terminal ~s against:\n~s~a"
|
||||||
|
nt
|
||||||
|
term
|
||||||
|
(apply
|
||||||
|
string-append
|
||||||
|
(map (λ (x) (format "\n ~s" x))
|
||||||
|
ans))))))
|
||||||
|
ans))]
|
||||||
[else
|
[else
|
||||||
(let ([mth (call-nt-proc/bindings (car rhss) term hole-info)])
|
(let ([mth (call-nt-proc/bindings (car rhss) term hole-info)])
|
||||||
(cond
|
(cond
|
||||||
|
@ -1644,6 +1655,8 @@ See match-a-pattern.rkt for more details
|
||||||
(or (call-nt-proc/bindings (car rhss) term hole-info)
|
(or (call-nt-proc/bindings (car rhss) term hole-info)
|
||||||
(loop (cdr rhss)))]))))
|
(loop (cdr rhss)))]))))
|
||||||
|
|
||||||
|
(define check-redudancy (make-parameter #f))
|
||||||
|
|
||||||
(define (match-nt/boolean list-rhs non-list-rhs nt term)
|
(define (match-nt/boolean list-rhs non-list-rhs nt term)
|
||||||
(let loop ([rhss (if (or (null? term) (pair? term))
|
(let loop ([rhss (if (or (null? term) (pair? term))
|
||||||
list-rhs
|
list-rhs
|
||||||
|
@ -1956,4 +1969,5 @@ See match-a-pattern.rkt for more details
|
||||||
the-not-hole the-hole hole?
|
the-not-hole the-hole hole?
|
||||||
rewrite-ellipses
|
rewrite-ellipses
|
||||||
build-compatible-context-language
|
build-compatible-context-language
|
||||||
caching-enabled?)
|
caching-enabled?
|
||||||
|
check-redudancy)
|
||||||
|
|
|
@ -389,7 +389,17 @@ nested lists.
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(set-cache-size! [size positive-integer?]) void?]{
|
@defproc[(set-cache-size! [size positive-integer?]) void?]{
|
||||||
Changes the size of the per-pattern and per-metafunction caches. The default size is @racket[350].
|
Changes the size of the per-pattern and per-metafunction caches.
|
||||||
|
|
||||||
|
The default size is @racket[350].
|
||||||
|
}
|
||||||
|
|
||||||
|
@defparam[check-redudancy check? boolean?]{
|
||||||
|
Ambiguous patterns can slow down
|
||||||
|
Redex's pattern matching implementation significantly. To help debug
|
||||||
|
such performance issues, set the @racket[check-redundancy]
|
||||||
|
parameter to @racket[#t]. This causes Redex to, at runtime,
|
||||||
|
report any redundant matches that it encounters.
|
||||||
}
|
}
|
||||||
|
|
||||||
@section{Terms}
|
@section{Terms}
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
judgment-holds
|
judgment-holds
|
||||||
in-domain?
|
in-domain?
|
||||||
caching-enabled?
|
caching-enabled?
|
||||||
make-coverage)
|
make-coverage
|
||||||
|
check-redudancy)
|
||||||
|
|
||||||
(provide (rename-out [test-match redex-match])
|
(provide (rename-out [test-match redex-match])
|
||||||
term-match
|
term-match
|
||||||
|
|
Loading…
Reference in New Issue
Block a user