-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rules system optimization #228
Conversation
@nobrakal Thanks for the PR! I like the overall goal: introducing the vocabulary of "good" producers and consumers and making sure that all exported functions are as good as possible! It would, of course, be nice if users could write their own good producers and consumers. My concern is that users who don't know (and perhaps don't want to know) about rewrite rules will be exposed to them if we start exporting functions like I would have hoped for the notion of "goodness" to be composable, i.e. if If we make goodness compositional we will never run out of goodness! :) |
P.S.: I guess what I'm after is a "good category" :-) The identity function |
I added some comments, many functions are good producers and good consumers :D (
That why I propose to export it from
I think that, strictly speaking, the notion of "goodness" is composable. The only problem here for me is that |
@nobrakal Great! :)
OK, let's do that. I'd prefer to export it with a simpler name
Oh, I see. That's more tricky than I thought -- there are layers of goodness! |
I said it before trying, but |
@nobrakal In this case, let's export it as |
I addressed your comments. More generally, I don't know the amount of documentation we need to add... There are many things to say :) |
@nobrakal What about removing the |
Co-Authored-By: Andrey Mokhov <andrey.mokhov@gmail.com>
@nobrakal I had a thorough look through the changes and left a bunch of comments, most of which should be easy to address. Hope we can merge this soon! |
Thank you very much for your detailed review ! I addressed "simple" issues and will come back soon to more difficult ones ^^ |
@nobrakal Thanks for addressing my comments! By the way, it looks like there are some merge conflicts. Please rebase. |
@snowleopard I do not understand: it seems I am up-to-date with |
@nobrakal Oops, looks like a GitHub bug. I see
when "Rebase and merge" is selected. If I switch to "Squash and merge", which is more appropriate in this case anyway, everything gets green! |
@nobrakal OK, I think we can merge this if you are ready! |
I just found a new good consumer! Except for this, all seems green for a merge :) |
@nobrakal Merged! Many thanks for this awesome improvement :-) |
Hi,
I have been working recently with fusion, and it made me think about some optimizations that can be made to the current system for
Algebra.Graph
.This:
Change to good producers
vertices
,edges
(ie. they are now expressed directly withbuildR
)... Meaning thatfoldg e v o c . vertices xs
is optimized to a single list traversal without a custom a rule.bind
is also a good producer, so I added itsbuildR
definition directly.star
is now (in addition to be a good producer of graph), a good consumer of lists (meaning thatstar . map f
is also optimized`).The
foldr1Safe
rule is now unneeded, I removed it.I added
INLINE
pragmas to functions expressed withfoldg
.All the previous tests are passing, and the benchmarking suite is happy.
Questions
I have some questions:
Can we expose
buildR
? Maybe moving it inAlgebra.Graph.Internal
, but exposing such a function allows the end-user to define its own function usingbuildR
and benefit from fusion usingfoldg/buildR
.The whole thing needs documentation. I like the "good producer" / "good consumer" vocabulary (stolen from the GHC manual). A good consumer is a function that can be fused with a good producer, and a good producer is a function that can be fused with a good consumer. Then we can tag all concerned functions.
Because of the use of
buildR
, we need rewrite rules to be enabled (either, somefoldg Empty Vertex Overlay Connect
will not be optimized). There is no problem for the library itself, but we should add a warning about it somewhere.