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

Switch on uncurried #6864

Merged
merged 8 commits into from
Jul 17, 2024
Merged

Switch on uncurried #6864

merged 8 commits into from
Jul 17, 2024

Conversation

cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented Jul 8, 2024

Build the compiler in uncurried mode, following on from #6764

This PR only changes the way the compiler is built, so it's easier to take a look at any differences in the generated code.

No Curry runtime is used in the library/tests now.

@cristianoc
Copy link
Collaborator Author

As one datapoint, the rescript-vscode tests give identical results on this PR w.r.t. master.

@@ -6,5 +6,5 @@
2 │ let makeVariables = makeVar(.~f=f => f)
3 │

This uncurried function has type (. ~f: 'a => 'a, unit) => int
This uncurried function has type (~f: 'a => 'a, unit) => int
Copy link
Member

Choose a reason for hiding this comment

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

In a separate PR, we should change "This uncurried function has ..." to "This function has ...".

let getOpt = Belt_Option.mapWithDefault;
function getOpt(opt, $$default, foo) {
return Belt_Option.mapWithDefault(opt, $$default, foo);
}
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this and at the ImmutableArray example, it seems that some optimization was lost here.

This is the ReScript code:

let getOpt = (opt, default, foo) => opt->Option.mapWithDefault(default, foo)

let even = odd;
function even(y) {
return odd(y);
}
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@@ -338,16 +338,16 @@ function xor(n1, n2) {
function hwb(n) {
let h = function (i, j) {
if (i === j) {
return mkNode("Zero", i, "One");
return mkVar(i);
Copy link
Member

Choose a reason for hiding this comment

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

Again inlining lost

@@ -71,7 +73,8 @@ function mergeDiff(s1, s2) {
}

}));
return Belt_Set.fromArray(Belt_MapDict.keysToArray(m.data), Icmp);
let x = Belt_MapDict.keysToArray(m.data);
return Belt_Set.fromArray(x, Icmp);
Copy link
Member

Choose a reason for hiding this comment

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

A temporary variable x is created here now which wasn't the case before.

@@ -202,7 +204,9 @@ b("File \"bs_poly_mutable_set_test.res\", line 94, characters 4-11", Belt_Mutabl

b("File \"bs_poly_mutable_set_test.res\", line 95, characters 4-11", Belt_MutableSet.subset(bb, v));

b("File \"bs_poly_mutable_set_test.res\", line 96, characters 4-11", Belt_MutableSet.isEmpty(Belt_MutableSet.intersect(aa, bb)));
let d$1 = Belt_MutableSet.intersect(aa, bb);
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@cristianoc cristianoc force-pushed the audit-curried branch 2 times, most recently from e418d93 to c57264c Compare July 13, 2024 18:06
@cristianoc cristianoc changed the base branch from audit-curried to master July 14, 2024 06:42
@cristianoc
Copy link
Collaborator Author

cristianoc commented Jul 14, 2024

@cknitt @zth I have now run out of things to test this. Let me know if you think of anything else to check.

@cknitt cknitt mentioned this pull request Jul 14, 2024
3 tasks
@cknitt
Copy link
Member

cknitt commented Jul 14, 2024

To test, I tried to compile a large project of ours.
This failed because Js_typed_array was removed in a previous PR, but rescript-webapi depends on it.

@zth
Copy link
Collaborator

zth commented Jul 14, 2024

To test, I tried to compile a large project of ours. This failed because Js_typed_array was removed in a previous PR, but rescript-webapi depends on it.

I assume it depends on the types only? Should be easy to add back the types.

@cknitt
Copy link
Member

cknitt commented Jul 14, 2024

Yes, patching it to replace Js.typed_array with Js_typed_array2 gets things to build again.

However, the result doesn't run.

The compiler now emits

          ...
          title: JsxRuntime.jsx((function (prim) {
            return ReactIntl.FormattedMessage;
          }), {
          ...

instead of

          ...
          title: JsxRuntime.jsx(ReactIntl.FormattedMessage, {
          ...

Would have to investigate where this was introduced, can look into it tomorrow.

@cristianoc
Copy link
Collaborator Author

My guess is that either some external is wrong, or there's a compiler bug on the arity of the external.
And that the same isso exists on master when compiling in uncurried mode, but not before the PR that handles arity in externals.

@cknitt
Copy link
Member

cknitt commented Jul 15, 2024

@cristianoc You guessed correctly! I created #6880 for this.

@cristianoc
Copy link
Collaborator Author

cristianoc commented Jul 16, 2024

@cristianoc You guessed correctly! I created #6880 for this.

Let me know what other issues are left now.

@zth
Copy link
Collaborator

zth commented Jul 16, 2024

@cknitt could you add back the types needed in a separate PR perhaps?

@cknitt
Copy link
Member

cknitt commented Jul 17, 2024

@cknitt could you add back the types needed in a separate PR perhaps?

Yes, will do.

@cknitt
Copy link
Member

cknitt commented Jul 17, 2024

Let me know what other issues are left now.

No other issues left from my point of view.

@cristianoc cristianoc merged commit 7d6b8d9 into master Jul 17, 2024
19 checks passed
@cristianoc cristianoc deleted the switch-on-uncurried branch July 17, 2024 14:30
@cknitt
Copy link
Member

cknitt commented Jul 18, 2024

@cknitt could you add back the types needed in a separate PR perhaps?

#6891

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