... | @@ -60,10 +60,30 @@ type GlobalRdrEnv = OccEnv [GlobalRdrElt] |
... | @@ -60,10 +60,30 @@ type GlobalRdrEnv = OccEnv [GlobalRdrElt] |
|
data GlobalRdrElt = GRE { gre_name :: Name, gre_prov :: Provenance }
|
|
data GlobalRdrElt = GRE { gre_name :: Name, gre_prov :: Provenance }
|
|
|
|
|
|
data Provenance = LocalDef | Imported [ImportSpec]
|
|
data Provenance = LocalDef | Imported [ImportSpec]
|
|
|
|
|
|
|
|
data ImportSpec = ImpSpec { is_decl :: ImpDeclSpec, is_item :: ImpItemSpec }
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
The environment 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`. 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. You can look in `RdrName.lhs` to see what an `ImportSpec` is, but among other things it says whether the import is qualified-only, and whether there is an "`as`" clause on the import statement.
|
|
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).
|
|
|
|
- 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.
|
|
|
|
- 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 `ImpItemSpec` that describes the import item that brought the entity into scope.
|
|
|
|
|
|
|
|
>
|
|
|
|
> For example, given
|
|
|
|
>
|
|
|
|
> ```wiki
|
|
|
|
> import qualified M( x, T(g) ) as Q
|
|
|
|
> ```
|
|
|
|
>
|
|
|
|
>
|
|
|
|
> 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!
|
|
|
|
|
|
|
|
|
|
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).
|
... | | ... | |