Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
21784fd
Fix 2 occurrences of `define-simple-macro-to-define-syntax-parse-rule`
resyntax-ci[bot] Feb 28, 2025
63a7fe1
Fix 2 occurrences of `zero-comparison-to-positive?`
resyntax-ci[bot] Feb 28, 2025
60a1399
Fix 1 occurrence of `syntax-disarm-migration`
resyntax-ci[bot] Feb 28, 2025
da8c553
Fix 5 occurrences of `let-to-define`
resyntax-ci[bot] Feb 28, 2025
583a1e3
Fix 2 occurrences of `if-else-false-to-and`
resyntax-ci[bot] Feb 28, 2025
f8d6c9d
Fix 15 occurrences of `single-clause-match-to-match-define`
resyntax-ci[bot] Feb 28, 2025
84dc345
Fix 2 occurrences of `map-to-for`
resyntax-ci[bot] Feb 28, 2025
c6f5a28
Fix 1 occurrence of `define-lambda-to-define`
resyntax-ci[bot] Feb 28, 2025
5f1257e
Fix 1 occurrence of `provide-deduplication`
resyntax-ci[bot] Feb 28, 2025
57862b3
Fix 1 occurrence of `if-begin-to-cond`
resyntax-ci[bot] Feb 28, 2025
651bd68
Fix 1 occurrence of `begin0-let-to-define-begin0`
resyntax-ci[bot] Feb 28, 2025
3575e85
Fix 1 occurrence of `case-lambda-with-single-case-to-lambda`
resyntax-ci[bot] Feb 28, 2025
3f21958
Fix 1 occurrence of `define-values-values-to-define`
resyntax-ci[bot] Feb 28, 2025
f2601c5
Fix 1 occurrence of `inverted-unless`
resyntax-ci[bot] Feb 28, 2025
c7858d9
Fix 2 occurrences of `sort-with-keyed-comparator-to-sort-by-key`
resyntax-ci[bot] Feb 28, 2025
c9d12e3
Fix 1 occurrence of `inverted-when`
resyntax-ci[bot] Feb 28, 2025
a51e0f3
Fix 1 occurrence of `let-to-define`
resyntax-ci[bot] Feb 28, 2025
df62579
Fix 1 occurrence of `cond-let-to-cond-define`
resyntax-ci[bot] Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions typed-racket-lib/typed-racket/base-env/annotate-classes.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
#:with ty #'t))
(define-splicing-syntax-class optional-standalone-annotation
(pattern (~optional a:standalone-annotation)
#:attr ty (if (attribute a) #'a.ty #f)))
#:attr ty (and (attribute a) #'a.ty)))

(define-syntax-class type-variables
#:attributes ((vars 1))
Expand Down Expand Up @@ -330,10 +330,8 @@
(define-values (all-mand-tys all-opt-tys)
(cond
[kw-property
(define-values (mand-kw-set opt-kw-set)
(values
(list->set (lambda-kws-mand kw-property))
(list->set (lambda-kws-opt kw-property))))
(define mand-kw-set (list->set (lambda-kws-mand kw-property)))
(define opt-kw-set (list->set (lambda-kws-opt kw-property)))

(define-values (mand-tys^ opt-kw^)
(partition (part-pred opt-kw-set)
Expand Down
6 changes: 5 additions & 1 deletion typed-racket-lib/typed-racket/base-env/base-structs.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

(require (for-template racket/base (prefix-in k: '#%kernel)))

(provide initialize-structs -Date -Srcloc -Date -Arity-At-Least -Exn)
(provide initialize-structs
-Date
-Srcloc
-Arity-At-Least
-Exn)

(define-syntax define-hierarchy
(syntax-rules (define-hierarchy)
Expand Down
8 changes: 2 additions & 6 deletions typed-racket-lib/typed-racket/base-env/unit-prims.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,8 @@
;; in the signature, this is needed to typecheck define-values/invoke-unit forms
(define-for-syntax (imports/members sig-id)
(define-values (_1 imp-mem _2 _3) (signature-members sig-id sig-id))
#`(#,sig-id #,@(map (lambda (id)
(local-expand
id
(syntax-local-context)
(kernel-form-identifier-list)))
imp-mem)))
#`(#,sig-id #,@(for/list ([id (in-list imp-mem)])
(local-expand id (syntax-local-context) (kernel-form-identifier-list)))))

;; Given a list of signature specs
;; Processes each signature spec to determine the variables exported
Expand Down
8 changes: 5 additions & 3 deletions typed-racket-lib/typed-racket/core.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
(and (attribute opt?) (syntax-e (attribute opt?))))]
[with-refinements? (and (or (attribute refinement-reasoning?)
(with-refinements?))
(when (not (eq? te-mode deep))
(unless (eq? te-mode deep)
(raise-arguments-error
(string->symbol (format "typed/racket/~a" (keyword->string (syntax-e te-attr))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackfirth this could use format-symbol from racket/syntax

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new rule for this in jackfirth/resyntax#442.

"#:with-refinements unsupported")))])
(string->symbol (format "typed/racket/~a"
(keyword->string
(syntax-e te-attr))))
"#:with-refinements unsupported")))])
(tc-module/full te-mode stx pmb-form
(λ (new-mod pre-before-code pre-after-code)
(define ctc-cache (make-hash))
Expand Down
12 changes: 5 additions & 7 deletions typed-racket-lib/typed-racket/rep/base-union.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@
(app BaseUnion-bases bases)))])))

