Skip to content

Automated Resyntax fixes #1433

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e039f96
Fix 1 occurrence of `define-simple-macro-to-define-syntax-parse-rule`
resyntax-ci[bot] Feb 7, 2025
91c6e07
Fix 1 occurrence of `equal-null-list-to-null-predicate`
resyntax-ci[bot] Feb 7, 2025
f46837d
Fix 4 occurrences of `cond-let-to-cond-define`
resyntax-ci[bot] Feb 7, 2025
971323b
Fix 2 occurrences of `map-to-for`
resyntax-ci[bot] Feb 7, 2025
0800863
Fix 11 occurrences of `let-to-define`
resyntax-ci[bot] Feb 7, 2025
656b360
Fix 1 occurrence of `inverted-when`
resyntax-ci[bot] Feb 7, 2025
56a3a63
Fix 2 occurrences of `if-else-false-to-and`
resyntax-ci[bot] Feb 7, 2025
c44355d
Fix 1 occurrence of `provide-deduplication`
resyntax-ci[bot] Feb 7, 2025
c941546
Fix 1 occurrence of `syntax-disarm-migration`
resyntax-ci[bot] Feb 7, 2025
53e0aa8
Fix 11 occurrences of `single-clause-match-to-match-define`
resyntax-ci[bot] Feb 7, 2025
1e3ee0d
Fix 3 occurrences of `define-lambda-to-define`
resyntax-ci[bot] Feb 7, 2025
b882ec8
Fix 1 occurrence of `for/fold-result-keyword`
resyntax-ci[bot] Feb 7, 2025
2d3c77c
Fix 1 occurrence of `append*-and-map-to-append-map`
resyntax-ci[bot] Feb 7, 2025
2ccae08
Fix 2 occurrences of `cond-else-if-to-cond`
resyntax-ci[bot] Feb 7, 2025
11536e2
Fix 1 occurrence of `define-values-values-to-define`
resyntax-ci[bot] Feb 7, 2025
ce153d6
Fix 1 occurrence of `always-throwing-if-to-when`
resyntax-ci[bot] Feb 7, 2025
8774879
Fix 1 occurrence of `quasiquote-to-list`
resyntax-ci[bot] Feb 7, 2025
408769f
Fix 1 occurrence of `if-else-false-to-and`
resyntax-ci[bot] Feb 7, 2025
6b9065e
Fix 1 occurrence of `let-to-define`
resyntax-ci[bot] Feb 7, 2025
4dbf750
Fix 2 occurrences of `nested-if-to-cond`
resyntax-ci[bot] Feb 7, 2025
3deddbd
Fix 1 occurrence of `define-let-to-double-define`
resyntax-ci[bot] Feb 7, 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
24 changes: 13 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,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))
Expand All @@ -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]
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 @@ -329,11 +329,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 @@ -435,11 +434,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
14 changes: 6 additions & 8 deletions typed-racket-lib/typed-racket/infer/constraints.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,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))
Expand Down
122 changes: 52 additions & 70 deletions typed-racket-lib/typed-racket/infer/infer-unit.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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))



Expand Down Expand Up @@ -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*))
Expand Down Expand Up @@ -915,16 +908,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
Expand All @@ -934,47 +923,40 @@
(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 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)])
(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?
(for/list ([md (in-stream (cset-maps C))])
(build-subst md))
Expand Down
Loading