[GHC] #13614: Rewrite rules not applied exhaustively when simplifying from plugin
GHC
ghc-devs at haskell.org
Tue Apr 25 22:51:44 UTC 2017
#13614: Rewrite rules not applied exhaustively when simplifying from plugin
-------------------------------------+-------------------------------------
Reporter: nomeata | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHC API | Version: 8.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):
Replying to [comment:1 simonpj]:
> It's not just that they aren't getting applied; somehow `foo 1` is
getting rewritten to `foo 2` which is deeply strange.
That is not strange, one of the rules is
{{{
"foo1" [1] foo 1 = foo 2
}}}
after all. But I wonder why it does not then apply the second rule.
> I'm not sure why you are simplifying twice.
Just in case it takes multiple simplifier iterations to apply rules
exhaustively (although it does not help).
My hypothesis is as follows:
Rewrite rules are attached (via the `IdInfo` field `ruleInfo`)to the `Id`
of the outermost function on the LHS of the rule; in this case `foo` (and
not looked up in some mapping, as one might naively expect). As far as I
can tell, the rule `foo1` and `foo2` are attached to all occurrences of
`foo` in the module – excluding the ones on the RHS of the rules
themselves!
This would explain this behaviour. It would rewrite
foo[ruleInfo=foo1,foo2] 1 `fun` foo[ruleInfo=foo1,foo2] 2
to
foo[ruleInfo=] 2 `fun` foo[ruleInfo=] 3
and then not apply any more rules (because `ruleInfo`) is empty.
This hypothesis would explain the behavior; what puzzles me is that it
works as expected if I compile the module as normal. And, pragmaticall,
what I wave to do so that my plugin acts as expected.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13614#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list