Quantified constraints block specialization (minimized example!)
## Summary
GHC in the following program fails to specialize `(+)` and `fromInteger`.
```
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE TypeData #-}
import Data.Kind (Type)
data Phantom (sh :: Type) = Phantom -- newtype fails to specialise as well
instance Show (Phantom sh) where
show Phantom = "show"
type Foo r = (forall sh. Show (Phantom sh), Num r)
-- this specialises fine:
-- type Foo r = (Num r)
type data TK = TKScalar Type
data AstTensor :: TK -> Type where
AstInt :: Int -> AstTensor (TKScalar Int)
AstPlus :: Foo r => AstTensor (TKScalar r) -> AstTensor (TKScalar r)
plusConcrete :: Foo r => r -> r
plusConcrete = (+ 1)
interpret :: AstTensor (TKScalar Int) -> Int
interpret v0 = case v0 of
AstInt n -> n
AstPlus u -> plusConcrete (interpret u)
main = print $ interpret (AstPlus (AstInt 2))
```
## Steps to reproduce
Search for `dNum` below.
```
~$ ghc -O1 -fforce-recomp -dno-typeable-binds -dsuppress-all -dsuppress-uniques -ddump-simpl --make specBug.hs
[1 of 2] Compiling Main ( specBug.hs, specBug.o )
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 107, types: 155, coercions: 27, joins: 0/1}
$fShowPhantom4 = "show"#
$fShowPhantom3 = unpackCString# $fShowPhantom4
$fShowPhantom_$cshow
= \ @sh ds -> case ds of { Phantom -> $fShowPhantom3 }
$fShowPhantom5 = "show"#
$fShowPhantom_$cshowsPrec
= \ @sh _ x s ->
case x of { Phantom -> unpackAppendCString# $fShowPhantom4 s }
$fShowPhantom2 = "show"#
$fShowPhantom1
= \ @sh x s ->
case x of { Phantom -> unpackAppendCString# $fShowPhantom4 s }
$fShowPhantom_$cshowList
= \ @sh ls s -> showList__ $fShowPhantom1 ls s
$fShowPhantom
= \ @sh ->
C:Show
$fShowPhantom_$cshowsPrec
$fShowPhantom_$cshow
$fShowPhantom_$cshowList
lvl = IS 1#
Rec {
interpret
= \ v0 ->
case v0 of {
AstInt co n -> n;
AstPlus @r co $dCTuple2 u ->
let { $dNum = $p1CTuple2 ($dCTuple2 `cast` <Co:9> :: ...) } in
+ $dNum
(interpret (u `cast` <Co:5> :: ...))
(fromInteger $dNum lvl)
}
end Rec }
main6 = ($fShowPhantom, $fNumInt)
main5 = I# 2#
main4 = AstInt @~<Co:2> :: ... main5
main3 = AstPlus @~<Co:2> :: ... main6 main4
main2 = case interpret main3 of { I# n -> itos n [] }
main1 = \ eta -> hPutStr2 stdout main2 True eta
main = main1 `cast` <Co:3> :: ...
main7 = runMainIO1 (main1 `cast` <Co:3> :: ...)
main = main7 `cast` <Co:3> :: ...
[2 of 2] Linking specBug [Objects changed]
```
## Expected behavior
`(+)` and `fromInteger` get specialised to `Int`, which now can be accomplished only by simplifying 'Foo`.
## Environment
* GHC version used: 9.14.1, HEAD
Optional:
* Operating System: Ubuntu
* System Architecture: amd64
issue