Fix up subst-gen to treat vars and idxs separately.

This commit is contained in:
Stevie Strickland 2010-06-04 14:13:03 -04:00 committed by Sam Tobin-Hochstadt
parent d886331807
commit ec09139e0a

View File

@ -465,20 +465,21 @@
(d/c (subst-gen C R) (d/c (subst-gen C R)
(cset? Type? . -> . (or/c #f list?)) (cset? Type? . -> . (or/c #f list?))
;; fixme - should handle these separately (define var-hash (free-vars* R))
(define must-vars (append (fv R) (fi R))) (define idx-hash (free-idxs* R))
(define (constraint->type v #:variable [variable #f]) ;; v : Symbol - variable for which to check variance
;; h : (Hash Symbol Variance) - hash to check variance in (either var or idx hash)
;; variable: Symbol - variable to use instead, if v was a temp var for idx extension
(define (constraint->type v h #:variable [variable #f])
(match v (match v
[(struct c (S X T)) [(struct c (S X T))
;; fixme - handle free indexes, remove Dotted (let ([var (hash-ref h (or variable X) Constant)])
(let ([var (hash-ref (free-vars* R) (or variable X) (λ () (hash-ref (free-idxs* R) (or variable X) Constant)))])
;(printf "variance was: ~a~nR was ~a~nX was ~a~nS T ~a ~a~n" var R (or variable X) S T) ;(printf "variance was: ~a~nR was ~a~nX was ~a~nS T ~a ~a~n" var R (or variable X) S T)
(evcase var (evcase var
[Constant S] [Constant S]
[Covariant S] [Covariant S]
[Contravariant T] [Contravariant T]
[Invariant S] [Invariant S]))]))
[Dotted T]))]))
(match (car (cset-maps C)) (match (car (cset-maps C))
[(cons cmap (dmap dm)) [(cons cmap (dmap dm))
(let ([subst (append (let ([subst (append
@ -487,18 +488,27 @@
[(dcon fixed rest) [(dcon fixed rest)
(list k (list k
(for/list ([f fixed]) (for/list ([f fixed])
(constraint->type f #:variable k)) (constraint->type f idx-hash #:variable k))
(and rest (constraint->type rest)))] (and rest (constraint->type rest idx-hash)))]
[(dcon-exact fixed rest) [(dcon-exact fixed rest)
(list k (list k
(for/list ([f fixed]) (for/list ([f fixed])
(constraint->type f #:variable k)) (constraint->type f idx-hash #:variable k))
(constraint->type rest))])) (constraint->type rest idx-hash))]))
(for/list ([(k v) (in-hash cmap)]) (for/list ([(k v) (in-hash cmap)])
(list k (constraint->type v))))]) (list k (constraint->type v var-hash))))])
;; verify that we got all the important variables ;; verify that we got all the important variables
(and (for/and ([v must-vars]) (and (for/and ([v (fv R)])
(assq v subst)) (let ([entry (assq v subst)])
;; Make sure we got a subst entry for a type var
;; (i.e. just a type to substitute)
(and entry (= (length entry) 2))))
(for/and ([v (fi R)])
(let ([entry (assq v subst)])
;; Make sure we got a subst entry for an index var
;; (i.e. a list of types for the fixed portion
;; and a type for the starred portion)
(and entry (= (length entry) 3))))
subst))])) subst))]))
;; V : a set of variables not to mention in the constraints ;; V : a set of variables not to mention in the constraints