Changes between Version 13 and Version 14 of Commentary/Compiler/Renamer


Ignore:
Timestamp:
Sep 11, 2015 8:21:59 AM (4 years ago)
Author:
jstolarek
Comment:

.lhs -> .hs

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/Renamer

    v13 v14  
    3737A big part of the renamer's task is to build the '''global rdr-env''' for the module, of type {{{GlobalRdrEnv}}}.  This environment allows us to take a qualified or un-qualified {{{RdrName}}} and figure out which {{{Name}}} it means.  The global rdr-env is built by looking at all the imports, and the top-level declarations of the module.
    3838
    39 You might think that the global rdr-env would be a mapping from {{{RdrName}}} to {{{Name}}}, but it isn't.  Here is what it looks like, after at least three iterations (all in [[GhcFile(compiler/basicTypes/RdrName.lhs)]]):
     39You might think that the global rdr-env would be a mapping from {{{RdrName}}} to {{{Name}}}, but it isn't.  Here is what it looks like, after at least three iterations (all in [[GhcFile(compiler/basicTypes/RdrName.hs)]]):
    4040{{{
    4141type GlobalRdrEnv = OccEnv [GlobalRdrElt]
     
    5353}}}
    5454Here is how to understand these types:
    55  * The environment (`GlobalRdrEnv`) maps an {{{OccName}}} to a list of all entities with that occurence name that are in scope (in any way). 
     55 * The environment (`GlobalRdrEnv`) maps an {{{OccName}}} to a list of all entities with that occurrence name that are in scope (in any way). 
    5656
    5757 * Each of these is represented by a {{{GlobalRdrElt}}}, which gives the entity's {{{Name}}} plus a specification of how it is in scope, its {{{Provenance}}}. 
     
    6666import qualified M( x, T(g) ) as Q
    6767}}}
    68  the {{{ImpDeclSpec}}} would describe the {{{qualified}}} and {{{as}}} part, while the {{{ImpItemSpec}}} describes the {{{T(g)}}} part.  You can look in {{{RdrName.lhs}}} to see what an {{{ImportDeclSpec}}} and {{{ImpItemSpec}}} are like!
     68 the {{{ImpDeclSpec}}} would describe the {{{qualified}}} and {{{as}}} part, while the {{{ImpItemSpec}}} describes the {{{T(g)}}} part.  You can look in {{{RdrName.hs}}} to see what an {{{ImportDeclSpec}}} and {{{ImpItemSpec}}} are like!
    6969 * The {{{Parent}}} of an entity is the {{{Name}}} under which it is grouped when the forms `T(..)` or `T(C,D)` are used in an export or import list.  In the `T(..)` form, all the things whose {{{Parent}}} is `T` are chosen.  In the `T(C,D)` form, it is required that `C` and `D` have `T` as parents. 
    7070   For example,
     
    7373   * The `Parent` of a class operation is its class
    7474
    75 With all that information, we can give good error messages, especially in the case where an occurrence "f" is ambiguous (i.e. different entities, both called "f", were imported by diffferent import statements).
     75With all that information, we can give good error messages, especially in the case where an occurrence "f" is ambiguous (i.e. different entities, both called "f", were imported by different import statements).
    7676
    77 The global rdr-env is created by [[GhcFile(compiler/rename/RnNames.lhs)]].
     77The global rdr-env is created by [[GhcFile(compiler/rename/RnNames.hs)]].
    7878
    7979It is important to note that the global rdr-env is created  ''before'' the renamer actually descends into the top-level bindings of a module. In other words, before {{{TcRnDriver.rnTopSrcDecls}}} performs the renaming of a module by way of {{{RnSource.rnSrcDecls}}}, it uses {{{RnNames.importsFromLocalDecls}}} to set up the global rdr-env environment, which contains {{{Names}}} for all imported and all locally defined toplevel binders.  Hence, when the helpers of {{{rnSrcDecls}}} come across the defining occurences of a toplevel {{{RdrName}}}, they don't rename it by generating a new name, but they simply look up its name in the global rdr-env.