Draft: Fix unusable unpack warning on UnliftedType
I fixed a wrongly emitted warning regarding the UNPACK
pragma. I discovered it in relation to #20204.
In that issue there was the problem that data Test = TestCon {-# UNPACK #-} IntU
wrongly claimed that a bang was required to use the pragma. However, IntU was an UnliftedType
and therefore the bang does not make sense. This problem has been fixed but another related issue came up. Namely, GHC currently reports the UNPACK
as being unusable, but in the case of IntU
that is not the case, because (IIRC) IntU
is still a box, it just always contains a value. Therefore the UNPACK
removing a level of indirection is certainly valid. I fixed this by adding a check that if HsLazy
-types (i.e. they're was no bang) are unlifted and not primitive, then the UNPACK
still make sense.
The not primitive
part is important such that {-# UNPACK #-} Int#
is still reported as unusable. I am only mildly certain that that predicate is precise enough. (Let's see what the testsuite says)
I also added the described situations in two extra tests.
I do believe that if this change is accepted, #20204 has been resolved entirely.