[GHC] #12632: Inline and Noinline pragmas ignored for instance functions

#12632: Inline and Noinline pragmas ignored for instance functions -------------------------------------+------------------------------------- Reporter: jeremy-list | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- An example source file which triggers the incorrect behaviour follows. I am currently unclear whether the effected inline and noinline pragmas are actually ignored by the simplifier or whether the inline rule shadowing warning is fired incorrectly. {{{#!hs class A a where (>>#) :: a -> a -> a instance A (Maybe a) where {-# NOINLINE (>>#) #-} a >># b = undefined {-# RULES "example" forall (a :: Maybe Int) (b :: Maybe Int) . a >># b = Just 4 #-} }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12632 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12632: Inline and Noinline pragmas ignored for instance functions -------------------------------------+------------------------------------- Reporter: jeremy-list | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Can you elaborate on what exactly is the "incorrect behaviour" that you are concerned about? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12632#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12632: Inline and Noinline pragmas ignored for instance functions -------------------------------------+------------------------------------- Reporter: jeremy-list | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jeremy-list): Compiling this code with "-O2 -ddump-rule-firings": {{{ class Inv a where inv :: a -> a instance Inv Bool where {-# NOINLINE inv #-} inv = not {-# RULES "force-inline" forall (a :: Bool) . inv a = not a #-} main = print (inv True) }}} The output from GHC is: {{{ [1 of 1] Compiling Main ( sample1.hs, sample1.o ) sample1.hs:8:11: warning: [-Winline-rule-shadowing] Rule "force-inline" may never fire because ‘inv’ might inline first Probable fix: add an INLINE[n] or NOINLINE[n] pragma for ‘inv’ Rule fired: force-inline Rule fired: Class op show Linking sample1 ... }}} Here the warning is incorrect because it ignores the NOINLINE pragma, but the rule is fired because the function isn't actually inlined. If the NOINLINE pragma is changed to INLINE the output from GHC is identical: the warning is emitted and the rule is fired. This is incorrect because the rule shouldn't fire if the function is inlined. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12632#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12632: Inline and Noinline pragmas ignored for instance functions -------------------------------------+------------------------------------- Reporter: jeremy-list | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Ah now I see what you mean, thanks. The thing is, in the RULE when you mention `inv` you are mentioning the `inv` from the class declaration; and you probably do not want to put NOINLINE on the class method (and I doubt that works anyway). I think you want the rule to work for "the `inf` at type `Bool`". The easiest way to do that is to name it: {{{ instance Inv Bool where inv = invBool invBool :: Bool -> Bool {-# NOINLINE invBool #-} invBool = not {-# RULES "force-inline" forall (a :: Bool) . invBool a = not a #-} }}} Now I think you'll find it works fine. It's a little less direct, but much more explicit and robust. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12632#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12632: Inline and Noinline pragmas ignored for instance functions -------------------------------------+------------------------------------- Reporter: jeremy-list | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jeremy-list): Thank you. Unfortunately this technique doesn't work for mulit-parameter type classes. Will file a separate ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12632#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC