
#9701: GADTs not specialized properly -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.9 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Runtime | Blocked By: performance bug | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by dfeuer): I think I've figured out what goes wrong here. As the comments in [https://ghc.haskell.org/trac/ghc/browser/ghc/compiler/specialise/Specialise.... the source] explain, there's a certain amount of redundancy between type arguments and dictionary arguments in general. The algorithm therefore ignores the type arguments and focuses on the dictionary arguments. For GADTs, this is not good enough. In particular, we can get something that looks (for a different `isItSilly` definition than the one above) like {{{ GADTDict.isItSillyInt :: GADTDict.Silly GHC.Types.Int -> GADTDict.Silly GHC.Types.Int -> GADTDict.Silly GHC.Types.Int GADTDict.isItSillyInt = \ (ds_dsS :: GADTDict.Silly GHC.Types.Int) (ds1_dsT :: GADTDict.Silly GHC.Types.Int) -> case ds_dsS of _ { GADTDict.Silly $dNum_apb a_ao9 -> case ds1_dsT of _ { GADTDict.Silly $dNum1_apc x_aoa -> GADTDict.Silly @ GHC.Types.Int $dNum1_apc (GHC.Num.+ @ GHC.Types.Int $dNum1_apc a_ao9 x_aoa) } } }}} Here, the compiler doesn't (currently) know what `$dNum1_apc` is; it's something it pulled out of a GADT constructor. But there's more information available: the `GHC.Types.Int` argument forces `$dNum1_apc` to be the `Num` dictionary for `Int`! The fix, presumably, is to recognize when a known (or collected) type argument corresponds to an unknown dictionary—when this happens, replace the dictionary with the right one. What I don't know is whether the necessary information about the correspondence is still readily available at this point. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9701#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler