diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/env/type-alias-env.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/env/type-alias-env.rkt index 70a77330..19e73b2f 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/env/type-alias-env.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/env/type-alias-env.rkt @@ -19,7 +19,7 @@ (define the-mapping (make-free-id-table)) -(define (mapping-put! id v) (dict-set! the-mapping id v)) +(define (mapping-put! id v) (free-id-table-set! the-mapping id v)) ;(trace mapping-put!) @@ -33,16 +33,16 @@ (mapping-put! id (make-resolved ty))) (define (lookup-type-alias id parse-type [k (lambda () (tc-error "Unknown type alias: ~a" (syntax-e id)))]) - (let/ec return - (match (dict-ref the-mapping id (lambda () (return (k)))) - [(struct unresolved (stx #f)) - (resolve-type-alias id parse-type)] - [(struct unresolved (stx #t)) - (tc-error/stx stx "Recursive Type Alias Reference")] - [(struct resolved (t)) t]))) + (match (free-id-table-ref the-mapping id #f) + [#f (k)] + [(struct unresolved (stx #f)) + (resolve-type-alias id parse-type)] + [(struct unresolved (stx #t)) + (tc-error/stx stx "Recursive Type Alias Reference")] + [(struct resolved (t)) t])) (define (resolve-type-alias id parse-type) - (define v (dict-ref the-mapping id)) + (define v (free-id-table-ref the-mapping id)) (match v [(struct unresolved (stx _)) (set-unresolved-in-process! v #t) @@ -53,7 +53,7 @@ t])) (define (resolve-type-aliases parse-type) - (for ([(id _) (in-dict the-mapping)]) + (for ([id (in-dict-keys the-mapping)]) (resolve-type-alias id parse-type))) ;; map over the-mapping, producing a list diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/infer/promote-demote.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/infer/promote-demote.rkt index c498d357..112d6da3 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/infer/promote-demote.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/infer/promote-demote.rkt @@ -11,7 +11,7 @@ (define (V-in? V . ts) (for/or ([e (in-list (append* (map fv ts)))]) - (memq e V))) + (memq e V))) ;; get-filters : SomeValues -> FilterSet ;; extract filters out of the range of a function type diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/rep/type-rep.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/rep/type-rep.rkt index 53e5830d..b3fefc48 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/rep/type-rep.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/rep/type-rep.rkt @@ -615,19 +615,29 @@ (define ((sub-pe st) e) (pathelem-case (#:Type st - #:PathElem (sub-pe st)) + #:PathElem (sub-pe st)) e)) ;; abstract-many : Names Type -> Scope^n ;; where n is the length of names (define (abstract-many names ty) - (define (nameTo name count type) + ;; mapping : dict[Type -> Natural] + (define (nameTo mapping type) (let loop ([outer 0] [ty type]) (define (sb t) (loop outer t)) + ;; transform : Name (Integer -> a) a -> a + ;; apply `mapping` to `name*`, returning `default` if it's not there + ;; use `f` to wrap the result + ;; note that this takes into account the value of `outer` + (define (transform name* f default) + (cond [(assq name* mapping) + => (λ (pr) + (f (+ (cdr pr) outer)))] + [else default])) (type-case - (#:Type sb #:Filter (sub-f sb) #:Object (sub-o sb)) + (#:Type sb #:Filter (sub-f sb) #:Object (sub-o sb)) ty - [#:F name* (if (eq? name name*) (*B (+ count outer)) ty)] + [#:F name* (transform name* *B ty)] ;; necessary to avoid infinite loops [#:Union elems (*Union (remove-dups (sort (map sb elems) type Type ;; where n is the length of types ;; all of the types MUST be Fs (define (instantiate-many images sc) - (define (replace image count type) + ;; mapping : dict[Natural -> Type] + (define (replace mapping type) (let loop ([outer 0] [ty type]) + ;; transform : Integer (Name -> a) a -> a + ;; apply `mapping` to `idx`, returning `default` if it's not there + ;; use `f` to wrap the result + ;; note that this takes into account the value of `outer` + (define (transform idx f default) + (cond [(assf (lambda (v) (eqv? (+ v outer) idx)) mapping) + => (lambda (pr) (f (cdr pr)))] + [else default])) (define (sb t) (loop outer t)) (define sf (sub-f sb)) (type-case (#:Type sb #:Filter sf #:Object (sub-o sb)) ty - [#:B idx (if (= (+ count outer) idx) - image - ty)] + [#:B idx (transform idx values ty)] ;; necessary to avoid infinite loops [#:Union elems (*Union (remove-dups (sort (map sb elems) type (listof def-binding?) (define (tc-toplevel/pass1 form) - #; ;; pass1 is fast - (do-time (format "pass1 ~a line ~a" - (if #t - (substring (~a (syntax-source form)) - (max 0 (- (string-length (~a (syntax-source form))) 20))) - (syntax-source form)) - (syntax-line form))) (parameterize ([current-orig-stx form]) (syntax-parse form #:literals (values define-values #%plain-app begin define-syntaxes) - ;#:literal-sets (kernel-literals) ;; forms that are handled in other ways [(~or _:ignore^ _:ignore-some^)