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

DRAFT ServiceLoader implementation for J2CL+Closure #245

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

niloc132
Copy link
Member

@niloc132 niloc132 commented Nov 26, 2023

Adds a custom compiler pass that optimizes a particular pattern of JS code, with a simple integration test that confirms that the fully-optimized output contains only the expected implementation, and no strings remain from the unused implementation.

Before merging, the JS example should be rewritten to handmade java (plus required shim JS), to specify an expected pattern to follow. Should also consider a "service loader version" to ensure that any given implementation confirms to these expectations, should they need to evolve further.

By itself, this will not work with a multi-stage build - another custom pass could be required, or requiring the use of goog.LOCALE to drive the selected property.

Partial #244

@niloc132
Copy link
Member Author

niloc132 commented Nov 27, 2023

At this point we have a working build for plain JS. For reference, here's the final output for the current sample, correctly picking just one implementation, removing the other, and inlining the results of the constant expressions:

(function(){globalThis.g=function(){};setTimeout(function(){return console.log("Hello, Java!")},100);}).call(this);

Note that globalThis.g=function(){} appears to be leftovers from a pass that builds a $J2CL_PRESERVE$ extern function - according to closure-compiler documentation this node should be removed, but clearly isn't. Definition in j2cl:
https://github.com/Vertispan/j2cl/blob/aa5f8c2eec98b5314071f96572a9002599754279/jre/java/java/lang/jre.js#L55-L59

The next step for this PR is to establish a Java (with some shim JS, probably will be generated) pattern that still compiles out nicely.

@niloc132 niloc132 added closure Related to the closure-compiler j2cl Related to the j2cl transpiler labels Nov 27, 2023
@niloc132 niloc132 added this to the 0.22 milestone Nov 27, 2023
@niloc132 niloc132 linked an issue Nov 27, 2023 that may be closed by this pull request
@niloc132 niloc132 modified the milestones: 0.22, 0.23 Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closure Related to the closure-compiler j2cl Related to the j2cl transpiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant