aarch64 compilation error
This is the simplest example I could reproduce with. In particular, it matters that Trans
and runTrans
are in different modules, and that we use -O1
.
Code below can also be found on GitHub. The same issue exists on master
at 81cb08e (and most previous commits) but that's a lot more complex.
Compiler was built with ghcup compile ghc -v 9.2.1 -b 8.10.7 -x aarch64-none-linux-gnu -c $(pwd)/build.mk
on an x86_64 Manjaro Linux host, using the gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz
toolchain from the official ARM distribution.
build.mk
:
V=0
BUILD_MAN = NO
BUILD_SPHINX_HTML = NO
BUILD_SPHINX_PDF = NO
Stage1Only = YES
HADDOCK_DOCS = NO
BuildFlavour = quick
WITH_TERMINFO = NO
BIGNUM_BACKEND = native
Main.hs
:
import Control.Monad
import Control.Monad.Except
import Control.Monad.State
import Control.Monad.Trans.Maybe
import Lib
main :: IO ()
main = go ()
where
go () =
maybe (go ()) pure
=<< runTrans
( (\() -> void $ liftIO $ pure ())
=<< liftIO (pure ())
)
runTrans :: Trans IO a -> IO (Maybe a)
runTrans (Trans x) = runMaybeT $ evalStateT x ()
Lib.hs
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Lib where
import Control.Monad.Except
import Control.Monad.State
import Control.Monad.Trans.Maybe
newtype Trans m a
= Trans
( StateT
()
( MaybeT
m
)
a
)
deriving newtype
( Functor
, Applicative
, Monad
, MonadIO
)
Log:
$ aarch64-none-linux-gnu-ghc-9.2.1 -O1 Main.hs -outputdir dist
[1 of 2] Compiling Lib ( Lib.hs, dist/Lib.o )
[2 of 2] Compiling Main ( Main.hs, dist/Main.o )
ghc: panic! (the 'impossible' happened)
(GHC version 9.2.1:
refineFromInScope
InScope {wild_00 main eta_B0 wild_X1E wild_a15Z y_a161 ds1_a1IJ
ipv_a1IK ipv1_a1IL ds_d1I4 main $trModule main_s2pH $trModule_s2pI
$trModule_s2pJ $trModule_s2pK $trModule_s2pL go_s2pM main_s2pN
lvl_s2pO lvl_s2pP lvl_s2pQ lvl_s2pR lvl_s2pS lvl_s2pT $j_s2pW}
s'_a16E
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Core/Opt/Simplify/Env.hs:706:30 in ghc:GHC.Core.Opt.Simplify.Env
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Verbose log:
$ aarch64-none-linux-gnu-ghc-9.2.1 -O1 Main.hs -outputdir dist -v
Glasgow Haskell Compiler, Version 9.2.1, stage 1 booted by GHC version 8.10.7
*** initializing unit database:
Using binary package database: /home/gthomas/.ghcup/ghc/aarch64-none-linux-gnu-9.2.1/lib/aarch64-none-linux-gnu-ghc-9.2.1/package.conf.d/package.cache
package flags []
loading package database /home/gthomas/.ghcup/ghc/aarch64-none-linux-gnu-9.2.1/lib/aarch64-none-linux-gnu-ghc-9.2.1/package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.8.0
wired-in package ghc-bignum mapped to ghc-bignum-1.2
wired-in package base mapped to base-4.16.0.0
wired-in package rts mapped to rts
wired-in package template-haskell mapped to template-haskell-2.18.0.0
wired-in package ghc not found.
!!! initializing unit database: finished in 21.95 milliseconds, allocated 3.741 megabytes
*** initializing unit database:
package flags []
loading package database /home/gthomas/.ghcup/ghc/aarch64-none-linux-gnu-9.2.1/lib/aarch64-none-linux-gnu-ghc-9.2.1/package.conf.d
wired-in package ghc-prim mapped to ghc-prim-0.8.0
wired-in package ghc-bignum mapped to ghc-bignum-1.2
wired-in package base mapped to base-4.16.0.0
wired-in package rts mapped to rts
wired-in package template-haskell mapped to template-haskell-2.18.0.0
wired-in package ghc not found.
!!! initializing unit database: finished in 2.68 milliseconds, allocated 2.055 megabytes
*** Chasing dependencies:
Chasing modules from: Main.hs
!!! Chasing dependencies: finished in 2.27 milliseconds, allocated 2.021 megabytes
Stable obj: {}
Stable BCO: {}
Ready for upsweep
[NONREC
ModSummary {
ms_hs_date = 2021-11-12 13:31:42.396878746 UTC
ms_mod = Lib,
ms_textual_imps = [(Nothing, Prelude),
(Nothing, Control.Monad.Trans.Maybe),
(Nothing, Control.Monad.State), (Nothing, Control.Monad.Except)]
ms_srcimps = []
} [],
NONREC
ModSummary {
ms_hs_date = 2021-11-12 13:36:22.614284008 UTC
ms_mod = Main,
ms_textual_imps = [(Nothing, Prelude), (Nothing, Lib),
(Nothing, Control.Monad.Trans.Maybe),
(Nothing, Control.Monad.State), (Nothing, Control.Monad.Except),
(Nothing, Control.Monad)]
ms_srcimps = []
} []]
*** Deleting temp files:
Deleting:
compile: input file ./Lib.hs
*** Checking old interface for Lib (use -ddump-hi-diffs for more details):
[1 of 2] Compiling Lib ( Lib.hs, dist/Lib.o )
*** Parser [Lib]:
!!! Parser [Lib]: finished in 0.41 milliseconds, allocated 0.607 megabytes
*** Renamer/typechecker [Lib]:
!!! Renamer/typechecker [Lib]: finished in 52.34 milliseconds, allocated 28.821 megabytes
*** Desugar [Lib]:
Result size of Desugar (before optimization)
= {terms: 406, types: 1,422, coercions: 456, joins: 0/58}
Result size of Desugar (after optimization)
= {terms: 242, types: 472, coercions: 154, joins: 0/0}
!!! Desugar [Lib]: finished in 4.81 milliseconds, allocated 5.071 megabytes
*** Simplifier [Lib]:
Result size of Simplifier iteration=1
= {terms: 368, types: 763, coercions: 548, joins: 0/12}
Result size of Simplifier iteration=2
= {terms: 337, types: 634, coercions: 343, joins: 0/7}
Result size of Simplifier
= {terms: 333, types: 610, coercions: 274, joins: 0/7}
!!! Simplifier [Lib]: finished in 6.59 milliseconds, allocated 8.722 megabytes
*** Specialise [Lib]:
Result size of Specialise
= {terms: 333, types: 610, coercions: 274, joins: 0/7}
!!! Specialise [Lib]: finished in 0.30 milliseconds, allocated 0.465 megabytes
*** Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = False}) [Lib]:
Result size of Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = False})
= {terms: 335, types: 615, coercions: 274, joins: 0/8}
!!! Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = False}) [Lib]: finished in 1.20 milliseconds, allocated 1.314 megabytes
*** Simplifier [Lib]:
Result size of Simplifier iteration=1
= {terms: 479, types: 961, coercions: 326, joins: 0/19}
Result size of Simplifier iteration=2
= {terms: 455, types: 893, coercions: 366, joins: 0/11}
Result size of Simplifier iteration=3
= {terms: 451, types: 883, coercions: 352, joins: 0/9}
Result size of Simplifier
= {terms: 451, types: 883, coercions: 352, joins: 0/9}
!!! Simplifier [Lib]: finished in 8.09 milliseconds, allocated 7.957 megabytes
*** Simplifier [Lib]:
Result size of Simplifier
= {terms: 451, types: 883, coercions: 352, joins: 0/9}
!!! Simplifier [Lib]: finished in 1.80 milliseconds, allocated 1.811 megabytes
*** Simplifier [Lib]:
Result size of Simplifier
= {terms: 451, types: 883, coercions: 352, joins: 0/9}
!!! Simplifier [Lib]: finished in 1.51 milliseconds, allocated 1.811 megabytes
*** Float inwards [Lib]:
Result size of Float inwards
= {terms: 451, types: 883, coercions: 352, joins: 0/9}
!!! Float inwards [Lib]: finished in 0.29 milliseconds, allocated 0.634 megabytes
*** Called arity analysis [Lib]:
Result size of Called arity analysis
= {terms: 451, types: 883, coercions: 352, joins: 0/9}
!!! Called arity analysis [Lib]: finished in 0.46 milliseconds, allocated 0.378 megabytes
*** Simplifier [Lib]:
Result size of Simplifier iteration=1
= {terms: 451, types: 883, coercions: 352, joins: 0/9}
Result size of Simplifier
= {terms: 445, types: 881, coercions: 352, joins: 0/9}
!!! Simplifier [Lib]: finished in 20.99 milliseconds, allocated 3.610 megabytes
*** Demand analysis [Lib]:
Result size of Demand analysis
= {terms: 445, types: 881, coercions: 352, joins: 0/9}
!!! Demand analysis [Lib]: finished in 0.67 milliseconds, allocated 1.069 megabytes
*** Constructed Product Result analysis [Lib]:
Result size of Constructed Product Result analysis
= {terms: 445, types: 881, coercions: 352, joins: 0/9}
!!! Constructed Product Result analysis [Lib]: finished in 0.31 milliseconds, allocated 0.263 megabytes
*** Worker Wrapper binds [Lib]:
Result size of Worker Wrapper binds
= {terms: 462, types: 932, coercions: 352, joins: 0/13}
!!! Worker Wrapper binds [Lib]: finished in 0.17 milliseconds, allocated 0.153 megabytes
*** Simplifier [Lib]:
Result size of Simplifier iteration=1
= {terms: 456, types: 926, coercions: 352, joins: 0/11}
Result size of Simplifier
= {terms: 444, types: 903, coercions: 352, joins: 0/8}
!!! Simplifier [Lib]: finished in 4.45 milliseconds, allocated 4.173 megabytes
*** Exitification transformation [Lib]:
Result size of Exitification transformation
= {terms: 444, types: 903, coercions: 352, joins: 0/8}
!!! Exitification transformation [Lib]: finished in 0.08 milliseconds, allocated 0.117 megabytes
*** Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = True}) [Lib]:
Result size of Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = True})
= {terms: 456, types: 938, coercions: 352, joins: 0/12}
!!! Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = True}) [Lib]: finished in 1.50 milliseconds, allocated 2.020 megabytes
*** Common sub-expression [Lib]:
Result size of Common sub-expression
= {terms: 450, types: 920, coercions: 352, joins: 0/12}
!!! Common sub-expression [Lib]: finished in 0.49 milliseconds, allocated 0.634 megabytes
*** Float inwards [Lib]:
Result size of Float inwards
= {terms: 446, types: 910, coercions: 352, joins: 0/10}
!!! Float inwards [Lib]: finished in 0.37 milliseconds, allocated 0.630 megabytes
*** Simplifier [Lib]:
Result size of Simplifier iteration=1
= {terms: 444, types: 908, coercions: 352, joins: 0/10}
Result size of Simplifier
= {terms: 444, types: 908, coercions: 352, joins: 0/10}
!!! Simplifier [Lib]: finished in 4.05 milliseconds, allocated 4.074 megabytes
*** Demand analysis [Lib]:
Result size of Demand analysis
= {terms: 444, types: 908, coercions: 352, joins: 0/10}
!!! Demand analysis [Lib]: finished in 0.78 milliseconds, allocated 1.146 megabytes
*** CoreTidy [Lib]:
Result size of Tidy Core
= {terms: 444, types: 908, coercions: 352, joins: 0/10}
!!! CoreTidy [Lib]: finished in 0.87 milliseconds, allocated 1.005 megabytes
Created temporary directory: /tmp/ghc123636_0
*** CorePrep [Lib]:
Result size of CorePrep
= {terms: 625, types: 1,303, coercions: 352, joins: 0/76}
!!! CorePrep [Lib]: finished in 1.28 milliseconds, allocated 1.811 megabytes
*** CoreToStg [Lib]:
*** Stg2Stg:
!!! CoreToStg [Lib]: finished in 1.93 milliseconds, allocated 0.683 megabytes
*** CodeGen [Lib]:
!!! CodeGen [Lib]: finished in 21.35 milliseconds, allocated 34.237 megabytes
*** WriteIface [dist/Lib.hi]:
writeBinIface: 55 Names
writeBinIface: 128 dict entries
!!! WriteIface [dist/Lib.hi]: finished in 1.16 milliseconds, allocated 1.247 megabytes
*** systool:as:
*** Assembler:
aarch64-none-linux-gnu-gcc -iquote. -Idist -no-pie -fPIC -U__PIC__ -D__PIC__ -x assembler -c /tmp/ghc123636_0/ghc_2.s -o dist/Lib.o.tmp
!!! systool:as: finished in 0.42 milliseconds, allocated 0.118 megabytes
*** Deleting temp files:
Deleting: /tmp/ghc123636_0/ghc_1.s /tmp/ghc123636_0/ghc_2.s /tmp/ghc123636_0/ghc_3.c
Warning: deleting non-existent /tmp/ghc123636_0/ghc_1.s
Warning: deleting non-existent /tmp/ghc123636_0/ghc_3.c
compile: input file Main.hs
*** Checking old interface for Main (use -ddump-hi-diffs for more details):
[2 of 2] Compiling Main ( Main.hs, dist/Main.o )
*** Parser [Main]:
!!! Parser [Main]: finished in 0.39 milliseconds, allocated 0.574 megabytes
*** Renamer/typechecker [Main]:
!!! Renamer/typechecker [Main]: finished in 3.86 milliseconds, allocated 3.005 megabytes
*** Desugar [Main]:
Result size of Desugar (before optimization)
= {terms: 86, types: 118, coercions: 3, joins: 0/15}
Result size of Desugar (after optimization)
= {terms: 66, types: 93, coercions: 3, joins: 0/5}
!!! Desugar [Main]: finished in 1.02 milliseconds, allocated 1.158 megabytes
*** Simplifier [Main]:
Result size of Simplifier iteration=1
= {terms: 192, types: 402, coercions: 220, joins: 0/4}
Result size of Simplifier iteration=2
= {terms: 117, types: 236, coercions: 116, joins: 0/0}
Result size of Simplifier iteration=3
= {terms: 119, types: 246, coercions: 125, joins: 0/0}
Result size of Simplifier
= {terms: 117, types: 243, coercions: 119, joins: 0/0}
!!! Simplifier [Main]: finished in 18.27 milliseconds, allocated 17.439 megabytes
*** Specialise [Main]:
Result size of Specialise
= {terms: 117, types: 243, coercions: 119, joins: 0/0}
!!! Specialise [Main]: finished in 0.22 milliseconds, allocated 0.174 megabytes
*** Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = False}) [Main]:
Result size of Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = False})
= {terms: 129, types: 311, coercions: 119, joins: 0/0}
!!! Float out(FOS {Lam = Just 0,
Consts = True,
OverSatApps = False}) [Main]: finished in 1.04 milliseconds, allocated 0.531 megabytes
*** Simplifier [Main]:
*** Deleting temp files:
Deleting:
*** Deleting temp dirs:
Deleting: /tmp/ghc123636_0
ghc: panic! (the 'impossible' happened)
(GHC version 9.2.1:
refineFromInScope
InScope {wild_00 main eta_B0 wild_X1E wild_a15Z y_a161 ds1_a1IK
ipv_a1IL ipv1_a1IM ds_d1I5 main $trModule main_s2pI $trModule_s2pJ
$trModule_s2pK $trModule_s2pL $trModule_s2pM go_s2pN main_s2pO
lvl_s2pP lvl_s2pQ lvl_s2pR lvl_s2pS lvl_s2pT lvl_s2pU $j_s2pX}
s'_a16E
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Core/Opt/Simplify/Env.hs:706:30 in ghc:GHC.Core.Opt.Simplify.Env
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug