ghc-6.12.2: The GHC APISource codeContentsIndex
RdrName
Contents
The main type
Construction
Destruction
Printing
Local mapping of RdrName to Name
Global mapping of RdrName to GlobalRdrElts
Global RdrName mapping elements: GlobalRdrElt, Provenance, ImportSpec
Description

GHC uses several kinds of name internally:

  • OccName.OccName: see OccName
  • RdrName is the type of names that come directly from the parser. They have not yet had their scoping and binding resolved by the renamer and can be thought of to a first approximation as an OccName.OccName with an optional module qualifier
  • Name: see Name
  • Id.Id: see Id
  • Var.Var: see Var
Synopsis
data RdrName
= Unqual OccName
| Qual ModuleName OccName
| Orig Module OccName
| Exact Name
mkRdrUnqual :: OccName -> RdrName
mkRdrQual :: ModuleName -> OccName -> RdrName
mkUnqual :: NameSpace -> FastString -> RdrName
mkVarUnqual :: FastString -> RdrName
mkQual :: NameSpace -> (FastString, FastString) -> RdrName
mkOrig :: Module -> OccName -> RdrName
nameRdrName :: Name -> RdrName
getRdrName :: NamedThing thing => thing -> RdrName
mkDerivedRdrName :: Name -> (OccName -> OccName) -> RdrName
rdrNameOcc :: RdrName -> OccName
rdrNameSpace :: RdrName -> NameSpace
setRdrNameSpace :: RdrName -> NameSpace -> RdrName
isRdrDataCon :: RdrName -> Bool
isRdrTyVar :: RdrName -> Bool
isRdrTc :: RdrName -> Bool
isQual :: RdrName -> Bool
isQual_maybe :: RdrName -> Maybe (ModuleName, OccName)
isUnqual :: RdrName -> Bool
isOrig :: RdrName -> Bool
isOrig_maybe :: RdrName -> Maybe (Module, OccName)
isExact :: RdrName -> Bool
isExact_maybe :: RdrName -> Maybe Name
isSrcRdrName :: RdrName -> Bool
showRdrName :: RdrName -> String
type LocalRdrEnv = OccEnv Name
emptyLocalRdrEnv :: LocalRdrEnv
extendLocalRdrEnv :: LocalRdrEnv -> Name -> LocalRdrEnv
extendLocalRdrEnvList :: LocalRdrEnv -> [Name] -> LocalRdrEnv
lookupLocalRdrEnv :: LocalRdrEnv -> RdrName -> Maybe Name
lookupLocalRdrOcc :: LocalRdrEnv -> OccName -> Maybe Name
elemLocalRdrEnv :: RdrName -> LocalRdrEnv -> Bool
type GlobalRdrEnv = OccEnv [GlobalRdrElt]
emptyGlobalRdrEnv :: GlobalRdrEnv
mkGlobalRdrEnv :: [GlobalRdrElt] -> GlobalRdrEnv
plusGlobalRdrEnv :: GlobalRdrEnv -> GlobalRdrEnv -> GlobalRdrEnv
lookupGlobalRdrEnv :: GlobalRdrEnv -> OccName -> [GlobalRdrElt]
extendGlobalRdrEnv :: GlobalRdrEnv -> GlobalRdrElt -> GlobalRdrEnv
pprGlobalRdrEnv :: GlobalRdrEnv -> SDoc
globalRdrEnvElts :: GlobalRdrEnv -> [GlobalRdrElt]
lookupGRE_RdrName :: RdrName -> GlobalRdrEnv -> [GlobalRdrElt]
lookupGRE_Name :: GlobalRdrEnv -> Name -> [GlobalRdrElt]
getGRE_NameQualifier_maybes :: GlobalRdrEnv -> Name -> [Maybe [ModuleName]]
hideSomeUnquals :: GlobalRdrEnv -> [OccName] -> GlobalRdrEnv
findLocalDupsRdrEnv :: GlobalRdrEnv -> [OccName] -> (GlobalRdrEnv, [[Name]])
pickGREs :: RdrName -> [GlobalRdrElt] -> [GlobalRdrElt]
data GlobalRdrElt = GRE {
gre_name :: Name
gre_par :: Parent
gre_prov :: Provenance
}
isLocalGRE :: GlobalRdrElt -> Bool
unQualOK :: GlobalRdrElt -> Bool
qualSpecOK :: ModuleName -> ImportSpec -> Bool
unQualSpecOK :: ImportSpec -> Bool
data Provenance
= LocalDef
| Imported [ImportSpec]
pprNameProvenance :: GlobalRdrElt -> SDoc
data Parent
= NoParent
| ParentIs Name
data ImportSpec = ImpSpec {
is_decl :: ImpDeclSpec
is_item :: ImpItemSpec
}
data ImpDeclSpec = ImpDeclSpec {
is_mod :: ModuleName
is_as :: ModuleName
is_qual :: Bool
is_dloc :: SrcSpan
}
data ImpItemSpec
= ImpAll
| ImpSome {
is_explicit :: Bool
is_iloc :: SrcSpan
}
importSpecLoc :: ImportSpec -> SrcSpan
importSpecModule :: ImportSpec -> ModuleName
isExplicitItem :: ImpItemSpec -> Bool
The main type
data RdrName Source
Do not use the data constructors of RdrName directly: prefer the family of functions that creates them, such as mkRdrUnqual
Constructors
Unqual OccNameUsed for ordinary, unqualified occurrences, e.g. x, y or Foo. Create such a RdrName with mkRdrUnqual
Qual ModuleName OccNameA qualified name written by the user in source code. The module isn't necessarily the module where the thing is defined; just the one from which it is imported. Examples are Bar.x, Bar.y or Bar.Foo. Create such a RdrName with mkRdrQual
Orig Module OccNameAn original name; the module is the defining module. This is used when GHC generates code that will be fed into the renamer (e.g. from deriving clauses), but where we want to say "Use Prelude.map dammit". One of these can be created with mkOrig
Exact Name

