summaryrefslogtreecommitdiff
path: root/compiler/typecheck/FamInst.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2018-12-20 17:49:34 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2018-12-21 16:54:17 +0000
commita57d5c4d3e39ab9ac2c31431b5e38818359fa5b5 (patch)
tree1a048f360c7ab359703ae869dcdd8e693094becb /compiler/typecheck/FamInst.hs
parent66ce7de15dbc594e6890b5651dba3aa669c8d5fc (diff)
downloadhaskell-a57d5c4d3e39ab9ac2c31431b5e38818359fa5b5.tar.gz
Fix treatment of hi-boot files and dfuns
Trac #16038 exposed the fact that TcRnDriver.checkHiBootIface was creating a binding, in the module being compiled, for $fxBlah = $fBlah but $fxBlah was a /GlobalId/. But all bindings should be for /LocalIds/ else dependency analysis goes down the tubes. * I added a CoreLint check that an occurrence of a GlobalId is not bound by an binding of a LocalId. (There is already a binding-site check that no binding binds a GlobalId.) * I refactored (and actually signficantly simplified) the tricky code for dfuns in checkHiBootIface to ensure that we get LocalIds for those boot-dfuns. Alas, I then got "duplicate instance" messages when compiling HsExpr. It turns out that this is a long-standing, but extremely delicate, bug: even before this patch, if you compile HsExpr with -ddump-tc-trace, you get "duplicate instance". Without -ddump-tc-trace, it's OK. What a mess! The reason for the duplicate-instance is now explained in Note [Loading your own hi-boot file] in LoadIface. I fixed it by a Gross Hack in LoadIface.loadInterface. This is at least no worse than before. But there should be a better way. I have opened #16081 for this.
Diffstat (limited to 'compiler/typecheck/FamInst.hs')
-rw-r--r--compiler/typecheck/FamInst.hs78
1 files changed, 41 insertions, 37 deletions
diff --git a/compiler/typecheck/FamInst.hs b/compiler/typecheck/FamInst.hs
index 144b315bed..5ad27db06e 100644
--- a/compiler/typecheck/FamInst.hs
+++ b/compiler/typecheck/FamInst.hs
@@ -84,57 +84,61 @@ defined in module B.
How do we ensure that we maintain the necessary consistency?
* Call a module which defines at least one type family instance a
-"family instance module". This flag `mi_finsts` is recorded in the
-interface file.
+ "family instance module". This flag `mi_finsts` is recorded in the
+ interface file.
* For every module we calculate the set of all of its direct and
-indirect dependencies that are family instance modules. This list
-`dep_finsts` is also recorded in the interface file so we can compute
-this list for a module from the lists for its direct dependencies.
+ indirect dependencies that are family instance modules. This list
+ `dep_finsts` is also recorded in the interface file so we can compute
+ this list for a module from the lists for its direct dependencies.
* When type checking a module M we check consistency of all the type
-family instances that are either provided by its `dep_finsts` or
-defined in the module M itself. This is a pairwise check, i.e., for
-every pair of instances we must check that they are consistent.
+ family instances that are either provided by its `dep_finsts` or
+ defined in the module M itself. This is a pairwise check, i.e., for
+ every pair of instances we must check that they are consistent.
-- For family instances coming from `dep_finsts`, this is checked in
-checkFamInstConsistency, called from tcRnImports. See Note
-[Checking family instance consistency] for details on this check (and
-in particular how we avoid having to do all these checks for every
-module we compile).
+ - For family instances coming from `dep_finsts`, this is checked in
+ checkFamInstConsistency, called from tcRnImports. See Note
+ [Checking family instance consistency] for details on this check
+ (and in particular how we avoid having to do all these checks for
+ every module we compile).
-- That leaves checking the family instances defined in M itself
-against instances defined in either M or its `dep_finsts`. This is
-checked in `tcExtendLocalFamInstEnv'.
+ - That leaves checking the family instances defined in M itself
+ against instances defined in either M or its `dep_finsts`. This is
+ checked in `tcExtendLocalFamInstEnv'.
-There are two subtle points in this scheme which have not been
+There are four subtle points in this scheme which have not been
addressed yet.
* We have checked consistency of the family instances *defined* by M
-or its imports, but this is not by definition the same thing as the
-family instances *used* by M or its imports. Specifically, we need to
-ensure when we use a type family instance while compiling M that this
-instance was really defined from either M or one of its imports,
-rather than being an instance that we happened to know about from
-reading an interface file in the course of compiling an unrelated
-module. Otherwise, we'll end up with no record of the fact that M
-depends on this family instance and type safety will be compromised.
-See #13102.
+ or its imports, but this is not by definition the same thing as the
+ family instances *used* by M or its imports. Specifically, we need to
+ ensure when we use a type family instance while compiling M that this
+ instance was really defined from either M or one of its imports,
+ rather than being an instance that we happened to know about from
+ reading an interface file in the course of compiling an unrelated
+ module. Otherwise, we'll end up with no record of the fact that M
+ depends on this family instance and type safety will be compromised.
+ See #13102.
* It can also happen that M uses a function defined in another module
-which is not transitively imported by M. Examples include the
-desugaring of various overloaded constructs, and references inserted
-by Template Haskell splices. If that function's definition makes use
-of type family instances which are not checked against those visible
-from M, type safety can again be compromised. See #13251.
+ which is not transitively imported by M. Examples include the
+ desugaring of various overloaded constructs, and references inserted
+ by Template Haskell splices. If that function's definition makes use
+ of type family instances which are not checked against those visible
+ from M, type safety can again be compromised. See #13251.
* When a module C imports a boot module B.hs-boot, we check that C's
-type family instances are compatible with those visible from
-B.hs-boot. However, C will eventually be linked against a different
-module B.hs, which might define additional type family instances which
-are inconsistent with C's. This can also lead to loss of type safety.
-See #9562.
-
+ type family instances are compatible with those visible from
+ B.hs-boot. However, C will eventually be linked against a different
+ module B.hs, which might define additional type family instances which
+ are inconsistent with C's. This can also lead to loss of type safety.
+ See #9562.
+
+* The call to checkFamConsistency for imported functions occurs very
+ early (in tcRnImports) and that causes problems if the imported
+ instances use type declared in the module being compiled.
+ See Note [Loading your own hi-boot file] in LoadIface.
-}
{-