mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-11-09 21:20:06 +03:00
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:
parent
c3873061d4
commit
7ee4d95f1b
@ -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);
|
||||
|
@ -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",
|
||||
});
|
||||
|
@ -1,3 +1,4 @@
|
||||
// Copies of f;:1
|
||||
function f() { return 123; }
|
||||
var g = global.__abstractOrNullOrUndefined ? __abstractOrNullOrUndefined("function", "f") : f;
|
||||
z = g && g();
|
||||
|
Loading…
Reference in New Issue
Block a user