Skip to content

Panic with unusual foreign function signature

Summary

We get a panic from resultWrapper when a foreign function has a pathologically bizarre type. In practice, this has no real impact on users since no one would ever try to write a foregin function like this, but there's still technically a mistake in the compiler.

Steps to reproduce

Compile this code (optimization level is irrelevant):

{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnliftedFFITypes #-}
{-# LANGUAGE RankNTypes #-}

module NonleadingForallFfiSignature (c_pow) where

import Foreign.C.Types (CDouble(..))
import Data.Kind (Type)

foreign import ccall "math.h pow"
  c_pow :: CDouble
        -> forall (a :: Type). CDouble
        -> forall (b :: Type). CDouble

The result is the following panic:

[1 of 1] Compiling NonleadingForallFfiSignature ( NonleadingForallFfiSignature.hs, NonleadingForallFfiSignature.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.6.5 for x86_64-unknown-linux):
	resultWrapper
  Double -> forall b. Double
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
        pprPanic, called at compiler/deSugar/DsCCall.hs:359:5 in ghc:DsCCall

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Expected behavior

The example code should either compile or fail with an error message. It should not panic.

Environment

  • GHC version used: 8.6.5

Optional:

  • Operating System: Ubuntu 18.04
  • System Architecture: x84_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information