Skip to content

ModuleOrigin SemiGroup instance looks incorrect

An issue was reported on IRC:

08:38 <hololeap> there's a transient bug that we're getting while compiling some packages using ghc-9.0.2 in gentoo. here's the full build output: http://sprunge.us/N4z2Ni?text
08:38 <hololeap> you can see the panic at line 114
08:38 <hololeap> this is using ghc patched with this commit: https://gitlab.haskell.org/ghc/ghc/-/commit/c7e801991dc9d4f702e92caf6d6347bbff6a8f3c
08:39 <hololeap> I'm wondering what could be the underlying cause of this panic and how we can debug it further
08:48 <hololeap> it looks like the ModuleOrigins would have to both be ModUnusable to produce this output: https://hackage.haskell.org/package/ghc-9.0.2/docs/src/GHC.Unit.State.html#line-197
08:48 <hololeap> how can we determine what is broken and how to fix it in this scenario?

See also: https://github.com/gentoo-haskell/gentoo-haskell/issues/1250

The relevant part of the build output is:

112 Preprocessing library for singletons-th-3.0..
113 Building library for singletons-th-3.0..
114 ghc: panic! (the 'impossible' happened)
115   (GHC version 9.0.2:
116 	ModOrigin: hidden module redefined
117   x: unusable module
118   y: unusable module
119   Call stack:
120       CallStack (from HasCallStack):
121         callStackDoc, called at compiler/GHC/Utils/Outputable.hs:1230:37 in ghc:GHC.Utils.Outputable
122         pprPanic, called at compiler/GHC/Unit/State.hs:239:14 in ghc:GHC.Unit.State
123 
124 Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug

#16996 (closed) and #11050 (closed) report similar issues.

The failures are all due to the partiality of the Semigroup instance of ModuleOrigin which was added in 20787529

Its Monoid instance looks dubious too (mempty is a ModOrigin...).

I would suggest removing both instances and then defining and using:

newtype ModuleOrigins
  = ModuleOrigins [ModuleOrigin]
  deriving (Monoid,Semigroup)

And then let lookupModule* functions deal with hidden/unusable/multiple module/units as they already do to some extent.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information