Remove tc-results? and other minor improvements.

This commit is contained in:
Eric Dobson 2013-01-20 14:49:06 -08:00 committed by Sam Tobin-Hochstadt
parent 5a43a5c730
commit a2f33f17e9
12 changed files with 57 additions and 46 deletions

View File

@ -2028,7 +2028,9 @@
(-> (-> b) Univ)))] (-> (-> b) Univ)))]
[abort-current-continuation [abort-current-continuation
(-polydots (a b d e c) (-polydots (a b d e c)
(->... (list (make-Prompt-Tagof b (->... '() (c c) d))) (c c) e))] (cl->*
(->... (list (make-Prompt-Tagof b (->... '() (c c) d))) (c c) e)
(->... (list (make-Prompt-Tagof b (->... '() (c c) ManyUniv))) (c c) e)))]
[make-continuation-prompt-tag [make-continuation-prompt-tag
(-poly (a b) (->opt [Sym] (make-Prompt-Tagof a b)))] (-poly (a b) (->opt [Sym] (make-Prompt-Tagof a b)))]
;; default-continuation-prompt-tag is defined in "base-contracted.rkt" ;; default-continuation-prompt-tag is defined in "base-contracted.rkt"

View File

@ -312,7 +312,7 @@
;; the index variables from the TOPLAS paper ;; the index variables from the TOPLAS paper
(define/cond-contract (cgen V X Y S T) (define/cond-contract (cgen V X Y S T)
((listof symbol?) (listof symbol?) (listof symbol?) ((listof symbol?) (listof symbol?) (listof symbol?)
(or/c Values/c ValuesDots?) (or/c Values/c ValuesDots?). -> . cset?) (or/c Values/c ValuesDots? AnyValues?) (or/c Values/c ValuesDots? AnyValues?) . -> . cset?)
;; useful quick loop ;; useful quick loop
(define/cond-contract (cg S T) (define/cond-contract (cg S T)
(Type/c Type/c . -> . cset?) (Type/c Type/c . -> . cset?)
@ -334,6 +334,7 @@
[(a a) empty] [(a a) empty]
;; CG-Top ;; CG-Top
[(_ (Univ:)) empty] [(_ (Univ:)) empty]
[(_ (AnyValues:)) empty]
;; check all non Type/c first so that calling subtype is safe ;; check all non Type/c first so that calling subtype is safe

View File

@ -21,8 +21,8 @@
(provide/cond-contract [parse-type (syntax? . c:-> . Type/c)] (provide/cond-contract [parse-type (syntax? . c:-> . Type/c)]
[parse-type/id (syntax? c:any/c . c:-> . Type/c)] [parse-type/id (syntax? c:any/c . c:-> . Type/c)]
[parse-tc-results (syntax? . c:-> . tc-results?)] [parse-tc-results (syntax? . c:-> . tc-results/c)]
[parse-tc-results/id (syntax? c:any/c . c:-> . tc-results?)]) [parse-tc-results/id (syntax? c:any/c . c:-> . tc-results/c)])
(provide star ddd/bound) (provide star ddd/bound)
(define enable-mu-parsing (make-parameter #t)) (define enable-mu-parsing (make-parameter #t))

View File

@ -117,6 +117,11 @@
(tc-expr/check expr (ret anns)) (tc-expr/check expr (ret anns))
(let ([ty (tc-expr expr)]) (let ([ty (tc-expr expr)])
(match ty (match ty
[(tc-any-results:)
(ret
(tc-error/expr
"Expression should produce ~a values, but produces an unknown number of values"
(length stxs)))]
[(tc-results: tys fs os) [(tc-results: tys fs os)
(if (not (= (length stxs) (length tys))) (if (not (= (length stxs) (length tys)))
(begin (begin

View File

@ -15,6 +15,30 @@
(define name-table (make-weak-hasheq)) (define name-table (make-weak-hasheq))
(define Type/c?
(λ (e)
(and (Type? e)
(not (Scope? e))
(not (arr? e))
(not (fld? e))
(not (Values? e))
(not (ValuesDots? e))
(not (AnyValues? e))
(not (Result? e)))))
;; (or/c Type/c Values? Results?)
;; Anything that can be treated as a Values by sufficient expansion
(define Values/c?
(λ (e)
(and (Type? e)
(not (Scope? e))
(not (arr? e))
(not (fld? e))
(not (ValuesDots? e))
(not (AnyValues? e)))))
(define Type/c (flat-named-contract 'Type Type/c?))
(define Values/c (flat-named-contract 'Values Values/c?))
;; Name = Symbol ;; Name = Symbol
@ -215,6 +239,8 @@
(combine-frees (map free-idxs* (cons dty rs))))] (combine-frees (map free-idxs* (cons dty rs))))]
[#:fold-rhs (*ValuesDots (map type-rec-id rs) (type-rec-id dty) dbound)]) [#:fold-rhs (*ValuesDots (map type-rec-id rs) (type-rec-id dty) dbound)])
(define SomeValues/c (or/c Values? AnyValues? ValuesDots?))
;; arr is NOT a Type ;; arr is NOT a Type
(def-type arr ([dom (listof Type/c)] (def-type arr ([dom (listof Type/c)]
[rng SomeValues/c] [rng SomeValues/c]
@ -743,31 +769,6 @@
;(trace subst subst-all) ;(trace subst subst-all)
(define Type/c?
(λ (e)
(and (Type? e)
(not (Scope? e))
(not (arr? e))
(not (fld? e))
(not (Values? e))
(not (ValuesDots? e))
(not (AnyValues? e))
(not (Result? e)))))
;; (or/c Type/c Values? Results?)
;; Anything that can be treated as a Values by sufficient expansion
(define Values/c?
(λ (e)
(and (Type? e)
(not (Scope? e))
(not (arr? e))
(not (fld? e))
(not (ValuesDots? e))
(not (AnyValues? e)))))
(define Type/c (flat-named-contract 'Type Type/c?))
(define Values/c (flat-named-contract 'Values Values/c?))
(define SomeValues/c (or/c Values? AnyValues? ValuesDots?))
(provide (provide
Mu-name: Mu-name:

View File

@ -12,8 +12,10 @@
(only-in srfi/1 split-at)) (only-in srfi/1 split-at))
(provide/cond-contract (provide/cond-contract
[check-below (-->d ([s (-or/c Type/c tc-results/c)] [t (-or/c Type/c tc-results/c)]) () [_ (if (Type? s) Type/c tc-results/c)])] [check-below (-->d ([s (-or/c Type/c tc-results/c)] [t (-or/c Type/c tc-results/c)]) ()
[cond-check-below (-->d ([s (-or/c Type/c tc-results/c)] [t (-or/c #f Type/c tc-results/c)]) () [_ (if (Type? s) Type/c tc-results/c)])]) [_ (if (Type/c? s) Type/c tc-results/c)])]
[cond-check-below (-->d ([s (-or/c Type/c tc-results/c)] [t (-or/c #f Type/c tc-results/c)]) ()
[_ (if (Type/c? s) Type/c tc-results/c)])])
(define (print-object o) (define (print-object o)
(match o (match o
@ -103,6 +105,13 @@
(unless (for/and ([t t1] [s t2]) (subtype t s)) (unless (for/and ([t t1] [s t2]) (subtype t s))
(tc-error/expr "Expected ~a, but got ~a" (stringify t2) (stringify t1))) (tc-error/expr "Expected ~a, but got ~a" (stringify t2) (stringify t1)))
expected] expected]
[((tc-any-results:) (or (? Type/c? t) (tc-result1: t _ _)))
(tc-error/expr "Expected 1 value, but got unknown number")
expected]
[((tc-any-results:) (tc-results: t2 fs os))
(tc-error/expr "Expected ~a values, but got unknown number" (length t2))
expected]
[((tc-result1: t1 f o) (? Type/c? t2)) [((tc-result1: t1 f o) (? Type/c? t2))
(unless (subtype t1 t2) (unless (subtype t1 t2)
(tc-error/expr "Expected ~a, but got ~a" t2 t1)) (tc-error/expr "Expected ~a, but got ~a" t2 t1))

View File

@ -27,7 +27,7 @@
;; we just ignore the values, except that it forces arg to return one value ;; we just ignore the values, except that it forces arg to return one value
(pattern (values arg) (pattern (values arg)
(match expected (match expected
[#f (single-value #'arg)] [(or #f (tc-any-results:)) (single-value #'arg)]
[(tc-result1: tp) [(tc-result1: tp)
(single-value #'arg expected)] (single-value #'arg expected)]
[(tc-results: ts) [(tc-results: ts)

View File

@ -242,7 +242,7 @@
(match (find-expected expected f*) (match (find-expected expected f*)
;; very conservative -- only do anything interesting if we get exactly one thing that matches ;; very conservative -- only do anything interesting if we get exactly one thing that matches
[(list) [(list)
(if (and (= 1 (length formals*)) (tc-results? expected)) (if (and (= 1 (length formals*)) (match expected ((tc-results: _) #t) (_ #f)))
(tc-error/expr #:return (list (lam-result null null (list #'here Univ) #f (ret (Un)))) (tc-error/expr #:return (list (lam-result null null (list #'here Univ) #f (ret (Un))))
"Expected a function of type ~a, but got a function with the wrong arity" "Expected a function of type ~a, but got a function with the wrong arity"
(match expected [(tc-result1: t) t])) (match expected [(tc-result1: t) t]))

View File

@ -29,7 +29,7 @@
(define/cond-contract (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 . c:-> . any/c) (((syntax? syntax? tc-results/c . c:-> . any/c)
(listof (listof identifier?)) (listof tc-results?) (listof tc-results?) (listof (listof identifier?)) (listof tc-results/c) (listof tc-results/c)
syntax? (listof syntax?) syntax? (listof syntax?) (or/c #f tc-results/c)) syntax? (listof syntax?) syntax? (listof syntax?) (or/c #f tc-results/c))
(#:abstract any/c) (#:abstract any/c)
. c:->* . . c:->* .
@ -130,7 +130,6 @@
(cond (cond
;; after everything, check the body expressions ;; after everything, check the body expressions
[(null? names) [(null? names)
;(if expected (tc-exprs/check (syntax->list body) expected) (tc-exprs (syntax->list body)))
(do-check void null null null form null body null expected #:abstract orig-flat-names)] (do-check void null null null form null body null expected #:abstract orig-flat-names)]
;; if none of the names bound in the letrec are free vars of this rhs ;; if none of the names bound in the letrec are free vars of this rhs
[(not (ormap (lambda (n) (s:member n flat-names bound-identifier=?)) [(not (ormap (lambda (n) (s:member n flat-names bound-identifier=?))

View File

@ -13,7 +13,7 @@
(define/cond-contract (abstract-results results arg-names) (define/cond-contract (abstract-results results arg-names)
(tc-results? (listof identifier?) . -> . SomeValues/c) (tc-results/c (listof identifier?) . -> . SomeValues/c)
(define keys (for/list ([(nm k) (in-indexed arg-names)]) k)) (define keys (for/list ([(nm k) (in-indexed arg-names)]) k))
(match results (match results
[(tc-any-results:) (make-AnyValues)] [(tc-any-results:) (make-AnyValues)]

View File

@ -17,12 +17,7 @@
;A Type that corresponds to the any contract for the ;A Type that corresponds to the any contract for the
;return type of functions ;return type of functions
;FIXME (define ManyUniv (make-AnyValues))
;This is not correct as Univ is only a single value.
(define ManyUniv Univ)
;; Char type (needed because of how sequences are checked in subtype) ;; Char type (needed because of how sequences are checked in subtype)
(define -Char (make-Base 'Char #'char? char? #'-Char #f)) (define -Char (make-Base 'Char #'char? char? #'-Char #f))

View File

@ -110,7 +110,7 @@
Object?)] Object?)]
[dty Type/c] [dty Type/c]
[dbound symbol?]) [dbound symbol?])
[res tc-results?])]) [res tc-results/c])])
(define (combine-results tcs) (define (combine-results tcs)
(match tcs (match tcs
@ -124,7 +124,6 @@
(tc-any-results* tc-any-results))) (tc-any-results* tc-any-results)))
(provide/cond-contract (provide/cond-contract
[combine-results ((listof tc-results?) . -> . tc-results?)] [combine-results ((listof tc-results?) . -> . tc-results?)]
[tc-result? (any/c . -> . boolean?)]
[tc-result-t (tc-result? . -> . Type/c)] [tc-result-t (tc-result? . -> . Type/c)]
[tc-result-equal? (tc-result? tc-result? . -> . boolean?)] [tc-result-equal? (tc-result? tc-result? . -> . boolean?)]
[tc-results? (any/c . -> . boolean?)] [tc-results? (any/c . -> . boolean?)]