[GHC] #16254: INLINABLE pragma and newtype wrappers prevent inlining

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #5327 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- In #5327, we allowed case-of-known constructor to see through bindings that were marked as INLINABLE and used newtypes. However, this works only if the newtype does not have a wrapper. The following code, which is the same as T5237 except for the extra type parameters in Size, does not cause the optimization to fire. {{{ {-# LANGUAGE GADTs, ExplicitForAll #-} module T16254 where newtype Size a b where Size :: forall b a. Int -> Size a b {-# INLINABLE val2 #-} val2 = Size 17 f n = case val2 of Size s -> s + s > n }}} The reason is that `exprIsConApp_maybe` sees `$WSize (I# 17#)`, which is an application with a nontrivial argument. In general, this could cause duplication of work, but in this case we're dealing with a newtype wrapper, so this is safe. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by monoidal): * owner: (none) => monoidal -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/247 -------------------------------------+------------------------------------- Changes (by monoidal): * differential: => https://gitlab.haskell.org/ghc/ghc/merge_requests/247 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/247 -------------------------------------+------------------------------------- Changes (by monoidal): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/247 -------------------------------------+------------------------------------- Comment (by simonpj):
The reason is that exprIsConApp_maybe sees $WSize (I# 17#)
This is true only if data constructor wrappers are inlined late, isn't it? Or is it some true even of (say) GHC 8.6? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/247 -------------------------------------+------------------------------------- Comment (by monoidal): The is true in GHC 8.6 or master - it doesn't require the inlining late patch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/247 -------------------------------------+------------------------------------- Comment (by simonpj): Hmm. I wonder why? I'd expect Size's wrapper to be inlined even inside the INLINEABLE unfolding. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/247 -------------------------------------+------------------------------------- Changes (by aspiwack): * cc: aspiwack (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/325/ -------------------------------------+------------------------------------- Changes (by monoidal): * status: patch => closed * differential: https://gitlab.haskell.org/ghc/ghc/merge_requests/247 => https://gitlab.haskell.org/ghc/ghc/merge_requests/325/ * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/325/ -------------------------------------+------------------------------------- Comment (by simonpj): What about a regression test for this ticket? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining -------------------------------------+------------------------------------- Reporter: monoidal | Owner: monoidal Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | simplCore/should_compile/T16254 Blocked By: | Blocking: Related Tickets: #5327 | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/325/ -------------------------------------+------------------------------------- Changes (by monoidal): * testcase: => simplCore/should_compile/T16254 Comment: It was pushed, I've set it here now. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16254#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16254: INLINABLE pragma and newtype wrappers prevent inlining
-------------------------------------+-------------------------------------
Reporter: monoidal | Owner: monoidal
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.3
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| simplCore/should_compile/T16254
Blocked By: | Blocking:
Related Tickets: #5327 | Differential Rev(s):
Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/325/
-------------------------------------+-------------------------------------
Comment (by Marge Bot

#16254: INLINABLE pragma and newtype wrappers prevent inlining
-------------------------------------+-------------------------------------
Reporter: monoidal | Owner: monoidal
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.3
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| simplCore/should_compile/T16254
Blocked By: | Blocking:
Related Tickets: #5327 | Differential Rev(s):
Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/325/
-------------------------------------+-------------------------------------
Comment (by Matthew Pickering
participants (1)
-
GHC