Change type variable environments from hash tables to sets.

original commit: 12384c6c3fd14020c99018d51058240f4258074d
This commit is contained in:
Sam Tobin-Hochstadt 2010-05-28 16:00:37 -04:00
parent 78b767252d
commit 38e065db7f
3 changed files with 12 additions and 12 deletions

View File

@ -1,5 +1,6 @@
#lang scheme/base
(require "test-utils.ss" (for-syntax scheme/base)
racket/set
(utils tc-utils)
(env type-alias-env type-env-structs tvar-env type-name-env init-envs)
(rep type-rep)
@ -105,8 +106,7 @@
[(Listof Number) (make-Listof N)]
[a (-v a) (extend-env (list 'a) (list (-v a))
initial-tvar-env)]
[a (-v a) (set-add initial-tvar-env 'a)]
[(All (a ...) (a ... -> Number))
(-polydots (a) ((list) [a a] . ->... . N))]

View File

@ -6,26 +6,26 @@
;; to types representing the type variable
;; technically, the mapped-to type is unnecessary, but it's convenient to have it around? maybe?
(require racket/require "type-env-structs.rkt" (path-up "utils/tc-utils.rkt" "rep/type-rep.rkt"))
(require racket/require racket/set (path-up "utils/tc-utils.rkt"))
(provide (all-defined-out))
;; the initial type variable environment - empty
;; this is used in the parsing of types
(define initial-index-env (make-empty-env #hasheq()))
(define initial-index-env (seteq))
;; a parameter for the current type variables
(define current-indexes (make-parameter initial-index-env))
;; takes a single index
(define-syntax-rule (extend-indexes index . body)
(parameterize ([current-indexes (extend (current-indexes) index (make-F index))]) . body))
(parameterize ([current-indexes (set-add (current-indexes) index)]) . body))
(define (bound-index? v) (lookup (current-indexes) v (lambda (_) #f)))
(define (bound-index? v) (set-member? (current-indexes) v))
(define (infer-index stx)
(define bounds (env-keys+vals (current-indexes)))
(define bounds (set-map (current-indexes) values))
(when (null? bounds)
(tc-error/stx stx "No type variable bound with ... in scope for ... type"))
(unless (null? (cdr bounds))
(tc-error/stx stx "Cannot infer bound for ... type"))
(car (car bounds)))
(car bounds))

View File

@ -7,18 +7,18 @@
;; to types representing the type variable
;; technically, the mapped-to type is unnecessary, but it's convenient to have it around? maybe?
(require racket/require "type-env-structs.rkt" (path-up "rep/type-rep.rkt"))
(require racket/set)
(provide (all-defined-out))
;; the initial type variable environment - empty
;; this is used in the parsing of types
(define initial-tvar-env (make-empty-env #hasheq()))
(define initial-tvar-env (seteq))
;; a parameter for the current type variables
(define current-tvars (make-parameter initial-tvar-env))
;; takes a list of vars
(define-syntax-rule (extend-tvars vars . body)
(parameterize ([current-tvars (extend-env vars (map make-F vars) (current-tvars))]) . body))
(parameterize ([current-tvars (foldr (λ (v s) (set-add s v)) (current-tvars) vars)]) . body))
(define (bound-tvar? v) (lookup (current-tvars) v (lambda (_) #f)))
(define (bound-tvar? v) (set-member? (current-tvars) v))