[GHC] #7995: module Pretty's "text/str" rule doesn't fire

#7995: module Pretty's "text/str" rule doesn't fire -----------------------------+---------------------------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.7 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- In this trivial but characteristic example {{{ import Pretty import Data.IORef main :: IO () main = do _ <- newIORef (text "test") return () }}} the "text/str" rule, which optimizes calls to `Pretty.text` applied to a string literal argument, doesn't fire. Likewise, such calls to `Outputable.text` don't get rewritten either. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7995 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7995: module Pretty's "text/str" rule doesn't fire -----------------------------+---------------------------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.7 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- Comment(by parcs): I suspect `Pretty.text "blah"` doesn't get rewritten because `Pretty.text` gets inlined before the rule has a chance to fire. `Pretty.text` is currently marked as `NOINLINE [1]`; if you change this to `NOINLINE [0]`, then the rule does fire. And it looks like `Outputable.text "blah"` doesn't get rewritten because `Pretty.text` gets inlined into the unfolding of `Outputable.text`. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7995#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7995: module Pretty's "text/str" rule doesn't fire -----------------------------+---------------------------------------------- Reporter: parcs | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.7 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- Comment(by parcs): I can think of two solutions: 1) Mark `Pretty.text` as `NOINLINE` to ensure that the "text/str" rule has a chance to fire and that `Pretty.text` doesn't get inlined into the unfolding of `Outputable.text`. This solution has the caveat that `Pretty.text` can no longer get inlined. 2) Add a corresponding "text/str" rule on `Outputable.text` and mark both `Pretty.text` and `Outputable.text` as `NOINLINE [0]` (to ensure that the rules get a chance to fire). -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7995#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7995: module Pretty's "text/str" rule doesn't fire
-----------------------------+----------------------------------------------
Reporter: parcs | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler
Version: 7.7 | Keywords:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: None/Unknown | Blockedby:
Blocking: | Related:
-----------------------------+----------------------------------------------
Comment(by simonpj@…):
commit d2c3630dedc577f7e6eb8e945b05a86992bd5e0a
{{{
Author: Simon Peyton Jones

#7995: module Pretty's "text/str" rule doesn't fire ---------------------------------------------+------------------------------ Reporter: parcs | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: fixed | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: simplCore/should_compile/T7995 | Blockedby: Blocking: | Related: ---------------------------------------------+------------------------------ Changes (by simonpj): * status: new => closed * difficulty: => Unknown * resolution: => fixed * testcase: => simplCore/should_compile/T7995 Comment: OK, I've fixed this. I'm not sure it's really worth adding a test but I have done so anyway. Good catch... knowing that this works should let us replace {{{ ptext (sLit "foo") }}} with the much tidier {{{ text "foo" }}} without increasing code size or execution time. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7995#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC