-
Notifications
You must be signed in to change notification settings - Fork 23
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
Eliminating <clinit> on Global objects #21
Comments
My guess is the use of the Looking at window_patched.js output from the elemental2 build, I want to guess that this is just the For a workaround you probably could just disable that const check, or remove all of those |
The reason is roughly that all native static fields on types go through this If my assumptions above are right and we are willing to let the fields be non-final when reflected into java then the diff --git a/java/jsinterop/generator/visitor/FieldsConverter.java b/java/jsinterop/generator/visitor/FieldsConverter.java
index 67b32e6..06bf856 100644
--- a/java/jsinterop/generator/visitor/FieldsConverter.java
+++ b/java/jsinterop/generator/visitor/FieldsConverter.java
@@ -130,6 +130,9 @@ public class FieldsConverter extends AbstractModelVisitor {
originalType.getFields().stream().noneMatch(f -> f.isStatic() && !f.isNativeReadOnly()),
"Non constant static fields are not supported on interface");
}
+ if (originalType.isClass() || originalType.isNamespace()) {
+ return;
+ }
Type constantWrapper = new Type(EntityKind.CLASS);
constantWrapper.setAccessModifier(DEFAULT); This seems to work with preliminary tests but before I went further and actually verified it across everything and tried to get it merged I just wanted to get some feedback. I guess I can try it out locally and send in the patch regardless. May try tonight |
From the relevant design doc:
So this current __Constants solution address both of the issues. This doesn't have any impact on J2CL where this is optimized away but we didn't invest on GWT2 to write an optimization for it. |
Would you consider a pull request that added an option like It would still allow users to potentially write code that assigned a value to these fields but this would be blocked by the javascript runtime so it seems like less of an issue. |
I'm not completely against it but maybe somebody could contribute a GWT compiler optimization instead? |
That would certainly be a better solution but I don't currently have the cycles that I would need to get that right. (Or the inclination as we want to move to j2cl as soon as possible). I will try try to put together a pull request for the above when I get the time. |
After experimentation, we have decided to move directly to J2CL so no longer see this as a priority. So I will close the issue until plans change. |
I'll re-open this since I noticed we have some patterns that doesn't optimize in J2CL. Either we should improve optimizations or change the implementation. |
Currently the global object created for each module ends up potentially having a
<clinit>
if there is variables accessed in scope. For exampleelemental2.dom.DomGlobal
has aelemental2.dom.DomGlobal__Constants
. TheDomGlobal__Constants
class has static fields mapped to javascript and thenDomGlobal
re-esposes those fields by using a static final field. This results inDomGlobal
having a<clinit>
method that simply assigns theDomGlobal__Constants
fields to theDomGlobal
fields. It also mandates that most code that accesses these fields must call the clinit method first.The whole
<clinit>
dance seems like unnecessary overhead and I am trying to understand why the fields are not moved directly to theDomGlobal
class. It would result in less code and have practically the same developer experience - the only difference that I am aware is that it does not stop user code re-assigning the variables as can not be final.Is there any other reason for this approach?
The text was updated successfully, but these errors were encountered: