[GHC] #12220: TypeApplications and DefaultSignatures - problems deducing type variables.
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Linux DefaultSignatures, | TypeApplications | Architecture: x86_64 | Type of failure: None/Unknown (amd64) | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The following example code throws an error. The example code: {{{#!hs {-#LANGUAGE TypeApplications#-} {-#LANGUAGE MultiParamTypeClasses #-} {-#LANGUAGE AllowAmbiguousTypes #-} {-#LANGUAGE FlexibleInstances #-} {-#LANGUAGE ScopedTypeVariables #-} {-#LANGUAGE DefaultSignatures #-} module Test1 where -- | Type a is only used for -- type application. class ToUse a where toUse :: Int -> Int -- | The type used for -- type application data Default -- | The instance using Default as type application. -- To call use: -- > toUse @Default instance ToUse Default where toUse a = 3*a -- | Typeclass whose methods work -- only with type application. class (ToUse a) => Uses a b where uses :: b -> [b] -- | Default Signature, which generates the problem. -- It is the same as the normal one -- Comment it to 'fix' the bug. default uses :: b -> [b] uses v = [v] -- | Normal instances, nothing special instance Uses Default Int where uses v = take (toUse @Default 3) $ repeat v -- | Another normal one instance Uses Default String where uses v = take (toUse @Default 2) $ repeat v -- | This one works nicely instance (ToUse t, Uses t a, Uses t b) => Uses t (a,b) where uses (vl,vr) = zip ls rs where ls = uses @t vl rs = uses @t vr -- | But this one doesn't. -- Unless you comment the default signature. instance (ToUse t, Uses t a, Uses t b, Uses t c) => Uses t (a,b,c) }}} The error: {{{ • Could not deduce (Uses a0 a) arising from a use of ‘Test1.$dmuses’ from the context: (ToUse t, Uses t a, Uses t b, Uses t c) bound by the instance declaration at Test1.hs:47:10-66 The type variable ‘a0’ is ambiguous Relevant bindings include uses :: (a, b, c) -> [(a, b, c)] (bound at Test1.hs:47:10) • In the expression: Test1.$dmuses In an equation for ‘uses’: uses = Test1.$dmuses In the instance declaration for ‘Uses t (a, b, c)’ }}} Commenting out the default signature fixes the problem. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | DefaultSignatures, TypeApplications Operating System: Linux | Architecture: x86_64 | (amd64) 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:"d2958bd08a049b61941f078e51809c7e63bc3354/ghc" d2958bd0/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="d2958bd08a049b61941f078e51809c7e63bc3354" Improve typechecking of instance defaults In an instance declaration when you don't specify the code for a method, GHC fills in from the default binding in the class. The type of the default method can legitmiately be ambiguous --- see Note [Default methods in instances] in TcInstDcls --- so typechecking it can be tricky. Trac #12220 showed that although we were dealing with that ambiguity for /vanilla/ default methods, we were not doing so for /generic/ default methods. Moreover we were dealing with it clumsily, by generating post-typechecked code. This patch fixes the bug AND deletes code! We now use the same code path for both vanilla and generic default methods; and generate /pre-typechecked/ code in both cases. The key trick is that we can use Visible Type Application to deal with the ambiguity, which wasn't possible before. Hooray. There is a small hit to performance in compiler/perf/T1969 which consists of nothing BUT instance declarations with several default methods to fill, which we now have to typecheck. The actual hit is from 724 -> 756 or 4% in that extreme example. Real world programs have vastly fewer instance decls. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | DefaultSignatures, TypeApplications Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | generics/T12220 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => merge * testcase: => generics/T12220 * milestone: => 8.0.2 Comment: Thanks for reporting this. Now fixed. I think that the fix is non-invasive and so could merge to 8.0.2 Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | DefaultSignatures, TypeApplications Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | generics/T12220 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): This isn't quite non-invasive, since it's causing some packages to fail to compile on GHC HEAD that were compiling on GHC 8.0.1. See #12466. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: merge Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: | DefaultSignatures, TypeApplications Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | generics/T12220 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Does anyone care if this doesn't make it into 8.0.1? If it goes in, we'll have to fix #12466 too. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: | DefaultSignatures, TypeApplications Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | generics/T12220 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed * milestone: 8.0.2 => 8.2.1 Comment: Given that no one feels terribly strongly about this we'll be bumping it off to 8.2.1. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: | DefaultSignatures, TypeApplications Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | generics/T12220 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.2.1 => 8.0.2 Comment: It ended up being not so bad to merge afterall. Merged to `ghc-8.0` as 54b887b5abf6ee723c6ac6aaa2d2f4c14cf74060. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: | DefaultSignatures, TypeApplications Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | generics/T12220 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): This also introduced another typechecker regression in GHC 8.0.2: #12784. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12220: TypeApplications and DefaultSignatures - problems deducing type variables. -------------------------------------+------------------------------------- Reporter: mkloczko | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.2 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: | DefaultSignatures, TypeApplications Operating System: Linux | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | generics/T12220 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ryan Scott <ryan.gl.scott@…>): In [changeset:"2e8463b232054b788b73e6551947a9434aa76009/ghc" 2e8463b2/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="2e8463b232054b788b73e6551947a9434aa76009" Update 8.0.2 release notes for #12784 Summary: The fix for #12220 exposed some ill-typed programs which passed the typechecker in GHC 8.0.1 but now fail to typecheck in GHC 8.0.2. It's a bit difficult to characterize what exactly triggers this bug, but we at least have a minimal example and a simple fix to illustrate the problem and solution, so let's add that the the 8.0.2 release notes to advertise this change. Resolves #12784. Reviewers: rwbarton, austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2682 GHC Trac Issues: #12784 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12220#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC