[GHC] #13371: instance selection too eager
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 (Type checker) | 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: -------------------------------------+------------------------------------- I see a regression in 8.0.2: the `g_f'` definition is rejected. The error goes away if I do one of: * -XNoMonoLocalBinds * -XNoPolyKinds * pasting the inferred type of `g_f` -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Changes (by aavogt): * Attachment "too_eager.hs" added. minimal test case coming from Data.HList.Dredge -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Comment (by rwbarton): No error in 8.0.1, though. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: niteria (added) Comment: I tried to figure out where in the 8.0.2 branch this regression was introduced. Unfortunately, I wasn't able to isolate an exact commit, because the range of commits in which it was introduced doesn't build. However, I know for sure it was introduced between: * cc02156b859159eff7d86043f67826c17f2bd170 (where the bug is not present): {{{ From cc02156b859159eff7d86043f67826c17f2bd170 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka <niteria@gmail.com> Date: Mon, 18 Apr 2016 07:32:03 -0700 Subject: [PATCH] Make benign non-determinism in pretty-printing more obvious This change takes us one step closer to being able to remove `varSetElemsWellScoped`. The end goal is to make every source of non-determinism obvious at the source level, so that when we achieve determinism it doesn't get broken accidentally. Test Plan: compile GHC Reviewers: simonmar, goldfire, simonpj, austin, bgamari Reviewed By: simonpj Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2123 GHC Trac Issues: #4012 (cherry picked from commit 0f96686b10fd36d479a54c71a6e1753193e85347) }}} * ae94a31e7f162b4a3ef6b6f837bd6006a98f639a (where the bug is present): {{{ From ae94a31e7f162b4a3ef6b6f837bd6006a98f639a Mon Sep 17 00:00:00 2001 From: Simon Peyton Jones <simonpj@microsoft.com> Date: Fri, 22 Apr 2016 10:47:14 +0100 Subject: [PATCH] Refactor free tyvars on LHS of rules A RULE can have unbound meta-tyvars on the LHS. Consider data T a = C foo :: T a -> Int foo C = 1 {-# RULES "myrule" foo C = 1 #-} After type checking the LHS becomes (foo alpha (C alpah)) and we do not want to zap the unbound meta-tyvar 'alpha' to Any, because that limits the applicability of the rule. Instead, we want to quantify over it! Previously there was a rather clunky implementation of this quantification, buried in the zonker in TcHsSyn (zonkTvCollecting). This patch refactors it so that the zonker just turns the meta-tyvar into a skolem, and the desugarer adds the quantification. See DsBinds Note [Free tyvars on rule LHS]. As it happened, the desugarer was already doing something similar for dictionaries. See DsBinds Note [Free dictionaries on rule LHS] No change in functionality, but less cruft. (cherry picked from commit 6ad2b42f866fa718855cc5c850e3549bc1428b3c) }}} I doubt that ae94a31e7f162b4a3ef6b6f837bd6006a98f639a was responsible, since it seems to only touch rewrite RULES. Furthermore, niteria authored all commits between cc02156b859159eff7d86043f67826c17f2bd170 and that point. Do you have a hunch what might be happening here, niteria? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Actually, compiling these commits from the HEAD branch (instead of the 8.0.2 branch) turned out to be more fruitful. I discovered that the commit which introduced this regression is c9bcaf3165586ac214fa694e61c55eb45eb131ab: {{{ From c9bcaf3165586ac214fa694e61c55eb45eb131ab Mon Sep 17 00:00:00 2001 From: Bartosz Nitka <niteria@gmail.com> Date: Tue, 26 Apr 2016 05:58:24 -0700 Subject: [PATCH] Kill varSetElemsWellScoped in quantifyTyVars varSetElemsWellScoped introduces unnecessary non-determinism in inferred type signatures. Removing this instance required changing the representation of TcDepVars to use deterministic sets. This is the last occurence of varSetElemsWellScoped, allowing me to finally remove it. Test Plan: ./validate I will update the expected outputs when commiting, some reordering of type variables in types is expected. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Comment (by niteria): This reproduces on recent HEAD. This appears to be another case of unspoken assumptions about the order. On top of c9bcaf3165586ac214fa694e61c55eb45eb131ab it suffices to make this change: {{{ --- a/compiler/typecheck/TcMType.hs +++ b/compiler/typecheck/TcMType.hs @@ -874,7 +874,7 @@ quantifyZonkedTyVars gbl_tvs (DV{ dv_kvs = dep_tkvs, dv_tvs = nondep_tkvs }) -- closeOverKinds all_cvs: do not quantify over coercion -- variables, or any any tvs that a covar depends on - nondep_tvs = dVarSetElems $ + nondep_tvs = varSetElems . dVarSetToVarSet $ nondep_tkvs `dVarSetMinusVarSet` gbl_tvs -- No worry about dependent covars here; they are -- all in dep_tkvs }}} to make the problem go away. It also fixes the problem on HEAD, except you have to use `nonDetEltsUFM` instead of `varSetElems`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Comment (by niteria): Broken GHC infers: {{{ g_f :: forall (b :: k0) k c a. F a (Proxy b) => a -> c }}} , while the working one infers {{{ g_f :: forall k (b :: k) c a. F a (Proxy b) => a -> c }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Changes (by niteria): * cc: goldfire (added) Comment: I think this has been broken since 6746549772c5cc0ac66c0fce562f297f4d4b80a2. Running before c9bcaf3165586ac214fa694e61c55eb45eb131ab with `-dunique- increment=-1` reproduces the problem. It appears that when we `growThetaTyVarsDSet` we add some kind variables to the nondependent type var set, but the vars inside depend on the newly added kind var. We then linearize without any regard for dependencies, because there shouldn't be any. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Changes (by dfeuer): * priority: normal => high * milestone: => 8.2.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.0.2 checker) | 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: | -------------------------------------+------------------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"7e96526ac2ef5987ecb03217d3d616b6281c1441/ghc" 7e96526/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="7e96526ac2ef5987ecb03217d3d616b6281c1441" Fix TcSimplify.decideQuantification for kind variables TcSimplify.decideQuantification was doing the Wrong Thing when "growing" the type variables to quantify over. We were trying to do this on a tyvar set where we'd split off the dependent type varaibles; and we just got it wrong. A kind variable wasn't being generalised properly, with confusing knock on consequences. All this led to Trac #13371 and Trac #13393. This commit tidies it all up: * The type TcDepVars is renamed as CandidateQTvs; and splitDepVarsOfType to candidateQTyVarsOfType * The code in TcSimplify.decideQuantification is simpler. It no longer does the tricky "grow" stuff over TcDepVars. Instead it use ordinary VarSets (thereby eliminating the nasty growThetaTyVarsDSet) and uses that to filter the result of candidateQTyVarsOfType. * I documented that candidateQTyVarsOfType returns the type variables in a good order in which to quantify, and rewrote it to use an accumulator pattern, so that we would predicatably get left-to-right ordering. In doing all this I also made UniqDFM behave a little more nicely: * When inserting an element that is there already, keep the old tag, while still overwriting with the new value. * This means that when doing udfmToList we get back elements in the order they were originally inserted, rather than in reverse order. It's not a big deal, but in a subsequent commit I use it to improve the order of type variables in inferred types. All this led to a lot of error message wibbles: - changing the order of quantified variables - changing the order in which instances are listed in GHCi - changing the tidying of variables in typechecker erors There's a submodule update for 'array' because one of its tests has an error-message change. I may not have associated all of them with the correct commit. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.0.2 checker) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | polykinds/T13371 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * testcase: => polykinds/T13371 * resolution: => fixed Comment: This is a bit of a big commit, but I think it'd be worth doing for 8.2 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.0.2 checker) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | polykinds/T13371 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): See also #13393 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13371: instance selection too eager -------------------------------------+------------------------------------- Reporter: aavogt | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.0.2 checker) | Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | polykinds/T13371 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): This was merged in a920404fb12fb52a59e4f728cce4d662a418c5f8. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13371#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC