-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Another Compaction Bug (Sorry) #1909
Comments
I think a similar problem came up during our synchronous meeting. One of the things I said is that promotion decisions need to be committed before they are allowed to influence other components so maybe that is a possible solution? I think merging is not a very scalable solution if we want other passes to exist in the pipeline between static inference and promotion. |
Yeah, I remember going over a similar problem (sorry, I forgot about this detail when implemented things). I don't love the idea of merging compaction and promotion, but I'll try to explain why I can't think of any good alternatives. Currently the order of passes is: inference->compaction->promotion.
For inference, I don't think this principle is necessary. In other words, if For compaction, I agree with this principle. In other words, we need to be committed to a decision on whether to promote If we want to be committed to a promotion decision for
(Compaction before promotion can't work if we want to follow this principle, since we don't know if we are promoting The problem with Promotion before CompactionIt's basically this issue: #1852. Basically, when we compact Another note: solution (2) in the original comment might work, but it doesn't follow this principle. It makes compaction decisions dictate promotion decisions rather than the other way around (i.e., if we make the decision to compact |
After a synchronous discussion last Thursday, we couldn't really come up with any other solution besides merging the passes. (The reason(s) are outlined in the above comment) We agreed to the following plan: try to externalize compaction into an analysis, and merge compaction and promotion. This way, if we decide that the passes are better separate, hopefully it will be less effort to merge them. |
Okay, sounds good! Thanks for thinking about this. I think a good litmus test for this merge is figuring out another pass that needs to live between inference and promotion (i.e. one that relies on control programs that can be rescheduled) and seeing what kind of interface it needs to use. |
Yeah, so if I imagine an imaginary pass that lives between inference and promotion, here's what it would have to do. tl;dr it will have to call In more detail: It will probably require an It will have to call Also, it will have to have a Finally, the Not perfect but overall pretty low effort? |
Interesting! I wonder if this pattern can be abstracted into a little trait that overrides the visitor methods and does this fixup for the pass. Then, instead of implementing Visitor, a user could implement that trait and rely on the overridden methods to do the right thing. |
Yeah, I think this makes sense to me. One question about what you had in mind (correct me if any of my assumptions are wrong): It seems like we want to be able to provide whoever is writing the pass with all of the familiar functions, like |
Yeah, I think there would need to be some repeated behavior between the two implementation. Ideally, we can override the top-level function responsible for dispatching to the |
I just realized my fix for #1852 still leaves another bug.
Suppose we have a component foo that is
@promotable
If we compact the following
seq
this means that we need
foo
to bestatic
, since compaction involves taking@promotable -> static<n>
control. (Also, any components thatfoo
instantiates now also need to be promoted tostatic
).However, the decision to make
foo
--or any other component--static doesn't happen until thestatic-promotion
pass, which runs after compaction. There's nothing in the promotion pass that forcesfoo
to be static.Solution/Future Direction
One solution could be to merge compaction and promotion passes, since they are philisophically doing the same thing (converting dynamic code to static code). One reason why I don't think this is actually too bad is that most of the analysis in the compaction pass is externalized to analyses. In fact, if you look at the code of the
finish_seq
function for both compaction and promotion, there are actually some similarities: they basically iterate thru the existingseq
, but the actual conversion of theseq
tostatic control
is outsourced to a separate function.Another solution is, in the compaction pass, to keep a list of all the components we have committed to promotion (i.e., all the components whose go port was written to in a seq that we compacted). At the end, we attach an attribute to all the components that must be static, and the promotion pass must promote them. This will lead to more aggressive promotion than before.
I'm still not 100% sure which solution is better, so I'd be happy to hear other people's thoughts.
Either way, there’s still the overall question of how to apply the promotion heuristics. I propose that, long-term, there should be some sort of universal promotion heuristic that applies to both compaction and promotion, while in the short term, we apply compaction aggressively (that is what we are doing currently), while performing generic promotion based on the heuristics.
The text was updated successfully, but these errors were encountered: