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

True literal types and union types for scala 3! #487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oyvindberg
Copy link
Collaborator

@oyvindberg oyvindberg commented Oct 13, 2022

Kapture.2022-10-13.at.14.40.36.mp4

On the scala side it's very (, very, very) difficult to handle erasure of methods in the presence of many overloads, when useful information added by literal types. Especially if you want to consider inheritance hierarchies, maintain high fidelity translation, and make it usable for end-user. It's borderline impossible, which is why ST has used the fake literal types which invents fake traits for all the literals. Suffixing of overloaded methods has also been used (createElement_div, for instance)

Now we use @targetName to disambiguate overloads. All methods which have literal types will get a targetName containing the method name and all the contained literals.

Like before, @JSName will be used to communicate the original method name to Javascript

Effectively, this creates a new namespace on the Scala side, and we can perform erasure checks like normal for all overloads with the same sequence of literals. It all seems to work out really well.

ST has until now (best-effortly) translated union types into inheritance. This was done to make things usable. scalac and IDE performance suffered before that hack, and IDE tooling was helpless when confronted with Scala.js' userland union type. This has all changed, and it's incredibly liberating to finally remove this hack too.

@oyvindberg
Copy link
Collaborator Author

Note that this branch relies on a fix for scala/scala3#16173 , so I used a locally built compiler which removes that particular check.

@oyvindberg
Copy link
Collaborator Author

Also props to @TheElectronWill who suggested this in #343 (comment)

On the scala side it's very, (, very, very) difficult to handle erasure of methods in the presence of many overloads, when useful information added by literal types. Especially if you want to consider inheritance hierarchies, maintain high fidelity translation, and make it usable for end-user. It's borderline impossible, which is why ST has used the fake literal types which invents fake traits for all the literals. Suffixing of overloaded methods has also been used (`createElement_div`, for instance)

Now we use @TargetNAME to disambiguate overloads. *All* methods which has literal types will get a `targetName` will containing the method name and all container literals.

Like before, `@JSName` will be used to communicate the original method name to Javascript

Effectively, this creates a new namespace on the Scala side, and we can perform erasure checks like normal for all overloads with the same sequence of literals. It all seems to work out really well.

ST has until now (best-effortly) translated union types into inheritance. This was done to make things usable. scalac and IDE performance suffered, and IDE tooling was helpless when confronted with Scala.js' userland union type. This has all changed, and it's incredibly liberating to finally remove this hack too.
@oyvindberg oyvindberg force-pushed the true-literal-and-union-types branch from 802a7e6 to 57a2058 Compare November 16, 2022 20:53
@oyvindberg
Copy link
Collaborator Author

preview of changes here ScalablyTyped/Distribution@dd3ce51

@TheElectronWill
Copy link

Amazing!
The code reduction is quite impressive 😄
image

scala/scala3#16173 is fixed in v3.2.1 :)

oyvindberg added a commit to oyvindberg/st-material-ui that referenced this pull request Dec 14, 2022
deps:
        "@emotion/react" -> "11.10.5",
        "@emotion/styled" -> "11.10.5",
        "@mui/material" -> "5.11.0",
        "@mui/icons-material" -> "5.11.0",
        "@types/react" -> "18.0.26",
        "@types/react-dom" -> "18.0.9",
        "@types/stylis" -> "4.0.2",
        "react" -> "18.2.0",
        "react-dom" -> "18.2.0"

Upgraded ST to 1.0.0-beta40
- includes " True literal types and union types for scala 3!" @ ScalablyTyped/Converter#487
- includes https://github.com/ScalablyTyped/Converter/tree/mui5-support

As a consequence this should be much, much nicer to use than before
@nkgm
Copy link

nkgm commented Apr 1, 2023

Thank you for all the hard work you've put into this project 🙏
I was thinking about using this in an upcoming project. Any plans of merging, or is this meant to be an ad-hoc thing?

@oyvindberg
Copy link
Collaborator Author

Thank you for all the hard work you've put into this project 🙏 I was thinking about using this in an upcoming project. Any plans of merging, or is this meant to be an ad-hoc thing?

Thanks :)

Yes, this will be merged eventually. The main thing it is missing is what to do about scala 2.13 where there is no `@targetName@ annotation.

I'm deep in two other projects now, so this will be solved in the coming months. in the meantime you can publishLocal a version of the converter which should work well enough for Scala 3.

@TheElectronWill
Copy link

The main thing it is missing is what to do about scala 2.13 where there is no `@targetName@ annotation.

I don't think much can be done in Scala 2, but that's not a big deal if the generated api is better for Scala 3, is it?

@nkgm
Copy link

nkgm commented Jun 11, 2024

Hello again! Still using a local build of this branch but now running into issues updating sbt:

java.lang.RuntimeException: This version of the ScalablyTyped plugin only supports 1.8.x. You're currently using 1.9.7

I don't really mind sticking with an older version of sbt, but that effectively ties me to an older JDK. I'm guessing this should do the trick, but also wondered if there's an update, even if the update is "no update" 😅

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