[GHC] #13966: Skip-less stream fusion
GHC
ghc-devs at haskell.org
Sat Jul 15 19:06:22 UTC 2017
#13966: Skip-less stream fusion
-------------------------------------+-------------------------------------
Reporter: jmspiewak | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.1-rc3
Resolution: | Keywords: JoinPoints
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 mpickering):
Here's how I am understanding this post as I have also been thinking about
this recently.
1. In the Join Points PLDI paper there is an example in section 5 where
join points allows `find` defined in terms of `any` to fuse. The author
wants(/expects(?)) this technique to also fuse together normal functional
pipelines as well as this simple examples.
2. The introduction of type classes seems irrelevant to the first point.
GHC has quite a few optimisations which it uses to eliminate type classes
and you can play lots of tricks around this to cause fusion like this to
happen. If you look at the code is structured, in `sum` where the specific
instance of `next3` is resolved to `Filter3 Int (EnumFromTo Int)` which
means that all the consumers nicely line up with each other and hence
fuse. The control flow of this program is very different to the first one.
3. A program with a polymorphic return type parametrised by a type class
is very similar to a program written in CPS. To see this similarity, when
writing a program in CPS in order for execution to continue you must
provide a function which says what to do next. When using type classes,
you must instead provide the *type* of the result which in then is
elaborated to a function or dictionary of functions which explain how to
proceed. Thus structuring your program in this way usually allows this
kind of fusion to happen.
4. Ah-ha! but purpose of join points is to allow the compiler to optimise
code written in direct style as well as code written in continuation
passing style so can we do better in this case? The answer to which I
don't yet know and I think is an open research problem.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13966#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list