diff --git a/typed-racket-lib/typed-racket/types/base-abbrev.rkt b/typed-racket-lib/typed-racket/types/base-abbrev.rkt index 4cf2dd01c..9e633fb42 100644 --- a/typed-racket-lib/typed-racket/types/base-abbrev.rkt +++ b/typed-racket-lib/typed-racket/types/base-abbrev.rkt @@ -102,15 +102,11 @@ (foldr -pair b l)) ;; Recursive types -(define-syntax -v - (syntax-rules () - [(_ x) (make-F 'x)])) +(define-syntax-rule (-v x) + (make-F 'x)) -(define-syntax -mu - (syntax-rules () - [(_ var ty) - (let ([var (-v var)]) - (make-Mu 'var ty))])) +(define-syntax-rule (-mu var ty) + (let ([var (-v var)]) (make-Mu 'var ty))) ;; Results (define/cond-contract (-result t [pset -tt-propset] [o -empty-obj]) @@ -493,31 +489,20 @@ ;; Convenient syntax for polymorphic types -(define-syntax -poly - (syntax-rules () - [(_ (vars ...) ty) - (let ([vars (-v vars)] ...) - (make-Poly (list 'vars ...) ty))])) - -(define-syntax -polydots - (syntax-rules () - [(_ (vars ... dotted) ty) - (let ([dotted (-v dotted)] - [vars (-v vars)] ...) - (make-PolyDots (list 'vars ... 'dotted) ty))])) - -(define-syntax -polyrow - (syntax-rules () - [(_ (var) consts ty) - (let ([var (-v var)]) - (make-PolyRow (list 'var) ty consts))])) +(define-syntax-rule (-poly (vars ...) ty) + (let ([vars (-v vars)] ...) (make-Poly (list 'vars ...) ty))) + +(define-syntax-rule (-polydots (vars ... dotted) ty) + (let ([dotted (-v dotted)] + [vars (-v vars)] ...) + (make-PolyDots (list 'vars ... 'dotted) ty))) + +(define-syntax-rule (-polyrow (var) consts ty) + (let ([var (-v var)]) (make-PolyRow (list 'var) ty consts))) ;; abbreviation for existential types -(define-syntax -some - (syntax-rules () - [(_ (vars ...) ty) - (let ([vars (-v vars)] ...) - (make-Some (list 'vars ...) ty))])) +(define-syntax-rule (-some (vars ...) ty) + (let ([vars (-v vars)] ...) (make-Some (list 'vars ...) ty))) ;; abbreviation for existential type results (define-syntax -some-res diff --git a/typed-racket-lib/typed-racket/types/classes.rkt b/typed-racket-lib/typed-racket/types/classes.rkt index 4e35d368c..1cf9b4d98 100644 --- a/typed-racket-lib/typed-racket/types/classes.rkt +++ b/typed-racket-lib/typed-racket/types/classes.rkt @@ -88,9 +88,9 @@ (match-define (Row: inits fields methods augments _) row) ;; check a given clause type (e.g., init, field) (define (check-clauses row-dict absence-set) - (for ([(name _) (in-dict row-dict)]) - (when (member name absence-set) - (fail name)))) + (for ([(name _) (in-dict row-dict)] + #:when (member name absence-set)) + (fail name))) (check-clauses inits init-absents) (check-clauses fields field-absents) (check-clauses methods method-absents) diff --git a/typed-racket-lib/typed-racket/types/generalize.rkt b/typed-racket-lib/typed-racket/types/generalize.rkt index 82710ae43..11f7efe01 100644 --- a/typed-racket-lib/typed-racket/types/generalize.rkt +++ b/typed-racket-lib/typed-racket/types/generalize.rkt @@ -45,15 +45,15 @@ [(Pair: t1 (== -Null)) (-lst t1)] [(MPair: t1 (== -Null)) (-mlst t1)] [(or (Pair: t1 t2) (MPair: t1 t2)) - (let ([t-new (loop t2)]) - (define -lst-type - ((match t* - [(Pair: _ _) -lst] - [(MPair: _ _) -mlst]) - t1)) - (if (type-equiv? -lst-type t-new) - -lst-type - (exit t)))] + (define t-new (loop t2)) + (define -lst-type + ((match t* + [(Pair: _ _) -lst] + [(MPair: _ _) -mlst]) + t1)) + (if (type-equiv? -lst-type t-new) + -lst-type + (exit t))] [(ListDots: t bound) (-lst (substitute Univ bound t))] [(? (lambda (t) (subtype t -Symbol))) -Symbol] [(== -True) -Boolean] diff --git a/typed-racket-lib/typed-racket/types/kw-types.rkt b/typed-racket-lib/typed-racket/types/kw-types.rkt index c218f177a..42e9ac352 100644 --- a/typed-racket-lib/typed-racket/types/kw-types.rkt +++ b/typed-racket-lib/typed-racket/types/kw-types.rkt @@ -31,8 +31,7 @@ ;; the kw protocol puts the arguments in keyword-sorted order in the ;; function header, so we need to sort the types to match (define sorted-kws - (sort keywords (λ (kw1 kw2) (keyword= (Arrow-max-arity a1) - (Arrow-max-arity a2))))) + (sort orig-arrows >= #:key Arrow-max-arity)) (for/fold ([mand-arg-table '()]) ([arrow (in-list arity-sorted-arrows)]) (cond @@ -172,36 +169,38 @@ ;; set and set->list to retain determinism (remove-duplicates (for/list ([(arrow arrow-mand-arg-count) (in-assoc mand-arg-table)]) - (match arrow - [(Arrow: dom rst kws rng rng-T+) - (define kws* (if actual-kws - (handle-extra-or-missing-kws kws actual-kws) - kws)) - (define kw-opts-supplied (if actual-kws - (lambda-kws-opt-supplied actual-kws) - '())) - (define mand-arg-count (if actual-kws - (lambda-kws-pos-mand-count actual-kws) - arrow-mand-arg-count)) - (define opt-arg-count (- (length dom) mand-arg-count)) - (define extra-opt-arg-count - ;; In case `dom` has too many arguments that we try to treat - ;; as optional: - (if actual-kws - (max 0 (- opt-arg-count (length (lambda-kws-pos-opt-supplied? actual-kws)))) - 0)) - (convert kws* - kw-opts-supplied - (take dom mand-arg-count) - (drop dom mand-arg-count) - (if actual-kws - (append (lambda-kws-pos-opt-supplied? actual-kws) - (make-list extra-opt-arg-count #f)) - (make-list opt-arg-count #f)) - rng - rst - split? - rng-T+)])))) + (match-define (Arrow: dom rst kws rng rng-T+) arrow) + (define kws* + (if actual-kws + (handle-extra-or-missing-kws kws actual-kws) + kws)) + (define kw-opts-supplied + (if actual-kws + (lambda-kws-opt-supplied actual-kws) + '())) + (define mand-arg-count + (if actual-kws + (lambda-kws-pos-mand-count actual-kws) + arrow-mand-arg-count)) + (define opt-arg-count (- (length dom) mand-arg-count)) + (define extra-opt-arg-count + ;; In case `dom` has too many arguments that we try to treat + ;; as optional: + (if actual-kws + (max 0 (- opt-arg-count (length (lambda-kws-pos-opt-supplied? actual-kws)))) + 0)) + (convert kws* + kw-opts-supplied + (take dom mand-arg-count) + (drop dom mand-arg-count) + (if actual-kws + (append (lambda-kws-pos-opt-supplied? actual-kws) + (make-list extra-opt-arg-count #f)) + (make-list opt-arg-count #f)) + rng + rst + split? + rng-T+)))) (apply cl->* fns)) ;; kw-convert : Type (Option LambdaKeywords) [Boolean] -> Type @@ -269,7 +268,7 @@ (take opt-types to-take)) (erase-props/Values rng) #:kws actual-kws - #:rest (if (= to-take opt-types-count) rest-type #f) + #:rest (and (= to-take opt-types-count) rest-type) #:T+ rng-T+)))] [else (int-err "unsupported arrs in keyword function type")])] [(Poly-names: names f) (make-Poly names (loop f))] diff --git a/typed-racket-lib/typed-racket/types/match-expanders.rkt b/typed-racket-lib/typed-racket/types/match-expanders.rkt index a0c7e3126..9e4c645e6 100644 --- a/typed-racket-lib/typed-racket/types/match-expanders.rkt +++ b/typed-racket-lib/typed-racket/types/match-expanders.rkt @@ -75,7 +75,7 @@ (app (λ (t) (Listof? t #t)) (? Type? elem-pat)))]))) -(define-simple-macro (make-Listof-pred listof-pred?:id pair-matcher:id) +(define-syntax-parse-rule (make-Listof-pred listof-pred?:id pair-matcher:id) (define (listof-pred? t [simple? #f]) (match t [(Mu-unsafe: diff --git a/typed-racket-lib/typed-racket/types/printer.rkt b/typed-racket-lib/typed-racket/types/printer.rkt index 8fd78cfde..94c4bc464 100644 --- a/typed-racket-lib/typed-racket/types/printer.rkt +++ b/typed-racket-lib/typed-racket/types/printer.rkt @@ -132,7 +132,7 @@ (define name-ref->sexp (match-lambda [(? syntax? name-ref) (syntax-e name-ref)] - [(cons lvl arg) `(,lvl ,arg)])) + [(cons lvl arg) (list lvl arg)])) ;; prop->sexp : Prop -> S-expression ;; Print a Prop (see prop-rep.rkt) to the given port @@ -149,20 +149,19 @@ ;; instead of (<= x y) (<= y x) when we have both inequalities (define-values (leqs others) (partition LeqProp? ps)) (define-values (eqs simple-leqs) - (for/fold ([eqs '()] [simple-leqs '()]) + (for/fold ([eqs '()] + [simple-leqs '()]) ([leq (in-list leqs)]) - (match leq - [(LeqProp: lhs rhs) - (define flip (-leq rhs lhs)) - (cond - [(not (member flip leqs)) - (values eqs (cons leq simple-leqs))] - [(member flip eqs) (values eqs simple-leqs)] - [else (values (cons leq eqs) simple-leqs)])]))) + (match-define (LeqProp: lhs rhs) leq) + (define flip (-leq rhs lhs)) + (cond + [(not (member flip leqs)) (values eqs (cons leq simple-leqs))] + [(member flip eqs) (values eqs simple-leqs)] + [else (values (cons leq eqs) simple-leqs)]))) (let ([simple-leqs (map prop->sexp simple-leqs)] [eqs (for/list ([leq (in-list eqs)]) - (match leq - [(LeqProp: lhs rhs) `(= ,(object->sexp lhs) ,(object->sexp rhs))]))] + (match-define (LeqProp: lhs rhs) leq) + `(= ,(object->sexp lhs) ,(object->sexp rhs)))] [others (map prop->sexp others)]) (match (append eqs simple-leqs others) [(list sexp) sexp] @@ -317,37 +316,36 @@ valid-names)) ;; some types in the union may not be coverable by the candidates ;; (e.g. type variables, etc.) - (define-values (uncoverable coverable) - (values (apply set-subtract elems (map cdr candidates)) - (set-intersect elems (apply set-union null (map cdr candidates))))) + (define uncoverable (apply set-subtract elems (map cdr candidates))) + (define coverable (set-intersect elems (apply set-union null (map cdr candidates)))) ;; set cover, greedy algorithm, ~lg n approximation (let loop ([to-cover coverable] [candidates candidates] [coverage '()]) - (cond [(null? to-cover) ; done - (define coverage-names (map car coverage)) - ;; to allow :type to cue the user on unexpanded aliases - ;; only union types can flow here, and any of those could be expanded - (set-box! (current-print-unexpanded) - (append coverage-names (unbox (current-print-unexpanded)))) - ;; reverse here to retain the old ordering from when srfi/1 was - ;; used to process the list sets - (values coverage-names (reverse uncoverable))] ; we want the names - [else - ;; pick the candidate that covers the most uncovered types - (define (covers-how-many? c) - (length (set-intersect (cdr c) to-cover))) - (define-values (next _) - (for/fold ([next (car candidates)] - [max-cover (covers-how-many? (car candidates))]) - ([c (in-list candidates)]) - (let ([how-many? (covers-how-many? c)]) - (if (> how-many? max-cover) - (values c how-many?) - (values next max-cover))))) - (loop (set-subtract to-cover (cdr next)) - (remove next candidates) - (cons next coverage))]))) + (cond + [(null? to-cover) ; done + (define coverage-names (map car coverage)) + ;; to allow :type to cue the user on unexpanded aliases + ;; only union types can flow here, and any of those could be expanded + (set-box! (current-print-unexpanded) + (append coverage-names (unbox (current-print-unexpanded)))) + ;; reverse here to retain the old ordering from when srfi/1 was + ;; used to process the list sets + (values coverage-names (reverse uncoverable))] ; we want the names + [else + ;; pick the candidate that covers the most uncovered types + (define (covers-how-many? c) + (length (set-intersect (cdr c) to-cover))) + (define next + (for/fold ([next (car candidates)] + [max-cover (covers-how-many? (car candidates))] + #:result next) + ([c (in-list candidates)]) + (let ([how-many? (covers-how-many? c)]) + (if (> how-many? max-cover) + (values c how-many?) + (values next max-cover))))) + (loop (set-subtract to-cover (cdr next)) (remove next candidates) (cons next coverage))]))) ;; arr->sexp : arr -> s-expression ;; Convert an arr (see type-rep.rkt) to its printable form @@ -365,11 +363,10 @@ ;; as long as the resulting s-expressions are `display`ed ;; this is fine, though it may not pretty-print well. (for/list ([kw (in-list kws)]) - (match kw - [(Keyword: k t req?) - (if req? - (format "~a ~a" k (type->sexp t)) - (format "[~a ~a]" k (type->sexp t)))])) + (match-define (Keyword: k t req?) kw) + (if req? + (format "~a ~a" k (type->sexp t)) + (format "[~a ~a]" k (type->sexp t)))) (match rst [(Rest: (list rst-t)) `(,(type->sexp rst-t) *)] [(Rest: rst-ts) `(#:rest-star ,(map type->sexp rst-ts))] @@ -461,8 +458,9 @@ (define-values (pre mid) (split-at lst to-drop)) (define-values (sub post) (split-at mid n)) (list pre sub post))) - (apply append (for/list ([i (range (length lst) 0 -1)]) - (sublist-n i lst)))) + (for*/list ([i (range (length lst) 0 -1)] + [v (in-list (sublist-n i lst))]) + v)) (let loop ([left-to-cover arrs]) ;; try to match the largest sublists possible that correspond to ;; ->* types and then the remainder are formatted normally @@ -478,16 +476,15 @@ ;; case-lambda->sexp : Type -> S-expression ;; Convert a case-> type to an s-expression (define (case-lambda->sexp type) - (match type - [(Fun: arrows) - (match arrows - [(list) '(case->)] - [(list a) (arr->sexp a)] - [(and arrs (list a b ...)) - (define cover (cover-case-lambda arrs)) - (if (> (length cover) 1) - `(case-> ,@cover) - (car cover))])])) + (match-define (Fun: arrows) type) + (match arrows + [(list) '(case->)] + [(list a) (arr->sexp a)] + [(and arrs (list a b ...)) + (define cover (cover-case-lambda arrs)) + (if (> (length cover) 1) + `(case-> ,@cover) + (car cover))])) ;; class->sexp : Class [#:object? Boolean] -> S-expression ;; Convert a class or object type to an s-expression @@ -512,11 +509,11 @@ (cons 'field (for/list ([name+type (in-list fields)]) (match-define (list name type) name+type) - `(,name ,(type->sexp type))))))) + (list name (type->sexp type))))))) (define methods* (for/list ([name+type (in-list methods)]) (match-define (list name type) name+type) - `(,name ,(type->sexp type)))) + (list name (type->sexp type)))) (define augments* (cond [(or object? (null? augments)) '()] [else (list (cons 'augment augments))])) @@ -613,7 +610,7 @@ (=> fail) (unless (null? ignored-names) (fail)) (define fuel (current-print-type-fuel)) - (cond [(> fuel 0) + (cond [(positive? fuel) (parameterize ([current-print-type-fuel (sub1 fuel)]) ;; if we still have fuel, print the expanded type and ;; add the name to the ignored list so that the union diff --git a/typed-racket-lib/typed-racket/types/prop-ops.rkt b/typed-racket-lib/typed-racket/types/prop-ops.rkt index e6e90c774..69589fe21 100644 --- a/typed-racket-lib/typed-racket/types/prop-ops.rkt +++ b/typed-racket-lib/typed-racket/types/prop-ops.rkt @@ -54,22 +54,24 @@ ;; can't be False, then the else prop should be -ff) (define (reduce-tc-results/subsumption res) (define (update-ps tcr) - (match tcr - [(tc-result: t ps obj) + (match-define (tc-result: t ps obj) tcr) + (cond + [(Bottom? t) (-tc-result t -ff-propset -empty-obj)] + [else + (define p+ + (if ps + (PropSet-thn ps) + -tt)) + (define p- + (if ps + (PropSet-els ps) + -tt)) + (define o (if obj obj -empty-obj)) (cond - [(Bottom? t) (-tc-result t -ff-propset -empty-obj)] - [else - (define p+ (if ps (PropSet-thn ps) -tt)) - (define p- (if ps (PropSet-els ps) -tt)) - (define o (if obj obj -empty-obj)) - (cond - [(or (equal? -False t) - (FalseProp? p+)) - (-tc-result (intersect t -False) (-PS -ff p-) o)] - [(not (overlap? t -False)) - (-tc-result t (-PS p+ -ff) o)] - [(FalseProp? p-) (-tc-result (subtract t -False) (-PS p+ -ff) o)] - [else (-tc-result t (-PS p+ p-) o)])])])) + [(or (equal? -False t) (FalseProp? p+)) (-tc-result (intersect t -False) (-PS -ff p-) o)] + [(not (overlap? t -False)) (-tc-result t (-PS p+ -ff) o)] + [(FalseProp? p-) (-tc-result (subtract t -False) (-PS p+ -ff) o)] + [else (-tc-result t (-PS p+ p-) o)])])) (match res [(tc-any-results: _) res] [(tc-results: tcrs db) @@ -108,13 +110,11 @@ (and (equal? pes1 (drop pes2 prefix-len)) (let ([prefix (take pes2 prefix-len)]) (Bottom? (update t1 t2 #t prefix))))) - (let ([len1 (length pes1)] - [len2 (length pes2)]) - (cond - [(<= len1 len2) - (check pes1 t1 pes2 t2 (- len2 len1))] - [else - (check pes2 t2 pes1 t1 (- len1 len2))]))) + (define len1 (length pes1)) + (define len2 (length pes2)) + (cond + [(<= len1 len2) (check pes1 t1 pes2 t2 (- len2 len1))] + [else (check pes2 t2 pes1 t1 (- len1 len2))])) ;; does pes2 refer to the same or a subcomponent of ;; pes1 and if so, does updating the t1+ w/ the t2- @@ -379,9 +379,7 @@ [(AndProp: ps*) (partition! ps*)] [_ (set! others (cons p others))]))) (define ors-smallest-to-largest - (append-map cdr (sort (hash->list ors) - (λ (len/ors1 len/ors2) - (< (car len/ors1) (car len/ors2)))))) + (append-map cdr (sort (hash->list ors) < #:key car))) (remove-duplicates (append ts nts others ors-smallest-to-largest) eq?)) (let loop ([ps (flatten-ands/remove-duplicates/order args)] [result null]) @@ -423,17 +421,14 @@ [((Fun: (list (Arrow: dom rst kws rng rng-T+))) type) (match rng [(Values: (list (Result: tp (PropSet: p+ p-) op))) - (let ([new-props (apply -and (build-list (length dom) - (lambda (i) - (-is-type i type))))]) - (make-Fun - (list (make-Arrow dom rst kws - (make-Values - (list (-result tp - (-PS (-and p+ new-props) - (-and p- new-props)) - op))) - rng-T+))))])]) + (define new-props (apply -and (build-list (length dom) (lambda (i) (-is-type i type))))) + (make-Fun + (list (make-Arrow + dom + rst + kws + (make-Values (list (-result tp (-PS (-and p+ new-props) (-and p- new-props)) op))) + rng-T+)))])]) ;; tc-results/c -> tc-results/c (define/match (erase-props tc) diff --git a/typed-racket-lib/typed-racket/types/resolve.rkt b/typed-racket-lib/typed-racket/types/resolve.rkt index 913cfa93f..50d774118 100644 --- a/typed-racket-lib/typed-racket/types/resolve.rkt +++ b/typed-racket-lib/typed-racket/types/resolve.rkt @@ -49,8 +49,7 @@ ;; return #t when t is not a registered name yet. (lookup-type-name t (lambda () #t))) t))) - (if (Type? t) t - #f)] + (and (Type? t) t)] [(_ _) (int-err "resolve-name: not a name ~a" t)])) (define already-resolving? (make-parameter #f)) @@ -62,18 +61,18 @@ (free-identifier=? n (poly-name (current-poly-struct)))) (define poly-num (length (poly-vars (current-poly-struct)))) (if (= poly-num (length rands)) - (when (not (or (ormap Error? rands) - (andmap equal? rands - (poly-vars (current-poly-struct))))) + (unless (or (ormap Error? rands) (andmap equal? rands (poly-vars (current-poly-struct)))) (tc-error (~a "structure type constructor applied to non-regular arguments" - "\n type: " rator - "\n arguments...: " rands))) + "\n type: " + rator + "\n arguments...: " + rands))) (tc-error (~a "wrong number of arguments to structure type constructor" "\n type: " rator "\n expected: " poly-num "\n given: " (length rands) "\n arguments...: " rands)))] - [(Name: name-id num-args _) #:when (> num-args 0) + [(Name: name-id num-args _) #:when (positive? num-args) (define num-rands (length rands)) (unless (= num-rands num-args) (tc-error (~a "wrong number of arguments to polymorphic type" @@ -98,11 +97,11 @@ (resolve-app-check-error rator rands orig-stx) (match rator [(? Name?) - (let ([r (resolve-name rator #t)]) - (and r - (if (TypeConstructor? r) - (apply r rands) - (resolve-app r rands stx))))] + (define r (resolve-name rator #t)) + (and r + (if (TypeConstructor? r) + (apply r rands) + (resolve-app r rands stx)))] [(App: r r*) (resolve-app (resolve-app r r* (current-orig-stx)) rands (current-orig-stx))] diff --git a/typed-racket-lib/typed-racket/types/signatures.rkt b/typed-racket-lib/typed-racket/types/signatures.rkt index ef1d115ac..2960079ac 100644 --- a/typed-racket-lib/typed-racket/types/signatures.rkt +++ b/typed-racket-lib/typed-racket/types/signatures.rkt @@ -49,17 +49,24 @@ ;; the given signature extends including itself ;; returns '() when given #f (define (signature-extensions sig*) - (let ([sig (and sig* (if (Signature? sig*) sig* (lookup-signature sig*)))]) - (if sig - (cons (Signature-name sig) - (signature-extensions (Signature-extends sig))) - null))) + (define sig + (and sig* + (if (Signature? sig*) + sig* + (lookup-signature sig*)))) + (if sig + (cons (Signature-name sig) (signature-extensions (Signature-extends sig))) + null)) (define (flatten-sigs sig*) - (let ([sig (and sig* (if (Signature? sig*) sig* (lookup-signature sig*)))]) - (if sig - (cons sig (flatten-sigs (Signature-extends sig))) - null))) + (define sig + (and sig* + (if (Signature? sig*) + sig* + (lookup-signature sig*)))) + (if sig + (cons sig (flatten-sigs (Signature-extends sig))) + null)) ;; : (listof Signature) -> boolean diff --git a/typed-racket-lib/typed-racket/types/substitute.rkt b/typed-racket-lib/typed-racket/types/substitute.rkt index 381fe65da..22e376517 100644 --- a/typed-racket-lib/typed-racket/types/substitute.rkt +++ b/typed-racket-lib/typed-racket/types/substitute.rkt @@ -75,13 +75,16 @@ (let sub ([target target]) (match target [(ListDots: dty dbound) - (if (eq? name dbound) - ;; We need to recur first, just to expand out any dotted usages of this. - (let ([expanded (sub dty)]) - (for/fold ([t (if rimage (-lst rimage) -Null)]) - ([img (in-list (reverse images))]) - (make-Pair (substitute img name expanded) t))) - (make-ListDots (sub dty) dbound))] + (cond + [(eq? name dbound) + ;; We need to recur first, just to expand out any dotted usages of this. + (define expanded (sub dty)) + (for/fold ([t (if rimage + (-lst rimage) + -Null)]) + ([img (in-list (reverse images))]) + (make-Pair (substitute img name expanded) t))] + [else (make-ListDots (sub dty) dbound)])] [(SequenceDots: types dty dbound) (if (eq? name dbound) (if rimage diff --git a/typed-racket-lib/typed-racket/types/subtype.rkt b/typed-racket-lib/typed-racket/types/subtype.rkt index e4301d3ef..a223d643b 100644 --- a/typed-racket-lib/typed-racket/types/subtype.rkt +++ b/typed-racket-lib/typed-racket/types/subtype.rkt @@ -533,7 +533,7 @@ (with-updated-seen A ;; be provable for subtyping to hold (define-values (t1* extracted-props) (extract-props obj t1)) - (define assumptions (apply -and (cons (-is-type obj t1*) extracted-props))) + (define assumptions (apply -and (-is-type obj t1*) extracted-props)) (define goal (match* (lower-ineq upper-ineq) @@ -658,9 +658,7 @@ ;; FIXME: thread the store through here (for/or ([num-t (in-list num-seq-types)]) (or (and (subtype* A t1 num-t) num-t)))) - (if type - (subtype* A type seq-t) - #f)] + (and type (subtype* A type seq-t))] [else #f])] [(Evt: evt-t) (cond @@ -793,30 +791,24 @@ (for/fold ([A A]) ([a2 (in-list arrows2)] #:break (not A)) - (match a2 - [(Arrow: dom2 rst2 kws2 raw-rng2) - (define A* (subtype-seq A - (subtypes* dom2 dom1) - (kw-subtypes* '() kws2))) - (cond - [(not A*) #f] - [else - (define arity (max (length dom1) (length dom2))) - (define-values (mapping t2s) - (for/lists (_1 _2) - ([idx (in-range arity)] - [id (in-list ids)]) - (define t (dom+rst-ref dom2 rst2 idx Univ)) - (values (list* idx id t) t))) - (with-naively-extended-lexical-env - [#:identifiers ids - #:types t2s] - (define A-res - (subval* A* - (instantiate-obj+simplify raw-rng1 mapping) - (instantiate-obj raw-rng2 ids))) - (and (implies-in-env? (lexical-env) -tt pre1) - A-res))])])))] + (match-define (Arrow: dom2 rst2 kws2 raw-rng2) a2) + (define A* (subtype-seq A (subtypes* dom2 dom1) (kw-subtypes* '() kws2))) + (cond + [(not A*) #f] + [else + (define arity (max (length dom1) (length dom2))) + (define-values (mapping t2s) + (for/lists (_1 _2) + ([idx (in-range arity)] [id (in-list ids)]) + (define t (dom+rst-ref dom2 rst2 idx Univ)) + (values (list* idx id t) t))) + (with-naively-extended-lexical-env [#:identifiers ids #:types t2s] + (define A-res + (subval* A* + (instantiate-obj+simplify raw-rng1 mapping) + (instantiate-obj raw-rng2 ids))) + (and (implies-in-env? (lexical-env) -tt pre1) + A-res))])))] [_ (continue<: A t1 t2 obj)])] [(case: Distinction (Distinction: nm1 id1 t1*)) (match t2 diff --git a/typed-racket-lib/typed-racket/types/tc-result.rkt b/typed-racket-lib/typed-racket/types/tc-result.rkt index 1b0cc074a..021f27cd3 100644 --- a/typed-racket-lib/typed-racket/types/tc-result.rkt +++ b/typed-racket-lib/typed-racket/types/tc-result.rkt @@ -156,8 +156,8 @@ [(_ t ps o) (tc-results: (list (tc-result: t ps o _)) #f)])) (define (tc-results-ts* tc) - (match tc - [(tc-results: (list (tc-result: ts _ _ _) ...) _) ts])) + (match-define (tc-results: (list (tc-result: ts _ _ _) ...) _) tc) + ts) (define-match-expander Result1: (syntax-rules () diff --git a/typed-racket-lib/typed-racket/types/utils.rkt b/typed-racket-lib/typed-racket/types/utils.rkt index b547010c2..69ea0c83d 100644 --- a/typed-racket-lib/typed-racket/types/utils.rkt +++ b/typed-racket-lib/typed-racket/types/utils.rkt @@ -16,7 +16,8 @@ (provide (all-from-out "tc-result.rkt" "tc-error.rkt")) -(define dom+rst-ref-failure (λ () (int-err "invalid index for domain and rest args"))) +(define (dom+rst-ref-failure) + (int-err "invalid index for domain and rest args")) ;; given the list of domain types (dom) ;; and the functions rest spec (rst), @@ -57,11 +58,10 @@ (int-err "instantiate-poly: wrong number of types: expected at least ~a, got ~a" (length fixed) (length types))) - (let* ([fixed-tys (take types (length fixed))] - [rest-tys (drop types (length fixed))] - [body* (subst-all (make-simple-substitution fixed fixed-tys) - body)]) - (substitute-dots rest-tys #f dotted body*))] + (define fixed-tys (take types (length fixed))) + (define rest-tys (drop types (length fixed))) + (define body* (subst-all (make-simple-substitution fixed fixed-tys) body)) + (substitute-dots rest-tys #f dotted body*)] [(PolyRow: names body _) (unless (= (length types) (length names)) (int-err "instantiate-poly: wrong number of types: expected ~a, got ~a" @@ -76,8 +76,8 @@ (int-err (string-append "instantiate-poly-dotted: wrong number of" " types: expected ~a, got ~a, types were ~a") (length fixed) (length types) types)) - (let ([body* (subst-all (make-simple-substitution fixed types) body)]) - (substitute-dotted null image var dotted body*))] + (define body* (subst-all (make-simple-substitution fixed types) body)) + (substitute-dotted null image var dotted body*)] [_ (int-err "instantiate-poly-dotted: requires PolyDots type, got ~a" t)])) diff --git a/typed-racket-test/main.rkt b/typed-racket-test/main.rkt index 85f66a8fb..ed47d35a2 100644 --- a/typed-racket-test/main.rkt +++ b/typed-racket-test/main.rkt @@ -32,17 +32,15 @@ (define (exn-pred p) - (let ([sexp (with-handlers - ([exn:fail? (lambda _ #f)]) - (call-with-input-file* - p - (lambda (prt) - (read-line prt 'any) (read prt))))]) - (match sexp - [(list-rest 'exn-pred e) - (eval `(exn-matches . ,e) (namespace-anchor->namespace a))] - [_ - (exn-matches ".*Type Checker.*" exn:fail:syntax?)]))) + (define sexp + (with-handlers ([exn:fail? (lambda _ #f)]) + (call-with-input-file* p + (lambda (prt) + (read-line prt 'any) + (read prt))))) + (match sexp + [(list-rest 'exn-pred e) (eval `(exn-matches . ,e) (namespace-anchor->namespace a))] + [_ (exn-matches ".*Type Checker.*" exn:fail:syntax?)])) (define-runtime-path src-dir ".") @@ -61,21 +59,21 @@ (not (set-member? excl (path->string (file-name-from-path p*)))))) (define-values [p*-base p*-name _] (split-path p*)) - (define prm (list p*-base p*-name - (if (places) - (delay/thread - (begin0 (run-in-other-place p* error?) - (when (zero? (modulo i 10)) - (eprintf ".")))) - (delay - (parameterize ([read-accept-reader #t] - [current-load-relative-directory p*-base] - [current-directory p*-base] - [current-output-port (open-output-nowhere)]) - (begin0 (dr p*-name) - (when (zero? (modulo i 10)) - (eprintf ".")))))))) - prm)) + (list p*-base + p*-name + (if (places) + (delay/thread + (begin0 (run-in-other-place p* error?) + (when (zero? (modulo i 10)) + (eprintf ".")))) + (delay + (parameterize ([read-accept-reader #t] + [current-load-relative-directory p*-base] + [current-directory p*-base] + [current-output-port (open-output-nowhere)]) + (begin0 (dr p*-name) + (when (zero? (modulo i 10)) + (eprintf "."))))))))) (define tests (for/list ([e prms]) (match-define (list path p prm) e) @@ -114,15 +112,16 @@ (define shootout (collection-path "tests" "racket" "benchmarks" "shootout" "typed")) (define common (collection-path "tests" "racket" "benchmarks" "common" "typed")) (define (mk dir) - (let ((promised-results - (for/hash ([file (in-list (directory-list dir))] - #:when (scheme-file? file)) - (values (path->string file) - (delay/thread (compile-path (build-path dir file))))))) - (make-test-suite (path->string dir) - (for/list ([(name results) promised-results]) - (test-suite name - (check-not-exn (λ () (force results)))))))) + (define promised-results + (for/hash ([file (in-list (directory-list dir))] + #:when (scheme-file? file)) + (values (path->string file) + (delay/thread + (compile-path (build-path dir file)))))) + (make-test-suite (path->string dir) + (for/list ([(name results) promised-results]) + (test-suite name + (check-not-exn (λ () (force results))))))) (test-suite "Compiling Benchmark tests" @@ -164,23 +163,19 @@ (define (just-one p*) (define-values (path p b) (split-path p*)) + (define dir (path->string path)) (define f - (let ([dir (path->string path)]) - (cond [(regexp-match? #rx"fail/" dir ) - (lambda (p thnk) - (define-values (pred info) (exn-pred p)) - (parameterize ([error-display-handler void]) - (with-check-info - (['predicates info]) - (check-exn pred thnk))))] - [(regexp-match? #rx"succeed/" dir) - (lambda (p thnk) (check-not-exn thnk))] - [(regexp-match? #rx"optimizer/tests/$" dir) - (lambda (p* thnk) (test-opt p))] - [(regexp-match? #rx"optimizer/missed-optimizations/$" dir) - (lambda (p* thnk) (test-missed-optimization p))] - [else - (error 'just-one "Unknown test kind for test: ~a" p*)]))) + (cond + [(regexp-match? #rx"fail/" dir) + (lambda (p thnk) + (define-values (pred info) (exn-pred p)) + (parameterize ([error-display-handler void]) + (with-check-info (['predicates info]) (check-exn pred thnk))))] + [(regexp-match? #rx"succeed/" dir) (lambda (p thnk) (check-not-exn thnk))] + [(regexp-match? #rx"optimizer/tests/$" dir) (lambda (p* thnk) (test-opt p))] + [(regexp-match? #rx"optimizer/missed-optimizations/$" dir) + (lambda (p* thnk) (test-missed-optimization p))] + [else (error 'just-one "Unknown test kind for test: ~a" p*)])) (test-suite (path->string p) (f @@ -271,20 +266,37 @@ (run-unit-test-suite (or (places) 1)) 0)) - (if (and (nightly?) (eq? 'cgc (system-type 'gc))) - (printf "Skipping Typed Racket tests.\n") - (let ([to-run (cond [(single) (list (single))] - [else - (append (if (int?) (list (int-tests (excl))) '()) - (if (gui?) (list (gui-tests)) '()) - (if (external?) (list (external-tests)) '()) - (if (opt?) (list (optimization-tests)) '()) - (if (missed-opt?) (list (missed-optimization-tests)) '()) - (if (bench?) (list (compile-benchmarks)) '()) - (if (math?) (list (compile-math)) '()))])]) - (unless (and (= unit-test-retcode 0) (= 0 ((exec) to-run))) - (eprintf "Typed Racket Tests did not pass.\n") - (exit 1))))) + (cond + [(and (nightly?) (eq? 'cgc (system-type 'gc))) (printf "Skipping Typed Racket tests.\n")] + [else + (define to-run + (cond + [(single) (list (single))] + [else + (append (if (int?) + (list (int-tests (excl))) + '()) + (if (gui?) + (list (gui-tests)) + '()) + (if (external?) + (list (external-tests)) + '()) + (if (opt?) + (list (optimization-tests)) + '()) + (if (missed-opt?) + (list (missed-optimization-tests)) + '()) + (if (bench?) + (list (compile-benchmarks)) + '()) + (if (math?) + (list (compile-math)) + '()))])) + (unless (and (= unit-test-retcode 0) (= 0 ((exec) to-run))) + (eprintf "Typed Racket Tests did not pass.\n") + (exit 1))])) ;; nightly tests in `run.rkt` for drdr chart continuity (module test racket/base) diff --git a/typed-racket-test/places.rkt b/typed-racket-test/places.rkt index 3c26d4f39..6eace20df 100644 --- a/typed-racket-test/places.rkt +++ b/typed-racket-test/places.rkt @@ -35,12 +35,13 @@ (define (dr p) (parameterize ([current-namespace (make-base-empty-namespace)]) - (let* ([root-module `(file ,(if (string? p) p (path->string p)))] - [submodule-test `(submod ,root-module test)] - [module-path (if (module-declared? submodule-test #t) - submodule-test - root-module)]) - (dynamic-require module-path #f)))) + (define root-module + `(file ,(if (string? p) + p + (path->string p)))) + (define submodule-test `(submod ,root-module test)) + (define module-path (if (module-declared? submodule-test #t) submodule-test root-module)) + (dynamic-require module-path #f))) (define (start-worker get-ch name) diff --git a/typed-racket-test/send-places.rkt b/typed-racket-test/send-places.rkt index 4e2b2545d..fc0b5641b 100644 --- a/typed-racket-test/send-places.rkt +++ b/typed-racket-test/send-places.rkt @@ -50,9 +50,9 @@ (define-values (res-ch res-ch*) (place-channel)) (place-channel-put enq-ch (vector 'log name dir res-ch*)) (define res (place-channel-get res-ch)) - (if (s-exn? res) - (raise (deserialize-exn res)) - res)] + (when (s-exn? res) + (raise (deserialize-exn res))) + res] [else (generate-log/place name dir)]))) @@ -61,8 +61,8 @@ (define-values (res-ch res-ch*) (place-channel)) (place-channel-put enq-ch (vector 'compile file res-ch*)) (define res (place-channel-get res-ch)) - (if (s-exn? res) - (raise (deserialize-exn res)) - res)] + (when (s-exn? res) + (raise (deserialize-exn res))) + res] [else (compile-path/place file)]))