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

Commit

Permalink
Nested optimized function with residual functions (#2397)
Browse files Browse the repository at this point in the history
Summary:
Release notes: none

This fixes a bug with nested optimized functions referencing nested residual functions and makes our internal bundle compile.

The issue was that we weren't checking if the function we get from `tryGetOptimizedFunctionRoot` was defined inside another optimized function, like we do already 5-6 lines up in the other if statement. This is an important thing, as the next line will result in `undefined` being returned. When `undefined` is returned, we use the `MainGenerator` rather than the `OptimizedFunction` generator, which means all declared values look at the wrong body.
Pull Request resolved: #2397

Differential Revision: D9223735

Pulled By: trueadm

fbshipit-source-id: 8e1cb1cc1b201b1ae1a804bc61a4bdc8790a3eea
  • Loading branch information
trueadm authored and facebook-github-bot committed Aug 8, 2018
1 parent e042645 commit d6253b2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/serializer/ResidualHeapSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ export class ResidualHeapSerializer {
} else {
let f = this.tryGetOptimizedFunctionRoot(functionValue);
if (f === undefined) return undefined;
if (this.isDefinedInsideFunction(f, functionValues)) {
continue;
}
if (additionalFunction !== undefined && additionalFunction !== f) return undefined;
additionalFunction = f;
}
Expand Down
31 changes: 31 additions & 0 deletions test/serializer/additional-functions/NestedOptimizedFunction17.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function fn(props, cond, cond2, cond3) {
var arr = Array.from(props.x);
var newObj;
var value;

if (cond) {
var _ref8;
value =
(_ref8 = props.feedback) != null
? (_ref8 = _ref8.display_comments) != null
? _ref8.ordering_mode
: _ref8
: _ref8;

var res = arr.map(function(item) {
var fn2 = function() {
return value;
};

return [item[value], fn2];
});
}

return res;
}

global.__optimize && __optimize(fn);

global.inspect = function() {
return true;
};

0 comments on commit d6253b2

Please sign in to comment.