Avoid a parameter for controlling resolve caching
The parameter dereference slowed down type-checking new-metrics.rkt to about 28s from 16s on DrDr. Instead of the parameter, explicitly remove items from the cache during type alias setup.
This commit is contained in:
parent
e4716bd68a
commit
862d58a2f4
|
@ -101,9 +101,6 @@
|
|||
;; other definitions need to be registered, do that before calling
|
||||
;; this function.
|
||||
(define (register-all-type-aliases type-alias-names type-alias-map)
|
||||
;; Disable resolve caching for the extent of this setup.
|
||||
;; Makes sure Name types don't get cached too soon.
|
||||
(parameterize ([current-cache-resolve? #f])
|
||||
;; Find type alias dependencies
|
||||
;; The two maps defined here contains the dependency structure
|
||||
;; of type aliases in two senses:
|
||||
|
@ -225,11 +222,14 @@
|
|||
(cons id new-deps)))
|
||||
|
||||
;; Actually register recursive type aliases
|
||||
(for ([id (in-list recursive-aliases)])
|
||||
(define name-types
|
||||
(for/list ([id (in-list recursive-aliases)])
|
||||
(define record (dict-ref type-alias-map id))
|
||||
(match-define (list _ args) record)
|
||||
(define deps (dict-ref new-dependency-map id))
|
||||
(register-resolved-type-alias id (make-Name id deps args #f)))
|
||||
(define name-type (make-Name id deps args #f))
|
||||
(register-resolved-type-alias id name-type)
|
||||
name-type))
|
||||
|
||||
;; Register non-recursive type aliases
|
||||
;;
|
||||
|
@ -240,6 +240,10 @@
|
|||
(define type-stx (car (dict-ref type-alias-map id)))
|
||||
(register-resolved-type-alias id (parse-type type-stx)))
|
||||
|
||||
;; Clear the resolver cache of Name types from this block
|
||||
(define (reset-resolver-cache!) (resolver-cache-remove! name-types))
|
||||
(reset-resolver-cache!)
|
||||
|
||||
;; Finish registering recursive aliases
|
||||
;; names-to-refine : Listof<Id>
|
||||
;; types-to-refine : Listof<Type>
|
||||
|
@ -254,13 +258,14 @@
|
|||
;; recursion (see resolve.rkt)
|
||||
(parameterize ([current-check-polymorphic-recursion args])
|
||||
(parse-type type-stx)))
|
||||
(reset-resolver-cache!)
|
||||
(register-type-name id type)
|
||||
(add-constant-variance! id args)
|
||||
(check-type-alias-contractive id type)
|
||||
(values id type args)))
|
||||
|
||||
;; Finally, do a last pass to refine the variance
|
||||
(refine-variance! names-to-refine types-to-refine tvarss)))
|
||||
(refine-variance! names-to-refine types-to-refine tvarss))
|
||||
|
||||
;; Syntax -> Syntax Syntax Syntax Option<Integer>
|
||||
;; Parse a type alias internal declaration
|
||||
|
|
|
@ -11,19 +11,12 @@
|
|||
|
||||
(provide resolve-name resolve-app needs-resolving?
|
||||
resolve resolve-app-check-error
|
||||
current-cache-resolve?
|
||||
resolver-cache-remove!
|
||||
current-check-polymorphic-recursion)
|
||||
(provide/cond-contract [resolve-once (Type/c . -> . (or/c Type/c #f))])
|
||||
|
||||
(define-struct poly (name vars) #:prefab)
|
||||
|
||||
;; This parameter allows other parts of the typechecker to
|
||||
;; request that the resolve cache isn't updated. This is needed
|
||||
;; by the setup for recursive type aliases, since certain Name
|
||||
;; types should not be cached while their mapping is still being
|
||||
;; computed.
|
||||
(define current-cache-resolve? (make-parameter #f))
|
||||
|
||||
;; Parameter<Option<Listof<Symbol>>>
|
||||
;; This parameter controls whether or not the resolving process
|
||||
;; should check for polymorphic recursion in implicit recursive
|
||||
|
@ -146,11 +139,17 @@
|
|||
(resolve-app r r* s)]
|
||||
[(Name: _ _ _ _) (resolve-name t)])])
|
||||
(when (and r*
|
||||
(not (currently-subtyping?))
|
||||
(current-cache-resolve?))
|
||||
(not (currently-subtyping?)))
|
||||
(hash-set! resolver-cache seq r*))
|
||||
r*)))
|
||||
|
||||
;; resolver-cache-remove! : (Listof Type) -> Void
|
||||
;; Removes the given types from the resolver cache. This is
|
||||
;; only used by recursive type alias set-up, which sometimes needs to
|
||||
;; undo certain resolutions.
|
||||
(define (resolver-cache-remove! keys)
|
||||
(for ([key (in-list keys)])
|
||||
(hash-remove! resolver-cache (Rep-seq key))))
|
||||
|
||||
;; Repeatedly unfolds Mu, App, and Name constructors until the top type
|
||||
;; constructor is not one of them.
|
||||
|
|
Loading…
Reference in New Issue
Block a user