[GHC] #15186: ghc 8.4.2 panic in profiling build

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.4.2 Keywords: | Operating System: Linux Architecture: x86_64 | Type of failure: Compile-time (amd64) | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- When building our crucible-llvm library (https://github.com/GaloisInc/crucible) with profiling enabled, we encounter the following: {{{ [19 of 21] Compiling Lang.Crucible.LLVM.Translation ( src/Lang/Crucible/LLVM/Translation.hs, dist/build/Lang/Crucible/LLVM/Translation.p_o ) ghc: panic! (the 'impossible' happened) (GHC version 8.4.2 for x86_64-unknown-linux): isUnliftedType r_a4IqS :: TYPE rep_a4IqR Call stack: CallStack (from HasCallStack): callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable pprPanic, called at compiler/types/Type.hs:1939:10 in ghc:Type Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} Procedure to reproduce: {{{ $ git clone https://github.com/GaloisInc/crucible $ cd crucible/crucible-llvm $ ghc --version The Glorious Glasgow Haskell Compilation System, version 8.4.2 $ cabal --version cabal-install version 2.0.0.1 compiled using version 2.0.1.0 of the Cabal library $ cabal configure --enable-library-profiling $ cabal build }}} Note: the llvm-pretty dependency on Hackage is not compatible with GHC 8.4.2; use the latest from the github repo at http://github.com/elliottt /llvm-pretty. The crucible and what4 dependencies come from sibling subdirectories in the same crucible checkout. This builds successfully when using GHC 8.2.2 instead. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Profiling | Version: 8.4.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * component: Compiler => Profiling Comment: I can trim this down to two modules, at least: {{{#!hs {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} module Foo (Ctx, Assignment, pattern EmptyAssn, pattern (:>)) where import Data.Kind (Type) import Unsafe.Coerce (unsafeCoerce) data Ctx k = EmptyCtx | Ctx k ::> k type SingleCtx x = 'EmptyCtx '::> x type family (<+>) (x :: Ctx k) (y :: Ctx k) :: Ctx k where x <+> 'EmptyCtx = x x <+> (y '::> e) = (x <+> y) '::> e data Height = Zero | Succ Height data BinomialTree (h::Height) (f :: k -> Type) :: Ctx k -> Type where Empty :: BinomialTree h f 'EmptyCtx PlusOne :: !Int -> !(BinomialTree ('Succ h) f x) -> !(BalancedTree h f y) -> BinomialTree h f (x <+> y) PlusZero :: !Int -> !(BinomialTree ('Succ h) f x) -> BinomialTree h f x newtype Assignment (f :: k -> *) (ctx :: Ctx k) = Assignment (BinomialTree 'Zero f ctx) data AssignView f ctx where AssignEmpty :: AssignView f 'EmptyCtx AssignExtend :: Assignment f ctx -> f tp -> AssignView f (ctx '::> tp) data DropResult f (ctx :: Ctx k) where DropEmpty :: DropResult f 'EmptyCtx DropExt :: BinomialTree 'Zero f x -> f y -> DropResult f (x '::> y) data BalancedTree h (f :: k -> Type) (p :: Ctx k) where BalLeaf :: !(f x) -> BalancedTree 'Zero f (SingleCtx x) BalPair :: !(BalancedTree h f x) -> !(BalancedTree h f y) -> BalancedTree ('Succ h) f (x <+> y) tsize :: BinomialTree h f a -> Int tsize Empty = 0 tsize (PlusOne s _ _) = 2*s+1 tsize (PlusZero s _) = 2*s bal_drop :: forall h f x y . BinomialTree h f x -> BalancedTree h f y -> DropResult f (x <+> y) bal_drop t (BalLeaf e) = DropExt t e bal_drop t (BalPair x y) = unsafeCoerce (bal_drop (PlusOne (tsize t) (unsafeCoerce t) x) y) bin_drop :: forall h f ctx . BinomialTree h f ctx -> DropResult f ctx bin_drop Empty = DropEmpty bin_drop (PlusZero _ u) = bin_drop u bin_drop (PlusOne s t u) = let m = case t of Empty -> Empty _ -> PlusZero s t in bal_drop m u viewAssign :: forall f ctx . Assignment f ctx -> AssignView f ctx viewAssign (Assignment x) = case bin_drop x of DropEmpty -> AssignEmpty DropExt t v -> AssignExtend (Assignment t) v pattern EmptyAssn :: () => ctx ~ 'EmptyCtx => Assignment f ctx pattern EmptyAssn <- (viewAssign -> AssignEmpty) pattern (:>) :: () => ctx' ~ (ctx '::> tp) => Assignment f ctx -> f tp -> Assignment f ctx' pattern (:>) a v <- (viewAssign -> AssignExtend a v) }}} {{{#!hs {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE PatternSynonyms #-} module Bar (pattern PointerExpr) where import Foo ------------------------------------------------------------------------------- pattern PointerExpr :: Expr tp pattern PointerExpr <- App (RollRecursive (EmptyAssn :> BVRepr) (App _)) ------------------------------------------------------------------------------- data CrucibleType where RecursiveType :: Ctx CrucibleType -> CrucibleType data TypeRepr (tp :: CrucibleType) where BVRepr :: TypeRepr tp TypeReprDummy :: TypeRepr tp data App (f :: CrucibleType -> *) (tp :: CrucibleType) where RollRecursive :: !(Assignment TypeRepr ctx) -> !(Expr tp) -> App f ('RecursiveType ctx) data Expr (tp :: CrucibleType) = App !(App Expr tp) | ExprDummy }}} {{{ $ /opt/ghc/8.4.2/bin/ghc -fforce-recomp -prof -fprof-auto -O Bar.hs [1 of 2] Compiling Foo ( Foo.hs, Foo.o ) [2 of 2] Compiling Bar ( Bar.hs, Bar.o ) ghc: panic! (the 'impossible' happened) (GHC version 8.4.2 for x86_64-unknown-linux): isUnliftedType r_a22f :: TYPE rep_a22e Call stack: CallStack (from HasCallStack): callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable pprPanic, called at compiler/types/Type.hs:1939:10 in ghc:Type Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug $ /opt/ghc/head/bin/ghc -fforce-recomp -prof -fprof-auto -O Bar.hs [1 of 2] Compiling Foo ( Foo.hs, Foo.o ) [2 of 2] Compiling Bar ( Bar.hs, Bar.o ) ghc: panic! (the 'impossible' happened) (GHC version 8.5.20180501 for x86_64-unknown-linux): isUnliftedType r_a256 :: TYPE rep_a255 Call stack: CallStack (from HasCallStack): callStackDoc, called at compiler/utils/Outputable.hs:1162:37 in ghc:Outputable pprPanic, called at compiler/types/Type.hs:1922:10 in ghc:Type Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Profiling | Version: 8.4.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): It turns out that `unsafeCoerce` isn't needed to reproduce the issue, fortunately. I've edited comment:1 accordingly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Profiling | Version: 8.4.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): The problem appears to be caused by the matcher for `PointerExpr`, which is levity polymorphic: {{{#!hs Bar.$mPointerExpr :: forall (r :: TYPE rep) (tp :: CrucibleType). Expr tp -> (GHC.Prim.Void# -> r) -> (GHC.Prim.Void# -> r) -> r }}} This particular form of levity polymorphism should be perfectly fine. However, it seems that the worker-wrapper pass somehow stumbles on to this: {{{ ghc-stage2: panic! (the 'impossible' happened) (GHC version 8.4.1 for x86_64-unknown-linux): isUnliftedType r_a32N :: TYPE rep_a32M Call stack: CallStack (from HasCallStack): callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable pprPanic, called at compiler/types/Type.hs:1951:10 in ghc:Type CallStack (from -prof): WorkWrap.splitFun (compiler/stranal/WorkWrap.hs:(470,1)-(566,42)) WorkWrap.tryWW (compiler/stranal/WorkWrap.hs:(397,1)-(424,65)) WorkWrap.wwBind (compiler/stranal/WorkWrap.hs:(86,1)-(97,76)) WorkWrap.wwTopBinds (compiler/stranal/WorkWrap.hs:(63,1)-(66,30)) SimplCore.WorkWrap (compiler/simplCore/SimplCore.hs:491:40-59) HscMain.Core2Core (compiler/main/HscMain.hs:1212:7-55) HscMain.hscSimplify' (compiler/main/HscMain.hs:(1206,1)-(1212,55)) HscMain.finish (compiler/main/HscMain.hs:(728,1)-(768,70)) HscMain.hscIncrementalCompile (compiler/main/HscMain.hs:(671,1)-(717,52)) GhcMake.upsweep_mod.compile_it (compiler/main/GhcMake.hs:(1457,13)-(1459,66)) GhcMake.upsweep_mod (compiler/main/GhcMake.hs:(1403,1)-(1559,49)) GhcMake.upsweep.upsweep' (compiler/main/GhcMake.hs:(1272,3)-(1371,91)) GhcMake.upsweep (compiler/main/GhcMake.hs:(1254,1)-(1371,91)) GhcMake.load'.upsweep_fn (compiler/main/GhcMake.hs:(393,9)-(394,41)) GhcMake.load'.checkHowMuch (compiler/main/GhcMake.hs:(270,9)-(272,27)) GhcMake.load' (compiler/main/GhcMake.hs:(246,1)-(494,38)) GhcMake.load (compiler/main/GhcMake.hs:(238,1)-(240,44)) GHC.withCleanupSession (compiler/main/GHC.hs:(466,1)-(475,37)) GHC.runGhc (compiler/main/GHC.hs:(441,1)-(446,26)) GHC.defaultErrorHandler (compiler/main/GHC.hs:(381,1)-(413,7)) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Profiling | Version: 8.4.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: T15186 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * testcase: => T15186 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: bgamari Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Profiling | Version: 8.4.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: T15186 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4756, Wiki Page: | Phab:D4757 -------------------------------------+------------------------------------- Changes (by bgamari): * owner: (none) => bgamari * differential: => Phab:D4756, Phab:D4757 * milestone: => 8.6.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: bgamari Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Profiling | Version: 8.4.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: T15186 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4756, Wiki Page: | Phab:D4757 -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15186: ghc 8.4.2 panic in profiling build
-------------------------------------+-------------------------------------
Reporter: kquick | Owner: bgamari
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Profiling | Version: 8.4.2
Resolution: | Keywords:
Operating System: Linux | Architecture: x86_64
Type of failure: Compile-time | (amd64)
crash or panic | Test Case: T15186
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4756,
Wiki Page: | Phab:D4757
-------------------------------------+-------------------------------------
Comment (by simonpj):
Just to fill in a bit more detail, the problem is not with `$mPointerExpr`
itself, but with a local binding within it, namely
{{{
let {
cont_s1eD [Dmd=

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: bgamari Type: bug | Status: patch Priority: normal | Milestone: 8.6.1 Component: Profiling | Version: 8.4.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: T15186 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4755, Wiki Page: | Phab:D4757 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * differential: Phab:D4756, Phab:D4757 => Phab:D4755, Phab:D4757 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15186: ghc 8.4.2 panic in profiling build
-------------------------------------+-------------------------------------
Reporter: kquick | Owner: bgamari
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Profiling | Version: 8.4.2
Resolution: | Keywords:
Operating System: Linux | Architecture: x86_64
Type of failure: Compile-time | (amd64)
crash or panic | Test Case: T15186
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4755,
Wiki Page: | Phab:D4757
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#15186: ghc 8.4.2 panic in profiling build
-------------------------------------+-------------------------------------
Reporter: kquick | Owner: bgamari
Type: bug | Status: patch
Priority: normal | Milestone: 8.6.1
Component: Profiling | Version: 8.4.2
Resolution: | Keywords:
Operating System: Linux | Architecture: x86_64
Type of failure: Compile-time | (amd64)
crash or panic | Test Case: T15186
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D4755,
Wiki Page: | Phab:D4757
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#15186: ghc 8.4.2 panic in profiling build -------------------------------------+------------------------------------- Reporter: kquick | Owner: bgamari Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Profiling | Version: 8.4.2 Resolution: fixed | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: T15186 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4755, Wiki Page: | Phab:D4757 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15186#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC