... | ... | @@ -71,6 +71,8 @@ type AvailFields = AvailFlds Name |
|
|
|
|
|
The `AvailTC` constructor represents a type and its pieces that are in scope. Record fields are now stored in a separate list (the third argument). If the fields are not overloaded, we store the selector names, whereas if they are overloaded, we store only the labels.
|
|
|
|
|
|
**AMG** This isn't quite enough, because we need to know the module of the selectors. (Data families mean this need not be the same as the parent's module.) I'm inclined to use `Overloaded [(OccName, name)]` in the interests of simplicity, and because otherwise we have to go to some trouble to avoid `gresFromAvails` outside the monad.
|
|
|
|
|
|
|
|
|
The `IEThingWith name [name] [OccName]` constructor of `IE`, which represents a thing that can be imported or exported, stores only the `OccName`s.
|
|
|
|
... | ... | @@ -128,14 +130,12 @@ The renamer (`rnHsRecFields1`) supplies `Left sel_name` for the selector if it i |
|
|
## Automatic instance generation
|
|
|
|
|
|
|
|
|
Typeclass and family instances are generated by `addLocalRecFldInsts` in `TcInstDecls`, regardless of whether or not the extension is enabled. This is called by `tcInstDecls1` to generate instances for fields from datatypes in the current group (at the same time as derived instances, from **deriving** clauses, are generated). The typeclass instances must be subsequently typechecked (by `tcInstDecls2`). Such instances are "private" in that they are available when typechecking the current module (in `tcg_inst_env`) but not exported to other modules (via `tcg_insts`). On the other hand, the underlying dfun ids and axioms are exported from the module as usual.
|
|
|
|
|
|
**AMG** This means that typeclass instances are not visible in GHCi, because it tracks only `tcg_insts` (via the `InteractiveContext`). I've added new fields in `TcGblEnv` to record the private instances, but there is still work to do here.
|
|
|
Typeclass and family instances are generated and typechecked by `makeOverloadedRecFldInsts` in `TcInstDecls`, regardless of whether or not the extension is enabled. This is called by `tcTopSrcDecls` to generate instances for fields from datatypes in the current group (just after derived instances, from **deriving** clauses, are generated). Overloaded record field instances are not exported to other modules (via `tcg_insts`), though underlying dfun ids and axioms are exported from the module as usual.
|
|
|
|
|
|
|
|
|
Moreover, `tcRnImports` calls `addImportedRecFldInsts` to add instances for overloaded record fields *that are in scope* from other modules. (This is different from the usual visible-everywhere story for instances.) We know which overloaded fields are in scope by looking at the `GlobalRdrEnv`. Since the dfuns and axioms are available, it is easy to turn them into appropriate `ClsInst`s and `FamInst`s.
|
|
|
Since the instances are not in scope in the usual way, `matchClassInst` and `tcLookupFamInst` look for the relevant constraints or type families and find the instances directly, rather than consulting `tcg_inst_env` or `tcg_fam_inst_env`. They first perform a lookup to check that the field name is in scope. A new field `tcg_fld_inst_env` in `TcGblEnv` maps a selector name in the current module to its `DFunId`s and `FamInst`s; this is needed for solving constraints that arise while checking the automatically generated instances themselves.
|
|
|
|
|
|
**AMG** When the extension is disabled, the instances are still generated and typechecked, and they must be in scope (via `addPrivateClsInsts`/`addPrivateTyFamInsts`) while they are being typechecked. This means `tcInstDecls1` and `2` need some refactoring.
|
|
|
**AMG** The instance lookup is currently implemented as a separate check, but needs to be integrated with the existing code to properly handle some obscure cases.
|
|
|
|
|
|
## Unused imports
|
|
|
|
... | ... | @@ -298,7 +298,7 @@ Should there be a difference between `f`, `g` and `h`? It would seem odd if `f` |
|
|
Of course, it is fine to use a qualified name in a record update.
|
|
|
|
|
|
|
|
|
I've implemented the first option, adding a new warning `-fwarn-qualified-overloaded-record-fields` which is on by default.
|
|
|
For now we've decided on the third option, allowing qualified names to refer only to a single field.
|
|
|
|
|
|
## Mangling selector names
|
|
|
|
... | ... | @@ -319,10 +319,8 @@ We could mangle selector names (using `$sel_foo_T` instead of `foo`) even when t |
|
|
- When there is only one thing in scope, don't do make it polymorphic (but document trade-offs). But maybe it should still support lenses?
|
|
|
- Forbid ambiguous qualified overloaded fields.
|
|
|
- Add `HsVarOut RdrName id` instead of `HsSingleRecFld` (or perhaps rename `HsVar` to `HsVarIn`); also useful to recall how the user referred to something.
|
|
|
- Resolve Has constraints in the solver, like newtype coercions and SingI, rather than the instance scoping malarkey.
|
|
|
|
|
|
- Sort out reporting of unused imports.
|
|
|
- Make instances available to GHCi.
|
|
|
- Haddock prints selector names in index and LaTeX exports list.
|
|
|
- What's going on with deprecations and fixity decls?
|
|
|
|
... | ... | |