... | @@ -57,19 +57,26 @@ You might think that the global rdr-env would be a mapping from `RdrName` to `Na |
... | @@ -57,19 +57,26 @@ You might think that the global rdr-env would be a mapping from `RdrName` to `Na |
|
type GlobalRdrEnv = OccEnv [GlobalRdrElt]
|
|
type GlobalRdrEnv = OccEnv [GlobalRdrElt]
|
|
-- An (OccEnv a) is a mapping from OccName to a
|
|
-- An (OccEnv a) is a mapping from OccName to a
|
|
|
|
|
|
data GlobalRdrElt = GRE { gre_name :: Name, gre_prov :: Provenance }
|
|
data GlobalRdrElt = GRE { gre_name :: Name
|
|
|
|
, gre_prov :: Provenance
|
|
|
|
, gre_par :: Parent }
|
|
|
|
|
|
data Provenance = LocalDef | Imported [ImportSpec]
|
|
data Provenance = LocalDef | Imported [ImportSpec]
|
|
|
|
|
|
data ImportSpec = ImpSpec { is_decl :: ImpDeclSpec, is_item :: ImpItemSpec }
|
|
data ImportSpec = ImpSpec { is_decl :: ImpDeclSpec, is_item :: ImpItemSpec }
|
|
|
|
|
|
|
|
data Parent = NoParent | ParentIs Name
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
Here is how to understand these types:
|
|
Here is how to understand these types:
|
|
|
|
|
|
- The environment maps an `OccName` to a list of all entities with that occurence name that are in scope (in any way).
|
|
- The environment (`GlobalRdrEnv`) maps an `OccName` to a list of all entities with that occurence name that are in scope (in any way).
|
|
|
|
|
|
- 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`.
|
|
- 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`.
|
|
|
|
|
|
- The `Provenance` has one of two forms. Either it is in scope because it is defined in this module (`LocalDef`), or because it is imported. In the latter case, the `[ImportSpec]` describes all the import statements that bring it into scope.
|
|
- The `Provenance` has one of two forms. Either it is in scope because it is defined in this module (`LocalDef`), or because it is imported. In the latter case, the `[ImportSpec]` describes all the import statements that bring it into scope.
|
|
|
|
|
|
- An `ImportSpec` has two components:
|
|
- An `ImportSpec` has two components:
|
|
|
|
|
|
- An `ImpDeclSpec` that describes the entire import declaration. This is shared between all entities brought into scope by a particular import declaration.
|
|
- An `ImpDeclSpec` that describes the entire import declaration. This is shared between all entities brought into scope by a particular import declaration.
|
... | @@ -85,6 +92,13 @@ Here is how to understand these types: |
... | @@ -85,6 +92,13 @@ Here is how to understand these types: |
|
>
|
|
>
|
|
> 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!
|
|
> 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!
|
|
|
|
|
|
|
|
- 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.
|
|
|
|
For example,
|
|
|
|
|
|
|
|
- The `Parent` of a data constructor is its data type
|
|
|
|
- The `Parent` of a record field selector is its data type
|
|
|
|
- The `Parent` of a class operation is its class
|
|
|
|
|
|
|
|
|
|
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).
|
|
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).
|
|
|
|
|
... | | ... | |