Add filter to AnyValues.
This commit is contained in:
parent
0c5c6f50c1
commit
fac2f05a6d
|
@ -400,7 +400,19 @@
|
||||||
[(a b) #:when (type-equal? a b) empty]
|
[(a b) #:when (type-equal? a b) empty]
|
||||||
;; CG-Top
|
;; CG-Top
|
||||||
[(_ (Univ:)) empty]
|
[(_ (Univ:)) empty]
|
||||||
[(_ (AnyValues:)) empty]
|
;; AnyValues
|
||||||
|
[((AnyValues: s-f) (AnyValues: t-f))
|
||||||
|
(cgen/filter V X Y s-f t-f)]
|
||||||
|
|
||||||
|
[((or (Values: (list (Result: _ fs _) ...))
|
||||||
|
(ValuesDots: (list (Result: _ fs _) ...) _ _))
|
||||||
|
(AnyValues: t-f))
|
||||||
|
(cset-join
|
||||||
|
(filter identity
|
||||||
|
(for/list ([f (in-list fs)])
|
||||||
|
(match f
|
||||||
|
[(FilterSet: f+ f-)
|
||||||
|
(% cset-meet (cgen/filter V X Y f+ t-f) (cgen/filter V X Y f- t-f))]))))]
|
||||||
|
|
||||||
;; check all non Type/c first so that calling subtype is safe
|
;; check all non Type/c first so that calling subtype is safe
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
;; extract filters out of the range of a function type
|
;; extract filters out of the range of a function type
|
||||||
(define (get-filters rng)
|
(define (get-filters rng)
|
||||||
(match rng
|
(match rng
|
||||||
[(AnyValues:) null]
|
[(AnyValues: f) (list (-FS f f))]
|
||||||
[(Values: (list (Result: _ lf _) ...)) lf]
|
[(Values: (list (Result: _ lf _) ...)) lf]
|
||||||
[(ValuesDots: (list (Result: _ lf _) ...) _ _) lf]))
|
[(ValuesDots: (list (Result: _ lf _) ...) _ _) lf]))
|
||||||
|
|
||||||
|
|
|
@ -292,7 +292,7 @@
|
||||||
[#:fold-rhs (*Values (map type-rec-id rs))])
|
[#:fold-rhs (*Values (map type-rec-id rs))])
|
||||||
|
|
||||||
|
|
||||||
(def-type AnyValues ()
|
(def-type AnyValues ([f Filter/c])
|
||||||
[#:fold-rhs #:base])
|
[#:fold-rhs #:base])
|
||||||
|
|
||||||
(def-type ValuesDots ([rs (listof Result?)] [dty Type/c] [dbound (or/c symbol? natural-number/c)])
|
(def-type ValuesDots ([rs (listof Result?)] [dty Type/c] [dbound (or/c symbol? natural-number/c)])
|
||||||
|
|
|
@ -50,7 +50,8 @@
|
||||||
[ta (in-sequence-forever (in-list t-a) #f)])
|
[ta (in-sequence-forever (in-list t-a) #f)])
|
||||||
(values oa ta))])
|
(values oa ta))])
|
||||||
(match rng
|
(match rng
|
||||||
[(AnyValues:) tc-any-results]
|
;; TODO add filters to tc-any-results
|
||||||
|
[(AnyValues: f) tc-any-results]
|
||||||
[(Values: results)
|
[(Values: results)
|
||||||
(define-values (t-r f-r o-r)
|
(define-values (t-r f-r o-r)
|
||||||
(for/lists (t-r f-r o-r)
|
(for/lists (t-r f-r o-r)
|
||||||
|
@ -248,7 +249,7 @@
|
||||||
(map (compose make-Function list make-arr)
|
(map (compose make-Function list make-arr)
|
||||||
doms
|
doms
|
||||||
(map (match-lambda ; strip filters
|
(map (match-lambda ; strip filters
|
||||||
[(AnyValues:) ManyUniv]
|
[(AnyValues: f) (-AnyValues f)]
|
||||||
[(Values: (list (Result: t _ _) ...))
|
[(Values: (list (Result: t _ _) ...))
|
||||||
(-values t)]
|
(-values t)]
|
||||||
[(ValuesDots: (list (Result: t _ _) ...) _ _)
|
[(ValuesDots: (list (Result: t _ _) ...) _ _)
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
(tc-results/c (listof identifier?) . -> . SomeValues/c)
|
(tc-results/c (listof identifier?) . -> . SomeValues/c)
|
||||||
(define keys (for/list ([(nm k) (in-indexed arg-names)]) (list 0 k)))
|
(define keys (for/list ([(nm k) (in-indexed arg-names)]) (list 0 k)))
|
||||||
(match results
|
(match results
|
||||||
[(tc-any-results:) (make-AnyValues)]
|
[(tc-any-results:) ManyUniv]
|
||||||
[(tc-results: ts fs os dty dbound)
|
[(tc-results: ts fs os dty dbound)
|
||||||
(make-ValuesDots
|
(make-ValuesDots
|
||||||
(for/list ([t (in-list ts)] [f (in-list fs)] [o (in-list os)])
|
(for/list ([t (in-list ts)] [f (in-list fs)] [o (in-list os)])
|
||||||
|
|
|
@ -165,7 +165,8 @@
|
||||||
(define/cond-contract (values->tc-results tc formals)
|
(define/cond-contract (values->tc-results tc formals)
|
||||||
(SomeValues/c (or/c #f (listof identifier?)) . -> . tc-results/c)
|
(SomeValues/c (or/c #f (listof identifier?)) . -> . tc-results/c)
|
||||||
(match tc
|
(match tc
|
||||||
[(AnyValues:) tc-any-results]
|
;; TODO make tc-any-results have a filter
|
||||||
|
[(AnyValues: f) tc-any-results]
|
||||||
[(ValuesDots: (list (and rs (Result: ts fs os)) ...) dty dbound)
|
[(ValuesDots: (list (and rs (Result: ts fs os)) ...) dty dbound)
|
||||||
(if formals
|
(if formals
|
||||||
(let-values ([(ts fs os)
|
(let-values ([(ts fs os)
|
||||||
|
|
|
@ -40,10 +40,6 @@
|
||||||
(define/decl -False (make-Value #f))
|
(define/decl -False (make-Value #f))
|
||||||
(define/decl -True (make-Value #t))
|
(define/decl -True (make-Value #t))
|
||||||
|
|
||||||
;; A Type that corresponds to the any contract for the
|
|
||||||
;; return type of functions
|
|
||||||
(define/decl ManyUniv (make-AnyValues))
|
|
||||||
|
|
||||||
(define -val make-Value)
|
(define -val make-Value)
|
||||||
|
|
||||||
;; Char type and List type (needed because of how sequences are checked in subtype)
|
;; Char type and List type (needed because of how sequences are checked in subtype)
|
||||||
|
@ -160,6 +156,11 @@
|
||||||
[(Path: p i) (-not-filter t i p)]
|
[(Path: p i) (-not-filter t i p)]
|
||||||
[_ -top]))
|
[_ -top]))
|
||||||
|
|
||||||
|
;; A Type that corresponds to the any contract for the
|
||||||
|
;; return type of functions
|
||||||
|
(define (-AnyValues f) (make-AnyValues f))
|
||||||
|
(define/decl ManyUniv (make-AnyValues -top))
|
||||||
|
|
||||||
;; Function types
|
;; Function types
|
||||||
(define/cond-contract (make-arr* dom rng
|
(define/cond-contract (make-arr* dom rng
|
||||||
#:rest [rest #f] #:drest [drest #f] #:kws [kws null]
|
#:rest [rest #f] #:drest [drest #f] #:kws [kws null]
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
;; keyword conversion.
|
;; keyword conversion.
|
||||||
(define (erase-filter/Values values)
|
(define (erase-filter/Values values)
|
||||||
(match values
|
(match values
|
||||||
[(AnyValues:) values]
|
[(AnyValues: _) ManyUniv]
|
||||||
[(Results: ts fs os)
|
[(Results: ts fs os)
|
||||||
(-values ts)]
|
(-values ts)]
|
||||||
[(Results: ts fs os dty dbound)
|
[(Results: ts fs os dty dbound)
|
||||||
|
|
|
@ -239,7 +239,8 @@
|
||||||
(cdr drest)))
|
(cdr drest)))
|
||||||
null)
|
null)
|
||||||
(match rng
|
(match rng
|
||||||
[(AnyValues:) '(AnyValues)]
|
[(AnyValues: (Top:)) '(AnyValues)]
|
||||||
|
[(AnyValues: f) `(AnyValues : ,(type->sexp f))]
|
||||||
[(Values: (list (Result: t (FilterSet: (Top:) (Top:)) (Empty:))))
|
[(Values: (list (Result: t (FilterSet: (Top:) (Top:)) (Empty:))))
|
||||||
(list (type->sexp t))]
|
(list (type->sexp t))]
|
||||||
[(Values: (list (Result: t
|
[(Values: (list (Result: t
|
||||||
|
@ -478,7 +479,8 @@
|
||||||
`(List ,(t->s dty) ,@dbound*)]
|
`(List ,(t->s dty) ,@dbound*)]
|
||||||
[(F: nm) nm]
|
[(F: nm) nm]
|
||||||
;; FIXME (Values are not types and shouldn't need to be considered here
|
;; FIXME (Values are not types and shouldn't need to be considered here
|
||||||
[(AnyValues:) 'AnyValues]
|
[(AnyValues: (Top:)) 'AnyValues]
|
||||||
|
[(AnyValues: f) `(AnyValues : ,(filter->sexp f))]
|
||||||
[(Values: (list v)) v]
|
[(Values: (list v)) v]
|
||||||
[(Values: (list v ...)) (cons 'values (map t->s v))]
|
[(Values: (list v ...)) (cons 'values (map t->s v))]
|
||||||
[(ValuesDots: v dty dbound)
|
[(ValuesDots: v dty dbound)
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
;; Non Types
|
;; Non Types
|
||||||
[Result (#:co #:co #:co)]
|
[Result (#:co #:co #:co)]
|
||||||
[Values ((#:listof #:co))]
|
[Values ((#:listof #:co))]
|
||||||
[AnyValues ()]))
|
[AnyValues (#:co)]))
|
||||||
|
|
||||||
(begin-for-syntax
|
(begin-for-syntax
|
||||||
(define-syntax-class type-name
|
(define-syntax-class type-name
|
||||||
|
|
|
@ -256,7 +256,6 @@
|
||||||
;; these cases are above as special cases
|
;; these cases are above as special cases
|
||||||
;; [((Union: (list)) _) A0] ;; this is extremely common, so it goes first
|
;; [((Union: (list)) _) A0] ;; this is extremely common, so it goes first
|
||||||
;; [(_ (Univ:)) A0]
|
;; [(_ (Univ:)) A0]
|
||||||
[((or (ValuesDots: _ _ _) (Values: _) (AnyValues:)) (AnyValues:)) A0]
|
|
||||||
;; error is top and bot
|
;; error is top and bot
|
||||||
[(_ (Error:)) A0]
|
[(_ (Error:)) A0]
|
||||||
[((Error:) _) A0]
|
[((Error:) _) A0]
|
||||||
|
@ -556,6 +555,15 @@
|
||||||
(subtype-seq A0
|
(subtype-seq A0
|
||||||
(subtypes* s-rs t-rs)
|
(subtypes* s-rs t-rs)
|
||||||
(subtype* s-dty t-dty))]
|
(subtype* s-dty t-dty))]
|
||||||
|
[((AnyValues: s-f) (AnyValues: t-f))
|
||||||
|
(filter-subtype* A0 s-f t-f)]
|
||||||
|
[((or (Values: (list (Result: _ fs _) ...))
|
||||||
|
(ValuesDots: (list (Result: _ fs _) ...) _ _))
|
||||||
|
(AnyValues: t-f))
|
||||||
|
(for/or ([f (in-list fs)])
|
||||||
|
(match f
|
||||||
|
[(FilterSet: f+ f-)
|
||||||
|
(and (filter-subtype* A0 f+ t-f) (filter-subtype* A0 f+ t-f) A0)]))]
|
||||||
[((Result: t (FilterSet: ft ff) o) (Result: t* (FilterSet: ft* ff*) o))
|
[((Result: t (FilterSet: ft ff) o) (Result: t* (FilterSet: ft* ff*) o))
|
||||||
(subtype-seq A0
|
(subtype-seq A0
|
||||||
(subtype* t t*)
|
(subtype* t t*)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user