-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ADVANCED compilation mode incorrectly removes non-dead code #4143
Comments
I was able to reproduce this, and minimize the example a bit more:
It looks like something in the peephole passes are causing this breakages, although I haven't identified exactly which yet. |
Hi @blickly thanks for taking a look! IIUC the example you provided seemed to work as expected, as I was able to simplify my previous example further:
Even without using Object.defineProperty and setting properties directly, the issue still exists:
|
I played around with example more, closure compiler can generate correct code for the following version that moves arrow function from the properties of
|
Oops, thanks for catching that. It still does look like one of the peephole passes is breaking the code. I think that the issue is that when determining whether
and that one actually has no side effects. It can't see the function defined on I'm honestly not sure if there's a way to fix this in the compiler without causing optimization backoff for other cases that folks care about. |
This is a common pattern for Closure compiler consumers that use webpack, and it's due to the import/export glue that webpack generates--meaning these consumers don't have control over it. Would you consider creating a command-line flag to disable this particular optimization? |
Are you using https://github.com/webpack-contrib/closure-webpack-plugin? In the abstract, without a plugin, this code is incompatible with Closure Compiler ADVANCED optimizations because from the compiler's perspective the definitions of "myFunction" are hidden by the reflective for loop. All the property optimizations will misbehave when faced with this code and you will be limited to the "SIMPLE" optimizations. The goal of the compiler would to unwind this code and flatten it so that the definitions and calls were clearly visible. |
I'm using a fork of it that was rewritten to work with webpack 5. Fundamentally all the plugin does is hook the optimization stage of webpack and create the correct input arguments for the Closure compiler. Generally, webpack is generating valid JS constructs. These constructs are needed for the implementation of import/export across modules and across chunks. The issue is that the Closure compiler optimizer is not able to correctly reason over these constructs. Looking for While I understand the hesitancy to lose an optimization, I also believe that correctness has to come before optimization. I'd love to see the optimizer correctly handle this case, but in the absence of that a flag can make everyone happy. |
I am using webpack with closure compiler, I ran into an issue that some function calls from certain modules were removed by the compiler.
This is the minimal example for reproducing the issue, it's basically the webpack code for requiring a module
Calling window.test() should print "hello" in the console. However the ADVANCED compilation mode turns window['test'] into an empty function
Please help take a look, thanks!
The text was updated successfully, but these errors were encountered: