Regression in GHC 9.6.1: spurious "Redundant constraint", where the constraint is inside a quantified constraint
Summary
GHC 9.6.1 with this commit
https://github.com/Mikolaj/horde-ad/commit/0152cfac4569ade762e4aa0bd7fda661ee94a6f5
and cabal test simplifiedOnlyTest
[Edit: and --allow-newer
] emit hundreds of Redundant constraint: KnownNat x
warnings that are wrong and refer to one of these three x
variables:
OTOH, GHC 9.4.5 [Edit: with no --allow-newer
]. compiles a very similar commit (the reason it can't compile the same commit will be described in another ticket)
https://github.com/Mikolaj/horde-ad/commit/da16d0d4650f96e70917ea39dc830bd39c103734
without even a single such warning. The supposedly redundant constraints are necessary to compile the code, under both GHC versions.
Steps to reproduce
Clone and check out the commits, build, inspect the log.
Expected behavior
I'd expect no such warning.
Environment
- GHC version used: 9.6.1 vs 9.4.5
BTW, I have reasons to suspect GHC 9.4.5 can't specialize this code (e.g., it executes it slower) and that, if it would, it would complain similarly. So GHC 9.6.1 may be more correct under the hood, though the spurious warning makes it appear as a regression in behaviour.
Edit: if that helps, here's a commit that exhibits the same behaviour as above, but works for both GHC 9.4.5 and 9.6.1: https://github.com/Mikolaj/horde-ad/commit/c65e21b671edc94d492a1f9c928afa0ac1465de0
Edit2: and here is yet another one that does not require ImpredicativeTypes
: https://github.com/Mikolaj/horde-ad/commit/bc734c7dbe11daeb98b377872f6f25e63c73dd34