Simplify Name type representation

Avoids contract errors by using a simpler representation
and sticking with it throughout.
This commit is contained in:
Asumu Takikawa 2015-04-08 03:24:50 -04:00
parent d22bf8cc11
commit 7bf4314af4
9 changed files with 17 additions and 22 deletions

View File

@ -180,7 +180,7 @@
#:attributes (poly-vars)
(pattern (All (arg:id ...) rest)
#:with poly-vars #'(arg ...))
(pattern type:expr #:with poly-vars #'#f))
(pattern type:expr #:with poly-vars #'()))
(define-splicing-syntax-class omit-define-syntaxes
#:attributes (omit)

View File

@ -80,10 +80,7 @@
[(Union: elems) (split-union elems)]
[(Base: n cnt pred _) (int-err "Base type ~a not in predefined-type-table" n)]
[(Name: stx args struct?)
`(make-Name (quote-syntax ,stx)
,(and args
`(list ,@(map (λ (x) `(quote-syntax ,x)) args)))
,struct?)]
`(make-Name (quote-syntax ,stx) ,args ,struct?)]
[(fld: t acc mut) `(make-fld ,(sub t) (quote-syntax ,acc) ,mut)]
[(Struct: name parent flds proc poly? pred-id)
`(make-Struct (quote-syntax ,name) ,(sub parent)

View File

@ -189,7 +189,7 @@
(for/list ([id (in-list recursive-aliases)])
(define record (dict-ref type-alias-map id))
(match-define (list _ args) record)
(define name-type (make-Name id args #f))
(define name-type (make-Name id (length args) #f))
(register-resolved-type-alias id name-type)
;; The `(make-placeholder-type id)` expression is used to make sure
;; that unions don't collapse the aliases too soon. This is a dummy
@ -199,9 +199,9 @@
;; because dummy values will leak due to environment serialization.
(register-type-name
id
(if args
(make-Poly (map syntax-e args) (make-placeholder-type id))
(make-placeholder-type id)))
(if (null? args)
(make-placeholder-type id)
(make-Poly (map syntax-e args) (make-placeholder-type id))))
name-type))
;; Register non-recursive type aliases
@ -240,7 +240,7 @@
;; Finally, do a last pass to refine the variance
(refine-variance! names-to-refine types-to-refine tvarss))
;; Syntax -> Syntax Syntax Syntax Option<Integer>
;; Syntax -> Syntax Syntax (Listof Syntax)
;; Parse a type alias internal declaration
(define (parse-type-alias form)
(syntax-parse form

View File

@ -64,7 +64,7 @@
(when (lookup-type-name to (lambda () #f))
(register-resolved-type-alias
from
(make-Name to #f #t))))
(make-Name to 0 #t))))
;; a mapping from id -> listof[Variance] (where id is the name of the type)

View File

@ -122,10 +122,10 @@
;; A type name, potentially recursive or mutually recursive or pointing
;; to a type for a struct type
;; id is the name stored in the environment
;; args are the type parameters for this type (or #f if none)
;; args is the number of arguments expected by this Name type
;; struct? indicates if this maps to a struct type
(def-type Name ([id identifier?]
[args (or/c #f (listof identifier?))]
[args exact-nonnegative-integer?]
[struct? boolean?])
[#:intern (hash-id id)] [#:frees #f] [#:fold-rhs #:base])

View File

@ -127,7 +127,7 @@
(define type-name (struct-names-type-name names))
(register-resolved-type-alias
type-name
(make-Name type-name (struct-desc-tvars desc) (Struct? sty)))
(make-Name type-name (length (struct-desc-tvars desc)) (Struct? sty)))
(register-type-name type-name
(make-Poly (struct-desc-tvars desc) sty)))
@ -148,8 +148,7 @@
;; the base-type, with free type variables
(define name-type
(make-Name (struct-names-type-name names)
#f #t))
(make-Name (struct-names-type-name names) 0 #t))
(define poly-base
(if (null? tvars)
name-type
@ -308,7 +307,7 @@
(c:listof Type/c) (c:or/c #f identifier?)
c:any/c)
(define parent-type
(and parent (resolve-name (make-Name parent #f #t))))
(and parent (resolve-name (make-Name parent 0 #t))))
(define parent-tys (map fld-t (get-flds parent-type)))
(define names (get-struct-names nm fld-names #f))

View File

@ -303,7 +303,7 @@
(type-vars (map type-vars-of-struct struct-defs)))
(for ([name names])
(register-resolved-type-alias
name (make-Name name #f #t)))
name (make-Name name 0 #t)))
(for-each register-type-name names)
(for-each add-constant-variance! names type-vars))
(do-time "after adding type names")

View File

@ -248,7 +248,7 @@
;; Type alias names
(define (-struct-name name)
(make-Name name #f #t))
(make-Name name 0 #t))
;; Structs
(define (-struct name parent flds [proc #f] [poly #f] [pred #'dummy])

View File

@ -60,10 +60,9 @@
" does not match the given number:"
" expected " num-poly
", given " num-rands))))]
[(Name: _ args #f)
(cond [args
[(Name: _ num-args #f)
(cond [(> num-args 0)
(define num-rands (length rands))
(define num-args (length args))
(unless (= num-rands num-args)
(tc-error (~a "The expected number of arguments for "
rator " does not match the given number:"