Changes between Version 53 and Version 54 of Records/OverloadedRecordFields/Implementation


Ignore:
Timestamp:
Aug 28, 2013 12:20:01 PM (18 months ago)
Author:
adamgundry
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Records/OverloadedRecordFields/Implementation

    v53 v54  
    6565The `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. 
    6666 
     67'''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. 
     68 
    6769The `IEThingWith name [name] [OccName]` constructor of `IE`, which represents a thing that can be imported or exported, stores only the `OccName`s. 
    6870 
     
    116118== Automatic instance generation == 
    117119 
    118 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. 
    119  
    120 '''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. 
    121  
    122 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.  
    123  
    124 '''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. 
     120Typeclass 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. 
     121 
     122Since 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. 
     123 
     124'''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. 
    125125 
    126126 
     
    270270Of course, it is fine to use a qualified name in a record update. 
    271271 
    272 I've implemented the first option, adding a new warning `-fwarn-qualified-overloaded-record-fields` which is on by default. 
     272For now we've decided on the third option, allowing qualified names to refer only to a single field. 
    273273 
    274274 
     
    292292* Forbid ambiguous qualified overloaded fields. 
    293293* Add `HsVarOut RdrName id` instead of `HsSingleRecFld` (or perhaps rename `HsVar` to `HsVarIn`); also useful to recall how the user referred to something. 
    294 * Resolve Has constraints in the solver, like newtype coercions and SingI, rather than the instance scoping malarkey. 
    295294 
    296295* Sort out reporting of unused imports. 
    297 * Make instances available to GHCi. 
    298296* Haddock prints selector names in index and LaTeX exports list. 
    299297* What's going on with deprecations and fixity decls?