[GHC] #12027: ghc 8.0rc4 treats INLINE pragmas for methods with default (implicit) definitions as errors

#12027: ghc 8.0rc4 treats INLINE pragmas for methods with default (implicit) definitions as errors -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I was getting around to testing some of my maths code with ghc 8.0 and i noticed that whereas in ghc 7.10 and earlier i could have an INLINE pragma for a method of a type class method that has a default implementation (whether this did anything or not is another question), in ghc 8.0 this now gives an ERROR (with not even a warning in ghc 7.10) is this a deliberate design change or an accident? I dont see it in the release notes! heres a small program that illustrates the differences (builds fine with no mention of the INLINE pragma matter under -Wall for 7.10, errors during build in 8.0) {{{ {-# LANGUAGE NoImplicitPrelude #-} module Main where import Prelude (putStrLn) import qualified Data.Functor as Fun import qualified Data.Foldable as F import Prelude hiding (map,foldl,foldr,init,scanl,scanr,scanl1,scanr1,foldl1,foldr1) newtype ListWrap a = ListWrap { unListWrap :: [a] } deriving (Eq, Show) instance Foldable ListWrap where {-# INLINE foldMap #-} {-# INLINE foldr #-} foldMap f (ListWrap ls)= (F.foldMap f ls ) main = putStrLn "hello" }}} this may be a *valid* design change, but i've not seen it documented anywhere, such as the release notes in the RC or in https://ghc.haskell.org/trac/ghc/wiki/Migration/8.0 ... so i'm assuming its a regression pending dicussion ;) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12027 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12027: ghc 8.0rc4 treats INLINE pragmas for methods with default (implicit) definitions as errors -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by carter): oh just to clarify, the error in ghc 8.0 is {{{ Shape.hs:15:14: error: The INLINE pragma for ‘foldr’ lacks an accompanying binding (The INLINE pragma must be given where ‘foldr’ is declared) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12027#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12027: ghc 8.0rc4 treats INLINE pragmas for methods with default (implicit) definitions as errors -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: bug | Status: closed Priority: high | Milestone: Component: Compiler | Version: 8.0.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => invalid Comment: Right, because, just as the error says, that INLINE doesn't correspond to any particular in-scope binding. However, you should not need an INLINE here; instead just place one on the default definition. You can test this yourself with the following, {{{#!hs module Class where class AClass a where aList :: a -> [Int] aList _ = [1,2,3] {-# INLINE aList #-} }}} {{{#!hs module Instance where import Class instance AClass Int where }}} {{{#!hs module Use where import Class import Instance n :: Int n = 42 main :: IO () main = print (aList n) }}} If you build `Use` with `-O -ddump-simpl` you will see that the RHS of `aList` has been inlined. I suspect the real bug here is the fact that this wasn't warned about previously. I'll try to draw attention to this change in the release notes. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12027#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12027: ghc 8.0rc4 treats INLINE pragmas for methods with default (implicit) definitions as errors -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: bug | Status: closed Priority: high | Milestone: Component: Compiler | Version: 8.0.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by carter): I think I definitely would get a warning previously somehow for ordinary things. But foldable was sneaking off and getting away with stuff -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12027#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12027: ghc 8.0rc4 treats INLINE pragmas for methods with default (implicit) definitions as errors -------------------------------------+------------------------------------- Reporter: carter | Owner: Type: bug | Status: closed Priority: high | Milestone: Component: Compiler | Version: 8.0.1 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I suppose it's conceivable that in some instances you want to inline the default method, and not in others. So we could make it so that a pragma for the (invisible) default-method binding in the instance overrides the one from the class decl. Possible, if there are compelling use-cases. But it's one more thing to specify, explain, implement, and maintain. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12027#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC