... | ... | @@ -6,7 +6,7 @@ This page gives a hopefully comprehensive view of how `Bool` type is wired-in in |
|
|
## Constants for Bool type and data constructors
|
|
|
|
|
|
|
|
|
All data constructors, type constructors and so on have their unique identifier which is needed during the compilation process. For the wired-in types these unique values are defined in the [prelude/PrelNames.lhs](/trac/ghc/browser/ghc/prelude/PrelNames.lhs). In case of `Bool` the relevant definitions look like this:
|
|
|
All data constructors, type constructors and so on have their unique identifier which is needed during the compilation process. For the wired-in types these unique values are defined in the [prelude/PrelNames.hs](/trac/ghc/browser/ghc/prelude/PrelNames.hs). In case of `Bool` the relevant definitions look like this:
|
|
|
|
|
|
```wiki
|
|
|
boolTyConKey, falseDataConKey, trueDataConKey :: Unique
|
... | ... | @@ -18,7 +18,7 @@ trueDataConKey = mkPreludeDataConUnique 15 -- line 1451 |
|
|
### A side note on generating Unique values
|
|
|
|
|
|
|
|
|
The `mkPreludeTyConUnique` and `mkPreludeDataConUnique` take care of generating a unique `Unique` value. They are defined in [basicTypes/Unique.lhs](/trac/ghc/browser/ghc/basicTypes/Unique.lhs):
|
|
|
The `mkPreludeTyConUnique` and `mkPreludeDataConUnique` take care of generating a unique `Unique` value. They are defined in [basicTypes/Unique.hs](/trac/ghc/browser/ghc/basicTypes/Unique.hs):
|
|
|
|
|
|
```wiki
|
|
|
data Unique = MkUnique FastInt
|
... | ... | @@ -31,12 +31,12 @@ mkPreludeDataConUnique i = mkUnique '6' (2*i) |
|
|
```
|
|
|
|
|
|
|
|
|
You will find definition of `mkUnique :: Char -> Int -> Unique` at line 135 in [basicTypes/Unique.lhs](/trac/ghc/browser/ghc/basicTypes/Unique.lhs).
|
|
|
You will find definition of `mkUnique :: Char -> Int -> Unique` at line 135 in [basicTypes/Unique.hs](/trac/ghc/browser/ghc/basicTypes/Unique.hs).
|
|
|
|
|
|
## Defining wired-in information about Bool
|
|
|
|
|
|
|
|
|
All the wired-in information that compiler needs to know about `Bool` is defined in [prelude/TysWiredIn.lhs](/trac/ghc/browser/ghc/prelude/TysWiredIn.lhs). This file exports following functions related to `Bool`:
|
|
|
All the wired-in information that compiler needs to know about `Bool` is defined in [prelude/TysWiredIn.hs](/trac/ghc/browser/ghc/prelude/TysWiredIn.hs). This file exports following functions related to `Bool`:
|
|
|
|
|
|
```wiki
|
|
|
boolTy, boolTyCon, boolTyCon_RDR, boolTyConName,
|
... | ... | @@ -62,13 +62,13 @@ falseDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "False") fa |
|
|
trueDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "True") trueDataConKey trueDataCon
|
|
|
```
|
|
|
|
|
|
`boolTyConKey`, `falseDataConKey` and `trueDataConKey` are `Unique` values defined earlier. `boolTyCon`, `falseDataCon` and `trueDataCon` are yet undefined. Type of syntax is defined in [basicTypes/Names.lhs](/trac/ghc/browser/ghc/basicTypes/Names.lhs), line 129:
|
|
|
`boolTyConKey`, `falseDataConKey` and `trueDataConKey` are `Unique` values defined earlier. `boolTyCon`, `falseDataCon` and `trueDataCon` are yet undefined. Type of syntax is defined in [basicTypes/Names.hs](/trac/ghc/browser/ghc/basicTypes/Names.hs), line 129:
|
|
|
|
|
|
```wiki
|
|
|
data BuiltInSyntax = BuiltInSyntax | UserSyntax
|
|
|
```
|
|
|
|
|
|
`BuiltInSyntax` is used for things like (:), \[\] and tuples. All other things are `UserSyntax`. `gHC_TYPES` is a module `GHC.Types` to which these type and data constructors get assigned. It is defined in [prelude/PrelNames.lhs](/trac/ghc/browser/ghc/prelude/PrelNames.lhs):
|
|
|
`BuiltInSyntax` is used for things like (:), \[\] and tuples. All other things are `UserSyntax`. `gHC_TYPES` is a module `GHC.Types` to which these type and data constructors get assigned. It is defined in [prelude/PrelNames.hs](/trac/ghc/browser/ghc/prelude/PrelNames.hs):
|
|
|
|
|
|
```wiki
|
|
|
gHC_TYPES = mkPrimModule (fsLit "GHC.Types") -- line 359
|
... | ... | @@ -77,7 +77,7 @@ mkPrimModule :: FastString -> Module -- line 435 |
|
|
mkPrimModule m = mkModule primPackageId (mkModuleNameFS m)
|
|
|
```
|
|
|
|
|
|
`FastString` is a string type based on `ByteStrings` and the `fsLit` function converts a standard Haskell `Strings` to `FastString`. See [utils/FastString.lhs](/trac/ghc/browser/ghc/utils/FastString.lhs) for more details.
|
|
|
`FastString` is a string type based on `ByteStrings` and the `fsLit` function converts a standard Haskell `Strings` to `FastString`. See [utils/FastString.hs](/trac/ghc/browser/ghc/utils/FastString.hs) for more details.
|
|
|
|
|
|
### A side note on creating wired-in Names
|
|
|
|
... | ... | @@ -100,7 +100,7 @@ data NameSort |
|
|
```
|
|
|
|
|
|
|
|
|
The `mkWiredInTyConName` and `mkWiredInDataConName` are functions that create `Name`s for wired in types and data constructors. They are defined in [prelude/TysWiredIn.lhs](/trac/ghc/browser/ghc/prelude/TysWiredIn.lhs), lines 163-173:
|
|
|
The `mkWiredInTyConName` and `mkWiredInDataConName` are functions that create `Name`s for wired in types and data constructors. They are defined in [prelude/TysWiredIn.hs](/trac/ghc/browser/ghc/prelude/TysWiredIn.hs), lines 163-173:
|
|
|
|
|
|
```wiki
|
|
|
mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name
|
... | ... | @@ -117,7 +117,7 @@ mkWiredInDataConName built_in modu fs unique datacon |
|
|
```
|
|
|
|
|
|
|
|
|
The `mkWiredInName` is defined in [basicTypes/Names.lhs](/trac/ghc/browser/ghc/basicTypes/Names.lhs) (lines 279-283), and it just assigns values to fields of `Name`:
|
|
|
The `mkWiredInName` is defined in [basicTypes/Names.hs](/trac/ghc/browser/ghc/basicTypes/Names.hs) (lines 279-283), and it just assigns values to fields of `Name`:
|
|
|
|
|
|
```wiki
|
|
|
mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name
|
... | ... | @@ -130,7 +130,7 @@ mkWiredInName mod occ uniq thing built_in |
|
|
## RdrNames for Bool
|
|
|
|
|
|
|
|
|
Having defined `Name`s for `Bool`, the [RdrName](commentary/compiler/rdr-name-type)s can be defined ([prelude/TysWiredIn.lhs](/trac/ghc/browser/ghc/prelude/TysWiredIn.lhs), lines 221-225):
|
|
|
Having defined `Name`s for `Bool`, the [RdrName](commentary/compiler/rdr-name-type)s can be defined ([prelude/TysWiredIn.hs](/trac/ghc/browser/ghc/prelude/TysWiredIn.hs), lines 221-225):
|
|
|
|
|
|
```wiki
|
|
|
boolTyCon_RDR, false_RDR, true_RDR :: RdrName
|
... | ... | @@ -139,7 +139,7 @@ false_RDR = nameRdrName falseDataConName |
|
|
true_RDR = nameRdrName trueDataConName
|
|
|
```
|
|
|
|
|
|
`nameRdrName` is defined in `basicTypes.lhs` (line 203) and it simply wraps the `Name` into one of `RdrName`'s value constructors:
|
|
|
`nameRdrName` is defined in `basicTypes.hs` (line 203) and it simply wraps the `Name` into one of `RdrName`'s value constructors:
|
|
|
|
|
|
```wiki
|
|
|
nameRdrName :: Name -> RdrName
|
... | ... | @@ -170,14 +170,14 @@ Note that `boolTyCon` is on the list of wired in type constructors created by `w |
|
|
|
|
|
### A side note on functions generating type and data constructors
|
|
|
|
|
|
[types/TypeRep.lhs](/trac/ghc/browser/ghc/types/TypeRep.lhs), lines 281-282:
|
|
|
[types/TypeRep.hs](/trac/ghc/browser/ghc/types/TypeRep.hs), lines 281-282:
|
|
|
|
|
|
```wiki
|
|
|
mkTyConTy :: TyCon -> Type
|
|
|
mkTyConTy tycon = TyConApp tycon []
|
|
|
```
|
|
|
|
|
|
[prelude/TysWiredIn.lhs](/trac/ghc/browser/ghc/prelude/TysWiredIn.lhs), 247-257:
|
|
|
[prelude/TysWiredIn.hs](/trac/ghc/browser/ghc/prelude/TysWiredIn.hs), 247-257:
|
|
|
|
|
|
```wiki
|
|
|
pcTyCon :: Bool -> RecFlag -> Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
|
... | ... | @@ -195,7 +195,7 @@ pcTyCon is_enum is_rec name cType tyvars cons |
|
|
False -- Not in GADT syntax
|
|
|
```
|
|
|
|
|
|
`prelude/TysWiredIn.lhs`, 261-297:
|
|
|
`prelude/TysWiredIn.hs`, 261-297:
|
|
|
|
|
|
```wiki
|
|
|
pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon
|
... | ... | @@ -239,7 +239,7 @@ falseDataConId = dataConWorkId falseDataCon |
|
|
trueDataConId = dataConWorkId trueDataCon
|
|
|
```
|
|
|
|
|
|
`falseDataConId` and `trueDataConId` just extract `Id` from previously defined data constructors. These definitions are from [basicTypes/DataCon.lhs](/trac/ghc/browser/ghc/basicTypes/DataCon.lhs):
|
|
|
`falseDataConId` and `trueDataConId` just extract `Id` from previously defined data constructors. These definitions are from [basicTypes/DataCon.hs](/trac/ghc/browser/ghc/basicTypes/DataCon.hs):
|
|
|
|
|
|
```wiki
|
|
|
data DataCon -- line 253
|
... | ... | |