From c5e6f50d96f84503bfe48b6738fc85de774a3d76 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 01/17] Fix 14 occurrences of `single-clause-match-to-match-define` This `match` expression can be simplified using `match-define`. --- .../typed-racket/infer/constraints.rkt | 10 +- .../typed-racket/infer/infer-unit.rkt | 106 ++++++++---------- .../typed-racket/infer/promote-demote.rkt | 26 +---- typed-racket-lib/typed-racket/logic/ineq.rkt | 11 +- .../static-contracts/combinators/object.rkt | 4 +- 5 files changed, 60 insertions(+), 97 deletions(-) diff --git a/typed-racket-lib/typed-racket/infer/constraints.rkt b/typed-racket-lib/typed-racket/infer/constraints.rkt index adf1aab67..47294e2e4 100644 --- a/typed-racket-lib/typed-racket/infer/constraints.rkt +++ b/typed-racket-lib/typed-racket/infer/constraints.rkt @@ -25,12 +25,10 @@ ;; add the constraints S <: var <: T to every map in cs (define (insert cs var S T) - (match cs - [(struct cset (maps)) - (make-cset (for/list ([map-entry (in-list maps)]) - (match-define (cons map dmap) map-entry) - (cons (hash-set map var (make-c S T)) - dmap)))])) + (match-define (struct cset (maps)) cs) + (make-cset (for/list ([map-entry (in-list maps)]) + (match-define (cons map dmap) map-entry) + (cons (hash-set map var (make-c S T)) dmap)))) ;; meet: Type Type -> Type ;; intersect the given types, producing the greatest lower bound diff --git a/typed-racket-lib/typed-racket/infer/infer-unit.rkt b/typed-racket-lib/typed-racket/infer/infer-unit.rkt index 66f6253d4..984bbdcc6 100644 --- a/typed-racket-lib/typed-racket/infer/infer-unit.rkt +++ b/typed-racket-lib/typed-racket/infer/infer-unit.rkt @@ -65,34 +65,28 @@ [indices (listof symbol?)]) #:transparent) (define (context-add-vars ctx vars) - (match ctx - [(context V X Y) - (context V (append vars X) Y)])) + (match-define (context V X Y) ctx) + (context V (append vars X) Y)) (define (context-add-var ctx var) - (match ctx - [(context V X Y) - (context V (cons var X) Y)])) + (match-define (context V X Y) ctx) + (context V (cons var X) Y)) (define (context-add ctx #:bounds [bounds empty] #:vars [vars empty] #:indices [indices empty]) - (match ctx - [(context V X Y) - (context (append bounds V) (append vars X) (append indices Y))])) + (match-define (context V X Y) ctx) + (context (append bounds V) (append vars X) (append indices Y))) (define (inferable-index? ctx bound) - (match ctx - [(context _ _ Y) - (memq bound Y)])) + (match-define (context _ _ Y) ctx) + (memq bound Y)) (define ((inferable-var? ctx) var) - (match ctx - [(context _ X _) - (memq var X)])) + (match-define (context _ X _) ctx) + (memq var X)) (define (empty-cset/context ctx) - (match ctx - [(context _ X Y) - (empty-cset X Y)])) + (match-define (context _ X Y) ctx) + (empty-cset X Y)) @@ -766,9 +760,8 @@ (list values -Nat))) (define type (for/or ([pred-type (in-list possibilities)]) - (match pred-type - [(list pred? type) - (and (pred? n) type)]))) + (match-define (list pred? type) pred-type) + (and (pred? n) type))) (cgen/seq context (seq (list type) -null-end) ts*)] ;; numeric? == #true [((Base-bits: #t _) (SequenceSeq: ts*)) @@ -917,16 +910,12 @@ ;; c : Constaint ;; variance : Variance (define (constraint->type v variance) - (match v - [(c S T) - (match variance - [(? variance:const?) S] - [(? variance:co?) S] - [(? variance:contra?) T] - [(? variance:inv?) (let ([gS (generalize S)]) - (if (subtype gS T) - gS - S))])])) + (match-define (c S T) v) + (match variance + [(? variance:const?) S] + [(? variance:co?) S] + [(? variance:contra?) T] + [(? variance:inv?) (let ([gS (generalize S)]) (if (subtype gS T) gS S))])) ;; Since we don't add entries to the empty cset for index variables (since there is no ;; widest constraint, due to dcon-exacts), we must add substitutions here if no constraint @@ -946,37 +935,30 @@ [(? variance:inv?) (i-subst null)])))) S)) (define (build-subst m) - (match m - [(cons cmap (dmap dm)) - (let* ([subst (hash-union - (for/hash ([(k dc) (in-hash dm)]) - (define (c->t c) (constraint->type c (hash-ref idx-hash k variance:const))) - (values - k - (match dc - [(dcon fixed #f) - (i-subst (map c->t fixed))] - [(or (dcon fixed rest) (dcon-exact fixed rest)) - (i-subst/starred - (map c->t fixed) - (c->t rest))] - [(dcon-dotted fixed dc dbound) - (i-subst/dotted - (map c->t fixed) - (c->t dc) - dbound)]))) - (for/hash ([(k v) (in-hash cmap)]) - (values k (t-subst (constraint->type v (hash-ref var-hash k variance:const))))))] - [subst (for/fold ([subst subst]) ([v (in-list X)]) - (let ([entry (hash-ref subst v #f)]) - ;; Make sure we got a subst entry for a type var - ;; (i.e. just a type to substitute) - ;; If we don't have one, there are no constraints on this variable - (if (and entry (t-subst? entry)) - subst - (hash-set subst v (t-subst Univ)))))]) - ;; verify that we got all the important variables - (extend-idxs subst))])) + (match-define (cons cmap (dmap dm)) m) + (let* ([subst (hash-union + (for/hash ([(k dc) (in-hash dm)]) + (define (c->t c) + (constraint->type c (hash-ref idx-hash k variance:const))) + (values k + (match dc + [(dcon fixed #f) (i-subst (map c->t fixed))] + [(or (dcon fixed rest) (dcon-exact fixed rest)) + (i-subst/starred (map c->t fixed) (c->t rest))] + [(dcon-dotted fixed dc dbound) + (i-subst/dotted (map c->t fixed) (c->t dc) dbound)]))) + (for/hash ([(k v) (in-hash cmap)]) + (values k (t-subst (constraint->type v (hash-ref var-hash k variance:const))))))] + [subst (for/fold ([subst subst]) ([v (in-list X)]) + (let ([entry (hash-ref subst v #f)]) + ;; Make sure we got a subst entry for a type var + ;; (i.e. just a type to substitute) + ;; If we don't have one, there are no constraints on this variable + (if (and entry (t-subst? entry)) + subst + (hash-set subst v (t-subst Univ)))))]) + ;; verify that we got all the important variables + (extend-idxs subst))) (if multiple-substitutions? (for/list ([md (in-stream (cset-maps C))]) (build-subst md)) diff --git a/typed-racket-lib/typed-racket/infer/promote-demote.rkt b/typed-racket-lib/typed-racket/infer/promote-demote.rkt index 21a321c2f..6947195e0 100644 --- a/typed-racket-lib/typed-racket/infer/promote-demote.rkt +++ b/typed-racket-lib/typed-racket/infer/promote-demote.rkt @@ -39,26 +39,12 @@ ;; arr? -> (or/c #f arr?) ;; Returns the changed arr or #f if there is no arr above it (define (arr-change arr) - (match arr - [(Arrow: dom rst kws rng rng-T+) - (cond - [(apply V-in? V (get-propsets rng)) - #f] - [(and (RestDots? rst) - (memq (RestDots-nm rst) V)) - (make-Arrow - (map contra dom) - (contra (RestDots-ty rst)) - (map contra kws) - (co rng) - rng-T+)] - [else - (make-Arrow - (map contra dom) - (and rst (contra rst)) - (map contra kws) - (co rng) - rng-T+)])])) + (match-define (Arrow: dom rst kws rng rng-T+) arr) + (cond + [(apply V-in? V (get-propsets rng)) #f] + [(and (RestDots? rst) (memq (RestDots-nm rst) V)) + (make-Arrow (map contra dom) (contra (RestDots-ty rst)) (map contra kws) (co rng) rng-T+)] + [else (make-Arrow (map contra dom) (and rst (contra rst)) (map contra kws) (co rng) rng-T+)])) (define (change-elems ts) (for/list ([t (in-list ts)]) (if (V-in? V t) diff --git a/typed-racket-lib/typed-racket/logic/ineq.rkt b/typed-racket-lib/typed-racket/logic/ineq.rkt index eb5430c45..0b04d0a80 100644 --- a/typed-racket-lib/typed-racket/logic/ineq.rkt +++ b/typed-racket-lib/typed-racket/logic/ineq.rkt @@ -99,9 +99,8 @@ ;; Leq to the internal leq rep (define (Leq->leq l) - (match l - [(LeqProp: (LExp: c1 ts1) (LExp: c2 ts2)) - (leq (lexp c1 ts1) (lexp c2 ts2))])) + (match-define (LeqProp: (LExp: c1 ts1) (LExp: c2 ts2)) l) + (leq (lexp c1 ts1) (lexp c2 ts2))) ;; ***************************************************************************** @@ -215,10 +214,8 @@ [(eqv? a 0) (lexp 0 (make-terms))] [(= a 1) exp] [else - (match exp - [(lexp: c h) - (lexp (* c a) - (terms-scale h a))])])) + (match-define (lexp: c h) exp) + (lexp (* c a) (terms-scale h a))])) (module+ test (check-equal? (lexp-set (lexp* 17 '(42 x)) 'x 0) diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/object.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/object.rkt index 85502d02e..1053c07b4 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/object.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/object.rkt @@ -83,8 +83,8 @@ (define (member-seq-sc-map f seq) (match-define (member-seq vals) seq) (member-seq (for/list ([v (in-list vals)]) - (match v - [(member-spec mod id sc) (member-spec mod id (and sc (f sc 'invariant)))])))) + (match-define (member-spec mod id sc) v) + (member-spec mod id (and sc (f sc 'invariant)))))) ;; TODO make this the correct subset (define object-member-spec? member-spec?) From 4e90895f992ca583784f4bf8082592a80c2d89d6 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 02/17] Fix 1 occurrence of `define-simple-macro-to-define-syntax-parse-rule` The `define-simple-macro` form has been renamed to `define-syntax-parse-rule`. --- typed-racket-lib/typed-racket/utils/utils.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/utils/utils.rkt b/typed-racket-lib/typed-racket/utils/utils.rkt index 6bb2bd48a..afa51e8c4 100644 --- a/typed-racket-lib/typed-racket/utils/utils.rkt +++ b/typed-racket-lib/typed-racket/utils/utils.rkt @@ -180,7 +180,7 @@ at least theoretically. (begin (define (name . args) . body) (provide name)))])) -(define-simple-macro (define/cond-contract/provide (name:id . args) c . body) +(define-syntax-parse-rule (define/cond-contract/provide (name:id . args) c . body) (begin (define (name . args) . body) (provide/cond-contract [name c]))) From a444e42a595d8f3ce86b42f5193a0ec1e439d6fc Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 03/17] Fix 1 occurrence of `equal-null-list-to-null-predicate` The `null?` predicate can be used to test for the empty list. --- typed-racket-lib/typed-racket/utils/utils.rkt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/typed-racket-lib/typed-racket/utils/utils.rkt b/typed-racket-lib/typed-racket/utils/utils.rkt index afa51e8c4..76c3616e2 100644 --- a/typed-racket-lib/typed-racket/utils/utils.rkt +++ b/typed-racket-lib/typed-racket/utils/utils.rkt @@ -377,10 +377,9 @@ at least theoretically. ;; quick in-list/rest and in-list-cycle sanity checks (module+ test - (unless (equal? (for/list ([_ (in-range 0)] - [val (in-list/rest (list 1 2) #f)]) - val) - (list)) + (unless (null? (for/list ([_ (in-range 0)] + [val (in-list/rest (list 1 2) #f)]) + val)) (error 'in-list/rest "broken!")) (unless (equal? (for/list ([_ (in-range 2)] [val (in-list/rest (list 1 2) #f)]) From 610fa91b608efd3dfecdb2fcb0700cd7b85eea8d Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 04/17] Fix 4 occurrences of `cond-let-to-cond-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- .../typed-racket/utils/disarm.rkt | 11 ++++----- .../typed-racket/utils/tc-utils.rkt | 23 +++++++++---------- typed-racket-lib/typed-racket/utils/utils.rkt | 16 ++++++------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/typed-racket-lib/typed-racket/utils/disarm.rkt b/typed-racket-lib/typed-racket/utils/disarm.rkt index 3d9ffcd20..a28115149 100644 --- a/typed-racket-lib/typed-racket/utils/disarm.rkt +++ b/typed-racket-lib/typed-racket/utils/disarm.rkt @@ -14,12 +14,11 @@ (if (eq? r (syntax-e stx)) stx (datum->syntax stx r stx stx)))] - [(pair? v) (let ([a (loop (car v))] - [d (loop (cdr v))]) - (if (and (eq? a (car v)) - (eq? d (cdr v))) - v - (cons a d)))] + [(pair? v) (define a (loop (car v))) + (define d (loop (cdr v))) + (if (and (eq? a (car v)) (eq? d (cdr v))) + v + (cons a d))] [else v]))) (define orig-insp (variable-reference->module-declaration-inspector diff --git a/typed-racket-lib/typed-racket/utils/tc-utils.rkt b/typed-racket-lib/typed-racket/utils/tc-utils.rkt index cbd84cf51..c50b77d84 100644 --- a/typed-racket-lib/typed-racket/utils/tc-utils.rkt +++ b/typed-racket-lib/typed-racket/utils/tc-utils.rkt @@ -137,18 +137,17 @@ don't depend on any other portion of the system (reset-errors!) (log-type-error (err-msg f) (err-stx f)) (raise-typecheck-error (err-msg f) (err-stx f))] - [else (let ([stxs - (for/list ([e (in-list l)]) - (with-handlers ([exn:fail:syntax? - (λ (e) ((error-display-handler) (exn-message e) e))]) - (log-type-error (err-msg e) (err-stx e)) - (raise-typecheck-error (err-msg e) (err-stx e))) - (err-stx e))]) - (reset-errors!) - (unless (null? stxs) - (raise-typecheck-error (format "Summary: ~a errors encountered" - (length stxs)) - (apply append stxs))))])) + [else (define stxs + (for/list ([e (in-list l)]) + (with-handlers ([exn:fail:syntax? (λ (e) + ((error-display-handler) (exn-message e) e))]) + (log-type-error (err-msg e) (err-stx e)) + (raise-typecheck-error (err-msg e) (err-stx e))) + (err-stx e))) + (reset-errors!) + (unless (null? stxs) + (raise-typecheck-error (format "Summary: ~a errors encountered" (length stxs)) + (apply append stxs)))])) ;; Returns #t if there's a type error recorded at the same position as ;; the given syntax object. Does not return a useful result if the diff --git a/typed-racket-lib/typed-racket/utils/utils.rkt b/typed-racket-lib/typed-racket/utils/utils.rkt index 76c3616e2..4b76d76d2 100644 --- a/typed-racket-lib/typed-racket/utils/utils.rkt +++ b/typed-racket-lib/typed-racket/utils/utils.rkt @@ -445,20 +445,20 @@ at least theoretically. (cond [(null? entries) (list (cons key val))] [else - (let ([entry (car entries)]) - (if (equal? (car entry) key) - (cons (cons key val) (cdr entries)) - (cons entry (loop (cdr entries)))))]))) + (define entry (car entries)) + (if (equal? (car entry) key) + (cons (cons key val) (cdr entries)) + (cons entry (loop (cdr entries))))]))) (define (assoc-remove d key) (let loop ([xd d]) (cond [(null? xd) null] [else - (let ([a (car xd)]) - (if (equal? (car a) key) - (cdr xd) - (cons a (loop (cdr xd)))))]))) + (define a (car xd)) + (if (equal? (car a) key) + (cdr xd) + (cons a (loop (cdr xd))))]))) (define (in-assoc-proc l) (in-parallel (map car l) (map cdr l))) From 5302a75e492d0020c11e800f1a627131998789dd Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 05/17] Fix 5 occurrences of `define-lambda-to-define` The `define` form supports a shorthand for defining functions. --- typed-racket-lib/typed-racket/logic/ineq.rkt | 16 ++++++++------ .../typed-racket/utils/shallow-contract.rkt | 22 +++++++++---------- .../utils/simple-result-arrow.rkt | 3 ++- .../performance/infer-timing.rkt | 3 ++- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/typed-racket-lib/typed-racket/logic/ineq.rkt b/typed-racket-lib/typed-racket/logic/ineq.rkt index 0b04d0a80..251334979 100644 --- a/typed-racket-lib/typed-racket/logic/ineq.rkt +++ b/typed-racket-lib/typed-racket/logic/ineq.rkt @@ -329,13 +329,15 @@ (-> lexp? (-> any/c any/c) string?) (define vars (terms-vars (lexp-vars e))) (define const (lexp-const e)) - (define term->string - (λ (x) (string-append (if (= 1 (lexp-coeff e x)) - "" - (number->string (lexp-coeff e x))) - "(" (if pp - (pp x) - (~a x)) ")"))) + (define (term->string x) + (string-append (if (= 1 (lexp-coeff e x)) + "" + (number->string (lexp-coeff e x))) + "(" + (if pp + (pp x) + (~a x)) + ")")) (cond [(terms-empty? vars) (number->string const)] [(zero? const) diff --git a/typed-racket-lib/typed-racket/utils/shallow-contract.rkt b/typed-racket-lib/typed-racket/utils/shallow-contract.rkt index 25b486069..f343d9011 100644 --- a/typed-racket-lib/typed-racket/utils/shallow-contract.rkt +++ b/typed-racket-lib/typed-racket/utils/shallow-contract.rkt @@ -46,23 +46,21 @@ (else ;#(keyword any/c real?)) diff --git a/typed-racket-test/performance/infer-timing.rkt b/typed-racket-test/performance/infer-timing.rkt index 72e09b02b..5af720428 100644 --- a/typed-racket-test/performance/infer-timing.rkt +++ b/typed-racket-test/performance/infer-timing.rkt @@ -407,7 +407,8 @@ (displayln `(big ,n)) (define ty-list (append ts ts)) (collect-garbage) (collect-garbage) (collect-garbage) - (define run (λ () (void (bigcall n ty-list)))) + (define (run) + (void (bigcall n ty-list))) (cond [hsbencher (define-values (vs t r gc) (time-apply run null)) From 79f01e945cdf3c3789a0dea85bb9cd38913579a0 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 06/17] Fix 8 occurrences of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- .../typed-racket/infer/constraints.rkt | 4 +- .../typed-racket/infer/infer-unit.rkt | 16 ++-- .../typed-racket/infer/intersect.rkt | 96 ++++++++++--------- typed-racket-lib/typed-racket/logic/ineq.rkt | 27 +++--- .../typed-racket/utils/plambda-utils.rkt | 33 +++---- .../typed-racket/utils/tc-utils.rkt | 80 ++++++++-------- 6 files changed, 127 insertions(+), 129 deletions(-) diff --git a/typed-racket-lib/typed-racket/infer/constraints.rkt b/typed-racket-lib/typed-racket/infer/constraints.rkt index 47294e2e4..2e38c1d5a 100644 --- a/typed-racket-lib/typed-racket/infer/constraints.rkt +++ b/typed-racket-lib/typed-racket/infer/constraints.rkt @@ -84,8 +84,8 @@ ;; produces a cset of all of the maps in all of the given csets ;; FIXME: should this call `remove-duplicates`? (define (cset-join l) - (let ([mapss (map cset-maps l)]) - (make-cset (apply stream-append mapss)))) + (define mapss (map cset-maps l)) + (make-cset (apply stream-append mapss))) (define (stream-remove-duplicates st) (define seen (mutable-set)) diff --git a/typed-racket-lib/typed-racket/infer/infer-unit.rkt b/typed-racket-lib/typed-racket/infer/infer-unit.rkt index 984bbdcc6..2e870339a 100644 --- a/typed-racket-lib/typed-racket/infer/infer-unit.rkt +++ b/typed-racket-lib/typed-racket/infer/infer-unit.rkt @@ -925,14 +925,14 @@ (hash-union (for/hash ([v (in-list Y)] #:unless (hash-has-key? S v)) - (let ([var (hash-ref idx-hash v variance:const)]) - (values v - (match var - [(? variance:const?) (i-subst null)] - [(? variance:co?) (i-subst null)] - [(? variance:contra?) (i-subst/starred null Univ)] - ;; TODO figure out if there is a better subst here - [(? variance:inv?) (i-subst null)])))) + (define var (hash-ref idx-hash v variance:const)) + (values v + (match var + [(? variance:const?) (i-subst null)] + [(? variance:co?) (i-subst null)] + [(? variance:contra?) (i-subst/starred null Univ)] + ;; TODO figure out if there is a better subst here + [(? variance:inv?) (i-subst null)]))) S)) (define (build-subst m) (match-define (cons cmap (dmap dm)) m) diff --git a/typed-racket-lib/typed-racket/infer/intersect.rkt b/typed-racket-lib/typed-racket/infer/intersect.rkt index 9326ff136..3278d1c16 100644 --- a/typed-racket-lib/typed-racket/infer/intersect.rkt +++ b/typed-racket-lib/typed-racket/infer/intersect.rkt @@ -161,52 +161,58 @@ ;; If the back pointer is never used, we don't create a μ-type, we just ;; return the result (define (resolvable-intersect initial-t1 initial-t2 seen obj additive?) - (let ([t1 (if (resolvable? initial-t1) - (resolve-once initial-t1) - initial-t1)]) - (cond - [(assoc (cons initial-t1 initial-t2) seen) - ;; we've seen these types before! -- use the stored symbol - ;; as a back pointer with an 'F' type (i.e. a type variable) - => (match-lambda - [(cons _ record) - ;; record that we did indeed use the back - ;; pointer by set!-ing the flag - (set-mcdr! record #t) - (make-F (mcar record))])] - ;; if t1 is not a fully defined type, do the simple thing - [(not t1) (if additive? - (-unsafe-intersect initial-t1 initial-t2) - initial-t1)] - [else - (let ([t2 (if (resolvable? initial-t2) - (resolve-once initial-t2) - initial-t2)]) - (cond - ;; if t2 is not a fully defined type, do the simple thing - [(not t2) (if additive? - (-unsafe-intersect t1 initial-t2) - t1)] - [else - ;; we've never seen these types together before! let's gensym a symbol - ;; so that if we do encounter them again, we can create a μ type. - (define name (gensym 'rec)) - ;; the 'record' contains the back pointer symbol we may or may not use in - ;; the car, and a flag for whether or not we actually used the back pointer - ;; in the cdr. - (define record (mcons name #f)) - (define seen* (list* (cons (cons initial-t1 initial-t2) record) - (cons (cons initial-t2 initial-t1) record) - seen)) - (define t (cond - [additive? (internal-intersect t1 t2 seen* obj)] - [else (internal-restrict t1 t2 seen* obj)])) + (define t1 + (if (resolvable? initial-t1) + (resolve-once initial-t1) + initial-t1)) + (cond + [(assoc (cons initial-t1 initial-t2) seen) + ;; we've seen these types before! -- use the stored symbol + ;; as a back pointer with an 'F' type (i.e. a type variable) + => + (match-lambda + [(cons _ record) + ;; record that we did indeed use the back + ;; pointer by set!-ing the flag + (set-mcdr! record #t) + (make-F (mcar record))])] + ;; if t1 is not a fully defined type, do the simple thing + [(not t1) + (if additive? + (-unsafe-intersect initial-t1 initial-t2) + initial-t1)] + [else + (let ([t2 (if (resolvable? initial-t2) + (resolve-once initial-t2) + initial-t2)]) + (cond + ;; if t2 is not a fully defined type, do the simple thing + [(not t2) + (if additive? + (-unsafe-intersect t1 initial-t2) + t1)] + [else + ;; we've never seen these types together before! let's gensym a symbol + ;; so that if we do encounter them again, we can create a μ type. + (define name (gensym 'rec)) + ;; the 'record' contains the back pointer symbol we may or may not use in + ;; the car, and a flag for whether or not we actually used the back pointer + ;; in the cdr. + (define record (mcons name #f)) + (define seen* + (list* (cons (cons initial-t1 initial-t2) record) + (cons (cons initial-t2 initial-t1) record) + seen)) + (define t (cond - ;; check if we used the backpointer, if so, - ;; make a recursive type using that name - [(mcdr record) (make-Mu name t)] - ;; otherwise just return the result - [else t])]))]))) + [additive? (internal-intersect t1 t2 seen* obj)] + [else (internal-restrict t1 t2 seen* obj)])) + (cond + ;; check if we used the backpointer, if so, + ;; make a recursive type using that name + [(mcdr record) (make-Mu name t)] + ;; otherwise just return the result + [else t])]))])) ;; intersect diff --git a/typed-racket-lib/typed-racket/logic/ineq.rkt b/typed-racket-lib/typed-racket/logic/ineq.rkt index 251334979..c10f1d008 100644 --- a/typed-racket-lib/typed-racket/logic/ineq.rkt +++ b/typed-racket-lib/typed-racket/logic/ineq.rkt @@ -486,21 +486,18 @@ ;; leq2: ... + cx + .... <= ... + dx + ... (let-values ([(l1 r1) (leq-lexps leq1)] [(l2 r2) (leq-lexps leq2)]) - (let ([a (lexp-coeff l1 x)] [b (lexp-coeff r1 x)] - [c (lexp-coeff l2 x)] [d (lexp-coeff r2 x)]) - (cond - ;; leq1: ax <= lexp1 - ;; leq2: lexp2 <= dx - [(and (eqv? 0 b) (eqv? 0 c)) - (leq (lexp-scale l2 a) - (lexp-scale r1 d))] - ;; leq1: lexp1 <= bx - ;; leq2: cx <= lexp2 - [(and (eqv? 0 a) (eqv? 0 d)) - (leq (lexp-scale l1 c) - (lexp-scale r2 b))] - [else - (error 'leq-join "cannot join ~a and ~a by ~a" leq1 leq2 x)])))) + (define a (lexp-coeff l1 x)) + (define b (lexp-coeff r1 x)) + (define c (lexp-coeff l2 x)) + (define d (lexp-coeff r2 x)) + (cond + ;; leq1: ax <= lexp1 + ;; leq2: lexp2 <= dx + [(and (eqv? 0 b) (eqv? 0 c)) (leq (lexp-scale l2 a) (lexp-scale r1 d))] + ;; leq1: lexp1 <= bx + ;; leq2: cx <= lexp2 + [(and (eqv? 0 a) (eqv? 0 d)) (leq (lexp-scale l1 c) (lexp-scale r2 b))] + [else (error 'leq-join "cannot join ~a and ~a by ~a" leq1 leq2 x)]))) (module+ test (check-equal? (leq-join (leq (lexp* '(2 x)) diff --git a/typed-racket-lib/typed-racket/utils/plambda-utils.rkt b/typed-racket-lib/typed-racket/utils/plambda-utils.rkt index 3d382d9a0..1682dd42e 100644 --- a/typed-racket-lib/typed-racket/utils/plambda-utils.rkt +++ b/typed-racket-lib/typed-racket/utils/plambda-utils.rkt @@ -28,22 +28,19 @@ (filter pair? (map rest tvarss))) (define (get-poly-tvarss form) - (let ([plambda-tvars - (let ([p (plambda-prop form)]) - (match (and p (map syntax-e (syntax->list p))) - [#f #f] - [(list var ... dvar '...) - (list (list var dvar))] - [(list id ...) - (list id)]))] - [scoped-tvarss - (for/list ((tvarss (in-list (lookup-scoped-tvar-layer form)))) - (for/list ((tvar (in-list tvarss))) - (match tvar - [(list (list v ...) dotted-v) - (list (map syntax-e v) (syntax-e dotted-v))] - [(list v ...) (map syntax-e v)])))]) - (if plambda-tvars - (cons plambda-tvars scoped-tvarss) - scoped-tvarss))) + (define plambda-tvars + (let ([p (plambda-prop form)]) + (match (and p (map syntax-e (syntax->list p))) + [#f #f] + [(list var ... dvar '...) (list (list var dvar))] + [(list id ...) (list id)]))) + (define scoped-tvarss + (for/list ([tvarss (in-list (lookup-scoped-tvar-layer form))]) + (for/list ([tvar (in-list tvarss)]) + (match tvar + [(list (list v ...) dotted-v) (list (map syntax-e v) (syntax-e dotted-v))] + [(list v ...) (map syntax-e v)])))) + (if plambda-tvars + (cons plambda-tvars scoped-tvarss) + scoped-tvarss)) diff --git a/typed-racket-lib/typed-racket/utils/tc-utils.rkt b/typed-racket-lib/typed-racket/utils/tc-utils.rkt index c50b77d84..e67430a44 100644 --- a/typed-racket-lib/typed-racket/utils/tc-utils.rkt +++ b/typed-racket-lib/typed-racket/utils/tc-utils.rkt @@ -77,20 +77,19 @@ don't depend on any other portion of the system (define warn-unreachable? (make-parameter #t)) (define (warn-unreachable e) - (let ([l (current-logger)] - [stx (locate-stx e)]) - (when (and (warn-unreachable?) - (log-level? l 'warning) - (and (syntax-transforming?) - #;(syntax-original? (syntax-local-introduce e))) - #;(and (orig-module-stx) - (eq? (debugf syntax-source-module e) - (debugf syntax-source-module (orig-module-stx)))) - #;(syntax-source-module stx)) - (log-message l 'warning - (format "Typed Racket has detected unreachable code: ~.s" - (locate-stx e)) - e)))) + (define l (current-logger)) + (locate-stx e) + (when (and (warn-unreachable?) + (log-level? l 'warning) + (and (syntax-transforming?) #;(syntax-original? (syntax-local-introduce e))) + #;(and (orig-module-stx) + (eq? (debugf syntax-source-module e) + (debugf syntax-source-module (orig-module-stx)))) + #;(syntax-source-module stx)) + (log-message l + 'warning + (format "Typed Racket has detected unreachable code: ~.s" (locate-stx e)) + e))) (define locate-stx ;; this hash handles using `locate-stx` even when orig/expand change @@ -196,17 +195,13 @@ don't depend on any other portion of the system (define delay-errors? (make-parameter #f)) (define (tc-error/delayed msg #:stx [stx* (current-orig-stx)] . rest) - (let ([stx (locate-stx stx*)]) - (unless (syntax? stx) - (int-err "erroneous syntax was not a syntax object: ~a\n (error message: ~a)" - stx - msg)) - (current-type-error? #t) - (if (delay-errors?) - (set! delayed-errors (cons (make-err (apply format msg rest) - (list stx)) - delayed-errors)) - (raise-typecheck-error (apply format msg rest) (list stx))))) + (define stx (locate-stx stx*)) + (unless (syntax? stx) + (int-err "erroneous syntax was not a syntax object: ~a\n (error message: ~a)" stx msg)) + (current-type-error? #t) + (if (delay-errors?) + (set! delayed-errors (cons (make-err (apply format msg rest) (list stx)) delayed-errors)) + (raise-typecheck-error (apply format msg rest) (list stx)))) ;; Produce a type error using modern Racket error syntax. ;; Avoid using format directives in the `msg`, `more`, and `field` @@ -245,22 +240,25 @@ don't depend on any other portion of the system ;; produce a type error, using the current syntax (define (tc-error msg . rest) - (let* ([ostx (current-orig-stx)] - [ostxs (if (list? ostx) ostx (list ostx))] - [stxs (map locate-stx ostxs)]) - (current-type-error? #t) - ;; If this isn't original syntax, then we can get some pretty bogus error - ;; messages. Note that this is from a macro expansion, so that introduced - ;; vars and such don't confuse the user. - (cond - [(or (not (orig-module-stx)) - (for/and ([s (in-list ostxs)] #:when s) - (eq? (syntax-source s) (syntax-source (orig-module-stx))))) - (raise-typecheck-error (apply format msg rest) stxs)] - [else (raise-typecheck-error - (apply format (string-append "Error in macro expansion -- " msg) - rest) - stxs)]))) + (define ostx (current-orig-stx)) + (define ostxs + (if (list? ostx) + ostx + (list ostx))) + (define stxs (map locate-stx ostxs)) + (current-type-error? #t) + ;; If this isn't original syntax, then we can get some pretty bogus error + ;; messages. Note that this is from a macro expansion, so that introduced + ;; vars and such don't confuse the user. + (cond + [(or (not (orig-module-stx)) + (for/and ([s (in-list ostxs)] + #:when s) + (eq? (syntax-source s) (syntax-source (orig-module-stx))))) + (raise-typecheck-error (apply format msg rest) stxs)] + [else + (raise-typecheck-error (apply format (string-append "Error in macro expansion -- " msg) rest) + stxs)])) ;; produce a type error, given a particular syntax (define (tc-error/stx stx msg . rest) From 8325e84e51367e492bbf3ce146e26707273eb2d3 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 07/17] Fix 3 occurrences of `let-values-then-call-to-call-with-values` This `let-values` expression can be replaced with a simpler, equivalent `call-with-values` expression. --- typed-racket-lib/typed-racket/logic/ineq.rkt | 37 +++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/typed-racket-lib/typed-racket/logic/ineq.rkt b/typed-racket-lib/typed-racket/logic/ineq.rkt index c10f1d008..6f5b8b644 100644 --- a/typed-racket-lib/typed-racket/logic/ineq.rkt +++ b/typed-racket-lib/typed-racket/logic/ineq.rkt @@ -596,36 +596,31 @@ (values xlhs xrhs (cons ineq nox))])))) (module+ test - (check-equal? (let-values ([(lt gt no) - (sli-partition (list (leq (lexp* '(2 x) '(4 y) 1) - (lexp* '(2 y)))) - 'x)]) - (list lt gt no)) + (check-equal? (call-with-values + (λ () (sli-partition (list (leq (lexp* '(2 x) '(4 y) 1) (lexp* '(2 y)))) 'x)) + list) (list (list (leq (lexp* '(2 x)) (lexp* '(-2 y) -1))) (list) (list))) - (check-equal? (let-values ([(lt gt no) - (sli-partition (list (leq (lexp* '(2 x) '(4 y) 1) - (lexp* '(2 y))) - (leq (lexp* '(2 x) '(4 y)) - (lexp* '(2 y) '(42 x)))) - 'x)]) - (list lt gt no)) + (check-equal? (call-with-values (λ () + (sli-partition (list (leq (lexp* '(2 x) '(4 y) 1) (lexp* '(2 y))) + (leq (lexp* '(2 x) '(4 y)) + (lexp* '(2 y) '(42 x)))) + 'x)) + list) (list (list (leq (lexp* '(2 x)) (lexp* '(-2 y) -1))) (list (leq (lexp* '(2 y)) (lexp* '(40 x)))) (list))) - (check-equal? (let-values ([(lt gt no) - (sli-partition (list (leq (lexp* '(2 x) '(4 y) -1) - (lexp* '(2 y))) - (leq (lexp* '(2 x) '(4 y)) - (lexp* '(2 y) '(42 x))) - (leq (lexp* '(2 z) '(4 y)) - (lexp* '(2 y) '(42 q)))) - 'x)]) - (list lt gt no)) + (check-equal? (call-with-values + (λ () + (sli-partition (list (leq (lexp* '(2 x) '(4 y) -1) (lexp* '(2 y))) + (leq (lexp* '(2 x) '(4 y)) (lexp* '(2 y) '(42 x))) + (leq (lexp* '(2 z) '(4 y)) (lexp* '(2 y) '(42 q)))) + 'x)) + list) (list (list (leq (lexp* '(2 x)) (lexp* '(-2 y) 1))) (list (leq (lexp* '(2 y)) From cc016ece818b2d653032562480c0de8e5cf19f37 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 08/17] Fix 1 occurrence of `inverted-when` This negated `when` expression can be replaced by an `unless` expression. --- typed-racket-lib/typed-racket/utils/opaque-object.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/utils/opaque-object.rkt b/typed-racket-lib/typed-racket/utils/opaque-object.rkt index 5263c1004..7f1f78825 100644 --- a/typed-racket-lib/typed-racket/utils/opaque-object.rkt +++ b/typed-racket-lib/typed-racket/utils/opaque-object.rkt @@ -53,7 +53,7 @@ (define guard/c (dynamic-object/c methods method-ctcs fields field-ctcs)) (define guard/c-proj ((contract-late-neg-projection guard/c) blame)) (λ (obj neg-party) - (when (not (object? obj)) + (unless (object? obj) (raise-blame-error blame #:missing-party neg-party obj "expected an object got ~a" obj)) (define actual-fields (field-names obj)) (define actual-methods From afcbd1098eecc49e280380f486f2eaab5b98cbed Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 09/17] Fix 2 occurrences of `syntax-disarm-migration` The `syntax-disarm` function is a legacy function that does nothing. --- typed-racket-lib/typed-racket/utils/disarm.rkt | 2 +- typed-racket-lib/typed/private/rewriter.rkt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/typed-racket-lib/typed-racket/utils/disarm.rkt b/typed-racket-lib/typed-racket/utils/disarm.rkt index a28115149..42c11a05f 100644 --- a/typed-racket-lib/typed-racket/utils/disarm.rkt +++ b/typed-racket-lib/typed-racket/utils/disarm.rkt @@ -9,7 +9,7 @@ (let loop ([v stx]) (cond [(syntax? v) - (let* ([stx (syntax-disarm v orig-insp)] + (let* ([stx v] [r (loop (syntax-e stx))]) (if (eq? r (syntax-e stx)) stx diff --git a/typed-racket-lib/typed/private/rewriter.rkt b/typed-racket-lib/typed/private/rewriter.rkt index 7bd43150d..8c40bfe27 100644 --- a/typed-racket-lib/typed/private/rewriter.rkt +++ b/typed-racket-lib/typed/private/rewriter.rkt @@ -7,7 +7,7 @@ (define-for-syntax (rewrite stx tbl from) (define (rw stx) - (syntax-parse (syntax-disarm stx code-insp) #:literal-sets (kernel-literals) + (syntax-parse stx #:literal-sets (kernel-literals) [i:identifier (dict-ref tbl #'i #'i)] ;; no expressions here From af833d03d2e9ba8b37cfa4ca21ec43c2341354d7 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 10/17] Fix 2 occurrences of `if-else-false-to-and` This `if` expression can be refactored to an equivalent expression using `and`. --- .../typed-racket/static-contracts/combinators/function.rkt | 2 +- typed-racket-lib/typed-racket/utils/struct-info.rkt | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/function.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/function.rkt index d67f007ee..e59ca8b56 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/function.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/function.rkt @@ -149,7 +149,7 @@ (and (and (not rest-arg) (null? (append mand-kw-args mand-args opt-kw-args opt-args)) typed-side?) ;; currently we only handle this trivial case ;; we could probably look at the actual kind of `range-args` as well - (if (not range-args) 'flat #f))) + (and (not range-args) 'flat))) (define (function-sc-constraints v f) diff --git a/typed-racket-lib/typed-racket/utils/struct-info.rkt b/typed-racket-lib/typed-racket/utils/struct-info.rkt index ec16b6ad2..ba9ca8fef 100644 --- a/typed-racket-lib/typed-racket/utils/struct-info.rkt +++ b/typed-racket-lib/typed-racket/utils/struct-info.rkt @@ -108,9 +108,7 @@ ;; the function returns the corresponding structure's type name (define/cond-contract (maybe-struct-info-wrapper-type ins) (c:-> c:any/c (c:or/c #f identifier?)) - (if (struct-info-wrapper? ins) - (struct-info-wrapper-type ins) - #f)) + (and (struct-info-wrapper? ins) (struct-info-wrapper-type ins))) ;; create a *-wrapper instance based on sname-is-constr? (define/cond-contract (make-struct-info-wrapper* id info type [sname-is-constr? #t]) From 4151d8d5369670122605cf0a33e749391c206be0 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 11/17] Fix 2 occurrences of `map-to-for` This `map` operation can be replaced with a `for/list` loop. --- .../typed-racket/static-contracts/combinators/struct.rkt | 9 ++++----- typed-racket-test/performance/infer-timing.rkt | 6 ++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/struct.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/struct.rkt index 2e10062a9..619e597b2 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/struct.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/struct.rkt @@ -38,11 +38,10 @@ (define (sc->constraints v f) (match-define (struct-combinator args _ mut?) v) (merge-restricts* (if mut? 'chaperone 'flat) - (map (lambda (a) - (if (not mut?) - (add-constraint (f a) 'chaperone) - (f a))) - args)))]) + (for/list ([a (in-list args)]) + (if (not mut?) + (add-constraint (f a) 'chaperone) + (f a)))))]) (define (struct/sc name mut? fields) (struct-combinator fields name mut?)) diff --git a/typed-racket-test/performance/infer-timing.rkt b/typed-racket-test/performance/infer-timing.rkt index 5af720428..c095da01e 100644 --- a/typed-racket-test/performance/infer-timing.rkt +++ b/typed-racket-test/performance/infer-timing.rkt @@ -64,10 +64,8 @@ ;; once we have a set of props that are true/false based on reaching ;; a certain point, this will be more useful (define (fx-from-cases . cases) - (apply from-cases (map (lambda (x) - (add-unconditional-prop-all-args - x -Fixnum)) - (flatten cases)))) + (apply from-cases (for/list ([x (in-list (flatten cases))]) + (add-unconditional-prop-all-args x -Fixnum)))) (define (binop t [r t]) (t t . -> . r)) From b3672faa7b12a9a27f2a79284a98ccc6c1a5988c Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 12/17] Fix 1 occurrence of `for/fold-result-keyword` Only one of the `for/fold` expression's result values is used. Use the `#:result` keyword to return just that result. --- .../typed-racket/utils/any-wrap.rkt | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/typed-racket-lib/typed-racket/utils/any-wrap.rkt b/typed-racket-lib/typed-racket/utils/any-wrap.rkt index 65f793f26..f8ff873e0 100644 --- a/typed-racket-lib/typed-racket/utils/any-wrap.rkt +++ b/typed-racket-lib/typed-racket/utils/any-wrap.rkt @@ -83,29 +83,28 @@ (define-values (sym init auto ref set! imms par skip?) (parameterize ([current-inspector inspector]) (struct-type-info struct-type))) - (define-values (fun/chap-list _) + (define fun/chap-list (for/fold ([res null] - [imms imms]) - ([n (in-range (+ init auto))]) + [imms imms] + #:result res) + ([n (in-range (+ init auto))]) (if (and (pair? imms) (= (car imms) n)) ;; field is immutable - (values - (list* (make-struct-field-accessor ref n) - (lambda (s v) (with-contract-continuation-mark - blame+neg-party - (any-wrap/traverse v neg-party seen))) - res) - (cdr imms)) + (values (list* (make-struct-field-accessor ref n) + (lambda (s v) + (with-contract-continuation-mark blame+neg-party + (any-wrap/traverse v neg-party seen))) + res) + (cdr imms)) ;; field is mutable - (values - (list* (make-struct-field-accessor ref n) - (lambda (s v) (with-contract-continuation-mark - blame+neg-party - (any-wrap/traverse v neg-party seen))) - (make-struct-field-mutator set! n) - (lambda (s v) (fail neg-party s)) - res) - imms)))) + (values (list* (make-struct-field-accessor ref n) + (lambda (s v) + (with-contract-continuation-mark blame+neg-party + (any-wrap/traverse v neg-party seen))) + (make-struct-field-mutator set! n) + (lambda (s v) (fail neg-party s)) + res) + imms)))) (cond [par (append fun/chap-list (extract-functions par))] [else fun/chap-list])) From e18d672c0b33916d445cbb4d815853242ce09e27 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 13/17] Fix 1 occurrence of `append*-and-map-to-append-map` The `append-map` function can be used to map each element into multiple elements in a single pass. --- typed-racket-lib/typed-racket/infer/promote-demote.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/infer/promote-demote.rkt b/typed-racket-lib/typed-racket/infer/promote-demote.rkt index 6947195e0..04af72941 100644 --- a/typed-racket-lib/typed-racket/infer/promote-demote.rkt +++ b/typed-racket-lib/typed-racket/infer/promote-demote.rkt @@ -14,7 +14,7 @@ [var-demote (c:-> Type? (c:listof symbol?) Type?)]) (define (V-in? V . ts) - (for/or ([e (in-list (append* (map fv ts)))]) + (for/or ([e (in-list (append-map fv ts))]) (memq e V))) ;; get-propset : SomeValues -> PropSet From 36d31db3e103feac9f4c03be71d4cefcd0aaab64 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 14/17] Fix 2 occurrences of `cond-else-if-to-cond` The `else`-`if` branch of this `cond` expression can be collapsed into the `cond` expression. --- .../typed-racket/infer/intersect.rkt | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/typed-racket-lib/typed-racket/infer/intersect.rkt b/typed-racket-lib/typed-racket/infer/intersect.rkt index 3278d1c16..3754f3a73 100644 --- a/typed-racket-lib/typed-racket/infer/intersect.rkt +++ b/typed-racket-lib/typed-racket/infer/intersect.rkt @@ -116,20 +116,16 @@ (nbits-intersect nbits1 nbits2))] [((BaseUnion: bbits nbits) (Base-bits: numeric? bits)) - (cond [numeric? (if (nbits-overlap? nbits bits) - t2 - -Bottom)] - [else (if (bbits-overlap? bbits bits) - t2 - -Bottom)])] + (cond + [numeric? (if (nbits-overlap? nbits bits) t2 -Bottom)] + [(bbits-overlap? bbits bits) t2] + [else -Bottom])] [((Base-bits: numeric? bits) (BaseUnion: bbits nbits)) - (cond [numeric? (if (nbits-overlap? nbits bits) - t1 - -Bottom)] - [else (if (bbits-overlap? bbits bits) - t1 - -Bottom)])] + (cond + [numeric? (if (nbits-overlap? nbits bits) t1 -Bottom)] + [(bbits-overlap? bbits bits) t1] + [else -Bottom])] [((BaseUnion-bases: bases1) t2) (apply Un (for/list ([b (in-list bases1)]) (rec b t2 obj)))] From 34fe69fb9e806a6ce3a765ce3c60e431cfc0dbae Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 15/17] Fix 1 occurrence of `always-throwing-if-to-when` Using `when` and `unless` is simpler than a conditional with an always-throwing branch. --- typed-racket-lib/typed-racket/utils/tc-utils.rkt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/typed-racket-lib/typed-racket/utils/tc-utils.rkt b/typed-racket-lib/typed-racket/utils/tc-utils.rkt index e67430a44..d6a67c5f3 100644 --- a/typed-racket-lib/typed-racket/utils/tc-utils.rkt +++ b/typed-racket-lib/typed-racket/utils/tc-utils.rkt @@ -105,9 +105,9 @@ don't depend on any other portion of the system [else stx])))) (define (raise-typecheck-error msg stxs) - (if (null? (cdr stxs)) - (raise-syntax-error (string->symbol "Type Checker") msg (car stxs)) - (raise-syntax-error (string->symbol "Type Checker") msg #f #f stxs))) + (when (null? (cdr stxs)) + (raise-syntax-error (string->symbol "Type Checker") msg (car stxs))) + (raise-syntax-error (string->symbol "Type Checker") msg #f #f stxs)) (define delayed-errors null) From fbda1584ea4a3a0d6c115ba82f018c16751f2c65 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 16/17] Fix 1 occurrence of `quasiquote-to-list` This quasiquotation is equialent to a simple `list` call. --- typed-racket-lib/typed-racket/utils/prefab.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/utils/prefab.rkt b/typed-racket-lib/typed-racket/utils/prefab.rkt index 00f356524..7014ef7ac 100644 --- a/typed-racket-lib/typed-racket/utils/prefab.rkt +++ b/typed-racket-lib/typed-racket/utils/prefab.rkt @@ -60,7 +60,7 @@ [(list (? number? n) (? vector? mut)) `(,base-sym ,n (0 #f) ,mut)] [(list (and auto (list auto-n _)) (? vector? mut)) - `(,base-sym ,(- remaining-length auto-n) ,auto ,mut)] + (list base-sym (- remaining-length auto-n) auto mut)] [(list (? number? n)) `(,base-sym ,n (0 #f) #())] [(list (and auto (list auto-n _))) From b765d1f4c7dc7cc75789d61b3d2af0344174ec63 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:49:34 +0000 Subject: [PATCH 17/17] Fix 1 occurrence of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- typed-racket-lib/typed-racket/infer/infer-unit.rkt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/typed-racket-lib/typed-racket/infer/infer-unit.rkt b/typed-racket-lib/typed-racket/infer/infer-unit.rkt index 2e870339a..a306c052d 100644 --- a/typed-racket-lib/typed-racket/infer/infer-unit.rkt +++ b/typed-racket-lib/typed-racket/infer/infer-unit.rkt @@ -950,13 +950,13 @@ (for/hash ([(k v) (in-hash cmap)]) (values k (t-subst (constraint->type v (hash-ref var-hash k variance:const))))))] [subst (for/fold ([subst subst]) ([v (in-list X)]) - (let ([entry (hash-ref subst v #f)]) - ;; Make sure we got a subst entry for a type var - ;; (i.e. just a type to substitute) - ;; If we don't have one, there are no constraints on this variable - (if (and entry (t-subst? entry)) - subst - (hash-set subst v (t-subst Univ)))))]) + (define entry (hash-ref subst v #f)) + ;; Make sure we got a subst entry for a type var + ;; (i.e. just a type to substitute) + ;; If we don't have one, there are no constraints on this variable + (if (and entry (t-subst? entry)) + subst + (hash-set subst v (t-subst Univ))))]) ;; verify that we got all the important variables (extend-idxs subst))) (if multiple-substitutions?