[GHC] #11062: Type families + hs-boot files = panic

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Compiler | Version: 7.11 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I have these modules: A.hs-boot: {{{ {-# LANGUAGE TypeFamilies #-} module A where type family F a }}} B.hs: {{{ {-# LANGUAGE TypeFamilies #-} module B where import {-# SOURCE #-} A type instance F Int = Bool }}} A.hs: {{{ {-# LANGUAGE TypeFamilies #-} module A where import B type family F a }}} And now this happens: {{{ rae:11:50:47 ~/temp/bug> ~/Documents/ghc-cur/inplace/bin/ghc-stage2 --version The Glorious Glasgow Haskell Compilation System, version 7.11.20151104 rae:11:50:50 ~/temp/bug> ~/Documents/ghc-cur/inplace/bin/ghc-stage2 -c A .hs-boot rae:11:50:52 ~/temp/bug> ~/Documents/ghc-cur/inplace/bin/ghc-stage2 -c B.hs rae:11:50:54 ~/temp/bug> ~/Documents/ghc-cur/inplace/bin/ghc-stage2 -c A.hs ghc-stage2: panic! (the 'impossible' happened) (GHC version 7.11.20151104 for x86_64-apple-darwin): tcIfaceGlobal (local): not found: F [] Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug rae:11:50:57 ~/temp/bug> }}} The problem occurs only in one-shot mode. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by goldfire): * Attachment "T11062.zip" added. Test case files -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): Oddly enough this is a regression from GHC 7.6.3 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: high | Milestone: 8.0.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * cc: ezyang (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.0.1 => 8.2.1 Comment: It doesn't appear that this will get fixed for 8.0.1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): Another example of this is T6018, when built in one-shot mode. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * keywords: TypeFamilies => TypeFamilies hs-boot -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): OK, it's actually pretty obvious what's going on here: family instance consistency gets checked in the renamer but this is too early, because we haven't put enough things in the type environment. The solution is to move the check later in the typechecking process. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2215 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => patch * differential: => Phab:D2215 Comment: If it is completely unacceptable to check type family instance consistency after type checking, then we'll have to look into a different way of fixing this problem. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2215 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I'm going to respond here to the comments on Phab:D2215 because I think Trac comments are more likely to survive long term than Phab discussion. The question is: ''where should we check for consistency of imported type- family axioms?'' Currently it's done right after processing the import declarations of a module; but that's too early when we are concerned about consistency of axioms for a type family declared in this module. The patch does it late, after type checking all the local declarations. That's bad too, because all that type checking could be done with bogus overlapping family instances. I can think of two solutions. 1. Check for consistency of axioms for `F` ''right after `F` is defined''. That is, somewhere in `TcTyClsDecls.tcTyClGroup`. Notes: * We'd still need to check consistency for ''imported'' families before we start typechecking anything. * With this more incremental behaviour it might be harder to optimise the number of pairs compared (see `checkFamInstConsistency` module-pair stuff). But that doesn't matter since it is vanishingly rare for a type family defined in this module to have any imported instances whatsoever. 2. Make family-instance lookup complain if it finds two matching instances. * That would means we'd never make use of inconsistent instances, which would prevent strange error messages * We'd still need to do an aggressive `checkFamInstConsistency` check after type checking, to ensure consistency of instances that we didn't actually need when compiling this module (see the comments above `FamInst.checkFamInstConsistency`. I'm not sure which is best. I think (2) looks a bit easier, and is quite close to the proposed patch; just needs an overlap check on lookup. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2215 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Another minor advantage of (2) is that we could remove the {{{ ; no_conflict <- checkForConflicts inst_envs fam_inst }}} check in `FamINst.addLocalFamInsts`, because inconsistency would be caught by the later aggressive check, and would not cause a problem meanwhile. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2215 Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): I attempted to do (2) but actually it is not that easy. The difficulty stems from the fact that some of the functions that query FamInstEnv, e.g., `normaliseType :: FamInstEnvs -> Role -> Type -> (Coercion, Type)` never fail; that is, they assume that there are no conflicting instances. So it would seem all of these functions would need to have their signatures changed that they might fail due to a conflicting instance. Might be worth it, but certainly not a non-invasive change. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic (type family consistency check too early) -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2215 Wiki Page: | -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic (type family consistency check too early) -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2215 Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): There is a technical difficulty with (1): we need to be able to distinguish between imported families and families which we are going to define. Unfortunately, these families are all bundled together in a `FamInstEnv`, and the only indication if it's local or external is in the `Name` of the `CoAxiom`, but we're not allowed to actually poke the `CoAxiom` to get this `Name` (since that will force the thunk.) So we need to carry along the `Name` of the `FamInstEnv`, or separate out local/external while we're typechecking the interface. The latter sounds less intrusive; we'll just end up with two FamInstEnvs in this case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic (type family consistency check too early) -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: patch Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2859 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * differential: Phab:D2215 => Phab:D2859 Comment: OK, we've got a new patch! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic (type family consistency check too
early)
-------------------------------------+-------------------------------------
Reporter: goldfire | Owner:
Type: bug | Status: patch
Priority: high | Milestone: 8.2.1
Component: Compiler | Version: 7.11
Resolution: | Keywords: TypeFamilies
| hs-boot
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2859
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang

#11062: Type families + hs-boot files = panic (type family consistency check too early) -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: fixed | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2859 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11062: Type families + hs-boot files = panic (type family consistency check too early) -------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler | Version: 7.11 Resolution: fixed | Keywords: TypeFamilies | hs-boot Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2859 Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): See #13251 for a follow-up. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11062#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC