Skip to content

GHCi crashes with external interpreter and user defined prompt function

Summary

GHCi crashes in :set prompt-function after switching on or off the external interpreter.

Steps to reproduce

1. Switch off external-interpreter

$ ghci Test.hs -fexternal-interpreter
GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Test             ( Test.hs, interpreted )
Ok, one module loaded.
*Test> :set prompt-function myprompt
ghc: this operation requires -fno-external-interpreter
*Test> :set -fno-external-interpreter
*Test> :set prompt-function myprompt
ghc-iserv: {handle: <file descriptor: 23>}: GHCi.Message.remoteCall: end of file
Speicherzugriffsfehler

Speicherzugriffsfehler is the German word for access violation.

2. Switch on external-interpreter

$ ghci Test.hs
GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Test             ( Test.hs, interpreted )
Ok, one module loaded.
*Test> :set prompt-function myprompt
*Test 2_: :set -fexternal-interpreter
*Test 3_: :set prompt-function myprompt
ghc: ghc-iserv terminated (-11)
Leaving GHCi.

The contents of Test.hs is:

import Data.List (intersperse)

myprompt :: [String] -> Int -> IO String
myprompt mod_names stmt_nr =
    return $ concat (intersperse " " mod_names) ++ " " ++ show stmt_nr ++ "_: "

Expected behavior

  • GHCi should not crash, ghc-iserv should not terminate.
  • Don't allow the use of :set -fexternal-interpreter or :set -fno-external-interpreter in the middle of a GHCi session. Both flags should be command-line only.

Environment

  • GHC version used: 8.10.2

Optional:

  • Operating System: Debian GNU/Linux 10
  • System Architecture: x86-64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information