Make sure all optimized functions are included in IR dumping (#2568)

Summary:
Release notes: None

Dumping happened before `processCollectedNestedOptimizedFunctions`,
which caused them to not be included. This is being fixed, plus some
minor refactoring to hide implementation details.
Pull Request resolved: https://github.com/facebook/prepack/pull/2568

Differential Revision: D10023363

Pulled By: NTillmann

fbshipit-source-id: 6abe2b5358f23705b501fc818536fb30d42a3b17
This commit is contained in:
Nikolai Tillmann 2018-09-24 19:13:04 -07:00 committed by Facebook Github Bot
parent 0e52d02190
commit 7f3b5d4caf
2 changed files with 17 additions and 17 deletions

View File

@ -50,14 +50,14 @@ export class Functions {
constructor(realm: Realm, moduleTracer: ModuleTracer) { constructor(realm: Realm, moduleTracer: ModuleTracer) {
this.realm = realm; this.realm = realm;
this.moduleTracer = moduleTracer; this.moduleTracer = moduleTracer;
this.writeEffects = new Map(); this._writeEffects = new Map();
this._noopFunction = undefined; this._noopFunction = undefined;
this._optimizedFunctionId = 0; this._optimizedFunctionId = 0;
} }
realm: Realm; realm: Realm;
moduleTracer: ModuleTracer; moduleTracer: ModuleTracer;
writeEffects: WriteEffects; _writeEffects: WriteEffects;
_noopFunction: void | ECMAScriptSourceFunctionValue; _noopFunction: void | ECMAScriptSourceFunctionValue;
_optimizedFunctionId: number; _optimizedFunctionId: number;
@ -168,7 +168,7 @@ export class Functions {
this.realm, this.realm,
componentRoot, componentRoot,
config, config,
this.writeEffects, this._writeEffects,
environmentRecordIdAfterGlobalCode, environmentRecordIdAfterGlobalCode,
logger, logger,
statistics, statistics,
@ -178,7 +178,7 @@ export class Functions {
} }
getDeclaringOptimizedFunction(functionValue: ECMAScriptSourceFunctionValue): void | FunctionValue { getDeclaringOptimizedFunction(functionValue: ECMAScriptSourceFunctionValue): void | FunctionValue {
for (let [optimizedFunctionValue, additionalEffects] of this.writeEffects) { for (let [optimizedFunctionValue, additionalEffects] of this._writeEffects) {
// CreatedObjects is all objects created by this optimized function but not // CreatedObjects is all objects created by this optimized function but not
// nested optimized functions. // nested optimized functions.
let createdObjects = additionalEffects.effects.createdObjects; let createdObjects = additionalEffects.effects.createdObjects;
@ -197,7 +197,7 @@ export class Functions {
this.getDeclaringOptimizedFunction(functionValue) this.getDeclaringOptimizedFunction(functionValue)
); );
invariant(additionalFunctionEffects !== null); invariant(additionalFunctionEffects !== null);
this.writeEffects.set(functionValue, additionalFunctionEffects); this._writeEffects.set(functionValue, additionalFunctionEffects);
} }
} }
@ -251,7 +251,7 @@ export class Functions {
); );
invariant(additionalFunctionEffects); invariant(additionalFunctionEffects);
effects = additionalFunctionEffects.effects; effects = additionalFunctionEffects.effects;
if (this.writeEffects.has(functionValue)) { if (this._writeEffects.has(functionValue)) {
let error = new CompilerDiagnostic( let error = new CompilerDiagnostic(
"Trying to optimize a function with two parent optimized functions, which is not currently allowed.", "Trying to optimize a function with two parent optimized functions, which is not currently allowed.",
functionValue.expressionLocation, functionValue.expressionLocation,
@ -261,7 +261,7 @@ export class Functions {
// we can recover by assuming one set of effects to show further diagnostics // we can recover by assuming one set of effects to show further diagnostics
if (realm.handleError(error) !== "Recover") throw new FatalError(); if (realm.handleError(error) !== "Recover") throw new FatalError();
} else { } else {
this.writeEffects.set(functionValue, additionalFunctionEffects); this._writeEffects.set(functionValue, additionalFunctionEffects);
} }
// Conceptually this will ensure that the nested additional function is defined // Conceptually this will ensure that the nested additional function is defined
@ -288,7 +288,7 @@ export class Functions {
let conflicts: Map<BabelNodeSourceLocation, CompilerDiagnostic> = new Map(); let conflicts: Map<BabelNodeSourceLocation, CompilerDiagnostic> = new Map();
let isParentOf = (possibleParent, fun) => { let isParentOf = (possibleParent, fun) => {
if (fun === undefined) return false; if (fun === undefined) return false;
let effects = this.writeEffects.get(fun); let effects = this._writeEffects.get(fun);
invariant(effects !== undefined); invariant(effects !== undefined);
if (effects.parentAdditionalFunction !== undefined) { if (effects.parentAdditionalFunction !== undefined) {
if (effects.parentAdditionalFunction === possibleParent) return true; if (effects.parentAdditionalFunction === possibleParent) return true;
@ -301,7 +301,7 @@ export class Functions {
let fun1Location = fun1.expressionLocation; let fun1Location = fun1.expressionLocation;
let fun1Name = fun1.getDebugName() || optionalStringOfLocation(fun1Location); let fun1Name = fun1.getDebugName() || optionalStringOfLocation(fun1Location);
// Also do argument validation here // Also do argument validation here
let additionalFunctionEffects = this.writeEffects.get(fun1); let additionalFunctionEffects = this._writeEffects.get(fun1);
invariant(additionalFunctionEffects !== undefined); invariant(additionalFunctionEffects !== undefined);
let e1 = additionalFunctionEffects.effects; let e1 = additionalFunctionEffects.effects;
invariant(e1 !== undefined); invariant(e1 !== undefined);
@ -333,11 +333,11 @@ export class Functions {
}; };
// Recursively apply all parent effects // Recursively apply all parent effects
let withPossibleParentEffectsApplied = (toExecute, optimizedFunction) => { let withPossibleParentEffectsApplied = (toExecute, optimizedFunction) => {
let funEffects = this.writeEffects.get(optimizedFunction); let funEffects = this._writeEffects.get(optimizedFunction);
invariant(funEffects !== undefined); invariant(funEffects !== undefined);
let parentAdditionalFunction = funEffects.parentAdditionalFunction; let parentAdditionalFunction = funEffects.parentAdditionalFunction;
if (parentAdditionalFunction !== undefined) { if (parentAdditionalFunction !== undefined) {
let parentEffects = this.writeEffects.get(parentAdditionalFunction); let parentEffects = this._writeEffects.get(parentAdditionalFunction);
invariant(parentEffects !== undefined); invariant(parentEffects !== undefined);
let newToExecute = () => this.realm.withEffectsAppliedInGlobalEnv(toExecute, parentEffects.effects); let newToExecute = () => this.realm.withEffectsAppliedInGlobalEnv(toExecute, parentEffects.effects);
withPossibleParentEffectsApplied(newToExecute, parentAdditionalFunction); withPossibleParentEffectsApplied(newToExecute, parentAdditionalFunction);
@ -355,7 +355,7 @@ export class Functions {
} }
getAdditionalFunctionValuesToEffects(): Map<FunctionValue, AdditionalFunctionEffects> { getAdditionalFunctionValuesToEffects(): Map<FunctionValue, AdditionalFunctionEffects> {
return this.writeEffects; return this._writeEffects;
} }
reportWriteConflicts( reportWriteConflicts(

View File

@ -161,19 +161,19 @@ export class Serializer {
}); });
} }
statistics.processCollectedNestedOptimizedFunctions.measure(() =>
this.functions.processCollectedNestedOptimizedFunctions(environmentRecordIdAfterGlobalCode)
);
statistics.dumpIR.measure(() => { statistics.dumpIR.measure(() => {
if (onExecute !== undefined) { if (onExecute !== undefined) {
let optimizedFunctions = new Map(); let optimizedFunctions = new Map();
for (let [functionValue, additionalFunctionEffects] of this.functions.writeEffects) for (let [functionValue, additionalFunctionEffects] of this.functions.getAdditionalFunctionValuesToEffects())
optimizedFunctions.set(functionValue, additionalFunctionEffects.generator); optimizedFunctions.set(functionValue, additionalFunctionEffects.generator);
onExecute(this.realm, optimizedFunctions); onExecute(this.realm, optimizedFunctions);
} }
}); });
statistics.processCollectedNestedOptimizedFunctions.measure(() =>
this.functions.processCollectedNestedOptimizedFunctions(environmentRecordIdAfterGlobalCode)
);
if (this.options.initializeMoreModules) { if (this.options.initializeMoreModules) {
statistics.initializeMoreModules.measure(() => this.modules.initializeMoreModules()); statistics.initializeMoreModules.measure(() => this.modules.initializeMoreModules());
if (this.logger.hasErrors()) return undefined; if (this.logger.hasErrors()) return undefined;