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

Make "external f: 'a => 'b;" shortcut for empty string #2537

Merged
merged 1 commit into from
Jan 29, 2020

Conversation

romanschejbal
Copy link
Contributor

This is a followup to #2464 based on the discussion in there.

@@ -405,9 +405,10 @@ type reactClass;

/* "react-dom" shouldn't spread the attribute over multiple lines */
[@bs.val] [@bs.module "react-dom"]
external render: (reactElement, element) => unit;
external render: (reactElement, element) => unit =
"render";
Copy link
Member

Choose a reason for hiding this comment

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

this is regressing from #2464 in that the printer shouldn't print the = "render"; part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure as the input for this particular output looks like this

/* "react-dom" shouldn't spread the attribute over multiple lines */
[@bs.val] [@bs.module "react-dom"]
external render : (reactElement, element) => unit = "render";

And the tests are passing, too. There's something else failing on the CI though which I don't understand.

Copy link
Member

Choose a reason for hiding this comment

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

I think we agreed in the last PR that if the ident and the primitive name agree we can drop it on the floor, but I could be misremembering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or did I misunderstand the assignment from Bob? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to drop it if they are the same too btw. But I don't know all the in & outs of bs.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I didn’t read the discussion in the other issue.

I disagree with the outcome, but oh well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you all know this, but I still want to write this out for anyone following this discussion.

@anmonteiro I think we agreed in the last PR that if the ident and the primitive name agree we can drop it on the floor, but I could be misremembering

With this behavior, it would be a breaking change for BuckleScript.
The recommendation is to always explicitly write the string value, even if the identifier matches the value itself.

[@bs.val] [@bs.module "react-dom"]
external render : (reactElement, element) => unit = "render";

Previously, you could leave it out blank as well, but this will now yield a warning that this is discouraged. As @bobzhang said, the reason is to prevent binding errors due to quick renaming of the identifier (with the punning, you wouldn't even know what's going on, especially if you are newcomer and never used the string representation for some reason).

Why does [@bs.obj] require a = "" then? This seems to be documented here:

[@bs.obj] external route: (
  ~_method:string,
  ~path:string,
  ~action:(list(string) => unit),
  ~options:Js.t({..})=?,
  unit
) => _ = "";

Note: the = "" part at the end is just a dummy placeholder, due to syntactic limitations. It serves no purpose currently.

So i guess the whole goal of this general external syntax feature is to get rid of this confusing [bs.obj] syntax?

@bobzhang
Copy link
Contributor

The diff looks good to me.
Note the old PR changed the semantics that's why it broke our CI.
I argued for dropping the punning since it makes refactoring fragile (for both C and JS) but have no strong opinions -- we used to like punning but figured it does not work with editor based refactoring (cc @chenglou)

@romanschejbal
Copy link
Contributor Author

Thanks for the clarification @ryyppy 👌

Can someone point me in the direction of how can I make the CI happy? Menhir version seems to be incompatible?

@cristianoc
Copy link
Contributor

CI breaks for unrelated reasons (also happens on a change-nothing diff which used to build OK).

@cristianoc cristianoc merged commit 528ad4b into reasonml:master Jan 29, 2020
@jordwalke
Copy link
Member

jordwalke commented Jan 30, 2020

@anmonteiro I think you and I agree on what would be ideal here. Punning is nice because if you omit a string, there's really only one thing you could ever want it to be - punned. The only exception is if you have to be using the current version of bs's ppx (which many are). Since breaking people isn't an option, we need to find a way to get to the ideal state without breaking people. Do you have an alternative suggestion to get to the ideal state of punning without breaking anyone?

There's a couple of changes that we are making a list of that need to be coordinated with a bs release. One is fixing label mangling, and the other is this punning. I'm keeping a list of these things.

@jordwalke
Copy link
Member

@bobzhang What would be involved in making the next release of bs gracefully ignore the contents of the string when using bs.obj? It seems like that would be a non-breaking BS change, that allows us to add this feature back. Without bs being graceful in allowing that, it is currently eating up a nice syntactic real estate for non-bs use cases (needlessly?)

@TheSpyder
Copy link

TheSpyder commented Feb 12, 2020

With this update, isn't the change list for 3.6.0 incorrect?

external myFn: (string) => unit is now equivalent to external myFn: (string) => "myFn"

(putting aside the typo, it should read external myFn: (string) => unit = "myFn")

I saw that and expected to be able to remove the = "myFn" from my code but I still get BS warning 105. This PR explains why.

@ryyppy
Copy link
Contributor

ryyppy commented Feb 12, 2020

@TheSpyder jup, i opened a PR a few days ago #2540 ... hasn't been merged yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants