From c00cc17e07e071a7232e09b21971a2f7afdccf9b Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Wed, 11 Feb 2015 01:36:31 -0500 Subject: [PATCH] Add cond-contracts to name-env functions This helped for debugging, especially since some of the comments were inaccurate. Removed contract comments that aren't more specific than the code contracts. --- .../typed-racket/env/type-name-env.rkt | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/typed-racket-lib/typed-racket/env/type-name-env.rkt b/typed-racket-lib/typed-racket/env/type-name-env.rkt index 3b6682a2..70424056 100644 --- a/typed-racket-lib/typed-racket/env/type-name-env.rkt +++ b/typed-racket-lib/typed-racket/env/type-name-env.rkt @@ -5,34 +5,44 @@ (require "../utils/utils.rkt") (require syntax/id-table + (contract-req) (env type-alias-env) (utils tc-utils) (rep type-rep free-variance) (types utils)) -(provide register-type-name - lookup-type-name - register-type-names - add-alias - type-name-env-map - - register-type-variance! - lookup-type-variance - type-variance-env-map - add-constant-variance! - refine-variance!) +(provide/cond-contract [register-type-name + (->* (identifier?) (Type/c) any)] + [register-type-names + (-> (listof identifier?) (listof Type/c) any)] + [add-alias (-> identifier? identifier? any)] + [type-name-env-map + (-> (-> identifier? Type/c any) any)] + [type-variance-env-map + (-> (-> identifier? variance? any) any)] + [lookup-type-name + (->* (identifier?) (procedure?) (or/c #t Type/c))] + [register-type-variance! + (-> identifier? (listof variance?) any)] + [lookup-type-variance + (-> identifier? (listof variance?))] + [add-constant-variance! + (-> identifier? (or/c #f (listof identifier?)) any)] + [refine-variance! + (-> (listof identifier?) + (listof Type/c) + (listof (or/c #f (listof symbol?))) + any)]) ;; a mapping from id -> type (where id is the name of the type) (define the-mapping (make-free-id-table)) ;; add a name to the mapping -;; identifier Type -> void (define (register-type-name id [type #t]) (free-id-table-set! the-mapping id type)) ;; add a bunch of names to the mapping -;; listof[identifier] listof[type] -> void (define (register-type-names ids types) (for-each register-type-name ids types)) @@ -62,7 +72,6 @@ (make-free-id-table)) ;; add a name to the mapping -;; identifier Type -> void (define (register-type-variance! id variance) (free-id-table-set! variance-mapping id variance)) @@ -76,7 +85,6 @@ (define (type-variance-env-map f) (free-id-table-map variance-mapping f)) -;; Listof Listof>> -> Void ;; Refines the variance of a type in the name environment (define (refine-variance! names types tvarss) (let loop () @@ -95,7 +103,6 @@ (equal? variance old-variance)]))) (unless sames? (loop)))) -;; Id Option> -> Void ;; Initialize variance of the given id to Constant for all type vars (define (add-constant-variance! name vars) (unless (or (not vars) (null? vars))