facebookarchive / prepack

A JavaScript bundle optimizer.
http://prepack.io
Other
14.21k stars 424 forks source link

Support path-based refinement of top #2536

Closed sb98052 closed 4 years ago

sb98052 commented 6 years ago

In many cases, partial evaluation is only possible conditionally, and it is desirable to fork based on that condition, in order to produce optimized code for the consequent path.

Currently, this does not work if an abstract value is set to top:

let x = __abstract("number", "7");
let f = __abstract(":number", "foo");

if (x === 7) {
  global.result = x + 5;
} else {
  global.result = foo(x);
}

...produces:

(function () {
  var _$1_global = this;

  var _2_ = 7;

  if (7 === _2_) {
    _$1_global.result = 5 + _2_;
  } else {
    var _$0_derived = foo(_2_);

    _$1_global.result = _$0_derived;
  }
}).call(this);