[GHC] #13044: make it possible to apply GHC rewrite rules to class methods

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Make it possible to apply GHC rewrite rules to class methods. As Conal wrote in a discussion on glasgow-haskell-users, it is too bad that we can't use class laws as optimizations in the form of rewrite rules. In that same thread Simon PJ referenced https://ghc.haskell.org/trac/ghc/ticket/11688, esp comment:7 which gives links to similar examples. https://ghc.haskell.org/trac/ghc/ticket/10528 comment:13 gives more background. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | 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: | -------------------------------------+------------------------------------- Changes (by nomeata): * cc: nomeata (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | 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: | -------------------------------------+------------------------------------- Changes (by snowleopard): * cc: snowleopard (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | 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: | -------------------------------------+------------------------------------- Description changed by bgamari: @@ -5,3 +5,3 @@ - https://ghc.haskell.org/trac/ghc/ticket/11688, esp comment:7 which gives - links to similar examples. https://ghc.haskell.org/trac/ghc/ticket/10528 - comment:13 gives more background. + https://ghc.haskell.org/trac/ghc/ticket/11688, especially + ticket:11688#comment:7 which gives links to similar examples. + ticket:10528#comment:13 gives more background. New description: Make it possible to apply GHC rewrite rules to class methods. As Conal wrote in a discussion on glasgow-haskell-users, it is too bad that we can't use class laws as optimizations in the form of rewrite rules. In that same thread Simon PJ referenced https://ghc.haskell.org/trac/ghc/ticket/11688, especially ticket:11688#comment:7 which gives links to similar examples. ticket:10528#comment:13 gives more background. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | 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: | -------------------------------------+------------------------------------- Description changed by bgamari: @@ -2,3 +2,4 @@ - wrote in a discussion on glasgow-haskell-users, it is too bad that we - can't use class laws as optimizations in the form of rewrite rules. In - that same thread Simon PJ referenced + wrote in a discussion on [[https://mail.haskell.org/pipermail/glasgow- + haskell-users/2016-November/026406.html|glasgow-haskell-users]], it is too + bad that we can't use class laws as optimizations in the form of rewrite + rules. In that same thread Simon PJ referenced New description: Make it possible to apply GHC rewrite rules to class methods. As Conal wrote in a discussion on [[https://mail.haskell.org/pipermail/glasgow- haskell-users/2016-November/026406.html|glasgow-haskell-users]], it is too bad that we can't use class laws as optimizations in the form of rewrite rules. In that same thread Simon PJ referenced https://ghc.haskell.org/trac/ghc/ticket/11688, especially ticket:11688#comment:7 which gives links to similar examples. ticket:10528#comment:13 gives more background. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | 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): Currently, rewrite rules, as well as unfolding (i.e. inlining) are active in certain phases, which are currently counted down from, I belive, 3 to 0. Exending this system of phases to something more expressive has always been a thought. Maybe it would help here? The smallest delta that might help is simply adding a a number of extra phases, say, from 7 to 4. The compiler would annotate all type class dictionary access functions (i.e. class methods) with `INLINE [~4]`, which would prevent them from being rewritten to the actual implementation. Then rewrite rules active in phases 7, 6 and 5 would have a pretty good chance of applying to class methods. Would this work? Obviously, one might want nicer ways of specifying phases (i.e. fixed names, or even arbitrary news with ordering constraints), but that is a slightly orthogonal discussion. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | 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 simonpj): I don't think there is anything fundamentally difficult here. Class methods have a special rewriting rule (see `MkId.dictSelRule`, which is not as well documented as it should be). It rewrites `op dict`, where `op` is a class method and `dict` is a dictionary, when possible to the type-specialised function. All we need to do is to stop that rule firing immediately. Perhaps it can fire in phase 2 (and hence 1 and 0) instead of always. That would give other rules a chance to match on it. I can't forsee all the consequences, but they should not be too drastic. But it would need careful perf testing; failure to optimise overloading can kill performance. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | 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 bgamari): The limitation described here leads to quite a bit of boilerplate in GHC itself to ensure that users can write rules against, e.g. `(==)`. See, for instance, `GHC.Int.eqInt64`. Moreover, I have seen a number of well-known packages (`text` being one example) which mistakenly try to match overloaded operators in their rewrite rules. Thankfully we now produce warnings in these cases, but previously these were latent performance bugs just waiting to be noticed. It would be great to eliminate this sharp edge. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13044: make it possible to apply GHC rewrite rules to class methods -------------------------------------+------------------------------------- Reporter: George | Owner: Type: task | 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: | -------------------------------------+------------------------------------- Changes (by mpickering): * cc: mpickering (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13044#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC