[GHC] #8644: 'Untouchable' error with constraint variable in rank-2 type
#8644: 'Untouchable' error with constraint variable in rank-2 type -------------------------------------+------------------------------------- Reporter: sbarclay | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.7 checker) | Operating System: Unknown/Multiple Keywords: | Type of failure: GHC rejects Architecture: Unknown/Multiple | valid program Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | -------------------------------------+------------------------------------- The following program compiles fine with GHC 7.6.3: {{{#!haskell {-# LANGUAGE ConstraintKinds, RankNTypes, GADTs #-} data Dict c where Dict :: c => Dict c foo :: Dict c -> (c => r) -> r foo Dict x = x bar :: Dict () bar = Dict main :: IO () main = print $ foo bar "Hello" }}} However, it produces the following error with HEAD: {{{ ConstraintIssue.hs:12:8: No instance for (Show s0) arising from a use of ‛print’ The type variable ‛s0’ is ambiguous Note: there are several potential instances: instance Show Double -- Defined in ‛GHC.Float’ instance Show Float -- Defined in ‛GHC.Float’ instance (Integral a, Show a) => Show (GHC.Real.Ratio a) -- Defined in ‛GHC.Real’ ...plus 24 others In the expression: print In the expression: print $ foo bar "Hello" In an equation for ‛main’: main = print $ foo bar "Hello" ConstraintIssue.hs:12:24: Couldn't match expected type ‛s0’ with actual type ‛[Char]’ ‛s0’ is untouchable inside the constraints (()) bound by a type expected by the context: (()) => s0 at ConstraintIssue.hs:12:16-30 In the second argument of ‛foo’, namely ‛"Hello"’ In the second argument of ‛($)’, namely ‛foo bar "Hello"’ In the expression: print $ foo bar "Hello" }}} If the type signature of 'main' is removed, the code compiles OK. If the empty constraint () is replaced with an equality constraint such as Int ~ Int, then the above error occurs with both 7.6.3 and HEAD, which I guess is intended behaviour. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8644> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8644: 'Untouchable' error with constraint variable in rank-2 type ----------------------------------------------+---------------------------- Reporter: sbarclay | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type checker) | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects valid program | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ----------------------------------------------+---------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"9e10d1883d7ea5ea422cda79b426f51d2b59b14d/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="9e10d1883d7ea5ea422cda79b426f51d2b59b14d" Improve the equality-floating story (again), to fix Trac #8644 We float equalities out of implications whose 'givens' include equalities. But it's a bit tricky knowing whether some givens do or do not include equalities, as #8644 shows. There the given has type 'c' (which might have equalities), but we discover that 'c ~ ()', which definitely doesn't. In short, we must look at the givens *after* normalisation, not before. Moreover, something similar happens in approximateWC, where we need to ask whether an implication has given equalities. This patch does the job: * Add a Boolean field inert_no_eqs to InertCans, which records whether we've added a non-constant equality * Add a field ic_no_eqs to Implication, which records whether the ic_given binders include any equalities * Get rid of Inst.hasEqualities altogether On the way I did some un-forced refactoring * Introduce the auxiliary function TcCanonical.flattenNestedFamApp * Kill off FamHeadMap and PredMap in favour of the new FunEqMap and DictMap respectively }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8644#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8644: 'Untouchable' error with constraint variable in rank-2 type ----------------------------------------------+---------------------------- Reporter: sbarclay | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type checker) | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects valid program | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ----------------------------------------------+---------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"2818ec6887a713211dfca69cc80241a1ef2e5d33/testsuite"]: {{{ #!CommitTicketReference repository="testsuite" revision="2818ec6887a713211dfca69cc80241a1ef2e5d33" Test Trac #8644 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8644#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8644: 'Untouchable' error with constraint variable in rank-2 type ----------------------------------------------+---------------------------- Reporter: sbarclay | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type checker) | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects valid program | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ----------------------------------------------+---------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"cf68a8e798fea44bea2804439732e534e096b0d1/testsuite"]: {{{ #!CommitTicketReference repository="testsuite" revision="cf68a8e798fea44bea2804439732e534e096b0d1" Update T7594 as a result of fixing #8644 The fix to #8644 makes the original T7594 pass (rightly). I've added a variant that shouuld and does fail }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8644#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8644: 'Untouchable' error with constraint variable in rank-2 type -------------------------------------------------+------------------------- Reporter: sbarclay | Owner: Type: bug | Status: Priority: normal | closed Component: Compiler (Type checker) | Milestone: Resolution: fixed | Version: 7.7 Operating System: Unknown/Multiple | Keywords: Type of failure: GHC rejects valid program | Architecture: Test Case: | Unknown/Multiple typecheck/should_compile/T8644 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Changes (by simonpj): * status: new => closed * testcase: => typecheck/should_compile/T8644 * resolution: => fixed Comment: Great catch, thank you! This showed (in a nice simple example) that the handling of equality floating was inadequate. Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8644#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#8644: 'Untouchable' error with constraint variable in rank-2 type -------------------------------------------------+------------------------- Reporter: sbarclay | Owner: Type: bug | Status: Priority: normal | closed Component: Compiler (Type checker) | Milestone: Resolution: fixed | Version: 7.7 Operating System: Unknown/Multiple | Keywords: Type of failure: GHC rejects valid program | Architecture: Test Case: | Unknown/Multiple typecheck/should_compile/T8644 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: -------------------------------------------------+------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"5d2fb2ee94fea4cf62ba767eb1555e42f4f21f46/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="5d2fb2ee94fea4cf62ba767eb1555e42f4f21f46" Further refine the test for 'given' equalities Trac #8651 revealed that my previous fix (itself in response to #8644) wasn't quite right. The plan, using the CtOrigin to identify constraints arising from flattening, is described in TcSimplify, Note [When does an implication have given equalities?] }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8644#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC