From bf8e9cfebcc5016e6da0678cefec00f1b71ec458 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 01/12] Fix 1 occurrence of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- .../typed-racket/base-env/top-interaction.rkt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/top-interaction.rkt b/typed-racket-lib/typed-racket/base-env/top-interaction.rkt index 5dbbf3830..7b87d7266 100644 --- a/typed-racket-lib/typed-racket/base-env/top-interaction.rkt +++ b/typed-racket-lib/typed-racket/base-env/top-interaction.rkt @@ -135,12 +135,9 @@ (λ (type) (match type [(tc-result1: (and t (? Fun?)) f o) - (let ([cleaned (cleanup-type t (parse-type #'desired-type) #f)]) - #`(display - #,(match cleaned - [(Fun: '()) - "Desired return type not in the given function's range.\n"] - [(Fun: _) - (pretty-format-rep cleaned)])))] + (define cleaned (cleanup-type t (parse-type #'desired-type) #f)) + #`(display #,(match cleaned + [(Fun: '()) "Desired return type not in the given function's range.\n"] + [(Fun: _) (pretty-format-rep cleaned)]))] [_ (error (format "~a: not a function" (syntax->datum #'op)))])) "must be applied to exactly two arguments")) From 5997073c80fd696c3425fd8984e19ce0defdd7ce Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 02/12] Fix 1 occurrence of `nested-if-to-cond` This `if`-`else` chain can be converted to a `cond` expression. --- .../typed-racket/base-env/prims-contract.rkt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt index afa318c27..11a345b69 100644 --- a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt @@ -224,11 +224,12 @@ (pattern (~seq (~optional (~seq (~and key (~or #:extra-constructor-name #:constructor-name)) name:id)) (~optional (~seq #:type-name type:id) #:defaults ([type struct-name]))) - #:attr ctor-value (if (attribute key) #'(key name) - (if legacy - #`(#:extra-constructor-name - #,(format-id struct-name "make-~a" struct-name)) - #'())))) + #:attr ctor-value (cond + [(attribute key) #'(key name)] + [legacy + #`(#:extra-constructor-name + #,(format-id struct-name "make-~a" struct-name))] + [else #'()]))) (define-syntax-class (struct-clause legacy) #:attributes (nm type (body 1) (constructor-parts 1) (tvar 1)) From f9d91353414278520539e8272e7618ff339b6e77 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 03/12] Fix 2 occurrences of `define-let-to-multi-define` This `let` expression can be pulled up into multiple `define` expressions. --- .../typed-racket/base-env/prims-contract.rkt | 11 +++++++---- typed-racket-lib/typed-racket/logic/ineq.rkt | 7 +++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt index 11a345b69..37496fa66 100644 --- a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt @@ -385,11 +385,14 @@ ;; will have added the casted expression's original type to the cast-table, so ;; that `(cast-table-ref id)` can get that type here. (λ () + (define types (cast-table-ref id)) (define type-stx - (let ([types (cast-table-ref id)]) - (cond [(not types) #f] - [(null? (cdr types)) (car types)] - [else (quasisyntax/loc (car types) (U #,@types))]))) + (cond + [(not types) #f] + [(null? (cdr types)) (car types)] + [else + (quasisyntax/loc (car types) + (U #,@types))])) `#s(contract-def ,type-stx ,flat? ,maker? typed ,te-mode)))) (define define-predicate diff --git a/typed-racket-lib/typed-racket/logic/ineq.rkt b/typed-racket-lib/typed-racket/logic/ineq.rkt index 6f5b8b644..93f44468e 100644 --- a/typed-racket-lib/typed-racket/logic/ineq.rkt +++ b/typed-racket-lib/typed-racket/logic/ineq.rkt @@ -439,10 +439,9 @@ ;; --> (ax - bx) <= ...3 + ...4 - ...1 - ...2 [else (define lhs* (lexp 0 (make-terms x (- x-lhs-coeff x-rhs-coeff)))) - (define rhs* - (let ([rhs-c* (- rhs-c lhs-c)] - [rhs-h* (terms-subtract rhs-ts lhs-ts)]) - (lexp rhs-c* (terms-remove rhs-h* x)))) + (define rhs-c* (- rhs-c lhs-c)) + (define rhs-h* (terms-subtract rhs-ts lhs-ts)) + (define rhs* (lexp rhs-c* (terms-remove rhs-h* x))) (leq lhs* rhs*)])])) ; x lhs From e06811890efbb8eb8c07760ad2e3886c84ae5312 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 04/12] Fix 1 occurrence of `if-let-to-cond` `cond` with internal definitions is preferred over `if` with `let`, to reduce nesting --- .../typed-racket/base-env/prims-contract.rkt | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt index 37496fa66..8e313274e 100644 --- a/typed-racket-lib/typed-racket/base-env/prims-contract.rkt +++ b/typed-racket-lib/typed-racket/base-env/prims-contract.rkt @@ -657,17 +657,22 @@ (make-struct-info (lambda () - #,(if (syntax-e #'parent) - (let-values (((parent-type-des parent-maker parent-pred - parent-sel parent-mut grand-parent) - (apply values - (extract-struct-info/checked #'parent)))) - #`(struct-info-list - (list #,@(map maybe-add-quote-syntax parent-sel)) - (list #,@(map maybe-add-quote-syntax parent-mut)))) - #`(let-values (((new-sels new-muts) - (id-drop orig-sels orig-muts num-fields))) - (struct-info-list new-sels new-muts))))))) + #,(cond + [(syntax-e #'parent) + (define-values (parent-type-des + parent-maker + parent-pred + parent-sel + parent-mut + grand-parent) + (apply values (extract-struct-info/checked #'parent))) + #`(struct-info-list + (list #,@(map maybe-add-quote-syntax parent-sel)) + (list #,@(map maybe-add-quote-syntax parent-mut)))] + [else + #`(let-values ([(new-sels new-muts) + (id-drop orig-sels orig-muts num-fields)]) + (struct-info-list new-sels new-muts))]))))) (define-syntax nm (if id-is-ctor? From ec631149d5d59ff2a44443c6f9098d62facbaae6 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 05/12] Fix 2 occurrences of `if-else-false-to-and` This `if` expression can be refactored to an equivalent expression using `and`. --- typed-racket-lib/typed-racket/env/global-env.rkt | 4 +--- typed-racket-lib/typed-racket/env/init-envs.rkt | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/typed-racket-lib/typed-racket/env/global-env.rkt b/typed-racket-lib/typed-racket/env/global-env.rkt index 6c026e7d5..059469d67 100644 --- a/typed-racket-lib/typed-racket/env/global-env.rkt +++ b/typed-racket-lib/typed-racket/env/global-env.rkt @@ -75,9 +75,7 @@ (define (maybe-finish-register-type id) (define v (free-id-table-ref the-mapping id)) - (if (box? v) - (register-type id (unbox v)) - #f)) + (and (box? v) (register-type id (unbox v)))) (define (unregister-type id) (free-id-table-remove! the-mapping id)) diff --git a/typed-racket-lib/typed-racket/env/init-envs.rkt b/typed-racket-lib/typed-racket/env/init-envs.rkt index 3cdecf0ba..4b0614fe1 100644 --- a/typed-racket-lib/typed-racket/env/init-envs.rkt +++ b/typed-racket-lib/typed-racket/env/init-envs.rkt @@ -437,10 +437,9 @@ (define (bound-in-this-module id) (define binding (identifier-binding id)) - (if (and (list? binding) (module-path-index? (car binding))) - (let-values ([(mp base) (module-path-index-split (car binding))]) - (not mp)) - #f)) + (and (and (list? binding) (module-path-index? (car binding))) + (let-values ([(mp base) (module-path-index-split (car binding))]) + (not mp)))) (define (make-init-code map f) (define (bound-f id v) From 7d77f9e5cbe0059c0fd1981eed7abb52cd077822 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 06/12] Fix 6 occurrences of `match-let-to-match-define` Internal definitions are recommended instead of `match-let` expressions with a single binding, to reduce nesting. --- .../typed-racket/env/type-env-structs.rkt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/typed-racket-lib/typed-racket/env/type-env-structs.rkt b/typed-racket-lib/typed-racket/env/type-env-structs.rkt index e3b41ec51..944953e5b 100644 --- a/typed-racket-lib/typed-racket/env/type-env-structs.rkt +++ b/typed-racket-lib/typed-racket/env/type-env-structs.rkt @@ -97,27 +97,27 @@ (define (env-replace-props e props) - (match-let ([(env tys otys _ als) e]) - (env tys otys props als))) + (match-define (env tys otys _ als) e) + (env tys otys props als)) (define (env-lookup-id e key fail) - (match-let ([(env tys _ _ _) e]) - (free-id-table-ref tys key (λ () (fail key))))) + (match-define (env tys _ _ _) e) + (free-id-table-ref tys key (λ () (fail key)))) (define (env-lookup-obj e key fail) - (match-let ([(env _ otys _ _) e]) - (hash-ref otys key (λ () (fail key))))) + (match-define (env _ otys _ _) e) + (hash-ref otys key (λ () (fail key)))) ;; like hash-set, but for the type of an ident in the lexical environment (define (env-set-id-type e ident type) - (match-let ([(env tys otys ps als) e]) - (env (free-id-table-set tys ident type) otys ps als))) + (match-define (env tys otys ps als) e) + (env (free-id-table-set tys ident type) otys ps als)) ;; like hash-set, but for the type of an object in the lexical environment (define (env-set-obj-type e obj type) - (match-let ([(env tys otys ps als) e]) - (env tys (hash-set otys obj type) ps als))) + (match-define (env tys otys ps als) e) + (env tys (hash-set otys obj type) ps als)) ;; extends an environment with types and aliases ;; e : the 'env' struct to be updated @@ -157,6 +157,6 @@ (env tys otys ps als)) (define (env-lookup-alias e key fail) - (match-let ([(env _ _ _ als) e]) - (free-id-table-ref als key (λ () (fail key))))) + (match-define (env _ _ _ als) e) + (free-id-table-ref als key (λ () (fail key)))) From ca49fbc6ff3a45ad6f4abacb21eac13124d10a95 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 07/12] Fix 1 occurrence of `begin0-begin-extraction` The `begin` form inside this `begin0` form can be extracted into the surrounding definition context. --- .../typed-racket/typed-reader.rkt | 65 +++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/typed-racket-lib/typed-racket/typed-reader.rkt b/typed-racket-lib/typed-racket/typed-reader.rkt index a9f157bcc..5da5979ee 100644 --- a/typed-racket-lib/typed-racket/typed-reader.rkt +++ b/typed-racket-lib/typed-racket/typed-reader.rkt @@ -31,40 +31,39 @@ (define (parse port read-one src) (skip-whitespace port) (define name (read-one)) - (begin0 (begin - (skip-whitespace port) - (let ([next (read-one)]) - (case (syntax-e next) - ;; type annotation - [(:) - (skip-whitespace port) - (type-label-property name (syntax->datum (read-one)))] - [(::) - (skip-whitespace port) - (datum->syntax name `(ann ,name : ,(read-one)))] - [(@) - (let ([elems (let loop ([es '()]) - (skip-whitespace port) - (if (equal? #\} (peek-char port)) - (reverse es) - (loop (cons (read-one) es))))]) - (datum->syntax name `(inst ,name : ,@elems)))] - ;; arbitrary property annotation - [(PROP) + (skip-whitespace port) + (begin0 (let ([next (read-one)]) + (case (syntax-e next) + ;; type annotation + [(:) + (skip-whitespace port) + (type-label-property name (syntax->datum (read-one)))] + [(::) + (skip-whitespace port) + (datum->syntax name `(ann ,name : ,(read-one)))] + [(@) + (let ([elems (let loop ([es '()]) + (skip-whitespace port) + (if (equal? #\} (peek-char port)) + (reverse es) + (loop (cons (read-one) es))))]) + (datum->syntax name `(inst ,name : ,@elems)))] + ;; arbitrary property annotation + [(PROP) + (skip-whitespace port) + (let* ([prop-name (syntax-e (read-one))]) (skip-whitespace port) - (let* ([prop-name (syntax-e (read-one))]) - (skip-whitespace port) - (syntax-property name prop-name (read-one)))] - ;; otherwise error - [else - (let-values ([(l c p) (port-next-location port)]) - (raise-read-error (format "typed expression ~a must be followed by :, ::, or @" - (syntax->datum name)) - src - l - c - p - 1))]))) + (syntax-property name prop-name (read-one)))] + ;; otherwise error + [else + (let-values ([(l c p) (port-next-location port)]) + (raise-read-error (format "typed expression ~a must be followed by :, ::, or @" + (syntax->datum name)) + src + l + c + p + 1))])) (skip-whitespace port) (let ([c (read-char port)]) (unless (equal? #\} c) From 76901557a0bf3462b91e5b76079a30a96ce4e1b9 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 08/12] Fix 1 occurrence of `inverted-when` This negated `when` expression can be replaced by an `unless` expression. --- typed-racket-test/succeed/shallow/pr241-variation-5.rkt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/typed-racket-test/succeed/shallow/pr241-variation-5.rkt b/typed-racket-test/succeed/shallow/pr241-variation-5.rkt index bcbd4741e..1b048a664 100644 --- a/typed-racket-test/succeed/shallow/pr241-variation-5.rkt +++ b/typed-racket-test/succeed/shallow/pr241-variation-5.rkt @@ -388,7 +388,8 @@ (filtered-in (if WARN-MISSING (lambda (str) - (when (not (known-string? str)) (printf "WARNING: Missing test for base type '~a'\n" str)) + (unless (known-string? str) + (printf "WARNING: Missing test for base type '~a'\n" str)) #f) (lambda (str) #f)) typed-racket/base-env/base-types)) From 3538723ca7163ca0343605a572a80b2437bdf624 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 09/12] Fix 2 occurrences of `error-to-raise-arguments-error` Use `raise-arguments-error` instead of `error` for better error messages that follow Racket conventions. --- typed-racket-lib/typed-racket/logic/ineq.rkt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typed-racket-lib/typed-racket/logic/ineq.rkt b/typed-racket-lib/typed-racket/logic/ineq.rkt index 93f44468e..1f00ac3bb 100644 --- a/typed-racket-lib/typed-racket/logic/ineq.rkt +++ b/typed-racket-lib/typed-racket/logic/ineq.rkt @@ -193,7 +193,7 @@ [(lexp: c ts) (define coeffs (terms-coeffs ts)) (if (zero? c) coeffs (cons c coeffs))] - [_ (error 'lexp-scalars "given invalid lexp ~a" exp)])) + [_ (raise-arguments-error 'lexp-scalars "given invalid lexp" "exp" exp)])) (module+ test (check-true (and (equal? (sort (lexp-vars (lexp* 17 '(42 x) '(2 z))) symbol Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 10/12] Fix 1 occurrence of `format-string-to-format-symbol` This `format` expression can be simplified to an equivalent `format-symbol` expression. --- typed-racket-lib/typed-racket/core.rkt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/typed-racket-lib/typed-racket/core.rkt b/typed-racket-lib/typed-racket/core.rkt index bd5ef1496..9e2369137 100644 --- a/typed-racket-lib/typed-racket/core.rkt +++ b/typed-racket-lib/typed-racket/core.rkt @@ -50,9 +50,7 @@ (with-refinements?)) (unless (eq? te-mode deep) (raise-arguments-error - (string->symbol (format "typed/racket/~a" - (keyword->string - (syntax-e te-attr)))) + (format-symbol "typed/racket/~a" te-attr) "#:with-refinements unsupported")))]) (tc-module/full te-mode stx pmb-form (λ (new-mod pre-before-code pre-after-code) From 56e65cfbc897f9fc7ca314f1a1b11e942435822f Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 11/12] Fix 1 occurrence of `format-identity` This use of `format` does nothing. --- .../succeed/shallow/untyped-struct-properties-with-self.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-test/succeed/shallow/untyped-struct-properties-with-self.rkt b/typed-racket-test/succeed/shallow/untyped-struct-properties-with-self.rkt index a53de7d5b..6eaf2e9eb 100644 --- a/typed-racket-test/succeed/shallow/untyped-struct-properties-with-self.rkt +++ b/typed-racket-test/succeed/shallow/untyped-struct-properties-with-self.rkt @@ -8,7 +8,7 @@ (module ty-foo typed/racket/shallow (require/typed (submod ".." foo) [prop:hi (Struct-Property (-> Self Any))] [hi-ref (-> Any (-> Any Void))]) (struct bar () #:property prop:hi (λ ([self : bar]) - (display (format "instance bar\n" )))) + (display "instance bar\n"))) (hi-ref (bar)) ) From 4734fc334666d51a8aec0b8d154b691d9459d2cf Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 01:07:05 +0000 Subject: [PATCH 12/12] Fix 1 occurrence of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- typed-racket-lib/typed-racket/typed-reader.rkt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/typed-racket-lib/typed-racket/typed-reader.rkt b/typed-racket-lib/typed-racket/typed-reader.rkt index 5da5979ee..97042f2b2 100644 --- a/typed-racket-lib/typed-racket/typed-reader.rkt +++ b/typed-racket-lib/typed-racket/typed-reader.rkt @@ -56,14 +56,14 @@ (syntax-property name prop-name (read-one)))] ;; otherwise error [else - (let-values ([(l c p) (port-next-location port)]) - (raise-read-error (format "typed expression ~a must be followed by :, ::, or @" - (syntax->datum name)) - src - l - c - p - 1))])) + (define-values (l c p) (port-next-location port)) + (raise-read-error (format "typed expression ~a must be followed by :, ::, or @" + (syntax->datum name)) + src + l + c + p + 1)])) (skip-whitespace port) (let ([c (read-char port)]) (unless (equal? #\} c)