We know exactly the Name. This is used:

  1. When the parser parses built-in syntax like [] and (,), but wants a RdrName from it
  2. By Template Haskell, when TH has generated a unique name

Such a RdrName can be created by using getRdrName on a Name

show/hide Instances
Construction
mkRdrUnqual :: OccName -> RdrNameSource
mkRdrQual :: ModuleName -> OccName -> RdrNameSource
mkUnqual :: NameSpace -> FastString -> RdrNameSource
mkVarUnqual :: FastString -> RdrNameSource
mkQual :: NameSpace -> (FastString, FastString) -> RdrNameSource
Make a qualified RdrName in the given namespace and where the ModuleName and the OccName are taken from the first and second elements of the tuple respectively
mkOrig :: Module -> OccName -> RdrNameSource
nameRdrName :: Name -> RdrNameSource
getRdrName :: NamedThing thing => thing -> RdrNameSource
mkDerivedRdrName :: Name -> (OccName -> OccName) -> RdrNameSource
Produce an original RdrName whose module that of a parent Name but its OccName is derived from that of it's parent using the supplied function
Destruction
rdrNameOcc :: RdrName -> OccNameSource
rdrNameSpace :: RdrName -> NameSpaceSource
setRdrNameSpace :: RdrName -> NameSpace -> RdrNameSource

This rather gruesome function is used mainly by the parser. When parsing:

 data T a = T | T1 Int

we parse the data constructors as types because of parser ambiguities, so then we need to change the type constr to a data constr

The exact-name case can occur when parsing:

 data [] a = [] | a : [a]

For the exact-name case we return an original name.

isRdrDataCon :: RdrName -> BoolSource
isRdrTyVar :: RdrName -> BoolSource
isRdrTc :: RdrName -> BoolSource
isQual :: RdrName -> BoolSource
isQual_maybe :: RdrName -> Maybe (ModuleName, OccName)Source
isUnqual :: RdrName -> BoolSource
isOrig :: RdrName -> BoolSource
isOrig_maybe :: RdrName -> Maybe (Module, OccName)Source
isExact :: RdrName -> BoolSource
isExact_maybe :: RdrName -> Maybe NameSource
isSrcRdrName :: RdrName -> BoolSource
Printing
showRdrName :: RdrName -> StringSource
Local mapping of RdrName to Name
type LocalRdrEnv = OccEnv NameSource
This environment is used to store local bindings (let, where, lambda, case). It is keyed by OccName, because we never use it for qualified names
emptyLocalRdrEnv :: LocalRdrEnvSource
extendLocalRdrEnv :: LocalRdrEnv -> Name -> LocalRdrEnvSource
extendLocalRdrEnvList :: LocalRdrEnv -> [Name] -> LocalRdrEnvSource
lookupLocalRdrEnv :: LocalRdrEnv -> RdrName -> Maybe NameSource
lookupLocalRdrOcc :: LocalRdrEnv -> OccName -> Maybe NameSource
elemLocalRdrEnv :: RdrName -> LocalRdrEnv -> BoolSource
Global mapping of RdrName to GlobalRdrElts
type GlobalRdrEnv = OccEnv [GlobalRdrElt]Source

Keyed by OccName; when looking up a qualified name we look up the OccName part, and then check the Provenance to see if the appropriate qualification is valid. This saves routinely doubling the size of the env by adding both qualified and unqualified names to the domain.

The list in the codomain is required because there may be name clashes These only get reported on lookup, not on construction

INVARIANT: All the members of the list have distinct gre_name fields; that is, no duplicate Names

INVARIANT: Imported provenance => Name is an ExternalName However LocalDefs can have an InternalName. This happens only when type-checking a [d| ... |] Template Haskell quotation; see this note in RnNames Note [Top-level Names in Template Haskell decl quotes]

