Skip to content

Automated Resyntax fixes #1448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
678f906
Fix 1 occurrence of `define-simple-macro-to-define-syntax-parse-rule`
resyntax-ci[bot] Apr 25, 2025
bf3615a
Fix 1 occurrence of `equal-null-list-to-null-predicate`
resyntax-ci[bot] Apr 25, 2025
ee5ab3c
Fix 4 occurrences of `cond-let-to-cond-define`
resyntax-ci[bot] Apr 25, 2025
a0f248b
Fix 1 occurrence of `for/fold-result-keyword`
resyntax-ci[bot] Apr 25, 2025
00d4989
Fix 4 occurrences of `define-lambda-to-define`
resyntax-ci[bot] Apr 25, 2025
49bff92
Fix 2 occurrences of `map-to-for`
resyntax-ci[bot] Apr 25, 2025
d4d578b
Fix 11 occurrences of `let-to-define`
resyntax-ci[bot] Apr 25, 2025
63f990b
Fix 2 occurrences of `inverted-when`
resyntax-ci[bot] Apr 25, 2025
cc4bdf9
Fix 1 occurrence of `if-else-false-to-and`
resyntax-ci[bot] Apr 25, 2025
bfc0fc8
Fix 1 occurrence of `syntax-disarm-migration`
resyntax-ci[bot] Apr 25, 2025
78b1a30
Fix 1 occurrence of `if-begin-to-cond`
resyntax-ci[bot] Apr 25, 2025
0e5d9f1
Fix 1 occurrence of `begin0-let-to-define-begin0`
resyntax-ci[bot] Apr 25, 2025
1caa433
Fix 1 occurrence of `case-lambda-with-single-case-to-lambda`
resyntax-ci[bot] Apr 25, 2025
8d0757d
Fix 1 occurrence of `always-throwing-if-to-when`
resyntax-ci[bot] Apr 25, 2025
6b6ac51
Fix 1 occurrence of `quasiquote-to-list`
resyntax-ci[bot] Apr 25, 2025
69807e3
Fix 1 occurrence of `sort-with-keyed-comparator-to-sort-by-key`
resyntax-ci[bot] Apr 25, 2025
77d5070
Fix 1 occurrence of `zero-comparison-to-positive?`
resyntax-ci[bot] Apr 25, 2025
5774b58
Fix 2 occurrences of `if-else-false-to-and`
resyntax-ci[bot] Apr 25, 2025
0915d46
Fix 1 occurrence of `let-to-define`
resyntax-ci[bot] Apr 25, 2025
890a65e
Fix 1 occurrence of `cond-let-to-cond-define`
resyntax-ci[bot] Apr 25, 2025
a2a9cc0
Fix 2 occurrences of `nested-if-to-cond`
resyntax-ci[bot] Apr 25, 2025
aa1c641
Fix 1 occurrence of `define-let-to-double-define`
resyntax-ci[bot] Apr 25, 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: 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))))
"#: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
22 changes: 11 additions & 11 deletions typed-racket-lib/typed-racket/env/global-env.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@
#: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))
(and (box? v) (register-type id (unbox v))))

