Memoize the Un constructor for unions

This seems to speed up typechecking by 5-10% (depending
on the machine) on compiling the math library and on
the "new-metrics.rkt" test.
This commit is contained in:
Asumu Takikawa 2015-10-24 01:27:56 -04:00
parent 9b8b525d42
commit ac880411d4

View File

@ -49,11 +49,16 @@
;; Normalizes representation by sorting types.
;; Type * -> Type
;; The input types can overlap and be union types
(define Un-cache (make-weak-hash))
(define Un
(case-lambda
[() -Bottom]
[(t) t]
[args
(define ts (foldr merge '()
(remove-dups (sort (append-map flat args) type<?))))
(make-union* ts)]))
(cond [(hash-ref Un-cache args #f)]
[else
(define ts (foldr merge '()
(remove-dups (sort (append-map flat args) type<?))))
(define type (make-union* ts))
(hash-set! Un-cache args type)
type])]))