From ca5aec0d048855236ab7ce77526fee853343b6aa Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:39:56 +0000 Subject: [PATCH 1/8] Fix 35 occurrences of `single-clause-match-to-match-define` This `match` expression can be simplified using `match-define`. --- .../typed-racket/rep/object-rep.rkt | 14 +- .../combinators/case-lambda.rkt | 37 ++--- .../static-contracts/combinators/control.rkt | 31 ++--- .../static-contracts/combinators/object.rkt | 130 ++++++++---------- .../static-contracts/combinators/prefab.rkt | 42 +++--- .../static-contracts/combinators/struct.rkt | 54 ++++---- .../static-contracts/combinators/unit.rkt | 79 +++++------ .../typecheck/tc-app/tc-app-lambda.rkt | 4 +- .../typecheck/tc-app/tc-app-values.rkt | 5 +- 9 files changed, 171 insertions(+), 225 deletions(-) diff --git a/typed-racket-lib/typed-racket/rep/object-rep.rkt b/typed-racket-lib/typed-racket/rep/object-rep.rkt index d9b1e3212..0a114ea72 100644 --- a/typed-racket-lib/typed-racket/rep/object-rep.rkt +++ b/typed-racket-lib/typed-racket/rep/object-rep.rkt @@ -272,16 +272,12 @@ (if (Empty? nm) (values c ts) (values c (terms-set ts p (+ coeff (terms-ref ts p)))))] - [(? exact-integer? new-const) - (values (+ new-const c) ts)] - [(LExp: c* ts*) - (values (+ c c*) (add-terms ts ts*))] + [(? exact-integer? new-const) (values (+ new-const c) ts)] + [(LExp: c* ts*) (values (+ c c*) (add-terms ts ts*))] [(list (? exact-integer? l-coeff) (? LExp? l)) - (match (scale-obj l-coeff l) - [(LExp: c* ts*) - (values (+ c c*) (add-terms ts ts*))])] - [(? Object? p) - (values c (terms-set ts p (add1 (terms-ref ts p))))] + (match-define (LExp: c* ts*) (scale-obj l-coeff l)) + (values (+ c c*) (add-terms ts ts*))] + [(? Object? p) (values c (terms-set ts p (add1 (terms-ref ts p))))] [(? name-ref/c var) (define p (-id-path var)) (values c (terms-set ts p (add1 (terms-ref ts p))))]))) diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/case-lambda.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/case-lambda.rkt index 2e3a5f0cd..2d06c91c0 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/case-lambda.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/case-lambda.rkt @@ -45,12 +45,15 @@ (arr-seq-sc-map f (combinator-args v)) (void)) (define (sc->contract v f) - (match v - [(arr-combinator (arr-seq args rest range)) - (with-syntax ([(arg-stx ...) (map f args)] - [(rest-stx ...) (if rest #`(#:rest #,(f rest)) #'())] - [range-stx (if range #`(values #,@(map f range)) #'any)]) - #'(arg-stx ... rest-stx ... . -> . range-stx))])) + (match-define (arr-combinator (arr-seq args rest range)) v) + (with-syntax ([(arg-stx ...) (map f args)] + [(rest-stx ...) (if rest + #`(#:rest #,(f rest)) + #'())] + [range-stx (if range + #`(values #,@(map f range)) + #'any)]) + #'(arg-stx ... rest-stx ... . -> . range-stx))) (define (sc->constraints v f) (merge-restricts* 'chaperone (map f (arr-seq->list (combinator-args v)))))]) @@ -66,20 +69,18 @@ (define (arr-seq-sc-map f seq) - (match seq - [(arr-seq args rest range) - (arr-seq - (map (λ (a) (f a 'contravariant)) args) - (and rest (f rest 'contravariant)) - (and range (map (λ (a) (f a 'covariant)) range)))])) + (match-define (arr-seq args rest range) seq) + (arr-seq (map (λ (a) (f a 'contravariant)) args) + (and rest (f rest 'contravariant)) + (and range (map (λ (a) (f a 'covariant)) range)))) (define (arr-seq->list seq) - (match seq - [(arr-seq args rest range) - (append - args - (if rest (list rest) empty) - (or range empty))])) + (match-define (arr-seq args rest range) seq) + (append args + (if rest + (list rest) + empty) + (or range empty))) (struct arr-seq (args rest range) diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/control.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/control.rkt index 0b35fc476..7eec8f2ac 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/control.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/control.rkt @@ -24,14 +24,12 @@ (pt-seq-map f (combinator-args v)) (void)) (define (sc->contract v f) - (match v - [(prompt-tag-combinator (pt-seq vals call-cc)) - (with-syntax ([(vals-stx ...) (map f vals)] - [(call-cc-stx ...) - (if call-cc - #`(#:call/cc (values #,@(map f call-cc))) - empty)]) - #'(prompt-tag/c vals-stx ... call-cc-stx ...))])) + (match-define (prompt-tag-combinator (pt-seq vals call-cc)) v) + (with-syntax ([(vals-stx ...) (map f vals)] + [(call-cc-stx ...) (if call-cc + #`(#:call/cc (values #,@(map f call-cc))) + empty)]) + #'(prompt-tag/c vals-stx ... call-cc-stx ...))) (define (sc->constraints v f) (merge-restricts* 'chaperone (map f (pt-seq->list (combinator-args v)))))]) @@ -52,16 +50,11 @@ (define (pt-seq-map f seq) - (match seq - [(pt-seq vals call-cc) - (define (f* a) (f a 'invariant)) - (pt-seq - (map f* vals) - (and call-cc (map f* call-cc)))])) + (match-define (pt-seq vals call-cc) seq) + (define (f* a) + (f a 'invariant)) + (pt-seq (map f* vals) (and call-cc (map f* call-cc)))) (define (pt-seq->list seq) - (match seq - [(pt-seq vals call-cc) - (append - vals - (or call-cc empty))])) + (match-define (pt-seq vals call-cc) seq) + (append vals (or call-cc empty))) 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 aaf0e2ecf..85502d02e 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/object.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/object.rkt @@ -42,14 +42,12 @@ #:property prop:combinator-name "class/sc" #:methods gen:sc [(define (sc-map v f) - (match v - [(class-combinator args opaque absents) - (class-combinator (member-seq-sc-map f args) opaque absents)])) + (match-define (class-combinator args opaque absents) v) + (class-combinator (member-seq-sc-map f args) opaque absents)) (define (sc-traverse v f) - (match v - [(class-combinator args opaque absents) - (member-seq-sc-map f args) - (void)])) + (match-define (class-combinator args opaque absents) v) + (member-seq-sc-map f args) + (void)) (define (sc->contract v f) (class/sc->contract v f)) (define (sc->constraints v f) @@ -60,20 +58,17 @@ #:property prop:combinator-name "instanceof/sc" #:methods gen:sc [(define (sc-map v f) - (match v - [(instanceof-combinator (list class)) - (instanceof-combinator (list (f class 'covariant)))])) + (match-define (instanceof-combinator (list class)) v) + (instanceof-combinator (list (f class 'covariant)))) (define (sc-traverse v f) - (match v - [(instanceof-combinator (list class)) - (f class 'covariant) - (void)])) + (match-define (instanceof-combinator (list class)) v) + (f class 'covariant) + (void)) (define (sc->contract v f) (instance/sc->contract v f)) (define (sc->constraints v f) - (match v - [(instanceof-combinator (list class)) - (f class)]))]) + (match-define (instanceof-combinator (list class)) v) + (f class))]) (define member-seq->list @@ -86,13 +81,10 @@ #:property prop:sequence member-seq->list) (define (member-seq-sc-map f seq) - (match seq - [(member-seq vals) - (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-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)))])))) ;; TODO make this the correct subset (define object-member-spec? member-spec?) @@ -105,14 +97,15 @@ (instanceof-combinator (list class))) (define ((member-spec->form f) v) - (match v - [(member-spec modifier id sc) - (with-syntax ([id/ctc (if sc #`(#,id #,(f sc)) id)]) - (case modifier - [(method) #'id/ctc] - [(inner) #'(inner id/ctc)] - [(init) #'(init id/ctc)] - [(field) #'(field id/ctc)]))])) + (match-define (member-spec modifier id sc) v) + (with-syntax ([id/ctc (if sc + #`(#,id #,(f sc)) + id)]) + (case modifier + [(method) #'id/ctc] + [(inner) #'(inner id/ctc)] + [(init) #'(init id/ctc)] + [(field) #'(field id/ctc)]))) (define (spec->id/ctc f modifier vals) (for/lists (_1 _2) @@ -122,50 +115,39 @@ (f (member-spec-sc spec))))) (define (object/sc->contract v f) - (match v - [(object-combinator (member-seq vals) opaque?) - #`(#,(if opaque? - #'object/c-opaque - #'object/c) - #,@(map (member-spec->form f) vals))])) - -(define (class/sc->contract v f) - (match v - [(class-combinator (member-seq vals) opaque absents) - (define-values (override-names override-ctcs) - (spec->id/ctc f 'override vals)) - (define-values (pubment-names pubment-ctcs) - (spec->id/ctc f 'pubment vals)) - (define/with-syntax (override-temp ...) - (generate-temporaries override-ctcs)) - (define/with-syntax (pubment-temp ...) - (generate-temporaries pubment-ctcs)) - (define/with-syntax (override-name ...) override-names) - (define/with-syntax (pubment-name ...) pubment-names) - (define/with-syntax (override-ctc ...) override-ctcs) - (define/with-syntax (pubment-ctc ...) pubment-ctcs) - (define vals-rest - (filter (λ (spec) - (not (memq (member-spec-modifier spec) - '(override pubment)))) - vals)) - #`(let ([override-temp override-ctc] ... - [pubment-temp pubment-ctc] ...) - (class/c #,@(if opaque '(#:opaque #:ignore-local-member-names) null) - #,@(map (member-spec->form f) vals-rest) - [override-name override-temp] ... - (override [override-name override-temp] ...) - (super [override-name override-temp] ...) - (inherit [override-name override-temp] ...) - [pubment-name pubment-temp] ... - (augment [pubment-name pubment-temp] ...) - (inherit [pubment-name pubment-temp] ...) - (absent #,@absents)))])) + (match-define (object-combinator (member-seq vals) opaque?) v) + #`(#,(if opaque? #'object/c-opaque #'object/c) #,@(map (member-spec->form f) vals))) + +(define (class/sc->contract v f) + (match-define (class-combinator (member-seq vals) opaque absents) v) + (define-values (override-names override-ctcs) (spec->id/ctc f 'override vals)) + (define-values (pubment-names pubment-ctcs) (spec->id/ctc f 'pubment vals)) + (define/with-syntax (override-temp ...) (generate-temporaries override-ctcs)) + (define/with-syntax (pubment-temp ...) (generate-temporaries pubment-ctcs)) + (define/with-syntax (override-name ...) override-names) + (define/with-syntax (pubment-name ...) pubment-names) + (define/with-syntax (override-ctc ...) override-ctcs) + (define/with-syntax (pubment-ctc ...) pubment-ctcs) + (define vals-rest + (filter (λ (spec) (not (memq (member-spec-modifier spec) '(override pubment)))) vals)) + #`(let ([override-temp override-ctc] ... + [pubment-temp pubment-ctc] ...) + (class/c #,@(if opaque + '(#:opaque #:ignore-local-member-names) + null) + #,@(map (member-spec->form f) vals-rest) + [override-name override-temp] ... + (override [override-name override-temp] ...) + (super [override-name override-temp] ...) + (inherit [override-name override-temp] ...) + [pubment-name pubment-temp] ... + (augment [pubment-name pubment-temp] ...) + (inherit [pubment-name pubment-temp] ...) + (absent #,@absents)))) (define (instance/sc->contract v f) - (match v - [(instanceof-combinator (list class)) - #`(instanceof/c #,(f class))])) + (match-define (instanceof-combinator (list class)) v) + #`(instanceof/c #,(f class))) (define (make-class-shape/sc init* field* public* augment*) (define-values [pubment* override*] (partition (lambda (nm) (memq nm augment*)) public*)) diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/prefab.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/prefab.rkt index c167925ad..c407981fd 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/prefab.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/prefab.rkt @@ -23,33 +23,27 @@ #:property prop:combinator-name "prefab/sc" #:methods gen:sc [(define (sc-map v f) - (match v - [(prefab-combinator args key field-mutability) - (prefab-combinator (map (λ (a mut?) (f a (if mut? 'invariant 'covariant))) - args - field-mutability) - key - field-mutability)])) + (match-define (prefab-combinator args key field-mutability) v) + (prefab-combinator + (map (λ (a mut?) (f a (if mut? 'invariant 'covariant))) args field-mutability) + key + field-mutability)) (define (sc-traverse v f) - (match v - [(prefab-combinator args key field-mutability) - (for-each (λ (a mut?) (f a (if mut? 'invariant 'covariant))) - args - field-mutability) - (void)])) + (match-define (prefab-combinator args key field-mutability) v) + (for-each (λ (a mut?) (f a (if mut? 'invariant 'covariant))) args field-mutability) + (void)) (define (sc->contract v f) - (match v - [(prefab-combinator args key _) - #`(prefab/c (quote #,(abbreviate-prefab-key key)) #,@(map f args))])) + (match-define (prefab-combinator args key _) v) + #`(prefab/c (quote #,(abbreviate-prefab-key key)) #,@(map f args))) (define (sc->constraints v f) - (match v - [(prefab-combinator args _ field-mutability) - (merge-restricts* - (if (ormap values field-mutability) 'chaperone 'flat) - (map (λ (a mut?) - (if (not mut?) (add-constraint (f a) 'chaperone) (f a))) - args - field-mutability))]))]) + (match-define (prefab-combinator args _ field-mutability) v) + (merge-restricts* (if (ormap values field-mutability) 'chaperone 'flat) + (map (λ (a mut?) + (if (not mut?) + (add-constraint (f a) 'chaperone) + (f a))) + args + field-mutability)))]) (define (prefab/sc key fields) (prefab-combinator fields key (prefab-key->field-mutability key))) 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 05da781aa..2e10062a9 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/struct.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/struct.rkt @@ -26,28 +26,23 @@ #:property prop:combinator-name "struct/sc" #:methods gen:sc [(define (sc-map v f) - (match v - [(struct-combinator args name mut?) - (struct-combinator (map (λ (a) (f a (if mut? 'invariant 'covariant))) args) - name mut?)])) + (match-define (struct-combinator args name mut?) v) + (struct-combinator (map (λ (a) (f a (if mut? 'invariant 'covariant))) args) name mut?)) (define (sc-traverse v f) - (match v - [(struct-combinator args name mut?) - (for-each (λ (a) (f a (if mut? 'invariant 'covariant))) args) - (void)])) + (match-define (struct-combinator args name mut?) v) + (for-each (λ (a) (f a (if mut? 'invariant 'covariant))) args) + (void)) (define (sc->contract v f) - (match v - [(struct-combinator args name _) - #`(struct/c #,name #,@(map f args))])) + (match-define (struct-combinator args name _) v) + #`(struct/c #,name #,@(map f args))) (define (sc->constraints v f) - (match v - [(struct-combinator args _ mut?) - (merge-restricts* (if mut? 'chaperone 'flat) - (map (lambda (a) - (if (not mut?) - (add-constraint (f a) 'chaperone) - (f a))) - args))]))]) + (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)))]) (define (struct/sc name mut? fields) (struct-combinator fields name mut?)) @@ -64,21 +59,18 @@ #:property prop:combinator-name "struct-type/sc" #:methods gen:sc [(define (sc-map v f) - (match v - [(struct-type/sc args) - (struct-type/sc (map (λ (a) (f a 'covariant)) args))])) + (match-define (struct-type/sc args) v) + (struct-type/sc (map (λ (a) (f a 'covariant)) args))) (define (sc-traverse v f) - (match v - [(struct-type/sc args) - (for-each (λ (a) (f a 'covariant)) args) - (void)])) + (match-define (struct-type/sc args) v) + (for-each (λ (a) (f a 'covariant)) args) + (void)) (define (sc->contract v f) - (match v - [(struct-type/sc args) - #`(struct-type/c #f)])) + (match-define (struct-type/sc args) v) + #`(struct-type/c #f)) (define (sc->constraints v f) - (match v - [(struct-type/sc args) (simple-contract-restrict 'chaperone)]))]) + (match-define (struct-type/sc args) v) + (simple-contract-restrict 'chaperone))]) (define-match-expander struct-type/sc: (syntax-parser diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/unit.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/unit.rkt index 106207066..8ea8181bf 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/unit.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/unit.rkt @@ -20,10 +20,9 @@ (match-define (unit-combinator unit-spec) v) (unit-combinator (unit-spec-sc-map f unit-spec))) (define (sc-traverse v f) - (match v - [(unit-combinator unit-spec) - (unit-spec-sc-map f unit-spec) - (void)])) + (match-define (unit-combinator unit-spec) v) + (unit-spec-sc-map f unit-spec) + (void)) (define (sc->contract v f) (unit/sc->contract v f)) (define (sc->constraints v f) @@ -43,53 +42,41 @@ #:property prop:sequence unit-spec->list) (define (unit-spec-sc-map f seq) - (match seq - [(unit-spec imports exports init-depends invokes) - (unit-spec - (map (signature-spec-sc-map f) imports) - (map (signature-spec-sc-map f) exports) - ;; leave init-depends alone since they don't contain contracts - init-depends - (map (lambda (invoke) (and invoke (f invoke 'covariant))) invokes))])) + (match-define (unit-spec imports exports init-depends invokes) seq) + (unit-spec (map (signature-spec-sc-map f) imports) + (map (signature-spec-sc-map f) exports) + ;; leave init-depends alone since they don't contain contracts + init-depends + (map (lambda (invoke) (and invoke (f invoke 'covariant))) invokes))) (define ((signature-spec-sc-map f) seq) - (match seq - [(signature-spec name (list ids ...) (list scs ...)) - (signature-spec - name - ids - (map (lambda (sc) (and sc (f sc 'invariant))) scs))])) + (match-define (signature-spec name (list ids ...) (list scs ...)) seq) + (signature-spec name ids (map (lambda (sc) (and sc (f sc 'invariant))) scs))) (define (unit/sc->contract v f) - (match v - [(unit-combinator - (unit-spec (list imports ...) - (list exports ...) - (list deps ...) - (list invoke/scs ...))) - - (define (sig-spec->syntax sig-spec) - (match sig-spec - [(signature-spec name members scs) - (define member-stx - (map (lambda (id sc) #`(#,id #,(f sc))) members scs)) - #`(#,name #,@member-stx)])) - - (define (invokes->contract lst) - (cond - ;; just a single contract - [(= 1 (length lst)) - #`#,(f (first lst))] - ;; values contract - [else - #`(values #,@(map f lst))])) - - #`(unit/c - (import #,@(map sig-spec->syntax imports)) - (export #,@(map sig-spec->syntax exports)) - (init-depend #,@deps) - #,(invokes->contract invoke/scs))])) + (match-define (unit-combinator (unit-spec (list imports ...) + (list exports ...) + (list deps ...) + (list invoke/scs ...))) + v) + (define (sig-spec->syntax sig-spec) + (match sig-spec + [(signature-spec name members scs) + (define member-stx (map (lambda (id sc) #`(#,id #,(f sc))) members scs)) + #`(#,name #,@member-stx)])) + + (define (invokes->contract lst) + (cond + ;; just a single contract + [(= 1 (length lst)) #`#,(f (first lst))] + ;; values contract + [else #`(values #,@(map f lst))])) + + #`(unit/c (import #,@(map sig-spec->syntax imports)) + (export #,@(map sig-spec->syntax exports)) + (init-depend #,@deps) + #,(invokes->contract invoke/scs))) (define (unit/sc imports exports init-depends invoke) (unit-combinator (unit-spec imports exports init-depends invoke))) diff --git a/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt b/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt index 4eaf0f242..21a6e7e5c 100644 --- a/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt +++ b/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt @@ -46,8 +46,8 @@ (let* ([res (tc/let-values #'((x) ...) #'(args ...) #'body expected)] [dom-ts (for/list ([arg (in-list (syntax-e #'(args ...)))]) - (match (type-of arg) - [(tc-result1: t) t]))] + (match-define (tc-result1: t) (type-of arg)) + t)] [cod-t (tc-results->values res)]) (add-typeof-expr #'lam (ret (->* dom-ts cod-t :T+ #t))) res)) diff --git a/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-values.rkt b/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-values.rkt index 574126137..90ec93407 100644 --- a/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-values.rkt +++ b/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-values.rkt @@ -68,8 +68,9 @@ (-tc-results (for/list ([arg (in-syntax #'args)] [tcr (in-list/rest tcrs #f)]) - (match (single-value arg (and tcr (-tc-results (list tcr) #f))) - [(tc-results: (list res) #f) res])) #f)) + (match-define (tc-results: (list res) #f) + (single-value arg (and tcr (-tc-results (list tcr) #f)))) + res) #f)) (define return-ty (tc-results->values res)) (define arg-tys (match return-ty [(Values: (list (Result: t* _ _) ...)) t*])) (add-typeof-expr #'op-name (ret (->* arg-tys return-ty :T+ #t))) From 0669cd70c30831dc39b8999f38a773afb2fe3ba1 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:39:56 +0000 Subject: [PATCH 2/8] Fix 1 occurrence of `map-to-for` This `map` operation can be replaced with a `for/list` loop. --- typed-racket-lib/typed-racket/env/init-envs.rkt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/typed-racket-lib/typed-racket/env/init-envs.rkt b/typed-racket-lib/typed-racket/env/init-envs.rkt index c456cbf85..29554473f 100644 --- a/typed-racket-lib/typed-racket/env/init-envs.rkt +++ b/typed-racket-lib/typed-racket/env/init-envs.rkt @@ -331,11 +331,10 @@ [(Instance: ty) `(make-Instance ,(type->sexp ty))] [(Signature: name extends mapping) (define (serialize-mapping m) - (map (lambda (id/ty) - (define id (car id/ty)) - (define ty (force (cdr id/ty))) - `(cons (quote-syntax ,id) ,(type->sexp ty))) - m)) + (for/list ([id/ty (in-list m)]) + (define id (car id/ty)) + (define ty (force (cdr id/ty))) + `(cons (quote-syntax ,id) ,(type->sexp ty)))) (define serialized-extends (and extends `(quote-syntax ,extends))) `(make-Signature (quote-syntax ,name) ,serialized-extends From 88e0afddba2759427709056b7aced53ba5ff0384 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:39:56 +0000 Subject: [PATCH 3/8] Fix 7 occurrences of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- .../typed-racket/env/global-env.rkt | 24 ++++++------ .../typed-racket/env/init-envs.rkt | 10 ++--- .../typed-racket/env/type-alias-env.rkt | 8 ++-- .../typecheck/tc-app/tc-app-lambda.rkt | 8 ++-- typed-racket-test/main.rkt | 39 +++++++++---------- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/typed-racket-lib/typed-racket/env/global-env.rkt b/typed-racket-lib/typed-racket/env/global-env.rkt index 116c15a03..6c026e7d5 100644 --- a/typed-racket-lib/typed-racket/env/global-env.rkt +++ b/typed-racket-lib/typed-racket/env/global-env.rkt @@ -74,10 +74,10 @@ #:when (attribute type))) (define (maybe-finish-register-type id) - (let ([v (free-id-table-ref the-mapping id)]) - (if (box? v) - (register-type id (unbox v)) - #f))) + (define v (free-id-table-ref the-mapping id)) + (if (box? v) + (register-type id (unbox v)) + #f)) (define (unregister-type id) (free-id-table-remove! the-mapping id)) @@ -91,13 +91,15 @@ the-mapping (lambda (id e) (when (box? e) - (let ([bnd (identifier-binding id)]) - (tc-error/delayed #:stx id - "Declaration for `~a' provided, but `~a' ~a" - (syntax-e id) (syntax-e id) - (cond [(eq? bnd 'lexical) "is a lexical binding"] ;; should never happen - [(not bnd) "has no definition"] - [else "is defined in another module"]))))))) + (define bnd (identifier-binding id)) + (tc-error/delayed #:stx id + "Declaration for `~a' provided, but `~a' ~a" + (syntax-e id) + (syntax-e id) + (cond + [(eq? bnd 'lexical) "is a lexical binding"] ;; should never happen + [(not bnd) "has no definition"] + [else "is defined in another module"])))))) ;; map over the-mapping, producing a list ;; (id type -> T) -> listof[T] diff --git a/typed-racket-lib/typed-racket/env/init-envs.rkt b/typed-racket-lib/typed-racket/env/init-envs.rkt index 29554473f..3cdecf0ba 100644 --- a/typed-racket-lib/typed-racket/env/init-envs.rkt +++ b/typed-racket-lib/typed-racket/env/init-envs.rkt @@ -436,11 +436,11 @@ `(make-PrefabPE (quote ,key) ,idx)])) (define (bound-in-this-module id) - (let ([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))) + (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)) (define (make-init-code map f) (define (bound-f id v) diff --git a/typed-racket-lib/typed-racket/env/type-alias-env.rkt b/typed-racket-lib/typed-racket/env/type-alias-env.rkt index de5b4c3e9..1996a739d 100644 --- a/typed-racket-lib/typed-racket/env/type-alias-env.rkt +++ b/typed-racket-lib/typed-racket/env/type-alias-env.rkt @@ -80,10 +80,10 @@ (match v [(struct unresolved (stx _ persistent?)) (set-unresolved-in-process! v #t) - (let ([t (parse-type stx)]) - (when persistent? - (mapping-put! id (make-resolved t))) - t)] + (define t (parse-type stx)) + (when persistent? + (mapping-put! id (make-resolved t))) + t] [(struct resolved (t)) t])) diff --git a/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt b/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt index 21a6e7e5c..2d7e8a86a 100644 --- a/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt +++ b/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-lambda.rkt @@ -82,10 +82,10 @@ (let* ([ts1 (generalize (tc-expr/t #'actual))] [ann-ts (for/list ([a (in-syntax #'(acc ...))] [ac (in-syntax #'(actuals ...))]) - (let ([type (find-annotation #'inner-body a)]) - (if type - (tc-expr/check/t ac (ret type)) - (generalize (tc-expr/t ac)))))] + (define type (find-annotation #'inner-body a)) + (if type + (tc-expr/check/t ac (ret type)) + (generalize (tc-expr/t ac))))] [ts (cons ts1 ann-ts)]) ;; check that the actual arguments are ok here (for/list ([a (in-syntax #'(actuals ...))] diff --git a/typed-racket-test/main.rkt b/typed-racket-test/main.rkt index 85f66a8fb..c8ba444f2 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 ".") @@ -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" From c9b5c874c68f9f4a88973e7c1a909d7983300c64 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:39:56 +0000 Subject: [PATCH 4/8] Fix 2 occurrences of `inline-unnecessary-define` This variable is returned immediately and can be inlined. --- .../static-contracts/combinators/exist.rkt | 10 +++---- typed-racket-test/main.rkt | 30 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/exist.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/exist.rkt index 0f16fc24f..fd14ce2a6 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/exist.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/exist.rkt @@ -29,12 +29,10 @@ (define (sc->contract v f) (match-define (exist-combinator (list names doms rngs)) v) (parameterize ([static-contract-may-contain-free-ids? #t]) - (define a - (with-syntax ([doms-stx (f doms)] - [rngs-stx (f rngs)] - [n (car names)]) - #'(->i ([n doms-stx]) (_ (n) rngs-stx)))) - a)) + (with-syntax ([doms-stx (f doms)] + [rngs-stx (f rngs)] + [n (car names)]) + #'(->i ([n doms-stx]) (_ (n) rngs-stx))))) (define (sc->constraints v f) (simple-contract-restrict 'flat))]) diff --git a/typed-racket-test/main.rkt b/typed-racket-test/main.rkt index c8ba444f2..6fb23ee3b 100644 --- a/typed-racket-test/main.rkt +++ b/typed-racket-test/main.rkt @@ -59,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) From 007f69f6ccbd5bf6871b19a8afe503a817de1b5c Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:39:56 +0000 Subject: [PATCH 5/8] Fix 1 occurrence of `if-else-false-to-and` This `if` expression can be refactored to an equivalent expression using `and`. --- .../static-contracts/combinators/function.rkt | 11 ++++------- 1 file changed, 4 insertions(+), 7 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 6535c1aa9..d67f007ee 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/function.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/function.rkt @@ -146,13 +146,10 @@ (match-define (function-combinator args indices mand-kws opt-kws typed-side?) v) (define-values (mand-args opt-args mand-kw-args opt-kw-args rest-arg range-args) (apply split-function-args args indices)) - (if (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) - #f)) + (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))) (define (function-sc-constraints v f) From 5dcdb5f4d277d9a56a114e832e9579bc4d9b8338 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:39:56 +0000 Subject: [PATCH 6/8] Fix 1 occurrence of `cond-else-if-to-cond` The `else`-`if` branch of this `cond` expression can be collapsed into the `cond` expression. --- .../static-contracts/combinators/simple.rkt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/typed-racket-lib/typed-racket/static-contracts/combinators/simple.rkt b/typed-racket-lib/typed-racket/static-contracts/combinators/simple.rkt index 3b80efef7..cc4b0b989 100644 --- a/typed-racket-lib/typed-racket/static-contracts/combinators/simple.rkt +++ b/typed-racket-lib/typed-racket/static-contracts/combinators/simple.rkt @@ -35,12 +35,10 @@ ;; ;; Note: does not handle cycles but there shouldn't be any (define (stx-equal? s1 s2) - (cond [(and (identifier? s1) (identifier? s2)) - (free-identifier=? s1 s2)] - [else - (if (and (syntax? s1) (syntax? s2)) - (equal?/recur (syntax-e s1) (syntax-e s2) stx-equal?) - (equal?/recur s1 s2 stx-equal?))])) + (cond + [(and (identifier? s1) (identifier? s2)) (free-identifier=? s1 s2)] + [(and (syntax? s1) (syntax? s2)) (equal?/recur (syntax-e s1) (syntax-e s2) stx-equal?)] + [else (equal?/recur s1 s2 stx-equal?)])) (struct simple-contract static-contract (syntax kind name) #:transparent From 2bf9a68055e79ddf0ceb305194200cc429351898 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:39:56 +0000 Subject: [PATCH 7/8] Fix 2 occurrences of `define-let-to-double-define` This `let` expression can be pulled up into a `define` expression. --- .../typed-racket/private/shallow-rewrite.rkt | 12 ++++---- typed-racket-test/main.rkt | 28 ++++++++----------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/typed-racket-lib/typed-racket/private/shallow-rewrite.rkt b/typed-racket-lib/typed-racket/private/shallow-rewrite.rkt index e9cb715b2..fa3509dc9 100644 --- a/typed-racket-lib/typed-racket/private/shallow-rewrite.rkt +++ b/typed-racket-lib/typed-racket/private/shallow-rewrite.rkt @@ -239,12 +239,12 @@ "#%plain-lambda formals" #'formals args)])) - (define check* - (let ([dom+ (for/fold ([acc '()]) - ([dom (in-list dom*)] - #:when (pair? dom)) - (cons (cdr dom) acc))]) - (protect-loop rst dom+))) + (define dom+ + (for/fold ([acc '()]) + ([dom (in-list dom*)] + #:when (pair? dom)) + (cons (cdr dom) acc))) + (define check* (protect-loop rst dom+)) (define ann-ty (and (type-annotation fst #:infer #f) (get-type fst #:infer #t #:default Univ))) diff --git a/typed-racket-test/main.rkt b/typed-racket-test/main.rkt index 6fb23ee3b..aff981068 100644 --- a/typed-racket-test/main.rkt +++ b/typed-racket-test/main.rkt @@ -163,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 From 91f5d90e052aa17a8172d1fa640c32a68506a16c Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 00:39:56 +0000 Subject: [PATCH 8/8] Fix 1 occurrence of `zero-comparison-to-negative?` This expression is equivalent to calling the `negative?` predicate. --- .../typed-racket/typecheck/tc-app/tc-app-hetero.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-hetero.rkt b/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-hetero.rkt index ed3d9622d..d1f74cc32 100644 --- a/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-hetero.rkt +++ b/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-hetero.rkt @@ -51,7 +51,7 @@ (cond [(not (and (integer? i-val) (exact? i-val))) (tc-error/expr #:stx expr "expected exact integer for ~a index, but got ~a" name i-val)] - [(< i-val 0) + [(negative? i-val) (tc-error/expr #:stx expr "index ~a too small for ~a ~a" i-val name type)] [(not (< i-val i-bound)) (tc-error/expr #:stx expr "index ~a too large for ~a ~a" i-val name type)]))