PUBLIC
> I'm not surprised that eventually it crashes and burns, because,
> again, I have only declared my DFunId ('$fShowOrderPolicy' in this
> case), but never defined it. Its definition would be a CoreExpr,
> right? So where would I put the pair of '(dfun,
> myCoreExprOfTheRightType)' for GHC to pick it up? Or is it the case
> that GHC would only need an 'Id's definition if it is trying to
> inline/specialize it, i.e. should I just attach the definition to the
> DFunId as an unfolding? Or is 'registerModule' already incomplete and
> it should put the 'CoreProgram' of the module to somewhere deep in the
> GHC state?
I tried adding a reasonable-looking unfolding to the DFun, but I am
still getting the same error when compiling code that uses the instance:
$fShowOrderPolicy [InlPrag=CONLIKE] :: Show OrderPolicy
[LclIdX[DFunId],
Unf=DFun: \ ->
C:Show \ _ [Occ=Dead] -> unpackCStringUtf8# "foo"#
\ _ [Occ=Dead] _ [Occ=Dead] _ [Occ=Dead] -> unpackCStringUtf8# "bar"#
\ _ [Occ=Dead] _ [Occ=Dead] -> unpackCStringUtf8# "baz"#]
panic! (the 'impossible' happened)
GHC version 9.3.20211130:
lookupIdSubst
$fShowOrderPolicy
InScope {foo mapM_}
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc-lib-0.20211130-7QA7vLTw0OYJmMsraoHe3v:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Core/Subst.hs:260:17 in ghc-lib-0.20211130-7QA7vLTw0OYJmMsraoHe3v:GHC.Core.Subst
I have added a minimal working reproducer to
https://gitlab.haskell.org/ghc/ghc/-/issues/21080
So the question remains, where do I need to put the DFun's definition
(a CoreExpr of the right type) for it to be usable as an instance?
Thanks,
Gergo