[GHC] #9562: Type families + hs-boot files = unsafeCoerce
GHC
ghc-devs at haskell.org
Mon May 4 17:55:36 UTC 2015
#9562: Type families + hs-boot files = unsafeCoerce
-------------------------------------+-------------------------------------
Reporter: goldfire | Owner: ezyang
Type: bug | Status: new
Priority: high | Milestone:
Component: Compiler | Version: 7.8.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: GHC accepts | Unknown/Multiple
invalid program | Test Case:
Blocked By: | Blocking:
Related Tickets: #10270 | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by ezyang):
Richard and I had a discussion, and we decided that solution 2 (when GHC
is preparing the list of modules to send to the linker, perform an overlap
check on type functions) is the only solution that works for linking
together LIBRARY files (e.g. libfoo.a). Solution 1 does not work in this
case, since when you link a library there isn't actually an executable to
overlap check.
This has a consequence that (at least for safe usage) you can't just use
`ar` to put `.o` files together: you must call GHC to do the overlap
check. This means we need a new major mode for GHC, to do the overlap
check for a set of modules (or even to just do the linking). The overlap
check should be implied when `--make` is used. It's harmless for `--make`
to report an overlap early (as is the case currently), but we must always
do overlap check at the end, in case `D` is compiled before `B` (as was
the case in 7.8). The overlap check can be skipped if there are no boot
files.
Aside: There is an alternate strategy we can use which avoids the need
for an overlap check at the very end. However, it requires that one-shot
compilation be done in a ''specific'' order, so we don't think we should
actually use it. Here's what you do: every `A.hs`/`A.hs-boot` pair
induces a cycle of imports, which must be compiled before `A.hs` can be
compiled. We ''always'' compile this cycle before we compile any other
modules which depend on `A.hs-boot`. When compiling a module which
transitively imports a boot file, we check if the real module has already
been compiled; if so, we load it and add its instances to our environment.
An instance which conflicts with the instance in `A.hs` will either be in
a critical cycle, or not. If it is in the critical cycle, we will report
overlap when `A.hs` is typechecked. Otherwise, we will load `A.hi` when
typechecking the module and report overlap.
One silly way to enforce this ordering is, when compiling a module which
transitively depends on a boot file, to produce a pre-hi file; only when
the real module has been compiled, only then can you re-process the hi
file to produce the real hi file.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9562#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list