Add a heuristic for case-lambda type simplification.

Makes simplification _much_ faster for types that have a single most
general case. That includes most numeric functions.
This commit is contained in:
Vincent St-Amour 2011-07-22 16:55:21 -04:00
parent 86490943a3
commit 3ba93cb165

View File

@ -238,6 +238,18 @@
(make-Function (list (make-arr dom (-values (list Univ)) (make-Function (list (make-arr dom (-values (list Univ))
rest drest null)))]) rest drest null)))])
candidates)]) candidates)])
;; Heuristic: often, the last case in the definition (first at
;; this point, we've reversed the list) is the most general of
;; all, subsuming all the others. If that's the case, just go
;; with it. Otherwise, go the slow way.
(define potentially-most-general (car fun-tys-ret-any))
(if (andmap (lambda (c) (subtype potentially-most-general c))
fun-tys-ret-any)
;; Yep. Return early.
(apply values (map list (car parts-acc)))
;; No luck, do it the slow way
(let loop ([cases fun-tys-ret-any] (let loop ([cases fun-tys-ret-any]
[parts parts-acc] [parts parts-acc]
;; accumulators ;; accumulators
@ -253,7 +265,7 @@
(loop (cdr cases) (cdr parts) (loop (cdr cases) (cdr parts)
(cons (car parts) parts-acc)))) ; we keep this one (cons (car parts) parts-acc)))) ; we keep this one
(unzip4 (reverse parts-acc)))))))) (unzip4 (reverse parts-acc)))))))))
;; Wrapper over possible-domains that works on types. ;; Wrapper over possible-domains that works on types.
(define (cleanup-type t [expected #f]) (define (cleanup-type t [expected #f])