mirror of
https://github.com/facebookarchive/prepack.git
synced 2024-08-17 10:30:32 +03:00
Simplify forked completion constructors (#2315)
Summary: Release note: Simplified forked completion constructors Since effects and completions are now 1-1, we can stop passing (completion, effects) argument pairs. Pull Request resolved: https://github.com/facebook/prepack/pull/2315 Differential Revision: D8985970 Pulled By: hermanventer fbshipit-source-id: 12ab3848951be4fee973bde71eaca135f56b1a3d
This commit is contained in:
parent
62b11dcb6e
commit
a1bd30ddb9
@ -133,19 +133,8 @@ export class ReturnCompletion extends AbruptCompletion {
|
||||
}
|
||||
|
||||
export class ForkedAbruptCompletion extends AbruptCompletion {
|
||||
constructor(
|
||||
realm: Realm,
|
||||
joinCondition: AbstractValue,
|
||||
consequent: AbruptCompletion,
|
||||
consequentEffects: Effects,
|
||||
alternate: AbruptCompletion,
|
||||
alternateEffects: Effects
|
||||
) {
|
||||
constructor(realm: Realm, joinCondition: AbstractValue, consequent: AbruptCompletion, alternate: AbruptCompletion) {
|
||||
super(realm.intrinsics.empty, undefined, consequent.location);
|
||||
invariant(consequentEffects.result === consequent);
|
||||
invariant(consequent.effects === consequentEffects);
|
||||
invariant(alternateEffects.result === alternate);
|
||||
invariant(alternate.effects === alternateEffects);
|
||||
this.joinCondition = joinCondition;
|
||||
this.consequent = consequent;
|
||||
this.alternate = alternate;
|
||||
@ -156,16 +145,7 @@ export class ForkedAbruptCompletion extends AbruptCompletion {
|
||||
alternate: AbruptCompletion;
|
||||
|
||||
shallowCloneWithoutEffects(): ForkedAbruptCompletion {
|
||||
let consequentEffects = this.consequentEffects;
|
||||
let alternateEffects = this.alternateEffects;
|
||||
return new ForkedAbruptCompletion(
|
||||
this.value.$Realm,
|
||||
this.joinCondition,
|
||||
this.consequent,
|
||||
consequentEffects,
|
||||
this.alternate,
|
||||
alternateEffects
|
||||
);
|
||||
return new ForkedAbruptCompletion(this.value.$Realm, this.joinCondition, this.consequent, this.alternate);
|
||||
}
|
||||
|
||||
// For convenience, this.consequent.effects should always be defined, but accessing it directly requires
|
||||
@ -233,9 +213,7 @@ export class ForkedAbruptCompletion extends AbruptCompletion {
|
||||
this.value.$Realm.intrinsics.empty,
|
||||
this.joinCondition,
|
||||
this.consequent,
|
||||
this.consequentEffects,
|
||||
this.alternate,
|
||||
this.alternateEffects,
|
||||
[]
|
||||
);
|
||||
}
|
||||
@ -249,16 +227,10 @@ export class PossiblyNormalCompletion extends NormalCompletion {
|
||||
value: Value,
|
||||
joinCondition: AbstractValue,
|
||||
consequent: Completion,
|
||||
consequentEffects: Effects,
|
||||
alternate: Completion,
|
||||
alternateEffects: Effects,
|
||||
savedPathConditions: Array<AbstractValue>,
|
||||
savedEffects: void | Effects = undefined
|
||||
) {
|
||||
invariant(consequent === consequentEffects.result);
|
||||
invariant(consequent.effects === consequentEffects);
|
||||
invariant(alternate === alternateEffects.result);
|
||||
invariant(alternate.effects === alternateEffects);
|
||||
invariant(consequent instanceof NormalCompletion || alternate instanceof NormalCompletion);
|
||||
super(value, undefined, consequent.location);
|
||||
this.joinCondition = joinCondition;
|
||||
@ -284,9 +256,7 @@ export class PossiblyNormalCompletion extends NormalCompletion {
|
||||
this.value,
|
||||
this.joinCondition,
|
||||
this.consequent,
|
||||
consequentEffects,
|
||||
this.alternate,
|
||||
alternateEffects,
|
||||
this.savedPathConditions,
|
||||
this.savedEffects
|
||||
);
|
||||
|
@ -164,23 +164,19 @@ export class JoinImplementation {
|
||||
c.value,
|
||||
pnc.joinCondition,
|
||||
pnc.consequent,
|
||||
pnc.consequentEffects,
|
||||
newAlternateEffects.result,
|
||||
newAlternateEffects,
|
||||
savedPathConditions,
|
||||
pnc.savedEffects
|
||||
);
|
||||
}
|
||||
invariant(pnc.alternate instanceof PossiblyNormalCompletion);
|
||||
na = this.composePossiblyNormalCompletions(realm, pnc.alternate, c, priorEffects);
|
||||
let newAlternateEffects = ae.shallowCloneWithResult(na);
|
||||
ae.shallowCloneWithResult(na);
|
||||
return new PossiblyNormalCompletion(
|
||||
c.value,
|
||||
pnc.joinCondition,
|
||||
pnc.consequent,
|
||||
pnc.consequentEffects,
|
||||
na,
|
||||
newAlternateEffects,
|
||||
savedPathConditions,
|
||||
pnc.savedEffects
|
||||
);
|
||||
@ -195,23 +191,19 @@ export class JoinImplementation {
|
||||
c.value,
|
||||
pnc.joinCondition,
|
||||
newConsequentEffects.result,
|
||||
newConsequentEffects,
|
||||
pnc.alternate,
|
||||
pnc.alternateEffects,
|
||||
savedPathConditions,
|
||||
pnc.savedEffects
|
||||
);
|
||||
}
|
||||
invariant(pnc.consequent instanceof PossiblyNormalCompletion);
|
||||
nc = this.composePossiblyNormalCompletions(realm, pnc.consequent, c);
|
||||
let newConsequentEffects = ce.shallowCloneWithResult(nc);
|
||||
ce.shallowCloneWithResult(nc);
|
||||
return new PossiblyNormalCompletion(
|
||||
c.value,
|
||||
pnc.joinCondition,
|
||||
nc,
|
||||
newConsequentEffects,
|
||||
pnc.alternate,
|
||||
pnc.alternateEffects,
|
||||
savedPathConditions,
|
||||
pnc.savedEffects
|
||||
);
|
||||
@ -292,10 +284,10 @@ export class JoinImplementation {
|
||||
// effects collected after pnc was constructed
|
||||
e: Effects
|
||||
): ForkedAbruptCompletion {
|
||||
let recurse = (xpnc, xe, nac, ne): [ForkedAbruptCompletion, Effects] => {
|
||||
let recurse = (xpnc, xe, nac, ne): ForkedAbruptCompletion => {
|
||||
let nx = this.replacePossiblyNormalCompletionWithForkedAbruptCompletion(realm, xpnc, nac, ne);
|
||||
let nxe = xe.shallowCloneWithResult(nx);
|
||||
return [nx, nxe];
|
||||
xe.shallowCloneWithResult(nx);
|
||||
return nx;
|
||||
};
|
||||
|
||||
let cloneEffects = () => {
|
||||
@ -319,12 +311,11 @@ export class JoinImplementation {
|
||||
// todo: simplify with implied path condition
|
||||
e = realm.composeEffects(pnc.alternateEffects, e);
|
||||
invariant(e.result instanceof AbruptCompletion);
|
||||
ac = e.result;
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, pncc, pnc.consequentEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, pncc, e.result);
|
||||
}
|
||||
invariant(pnca instanceof PossiblyNormalCompletion);
|
||||
let [na, nae] = recurse(pnca, pnc.alternateEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, pncc, pnc.consequentEffects, na, nae);
|
||||
let na = recurse(pnca, pnc.alternateEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, pncc, na);
|
||||
}
|
||||
|
||||
// * case (SimpleNormalCompletion, AbruptCompletion)
|
||||
@ -334,12 +325,11 @@ export class JoinImplementation {
|
||||
// todo: simplify with implied path condition
|
||||
e = realm.composeEffects(pnc.consequentEffects, e);
|
||||
invariant(e.result instanceof AbruptCompletion);
|
||||
ac = e.result;
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, ac, e, pnca, pnc.alternateEffects);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, e.result, pnca);
|
||||
}
|
||||
invariant(pncc instanceof PossiblyNormalCompletion);
|
||||
let [nc, nce] = recurse(pncc, pnc.consequentEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, nc, nce, pnca, pnc.alternateEffects);
|
||||
let nc = recurse(pncc, pnc.consequentEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, nc, pnca);
|
||||
}
|
||||
|
||||
// * case (SimpleNormalCompletion, SimpleNormalCompletion)
|
||||
@ -356,9 +346,9 @@ export class JoinImplementation {
|
||||
na = nae.result;
|
||||
} else {
|
||||
invariant(pnca instanceof PossiblyNormalCompletion);
|
||||
[na, nae] = recurse(pnca, pnc.alternateEffects, ac, e);
|
||||
na = recurse(pnca, pnc.alternateEffects, ac, e);
|
||||
}
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, nc, nce, na, nae);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, nc, na);
|
||||
}
|
||||
|
||||
// * case (PossibleNormalCompletion, SimpleNormalCompletion)
|
||||
@ -368,17 +358,17 @@ export class JoinImplementation {
|
||||
let na = nae.result;
|
||||
invariant(pncc instanceof PossiblyNormalCompletion);
|
||||
[ac, e] = cloneEffects();
|
||||
let [nc, nce] = recurse(pncc, pnc.consequentEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, nc, nce, na, nae);
|
||||
let nc = recurse(pncc, pnc.consequentEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, nc, na);
|
||||
}
|
||||
|
||||
// * case (PossibleNormalCompletion, PossibleNormalCompletion)
|
||||
invariant(pncc instanceof PossiblyNormalCompletion);
|
||||
invariant(pnca instanceof PossiblyNormalCompletion);
|
||||
let [nc, nce] = recurse(pncc, pnc.consequentEffects, ac, e);
|
||||
let nc = recurse(pncc, pnc.consequentEffects, ac, e);
|
||||
[ac, e] = cloneEffects();
|
||||
let [na, nae] = recurse(pnca, pnc.alternateEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, nc, nce, na, nae);
|
||||
let na = recurse(pnca, pnc.alternateEffects, ac, e);
|
||||
return new ForkedAbruptCompletion(realm, pnc.joinCondition, nc, na);
|
||||
|
||||
// Impossible cases:
|
||||
// * case (AbruptCompletion, AbruptCompletion)
|
||||
@ -400,7 +390,7 @@ export class JoinImplementation {
|
||||
let rv = this.joinValues(realm, c.value, a.value, getAbstractValue);
|
||||
invariant(rv instanceof Value);
|
||||
a.value = rv;
|
||||
return new PossiblyNormalCompletion(rv, joinCondition, c, ce, a, ae, []);
|
||||
return new PossiblyNormalCompletion(rv, joinCondition, c, a, []);
|
||||
}
|
||||
|
||||
// Join all effects that result in completions of type CompletionType.
|
||||
@ -619,7 +609,7 @@ export class JoinImplementation {
|
||||
return new SimpleNormalCompletion(val);
|
||||
}
|
||||
if (result1 instanceof AbruptCompletion && result2 instanceof AbruptCompletion) {
|
||||
return new ForkedAbruptCompletion(realm, joinCondition, result1, e1, result2, e2);
|
||||
return new ForkedAbruptCompletion(realm, joinCondition, result1, result2);
|
||||
}
|
||||
if (result1 instanceof NormalCompletion && result2 instanceof NormalCompletion) {
|
||||
return this.joinNormalCompletions(realm, joinCondition, result1, e1, result2, e2);
|
||||
@ -638,9 +628,7 @@ export class JoinImplementation {
|
||||
completion.value,
|
||||
joinCondition,
|
||||
result1,
|
||||
e1,
|
||||
result2,
|
||||
e2,
|
||||
savedPathConditions,
|
||||
savedEffects
|
||||
);
|
||||
@ -659,9 +647,7 @@ export class JoinImplementation {
|
||||
completion.value,
|
||||
joinCondition,
|
||||
result1,
|
||||
e1,
|
||||
result2,
|
||||
e2,
|
||||
savedPathConditions,
|
||||
savedEffects
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user