mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-10-26 15:20:18 +03:00
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:
parent
fbf3d0a639
commit
abe84227f5
@ -74,6 +74,7 @@ let prepackOptions = {
|
||||
reactOutput: "jsx",
|
||||
reactVerbose: true,
|
||||
reactOptimizeNestedFunctions: false,
|
||||
arrayNestedOptimizedFunctionsEnabled: false,
|
||||
inlineExpressions: true,
|
||||
invariantLevel: 0,
|
||||
abstractValueImpliesMax: 1000,
|
||||
|
@ -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 = {
|
||||
|
@ -59,6 +59,7 @@ export type RealmOptions = {
|
||||
reactOptimizeNestedFunctions?: boolean,
|
||||
stripFlow?: boolean,
|
||||
abstractValueImpliesMax?: number,
|
||||
arrayNestedOptimizedFunctionsEnabled?: boolean,
|
||||
};
|
||||
|
||||
export type SerializerOptions = {
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -133,6 +133,7 @@ ${source}
|
||||
reactEnabled: true,
|
||||
reactOutput: useJSXOutput ? "jsx" : "create-element",
|
||||
reactOptimizeNestedFunctions: true,
|
||||
arrayNestedOptimizedFunctionsEnabled: true,
|
||||
inlineExpressions: true,
|
||||
invariantLevel: 0,
|
||||
stripFlow: true,
|
||||
|
@ -1,3 +1,5 @@
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
function fn(props, cond, cond2, cond3) {
|
||||
var arr = Array.from(props.x);
|
||||
var newObj;
|
||||
|
@ -1,3 +1,5 @@
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
function fn(x, y) {
|
||||
var edges = Array.from(x);
|
||||
var items = edges
|
||||
|
@ -1,4 +1,5 @@
|
||||
// does not contain:// this function should be inlined
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
(function() {
|
||||
function add(a, b) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
// does not contain:// this function should be inlined
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
(function() {
|
||||
var obj = {
|
||||
|
@ -1,4 +1,5 @@
|
||||
// does contain:// this function should not be inlined
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
(function() {
|
||||
var obj = {
|
||||
|
@ -1,4 +1,5 @@
|
||||
// does contain:// this function should not be inlined
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
(function() {
|
||||
function add(a, b) {
|
||||
|
@ -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
|
||||
|
@ -1,3 +1,5 @@
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
function fn(x, y, obj, cond) {
|
||||
var arr = Array.from(x);
|
||||
var arr2 = Array.from(y);
|
||||
|
@ -1,3 +1,5 @@
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
function fn(x, cond, abstractFunc) {
|
||||
var arr = Array.from(x);
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
function fn(x, obj, cond, cond4) {
|
||||
var arr = Array.from(x);
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
function fn(x, obj, cond, cond2, cond3, cond4) {
|
||||
var arr = Array.from(x);
|
||||
var a;
|
||||
|
@ -1,3 +1,5 @@
|
||||
// arrayNestedOptimizedFunctionsEnabled
|
||||
|
||||
function fn(props, cond) {
|
||||
var arr = Array.from(props.x);
|
||||
var newObj;
|
||||
|
Loading…
Reference in New Issue
Block a user