HoriSun / closure-compiler

Automatically exported from code.google.com/p/closure-compiler
0 stars 0 forks source link

dead code affects side-effect analysis #1181

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// ==/ClosureCompiler==

var globalMap = {}

/** @constructor */
function hello(name) {
  this.name = name
  if (false) globalMap[name] = this
}
new hello('New user');

gets compiled to:

new function(a){this.name=a}("New user");

it should get compiled away to nothing.

I think the problem is that side-effect analysis is done way too early in the 
pipeline. It might make sense to do it between the first and second 
optimization loops, but not really sure. I don't know if the if the side-effect 
analysis is safe to run multiple times.

Original issue reported on code.google.com by Nicholas.J.Santos on 18 Dec 2013 at 9:56

GoogleCodeExporter commented 9 years ago

Original comment by Nicholas.J.Santos on 18 Dec 2013 at 9:57

GoogleCodeExporter commented 9 years ago
We could also fix this particular code snippet by allowing FunctionInjector to 
inline simple 'new' calls, but i think solving the more general problem could 
open up possibilities elsewhere.

Original comment by Nicholas.J.Santos on 18 Dec 2013 at 11:35

GoogleCodeExporter commented 9 years ago
I've thought about this a number of time.  Previously, we didn't do it because 
we wanted smart name removal to take advantage of it but we run that later now 
too.  

Running just before the first smart name removal (after the first dead code 
run) might be sufficient.  doing local dead code removal before disambiguate 
properties might be helpful too.

Original comment by concavel...@gmail.com on 19 Dec 2013 at 7:43

GoogleCodeExporter commented 9 years ago
Issue tracking has been migrated to github. Please make any further comments on 
this issue through https://github.com/google/closure-compiler/issues

Original comment by blic...@google.com on 1 May 2014 at 6:31

GoogleCodeExporter commented 9 years ago

Original comment by blic...@google.com on 1 May 2014 at 6:34