Handle specialisation of recursive function that does not always preserve the arguments (MPR#7291)#780
Handle specialisation of recursive function that does not always preserve the arguments (MPR#7291)#780chambart wants to merge 4 commits intoocaml:trunkfrom
Conversation
|
Hmm, I think this might be plausible for 4.04 actually. I'm going to tidy it up a bit. |
|
I haven't read the patch properly yet, but doesn't this risk adding closure allocations when specializing a function. We're currently careful to only request specialisation when a set of closures has no free variables, whilst this change seems to add the original set of closures as a free variable of the new set. |
|
@chambart Please see chambart#33 -- I suggest merging that and then re-reading. I haven't got time to test this before going away; could you write some tests (ideally in the testsuite) including a distillation of the original problem from #731? If that all works, I think we should merge this in 4.04 instead of my original hack. I think it would be a mistake not to fix this problem in 4.04. |
|
@lpw25 Hmm, I'm not sure it will. Given the current behaviour of |
|
I don't think it matters if the calls are in subfunctions. In order for the old set of closures to be available when we create those subfunctions it is going to need to be a free variable of the new set of closures. |
|
Actually, I think this is probably fine. The new free variables are necessarily pointing to closures which themselves have no free variables. Even though flambda doesn't express it, such closures will be statically allocated and so the free variables will disappear, and I think this means there will be no closure allocation. This inability of flambda to understand that closures with no free variables will always be statically allocated -- even when other scoping issues prevent them from being lifted to symbols -- is quite annoying. At some point it will probably need to be addressed. There are still some downsides to this approach. For instance, the existence of free variables will prevent the new set of closures from being further specialised. |
Make Inlining_transform.inline_by_copying_function_declaration robust to Invariant_params being an overaproximation.
|
I tried to make a self contained test exposing the problem, but there are too many interactions to make a robust one. This clearly ask for something to help writing intricate inlining test cases. It could be done either with an inline attribute telling during which inlining phase to force the inline of a function (here specializing the call site before inlining the calls inside the body of the function). Or a concrete syntax for flambda could do (but would be awful to write with all the attributes everywhere...). |
|
You are right @lpw25 this is certainly inelegant (at least) to not be able to consider that as closed function even if we certainly know that it will be the case. I am still unsure what would be the right approach with the less downsides on that point. @damiendoligez This is quite an important bugfix for 4.04 do you approve in principle for something like this at that point in the release ? |
|
@damiendoligez Ping |
|
Since it fixes a rather important bug and it only impacts flambda, I have no problem merging this into 4.04, but you guys need to choose between this one and #731. |
|
@mshinwell @chambart @lpw25 |
|
I think we are waiting for @chambart to return from vacation before making a decision |
|
@damiendoligez Yeah, I'm sorry, we all need to round up on this one again. I think we need to wait until next Monday. |
|
Let's say at least tuesday, I will be too wasted on monday to give a sensible answer. |
|
No problem. |
|
@chambart Leo and I discussed this again and we think merging this one is probably best, since it seems more principled and possibly safer. If you are in agreement please go ahead. |
|
@chambart : Ping |
|
This is not completely certain, but https://forge.ocamlcore.org/tracker/index.php?func=detail&aid=1674&group_id=54&atid=291 is probably an instance of this bug. |
|
We've agreed this is the right way to go, and will merge now. |
|
This branch was based on trunk, so this was manually pushed to 4.04 |
…ins_effects Backport of pr770
* Implement "destroyed" on the CFG representation. * rebase * ocamlformat
* Rename `.gitattribute` to `.gitattributes` * Treat .eml as .html Co-authored-by: Cuihtlauac ALVARADO <cuihtmlauac@tarides.com>
This is a followup to #731
The other solution to fixing MPR#7291 is to drop the requirement from the parameter invariance analysis from being an over-approximation.
This is done by some rewriting of specialised functions before freshening. Every recursive calls that are not obviously preserving the arguments that will be specialised call the original function instead of a recursive call to the specialised version.
This is a bit more complex than originally expected to be able to multiply recursive functions like:
This change is not the most efficient possible: There are 3 added rewritings of the functions.
Some could be eliminated. This is only a first proposal.