Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,63 @@
#:property prop:combinator-name "dep->/sc"
#:methods gen:sc
[(define (sc->contract v rec)
(match v
[(->i/sc typed-side? ids dom/scs dom-deps pre pre-deps rng/scs rng-deps)
(with-syntax ([(id ...) ids]
[(c ...) (for/list ([d/sc (in-list dom/scs)]
[dep-ids (in-list dom-deps)])
(cond
[(not (null? dep-ids))
(parameterize ([static-contract-may-contain-free-ids? #t])
(rec d/sc))]
[else (rec d/sc)]))]
[(dep ...) dom-deps]
[(r-deps ...) rng-deps]
[(p-deps ...) pre-deps])
#`(->i ([id dep c] ...)
#,@(cond
[(not pre) #'()]
[else #`(#:pre (p-deps ...)
#,(cond
[(not (null? pre-deps))
(parameterize ([static-contract-may-contain-free-ids? #t])
(rec pre))]
[else (rec pre)]))])
#,(cond
[(and typed-side? (andmap any/sc? rng-deps)) #'any]
[(null? rng-deps)
#`[_ () (values #,@(map rec rng/scs))]]
[else
(parameterize ([static-contract-may-contain-free-ids? #t])
#`[_ (r-deps ...) (values #,@(map rec rng/scs))])])))]))
(match-define (->i/sc typed-side? ids dom/scs dom-deps pre pre-deps rng/scs rng-deps) v)
(with-syntax ([(id ...) ids]
[(c ...) (for/list ([d/sc (in-list dom/scs)]
[dep-ids (in-list dom-deps)])
(cond
[(not (null? dep-ids))
(parameterize ([static-contract-may-contain-free-ids? #t])
(rec d/sc))]
[else (rec d/sc)]))]
[(dep ...) dom-deps]
[(r-deps ...) rng-deps]
[(p-deps ...) pre-deps])
#`(->i ([id dep c] ...)
#,@(cond
[(not pre) #'()]
[else
#`(#:pre (p-deps ...)
#,(cond
[(not (null? pre-deps))
(parameterize ([static-contract-may-contain-free-ids? #t])
(rec pre))]
[else (rec pre)]))])
#,(cond
[(and typed-side? (andmap any/sc? rng-deps)) #'any]
[(null? rng-deps) #`[_ () (values #,@(map rec rng/scs))]]
[else
(parameterize ([static-contract-may-contain-free-ids? #t])
#`[_ (r-deps ...) (values #,@(map rec rng/scs))])]))))
(define (sc-map v f)
(match v
[(->i/sc typed-side? ids dom/scs dom-deps pre pre-deps rng/scs rng-deps)
(->i/sc typed-side?
ids
(for/list ([d/sc (in-list dom/scs)])
(f d/sc 'contravariant))
dom-deps
(and pre (f pre 'contravariant))
pre-deps
(for/list ([r/sc (in-list rng/scs)])
(f r/sc 'covariant))
rng-deps)]))
(match-define (->i/sc typed-side? ids dom/scs dom-deps pre pre-deps rng/scs rng-deps) v)
(->i/sc typed-side?
ids
(for/list ([d/sc (in-list dom/scs)])
(f d/sc 'contravariant))
dom-deps
(and pre (f pre 'contravariant))
pre-deps
(for/list ([r/sc (in-list rng/scs)])
(f r/sc 'covariant))
rng-deps))
(define (sc-traverse v f)
(match v
[(->i/sc _ _ dom/scs _ pre _ rng/scs _)
(for ([d/sc (in-list dom/scs)])
(f d/sc 'contravariant))
(when pre (f pre 'contravariant))
(for ([r/sc (in-list rng/scs)])
(f r/sc 'covariant))]))
(match-define (->i/sc _ _ dom/scs _ pre _ rng/scs _) v)
(for ([d/sc (in-list dom/scs)])
(f d/sc 'contravariant))
(when pre
(f pre 'contravariant))
(for ([r/sc (in-list rng/scs)])
(f r/sc 'covariant)))
(define (sc-terminal-kind v) 'impersonator)
(define (sc->constraints v f)
(match v
[(->i/sc _ _ dom/scs _ pre _ rng/scs _)
(merge-restricts* 'impersonator
(append (if pre (list (f pre)) (list))
(map f rng/scs)
(map f dom/scs)))]))])
(match-define (->i/sc _ _ dom/scs _ pre _ rng/scs _) v)
(merge-restricts* 'impersonator
(append (if pre
(list (f pre))
(list))
(map f rng/scs)
(map f dom/scs))))])

(require-for-cond-contract "proposition.rkt")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
#:transparent
#:property prop:combinator-name "unit/sc"
#:methods gen:sc
[(define (sc-map v f)
(match v
[(unit-combinator unit-spec)
(unit-combinator (unit-spec-sc-map f unit-spec))]))
[(define (sc-map v f)
(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)
Expand Down
47 changes: 16 additions & 31 deletions typed-racket-lib/typed-racket/types/base-abbrev.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,11 @@
(foldr -pair b l))

;; Recursive types
(define-syntax -v
(syntax-rules ()
[(_ x) (make-F 'x)]))
(define-syntax-rule (-v x)
(make-F 'x))

(define-syntax -mu
(syntax-rules ()
[(_ var ty)
(let ([var (-v var)])
(make-Mu 'var ty))]))
(define-syntax-rule (-mu var ty)
(let ([var (-v var)]) (make-Mu 'var ty)))

;; Results
(define/cond-contract (-result t [pset -tt-propset] [o -empty-obj])
Expand Down Expand Up @@ -493,31 +489,20 @@


;; Convenient syntax for polymorphic types
(define-syntax -poly
(syntax-rules ()
[(_ (vars ...) ty)
(let ([vars (-v vars)] ...)
(make-Poly (list 'vars ...) ty))]))

(define-syntax -polydots
(syntax-rules ()
[(_ (vars ... dotted) ty)
(let ([dotted (-v dotted)]
[vars (-v vars)] ...)
(make-PolyDots (list 'vars ... 'dotted) ty))]))

(define-syntax -polyrow
(syntax-rules ()
[(_ (var) consts ty)
(let ([var (-v var)])
(make-PolyRow (list 'var) ty consts))]))
(define-syntax-rule (-poly (vars ...) ty)
(let ([vars (-v vars)] ...) (make-Poly (list 'vars ...) ty)))

(define-syntax-rule (-polydots (vars ... dotted) ty)
(let ([dotted (-v dotted)]
[vars (-v vars)] ...)
(make-PolyDots (list 'vars ... 'dotted) ty)))

(define-syntax-rule (-polyrow (var) consts ty)
(let ([var (-v var)]) (make-PolyRow (list 'var) ty consts)))

;; abbreviation for existential types
(define-syntax -some
(syntax-rules ()
[(_ (vars ...) ty)
(let ([vars (-v vars)] ...)
(make-Some (list 'vars ...) ty))]))
(define-syntax-rule (-some (vars ...) ty)
(let ([vars (-v vars)] ...) (make-Some (list 'vars ...) ty)))

;; abbreviation for existential type results
(define-syntax -some-res
Expand Down
6 changes: 3 additions & 3 deletions typed-racket-lib/typed-racket/types/classes.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
(match-define (Row: inits fields methods augments _) row)
;; check a given clause type (e.g., init, field)
(define (check-clauses row-dict absence-set)
(for ([(name _) (in-dict row-dict)])
(when (member name absence-set)
(fail name))))
(for ([(name _) (in-dict row-dict)]
#:when (member name absence-set))
(fail name)))
(check-clauses inits init-absents)
(check-clauses fields field-absents)
(check-clauses methods method-absents)
Expand Down
18 changes: 9 additions & 9 deletions typed-racket-lib/typed-racket/types/generalize.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
[(Pair: t1 (== -Null)) (-lst t1)]
[(MPair: t1 (== -Null)) (-mlst t1)]
[(or (Pair: t1 t2) (MPair: t1 t2))
(let ([t-new (loop t2)])
(define -lst-type
((match t*
[(Pair: _ _) -lst]
[(MPair: _ _) -mlst])
t1))
(if (type-equiv? -lst-type t-new)
-lst-type
(exit t)))]
(define t-new (loop t2))
(define -lst-type
((match t*
[(Pair: _ _) -lst]
[(MPair: _ _) -mlst])
t1))
(if (type-equiv? -lst-type t-new)
-lst-type
(exit t))]
[(ListDots: t bound) (-lst (substitute Univ bound t))]
[(? (lambda (t) (subtype t -Symbol))) -Symbol]
[(== -True) -Boolean]
Expand Down
71 changes: 35 additions & 36 deletions typed-racket-lib/typed-racket/types/kw-types.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
;; the kw protocol puts the arguments in keyword-sorted order in the
;; function header, so we need to sort the types to match
(define sorted-kws
(sort keywords (λ (kw1 kw2) (keyword<? (Keyword-kw kw1)
(Keyword-kw kw2)))))
(sort keywords keyword<? #:key Keyword-kw))

(define pos-opt-arg-types
(append (for/list ([t (in-list optional-arg-types)]
Expand Down Expand Up @@ -148,9 +147,7 @@
(define (calculate-mandatory-args orig-arrows)
;; sorted order is important, our loops below rely on this order
(define arity-sorted-arrows
(sort orig-arrows
(λ (a1 a2) (>= (Arrow-max-arity a1)
(Arrow-max-arity a2)))))
(sort orig-arrows >= #:key Arrow-max-arity))
(for/fold ([mand-arg-table '()])
([arrow (in-list arity-sorted-arrows)])
(cond
Expand All @@ -172,36 +169,38 @@
;; set and set->list to retain determinism
(remove-duplicates
(for/list ([(arrow arrow-mand-arg-count) (in-assoc mand-arg-table)])
(match arrow
[(Arrow: dom rst kws rng rng-T+)
(define kws* (if actual-kws
(handle-extra-or-missing-kws kws actual-kws)
kws))
(define kw-opts-supplied (if actual-kws
(lambda-kws-opt-supplied actual-kws)
'()))
(define mand-arg-count (if actual-kws
(lambda-kws-pos-mand-count actual-kws)
arrow-mand-arg-count))
(define opt-arg-count (- (length dom) mand-arg-count))
(define extra-opt-arg-count
;; In case `dom` has too many arguments that we try to treat
;; as optional:
(if actual-kws
(max 0 (- opt-arg-count (length (lambda-kws-pos-opt-supplied? actual-kws))))
0))
(convert kws*
kw-opts-supplied
(take dom mand-arg-count)
(drop dom mand-arg-count)
(if actual-kws
(append (lambda-kws-pos-opt-supplied? actual-kws)
(make-list extra-opt-arg-count #f))
(make-list opt-arg-count #f))
rng
rst
split?
rng-T+)]))))
(match-define (Arrow: dom rst kws rng rng-T+) arrow)
(define kws*
(if actual-kws
(handle-extra-or-missing-kws kws actual-kws)
kws))
(define kw-opts-supplied
(if actual-kws
(lambda-kws-opt-supplied actual-kws)
'()))
(define mand-arg-count
(if actual-kws
(lambda-kws-pos-mand-count actual-kws)
arrow-mand-arg-count))
(define opt-arg-count (- (length dom) mand-arg-count))
(define extra-opt-arg-count
;; In case `dom` has too many arguments that we try to treat
;; as optional:
(if actual-kws
(max 0 (- opt-arg-count (length (lambda-kws-pos-opt-supplied? actual-kws))))
0))
(convert kws*
kw-opts-supplied
(take dom mand-arg-count)
(drop dom mand-arg-count)
(if actual-kws
(append (lambda-kws-pos-opt-supplied? actual-kws)
(make-list extra-opt-arg-count #f))
(make-list opt-arg-count #f))
rng
rst
split?
rng-T+))))
(apply cl->* fns))

;; kw-convert : Type (Option LambdaKeywords) [Boolean] -> Type
Expand Down Expand Up @@ -269,7 +268,7 @@
(take opt-types to-take))
(erase-props/Values rng)
#:kws actual-kws
#:rest (if (= to-take opt-types-count) rest-type #f)
#:rest (and (= to-take opt-types-count) rest-type)
#:T+ rng-T+)))]
[else (int-err "unsupported arrs in keyword function type")])]
[(Poly-names: names f) (make-Poly names (loop f))]
Expand Down
2 changes: 1 addition & 1 deletion typed-racket-lib/typed-racket/types/match-expanders.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
(app (λ (t) (Listof? t #t)) (? Type? elem-pat)))])))


(define-simple-macro (make-Listof-pred listof-pred?:id pair-matcher:id)
(define-syntax-parse-rule (make-Listof-pred listof-pred?:id pair-matcher:id)
(define (listof-pred? t [simple? #f])
(match t
[(Mu-unsafe:
Expand Down
Loading