Avoid generating two references to intrinsics that are in union.

Summary:
Serializing the arguments of an "abstractConcreteUnion" causes the abstract element to be assigned to a temp twice (once as a argument and once as the union). Avoid this by returning the serialized value of the abstract argument as the result of serializing the union.
Closes https://github.com/facebook/prepack/pull/1158

Differential Revision: D6337410

Pulled By: hermanventer

fbshipit-source-id: 6eaaa09de1622da076dbe58d5f2a490cb6f3d45b
This commit is contained in:
Herman Venter 2017-11-15 14:40:39 -08:00 committed by Facebook Github Bot
parent c3873061d4
commit 7ee4d95f1b
3 changed files with 7 additions and 1 deletions

View File

@ -1266,6 +1266,11 @@ export class ResidualHeapSerializer {
_serializeAbstractValueHelper(val: AbstractValue): BabelNodeExpression {
let serializedArgs = val.args.map((abstractArg, i) => this.serializeValue(abstractArg));
if (val.kind === "abstractConcreteUnion") {
let abstractIndex = val.args.findIndex(v => v instanceof AbstractValue);
invariant(abstractIndex >= 0 && abstractIndex < val.args.length);
return serializedArgs[abstractIndex];
}
let serializedValue = val.buildNode(serializedArgs);
if (serializedValue.type === "Identifier") {
let id = ((serializedValue: any): BabelNodeIdentifier);

View File

@ -587,7 +587,7 @@ export default class AbstractValue extends Value {
values = ValuesDomain.topVal;
}
let types = TypesDomain.topVal;
let [hash, operands] = hashCall("union", ...elements);
let [hash, operands] = hashCall("abstractConcreteUnion", ...elements);
let result = new AbstractValue(realm, types, values, hash, operands, abstractValue._buildNode, {
kind: "abstractConcreteUnion",
});

View File

@ -1,3 +1,4 @@
// Copies of f;:1
function f() { return 123; }
var g = global.__abstractOrNullOrUndefined ? __abstractOrNullOrUndefined("function", "f") : f;
z = g && g();