[GHC] #12689: DataCon wrappers get in the way of rules

GHC ghc-devs at haskell.org
Thu Oct 13 13:42:43 UTC 2016


#12689: DataCon wrappers get in the way of rules
-------------------------------------+-------------------------------------
        Reporter:  nomeata           |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by nomeata):

 Here is an idea that came out of what Iavor said (or at least how I
 understood him). There are still open questions, but I do like the general
 approach:

 Consider a rule (which I write with the wrapper name already, as that is
 what we desugar to these days)
 {{{
 RULE forall a b. foo ($WMkCon a b) = bar a b
 }}}
 and a wrapper
 {{{
 $WMkCon a b = case a of (a1,a2) -> MkCon a1 a2 b
 }}}

 We don’t want cases on the LHS of the rule, so we do not just want to
 inline MkCon into the LHS. But what if we move it to the right hand side,
 and write the rule like that:
 {{{
 RULE forall a1 a2 b.  foo (MkCon a1 a2 b) = let a = (a1,a2) in bar a b
 }}}
 The rule is nice because the LHS is a normal form (with regard to the
 simplifier and the rewrite rules).


 The necessary transformations could be stored with the unfolding
 information of `$WMkCon`. At least for a strict `foo`, things might work
 out. We’d get:
 {{{
    case some expr of (a1,a2) -> …  foo (MkCon a1 a2 someB) …
 →  case some expr of (a1,a2) -> …  (let a = (a1,a2) in bar a someB) … --
 rule fires
 →  case some expr of (a1,a2) -> …  bar (a1,a2) a someB …             --
 inlining
 }}}
 and further cleanup may happen due to CSE.

 Unfortunately it does not work as immediately if `foo` is not strict, as
 the `case` does not get floated out of the way, and we need to match an
 expression like
 {{{
 foo (case some expr of (a,b) -> MkCon a1 a2 someB)
 }}}
 and it would not be sound if the matcher would simply float the case out
 of the way.

 So this idea requires more thought.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12689#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list