|
|
|
|
|
\[ Up: [Commentary/Compiler/HscMain](commentary/compiler/hsc-main) \]
|
|
|
|
|
|
# The `Name` and `OccName` types
|
|
|
# The `Name` type
|
|
|
|
|
|
|
|
|
Every entity (type constructor, class, identifier, type variable) has a `Name`. The Name type is pervasive in GHC, and is defined in [compiler/basicTypes/Name.lhs](/trac/ghc/browser/ghc/compiler/basicTypes/Name.lhs). Here is what a `Name` looks like, though it is private to the Name module:
|
... | ... | @@ -16,7 +16,7 @@ data Name = Name { |
|
|
```
|
|
|
|
|
|
- The `n_sort` field says what sort of name this is: see [\#NameSort](wiki-start#) below.
|
|
|
- The `n_occ` field gives the "occurrence name" of the Name; see OccName below.
|
|
|
- The `n_occ` field gives the "occurrence name", or **OccName?**, of the Name.
|
|
|
- The `n_uniq` field allows fast tests for equality of Names.
|
|
|
- The `n_loc` field gives some indication of where the name was bound.
|
|
|
|
... | ... | @@ -92,27 +92,3 @@ Here are the sorts of Name an entity can have: |
|
|
|
|
|
- Before CoreTidy, the Ids that were defined at top level in the original source program get `External` Names, whereas extra top-level bindings generated (say) by the type checker get `Internal` Names. This distinction is occasionally useful for filtering diagnostic output; e.g. for `-ddump-types`.
|
|
|
- After CoreTidy: An Id with an `External` Name will generate symbols that appear as external symbols in the object file. An Id with an `Internal` Name cannot be referenced from outside the module, and so generates a local symbol in the object file. The CoreTidy pass makes the decision about which names should be External and which Internal. |
|
|
|
|
|
## Occurrence names: `OccName`
|
|
|
|
|
|
|
|
|
An `OccName` is more-or-less just a string, like "foo" or "Tree", giving the (unqualified) name of an entity.
|
|
|
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 [compiler/basicTypes/OccName.lhs](/trac/ghc/browser/ghc/compiler/basicTypes/OccName.lhs):
|
|
|
|
|
|
```wiki
|
|
|
data OccName = OccName NameSpace EncodedFS
|
|
|
```
|
|
|
|
|
|
|
|
|
The `EncodedFS` is a synonym for `FastString` indicating that the string is Z-encoded. (Details in [compiler/basicTypes/OccName.lhs](/trac/ghc/browser/ghc/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.
|
|
|
|
|
|
|
|
|
The name spaces are:
|
|
|
|
|
|
```wiki
|
|
|
data NameSpace = VarName -- Variables, including "source" data constructors
|
|
|
| DataName -- "Real" data constructors
|
|
|
| TvName -- Type variables
|
|
|
| TcClsName -- Type constructors and classes; Haskell has them
|
|
|
-- in the same name space for now.
|
|
|
``` |
|
|
\ No newline at end of file |