-
Notifications
You must be signed in to change notification settings - Fork 374
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
dead code not eliminated when two Boolean.parseBoolean in same function #9731
Comments
The issue you’re having is due to the complexity of your I was able to take your provided example and started experimenting with it. Using the initial implementation static boolean isFeatureFooEnabled() {
if (Boolean.parseBoolean(System.getProperty("myapp.property1"))) {
return true;
}
if (Boolean.parseBoolean(System.getProperty("myapp.property2"))) {
return true;
}
return false;
} If I set both properties to $wnd.alert(‘Foo’); And it also removes the class declarations, since those are really useless by this point. If I set property1 to $wnd.alert(‘Foo’); Same thing! But when setting property1 to delegate = ($clinit_Boolean() , $clinit_Boolean() , true)?new DelegateFoo:new DelegateNoFoo;
delegate.display(); I think the reason it’s doing this is because the It’s possible that GWT could do extra pass at cleaning this up, but there are ways of implementing code to ensure code is removed properly due to being unreachable. If I were to refactor the static boolean isFeatureFooEnabled() {
return (Boolean.parseBoolean(System.getProperty("myapp.property1")))
|| (Boolean.parseBoolean(System.getProperty("myapp.property2")));
} Setting either or both properties to true now will end up getting what we’d expect; inlining of the It also means that changing both properties to In both cases, the compiler was able to remove the unreachable class declarations properly. |
Hi,
In some circumstances, unreachable code is not removed properly.
I am adding a minimal reproducible testcase:
If myapp.property1 and myapp.property2 are both set to false, the above code will compile to
So it means that even if DelegateNoFoo is never used, its code will not be removed. It's a constraint example, but in our application, those delegates are actually pretty big and depend on many other classes. It means that we end up building and shipping a lot of unused code.
If there is only one Boolean.parseBoolean, the code compiles (correctly) to
delegate = ($clinit_Boolean() , new DelegateNoFoo);
Also, if we modify isFeatureFooEnabled to
It will compile to
delegate = ($clinit_Boolean() , $clinit_Boolean() , new DelegateNoFoo);
But this is fragile and won't scale if isFeatureFooEnabled() becomes more complex
The text was updated successfully, but these errors were encountered: