Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Regular and "array nested" optimized functions don't work together #2566

Open
NTillmann opened this issue Sep 22, 2018 · 1 comment
Open
Labels
bug Instant Render optimized functions Issues around optimizing not global code, but additional functions priority: high

Comments

@NTillmann
Copy link
Contributor

NTillmann commented Sep 22, 2018

Prepacking this, with --instantRender (to trigger realm.arrayNestedOptimizedFunctionsEnabled, which is not otherwise directly exposed via the CLI)...

function f(a) {
  return Array.from(a).map(function() {
    function g() { return 21 + 21; }
    __optimize(g);
    return g;
  });
}
__optimize(f);

...results in...

var f;
(function () {
  var _$2 = this;
  var _$3 = _$2.Array;
  var _$4 = _$3.from;
  var _1 = function (a) {
    var _5 = function () {
      var _8 = function () {
        return 21 + 21;
      };
      return _8;
    };
    var _$0 = _$4(a);
    var _$1 = _$0.map(_5);
    return _$1;
  };
  _$2.f = _1;
}).call(this);

Note that _8 did NOT get optimized!

Also note that this message was produced:

In input file /tmp/test.js(3:5) RecoverableError PP1008: Called __optimize on function in failed speculative context (https://github.com/facebook/prepack/wiki/PP1008)

Not helpful, rather confusing, but likely related?

@NTillmann NTillmann added bug priority: high Instant Render optimized functions Issues around optimizing not global code, but additional functions labels Sep 22, 2018
@NTillmann NTillmann changed the title Regular and "array nested" don't work together Regular and "array nested" optimized functions don't work together Sep 22, 2018
@cblappert
Copy link
Contributor

Right, so what's happening here is that when we optimize the function in array.map, we record that we should optimize g, but g doesn't exist when we try to optimize it at the end of global code execution unless we apply the effects from the array.map optimized function.

We need to either record that the array.map function is the parent of g and apply it's effects before optimizing g or add a way to optimize g inplace during the call to map #2336

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Instant Render optimized functions Issues around optimizing not global code, but additional functions priority: high
Projects
None yet
Development

No branches or pull requests

2 participants