From ac3823228231bc2d24d7f9a90a0d0842069c5732 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Mon, 4 Nov 2013 17:39:56 -0500 Subject: [PATCH] Name and print top types consistently Closes PR 14117 Closes PR 14118 --- .../scribblings/reference/types.scrbl | 48 ++++++++++++++++++- .../typed-racket/base-env/base-types.rkt | 6 +++ .../typed-racket/types/abbrev.rkt | 6 +++ .../typed-racket/types/printer.rkt | 15 +++--- 4 files changed, 66 insertions(+), 9 deletions(-) diff --git a/pkgs/typed-racket-pkgs/typed-racket-doc/typed-racket/scribblings/reference/types.scrbl b/pkgs/typed-racket-pkgs/typed-racket-doc/typed-racket/scribblings/reference/types.scrbl index cda8a5cfdd..48990e6555 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-doc/typed-racket/scribblings/reference/types.scrbl +++ b/pkgs/typed-racket-pkgs/typed-racket-doc/typed-racket/scribblings/reference/types.scrbl @@ -301,10 +301,25 @@ corresponding to @racket[trest], where @racket[bound] @defform[(MListof t)]{Homogenous @rtech{mutable lists} of @racket[t].} @defform[(MPairof t u)]{@rtech{Mutable pairs} of @racket[t] and @racket[u].} +@defidform[MPairTop]{is the type of a @rtech{mutable pair} with unknown + element types and is the supertype of all mutable pair types. + This type typically appears in programs via the combination of + occurrence typing and @racket[mpair?]. +@ex[(lambda: ([x : Any]) (if (mpair? x) x (error "not an mpair!")))] +} + @defform[(Boxof t)]{A @rtech{box} of @racket[t]} @ex[(box "hello world")] +@defidform[BoxTop]{is the type of a @rtech{box} with an unknown element + type and is the supertype of all box types. Only read-only box operations + (e.g. @racket[unbox]) are allowed on values of this type. This type + typically appears in programs via the combination of occurrence + typing and @racket[box?]. +@ex[(lambda: ([x : Any]) (if (box? x) x (error "not a box!")))] +} + @defform[(Vectorof t)]{Homogenous @rtech{vectors} of @racket[t]} @defform[(Vector t ...)]{is the type of the list with one element, in order, for each type provided to the @racket[Vector] type constructor.} @@ -314,7 +329,8 @@ corresponding to @racket[trest], where @racket[bound] #(a b c)] @defidform[VectorTop]{is the type of a @rtech{vector} with unknown length and - element types. Only read-only vector operations (e.g. @racket[vector-ref]) + element types and is the supertype of all vector types. + Only read-only vector operations (e.g. @racket[vector-ref]) are allowed on values of this type. This type typically appears in programs via the combination of occurrence typing and @racket[vector?]. @ex[(lambda: ([x : Any]) (if (vector? x) x (error "not a vector!")))] @@ -327,7 +343,8 @@ corresponding to @racket[trest], where @racket[bound] @ex[#hash((a . 1) (b . 2))] } @defidform[HashTableTop]{is the type of a @rtech{hash table} with unknown key - and value types. Only read-only hash table operations (e.g. + and value types and is the supertype of all hash table types. Only read-only + hash table operations (e.g. @racket[hash-ref]) are allowed on values of this type. This type typically appears in programs via the combination of occurrence typing and @racket[hash?]. @@ -344,6 +361,13 @@ corresponding to @racket[trest], where @racket[bound] ] } +@defidform[ChannelTop]{is the type of a @rtech{channel} with unknown + message type and is the supertype of all channel types. This type typically + appears in programs via the combination of occurrence typing and + @racket[channel?]. +@ex[(lambda: ([x : Any]) (if (channel? x) x (error "not a channel!")))] +} + @defform*[[(Parameterof t) (Parameterof s t)]]{A @rtech{parameter} of @racket[t]. If two type arguments are supplied, the first is the type the parameter accepts, and the second is the type returned. @@ -361,6 +385,12 @@ type @racket[_t] on each iteration.} @defform[(Custodian-Boxof t)]{A @rtech{custodian box} of @racket[t].} @defform[(Thread-Cellof t)]{A @rtech{thread cell} of @racket[t].} +@defidform[Thread-CellTop]{is the type of a @rtech{thread cell} with unknown + element type and is the supertype of all thread cell types. This type typically + appears in programs via the combination of occurrence typing and + @racket[thread-cell?]. +@ex[(lambda: ([x : Any]) (if (thread-cell? x) x (error "not a thread cell!")))] +} @defform[(Ephemeronof t)]{An @rtech{ephemeron} whose value is of type @racket[t].} @@ -425,6 +455,13 @@ functions and continuation mark functions. @ex[(make-continuation-prompt-tag 'prompt-tag)] } +@defidform[Prompt-TagTop]{is the type of a @rtech{prompt tag} with unknown + body and handler types and is the supertype of all prompt tag types. This type + typically appears in programs via the combination of occurrence typing + and @racket[continuation-prompt-tag?]. +@ex[(lambda: ([x : Any]) (if (continuation-prompt-tag? x) x (error "not a prompt tag!")))] +} + @defform[(Continuation-Mark-Keyof t)]{ A continuation mark key that is used for continuation mark operations such as @racket[with-continuation-mark] and @@ -435,6 +472,13 @@ functions and continuation mark functions. @ex[(make-continuation-mark-key 'mark-key)] } +@defidform[Continuation-Mark-KeyTop]{is the type of a continuation mark + key with unknown element type and is the supertype of all continuation mark key + types. This type typically appears in programs + via the combination of occurrence typing and @racket[continuation-mark-key?]. +@ex[(lambda: ([x : Any]) (if (continuation-mark-key? x) x (error "not a mark key!")))] +} + @section{Other Type Constructors} diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-types.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-types.rkt index 78aa28852b..3c1ae1dfde 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-types.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-types.rkt @@ -105,8 +105,14 @@ [Sexp -Sexp] ;; (Sexpof (U)), syntax->datum of "2D" syntax [Identifier Ident] [Procedure top-func] +[BoxTop -BoxTop] +[ChannelTop -ChannelTop] [VectorTop -VectorTop] [HashTableTop -HashTop] +[MPairTop -MPairTop] +[ThreadCellTop -ThreadCellTop] +[Prompt-TagTop -Prompt-TagTop] +[Continuation-Mark-KeyTop -Continuation-Mark-KeyTop] [Keyword -Keyword] [Thread -Thread] [Resolved-Module-Path -Resolved-Module-Path] diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/abbrev.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/abbrev.rkt index 83b7f5c06c..f0e17d89b5 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/abbrev.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/abbrev.rkt @@ -154,8 +154,14 @@ (define Syntax-Sexp (-Sexpof Any-Syntax)) (define Ident (-Syntax -Symbol)) (define -HT make-Hashtable) +(define/decl -BoxTop (make-BoxTop)) +(define/decl -ChannelTop (make-ChannelTop)) (define/decl -HashTop (make-HashtableTop)) (define/decl -VectorTop (make-VectorTop)) +(define/decl -MPairTop (make-MPairTop)) +(define/decl -ThreadCellTop (make-ThreadCellTop)) +(define/decl -Prompt-TagTop (make-Prompt-TagTop)) +(define/decl -Continuation-Mark-KeyTop (make-Continuation-Mark-KeyTop)) (define/decl -Port (Un -Output-Port -Input-Port)) (define/decl -SomeSystemPath (Un -Path -OtherSystemPath)) (define/decl -Pathlike (Un -String -Path)) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/printer.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/printer.rkt index e897153ec1..510344cbe6 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/printer.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/printer.rkt @@ -275,13 +275,14 @@ (fp "~a" (car names))])] [(StructType: (Struct: nm _ _ _ _ _)) (fp "(StructType ~a)" (syntax-e nm))] [(StructTop: (Struct: nm _ _ _ _ _)) (fp "(Struct ~a)" (syntax-e nm))] - [(BoxTop:) (fp "Box")] - [(ChannelTop:) (fp "Channel")] - [(ThreadCellTop:) (fp "ThreadCell")] - [(VectorTop:) (fp "Vector")] - [(MPairTop:) (fp "MPair")] - [(Prompt-TagTop:) (fp "Prompt-Tag")] - [(Continuation-Mark-KeyTop:) (fp "Continuation-Mark-Key")] + [(BoxTop:) (fp "BoxTop")] + [(ChannelTop:) (fp "ChannelTop")] + [(ThreadCellTop:) (fp "ThreadCellTop")] + [(VectorTop:) (fp "VectorTop")] + [(HashtableTop:) (fp "HashTableTop")] + [(MPairTop:) (fp "MPairTop")] + [(Prompt-TagTop:) (fp "Prompt-TagTop")] + [(Continuation-Mark-KeyTop:) (fp "Continuation-Mark-KeyTop")] [(App: rator rands stx) (fp "~a" (list* rator rands))] ;; special cases for lists