Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,870
    • Issues 4,870
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 453
    • Merge requests 453
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17590
Closed
Open
Created Dec 19, 2019 by Ryan Scott@RyanGlScottMaintainer

HEAD-only panic (coVarKindsTypesRole, non coercion variable) with -O2 and -dcore-lint

This was originally spotted on head.hackage's CI, as this bug prevents the JuicyPixels-3.3.4 library from compiling. Here is a minimized reproducer:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeOperators #-}
module Codec.Picture.Metadata where

import Control.DeepSeq( NFData( .. ) )
import Data.Typeable( (:~:)( Refl ) )
import Data.Word( Word16 )

data ExifTag
  = TagPhotometricInterpretation
  | TagUnknown !Word16
  deriving Eq

data ExifData = ExifNone

data Keys a where
  Exif        :: !ExifTag -> Keys ExifData
  Unknown     :: !String -> Keys Value

data Value

data Elem k =
  forall a. (Show a, NFData a) => !(k a) :=> a

keyEq :: Keys a -> Keys b -> Maybe (a :~: b)
keyEq a b = case (a, b) of
  (Unknown v1, Unknown v2) | v1 == v2 -> Just Refl
  (Exif t1, Exif t2) | t1 == t2 -> Just Refl
  _ -> Nothing

newtype Metadatas = Metadatas { getMetadatas :: [Elem Keys] }

lookup :: Keys a -> Metadatas -> Maybe a
lookup k = go . getMetadatas where
  go [] = Nothing
  go ((k2 :=> v) : rest) = case keyEq k k2 of
    Nothing -> go rest
    Just Refl -> Just v

With GHC 8.10.1 or earlier, this compiles successfully with -O2 and -dcore-lint. On GHC HEAD, however, it panics:

$ ~/Software/ghc5/inplace/bin/ghc-stage2 -O2 -fforce-recomp Bug2.hs -dcore-lint
[1 of 1] Compiling Codec.Picture.Metadata ( Bug2.hs, Bug2.o )
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.11.0.20191217:
        coVarKindsTypesRole, non coercion variable
  wild_X6
  ExifTag
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1173:37 in ghc:Outputable
        pprPanic, called at compiler/types/Coercion.hs:490:4 in ghc:Coercion
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking