Limit the number of parameters for an uncurried or untupled function#9620
Merged
xavierleroy merged 3 commits intoocaml:trunkfrom Jun 5, 2020
Merged
Limit the number of parameters for an uncurried or untupled function#9620xavierleroy merged 3 commits intoocaml:trunkfrom
xavierleroy merged 3 commits intoocaml:trunkfrom
Conversation
mshinwell
requested changes
Jun 1, 2020
Contributor
mshinwell
left a comment
There was a problem hiding this comment.
A couple of comments:
- Flambda can add extra arguments to functions during some of its unboxing passes, but they are limited by the number set in the
Backendmodule (seeoptmain.ml). This should always be (much) lower than the new limit here, since the Flambda transformations don't want to break tail recursion. - Flambda uses the worker-wrapper technique for tupled functions, so I think this code needs modifying, to not do this transformation if the size of the tuple is over the limit. See
tupled_function_call_stubinmiddle_end/flambda/closure_conversion.ml. - Could we please have a backstop in
cmmgen.mlor thereabouts that ensures a fatal error is generated if we do end up generating functions with too many parameters?
Contributor
Author
That's part of the other pull request, #9619, file asmcomp/cmm_helpers.ml, line 79. |
Contributor
Author
|
Concerning Flambda, I'm not competent to work on it. Would you @mshinwell, or perhaps @chambart or @lthis, please update Flambda as appropriate? Feel free to push to my branch. |
lthls
reviewed
Jun 2, 2020
Contributor
|
@xavierleroy As per the comment I've just resolved, I was mistaken; I don't think we need to do anything with Flambda. This should be good to merge once the CI passes, then. |
mshinwell
approved these changes
Jun 2, 2020
This commit introduces a quantity Lambda.max_arity that is the maximal number of parameters that a Lambda function can have. Uncurrying is throttled so that, for example, assuming the limit is 10, a 15-argument curried function fun x1 ... x15 -> e becomes a 10-argument function (x1...x10) that returns a 5-argument function (x11...x15). Concerning untupling, a function that takes a N-tuple of arguments, where N is above the limit, remains a function that takes a single argument that is a tuple. Currently, max_arity is set to 126 in native-code, to match the new representation of closures proposed in ocaml#9619. A signed 8-bit field is used to store the arity. 126 instead of 127 to account for the extra "environment" argument. In bytecode the limit is infinity (max_int) because there are no needs yet for a limited number of parameters.
Addresses review comment. To be squashed with 941c05b
25c85d6 to
9d31539
Compare
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 commit introduces a quantity
Lambda.max_aritythat is the maximal number of parameters that a Lambda function can have.Uncurrying is throttled so that, for example, assuming the limit is 10, a 15-argument curried function
fun x1 ... x15 -> ebecomes a 10-argument function (x1...x10) that returns a 5-argumentfunction (x11...x15).
Concerning untupling, a function that takes a N-tuple of arguments, where N is above the limit, remains a function that takes a single argument that is a tuple.
Currently,
max_arityis set to 126 in native-code, to match the new representation of closures proposed in #9619. A signed 8-bit field is used to store the arity. 126 instead of 127 to account for the extra "environment" argument.In bytecode the limit is infinity (
max_int) because there are no needs yet for a limited number of parameters.