script: internal error: scavenge: unimplemented/strange closure type 15894 @ 0x42002342e0
Summary
When running a script, I got an error that asked to be reported here. The intention is that main
is a side effect that produces an audible beep.
Steps to reproduce
Here is the command I ran (it is a cabal command, but in the error it said to report it here):
$ cabal run pad2.hs
Resolving dependencies...
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
- fake-package-0 (exe:script) (first run)
Configuring executable 'script' for fake-package-0..
Preprocessing executable 'script' for fake-package-0..
Building executable 'script' for fake-package-0..
[1 of 1] Compiling Main ( Main.hs, /tmp/cabal-repl.-162891/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fake-package-0/x/script/build/script/script-tmp/Main.o )
Linking /tmp/cabal-repl.-162891/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fake-package-0/x/script/build/script/script ...
ALSA lib pcm_dsnoop.c:641:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
script: internal error: scavenge: unimplemented/strange closure type 15894 @ 0x42002342e0
(GHC version 8.6.5 for x86_64_unknown_linux)
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
Aborted (core dumped)
Here is the source of pad2.hs
:
#!/usr/bin/env cabal
{- cabal:
build-depends: base, bindings-portaudio, vector, derive-storable
-}
{-# LANGUAGE DeriveGeneric #-}
module Main where
import Control.Concurrent
import Data.IORef
import qualified Data.Vector as V
import qualified Data.Vector.Storable.Mutable as MV
import Foreign.Storable.Generic
import GHC.Generics
import System.PortAudio
data Pair a = Pair !a !a deriving (Generic, Generic1)
instance GStorable a => GStorable (Pair a)
instance Functor Pair where
fmap f (Pair x y) = Pair (f x) (f y)
instance Foldable Pair where
foldMap f (Pair x y) = f x <> f y
instance Applicative Pair where
pure x = Pair x x
Pair f g <*> Pair x y = Pair (f x) (g y)
period :: Int
period = 128
table = [sin t | i <- [0..], let t = fromIntegral i / fromIntegral period * 2 * pi]
callback :: IORef [Float] -> Status -> input -> MV.IOVector (Pair Float) -> IO StreamCallbackResult
callback t _ _ o = do
i0 <- readIORef t
i0' <- go i0 0
writeIORef t i0'
return Continue
where
n = MV.length o
go :: [Float] -> Int -> IO [Float]
go i0 i
| i == n = return i0
| otherwise = do
let (v:i0') = i0
MV.write o i $ Pair v v
go i0' (i + 1)
main :: IO ()
main = withPortAudio (do
(_, dev : _) <- getDevices
t <- newIORef table
let output = streamParameters dev 0
withStream 44100 44100 noConnection output mempty (callback t)
$ let w = threadDelay maxBound >> w in w)
I had to install this to get bindings-portaudio
to compile. Also, when I ran it multiple times it would sometimes give different errors in a seemingly random fashion (race conditions?).
Expected behavior
main
should produce an audible beep.
Environment
- GHC version used: 8.6.5
- Operating System: Ubuntu 20.04
- System Architecture: x86_64