Adds a flag for Array.prototype method nested optimized functions (#2404)

Summary:
Release notes: adds a `arrayNestedOptimizedFunctionsEnabled` flag to enable nested optimized functions derived from Array.prototype methods (like `map`) and Array.from

This PR puts the existing (unstable) work for Array prototype methods behind a flag. The flag is enabled by default in React and serializer tests.
Pull Request resolved: https://github.com/facebook/prepack/pull/2404

Differential Revision: D9272747

Pulled By: trueadm

fbshipit-source-id: d7e53656a12cd6cff680a9ef0e2580a93d56e34e
This commit is contained in:
Dominic Gannaway 2018-08-10 11:35:42 -07:00 committed by Facebook Github Bot
parent fbf3d0a639
commit abe84227f5
19 changed files with 32 additions and 1 deletions

View File

@ -74,6 +74,7 @@ let prepackOptions = {
reactOutput: "jsx",
reactVerbose: true,
reactOptimizeNestedFunctions: false,
arrayNestedOptimizedFunctionsEnabled: false,
inlineExpressions: true,
invariantLevel: 0,
abstractValueImpliesMax: 1000,

View File

@ -363,7 +363,11 @@ function runTest(name, code, options: PrepackOptions, args) {
internalDebug: true,
serialize: true,
uniqueSuffix: "",
arrayNestedOptimizedFunctionsEnabled: false,
}): any): PrepackOptions); // Since PrepackOptions is an exact type I have to cast
if (code.includes("// arrayNestedOptimizedFunctionsEnabled")) {
options.arrayNestedOptimizedFunctionsEnabled = true;
}
if (code.includes("// throws introspection error")) {
try {
let realmOptions = {

View File

@ -59,6 +59,7 @@ export type RealmOptions = {
reactOptimizeNestedFunctions?: boolean,
stripFlow?: boolean,
abstractValueImpliesMax?: number,
arrayNestedOptimizedFunctionsEnabled?: boolean,
};
export type SerializerOptions = {

View File

@ -61,6 +61,7 @@ export type PrepackOptions = {|
debuggerConfigArgs?: DebuggerConfigArguments,
debugReproArgs?: DebugReproArguments,
onParse?: BabelNodeFile => void,
arrayNestedOptimizedFunctionsEnabled?: boolean,
|};
export function getRealmOptions({
@ -87,6 +88,7 @@ export function getRealmOptions({
abstractValueImpliesMax,
debuggerConfigArgs,
debugReproArgs,
arrayNestedOptimizedFunctionsEnabled,
}: PrepackOptions): RealmOptions {
return {
compatibility,
@ -112,6 +114,7 @@ export function getRealmOptions({
abstractValueImpliesMax,
debuggerConfigArgs,
debugReproArgs,
arrayNestedOptimizedFunctionsEnabled,
};
}

View File

@ -337,6 +337,7 @@ export class Realm {
this.debugNames = opts.debugNames;
this._checkedObjectIds = new Map();
this.optimizedFunctions = new Map();
this.arrayNestedOptimizedFunctionsEnabled = opts.arrayNestedOptimizedFunctionsEnabled || false;
}
statistics: RealmStatistics;
@ -482,6 +483,7 @@ export class Realm {
_checkedObjectIds: Map<ObjectValue | AbstractObjectValue, number>;
optimizedFunctions: Map<FunctionValue | AbstractValue, ArgModel | void>;
arrayNestedOptimizedFunctionsEnabled: boolean;
// to force flow to type the annotations
isCompatibleWith(compatibility: Compatibility): boolean {

View File

@ -80,7 +80,7 @@ function createArrayWithWidenedNumericProperty(
let abstractArrayValue = new ArrayValue(realm, intrinsicName);
if (possibleNestedOptimizedFunctions !== undefined) {
if (!realm.react.enabled || realm.react.optimizeNestedFunctions) {
if (realm.arrayNestedOptimizedFunctionsEnabled && (!realm.react.enabled || realm.react.optimizeNestedFunctions)) {
evaluatePossibleNestedOptimizedFunctionsAndStoreEffects(
realm,
abstractArrayValue,

View File

@ -133,6 +133,7 @@ ${source}
reactEnabled: true,
reactOutput: useJSXOutput ? "jsx" : "create-element",
reactOptimizeNestedFunctions: true,
arrayNestedOptimizedFunctionsEnabled: true,
inlineExpressions: true,
invariantLevel: 0,
stripFlow: true,

View File

@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled
function fn(props, cond, cond2, cond3) {
var arr = Array.from(props.x);
var newObj;

View File

@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled
function fn(x, y) {
var edges = Array.from(x);
var items = edges

View File

@ -1,4 +1,5 @@
// does not contain:// this function should be inlined
// arrayNestedOptimizedFunctionsEnabled
(function() {
function add(a, b) {

View File

@ -1,4 +1,5 @@
// does not contain:// this function should be inlined
// arrayNestedOptimizedFunctionsEnabled
(function() {
var obj = {

View File

@ -1,4 +1,5 @@
// does contain:// this function should not be inlined
// arrayNestedOptimizedFunctionsEnabled
(function() {
var obj = {

View File

@ -1,4 +1,5 @@
// does contain:// this function should not be inlined
// arrayNestedOptimizedFunctionsEnabled
(function() {
function add(a, b) {

View File

@ -1,3 +1,4 @@
// arrayNestedOptimizedFunctionsEnabled
// skip lint
// The original issue here was that nested is defined inside of fn2 which is a non-optimized function
// called by fn (an optimized function). That caused Prepack to not detect that nested was nested

View File

@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled
function fn(x, y, obj, cond) {
var arr = Array.from(x);
var arr2 = Array.from(y);

View File

@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled
function fn(x, cond, abstractFunc) {
var arr = Array.from(x);

View File

@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled
function fn(x, obj, cond, cond4) {
var arr = Array.from(x);

View File

@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled
function fn(x, obj, cond, cond2, cond3, cond4) {
var arr = Array.from(x);
var a;

View File

@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled
function fn(props, cond) {
var arr = Array.from(props.x);
var newObj;