
#10595: BuiltinRules override other rules in some cases. -------------------------------------+------------------------------------- Reporter: gjsimms | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): GHC has a crude-but-effective way to control the order of application of rules, called "phases". See the reference to phase control in [https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/rewrite- rules.html 7.23.1 in the manual]. Phases count down; currently 2, 1, 0. Currently, though, a class-method has a built-in rule (selection from dictionary) which is always active. There is no way for the user to override this, to make it active in (say) phase 1 and later. If you could, that would solve your problem. The only straightforward solution I can see is to make the built-in rule for class methods inactive in phase 2, so that user-written rules take precedence. The trouble with this is that it will delay the moment at which the per-instance functions (which may have rules of their own) become visible. Rather than attempt a change with global consequences, I suggest that you simply make a new intermediate function, just as you have done with `ida'`. Instead of NOINLINE you can say `INLINE [1]` which will inline it in phase 1. Now write your rules for `ida'`. This has the effect of delaying the built-in class-method rule for `ida` without affecting any other functions. I'll add a paragraph to the user manual about this. And I'll close this as wont-fix, because there is a good workaround and no obviously better design. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10595#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler