Skip to content

New mechanism to determine arity of externals. #6874

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

Merged
merged 1 commit into from
Jul 13, 2024
Merged

Conversation

cristianoc
Copy link
Collaborator

The arity of external declarations is currently determined just based on the untyped parse tree. This is probably because the "real" arity is ambiguous in curried mode, and the convention is that an explicit type of the form t1 => t2 => t3 determines arity 2, but type aliases are ignored.

Here's an example:
https://rescript-lang.org/try?version=v11.1.2&code=C4TwDgpgBArlC8UAUBLAdsANFdwCUCAfDhgFAACAbgIYA2UEAHsBAE5p1SUCMAXLAigAiSkKgB6cVGqsUoKADNWAewC2AlAGccqsLRQBjORRr0mLdp0oAmfqgzZcBeMVyCRYydNnytDRnqGxqS0EMCK3IKMRFzcSIyYjHghYYrWUTE28YnJQA

In the example

type u = (int, int) => int
@val external v1: u = "v" // arity from u is implicit
@val external v2: (int, int) => int = "v" // arity is explicit

let f1 = x => v1(x,x)
let f2 = x => v2(x,x)

we have that v2 is determined to have arity 2, but the arity of v1 is not determined. As a consequence, the code generated for f1 uses runtime Curry, both in curried an uncurried mode.

This PR uses the actual type coming from the type checker when in uncurried mode, as that does not suffer from ambiguity.

The consequences are that the external behaves the same however the type is defined, and in the example, no Curry runtime is generated.

@cristianoc cristianoc force-pushed the new_external_arity branch from 610d619 to 908ffe8 Compare July 13, 2024 07:02
@cristianoc cristianoc requested review from cknitt and zth July 13, 2024 07:02
@cristianoc cristianoc force-pushed the new_external_arity branch from 908ffe8 to 98ff408 Compare July 13, 2024 07:05
Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@cristianoc cristianoc force-pushed the new_external_arity branch from 98ff408 to 7a53982 Compare July 13, 2024 07:08
The arity of external declarations is currently determined just based on the untyped parse tree.
This is probably because the "real" arity is ambiguous in curried mode, and the convention is that an explicit type of the form `t1 => t2 => t3` determines arity 2, but type aliases are ignored.

Here's an example:
https://rescript-lang.org/try?version=v11.1.2&code=C4TwDgpgBArlC8UAUBLAdsANFdwCUCAfDhgFAACAbgIYA2UEAHsBAE5p1SUCMAXLAigAiSkKgB6cVGqsUoKADNWAewC2AlAGccqsLRQBjORRr0mLdp0oAmfqgzZcBeMVyCRYydNnytDRnqGxqS0EMCK3IKMRFzcSIyYjHghYYrWUTE28YnJQA

In the example

```res
type u = (int, int) => int
@Val external v1: u = "v" // arity from u is implicit
@Val external v2: (int, int) => int = "v" // arity is explicit

let f1 = x => v1(x,x)
let f2 = x => v2(x,x)
```

we have that `v2` is determined to have arity 2, but the arity of `v1` is not determined.
As a consequence, the code generated for `f1` uses runtime `Curry`, both in curried an uncurried mode.

This PR uses the actual type coming from the type checker when in uncurried mode, as that does not suffer from ambiguity.

The consequences are that the external behaves the same however the type is defined, and in the example, no `Curry` runtime is generated.
@cristianoc cristianoc force-pushed the new_external_arity branch from 7a53982 to 5dfdabf Compare July 13, 2024 07:10
@cristianoc cristianoc merged commit f41f93a into master Jul 13, 2024
19 checks passed
@cristianoc cristianoc deleted the new_external_arity branch July 13, 2024 12:40
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