(define (BaseUnion-bases t)
(match t
[(BaseUnion: bbits nbits)
(cond
[(eqv? bbits 0) (nbits->base-types nbits)]
[(eqv? nbits 0) (bbits->base-types bbits)]
[else (append (bbits->base-types bbits)
(nbits->base-types nbits))])]))
(match-define (BaseUnion: bbits nbits) t)
(cond
[(eqv? bbits 0) (nbits->base-types nbits)]
[(eqv? nbits 0) (bbits->base-types bbits)]
[else (append (bbits->base-types bbits) (nbits->base-types nbits))]))
2 changes: 1 addition & 1 deletion typed-racket-lib/typed-racket/rep/core-rep.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
(-> Result? Result?)
(match-define (Result: type propset optobject n-existentials) result)
(cond
[(> n-existentials 0)
[(positive? n-existentials)
(define syms (hash-ref type-var-name-table result (build-list n-existentials (lambda _ (gensym)))))
(define vars (map make-F syms))
(make-Result (instantiate-type type vars) (instantiate-propset propset vars) optobject n-existentials)]
Expand Down
8 changes: 3 additions & 5 deletions typed-racket-lib/typed-racket/rep/free-ids.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@
(cond
[(member x seen free-identifier=?) (cons x seen)]
[else
(begin0
(let ([seen+x (cons x seen)])
(for/or ([neighbor (in-list (cdr (assoc x deps free-identifier=?)))])
(and (not (member neighbor visited free-identifier=?))
(visit neighbor seen+x))))
(define seen+x (cons x seen))
(begin0 (for/or ([neighbor (in-list (cdr (assoc x deps free-identifier=?)))])
(and (not (member neighbor visited free-identifier=?)) (visit neighbor seen+x)))
(set! visited (cons x visited)))]))
(match (for/or ([entry (in-list deps)])
(visit (car entry) '()))
Expand Down
12 changes: 4 additions & 8 deletions typed-racket-lib/typed-racket/rep/free-variance.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,14 @@
(for/fold ([hash (hasheq)]
[computed null])
([frees (in-list freess)])
(match frees
[(combined-frees new-hash new-computed)
(values (combine-hashes (list hash new-hash))
(append new-computed computed))])))
(match-define (combined-frees new-hash new-computed) frees)
(values (combine-hashes (list hash new-hash)) (append new-computed computed))))
(combined-frees hash computed))


(define (free-vars-remove frees name)
(match frees
[(combined-frees hash computed)
(combined-frees (hash-remove hash name)
(map (λ (v) (remove-frees v name)) computed))]))
(match-define (combined-frees hash computed) frees)
(combined-frees (hash-remove hash name) (map (λ (v) (remove-frees v name)) computed)))

