[GHC] #10340: Type inference regression with Any
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 (Type checker) | Operating System: Unknown/Multiple Keywords: | Type of failure: GHC rejects Architecture: | valid program Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- The following module typechecks with GHC 7.8.3, but GHC 7.10.1 gives an error: {{{#!hs {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} module Foo where import GHC.Exts (Any) class MonadState s m where get :: m s newtype State s a = State (s -> (s, a)) instance MonadState s (State s) where get = State $ \s -> (s, s) foo :: State Any Any foo = get }}} {{{ [1 of 1] Compiling Foo ( any.hs, any.o ) any.hs:15:7: No instance for (MonadState Any (State Any)) arising from a use of ‘get’ In the expression: get In an equation for ‘foo’: foo = get }}} If I replace the uses of `Any` with `Int`, the problem goes away. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10340> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.10.1 checker) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Comment (by goldfire): I just took a look, and the problem here is fairly simple. I'm not sure what the right solution is, though. Here are the constraints that get to the solver: {{{ [W] $dMonadState_a1UB :: MonadState s_a1Uy[tau:1] m_a1Uz[tau:1] (CNonCanonical) [W] cobox_a1UD :: m_a1Uz[tau:1] ~ State Any (CNonCanonical) [W] cobox_a1UE :: s_a1Uy[tau:1] ~ Any (CNonCanonical) }}} In short order, we get a fuv for `Any` {{{ [W] cobox_a1UT :: Any ~ s_a1US[fuv:0] (CFunEqCan) }}} and a unification for `m_a1Uz`. {{{ setWantedTyBind m_a1Uz[tau:1] := State s_a1US[fuv:0] }}} The solver then attacks `cobox_a1UE`, which canonicalizes to {{{ [W] cobox_a1UW :: s_a1US[fuv:0] ~ s_a1Uy[tau:1] (CTyEqCan) }}} Because an fuv is on the left, no unification takes place. See `Note [Orient equalities with flatten-meta-vars on the left]` in !TcFlatten. When we then canonicalize the `MonadState` constraint, we get {{{ [W] $dMonadState_a1UB :: MonadState s_a1Uy[tau:1] (State s_a1US[fuv:0]) (CDictCan) }}} which can't get solved and is reported to the user. The "obvious" solution to me is to re-orient the `CTyEqCan` above (`cobox_a1UW`) so that unification gets the job done for us. But that `Note [Orient equalities with flatten-meta-vars on the left]` in !TcFlatten tells me not to. Another solution is to allow a Wanted to rewrite a Wanted here, but we've previously been convinced that this is a bad idea. Incidentally, I don't think this problem is at all restricted to `Any`. I haven't tested any other code, but I imagine this will bite whenever we want an instance with repeated pattern variables to match a type with irreducible type families. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10340#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.10.1 checker) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Comment (by simonpj): Exactly. I have a big patch in-flight to fix this and #10009. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10340#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.10.1 checker) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"a1275a762ec04c1159ae37199b1c8f998a5c5499/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="a1275a762ec04c1159ae37199b1c8f998a5c5499" Improve improvement in the constraint solver This regrettably-big patch substantially improves the way in which "improvement" happens in the constraint solver. It was triggered by trying to crack Trac #10009, but it turned out to solve #10340 as well. The big picture, with several of the trickiest examples, is described in Note [The improvement story] in TcInteract. The major change is this: * After solving we explicitly try "improvement", by - making the unsolved Wanteds into Deriveds - allowing Deriveds to rewrite Deriveds This more aggressive rewriting "unlocks" some extra guess-free unifications. * The main loop is in TcInteract.solveSimpleWanteds, but I also ended up refactoring TcSimplify.simpl_loop, and its surrounding code. Notably, any insolubles from the Givens are pulled out and treated separately, rather than staying in the inert set during the solveSimpleWanteds loop. There are a lot of follow-on changes * Do not emit generate Derived improvements from Wanteds. This saves work in the common case where they aren't needed. * For improvement we should really do type-class reduction on Derived constraints in doTopReactDict. That entailed changing the GenInst constructor a bit; a local and minor change * Some annoying faffing about with dropping derived constraints; see dropDerivedWC, dropDerivedSimples, dropDerivedInsols, and their Notes. * Some substantial refactoring in TcErrors.reportWanteds. This work wasn't strictly forced, but I got sucked into it. All the changes are in TcErrors. * Use TcS.unifyTyVar consistently, rather than setWantedTyBind, so that unifications are properly tracked. * Refactoring around solveWantedsTcM, solveWantedsAndDrop. They previously guaranteed a zonked result, but it's more straightforward for clients to zonk. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10340#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 7.10.1 checker) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Comment (by simonpj): Not clear whether to merge this to 7.10. It's a big patch. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10340#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: merge Priority: normal | Milestone: 7.10.2 Component: Compiler (Type | Version: 7.10.1 checker) | Keywords: Resolution: | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => merge * milestone: => 7.10.2 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10340#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.12.1 Component: Compiler (Type | Version: 7.10.1 checker) | Keywords: Resolution: fixed | Architecture: Operating System: Unknown/Multiple | Unknown/Multiple Type of failure: GHC rejects | Test Case: valid program | Blocking: Blocked By: | Differential Revisions: Related Tickets: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed * milestone: 7.10.2 => 7.12.1 Comment: I'm moving this to 7.12.1 and closing; it's fixed, but won't be making 7.10.2. See #10009:comment:36 for more. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10340#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10340: Type inference regression with Any -------------------------------------+------------------------------------- Reporter: akio | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.12.1 Component: Compiler (Type | Version: 7.10.1 checker) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: GHC rejects | Test Case: indexed- valid program | types/should_compile/T10340 Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by simonpj): * testcase: => indexed-types/should_compile/T10340 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10340#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC