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

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/debug-fb-www.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ let prepackOptions = {
reactOutput: "jsx",
reactVerbose: true,
reactOptimizeNestedFunctions: false,
arrayNestedOptimizedFunctionsEnabled: false,
inlineExpressions: true,
invariantLevel: 0,
abstractValueImpliesMax: 1000,
Expand Down
4 changes: 4 additions & 0 deletions scripts/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export type RealmOptions = {
reactOptimizeNestedFunctions?: boolean,
stripFlow?: boolean,
abstractValueImpliesMax?: number,
arrayNestedOptimizedFunctionsEnabled?: boolean,
};

export type SerializerOptions = {
Expand Down
3 changes: 3 additions & 0 deletions src/prepack-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type PrepackOptions = {|
debuggerConfigArgs?: DebuggerConfigArguments,
debugReproArgs?: DebugReproArguments,
onParse?: BabelNodeFile => void,
arrayNestedOptimizedFunctionsEnabled?: boolean,
|};

export function getRealmOptions({
Expand All @@ -87,6 +88,7 @@ export function getRealmOptions({
abstractValueImpliesMax,
debuggerConfigArgs,
debugReproArgs,
arrayNestedOptimizedFunctionsEnabled,
}: PrepackOptions): RealmOptions {
return {
compatibility,
Expand All @@ -112,6 +114,7 @@ export function getRealmOptions({
abstractValueImpliesMax,
debuggerConfigArgs,
debugReproArgs,
arrayNestedOptimizedFunctionsEnabled,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/values/ArrayValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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,
Expand Down
1 change: 1 addition & 0 deletions test/react/setupReactTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ ${source}
reactEnabled: true,
reactOutput: useJSXOutput ? "jsx" : "create-element",
reactOptimizeNestedFunctions: true,
arrayNestedOptimizedFunctionsEnabled: true,
inlineExpressions: true,
invariantLevel: 0,
stripFlow: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled

function fn(props, cond, cond2, cond3) {
var arr = Array.from(props.x);
var newObj;
Expand Down
2 changes: 2 additions & 0 deletions test/serializer/optimized-functions/ArrayFrom3.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled

function fn(x, y) {
var edges = Array.from(x);
var items = edges
Expand Down
1 change: 1 addition & 0 deletions test/serializer/optimized-functions/ArrayFrom6.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// does not contain:// this function should be inlined
// arrayNestedOptimizedFunctionsEnabled

(function() {
function add(a, b) {
Expand Down
1 change: 1 addition & 0 deletions test/serializer/optimized-functions/ArrayFrom7.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// does not contain:// this function should be inlined
// arrayNestedOptimizedFunctionsEnabled

(function() {
var obj = {
Expand Down
1 change: 1 addition & 0 deletions test/serializer/optimized-functions/ArrayFrom8.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// does contain:// this function should not be inlined
// arrayNestedOptimizedFunctionsEnabled

(function() {
var obj = {
Expand Down
1 change: 1 addition & 0 deletions test/serializer/optimized-functions/ArrayFrom9.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// does contain:// this function should not be inlined
// arrayNestedOptimizedFunctionsEnabled

(function() {
function add(a, b) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/serializer/optimized-functions/Issue2358.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled

function fn(x, y, obj, cond) {
var arr = Array.from(x);
var arr2 = Array.from(y);
Expand Down
2 changes: 2 additions & 0 deletions test/serializer/optimized-functions/Issue2359-1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled

function fn(x, cond, abstractFunc) {
var arr = Array.from(x);

Expand Down
2 changes: 2 additions & 0 deletions test/serializer/optimized-functions/Issue2392-1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled

function fn(x, obj, cond, cond4) {
var arr = Array.from(x);

Expand Down
2 changes: 2 additions & 0 deletions test/serializer/optimized-functions/Issue2392-2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled

function fn(x, obj, cond, cond2, cond3, cond4) {
var arr = Array.from(x);
var a;
Expand Down
2 changes: 2 additions & 0 deletions test/serializer/optimized-functions/Issue2398.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// arrayNestedOptimizedFunctionsEnabled

function fn(props, cond) {
var arr = Array.from(props.x);
var newObj;
Expand Down