[GHC] #12644: Lack of instantiation in GHC 8.0.1
#12644: Lack of instantiation in GHC 8.0.1 -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Consider {{{ data T a = T1 Int instance Show (T a) where show (T1 x) = show x t1 :: T a t1 = T1 1 f :: String f = show t1 }}} This should typecheck fine. The `a` in data type `T` is phantom, but we often use phantom types. But it isn't with GHC 8.0.1: {{{ • No instance for (Show (forall a. T a)) arising from a use of ‘show’ • In the expression: show t1 In an equation for ‘f’: f = show t1 }}} The problem is in the lack of instantation of `t1` in the argument of `show`. I'm fixing this, but I wanted to make a ticket to exhibit it. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12644> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12644: Lack of instantiation in GHC 8.0.1 -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by simonpj: @@ -3,0 +3,2 @@ + {-# LANGUAGE ImpredicativeTypes #-} + @@ -24,1 +26,1 @@ - The problem is in the lack of instantation of `t1` in the argument of + The problem is in the lack of instantiation of `t1` in the argument of @@ -27,0 +29,3 @@ + Admittedly it only happens with `-XImpredicativeTypes`, but that flag + should never make a legal program fail! + New description: Consider {{{ {-# LANGUAGE ImpredicativeTypes #-} data T a = T1 Int instance Show (T a) where show (T1 x) = show x t1 :: T a t1 = T1 1 f :: String f = show t1 }}} This should typecheck fine. The `a` in data type `T` is phantom, but we often use phantom types. But it isn't with GHC 8.0.1: {{{ • No instance for (Show (forall a. T a)) arising from a use of ‘show’ • In the expression: show t1 In an equation for ‘f’: f = show t1 }}} The problem is in the lack of instantiation of `t1` in the argument of `show`. Admittedly it only happens with `-XImpredicativeTypes`, but that flag should never make a legal program fail! I'm fixing this, but I wanted to make a ticket to exhibit it. -- -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12644#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12644: Lack of instantiation in GHC 8.0.1 -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | typecheck/should_compile/T12644 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * testcase: => typecheck/should_compile/T12644 * resolution: => fixed Comment: Fixed as part of {{{ commit b612da667fe8fa5277fc78e972a86d4b35f98364 Author: Simon Peyton Jones <simonpj@microsoft.com> Date: Sun Sep 25 15:50:18 2016 +0100 Fix impredicativity (again) This patch fixes Trac #12616. Dignosis. In TcUnify.tc_sub_type_ds we were going to some trouble to support co- and contra-variance even for impredicative types. With -XImpredicativeTYpes, this allowed a unification variable to be unified with a polytype (probably wrongly) and that caused later trouble in the constraint solver, where -XImpredicativeTypes was /not/ on. In effect, -XImpredicativeTypes can't be switched on locally. Why did we want ImpredicativeTypes locally? Because the program generated by GND for a higher-rank method involved impredicative instantation of 'coerce': op = coerce op -- where op has a higher rank type See Note [Newtype-deriving instances] in TcGenDeriv. Cure. 1. It is ghastly to rely on ImpredicativeTypes (a 100% flaky feature) to instantiate coerce polymorphically. Happily we now have Visible Type Application, so I've used that instead which should be solid and reliable. 2. I deleted the code in tc_sub_type_ds that allows the constraint solver to "look through" a unification variable to find a polytype. That used to be essential in the days of ReturnTv, but it's utterly unreliable and should be consigned to the dustbin of history. (We have ExpType now for the essential uses.) Tests involving ImpredicativeTypes are affected, but I'm not worried about them... it's advertised as a feature you can't rely on, and I want to reform it outright. compiler/hsSyn/HsUtils.hs | 8 ++++---- compiler/typecheck/TcDeriv.hs | 2 ++ compiler/typecheck/TcGenDeriv.hs | 61 +++++++++++++++++++++++++++++++------------------------------ compiler/typecheck/TcUnify.hs | 30 ++++++++---------------------- testsuite/tests/boxy/Base1.hs | 35 +++++++++++++++++++---------------- testsuite/tests/boxy/T2193.hs | 2 ++ testsuite/tests/boxy/all.T | 4 ++-- testsuite/tests/deriving/should_compile/T12616.hs | 21 +++++++++++++++++++++ testsuite/tests/deriving/should_compile/all.T | 1 + testsuite/tests/deriving/should_fail/T4846.stderr | 4 ++-- testsuite/tests/typecheck/should_compile/T11319.hs | 3 +++ testsuite/tests/typecheck/should_compile/T12644.hs | 14 ++++++++++++++ testsuite/tests/typecheck/should_compile/all.T | 3 ++- testsuite/tests/typecheck/should_compile/tc211.hs | 3 +++ testsuite/tests/typecheck/should_compile/tc211.stderr | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- testsuite/tests/typecheck/should_fail/T10619.stderr | 18 ++++-------------- testsuite/tests/typecheck/should_fail/T2846b.stderr | 3 ++- testsuite/tests/typecheck/should_fail/T8428.stderr | 5 ++++- testsuite/tests/typecheck/should_fail/all.T | 2 +- testsuite/tests/typecheck/should_fail/tcfail016.stderr | 2 +- testsuite/tests/typecheck/should_fail/tcfail165.hs | 4 +++- testsuite/tests/typecheck/should_fail/tcfail165.stderr | 12 ++++++++++++ testsuite/tests/typecheck/should_fail/tcfail174.hs | 2 ++ testsuite/tests/typecheck/should_fail/tcfail174.stderr | 19 +++++++++++++------ 24 files changed, 230 insertions(+), 106 deletions(-) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12644#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC