`(Prelude.$)` under Unrestricted data causes GHCi panic with `LinearTypes`
Summary
GHC 9.4.7 SEGVs when (Prelude.$)
is used under unrestricted modality Ur
when LinearTypes
enabled.
Steps to reproduce
Complete exmaple is accessible in GitHub.
- Save the following as
Main.hs
:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LinearTypes #-}
module Main (main) where
data Ur a where
Ur :: a -> Ur a
unur :: Ur a -> a
unur (Ur a) = a
segvGHCi :: Ur ()
segvGHCi = Ur $ ()
main :: IO ()
main = print (unur segvGHCi)
The binary compiled by GHC just works as expected:
$ cabal run
()
OTOH, calling main
from GHCi makes GHC panic!
$ cabal repl --repl-no-load
Build profile: -w ghc-9.4.7 -O1
In order, the following will be built (use -v for more details):
- linear-dollar-segv-ghci-0.1.0.0 (exe:linear-dollar-segv-ghci) (ephemeral targets)
Preprocessing executable 'linear-dollar-segv-ghci' for linear-dollar-segv-ghci-0.1.0.0..
GHCi, version 9.4.7: https://www.haskell.org/ghc/ :? for help
Some flags have not been recognized: prompt2, ghci|
Loaded GHCi configuration from /Users/hiromi/.dotfiles/.ghci
Loaded GHCi configuration from /Users/hiromi/Documents/Programming/Haskell/git/linear-dollar-segv-ghci/.ghci
[Prelude]
ghci> :l Main
[1 of 2] Compiling Main ( src/Main.hs, interpreted )
Ok, one module loaded.
[*Main]
ghci> main
Error: cabal: repl failed for exe:linear-dollar-segv-ghci from
linear-dollar-segv-ghci-0.1.0.0. The build process segfaulted (i.e. SIGSEGV).
If we omit $
in the segvGHCi
, everything works fine also on GHCi.
Expected behavior
GHCi should just print:
()
Environment
- GHC version used: 9.4.7 (and also 9.4.5)
- OTOH, GHC 9.6.2 won't panic with this example.
Optional:
- Operating System: macOS Ventura 13.5.2 (22G91)
- System Architecture: MacBook Pro 15-inch 2019 (2.6 GHz 6 cores Intel Core i7)