Skip to content

Commit f450193

Browse files
committed
Update on "[compiler] Infer phi types, extend mutable ranges to account for Store effects"
Redo of an earlier (pre-OSS) PR to infer types of phi nodes. There are a few pieces to this: 1. Update InferTypes to infer the type of `phi.id.type`, not the unused `phi.type`. 2. Update the algorithm to verify that all the phi types are actually equal, not just have the same kind. 3. Handle circular types by removing the cycle. However, that reveals another issue: InferMutableRanges currently infers the results of `Store` effects _after_ its fixpoint loop. That was fine when a Store could never occur on a phi (since they wouldn't have a type to get a function signature from). Now though, we can have Store effects occur on phis, and we need to ensure that this correctly updates the mutable range of the phi operands - recursively. See new test that fails without the fixpoint loop. [ghstack-poisoned]
1 parent 4f80cbb commit f450193

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutableRanges.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,28 @@ export function inferMutableRanges(ir: HIRFunction): void {
5050
// Re-infer mutable ranges for all values
5151
inferMutableLifetimes(ir, true);
5252

53-
// Re-infer mutable ranges for aliases, but *not* for stores
53+
/**
54+
* The second inferMutableLifetimes() call updates mutable ranges
55+
* of values to account for Store effects. Now we need to update
56+
* all aliases of such values to extend their ranges as well. Note
57+
* that the store only mutates the the directly aliased value and
58+
* not any of its inner captured references. For example:
59+
*
60+
* ```
61+
* let y;
62+
* if (cond) {
63+
* y = [];
64+
* } else {
65+
* y = [{}];
66+
* }
67+
* y.push(z);
68+
* ```
69+
*
70+
* The Store effect from the `y.push` modifies the values that `y`
71+
* directly aliases - the two arrays from the if/else branches -
72+
* but does not modify values that `y` "contains" such as the
73+
* object literal or `z`.
74+
*/
5475
prevAliases = aliases.canonicalize();
5576
while (true) {
5677
inferMutableRangesForAlias(ir, aliases);

0 commit comments

Comments
 (0)