HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-9.10.3GHC2021

GHC.Types.Name.Reader

GHC uses several kinds of name internally:

  • OccName: see GHC.Types.Name.Occurrence#name_types

  • 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 with an optional module qualifier

  • Name: see GHC.Types.Name#name_types

  • GHC.Types.Id.Id: see GHC.Types.Id#name_types

  • Var: see GHC.Types.Var#name_types

  • 20 types
  • 101 values
  • Packageghc-9.10.3
  • Exports123
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceReader.hs

The main type

1 declaration
datadata RdrName
#

Reader Name

Do not use the data constructors of RdrName directly: prefer the family of functions that creates them, such as mkRdrUnqual

  • Note: A Located RdrName will only have API Annotations if it is a compound one, e.g.

`bar`
( ~ )

Constructors

  • Unqual OccName

    Unqualified name

    Used for ordinary, unqualified occurrences, e.g. x, y or Foo. Create such a RdrName with mkRdrUnqual

  • Qual ModuleName OccName

    Qualified name

    A 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 OccName

    Original name

    An 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

    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

Instances8Eq, Data, Ord, Outputable, OutputableBndr, HasOccName, …

Construction

Destruction

Local mapping of RdrName to Name.Name

11 declarations

Global mapping of RdrName to GlobalRdrElts

10 declarations

Global Reader Environment

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 1: All the members of the list have distinct gre_name fields; that is, no duplicate Names

INVARIANT 2: 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 GHC.Rename.Names Note [Top-level Names in Template Haskell decl quotes]

INVARIANT 3: If the GlobalRdrEnv maps [occ -> gre], then greOccName gre = occ

Looking up GlobalRdrElts

datadata FieldsOrSelectors
#

When looking up GREs, we may or may not want to include fields that were defined in modules with NoFieldSelectors enabled. See Note [NoFieldSelectors].

Constructors

  • WantNormal

    Include normal names, and fields with selectors, but ignore fields without selectors.

  • WantBoth

    Include normal names and all fields (regardless of whether they have selectors).

  • WantField

    Include only fields, with or without selectors, ignoring any non-fields in scope.

Instances2Eq, Show
datadata LookupGRE info where
#

What should we look up in a GlobalRdrEnv? Should we only look up names with the exact same OccName, or do we allow different NameSpaces?

Depending on the answer, we might need more or less information from the GlobalRdrEnv, e.g. if we want to include matching record fields we need to know if the corresponding record fields define field selectors, for which we need to consult the GREInfo. This is why this datatype is a GADT.

See Note [IfGlobalRdrEnv].

Constructors

datadata WhichGREs info where
#

How should we look up in a GlobalRdrEnv? Which NameSpaces are considered relevant for a given lookup?

Constructors

Instances1Outputable
valuepickGREs :: RdrName -> [GlobalRdrEltX info] -> [GlobalRdrEltX info]
#

Takes a list of GREs which have the right OccName x Pick those GREs that are in scope * Qualified, as M.x if want_qual is Qual M _ * Unqualified, as x if want_unqual is Unqual _

Return each such GRE, with its ImportSpecs filtered, to reflect how it is in scope qualified or unqualified respectively. See Note [GRE filtering]

valuepickGREsModExp
  1. :: ModuleName
  2. -> [GlobalRdrEltX info]
  3. -> [(GlobalRdrEltX info, GlobalRdrEltX info)]
#

Pick GREs that are in scope *both* qualified *and* unqualified Return each GRE that is, as a pair (qual_gre, unqual_gre) These two GREs are the original GRE with imports filtered to express how it is in scope qualified an unqualified respectively

Used only for the 'module M' item in export list; see exports_from_avail

GlobalRdrElts

8 declarations
valuegresToAvailInfo :: [GlobalRdrEltX info] -> [AvailInfo]
#

Takes a list of distinct GREs and folds them into AvailInfos. This is more efficient than mapping each individual GRE to an AvailInfo and then folding using plusAvail, but needs the uniqueness assumption.

Global RdrName mapping elements: GlobalRdrElt, Provenance, ImportSpec

datadata GlobalRdrEltX info
#

Global Reader Element

Something in scope in the renamer; usually a member of the GlobalRdrEnv. See Note [GlobalRdrElt provenance].

Why do we parametrise over the gre_info field? See Note [IfGlobalRdrEnv].

Constructors

  • GRE
    • gre_name :: !Name
    • gre_par :: !Parent

      See Note [Parents]

    • gre_lcl :: !Bool

      True = the thing was defined locally

    • gre_imp :: !Bag ImportSpec

      In scope through these imports See Note [GlobalRdrElt provenance] for the relation between gre_lcl and gre_imp.

    • gre_info :: info

      Information the renamer knows about this particular Name.

      Careful about forcing this field! Forcing it can trigger the loading of interface files.

      Note [Retrieving the GREInfo from interfaces] in GHC.Types.GREInfo.

Instances4Data, NFData, Outputable, HasOccName

Shadowing

Information attached to a GlobalRdrElt

datadata ConLikeName
#

The Name of a ConLike.

Useful when we are in the renamer and don't yet have a full DataCon or PatSyn to hand.

Instances5Eq, Data, NFData, Outputable, Uniquable
datadata RecFieldInfo
#

Constructors

Instances5Eq, Data, NFData, Outputable, ToHie

Parent information

datadata ImportSpec
#

Import Specification

The ImportSpec of something says how it came to be imported It's quite elaborate so that we can give accurate unused-name warnings.

Instances4Eq, Data, NFData, Outputable
datadata ImpDeclSpec
#

Import Declaration Specification

Describes a particular import declaration and is shared among all the Provenances for that decl

Constructors

  • ImpDeclSpec
    • is_mod :: !Module

      Module imported, e.g. import Muggle Note the Muggle may well not be the defining module for this thing!

    • is_as :: !ModuleName

      Import alias, e.g. from as M (or Muggle if there is no as clause)

    • is_qual :: !Bool

      Was this import qualified?

    • is_dloc :: !SrcSpan

      The location of the entire import declaration

Instances2Eq, Data
datadata ImpItemSpec
#

Import Item Specification

Describes import info a particular Name

Constructors

  • ImpAll

    The 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.

Instances2Eq, Data

Utils

1 declaration