Skip to content

Automated Resyntax fixes #1429

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 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
28c797b
Fix 1 occurrence of `define-simple-macro-to-define-syntax-parse-rule`
resyntax-ci[bot] Jan 17, 2025
e15179a
Fix 1 occurrence of `equal-null-list-to-null-predicate`
resyntax-ci[bot] Jan 17, 2025
a29adca
Fix 4 occurrences of `cond-let-to-cond-define`
resyntax-ci[bot] Jan 17, 2025
5c9e411
Fix 2 occurrences of `map-to-for`
resyntax-ci[bot] Jan 17, 2025
1415abf
Fix 11 occurrences of `let-to-define`
resyntax-ci[bot] Jan 17, 2025
e4c346d
Fix 12 occurrences of `single-clause-match-to-match-define`
resyntax-ci[bot] Jan 17, 2025
044df9a
Fix 1 occurrence of `if-else-false-to-and`
resyntax-ci[bot] Jan 17, 2025
f0c77b1
Fix 4 occurrences of `define-lambda-to-define`
resyntax-ci[bot] Jan 17, 2025
6aa73ea
Fix 1 occurrence of `syntax-disarm-migration`
resyntax-ci[bot] Jan 17, 2025
ba4dce5
Fix 1 occurrence of `for/fold-result-keyword`
resyntax-ci[bot] Jan 17, 2025
75969b2
Fix 1 occurrence of `append*-and-map-to-append-map`
resyntax-ci[bot] Jan 17, 2025
dc11271
Fix 2 occurrences of `cond-else-if-to-cond`
resyntax-ci[bot] Jan 17, 2025
3d38559
Fix 1 occurrence of `always-throwing-if-to-when`
resyntax-ci[bot] Jan 17, 2025
a1f276d
Fix 1 occurrence of `quasiquote-to-list`
resyntax-ci[bot] Jan 17, 2025
d5a65bb
Fix 1 occurrence of `zero-comparison-to-negative?`
resyntax-ci[bot] Jan 17, 2025
6f0aabd
Fix 1 occurrence of `inverted-when`
resyntax-ci[bot] Jan 17, 2025
9d3e2e6
Fix 2 occurrences of `if-else-false-to-and`
resyntax-ci[bot] Jan 17, 2025
27d2d5e
Fix 1 occurrence of `let-to-define`
resyntax-ci[bot] Jan 17, 2025
e2514b7
Fix 2 occurrences of `nested-if-to-cond`
resyntax-ci[bot] Jan 17, 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
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 @@ -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
Loading