
#5835: Make better use of known dictionaries -------------------------------------+------------------------------------- Reporter: rl | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 7.5 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.0.1 => 8.2.1 Old description:
Example:
{{{ {-# LANGUAGE GADTs #-} module T5835 where
data T a where T :: Eq a => a -> T a
foo :: a -> T a -> Bool {-# INLINE foo #-} foo x = \(T y) -> x == y
appl :: (a -> b) -> a -> b {-# NOINLINE appl #-} appl f x = f x
bar :: T Int -> Bool bar t = appl (foo 42) t }}}
GHC generates this for `bar`:
{{{ bar2 :: Int bar2 = I# 42
bar1 :: T Int -> Bool bar1 = \ (ds_dhk :: T Int) -> case ds_dhk of _ { T $dEq_agz y_aa4 -> == @ Int $dEq_agz bar2 y_aa4 }
bar :: T Int -> Bool bar = \ (t_aga :: T Int) -> appl @ (T Int) @ Bool bar1 t_aga }}}
Note how it want to get the `Eq` dictionary for `Int` from `T`. But we know the `Eq Int` instance without inspecting `T` and `bar` could be significantly simplified if we used that.
New description: Example: {{{#!hs {-# LANGUAGE GADTs #-} module T5835 where data T a where T :: Eq a => a -> T a foo :: a -> T a -> Bool {-# INLINE foo #-} foo x = \(T y) -> x == y appl :: (a -> b) -> a -> b {-# NOINLINE appl #-} appl f x = f x bar :: T Int -> Bool bar t = appl (foo 42) t }}} GHC generates this for `bar`: {{{ bar2 :: Int bar2 = I# 42 bar1 :: T Int -> Bool bar1 = \ (ds_dhk :: T Int) -> case ds_dhk of _ { T $dEq_agz y_aa4 -> == @ Int $dEq_agz bar2 y_aa4 } bar :: T Int -> Bool bar = \ (t_aga :: T Int) -> appl @ (T Int) @ Bool bar1 t_aga }}} Note how it want to get the `Eq` dictionary for `Int` from `T`. But we know the `Eq Int` instance without inspecting `T` and `bar` could be significantly simplified if we used that. -- Comment: Looks like this won't make it for 8.0. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/5835#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler