Skip to content
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

Avoid generating calls to Curry when adjusting arity of uncurried f… #6870

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented Jul 11, 2024

…unctions.

A function such as this one:

let t4 = ({contents: x0}, {contents: x1}, {contents: x2}, {contents: x3}) => (x0, x1, x2, x3)

is 4 nested functions each one extracting the contents field. In uncurried mode, the arity is adjusted to be 4, by putting a wrapper on top. The wrapper was added by applying all the new args at once, which requires Curry runtime.

…unctions.

A function such as this one:
```
let t4 = ({contents: x0}, {contents: x1}, {contents: x2}, {contents: x3}) => (x0, x1, x2, x3)
```

is 4 nested functions each one extracting the `contents` field.
In uncurried mode, the arity is adjusted to be 4, by putting a wrapper on top.
The wrapper was added by applying all the new args at once, which requires `Curry` runtime.
@cristianoc cristianoc force-pushed the uncurry_arity_adjustment branch from da19b3d to c550944 Compare July 11, 2024 08:27
@cristianoc cristianoc requested review from cknitt and zth July 11, 2024 08:27
@cknitt
Copy link
Member

cknitt commented Jul 11, 2024

@cristianoc
Copy link
Collaborator Author

I don't understand why nested function calls are generated at all for >3 parameters.

https://rescript-lang.org/try?version=v11.1.2&code=DYUwLgBArmDMEF4IAoDeBjA9gOzCXAzgFwQAeADAL4A0EGOehJpAjDXVrvmMWQEyUAlIgB8KCrVaS+ggFCzQkGABZEKelyZkqtDYx7M2uzvt6kBxhtzOwho8eUktpk2HKA

Multiple args with pattern matching are internally represented as nested functions with arity 1.
Then a transformation is applied to wrap this into a function of several args, and the new parameters are passed down to the nested functions.
Then a bunch of optimizations kick in, which might or might not remove/ inline the nested functions based on whatever optimization heuristics are applied based on the complexity of the example.

@cristianoc
Copy link
Collaborator Author

One could write the code by hand, wrapper etc, and observe different optimizations based on on the complexity.

@cristianoc
Copy link
Collaborator Author

Improving the existing optimizations, which are not about uncurried functions, is a good question, but separate.

@cristianoc cristianoc merged commit eb4c157 into master Jul 12, 2024
19 checks passed
@cristianoc cristianoc deleted the uncurry_arity_adjustment branch July 12, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants