HEAD crash with "Template variable unbound in rewrite rule"
Edit: a greatly minimized version is at https://github.com/sheaf/ghc-26682 and a slightly minimized version is on branch repro-UNPACK2.
Summary
I'm getting many alike errors, the last of which reads
[11 of 12] Compiling TestMnistRNNS ( test/simplified/TestMnistRNNS.hs, dist-newstyle/build/x86_64-linux/ghc-9.15.20251212/horde-ad-0.3.0.0/l/testCommonLibrary/build/testCommonLibrary/TestMnistRNNS.o, dist-newstyle/build/x86_64-linux/ghc-9.15.20251212/horde-ad-0.3.0.0/l/testCommonLibrary/build/testCommonLibrary/TestMnistRNNS.dyn_o )
<no location info>: error:
panic! (the 'impossible' happened)
GHC version 9.15.20251212:
Template variable unbound in rewrite rule
Variable: $dKnownShS_s1cQdq :: ShS
('(:) @Nat width_a1cMgj ('(:) @Nat SizeMnistHeight ('[] @Nat)))
Rule bndrs: [width_a1cMgj, $dKnownShS_s1cQdq, $dKnownShS_s1cTVC,
$dNumScalar_s1cTVB, $dBaseTensor_s1cTVA]
LHS args: [TYPE: '(:)
@Nat width_a1cMgj ('(:) @Nat SizeMnistHeight ('[] @Nat)),
TYPE: Double, TYPE: Concrete, $dKnownShS_s1cTVC,
$dNumScalar_s1cTVB, $dBaseTensor_s1cTVA]
Actual args: [TYPE: '(:)
@Nat width_a1cMvH ('(:) @Nat SizeMnistHeight ('[] @Nat)),
TYPE: Double, TYPE: Concrete,
C:KnownShS
@('(:) @Nat width_a1cMvH ('(:) @Nat SizeMnistHeight ('[] @Nat)))
$dKnownShS_s1cQ5E,
$dNumScalar_s1cPQO, $fBaseTensorConcrete, range_s1cVXr,
lvl_s1cVXq
`cast` (Sym N:StdGen :: (SMGen :: Type) ~R# (StdGen :: Type))]
Call stack:
CallStack (from HasCallStack):
pprPanic, called at compiler/GHC/Core/Rules.hs:794:10 in ghc-9.15-inplace:GHC.Core.Rules
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Interestingly, removing the only UNPACK pragma from package ox-arrays is a workaround for this issue (a workaround which I use successfully for some days now, but it lowers performance of horde-ad a bit, unfortunately). Here's how the UNPACK looks like (it unpacks a SNat; I hope this does not interfere with how typing plugins work).
ConsKnown :: forall n sh i. {-# UNPACK #-} SNat n -> ListH sh i -> ListH (Just n : sh) i
BTW, the error message looks similar to the one in #13882.
Steps to reproduce
git clone git@github.com:Mikolaj/horde-ad.git
cd horde-ad
git checkout repro-UNPACK
cabal update
cabal build testCommonLibrary --enable-optimization --allow-newer -w /home/mikolaj/r/ghc.Andreas3/ghc/_build/stage1/bin/ghc --constraint=ghc-typelits-natnormalise==0.9.1
This is not minimized in any way so far, except that -fpolymorphic-specialisation is removed and it still repros.
Expected behavior
Compiles.
Environment
- GHC version used: 9.15.20251212 and others
Optional:
- Operating System: Ubuntu
- System Architecture: amd64