(define (unregister-type id)
(free-id-table-remove! the-mapping id))
Expand All @@ -91,13 +89,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]
Expand Down
18 changes: 8 additions & 10 deletions typed-racket-lib/typed-racket/env/init-envs.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -437,11 +436,10 @@
`(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))
(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)
Expand Down
8 changes: 4 additions & 4 deletions typed-racket-lib/typed-racket/env/type-alias-env.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down
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
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)
(eq-hash-code q))))])
(let ([ps (sort ps unsafe-fx<= #:key eq-hash-code)])
(intern-single-ref!
orprop-intern-table
ps
Expand Down
18 changes: 9 additions & 9 deletions typed-racket-lib/typed-racket/tc-setup.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
;; types are enforced (not no-check etc.),
;; PLT_TR_NO_OPTIMIZE is not set, and the
;; current code inspector has sufficient privileges
(if (and (optimize?)
(memq (current-type-enforcement-mode) (list deep shallow))
(not (getenv "PLT_TR_NO_OPTIMIZE"))
(authorized-code-inspector?))
(begin
(do-time "Starting optimizer")
(begin0 (stx-map optimize-top body)
(do-time "Optimized")))
body))
(cond
[(and (optimize?)
(memq (current-type-enforcement-mode) (list deep shallow))
(not (getenv "PLT_TR_NO_OPTIMIZE"))
(authorized-code-inspector?))
(do-time "Starting optimizer")
(begin0 (stx-map optimize-top body)
(do-time "Optimized"))]
[else body]))

(define (maybe-shallow-rewrite body-stx ctc-cache)
(case (current-type-enforcement-mode)
Expand Down
125 changes: 67 additions & 58 deletions typed-racket-lib/typed-racket/typed-reader.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,82 @@
(define (skip-whitespace port)
;; Skips whitespace characters, sensitive to the current
;; readtable's definition of whitespace
(let ([ch (peek-char port)])
(unless (eof-object? ch)
;; Consult current readtable:
(let-values ([(like-ch/sym proc dispatch-proc)
(readtable-mapping (current-readtable) ch)])
;; If like-ch/sym is whitespace, then ch is whitespace
(when (and (char? like-ch/sym)
(char-whitespace? like-ch/sym))
(read-char port)
(skip-whitespace port))))))
(define ch (peek-char port))
(unless (eof-object? ch)
;; Consult current readtable:
(define-values (like-ch/sym proc dispatch-proc) (readtable-mapping (current-readtable) ch))
;; If like-ch/sym is whitespace, then ch is whitespace
(when (and (char? like-ch/sym) (char-whitespace? like-ch/sym))
(read-char port)
(skip-whitespace port))))

(define (skip-comments read-one port src)
;; Recursive read, but skip comments and detect EOF
(let loop ()
(let ([v (read-one)])
(cond
[(special-comment? v) (loop)]
[(eof-object? v)
(let-values ([(l c p) (port-next-location port)])
(raise-read-eof-error "unexpected EOF in type annotation" src l c p 1))]
[else v]))))
(define v (read-one))
(cond
[(special-comment? v) (loop)]
[(eof-object? v)
(define-values (l c p) (port-next-location port))
(raise-read-eof-error "unexpected EOF in type annotation" src l c p 1)]
[else v])))

(define (parse port read-one src)
(skip-whitespace port)
(let ([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)
(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))])))
(skip-whitespace port)
(let ([c (read-char port)])
(unless (equal? #\} c)
(let-values ([(l c p) (port-next-location port)])
(raise-read-error (format "typed expression ~a not properly terminated" (syntax->datum name)) src l c p 1)))))))
(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)
(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))])))
(skip-whitespace port)
(let ([c (read-char port)])
(unless (equal? #\} c)
(let-values ([(l c p) (port-next-location port)])
(raise-read-error (format "typed expression ~a not properly terminated"
(syntax->datum name))
src
l
c
p
1))))))

(define parse-id-type
(case-lambda
[(ch port src line col pos)
;; `read-syntax' mode
(datum->syntax
#f
(parse port
(lambda () (read-syntax src port ))
src)
(let-values ([(l c p) (port-next-location port)])
(list src line col pos (and pos (- p pos)))))]))
(λ (ch port src line col pos)
;; `read-syntax' mode
(datum->syntax #f
(parse port (lambda () (read-syntax src port)) src)
(let-values ([(l c p) (port-next-location port)])
(list src line col pos (and pos (- p pos)))))))

(define (readtable)
; don't install the reader macro if a dispatch macro on the open brace has already been installed
Expand Down
37 changes: 18 additions & 19 deletions typed-racket-lib/typed-racket/utils/any-wrap.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
13 changes: 6 additions & 7 deletions typed-racket-lib/typed-racket/utils/disarm.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
(let loop ([v stx])
(cond
[(syntax? v)
(let* ([stx (syntax-disarm v orig-insp)]
(let* ([stx v]
Copy link
Member

Choose a reason for hiding this comment

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

couldn't this have been converted to define?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. But Resyntax has a bug in it currently that prevents it from seeing that, see jackfirth/resyntax#345.

[r (loop (syntax-e stx))])
(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
Expand Down
2 changes: 1 addition & 1 deletion typed-racket-lib/typed-racket/utils/opaque-object.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading