[GHC] #13487: GHC panic with deferred custom type errors

#13487: GHC panic with deferred custom type errors -------------------------------------+------------------------------------- Reporter: DimaSamoz | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: MacOS X Architecture: | Type of failure: Compile-time Unknown/Multiple | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I'm working on a music composition library that enforces composition rules at the type level. It makes heavy use of TypeInType and custom compiler errors. For example, it disallows dissonant major seventh intervals (e.g., a C and a B) in harmonic composition. While testing the library, I encountered a GHC panic which I haven't seen anywhere – unfortunately I don't know enough about GHC to understand what is causing the panic and couldn't reproduce it in simpler examples. I was hoping that you could point me in the right direction so that I can find a smaller program that reproduces the error. In GHCi, with the -fdefer-type-errors flag set, the following code (which should throw a custom type error as it describes composing a B quarter note with a C quarter note) produces a panic: {{{ λ: let t = c qn :-: b qn <interactive>:21:9: warning: [-Wdeferred-type-errors] • Can't have major sevenths in chords: C and B • In the expression: c qn :-: b qn In an equation for ‘t’: t = c qn :-: b qn ghc: panic! (the 'impossible' happened) (GHC version 8.0.2 for x86_64-apple-darwin): nameModule system irred_aCeG Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} This does not appear when loading a source file, or when -fdefer-type- errors is disabled, and only happens when the expression is assigned to a new value. A lot of the literals in the library are generated by TemplateHaskell, but the error happens without them as well: {{{ λ: let s = Note (Root :: Root (PitchRoot (Pitch B Natural Oct4))) (Dur :: Dur Quarter ) λ: let t = Note (Root :: Root (PitchRoot (Pitch C Natural Oct4))) (Dur :: Dur Quarter ) λ: let v = s :-: t <interactive>:27:9: warning: [-Wdeferred-type-errors] • Can't have major sevenths in chords: B and C • In the expression: s :-: t In an equation for ‘v’: v = s :-: t ghc: panic! (the 'impossible' happened) (GHC version 8.0.2 for x86_64-apple-darwin): nameModule system irred_aCnF Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} The library is available on Hackage (https://hackage.haskell.org/package/mezzo) and the error is reproducible as soon as the main module is loaded. I'd happily try to find a smaller example which gives the same error, so I was hoping that you might have some ideas about what could be going wrong. Thank you! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13487 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13487: GHC panic with deferred custom type errors -------------------------------------+------------------------------------- Reporter: DimaSamoz | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: GHCi | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * os: MacOS X => Unknown/Multiple * component: Compiler => GHCi * milestone: => 8.4.1 Comment: Thanks for the bug report! Here is a minimal file which exhibits the issue: {{{#!hs {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} module Mezzo where import Data.Kind (Constraint) import GHC.TypeLits data Foo a b where (:-:) :: Error a b => a -> b -> Foo a b type family Error a b :: Constraint where Error Int Int = () Error _ _ = TypeError ('Text "GHC panic in 3... 2... 1...") }}} Now load this into GHCi like so: {{{ $ /opt/ghc/8.2.1/bin/ghci Mezzo.hs -fdefer-type-errors GHCi, version 8.2.0.20170321: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Mezzo ( Mezzo.hs, interpreted ) Ok, modules loaded: Mezzo. λ> let v = 'a' :-: 'b' <interactive>:1:9: warning: [-Wdeferred-type-errors] • GHC panic in 3... 2... 1... • In the expression: 'a' :-: 'b' In an equation for ‘v’: v = 'a' :-: 'b' ghc: panic! (the 'impossible' happened) (GHC version 8.2.0.20170321 for x86_64-unknown-linux): nameModule system irred_a2AK Call stack: CallStack (from HasCallStack): prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1191:58 in ghc:Outputable callStackDoc, called at compiler/utils/Outputable.hs:1195:37 in ghc:Outputable pprPanic, called at compiler/basicTypes/Name.hs:239:3 in ghc:Name }}} I can reproduce this with 8.0.1, 8.0.2, 8.2.1, and HEAD. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13487#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13487: GHC panic with deferred custom type errors -------------------------------------+------------------------------------- Reporter: DimaSamoz | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: GHCi | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by DimaSamoz): Thank you! Yes, that looks similar to my definition of `:-:`: {{{ #!haskell data Music :: forall n l. Partiture n l -> Type where -- | Parallel or harmonic composition of music. (:-:) :: ValidHarm m1 m2 => Music m1 -> Music m2 -> Music (m1 +-+ m2) ... }}} `ValidHarm` checks whether the two pieces of music can be composed and returns a `TypeError` if there is a composition mistake. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13487#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13487: GHC panic with deferred custom type errors -------------------------------------+------------------------------------- Reporter: DimaSamoz | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: GHCi | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by DimaSamoz): Adding {{{ #!haskell c = evaluate ('a' :-: 'b') }}} to the above example, then loading it and querying the value of `c` also triggers the panic. This wouldn't be surprising if GHCi called `evaluate` upon let bindings, but surely that's not the case? I encountered this error when trying to test my library using the `should- not-typecheck` package (https://hackage.haskell.org/package/should-not- typecheck), which provides a HSpec assertion `shouldNotTypecheck` that passes only if the argument doesn't compile (hence the need for deferred type errors). I eventually realised that the library doesn't work with custom compiler errors: the function performs a case split on the result of `try (evaluate $ force a)` (for the argument `a`), but terms with custom type errors never got into the `Left (TypeError msg)` case (where the assertion could pass), so the function thought that the argument compiles. This might not be directly related, but I thought I would mention it in case it is! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13487#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13487: GHC panic with deferred custom type errors
-------------------------------------+-------------------------------------
Reporter: DimaSamoz | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.4.1
Component: GHCi | Version: 8.0.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Compile-time | Unknown/Multiple
crash or panic | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#13487: GHC panic with deferred custom type errors -------------------------------------+------------------------------------- Reporter: DimaSamoz | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.4.1 Component: GHCi | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash or panic | typecheck/should_fail/T13487 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => merge * testcase: => typecheck/should_fail/T13487 Comment: Thanks for the nice example. Happily, a one-line fix. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13487#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13487: GHC panic with deferred custom type errors -------------------------------------+------------------------------------- Reporter: DimaSamoz | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.4.1 Component: GHCi | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash or panic | typecheck/should_fail/T13487 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by DimaSamoz): Fantastic, thank you very much! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13487#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13487: GHC panic with deferred custom type errors -------------------------------------+------------------------------------- Reporter: DimaSamoz | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.2.1 Component: GHCi | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash or panic | typecheck/should_fail/T13487 Blocked By: | Blocking: Related Tickets: #12104 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #12104 * milestone: 8.4.1 => 8.2.1 Comment: This was marked as merge, but the milestone was 8.4.1. I've opted to mark it for the 8.2.1 milestone, especially since it fixes #12104 (see https://ghc.haskell.org/trac/ghc/ticket/12104#comment:8). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13487#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13487: GHC panic with deferred custom type errors
-------------------------------------+-------------------------------------
Reporter: DimaSamoz | Owner: (none)
Type: bug | Status: merge
Priority: normal | Milestone: 8.2.1
Component: GHCi | Version: 8.0.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Compile-time | Test Case:
crash or panic | typecheck/should_fail/T13487
Blocked By: | Blocking:
Related Tickets: #12104 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13487: GHC panic with deferred custom type errors -------------------------------------+------------------------------------- Reporter: DimaSamoz | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: GHCi | Version: 8.0.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash or panic | typecheck/should_fail/T13487 Blocked By: | Blocking: Related Tickets: #12104 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: comment:4 merged to `ghc-8.2` as a97406e978de9bbc333da48cb36d2b65da85dc7a. commment:8 merged as 477e7d2860b2c68c820db004e4ad094f162632ea. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13487#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC