Flambda fix: try to make Unbox_closures behave more reasonably#480
Merged
mshinwell merged 1 commit intoocaml:4.03from Feb 26, 2016
Merged
Flambda fix: try to make Unbox_closures behave more reasonably#480mshinwell merged 1 commit intoocaml:4.03from
mshinwell merged 1 commit intoocaml:4.03from
Conversation
Contributor
Author
|
Oh, I forgot one other thing: this patch also marks partial application wrappers as stubs, which should have been the case before. |
449cee7 to
edee702
Compare
edee702 to
0453c74
Compare
mshinwell
added a commit
that referenced
this pull request
Feb 26, 2016
GPR#480: Flambda fix: try to make Unbox_closures behave more reasonably
mshinwell
added a commit
that referenced
this pull request
Feb 26, 2016
GPR#480: Flambda fix: try to make Unbox_closures behave more reasonably
Octachron
pushed a commit
to Octachron/ocaml
that referenced
this pull request
Feb 29, 2016
GPR#480: Flambda fix: try to make Unbox_closures behave more reasonably
mshinwell
pushed a commit
to mshinwell/ocaml
that referenced
this pull request
Jul 9, 2021
Allow Rec_info_expr to express that an occurrence may be arbitrarily deep, so that we don't want to inline it automatically but may still observe an `@unrolled` attribute, or that we don't want to inline or unroll at all.
stedolan
pushed a commit
to stedolan/ocaml
that referenced
this pull request
May 24, 2022
* Add Cbswap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(This is mainly for the attention of @chambart )
@damiendoligez : This is really a somewhat lengthy bug fix that I would like to get into 4.03, unless Pierre thinks the approach is unreasonable. Can this actually get into the release candidate? There may be a few more fixes to this today, but I hope to have the thing tested pretty thoroughly by the end of the day.
This patch aims to make Unbox_closures behave more reasonably. The pass now has two options:
A direct call surrogate is a function g that will be used instead of another function f when a direct call is discovered to f. In the case of Unbox_closures, we end up with three functions:
(a) an alpha-renamed copy of the original function (this has the original fun_var), call this f;
(b) a stub, which is marked as a surrogate to f;
(c) a transformed version of the original function, without the free variable(s), which is called by the stub.
When an indirect call is discovered, nothing happens, and f is called. However upon a direct call, the set of closures instructs Inline_and_simplify to use the surrogate (the stub) instead. This of course guarantees that all such generated stubs will be inlined.
In the future, direct call surrogates could perhaps be implemented using functions with multiple entry points.
When doing the Unbox_closures transformation an estimate of the number of free variables being removed is used to calculate a benefit; this is assessed against the function's size. A scaling factor (-unbox-closures-factor) is applied, effectively multiplying the benefit, since it isn't yet clear where the sweet spot may be and this might potentially vary. If the benefit exceeds the size then the transformation will be willing to duplicate and generate a surrogate (case 2 above). Otherwise it proceeds with case 1 as usual.
Most of this patch is actually just moving code around to write the function that duplicates another function with the appropriate alpha-renaming. We will probably need this in the future in any case. It's also made simplify_set_of_closures rather more readable.
This patch also increases the default inline allocation cost, which we suspect is too low.