Changes between Version 4 and Version 5 of Commentary/Compiler/NameType


Ignore:
Timestamp:
Sep 8, 2006 11:14:03 AM (9 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/NameType

    v4 v5  
    11[ Up: [wiki:Commentary/Compiler/HscMain] ]
    22
    3 = The {{{Name}}} and {{{OccName}}} types =
     3= The {{{Name}}} type =
    44
    55Every entity (type constructor, class, identifier, type variable) has a {{{Name}}}. The Name type is pervasive in GHC, and is defined in [[GhcFile(compiler/basicTypes/Name.lhs)]]. Here is what a {{{Name}}} looks like, though it is private to the Name module:
     
    1313}}}
    1414 * The {{{n_sort}}} field says what sort of name this is: see [wiki:#NameSort] below.
    15  * The {{{n_occ}}} field gives the "occurrence name" of the Name; see OccName below.
     15 * The {{{n_occ}}} field gives the "occurrence name", or '''[wiki:Commentary/Compiler/RdrName#TheOccNametype OccName]''', of the Name.
    1616 * The {{{n_uniq}}} field allows fast tests for equality of Names.
    1717 * The {{{n_loc}}} field gives some indication of where the name was bound.
     
    7676
    7777
    78 == Occurrence names: {{{OccName}}} ==
    79 
    80 An {{{OccName}}} is more-or-less just a string, like "foo" or "Tree", giving the (unqualified) name of an entity.
    81 Well, not quite just a string, because in Haskell a name like "C" could mean a type constructor or data constructor, depending on context. So GHC defines a type OccName (defined in basicTypes/OccName.lhs) that is a pair of a {{{FastString}}} and a {{{NameSpace}}} indicating which name space the name is drawn from. The data type is defined (abstractly) in [[GhcFile(compiler/basicTypes/OccName.lhs)]]:
    82 {{{
    83 data OccName = OccName NameSpace EncodedFS
    84 }}}
    85 The {{{EncodedFS}}} is a synonym for {{{FastString}}} indicating that the string is Z-encoded. (Details in [[GhcFile(compiler/basicTypes/OccName.lhs)]].) Z-encoding encodes funny characters like '%' and '$' into alphabetic characters, like "zp" and "zd", so that they can be used in object-file symbol tables without confusing linkers and suchlike.
    86 
    87 The name spaces are:
    88 
    89 {{{
    90 data NameSpace = VarName        -- Variables, including "source" data constructors
    91                | DataName       -- "Real" data constructors
    92                | TvName         -- Type variables
    93                | TcClsName      -- Type constructors and classes; Haskell has them
    94                                 -- in the same name space for now.
    95 }}}
    96