emptyGlobalRdrEnv :: GlobalRdrEnvSource
mkGlobalRdrEnv :: [GlobalRdrElt] -> GlobalRdrEnvSource
plusGlobalRdrEnv :: GlobalRdrEnv -> GlobalRdrEnv -> GlobalRdrEnvSource
lookupGlobalRdrEnv :: GlobalRdrEnv -> OccName -> [GlobalRdrElt]Source
extendGlobalRdrEnv :: GlobalRdrEnv -> GlobalRdrElt -> GlobalRdrEnvSource
pprGlobalRdrEnv :: GlobalRdrEnv -> SDocSource
globalRdrEnvElts :: GlobalRdrEnv -> [GlobalRdrElt]Source
lookupGRE_RdrName :: RdrName -> GlobalRdrEnv -> [GlobalRdrElt]Source
lookupGRE_Name :: GlobalRdrEnv -> Name -> [GlobalRdrElt]Source
getGRE_NameQualifier_maybes :: GlobalRdrEnv -> Name -> [Maybe [ModuleName]]Source
hideSomeUnquals :: GlobalRdrEnv -> [OccName] -> GlobalRdrEnvSource

Hide any unqualified bindings for the specified OccNames This is used in TH, when renaming a declaration bracket

 [d| foo = ... |]

We want unqualified foo in ... to mean this foo, not the one from the enclosing module. But the qualified name from the enclosing module must certainly still be available

findLocalDupsRdrEnv :: GlobalRdrEnv -> [OccName] -> (GlobalRdrEnv, [[Name]])Source
For each OccName, see if there are multiple local definitions for it. If so, remove all but one (to suppress subsequent error messages) and return a list of the duplicate bindings
pickGREs :: RdrName -> [GlobalRdrElt] -> [GlobalRdrElt]Source

Take a list of GREs which have the right OccName Pick those GREs that are suitable for this RdrName And for those, keep only only the Provenances that are suitable

Consider:

	 module A ( f ) where
	 import qualified Foo( f )
	 import Baz( f )
	 f = undefined

Let's suppose that Foo.f and Baz.f are the same entity really. The export of f is ambiguous because it's in scope from the local def and the import. The lookup of Unqual f should return a GRE for the locally-defined f, and a GRE for the imported f, with a single provenance, namely the one for Baz(f).

Global RdrName mapping elements: GlobalRdrElt, Provenance, ImportSpec
data GlobalRdrElt Source
An element of the GlobalRdrEnv
Constructors
GRE
gre_name :: Name
gre_par :: Parent
gre_prov :: ProvenanceWhy it's in scope
show/hide Instances
isLocalGRE :: GlobalRdrElt -> BoolSource
unQualOK :: GlobalRdrElt -> BoolSource
Test if an unqualifed version of this thing would be in scope
qualSpecOK :: ModuleName -> ImportSpec -> BoolSource
Is in scope qualified with the given module?
unQualSpecOK :: ImportSpec -> BoolSource
Is in scope unqualified?
data Provenance Source
The Provenance of something says how it came to be in scope. It's quite elaborate so that we can give accurate unused-name warnings.
Constructors
LocalDefThe thing was defined locally
Imported [ImportSpec]

The thing was imported.

INVARIANT: the list of ImportSpec is non-empty

show/hide Instances
pprNameProvenance :: GlobalRdrElt -> SDocSource
Print out the place where the name was imported
data Parent Source
The children of a Name are the things that are abbreviated by the .. notation in export lists. Specifically: TyCon Children are * data constructors * record field ids Class Children are * class operations Each child has the parent thing as its Parent
Constructors
NoParent
ParentIs Name
show/hide Instances
data ImportSpec Source
Constructors
ImpSpec
is_decl :: ImpDeclSpec
is_item :: ImpItemSpec
show/hide Instances
data ImpDeclSpec Source
Describes a particular import declaration and is shared among all the Provenances for that decl
Constructors
ImpDeclSpec
is_mod :: ModuleNameModule imported, e.g. import Muggle Note the Muggle may well not be the defining module for this thing!
is_as :: ModuleNameImport alias, e.g. from as M (or Muggle if there is no as clause)
is_qual :: BoolWas this import qualified?
is_dloc :: SrcSpanThe location of the entire import declaration
show/hide Instances
data ImpItemSpec Source
Describes import info a particular Name
Constructors
ImpAllThe import had no import list, or had a hiding list
ImpSome

The import had an import list. The is_explicit field is True iff the thing was named explicitly in the import specs rather than being imported as part of a ... group. Consider:

 import C( T(..) )

Here the constructors of T are not named explicitly; only T is named explicitly.

is_explicit :: Bool
is_iloc :: SrcSpan
show/hide Instances
importSpecLoc :: ImportSpec -> SrcSpanSource
importSpecModule :: ImportSpec -> ModuleNameSource
isExplicitItem :: ImpItemSpec -> BoolSource
Produced by Haddock version 2.6.1