Skip to content

"ghc-iserv terminated (-11)" with `-fobject-code -fexternal-interpreter`

Summary

I consistently get a crash using -fexternal-interpreter, with ghc 8.10.{1,2} on a mac. ghc 8.8.4 does not suffer from this issue, and neither does any ghc on my NixOS machine.

Steps to reproduce

(See #18911 (comment 310528) for a much simpler example)

(For background: I have been minimising a test case at https://gist.github.com/brprice/52b2e6e868b5127bf2a1976349cd4fa6, but reading that is not needed to understand this report)

Consider the two files

-- OIOT.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-} -- This is needed to trigger the bug!
module OIOT where

type OpticKind = *

-- | Tag for a lens.
data A_Lens :: OpticKind
-- DTO.hs

{-# LANGUAGE KindSignatures  #-}
{-# LANGUAGE DataKinds #-}

module Data.Tuple.Optics
  (
    Field1(_1)
  ) where

import OIOT

data Optic (k :: OpticKind) a = O

class Field1 a where -- it seems to be important to have a class to trigger the bug
  _1 :: Optic A_Lens a

[These names are because this has been minimised from some code using optics]

We first compile OIOT, then load DTO with ghci+external-intepreter, which crashes as soon as :print a term from DTO:

$ ghc OIOT
[1 of 1] Compiling OIOT             ( OIOT.hs, OIOT.o )

$ ghci -fexternal-interpreter DTO.hs 
GHCi, version 8.10.1: https://www.haskell.org/ghc/  :? for help
[2 of 2] Compiling Data.Tuple.Optics ( DTO.hs, interpreted )
Ok, two modules loaded.
*Data.Tuple.Optics> :print _1
ghc: ghc-iserv terminated (-11)
Leaving GHCi.

The separation into two modules is necessary to trigger the bug: inlining OIOT into DTO avoids it (whether compiled or interpreted). It also seems necessary to compile OIOT, but it doesn't matter if we compile DTO or not. Alternatively to a separate compiliation step, ghc -fobject-code -fexternal-interpreter DTO will show the bug.

The gist https://gist.github.com/brprice/52b2e6e868b5127bf2a1976349cd4fa6 contains these files and some nix-expressions to obtain ghc-8.10.2 (one via haskell.nix, one via nixpkgs, because before I had boiled it down this far only the haskell.nix ghc was tickling this bug).

Expected behavior

Without -fexternal-interpreter, everything behaves as expected (no crashes):

$ ghc OIOT
[1 of 1] Compiling OIOT             ( OIOT.hs, OIOT.o )

$ ghci DTO.hs 
GHCi, version 8.10.1: https://www.haskell.org/ghc/  :? for help
[1 of 2] Compiling OIOT             ( OIOT.hs, interpreted )
[2 of 2] Compiling Data.Tuple.Optics ( DTO.hs, interpreted )
Ok, two modules loaded.
*Data.Tuple.Optics> :print _1
_1 = (_t1::t1)
*Data.Tuple.Optics>

Environment

  • GHC version used: 8.10.1 and 8.10.2 have this bug, 8.8.4 does not
  • Operating System: The Mac reports:
$ uname -a
Darwin turing 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64
$ sw_vers
ProductName:       Mac OS X
ProductVersion:    10.15.7
BuildVersion:      19H2
$ ghc -V
 The Glorious Glasgow Haskell Compilation System, version 8.10.2

This bug does not show up on my NixOS box.

Edited by Ben Price
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information