8000 Introduce a binary API with Scala functions in `Reflect`. by sjrd · Pull Request #5161 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Introduce a binary API with Scala functions in Reflect. #5161

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sjrd
Copy link
Member
@sjrd sjrd commented May 1, 2025

And make its internals independent of JS interop.
This way, it will be usable in Wasm without JS host.

We use new names for the methods, instead of overloads, because older compilers look for those methods by name only. If an older compiler gets a newer library on the classpath, and the methods with those names became overloaded, the compiler would crash.

In the commit, we do not change the compiler yet, to test that the deprecated methods are correct.

In the second commit, we change the compiler to use the new APIs.


This does not bring any immediate benefit. It's more for a long-term vision. But it also shouldn't hurt, besides the cost of maintaining a deprecated pair of methods. If we had had NewLambda all along, I think we would have designed this API using the Scala types to begin with. The Reflect object never pretended to be Scala-agnostic, since its public API is full of Scala types anyway.

@sjrd sjrd requested a review from gzm0 May 1, 2025 15:17
sjrd added 2 commits May 3, 2025 11:15
And make its internals independent of JS interop.
This way, it will be usable in Wasm without JS host.

We use new names for the methods, instead of overloads, because
older compilers look for those methods by name only. If an older
compiler gets a newer library on the classpath, and the methods
with those names became overloaded, the compiler would crash.

In this commit, we do not change the compiler yet, to test that the
deprecated methods are correct.
@sjrd sjrd force-pushed the reflect-use-newlambda branch from 6b00b7f to b223873 Compare May 3, 2025 09:16
@gzm0
Copy link
Contributor
gzm0 commented May 4, 2025

I think this is a worthwhile thing to do. Have you given any thought whether we should attempt to make the reflect API Scala agnostic as well? It seems it only relies on Scala only (i.e. non Scala.js IR) concepts superficially.

IDK when we first designed this, but it might have been well before the times of the Scala independent javalib. With it, I wonder if we should at least make the interface we design now Scala independent.

@sjrd
Copy link
Member Author
sjrd commented May 4, 2025

We can make the new registration API not use any Scala type. But it won't change the fact that the public API exposes Options, Lists and Seqs (through varargs). We could add new Java-friendly accessors. Whatever we do, however, that library will need a dependency on the Scala library.

We also need a Java type for the pair of Class to constructor data. Maybe a java.util.Map.Entry[_]?

@gzm0
Copy link
Contributor
gzm0 commented May 20, 2025

I've been thinking about this and I'm wondering if it would make more sense to specify registration in terms of IR opcodes. It's essentially functionality provided by the runtime.

But it won't change the fact that the public API exposes Options, Lists and Seqs (through varargs). We could add new Java-friendly accessors. Whatever we do, however, that library will need a dependency on the Scala library.

But couldn't we make the core implementation rely on Java only and keep the Scala interface an adapter?

We also need a Java type for the pair of Class to constructor data. Maybe a java.util.Map.Entry[_]?

Yeah... feels a bit of a stretch after having read the Javadoc, but maybe :-/

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.

2 participants
0