Give more meaningful names to conditional contract forms.
original commit: a1fab6ec06b1b000e0419f617ec974f2827c57e4
This commit is contained in:
parent
c1c0fa70af
commit
794bfe775b
2
collects/typed-scheme/env/lexical-env.rkt
vendored
2
collects/typed-scheme/env/lexical-env.rkt
vendored
|
@ -18,7 +18,7 @@
|
|||
|
||||
(provide lexical-env with-lexical-env with-lexical-env/extend
|
||||
with-lexical-env/extend/props)
|
||||
(p/c
|
||||
(provide/cond-contract
|
||||
[lookup-type/lexical ((identifier?) (prop-env? #:fail (or/c #f (-> any/c #f))) . ->* . (or/c Type/c #f))]
|
||||
[update-type/lexical (((identifier? Type/c . -> . Type/c) identifier?) (prop-env?) . ->* . env?)])
|
||||
|
||||
|
|
24
collects/typed-scheme/env/type-env-structs.rkt
vendored
24
collects/typed-scheme/env/type-env-structs.rkt
vendored
|
@ -1,4 +1,4 @@
|
|||
#lang scheme/base
|
||||
#lang scheme/base
|
||||
|
||||
(require scheme/contract unstable/sequence racket/dict syntax/id-table
|
||||
(prefix-in r: "../utils/utils.rkt")
|
||||
|
@ -20,12 +20,12 @@
|
|||
|
||||
;; eq? has the type of equal?, and l is an alist (with conses!)
|
||||
;; props is a list of known propositions
|
||||
(r:d-s/c env ([l (and/c (not/c dict-mutable?) dict?)])
|
||||
(r:define-struct/cond-contract env ([l (and/c (not/c dict-mutable?) dict?)])
|
||||
#:transparent
|
||||
#:property prop:custom-write
|
||||
(lambda (e prt mode)
|
||||
(fprintf prt "(env ~a)" (dict-map (env-l e) list))))
|
||||
(r:d-s/c (prop-env env) ([props (listof Filter/c)])
|
||||
(r:define-struct/cond-contract (prop-env env) ([props (listof Filter/c)])
|
||||
#:transparent
|
||||
#:property prop:custom-write
|
||||
(lambda (e prt mode)
|
||||
|
@ -39,34 +39,34 @@
|
|||
(define (env-filter f e)
|
||||
(match e
|
||||
[(env l)
|
||||
(mk-env e
|
||||
(mk-env e
|
||||
(for/fold ([h l])
|
||||
([(k v) (in-dict l)]
|
||||
#:when (not (f (cons k v))))
|
||||
(dict-remove h k)))]))
|
||||
|
||||
(r:d/c (make-empty-env dict)
|
||||
(r:define/cond-contract (make-empty-env dict)
|
||||
(dict? . -> . env?)
|
||||
(env dict))
|
||||
|
||||
(r:d/c (make-empty-prop-env dict)
|
||||
(r:define/cond-contract (make-empty-prop-env dict)
|
||||
(dict? . -> . prop-env?)
|
||||
(prop-env dict null))
|
||||
|
||||
(r:d/c (env-props e)
|
||||
(r:define/cond-contract (env-props e)
|
||||
(prop-env? . -> . (listof Filter/c))
|
||||
(prop-env-props e))
|
||||
|
||||
(define (env-keys+vals e)
|
||||
(match e
|
||||
[(env l) (for/list ([(k v) (in-dict l)]) (cons k v))]))
|
||||
[(env l) (for/list ([(k v) (in-dict l)]) (cons k v))]))
|
||||
|
||||
(r:d/c (env-map f e)
|
||||
(r:define/cond-contract (env-map f e)
|
||||
((any/c any/c . -> . any/c) env? . -> . env?)
|
||||
(mk-env e (dict-map f (env-l e))))
|
||||
|
||||
;; extend that works on single arguments
|
||||
(define (extend e k v)
|
||||
(define (extend e k v)
|
||||
(match e
|
||||
[(env l) (mk-env e (dict-set l k v))]
|
||||
[_ (int-err "extend: expected environment, got ~a" e)]))
|
||||
|
@ -88,10 +88,10 @@
|
|||
[_ (int-err "lookup: expected environment, got ~a" e)]))
|
||||
|
||||
|
||||
;; takes two lists of sets to be added, which are either added one at a time, if the
|
||||
;; takes two lists of sets to be added, which are either added one at a time, if the
|
||||
;; elements are not lists, or all at once, if the elements are lists
|
||||
(define (extend/values kss vss env)
|
||||
(foldr (lambda (ks vs env)
|
||||
(foldr (lambda (ks vs env)
|
||||
(cond [(and (list? ks) (list? vs))
|
||||
(extend-env ks vs env)]
|
||||
[(or (list? ks) (list? vs))
|
||||
|
|
|
@ -5,28 +5,28 @@
|
|||
;; S, T types
|
||||
;; X a var
|
||||
;; represents S <: X <: T
|
||||
(d-s/c c ([S Type/c] [X symbol?] [T Type/c]) #:transparent)
|
||||
(define-struct/cond-contract c ([S Type/c] [X symbol?] [T Type/c]) #:transparent)
|
||||
|
||||
;; fixed : Listof[c]
|
||||
;; rest : option[c]
|
||||
;; a constraint on an index variable
|
||||
;; the index variable must be instantiated with |fixed| arguments, each meeting the appropriate constraint
|
||||
;; and further instantions of the index variable must respect the rest constraint, if it exists
|
||||
(d-s/c dcon ([fixed (listof c?)] [rest (or/c c? #f)]) #:transparent)
|
||||
(define-struct/cond-contract dcon ([fixed (listof c?)] [rest (or/c c? #f)]) #:transparent)
|
||||
|
||||
;; fixed : Listof[c]
|
||||
;; rest : c
|
||||
(d-s/c dcon-exact ([fixed (listof c?)] [rest c?]) #:transparent)
|
||||
(define-struct/cond-contract dcon-exact ([fixed (listof c?)] [rest c?]) #:transparent)
|
||||
|
||||
;; fixed : Listof[c]
|
||||
;; type : c
|
||||
;; bound : var
|
||||
(d-s/c dcon-dotted ([fixed (listof c?)] [type c?] [bound symbol?]) #:transparent)
|
||||
(define-struct/cond-contract dcon-dotted ([fixed (listof c?)] [type c?] [bound symbol?]) #:transparent)
|
||||
|
||||
(define dcon/c (or/c dcon? dcon-exact? dcon-dotted?))
|
||||
|
||||
;; map : hash mapping index variables to dcons
|
||||
(d-s/c dmap ([map (hash/c symbol? dcon/c)]) #:transparent)
|
||||
(define-struct/cond-contract dmap ([map (hash/c symbol? dcon/c)]) #:transparent)
|
||||
|
||||
;; maps is a list of pairs of
|
||||
;; - functional maps from vars to c's
|
||||
|
@ -34,7 +34,7 @@
|
|||
;; we need a bunch of mappings for each cset to handle case-lambda
|
||||
;; because case-lambda can generate multiple possible solutions, and we
|
||||
;; don't want to rule them out too early
|
||||
(d-s/c cset ([maps (listof (cons/c (hash/c symbol? c? #:immutable #t) dmap?))]) #:transparent)
|
||||
(define-struct/cond-contract cset ([maps (listof (cons/c (hash/c symbol? c? #:immutable #t) dmap?))]) #:transparent)
|
||||
|
||||
(define-match-expander c:
|
||||
(lambda (stx)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
(export dmap^)
|
||||
|
||||
;; dcon-meet : dcon dcon -> dcon
|
||||
(d/c (dcon-meet dc1 dc2)
|
||||
(define/cond-contract (dcon-meet dc1 dc2)
|
||||
(dcon/c dcon/c . -> . dcon/c)
|
||||
(match* (dc1 dc2)
|
||||
[((struct dcon-exact (fixed1 rest1)) (or (struct dcon (fixed2 rest2))
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
;; cset : the constraints being manipulated
|
||||
;; takes the constraints on vars and creates a dmap entry contstraining dbound to be |vars|
|
||||
;; with the constraints that cset places on vars
|
||||
(d/c (move-vars-to-dmap cset dbound vars)
|
||||
(define/cond-contract (move-vars-to-dmap cset dbound vars)
|
||||
(cset? symbol? (listof symbol?) . -> . cset?)
|
||||
(mover cset dbound vars
|
||||
(λ (cmap dmap)
|
||||
|
@ -67,7 +67,7 @@
|
|||
;; dbound : index variable
|
||||
;; cset : the constraints being manipulated
|
||||
;;
|
||||
(d/c (move-rest-to-dmap cset dbound #:exact [exact? #f])
|
||||
(define/cond-contract (move-rest-to-dmap cset dbound #:exact [exact? #f])
|
||||
((cset? symbol?) (#:exact boolean?) . ->* . cset?)
|
||||
(mover cset dbound null
|
||||
(λ (cmap dmap)
|
||||
|
@ -79,7 +79,7 @@
|
|||
;; dbound : index variable
|
||||
;; cset : the constraints being manipulated
|
||||
;;
|
||||
(d/c (move-dotted-rest-to-dmap cset dbound)
|
||||
(define/cond-contract (move-dotted-rest-to-dmap cset dbound)
|
||||
(cset? symbol? . -> . cset?)
|
||||
(mover cset dbound null
|
||||
(λ (cmap dmap)
|
||||
|
@ -94,7 +94,7 @@
|
|||
;; in place, and the "simple" case will then call move-rest-to-dmap. This means
|
||||
;; we need to extract that result from the dmap and merge it with the fixed vars
|
||||
;; we now handled. So I've extended the mover to give access to the dmap, which we use here.
|
||||
(d/c (move-vars+rest-to-dmap cset dbound vars #:exact [exact? #f])
|
||||
(define/cond-contract (move-vars+rest-to-dmap cset dbound vars #:exact [exact? #f])
|
||||
((cset? symbol? (listof symbol?)) (#:exact boolean?) . ->* . cset?)
|
||||
(mover cset dbound vars
|
||||
(λ (cmap dmap)
|
||||
|
@ -298,7 +298,7 @@
|
|||
;; produces a cset which determines a substitution that makes S a subtype of T
|
||||
;; implements the V |-_X S <: T => C judgment from Pierce+Turner, extended with
|
||||
;; the index variables from the TOPLAS paper
|
||||
(d/c (cgen V X Y S T)
|
||||
(define/cond-contract (cgen V X Y S T)
|
||||
((listof symbol?) (listof symbol?) (listof symbol?) Type? Type? . -> . cset?)
|
||||
;; useful quick loop
|
||||
(define (cg S T) (cgen V X Y S T))
|
||||
|
@ -541,7 +541,7 @@
|
|||
;; C : cset? - set of constraints found by the inference engine
|
||||
;; Y : (listof symbol?) - index variables that must have entries
|
||||
;; R : Type? - result type into which we will be substituting
|
||||
(d/c (subst-gen C Y R)
|
||||
(define/cond-contract (subst-gen C Y R)
|
||||
(cset? (listof symbol?) Type? . -> . (or/c #f substitution/c))
|
||||
(define var-hash (free-vars* R))
|
||||
(define idx-hash (free-idxs* R))
|
||||
|
@ -647,8 +647,8 @@
|
|||
;; expected-cset : a cset representing the expected type, to meet early and
|
||||
;; keep the number of constraints in check. (empty by default)
|
||||
;; produces a cset which determines a substitution that makes the Ss subtypes of the Ts
|
||||
(d/c (cgen/list V X Y S T
|
||||
#:expected-cset [expected-cset (empty-cset '() '())])
|
||||
(define/cond-contract (cgen/list V X Y S T
|
||||
#:expected-cset [expected-cset (empty-cset '() '())])
|
||||
(((listof symbol?) (listof symbol?) (listof symbol?) (listof Type?) (listof Type?))
|
||||
(#:expected-cset cset?) . ->* . cset?)
|
||||
(unless (= (length S) (length T))
|
||||
|
|
|
@ -5,59 +5,59 @@
|
|||
(provide (all-defined-out))
|
||||
|
||||
(define-signature dmap^
|
||||
([cnt dmap-meet (dmap? dmap? . -> . dmap?)]))
|
||||
([cond-contracted dmap-meet (dmap? dmap? . -> . dmap?)]))
|
||||
|
||||
(define-signature promote-demote^
|
||||
([cnt var-promote (Type? (listof symbol?) . -> . Type?)]
|
||||
[cnt var-demote (Type? (listof symbol?) . -> . Type?)]))
|
||||
([cond-contracted var-promote (Type? (listof symbol?) . -> . Type?)]
|
||||
[cond-contracted var-demote (Type? (listof symbol?) . -> . Type?)]))
|
||||
|
||||
(define-signature constraints^
|
||||
([cnt exn:infer? (any/c . -> . boolean?)]
|
||||
[cnt fail-sym symbol?]
|
||||
([cond-contracted exn:infer? (any/c . -> . boolean?)]
|
||||
[cond-contracted fail-sym symbol?]
|
||||
;; inference failure - masked before it gets to the user program
|
||||
(define-syntaxes (fail!)
|
||||
(syntax-rules ()
|
||||
[(_ s t) (raise (list fail-sym s t))]))
|
||||
[cnt cset-meet (cset? cset? . -> . cset?)]
|
||||
[cnt cset-meet* ((listof cset?) . -> . cset?)]
|
||||
[cond-contracted cset-meet (cset? cset? . -> . cset?)]
|
||||
[cond-contracted cset-meet* ((listof cset?) . -> . cset?)]
|
||||
no-constraint
|
||||
[cnt empty-cset ((listof symbol?) (listof symbol?) . -> . cset?)]
|
||||
[cnt insert (cset? symbol? Type? Type? . -> . cset?)]
|
||||
[cnt cset-combine ((listof cset?) . -> . cset?)]
|
||||
[cnt c-meet ((c? c?) (symbol?) . ->* . c?)]))
|
||||
[cond-contracted empty-cset ((listof symbol?) (listof symbol?) . -> . cset?)]
|
||||
[cond-contracted insert (cset? symbol? Type? Type? . -> . cset?)]
|
||||
[cond-contracted cset-combine ((listof cset?) . -> . cset?)]
|
||||
[cond-contracted c-meet ((c? c?) (symbol?) . ->* . c?)]))
|
||||
|
||||
(define-signature restrict^
|
||||
([cnt restrict (Type? Type? . -> . Type?)]))
|
||||
([cond-contracted restrict (Type? Type? . -> . Type?)]))
|
||||
|
||||
(define-signature infer^
|
||||
([cnt infer ((;; variables from the forall
|
||||
(listof symbol?)
|
||||
;; indexes from the forall
|
||||
(listof symbol?)
|
||||
;; actual argument types from call site
|
||||
(listof Type?)
|
||||
;; domain
|
||||
(listof Type?)
|
||||
;; range
|
||||
(or/c #f Type?))
|
||||
;; optional expected type
|
||||
((or/c #f Type?))
|
||||
. ->* . any)]
|
||||
[cnt infer/vararg ((;; variables from the forall
|
||||
(listof symbol?)
|
||||
;; indexes from the forall
|
||||
(listof symbol?)
|
||||
;; actual argument types from call site
|
||||
(listof Type?)
|
||||
;; domain
|
||||
(listof Type?)
|
||||
;; rest
|
||||
(or/c #f Type?)
|
||||
;; range
|
||||
(or/c #f Type?))
|
||||
;; [optional] expected type
|
||||
((or/c #f Type?)) . ->* . any)]
|
||||
[cnt infer/dots (((listof symbol?)
|
||||
symbol?
|
||||
(listof Type?) (listof Type?) Type? Type? (listof symbol?))
|
||||
(#:expected (or/c #f Type?)) . ->* . any)]))
|
||||
([cond-contracted infer ((;; variables from the forall
|
||||
(listof symbol?)
|
||||
;; indexes from the forall
|
||||
(listof symbol?)
|
||||
;; actual argument types from call site
|
||||
(listof Type?)
|
||||
;; domain
|
||||
(listof Type?)
|
||||
;; range
|
||||
(or/c #f Type?))
|
||||
;; optional expected type
|
||||
((or/c #f Type?))
|
||||
. ->* . any)]
|
||||
[cond-contracted infer/vararg ((;; variables from the forall
|
||||
(listof symbol?)
|
||||
;; indexes from the forall
|
||||
(listof symbol?)
|
||||
;; actual argument types from call site
|
||||
(listof Type?)
|
||||
;; domain
|
||||
(listof Type?)
|
||||
;; rest
|
||||
(or/c #f Type?)
|
||||
;; range
|
||||
(or/c #f Type?))
|
||||
;; [optional] expected type
|
||||
((or/c #f Type?)) . ->* . any)]
|
||||
[cond-contracted infer/dots (((listof symbol?)
|
||||
symbol?
|
||||
(listof Type?) (listof Type?) Type? Type? (listof symbol?))
|
||||
(#:expected (or/c #f Type?)) . ->* . any)]))
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
(define-struct poly (name vars) #:prefab)
|
||||
|
||||
(p/c [parse-type (syntax? . c:-> . Type/c)]
|
||||
[parse-type/id (syntax? c:any/c . c:-> . Type/c)]
|
||||
[parse-tc-results (syntax? . c:-> . tc-results?)]
|
||||
[parse-tc-results/id (syntax? c:any/c . c:-> . tc-results?)])
|
||||
(provide/cond-contract [parse-type (syntax? . c:-> . Type/c)]
|
||||
[parse-type/id (syntax? c:any/c . c:-> . Type/c)]
|
||||
[parse-tc-results (syntax? . c:-> . tc-results?)]
|
||||
[parse-tc-results/id (syntax? c:any/c . c:-> . tc-results?)])
|
||||
|
||||
(provide star ddd/bound)
|
||||
(define enable-mu-parsing (make-parameter #t))
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
;; expr : the RHS expression
|
||||
;; tc-expr : a function like `tc-expr' from tc-expr-unit
|
||||
;; tc-expr/check : a function like `tc-expr/check' from tc-expr-unit
|
||||
(d/c (get-type/infer stxs expr tc-expr tc-expr/check)
|
||||
(define/cond-contract (get-type/infer stxs expr tc-expr tc-expr/check)
|
||||
((listof identifier?) syntax? (syntax? . -> . tc-results?) (syntax? tc-results? . -> . tc-results?) . -> . tc-results?)
|
||||
(match stxs
|
||||
[(list stx ...)
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
"interning.rkt"
|
||||
racket/syntax unstable/match unstable/struct
|
||||
mzlib/etc
|
||||
scheme/contract
|
||||
(for-syntax
|
||||
scheme/contract
|
||||
(for-syntax
|
||||
scheme/list
|
||||
(only-in racket/syntax generate-temporary)
|
||||
racket/match
|
||||
|
@ -35,16 +35,16 @@
|
|||
#:attributes (i cnt)
|
||||
(pattern i:id
|
||||
#:with cnt #'any/c)
|
||||
(pattern [i:id cnt]))
|
||||
(pattern [i:id cnt]))
|
||||
;; fields
|
||||
(define-syntax-class (idlist name)
|
||||
#:attributes ((i 1) (cnt 1) fs maker pred (acc 1))
|
||||
(pattern (oci:opt-cnt-id ...)
|
||||
(pattern (oci:opt-cnt-id ...)
|
||||
#:with (i ...) #'(oci.i ...)
|
||||
#:with (cnt ...) #'(oci.cnt ...)
|
||||
#:with fs #'(i ...)
|
||||
#:with (_ maker pred acc ...) (build-struct-names name (syntax->list #'fs) #f #t name)))
|
||||
|
||||
|
||||
(define (combiner f flds)
|
||||
(syntax-parse flds
|
||||
[() #'#hasheq()]
|
||||
|
@ -79,11 +79,11 @@
|
|||
#:with fold (format-id #f "~a-fold" #'nm)
|
||||
#:with kw (string->keyword (symbol->string (syntax-e #'nm)))
|
||||
#:with *maker (format-id #'nm "*~a" #'nm)))
|
||||
(lambda (stx)
|
||||
(syntax-parse stx
|
||||
(lambda (stx)
|
||||
(syntax-parse stx
|
||||
[(dform nm:form-nm
|
||||
(~var flds (idlist #'nm))
|
||||
(~or
|
||||
(~or
|
||||
(~optional (~and (~fail #:unless key? "#:key not allowed")
|
||||
[#:key key-expr:expr])
|
||||
#:defaults ([key-expr #'#f]))
|
||||
|
@ -94,14 +94,14 @@
|
|||
[(f) #'f]
|
||||
[(fs ...) #'(list fs ...)])]))
|
||||
(~optional [#:frees frees:frees-pat]
|
||||
#:defaults
|
||||
#:defaults
|
||||
([frees.f1 (combiner #'Rep-free-vars #'flds.fs)]
|
||||
[frees.f2 (combiner #'Rep-free-idxs #'flds.fs)]))
|
||||
(~optional [#:fold-rhs (~var fold-rhs (fold-pat #'nm.fold))]
|
||||
#:defaults
|
||||
([fold-rhs.proc
|
||||
#'(procedure-rename
|
||||
(lambda ()
|
||||
(lambda ()
|
||||
#`(nm.*maker (#,type-rec-id flds.i) ...))
|
||||
'nm.fold)]))
|
||||
(~optional [#:contract cnt:expr]
|
||||
|
@ -112,21 +112,21 @@
|
|||
;; has to be down here to refer to #'cnt
|
||||
[provides (if (attribute no-provide?)
|
||||
#'(begin)
|
||||
#'(begin
|
||||
#'(begin
|
||||
(provide nm.ex flds.pred flds.acc ...)
|
||||
(p/c (rename nm.*maker flds.maker cnt))))])
|
||||
(provide/cond-contract (rename nm.*maker flds.maker cnt))))])
|
||||
#`(begin
|
||||
(define-struct (nm #,par) flds.fs #:inspector #f)
|
||||
(define-match-expander nm.ex
|
||||
(lambda (s)
|
||||
(syntax-parse s
|
||||
[(_ . fs)
|
||||
(syntax-parse s
|
||||
[(_ . fs)
|
||||
#:with pat (syntax/loc s (ign-pats ... . fs))
|
||||
(syntax/loc s (struct nm pat))])))
|
||||
(begin-for-syntax
|
||||
(hash-set! #,ht-stx 'nm.kw (list #'nm.ex #'flds.fs fold-rhs.proc #f)))
|
||||
#,(quasisyntax/loc stx
|
||||
(w/c nm ([nm.*maker cnt])
|
||||
(with-cond-contract nm ([nm.*maker cnt])
|
||||
#,(quasisyntax/loc #'nm
|
||||
(defintern (nm.*maker . flds.fs) flds.maker intern?
|
||||
#:extra-args
|
||||
|
@ -136,17 +136,17 @@
|
|||
|
||||
(define-for-syntax (mk-fold ht type-rec-id rec-ids kws)
|
||||
(lambda (stx)
|
||||
(define new-ht (hash-copy ht))
|
||||
(define new-ht (hash-copy ht))
|
||||
(define-syntax-class clause
|
||||
(pattern
|
||||
(pattern
|
||||
(k:keyword #:matcher mtch pats ... e:expr)
|
||||
#:attr kw (attribute k.datum)
|
||||
#:attr val (list #'mtch
|
||||
#:attr val (list #'mtch
|
||||
(syntax/loc this-syntax (pats ...))
|
||||
(lambda () #'e)
|
||||
this-syntax))
|
||||
(pattern
|
||||
(k:keyword pats ... e:expr)
|
||||
(k:keyword pats ... e:expr)
|
||||
#:attr kw (syntax-e #'k)
|
||||
#:attr val (list (format-id stx "~a:" (attribute kw))
|
||||
(syntax/loc this-syntax (pats ...))
|
||||
|
@ -165,7 +165,7 @@
|
|||
(define-syntax-class (sized-list kws)
|
||||
#:description (format "keyword expr pairs matching with keywords in the list ~a" kws)
|
||||
(pattern ((~or (~seq (~var k (keyword-in kws)) e:expr)) ...)
|
||||
#:when (equal? (length (attribute k.datum))
|
||||
#:when (equal? (length (attribute k.datum))
|
||||
(length (remove-duplicates (attribute k.datum))))
|
||||
#:attr mapping (for/hash ([k* (attribute k.datum)]
|
||||
[e* (attribute e)])
|
||||
|
@ -213,14 +213,14 @@
|
|||
(define-syntax i.d-id (mk #'i.name #'i.ht i.key?)) ...
|
||||
(define-for-syntax i.ht (make-hasheq)) ...
|
||||
(define-struct/printer (i.name Rep) (i.fld-names ...) (lambda (a b c) ((unbox i.printer) a b c))) ...
|
||||
(define-for-syntax i.rec-id #'i.rec-id) ...
|
||||
(provide i.case ...)
|
||||
(define-for-syntax i.rec-id #'i.rec-id) ...
|
||||
(provide i.case ...)
|
||||
(define-syntaxes (i.case ...)
|
||||
(let ()
|
||||
(let ()
|
||||
(apply values
|
||||
(map (lambda (ht)
|
||||
(map (lambda (ht)
|
||||
(define rec-ids (list i.rec-id ...))
|
||||
(mk-fold ht
|
||||
(mk-fold ht
|
||||
(car rec-ids)
|
||||
rec-ids
|
||||
'(i.kw ...)))
|
||||
|
@ -235,11 +235,11 @@
|
|||
[Rep-free-vars free-vars*]
|
||||
[Rep-free-idxs free-idxs*]))
|
||||
|
||||
(p/c (struct Rep ([seq exact-nonnegative-integer?]
|
||||
[free-vars (hash/c symbol? variance?)]
|
||||
[free-idxs (hash/c symbol? variance?)]
|
||||
[stx (or/c #f syntax?)]))
|
||||
[replace-syntax (Rep? syntax? . -> . Rep?)])
|
||||
(provide/cond-contract (struct Rep ([seq exact-nonnegative-integer?]
|
||||
[free-vars (hash/c symbol? variance?)]
|
||||
[free-idxs (hash/c symbol? variance?)]
|
||||
[stx (or/c #f syntax?)]))
|
||||
[replace-syntax (Rep? syntax? . -> . Rep?)])
|
||||
|
||||
(define (replace-field val new-val idx)
|
||||
(define-values (type skipped) (struct-info val))
|
||||
|
|
|
@ -420,7 +420,7 @@
|
|||
|
||||
;; remove-dups: List[Type] -> List[Type]
|
||||
;; removes duplicate types from a SORTED list
|
||||
(d/c (remove-dups types)
|
||||
(define/cond-contract (remove-dups types)
|
||||
((listof Rep?) . -> . (listof Rep?))
|
||||
(cond [(null? types) types]
|
||||
[(null? (cdr types)) types]
|
||||
|
@ -443,14 +443,16 @@
|
|||
[_ (int-err "Tried to remove too many scopes: ~a" sc)])))
|
||||
|
||||
;; type equality
|
||||
(d/c (type-equal? s t) (Rep? Rep? . -> . boolean?) (eq? (Rep-seq s) (Rep-seq t)))
|
||||
(define/cond-contract (type-equal? s t)
|
||||
(Rep? Rep? . -> . boolean?)
|
||||
(eq? (Rep-seq s) (Rep-seq t)))
|
||||
|
||||
;; inequality - good
|
||||
(d/c (type<? s t)
|
||||
(define/cond-contract (type<? s t)
|
||||
(Rep? Rep? . -> . boolean?)
|
||||
(< (Rep-seq s) (Rep-seq t)))
|
||||
|
||||
(d/c (type-compare s t)
|
||||
(define/cond-contract (type-compare s t)
|
||||
(Rep? Rep? . -> . (or/c -1 0 1))
|
||||
(cond [(type-equal? s t) 0]
|
||||
[(type<? s t) 1]
|
||||
|
@ -732,6 +734,6 @@
|
|||
[Poly-body* Poly-body]
|
||||
[PolyDots-body* PolyDots-body]))
|
||||
|
||||
(p/c [type-equal? (Rep? Rep? . -> . boolean?)])
|
||||
(provide/cond-contract [type-equal? (Rep? Rep? . -> . boolean?)])
|
||||
|
||||
;(trace unfold)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
(except-in syntax/parse id)
|
||||
(only-in srfi/1 split-at))
|
||||
|
||||
(p/c
|
||||
(provide/cond-contract
|
||||
[check-below (-->d ([s (-or/c Type/c tc-results?)] [t (-or/c Type/c tc-results?)]) () [_ (if (Type? s) Type/c tc-results?)])])
|
||||
|
||||
(define (print-object o)
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
(define-struct (def-stx-binding binding) () #:transparent)
|
||||
(define-struct (def-struct-stx-binding def-stx-binding) (static-info) #:transparent)
|
||||
|
||||
(p/c (struct binding ([name identifier?]))
|
||||
(struct (def-binding binding) ([name identifier?] [ty any/c]))
|
||||
(struct (def-stx-binding binding) ([name identifier?]))
|
||||
(struct (def-struct-stx-binding binding) ([name identifier?] [static-info (or/c #f struct-info?)])))
|
||||
(provide/cond-contract
|
||||
(struct binding ([name identifier?]))
|
||||
(struct (def-binding binding) ([name identifier?] [ty any/c]))
|
||||
(struct (def-stx-binding binding) ([name identifier?]))
|
||||
(struct (def-struct-stx-binding binding) ([name identifier?] [static-info (or/c #f struct-info?)])))
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
(private type-annotation)
|
||||
(for-template scheme/base))
|
||||
|
||||
(p/c [find-annotation (syntax? identifier? . -> . (or/c #f Type/c))])
|
||||
(provide/cond-contract [find-annotation (syntax? identifier? . -> . (or/c #f Type/c))])
|
||||
|
||||
(define-syntax-class lv-clause
|
||||
#:transparent
|
||||
|
|
|
@ -7,39 +7,39 @@
|
|||
(provide (all-defined-out))
|
||||
|
||||
(define-signature tc-expr^
|
||||
([cnt tc-expr (syntax? . -> . tc-results?)]
|
||||
[cnt tc-literal (->* (syntax?) ((or/c #f Type/c)) Type/c)]
|
||||
[cnt tc-expr/check (syntax? tc-results? . -> . tc-results?)]
|
||||
[cnt tc-expr/check/t (syntax? tc-results? . -> . Type/c)]
|
||||
[cnt tc-exprs ((listof syntax?) . -> . tc-results?)]
|
||||
[cnt tc-exprs/check ((listof syntax?) tc-results? . -> . tc-results?)]
|
||||
[cnt tc-expr/t (syntax? . -> . Type/c)]
|
||||
[cnt single-value ((syntax?) ((or/c tc-results? #f)) . ->* . tc-results?)]))
|
||||
([cond-contracted tc-expr (syntax? . -> . tc-results?)]
|
||||
[cond-contracted tc-literal (->* (syntax?) ((or/c #f Type/c)) Type/c)]
|
||||
[cond-contracted tc-expr/check (syntax? tc-results? . -> . tc-results?)]
|
||||
[cond-contracted tc-expr/check/t (syntax? tc-results? . -> . Type/c)]
|
||||
[cond-contracted tc-exprs ((listof syntax?) . -> . tc-results?)]
|
||||
[cond-contracted tc-exprs/check ((listof syntax?) tc-results? . -> . tc-results?)]
|
||||
[cond-contracted tc-expr/t (syntax? . -> . Type/c)]
|
||||
[cond-contracted single-value ((syntax?) ((or/c tc-results? #f)) . ->* . tc-results?)]))
|
||||
|
||||
(define-signature check-subforms^
|
||||
([cnt check-subforms/ignore (syntax? . -> . any)]
|
||||
[cnt check-subforms/with-handlers (syntax? . -> . any)]
|
||||
[cnt check-subforms/with-handlers/check (syntax? tc-results? . -> . any)]))
|
||||
([cond-contracted check-subforms/ignore (syntax? . -> . any)]
|
||||
[cond-contracted check-subforms/with-handlers (syntax? . -> . any)]
|
||||
[cond-contracted check-subforms/with-handlers/check (syntax? tc-results? . -> . any)]))
|
||||
|
||||
(define-signature tc-if^
|
||||
([cnt tc/if-twoarm ((syntax? syntax? syntax?) (tc-results?) . ->* . tc-results?)]))
|
||||
([cond-contracted tc/if-twoarm ((syntax? syntax? syntax?) (tc-results?) . ->* . tc-results?)]))
|
||||
|
||||
(define-signature tc-lambda^
|
||||
([cnt tc/lambda (syntax? syntax? syntax? . -> . tc-results?)]
|
||||
[cnt tc/lambda/check (syntax? syntax? syntax? tc-results? . -> . tc-results?)]
|
||||
[cnt tc/rec-lambda/check (syntax? syntax? syntax? syntax? (listof Type/c) tc-results? . -> . tc-results?)]))
|
||||
([cond-contracted tc/lambda (syntax? syntax? syntax? . -> . tc-results?)]
|
||||
[cond-contracted tc/lambda/check (syntax? syntax? syntax? tc-results? . -> . tc-results?)]
|
||||
[cond-contracted tc/rec-lambda/check (syntax? syntax? syntax? syntax? (listof Type/c) tc-results? . -> . tc-results?)]))
|
||||
|
||||
(define-signature tc-app^
|
||||
([cnt tc/app (syntax? . -> . tc-results?)]
|
||||
[cnt tc/app/check (syntax? tc-results? . -> . tc-results?)]))
|
||||
([cond-contracted tc/app (syntax? . -> . tc-results?)]
|
||||
[cond-contracted tc/app/check (syntax? tc-results? . -> . tc-results?)]))
|
||||
|
||||
(define-signature tc-apply^
|
||||
([cnt tc/apply (syntax? syntax? . -> . tc-results?)]))
|
||||
([cond-contracted tc/apply (syntax? syntax? . -> . tc-results?)]))
|
||||
|
||||
(define-signature tc-let^
|
||||
([cnt tc/let-values ((syntax? syntax? syntax? syntax?) ((or/c #f tc-results?)) . ->* . tc-results?)]
|
||||
[cnt tc/letrec-values ((syntax? syntax? syntax? syntax?) ((or/c #f tc-results?)) . ->* . tc-results?)]))
|
||||
([cond-contracted tc/let-values ((syntax? syntax? syntax? syntax?) ((or/c #f tc-results?)) . ->* . tc-results?)]
|
||||
[cond-contracted tc/letrec-values ((syntax? syntax? syntax? syntax?) ((or/c #f tc-results?)) . ->* . tc-results?)]))
|
||||
|
||||
(define-signature tc-dots^
|
||||
([cnt tc/dots (syntax? . -> . (values Type/c symbol?))]))
|
||||
([cond-contracted tc/dots (syntax? . -> . (values Type/c symbol?))]))
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
|
||||
;; syntax? syntax? arr? (listof tc-results?) (or/c #f tc-results) [boolean?] -> tc-results?
|
||||
(d/c (tc/funapp1 f-stx args-stx ftype0 argtys expected #:check [check? #t])
|
||||
(define/cond-contract (tc/funapp1 f-stx args-stx ftype0 argtys expected #:check [check? #t])
|
||||
((syntax? syntax? arr? (c:listof tc-results?) (c:or/c #f tc-results?)) (#:check boolean?) . c:->* . tc-results?)
|
||||
(match* (ftype0 argtys)
|
||||
;; we check that all kw args are optional
|
||||
|
@ -65,9 +65,9 @@
|
|||
[else (string-append (stringify (map make-printable dom)) rng-string)])))
|
||||
|
||||
;; Generates error messages when operand types don't match operator domains.
|
||||
(d/c (domain-mismatches f-stx args-stx ty doms rests drests rngs arg-tys tail-ty tail-bound
|
||||
#:expected [expected #f] #:return [return (make-Union null)]
|
||||
#:msg-thunk [msg-thunk (lambda (dom) dom)])
|
||||
(define/cond-contract (domain-mismatches f-stx args-stx ty doms rests drests rngs arg-tys tail-ty tail-bound
|
||||
#:expected [expected #f] #:return [return (make-Union null)]
|
||||
#:msg-thunk [msg-thunk (lambda (dom) dom)])
|
||||
((syntax? syntax? Type/c (c:listof (c:listof Type/c)) (c:listof (c:or/c #f Type/c))
|
||||
(c:listof (c:or/c #f (c:cons/c Type/c (c:or/c c:natural-number/c symbol?))))
|
||||
(c:listof (c:or/c Values? ValuesDots?)) (c:listof tc-results?) (c:or/c #f Type/c) c:any/c)
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
t]))
|
||||
|
||||
;; sets the flag box to #f if anything becomes (U)
|
||||
(d/c (env+ env fs flag)
|
||||
(define/cond-contract (env+ env fs flag)
|
||||
(([e env?] [fs (listof Filter/c)] [bx (box/c boolean?)])
|
||||
#:pre (bx) (unbox bx) . ->i . [_ env?])
|
||||
(define-values (props atoms) (combine-props fs (env-props env) flag))
|
||||
|
@ -86,5 +86,6 @@
|
|||
x Γ)]
|
||||
[_ Γ])))
|
||||
|
||||
(p/c [env+ (([e env?] [fs (listof Filter/c)] [bx (box/c boolean?)])
|
||||
#:pre (bx) (unbox bx) . ->i . [_ env?])])
|
||||
(provide/cond-contract
|
||||
[env+ (([e env?] [fs (listof Filter/c)] [bx (box/c boolean?)])
|
||||
#:pre (bx) (unbox bx) . ->i . [_ env?])])
|
||||
|
|
|
@ -170,7 +170,7 @@
|
|||
;; typecheck an identifier
|
||||
;; the identifier has variable effect
|
||||
;; tc-id : identifier -> tc-results
|
||||
(d/c (tc-id id)
|
||||
(define/cond-contract (tc-id id)
|
||||
(--> identifier? tc-results?)
|
||||
(let* ([ty (lookup-type/lexical id)])
|
||||
(ret ty
|
||||
|
@ -229,7 +229,7 @@
|
|||
t)]))))
|
||||
|
||||
;; tc-expr/check : syntax tc-results -> tc-results
|
||||
(d/c (tc-expr/check/internal form expected)
|
||||
(define/cond-contract (tc-expr/check/internal form expected)
|
||||
(--> syntax? tc-results? tc-results?)
|
||||
(parameterize ([current-orig-stx form])
|
||||
;(printf "form: ~a\n" (syntax-object->datum form))
|
||||
|
@ -426,7 +426,7 @@
|
|||
(add-typeof-expr form r)
|
||||
r)]))))
|
||||
|
||||
(d/c (tc/send form rcvr method args [expected #f])
|
||||
(define/cond-contract (tc/send form rcvr method args [expected #f])
|
||||
(-->* (syntax? syntax? syntax? syntax?) ((-or/c tc-results? #f)) tc-results?)
|
||||
(match (tc-expr rcvr)
|
||||
[(tc-result1: (Instance: (and c (Class: _ _ methods))))
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
(tc/funapp1 f-stx args-stx (subst-all substitution a) argtys expected #:check #f))))
|
||||
(poly-fail f-stx args-stx t argtys #:name (and (identifier? f-stx) f-stx) #:expected expected))))]))
|
||||
|
||||
(d/c (tc/funapp f-stx args-stx ftype0 argtys expected)
|
||||
(define/cond-contract (tc/funapp f-stx args-stx ftype0 argtys expected)
|
||||
(syntax? syntax? tc-results? (c:listof tc-results?) (c:or/c #f tc-results?) . c:-> . tc-results?)
|
||||
(match* (ftype0 argtys)
|
||||
;; we special-case this (no case-lambda) for improved error messages
|
||||
|
|
|
@ -15,19 +15,19 @@
|
|||
(types abbrev utils)
|
||||
(env type-env-structs lexical-env tvar-env index-env)
|
||||
(utils tc-utils)
|
||||
|
||||
|
||||
racket/match)
|
||||
(require (for-template scheme/base "internal-forms.rkt"))
|
||||
|
||||
(import tc-expr^)
|
||||
(export tc-lambda^)
|
||||
|
||||
(d-s/c lam-result ([args (listof (list/c identifier? Type/c))]
|
||||
[kws (listof (list/c keyword? identifier? Type/c boolean?))]
|
||||
[rest (or/c #f (list/c identifier? Type/c))]
|
||||
[drest (or/c #f (cons/c identifier? (cons/c Type/c symbol?)))]
|
||||
[body tc-results?])
|
||||
#:transparent)
|
||||
(define-struct/cond-contract lam-result ([args (listof (list/c identifier? Type/c))]
|
||||
[kws (listof (list/c keyword? identifier? Type/c boolean?))]
|
||||
[rest (or/c #f (list/c identifier? Type/c))]
|
||||
[drest (or/c #f (cons/c identifier? (cons/c Type/c symbol?)))]
|
||||
[body tc-results?])
|
||||
#:transparent)
|
||||
|
||||
(define (lam-result->type lr)
|
||||
(match lr
|
||||
|
@ -36,7 +36,7 @@
|
|||
(if rest (list (car rest)) null)
|
||||
(if drest (list (car drest)) null)
|
||||
kw-id)])
|
||||
(make-arr
|
||||
(make-arr
|
||||
arg-tys
|
||||
(abstract-results body arg-names)
|
||||
#:kws (map make-Keyword kw kw-ty req?)
|
||||
|
@ -57,10 +57,10 @@
|
|||
(if rest " and a rest arg" "")))
|
||||
|
||||
;; listof[id] option[id] block listof[type] option[type] option[(cons type var)] tc-result -> lam-result
|
||||
(d/c (check-clause arg-list rest body arg-tys rest-ty drest ret-ty)
|
||||
((listof identifier?)
|
||||
(or/c #f identifier?) syntax? (listof Type/c) (or/c #f Type/c) (or/c #f (cons/c Type/c symbol?)) tc-results?
|
||||
. --> .
|
||||
(define/cond-contract (check-clause arg-list rest body arg-tys rest-ty drest ret-ty)
|
||||
((listof identifier?)
|
||||
(or/c #f identifier?) syntax? (listof Type/c) (or/c #f Type/c) (or/c #f (cons/c Type/c symbol?)) tc-results?
|
||||
. --> .
|
||||
lam-result?)
|
||||
(let* ([arg-len (length arg-list)]
|
||||
[tys-len (length arg-tys)]
|
||||
|
@ -71,11 +71,11 @@
|
|||
[(< arg-len tys-len) (take arg-tys arg-len)]
|
||||
[(> arg-len tys-len) (append arg-tys
|
||||
(map (lambda _ (or rest-ty (Un)))
|
||||
(drop arg-list tys-len)))]))])
|
||||
(drop arg-list tys-len)))]))])
|
||||
(define (check-body)
|
||||
(with-lexical-env/extend
|
||||
(with-lexical-env/extend
|
||||
arg-list arg-types
|
||||
(make-lam-result (for/list ([al arg-list] [at arg-types] [a-ty arg-tys]) (list al at)) null
|
||||
(make-lam-result (for/list ([al arg-list] [at arg-types] [a-ty arg-tys]) (list al at)) null
|
||||
(and rest-ty (list (or rest (generate-temporary)) rest-ty))
|
||||
;; make up a fake name if none exists, this is an error case anyway
|
||||
(and drest (cons (or rest (generate-temporary)) drest))
|
||||
|
@ -120,13 +120,13 @@
|
|||
;; syntax-list[id] block -> lam-result
|
||||
(define (tc/lambda-clause args body)
|
||||
(syntax-case args ()
|
||||
[(args ...)
|
||||
[(args ...)
|
||||
(let* ([arg-list (syntax->list #'(args ...))]
|
||||
[arg-types (get-types arg-list #:default Univ)])
|
||||
(with-lexical-env/extend
|
||||
(with-lexical-env/extend
|
||||
arg-list arg-types
|
||||
(make lam-result
|
||||
(map list arg-list arg-types)
|
||||
(map list arg-list arg-types)
|
||||
null
|
||||
#f
|
||||
#f
|
||||
|
@ -134,7 +134,7 @@
|
|||
[(args ... . rest)
|
||||
(let* ([arg-list (syntax->list #'(args ...))]
|
||||
[arg-types (get-types arg-list #:default Univ)])
|
||||
(cond
|
||||
(cond
|
||||
[(dotted? #'rest)
|
||||
=>
|
||||
(lambda (bound)
|
||||
|
@ -144,7 +144,7 @@
|
|||
(tc-error/stx #'rest "Bound on ... type (~a) was not in scope" bound)))
|
||||
(let ([rest-type (extend-tvars (list bound)
|
||||
(get-type #'rest #:default Univ))])
|
||||
(with-lexical-env/extend
|
||||
(with-lexical-env/extend
|
||||
(cons #'rest arg-list)
|
||||
(cons (make-ListDots rest-type bound) arg-types)
|
||||
(make-lam-result
|
||||
|
@ -155,8 +155,8 @@
|
|||
(tc-exprs (syntax->list body))))))]
|
||||
[else
|
||||
(let ([rest-type (get-type #'rest #:default Univ)])
|
||||
(with-lexical-env/extend
|
||||
(cons #'rest arg-list)
|
||||
(with-lexical-env/extend
|
||||
(cons #'rest arg-list)
|
||||
(cons (make-Listof rest-type) arg-types)
|
||||
(make-lam-result
|
||||
(map list arg-list arg-types)
|
||||
|
@ -194,7 +194,7 @@
|
|||
[(null? (syntax-e s)) null]
|
||||
[else (list s)])))
|
||||
(define (go formals bodies formals* bodies* nums-seen)
|
||||
(cond
|
||||
(cond
|
||||
[(null? formals)
|
||||
(map tc/lambda-clause (reverse formals*) (reverse bodies*))]
|
||||
[(memv (syntax-len (car formals)) nums-seen)
|
||||
|
@ -202,19 +202,19 @@
|
|||
(tc/lambda-clause (car formals) (car bodies))
|
||||
(go (cdr formals) (cdr bodies) formals* bodies* nums-seen)]
|
||||
[else
|
||||
(go (cdr formals) (cdr bodies)
|
||||
(go (cdr formals) (cdr bodies)
|
||||
(cons (car formals) formals*)
|
||||
(cons (car bodies) bodies*)
|
||||
(cons (syntax-len (car formals)) nums-seen))]))
|
||||
(cond
|
||||
(cond
|
||||
;; special case for not-case-lambda
|
||||
[(and expected
|
||||
(= 1 (length (syntax->list formals))))
|
||||
(let loop ([expected expected])
|
||||
(match expected
|
||||
(let loop ([expected expected])
|
||||
(match expected
|
||||
[(tc-result1: (and t (Mu: _ _))) (loop (ret (unfold t)))]
|
||||
[(tc-result1: (Function: (list (arr: argss rets rests drests '()) ...)))
|
||||
(let ([fmls (car (syntax->list formals))])
|
||||
(let ([fmls (car (syntax->list formals))])
|
||||
(for/list ([args argss] [ret rets] [rest rests] [drest drests])
|
||||
(tc/lambda-clause/check fmls (car (syntax->list bodies))
|
||||
args (values->tc-results ret (formals->list fmls)) rest drest)))]
|
||||
|
@ -224,15 +224,15 @@
|
|||
|
||||
(define (tc/mono-lambda/type formals bodies expected)
|
||||
(define t (make-Function (map lam-result->type (tc/mono-lambda formals bodies expected))))
|
||||
(if expected
|
||||
(if expected
|
||||
(and (check-below (ret t true-filter) expected) t)
|
||||
t))
|
||||
|
||||
;; tc/plambda syntax syntax-list syntax-list type -> Poly
|
||||
;; formals and bodies must by syntax-lists
|
||||
(d/c (tc/plambda form formals bodies expected)
|
||||
(define/cond-contract (tc/plambda form formals bodies expected)
|
||||
(syntax? syntax? syntax? (or/c tc-results? #f) . --> . Type/c)
|
||||
(d/c (maybe-loop form formals bodies expected)
|
||||
(define/cond-contract (maybe-loop form formals bodies expected)
|
||||
(syntax? syntax? syntax? tc-results? . --> . Type/c)
|
||||
(match expected
|
||||
[(tc-result1: (Function: _)) (tc/mono-lambda/type formals bodies expected)]
|
||||
|
@ -245,7 +245,7 @@
|
|||
[(tc-result1: (and t (Poly-names: ns expected*)))
|
||||
(let* ([tvars (let ([p (syntax-property form 'typechecker:plambda)])
|
||||
(when (and (pair? p) (eq? '... (car (last p))))
|
||||
(tc-error
|
||||
(tc-error
|
||||
"Expected a polymorphic function without ..., but given function had ..."))
|
||||
(or (and p (map syntax-e (syntax->list p)))
|
||||
ns))]
|
||||
|
@ -254,7 +254,7 @@
|
|||
;(printf "plambda: ~a ~a ~a \n" literal-tvars new-tvars ty)
|
||||
t)]
|
||||
[(tc-result1: (and t (PolyDots-names: (list ns ... dvar) expected*)))
|
||||
(let-values
|
||||
(let-values
|
||||
([(tvars dotted)
|
||||
(let ([p (syntax-property form 'typechecker:plambda)])
|
||||
(if p
|
||||
|
@ -264,7 +264,7 @@
|
|||
[_ (tc-error "Expected a polymorphic function with ..., but given function had no ...")])
|
||||
(values ns dvar)))])
|
||||
;; check the body for side effect
|
||||
(extend-indexes dotted
|
||||
(extend-indexes dotted
|
||||
(extend-tvars tvars
|
||||
(maybe-loop form formals bodies (ret expected*))))
|
||||
t)]
|
||||
|
@ -280,7 +280,7 @@
|
|||
(tc/mono-lambda/type formals bodies #f))])
|
||||
;(printf "plambda: ~a ~a ~a \n" literal-tvars new-tvars ty)
|
||||
(make-Poly tvars ty))])]
|
||||
[(tc-result1: t)
|
||||
[(tc-result1: t)
|
||||
(unless (check-below (tc/plambda form formals bodies #f) t)
|
||||
(tc-error/expr #:return expected
|
||||
"Expected a value of type ~a, but got a polymorphic function." t))
|
||||
|
@ -290,7 +290,7 @@
|
|||
;; typecheck a sequence of case-lambda clauses, which is possibly polymorphic
|
||||
;; tc/lambda/internal syntax syntax-list syntax-list option[type] -> tc-result
|
||||
(define (tc/lambda/internal form formals bodies expected)
|
||||
(if (or (syntax-property form 'typechecker:plambda)
|
||||
(if (or (syntax-property form 'typechecker:plambda)
|
||||
(match expected
|
||||
[(tc-result1: t) (or (Poly? t) (PolyDots? t))]
|
||||
[_ #f]))
|
||||
|
|
|
@ -27,16 +27,16 @@
|
|||
[(tc-results: ts _ _)
|
||||
(ret ts (for/list ([f ts]) (make-NoFilter)) (for/list ([f ts]) (make-NoObject)))]))
|
||||
|
||||
(d/c (do-check expr->type namess results expected-results form exprs body clauses expected #:abstract [abstract null])
|
||||
(define/cond-contract (do-check expr->type namess results expected-results form exprs body clauses expected #:abstract [abstract null])
|
||||
(((syntax? syntax? tc-results? . c:-> . any/c)
|
||||
(listof (listof identifier?)) (listof tc-results?) (listof tc-results?)
|
||||
syntax? (listof syntax?) syntax? (listof syntax?) (or/c #f tc-results?))
|
||||
(#:abstract any/c)
|
||||
. c:->* .
|
||||
tc-results?)
|
||||
(w/c t/p ([types (listof (listof Type/c))] ; types that may contain undefined (letrec)
|
||||
[expected-types (listof (listof Type/c))] ; types that may not contain undefined (what we got from the user)
|
||||
[props (listof (listof Filter?))])
|
||||
(with-cond-contract t/p ([types (listof (listof Type/c))] ; types that may contain undefined (letrec)
|
||||
[expected-types (listof (listof Type/c))] ; types that may not contain undefined (what we got from the user)
|
||||
[props (listof (listof Filter?))])
|
||||
(define-values (types expected-types props)
|
||||
(for/lists (t e p)
|
||||
([r (in-list results)]
|
||||
|
@ -56,8 +56,8 @@
|
|||
(make-ImpFilter (-filter (-val #f) n) f-)))))]
|
||||
[((tc-results: ts (NoFilter:) _) (tc-results: e-ts (NoFilter:) _))
|
||||
(values ts e-ts null)]))))
|
||||
(w/c append-region ([p1 (listof Filter?)]
|
||||
[p2 (listof Filter?)])
|
||||
(with-cond-contract append-region ([p1 (listof Filter?)]
|
||||
[p2 (listof Filter?)])
|
||||
(define-values (p1 p2)
|
||||
(combine-props (apply append props) (env-props (lexical-env)) (box #t))))
|
||||
;; extend the lexical environment for checking the body
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
(provide abstract-results)
|
||||
|
||||
|
||||
(d/c (abstract-results results arg-names)
|
||||
(define/cond-contract (abstract-results results arg-names)
|
||||
(tc-results? (listof identifier?) . -> . (or/c Values? ValuesDots?))
|
||||
(define keys (for/list ([(nm k) (in-indexed arg-names)]) k))
|
||||
(match results
|
||||
|
@ -27,7 +27,7 @@
|
|||
(make-Result t (abstract-filter arg-names keys f) (abstract-object arg-names keys o))))]))
|
||||
|
||||
|
||||
(d/c (abstract-object ids keys o)
|
||||
(define/cond-contract (abstract-object ids keys o)
|
||||
(-> (listof identifier?) (listof name-ref/c) Object? Object?)
|
||||
(define (lookup y)
|
||||
(for/first ([x ids] [i keys] #:when (free-identifier=? x y)) i))
|
||||
|
@ -39,16 +39,16 @@
|
|||
[_ (make-Empty)]))
|
||||
|
||||
|
||||
(d/c (abstract-filter ids keys fs)
|
||||
(define/cond-contract (abstract-filter ids keys fs)
|
||||
(-> (listof identifier?) (listof name-ref/c) FilterSet/c FilterSet/c)
|
||||
(match fs
|
||||
[(FilterSet: f+ f-)
|
||||
(-FS (abo ids keys f+) (abo ids keys f-))]
|
||||
[(NoFilter:) (-FS -top -top)]))
|
||||
|
||||
(d/c (abo xs idxs f)
|
||||
(define/cond-contract (abo xs idxs f)
|
||||
((listof identifier?) (listof name-ref/c) Filter/c . -> . Filter/c)
|
||||
(d/c (lookup y)
|
||||
(define/cond-contract (lookup y)
|
||||
(identifier? . -> . (or/c #f integer?))
|
||||
(for/first ([x xs] [i idxs] #:when (free-identifier=? x y)) i))
|
||||
(define-match-expander lookup:
|
||||
|
@ -77,7 +77,7 @@
|
|||
(provide combine-props tc-results->values)
|
||||
|
||||
|
||||
(d/c (resolve atoms prop)
|
||||
(define/cond-contract (resolve atoms prop)
|
||||
((listof Filter/c)
|
||||
Filter/c
|
||||
. -> .
|
||||
|
@ -102,7 +102,7 @@
|
|||
[(cons (AndFilter: ps*) ps) (loop (append ps* ps))]
|
||||
[(cons p ps) (cons p (loop ps))])))
|
||||
|
||||
(d/c (combine-props new-props old-props flag)
|
||||
(define/cond-contract (combine-props new-props old-props flag)
|
||||
((listof Filter/c) (listof Filter/c) (box/c boolean?)
|
||||
. -> .
|
||||
(values (listof (or/c ImpFilter? OrFilter? AndFilter?)) (listof (or/c TypeFilter? NotTypeFilter?))))
|
||||
|
|
|
@ -89,18 +89,18 @@
|
|||
|
||||
;; construct all the various types for structs, and then register the approriate names
|
||||
;; identifier listof[identifier] type listof[fld] listof[Type] boolean -> Type listof[Type] listof[Type]
|
||||
(d/c (mk/register-sty nm flds parent parent-fields types
|
||||
#:wrapper [wrapper values]
|
||||
#:type-wrapper [type-wrapper values]
|
||||
#:pred-wrapper [pred-wrapper values]
|
||||
#:mutable [setters? #f]
|
||||
#:struct-info [si #f]
|
||||
#:proc-ty [proc-ty #f]
|
||||
#:maker [maker* #f]
|
||||
#:predicate [pred* #f]
|
||||
#:constructor-return [cret #f]
|
||||
#:poly? [poly? #f]
|
||||
#:type-only [type-only #f])
|
||||
(define/cond-contract (mk/register-sty nm flds parent parent-fields types
|
||||
#:wrapper [wrapper values]
|
||||
#:type-wrapper [type-wrapper values]
|
||||
#:pred-wrapper [pred-wrapper values]
|
||||
#:mutable [setters? #f]
|
||||
#:struct-info [si #f]
|
||||
#:proc-ty [proc-ty #f]
|
||||
#:maker [maker* #f]
|
||||
#:predicate [pred* #f]
|
||||
#:constructor-return [cret #f]
|
||||
#:poly? [poly? #f]
|
||||
#:type-only [type-only #f])
|
||||
(c->* (identifier? (listof identifier?) (or/c Type/c #f) (listof fld?) (listof Type/c))
|
||||
(#:wrapper procedure?
|
||||
#:type-wrapper procedure?
|
||||
|
@ -144,15 +144,15 @@
|
|||
;; generate names, and register the approriate types give field types and structure type
|
||||
;; optionally wrap things
|
||||
;; identifier Type Listof[identifer] Listof[Type] Listof[Type] #:wrapper (Type -> Type) #:maker identifier
|
||||
(d/c (register-struct-types nm sty flds external-fld-types external-fld-types/no-parent setters?
|
||||
#:wrapper [wrapper values]
|
||||
#:struct-info [si #f]
|
||||
#:type-wrapper [type-wrapper values]
|
||||
#:pred-wrapper [pred-wrapper values]
|
||||
#:maker [maker* #f]
|
||||
#:predicate [pred* #f]
|
||||
#:poly? [poly? #f]
|
||||
#:constructor-return [cret #f])
|
||||
(define/cond-contract (register-struct-types nm sty flds external-fld-types external-fld-types/no-parent setters?
|
||||
#:wrapper [wrapper values]
|
||||
#:struct-info [si #f]
|
||||
#:type-wrapper [type-wrapper values]
|
||||
#:pred-wrapper [pred-wrapper values]
|
||||
#:maker [maker* #f]
|
||||
#:predicate [pred* #f]
|
||||
#:poly? [poly? #f]
|
||||
#:constructor-return [cret #f])
|
||||
(c->* (identifier? Struct? (listof identifier?) (listof Type/c) (listof Type/c) boolean?)
|
||||
(#:wrapper procedure?
|
||||
#:type-wrapper procedure?
|
||||
|
@ -248,10 +248,10 @@
|
|||
|
||||
;; typecheck a non-polymophic struct and register the approriate types
|
||||
;; tc/struct : (U identifier (list identifier identifier)) Listof[identifier] Listof[syntax] -> void
|
||||
(d/c (tc/struct nm/par flds tys [proc-ty #f]
|
||||
#:maker [maker #f] #:constructor-return [cret #f] #:mutable [mutable #f]
|
||||
#:predicate [pred #f]
|
||||
#:type-only [type-only #f])
|
||||
(define/cond-contract (tc/struct nm/par flds tys [proc-ty #f]
|
||||
#:maker [maker #f] #:constructor-return [cret #f] #:mutable [mutable #f]
|
||||
#:predicate [pred #f]
|
||||
#:type-only [type-only #f])
|
||||
(c->* (syntax? (listof identifier?) (listof syntax?))
|
||||
((or/c #f syntax?)
|
||||
#:maker any/c
|
||||
|
@ -283,7 +283,7 @@
|
|||
;; register a struct type
|
||||
;; convenience function for built-in structs
|
||||
;; tc/builtin-struct : identifier identifier Listof[identifier] Listof[Type] Listof[Type] -> void
|
||||
(d/c (tc/builtin-struct nm parent flds tys #;parent-tys)
|
||||
(define/cond-contract (tc/builtin-struct nm parent flds tys #;parent-tys)
|
||||
(c-> identifier? (or/c #f identifier?) (listof identifier?)
|
||||
(listof Type/c) #;(listof fld?)
|
||||
any/c)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
(provide (all-defined-out))
|
||||
|
||||
(d/c (open-Result r objs [ts #f])
|
||||
(define/cond-contract (open-Result r objs [ts #f])
|
||||
(->* (Result? (listof Object?)) ((listof Type/c)) (values Type/c FilterSet? Object?))
|
||||
(match r
|
||||
[(Result: t fs old-obj)
|
||||
|
@ -23,7 +23,7 @@
|
|||
(subst-filter-set fs k o #t arg-ty)
|
||||
(subst-object old-obj k o #t)))]))
|
||||
|
||||
(d/c (subst-filter-set fs k o polarity [t #f])
|
||||
(define/cond-contract (subst-filter-set fs k o polarity [t #f])
|
||||
(->* ((or/c FilterSet? NoFilter?) name-ref/c Object? boolean?) ((or/c #f Type/c)) FilterSet?)
|
||||
(define extra-filter (if t (make-TypeFilter t null k) -top))
|
||||
(define (add-extra-filter f)
|
||||
|
@ -37,10 +37,10 @@
|
|||
(subst-filter (add-extra-filter f-) k o polarity))]
|
||||
[_ (-FS -top -top)]))
|
||||
|
||||
(d/c (subst-type t k o polarity)
|
||||
(define/cond-contract (subst-type t k o polarity)
|
||||
(-> Type/c name-ref/c Object? boolean? Type/c)
|
||||
(define (st t) (subst-type t k o polarity))
|
||||
(d/c (sf fs) (FilterSet? . -> . FilterSet?) (subst-filter-set fs k o polarity))
|
||||
(define/cond-contract (sf fs) (FilterSet? . -> . FilterSet?) (subst-filter-set fs k o polarity))
|
||||
(type-case (#:Type st
|
||||
#:Filter sf
|
||||
#:Object (lambda (f) (subst-object f k o polarity)))
|
||||
|
@ -57,7 +57,7 @@
|
|||
(and drest (cons (st (car drest)) (cdr drest)))
|
||||
(map st kws)))]))
|
||||
|
||||
(d/c (subst-object t k o polarity)
|
||||
(define/cond-contract (subst-object t k o polarity)
|
||||
(-> Object? name-ref/c Object? boolean? Object?)
|
||||
(match t
|
||||
[(NoObject:) t]
|
||||
|
@ -72,7 +72,7 @@
|
|||
t)]))
|
||||
|
||||
;; this is the substitution metafunction
|
||||
(d/c (subst-filter f k o polarity)
|
||||
(define/cond-contract (subst-filter f k o polarity)
|
||||
(-> Filter/c name-ref/c Object? boolean? Filter/c)
|
||||
(define (ap f) (subst-filter f k o polarity))
|
||||
(define (tf-matcher t p i k o polarity maker)
|
||||
|
@ -146,7 +146,7 @@
|
|||
|
||||
|
||||
;; (or/c Values? ValuesDots?) listof[identifier] -> tc-results?
|
||||
(d/c (values->tc-results tc formals)
|
||||
(define/cond-contract (values->tc-results tc formals)
|
||||
((or/c Values? ValuesDots?) (or/c #f (listof identifier?)) . -> . tc-results?)
|
||||
(match tc
|
||||
[(ValuesDots: (list (and rs (Result: ts fs os)) ...) dty dbound)
|
||||
|
|
|
@ -89,11 +89,11 @@
|
|||
#'(Mu: var (Union: (list (Value: '()) (MPair: elem-pat (F: var)))))])))
|
||||
|
||||
|
||||
(d/c (-result t [f -no-filter] [o -no-obj])
|
||||
(define/cond-contract (-result t [f -no-filter] [o -no-obj])
|
||||
(c:->* (Type/c) (FilterSet? Object?) Result?)
|
||||
(make-Result t f o))
|
||||
|
||||
(d/c (-values args)
|
||||
(define/cond-contract (-values args)
|
||||
(c:-> (listof Type/c) (or/c Type/c Values?))
|
||||
(match args
|
||||
;[(list t) t]
|
||||
|
@ -178,7 +178,7 @@
|
|||
(define -no-obj (make-Empty))
|
||||
|
||||
|
||||
(d/c (-FS + -)
|
||||
(define/cond-contract (-FS + -)
|
||||
(c:-> Filter/c Filter/c FilterSet?)
|
||||
(match* (+ -)
|
||||
[((Bot:) _) (make-FilterSet -bot -top)]
|
||||
|
@ -219,9 +219,9 @@
|
|||
|
||||
(define top-func (make-Function (list (make-top-arr))))
|
||||
|
||||
(d/c (make-arr* dom rng
|
||||
#:rest [rest #f] #:drest [drest #f] #:kws [kws null]
|
||||
#:filters [filters -no-filter] #:object [obj -no-obj])
|
||||
(define/cond-contract (make-arr* dom rng
|
||||
#:rest [rest #f] #:drest [drest #f] #:kws [kws null]
|
||||
#:filters [filters -no-filter] #:object [obj -no-obj])
|
||||
(c:->* ((listof Type/c) (or/c Values? ValuesDots? Type/c))
|
||||
(#:rest (or/c #f Type/c)
|
||||
#:drest (or/c #f (cons/c Type/c symbol?))
|
||||
|
@ -305,13 +305,13 @@
|
|||
(define (-struct name parent flds constructor [proc #f] [poly #f] [pred #'dummy] [cert values])
|
||||
(make-Struct name parent flds proc poly pred cert constructor))
|
||||
|
||||
(d/c (-filter t i [p null])
|
||||
(define/cond-contract (-filter t i [p null])
|
||||
(c:->* (Type/c name-ref/c) ((listof PathElem?)) Filter/c)
|
||||
(if (or (type-equal? Univ t) (and (identifier? i) (is-var-mutated? i)))
|
||||
-top
|
||||
(make-TypeFilter t p i)))
|
||||
|
||||
(d/c (-not-filter t i [p null])
|
||||
(define/cond-contract (-not-filter t i [p null])
|
||||
(c:->* (Type/c name-ref/c) ((listof PathElem?)) Filter/c)
|
||||
(if (or (type-equal? (make-Union null) t) (and (identifier? i) (is-var-mutated? i)))
|
||||
-top
|
||||
|
@ -329,7 +329,7 @@
|
|||
(define (asym-pred dom rng filter)
|
||||
(make-Function (list (make-arr* (list dom) rng #:filters filter))))
|
||||
|
||||
(d/c make-pred-ty
|
||||
(define/cond-contract make-pred-ty
|
||||
(case-> (c:-> Type/c Type/c)
|
||||
(c:-> (listof Type/c) Type/c Type/c Type/c)
|
||||
(c:-> (listof Type/c) Type/c Type/c integer? Type/c)
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
;; compact : (Listof prop) bool -> (Listof prop)
|
||||
;; props : propositions to compress
|
||||
;; or? : is this an OrFilter (alternative is AndFilter)
|
||||
(d/c (compact props or?)
|
||||
(define/cond-contract (compact props or?)
|
||||
((listof Filter/c) boolean? . --> . (listof Filter/c))
|
||||
(define tf-map (make-hash))
|
||||
(define ntf-map (make-hash))
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
scheme/contract)
|
||||
|
||||
(provide resolve-name resolve-app needs-resolving? resolve)
|
||||
(p/c [resolve-once (Type/c . -> . (or/c Type/c #f))])
|
||||
(provide/cond-contract [resolve-once (Type/c . -> . (or/c Type/c #f))])
|
||||
|
||||
(define-struct poly (name vars) #:prefab)
|
||||
|
||||
|
|
|
@ -12,17 +12,17 @@
|
|||
(struct-out t-subst) (struct-out i-subst) (struct-out i-subst/starred) (struct-out i-subst/dotted)
|
||||
substitution/c make-simple-substitution)
|
||||
|
||||
(d-s/c subst-rhs () #:transparent)
|
||||
(d-s/c (t-subst subst-rhs) ([type Type/c]) #:transparent)
|
||||
(d-s/c (i-subst subst-rhs) ([types (listof Type/c)]) #:transparent)
|
||||
(d-s/c (i-subst/starred subst-rhs) ([types (listof Type/c)] [starred Type/c]) #:transparent)
|
||||
(d-s/c (i-subst/dotted subst-rhs) ([types (listof Type/c)] [dty Type/c] [dbound symbol?]) #:transparent)
|
||||
(define-struct/cond-contract subst-rhs () #:transparent)
|
||||
(define-struct/cond-contract (t-subst subst-rhs) ([type Type/c]) #:transparent)
|
||||
(define-struct/cond-contract (i-subst subst-rhs) ([types (listof Type/c)]) #:transparent)
|
||||
(define-struct/cond-contract (i-subst/starred subst-rhs) ([types (listof Type/c)] [starred Type/c]) #:transparent)
|
||||
(define-struct/cond-contract (i-subst/dotted subst-rhs) ([types (listof Type/c)] [dty Type/c] [dbound symbol?]) #:transparent)
|
||||
|
||||
(define substitution/c (hash/c symbol? subst-rhs? #:immutable #t))
|
||||
|
||||
(define (subst v t e) (substitute t v e))
|
||||
|
||||
(d/c (make-simple-substitution vs ts)
|
||||
(define/cond-contract (make-simple-substitution vs ts)
|
||||
(([vs (listof symbol?)] [ts (listof Type/c)]) ()
|
||||
#:pre (vs ts) (= (length vs) (length ts))
|
||||
. ->i . [_ substitution/c])
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
|
||||
;; substitute : Type Name Type -> Type
|
||||
(d/c (substitute image name target #:Un [Un (get-union-maker)])
|
||||
(define/cond-contract (substitute image name target #:Un [Un (get-union-maker)])
|
||||
((Type/c symbol? Type?) (#:Un procedure?) . ->* . Type?)
|
||||
(define (sb t) (substitute image name t))
|
||||
(if (hash-ref (free-vars* target) name #f)
|
||||
|
@ -64,7 +64,7 @@
|
|||
|
||||
;; implements angle bracket substitution from the formalism
|
||||
;; substitute-dots : Listof[Type] Option[type] Name Type -> Type
|
||||
(d/c (substitute-dots images rimage name target)
|
||||
(define/cond-contract (substitute-dots images rimage name target)
|
||||
((listof Type/c) (or/c #f Type/c) symbol? Type? . -> . Type?)
|
||||
(define (sb t) (substitute-dots images rimage name t))
|
||||
(if (or (hash-ref (free-idxs* target) name #f) (hash-ref (free-vars* target) name #f))
|
||||
|
@ -140,7 +140,7 @@
|
|||
;; substitute many variables
|
||||
;; substitution = Listof[U List[Name,Type] List[Name,Listof[Type]]]
|
||||
;; subst-all : substitution Type -> Type
|
||||
(d/c (subst-all s t)
|
||||
(define/cond-contract (subst-all s t)
|
||||
(substitution/c Type? . -> . Type?)
|
||||
(for/fold ([t t]) ([(v r) (in-hash s)])
|
||||
(match r
|
||||
|
|
|
@ -184,7 +184,7 @@
|
|||
|
||||
;(trace subtypes*/varargs)
|
||||
|
||||
(d/c (combine-arrs arrs)
|
||||
(define/cond-contract (combine-arrs arrs)
|
||||
(c-> (listof arr?) (or/c #f arr?))
|
||||
(match arrs
|
||||
[(list (and a1 (arr: dom1 rng1 #f #f '())) (arr: dom rng #f #f '()) ...)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
(define (reset-type-table) (set! table (make-hasheq)))
|
||||
|
||||
(define (add-typeof-expr e t)
|
||||
(define (add-typeof-expr e t)
|
||||
(when (optimize?)
|
||||
(hash-set! table e t)))
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
(define (add-struct-fn! id pe mut?) (dict-set! struct-fn-table id (list pe mut?)))
|
||||
|
||||
(define-values (struct-accessor? struct-mutator?)
|
||||
(define-values (struct-accessor? struct-mutator?)
|
||||
(let ()
|
||||
(define ((mk mut?) id)
|
||||
(cond [(dict-ref struct-fn-table id #f)
|
||||
|
@ -48,7 +48,7 @@
|
|||
#:when (bound-in-this-module k))
|
||||
(match v
|
||||
[(list pe mut?)
|
||||
#`(add-struct-fn! (quote-syntax #,k)
|
||||
#`(add-struct-fn! (quote-syntax #,k)
|
||||
#,(print-convert pe)
|
||||
#,mut?)])))))
|
||||
|
||||
|
@ -70,17 +70,18 @@
|
|||
(eq? t? (hash-ref tautology-contradiction-table e 'not-there)))
|
||||
(values (mk 'tautology) (mk 'contradiction) (mk 'neither))))
|
||||
|
||||
(p/c [add-typeof-expr (syntax? tc-results? . -> . any/c)]
|
||||
[type-of (syntax? . -> . tc-results?)]
|
||||
[reset-type-table (-> any/c)]
|
||||
[add-struct-fn! (identifier? StructPE? boolean? . -> . any/c)]
|
||||
[struct-accessor? (identifier? . -> . (or/c #f StructPE?))]
|
||||
[struct-mutator? (identifier? . -> . (or/c #f StructPE?))]
|
||||
[struct-fn-idx (identifier? . -> . exact-integer?)]
|
||||
[make-struct-table-code (-> syntax?)]
|
||||
[add-tautology (syntax? . -> . any/c)]
|
||||
[add-contradiction (syntax? . -> . any/c)]
|
||||
[add-neither (syntax? . -> . any/c)]
|
||||
[tautology? (syntax? . -> . boolean?)]
|
||||
[contradiction? (syntax? . -> . boolean?)]
|
||||
[neither? (syntax? . -> . boolean?)])
|
||||
(provide/cond-contract
|
||||
[add-typeof-expr (syntax? tc-results? . -> . any/c)]
|
||||
[type-of (syntax? . -> . tc-results?)]
|
||||
[reset-type-table (-> any/c)]
|
||||
[add-struct-fn! (identifier? StructPE? boolean? . -> . any/c)]
|
||||
[struct-accessor? (identifier? . -> . (or/c #f StructPE?))]
|
||||
[struct-mutator? (identifier? . -> . (or/c #f StructPE?))]
|
||||
[struct-fn-idx (identifier? . -> . exact-integer?)]
|
||||
[make-struct-table-code (-> syntax?)]
|
||||
[add-tautology (syntax? . -> . any/c)]
|
||||
[add-contradiction (syntax? . -> . any/c)]
|
||||
[add-neither (syntax? . -> . any/c)]
|
||||
[tautology? (syntax? . -> . boolean?)]
|
||||
[contradiction? (syntax? . -> . boolean?)]
|
||||
[neither? (syntax? . -> . boolean?)])
|
||||
|
|
|
@ -60,8 +60,8 @@
|
|||
|
||||
|
||||
;; this structure represents the result of typechecking an expression
|
||||
(d-s/c tc-result ([t Type/c] [f FilterSet/c] [o Object?]) #:transparent)
|
||||
(d-s/c tc-results ([ts (listof tc-result?)] [drest (or/c (cons/c Type/c symbol?) #f)]) #:transparent)
|
||||
(define-struct/cond-contract tc-result ([t Type/c] [f FilterSet/c] [o Object?]) #:transparent)
|
||||
(define-struct/cond-contract tc-results ([ts (listof tc-result?)] [drest (or/c (cons/c Type/c symbol?) #f)]) #:transparent)
|
||||
|
||||
(define-match-expander tc-result:
|
||||
(syntax-parser
|
||||
|
@ -133,7 +133,7 @@
|
|||
|
||||
;(trace ret)
|
||||
|
||||
(p/c
|
||||
(provide/cond-contract
|
||||
[ret
|
||||
(->i ([t (or/c Type/c (listof Type/c))])
|
||||
([f (t) (if (list? t)
|
||||
|
|
|
@ -163,14 +163,20 @@ at least theoretically.
|
|||
|
||||
|
||||
;; turn contracts on and off - off by default for performance.
|
||||
(provide (for-syntax enable-contracts?) p/c w/c cnt d-s/c d/c d/c/p)
|
||||
(provide (for-syntax enable-contracts?)
|
||||
provide/cond-contract
|
||||
with-cond-contract
|
||||
cond-contracted
|
||||
define-struct/cond-contract
|
||||
define/cond-contract
|
||||
define/cond-contract/provide)
|
||||
|
||||
(define-syntax-rule (d/c/p (name . args) c . body)
|
||||
(begin (d/c (name . args) c . body)
|
||||
(p/c [name c])))
|
||||
(define-syntax-rule (define/cond-contract/provide (name . args) c . body)
|
||||
(begin (define/cond-contract (name . args) c . body)
|
||||
(provide/cond-contract [name c])))
|
||||
|
||||
;; these are versions of the contract forms conditionalized by `enable-contracts?'
|
||||
(define-syntax p/c
|
||||
(define-syntax provide/cond-contract
|
||||
(if enable-contracts?
|
||||
(make-rename-transformer #'provide/contract)
|
||||
(lambda (stx)
|
||||
|
@ -186,17 +192,17 @@ at least theoretically.
|
|||
[(_ c:clause ...)
|
||||
#'(provide c.i ...)]))))
|
||||
|
||||
(define-syntax w/c
|
||||
(define-syntax with-cond-contract
|
||||
(if enable-contracts?
|
||||
(make-rename-transformer #'with-contract)
|
||||
(lambda (stx)
|
||||
(lambda (stx)
|
||||
(syntax-parse stx
|
||||
[(_ name (~or #:results #:result) spec . body)
|
||||
#'(let () . body)]
|
||||
[(_ name specs . body)
|
||||
#'(begin . body)]))))
|
||||
|
||||
(define-syntax d/c
|
||||
(define-syntax define/cond-contract
|
||||
(if enable-contracts?
|
||||
(make-rename-transformer #'define/contract)
|
||||
(lambda (stx)
|
||||
|
@ -204,14 +210,14 @@ at least theoretically.
|
|||
[(_ head cnt . body)
|
||||
#'(define head . body)]))))
|
||||
|
||||
(define-syntax d-s/c
|
||||
(define-syntax define-struct/cond-contract
|
||||
(if enable-contracts?
|
||||
(make-rename-transformer #'define-struct/contract)
|
||||
(syntax-rules ()
|
||||
[(_ hd ([i c] ...) . opts)
|
||||
(define-struct hd (i ...) . opts)])))
|
||||
|
||||
(define-signature-form (cnt stx)
|
||||
(define-signature-form (cond-contracted stx)
|
||||
(syntax-case stx ()
|
||||
[(_ nm cnt)
|
||||
(if enable-contracts?
|
||||
|
|
Loading…
Reference in New Issue
Block a user