Do substitution properly from dmap.

This commit is contained in:
Sam Tobin-Hochstadt 2008-06-19 18:04:19 -04:00
parent b9e1676a55
commit 0f142d97e3
3 changed files with 29 additions and 18 deletions

View File

@ -319,23 +319,28 @@
[else (fail! S T)])])))) [else (fail! S T)])]))))
(define (subst-gen C R) (define (subst-gen C R)
(for/list ([(k v) (car (car (cset-maps C)))]) (define (constraint->type v #:variable [variable #f])
(match v (match v
[(struct c (S X T)) [(struct c (S X T))
(let ([var (hash-ref (free-vars* R) X Constant)]) (let ([var (hash-ref (free-vars* R) (or variable X) Constant)])
;(printf "variance was: ~a~nR was ~a~n" var R) ;(printf "variance was: ~a~nR was ~a~nX was ~a~n" var R (or variable X))
(list
X
(evcase var (evcase var
[Constant S] [Constant S]
[Covariant S] [Covariant S]
[Contravariant T] [Contravariant T]
[Invariant [Invariant S]))]))
#; ; don't fail, we just pretend in covariance (match (car (cset-maps C))
(unless (type-equal? S T) [(cons cmap (struct dmap (dm)))
;(printf "invariant and not equal ~a ~a" S T) (append
(fail! S T)) (for/list ([(k dc) dm])
S])))]))) (match dc
[(struct dcon (fixed rest))
(list k
(for/list ([f fixed])
(constraint->type f #:variable k))
(and rest (constraint->type rest)))]))
(for/list ([(k v) cmap])
(list k (constraint->type v))))]))
(define (cgen/list X V S T) (define (cgen/list X V S T)
(cset-meet* (for/list ([s S] [t T]) (cgen V X s t)))) (cset-meet* (for/list ([s S] [t T]) (cgen V X s t))))

View File

@ -101,9 +101,9 @@
(dt arr (dom rng rest drest thn-eff els-eff) (dt arr (dom rng rest drest thn-eff els-eff)
[#:frees (combine-frees (append (map flip-variances (map free-vars* (append (if rest (list rest) null) dom))) [#:frees (combine-frees (append (map flip-variances (map free-vars* (append (if rest (list rest) null) dom)))
(match drest (match drest
[(cons t (? symbol? bnd)) #;[(cons t (? symbol? bnd))
(let ([vs (free-vars* t)]) (let ([vs (free-vars* t)])
(list (flip-variances (fix-bound vs bnd))))] (list (flip-variances vs)))]
[(cons t bnd) (list (flip-variances (free-vars* t)))] [(cons t bnd) (list (flip-variances (free-vars* t)))]
[_ null]) [_ null])
(list (free-vars* rng)) (list (free-vars* rng))
@ -111,9 +111,9 @@
(map free-vars* (append thn-eff els-eff))))) (map free-vars* (append thn-eff els-eff)))))
(combine-frees (append (map flip-variances (map free-idxs* (append (if rest (list rest) null) dom))) (combine-frees (append (map flip-variances (map free-idxs* (append (if rest (list rest) null) dom)))
(match drest (match drest
[(cons t (? number? bnd)) #;[(cons t (? number? bnd))
(let ([vs (free-idxs* t)]) (let ([vs (free-idxs* t)])
(list (flip-variances (fix-bound vs bnd))))] (list (flip-variances vs)))]
[(cons t bnd) (list (flip-variances (free-idxs* t)))] [(cons t bnd) (list (flip-variances (free-idxs* t)))]
[_ null]) [_ null])
(list (free-idxs* rng)) (list (free-idxs* rng))

View File

@ -54,7 +54,6 @@
(define (sb t) (substitute-dots images name t)) (define (sb t) (substitute-dots images name t))
(if (hash-ref (free-vars* target) name #f) (if (hash-ref (free-vars* target) name #f)
(type-case sb target (type-case sb target
[#:F name* target]
[#:arr dom rng rest drest thn-eff els-eff [#:arr dom rng rest drest thn-eff els-eff
(if (and (pair? drest) (if (and (pair? drest)
(eq? name (cdr drest))) (eq? name (cdr drest)))
@ -101,7 +100,14 @@
;; substitution = Listof[List[Name,Type]] ;; substitution = Listof[List[Name,Type]]
;; subst-all : substition Type -> Type ;; subst-all : substition Type -> Type
(define (subst-all s t) (define (subst-all s t)
(foldr (lambda (e acc) (substitute (cadr e) (car e) acc)) t s)) (for/fold ([t t]) ([e s])
(match e
[(list v (list imgs ...) #f)
(substitute-dots imgs v t)]
[(list v (list ts) starred)
(int-err "subst-all: nyi")]
[(list v img)
(substitute img v t)])))
;; unfold : Type -> Type ;; unfold : Type -> Type