;;
(define (free-vars-names vars)
Expand Down
17 changes: 7 additions & 10 deletions typed-racket-lib/typed-racket/rep/object-rep.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@
[(list (? exact-integer? coeff) (? Path? p))
(values c (terms-set ts p (+ coeff (terms-ref ts p))))]
[(list (? exact-integer? coeff) (? name-ref/c nm))
(let ([p (-id-path nm)])
(if (Empty? nm)
(values c ts)
(values c (terms-set ts p (+ coeff (terms-ref ts p))))))]
(define p (-id-path nm))
(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*)
Expand Down Expand Up @@ -313,9 +313,7 @@
(-> OptObject? (or/c #f exact-integer?))
(match l
[(LExp: c terms)
(if (hash-empty? terms)
c
#f)]
(and (hash-empty? terms) c)]
[_ #f]))

(define/cond-contract (in-LExp? obj l)
Expand Down Expand Up @@ -388,6 +386,5 @@
(make-LExp* (+ c1 c2) (terms-add terms1 terms2))]))

(define (add-path-to-lexp p l)
(match l
[(LExp: const terms)
(make-LExp* const (terms-set terms p (add1 (terms-ref terms p))))]))
(match-define (LExp: const terms) l)
(make-LExp* const (terms-set terms p (add1 (terms-ref terms p)))))
3 changes: 1 addition & 2 deletions typed-racket-lib/typed-racket/rep/prop-rep.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@
[#:for-each (f) (for-each f ps)]
[#:custom-constructor/contract
(-> (listof (or/c TypeProp? NotTypeProp? LeqProp?)) OrProp?)
(let ([ps (sort ps (λ (p q) (unsafe-fx<= (eq-hash-code p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackfirth my guess is that this change is slower

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is, that seems like a missed optimization opportunity in sort.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really an issue of inlining.

(eq-hash-code q))))])
(let ([ps (sort ps unsafe-fx<= #:key eq-hash-code)])
(intern-single-ref!
orprop-intern-table
ps
Expand Down
2 changes: 1 addition & 1 deletion typed-racket-lib/typed-racket/rep/rep-switch.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(~var clause (switch-clause #'(pre-args ...) #'arg #'(post-args ...))) ...
[(~datum else:) . default])
(define name-symbols (map syntax->datum (syntax->list #'(clause.name ...))))
(unless (not (null? name-symbols))
(when (null? name-symbols)
(raise-syntax-error 'define-switch "switch cannot be null" stx))
(define sorted-name-symbols (sort name-symbols symbol<?))
(unless (eq? (first name-symbols) (first sorted-name-symbols))
Expand Down
18 changes: 7 additions & 11 deletions typed-racket-lib/typed-racket/rep/rep-utils.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@
;; NOTE: the #:construct expression is only run if there
;; is no interned copy, so we should avoid unnecessary
;; allocation w/ this approach
(define-simple-macro (intern-single-ref! table-exp:expr
key-exp:expr
#:construct val-exp:expr)
(define-syntax-parse-rule (intern-single-ref! table-exp:expr key-exp:expr #:construct val-exp:expr)
(let ([table table-exp])
(define key key-exp)
(define intern-box (hash-ref table key #f))
Expand All @@ -132,13 +130,11 @@

;; fetches an interned Rep based on the given _two_ keys
;; see 'intern-single-ref!'
(define-simple-macro (intern-double-ref! table:id
key-exp1:expr
key-exp2:expr
#:construct val-exp:expr)
(intern-single-ref! (hash-ref! table key-exp1 make-hash)
key-exp2
#:construct val-exp))
(define-syntax-parse-rule (intern-double-ref! table:id
key-exp1:expr
key-exp2:expr
#:construct val-exp:expr)
(intern-single-ref! (hash-ref! table key-exp1 make-hash) key-exp2 #:construct val-exp))



Expand Down Expand Up @@ -398,7 +394,7 @@
;; singletons cannot have fields or #:no-provide
(when (and (attribute singleton)
(or (attribute no-provide?-kw)
(> (length (syntax->list #'flds)) 0)))
(positive? (length (syntax->list #'flds)))))
(raise-syntax-error 'def-rep "singletons cannot have fields or the #:no-provide option"
#'var))
(when (and (attribute base?)
Expand Down
6 changes: 3 additions & 3 deletions typed-racket-lib/typed-racket/rep/type-rep.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,8 @@
(match ts
[(list) (-refine Univ prop)]
[(list t) (-refine t prop)]
[_ (let ([t (make-Intersection ts -tt elems)])
(-refine t prop))])]
[_ (define t (make-Intersection ts -tt elems))
(-refine t prop)])]
[(cons arg args)
(match arg
[(Univ:) (loop ts elems prop args)]
Expand Down Expand Up @@ -1806,7 +1806,7 @@

;; sorts the given field of a Row by the member name
(define (sort-row-clauses clauses)
(sort clauses (λ (x y) (symbol<? (car x) (car y)))))
(sort clauses symbol<? #:key car))

(define-match-expander Class:*
(λ (stx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))])

Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorawee why is this on two lines?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a "community"'s preference to always format function definition this way. It used to support one-line format, but IIRC, either @jackfirth or @Metaxal gathered supporters to NOT do the one-line format, and I made the change accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be interested to find that discussion; I strongly disagree.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was me, I don't remember having a strong opinion about this. Perhaps it was more of a pragmatic choice at that time(?). But again, perhaps it wasn't me 😁

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's @Metaxal. I'm very lucky that I wrote your name in the commit message 😂

sorawee/fmt@831bb4c

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha indeed! Though "Suggestion by" sounds a bit different from "gathered supporters to NOT do" ;)

Again, I don't feel particularly strongly about this, although I do have a preference for two lines so that the function header stands out. I'm not going to die on this hill though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was also me. I was (and still am) of the strong opinion that function definitions should never be on a single line. Otherwise it's hard to tell them apart from variable definitions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions are just another kind of variable. ;)

(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)))
Loading