Skip to content

Commit f13cfb0

Browse files
committed
[compiler] comments and todos
ghstack-source-id: 851743f Pull Request resolved: facebook/react#33376
1 parent fa04da9 commit f13cfb0

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {inferMutableLifetimes} from './InferMutableLifetimes';
1717
import {inferMutableRangesForAlias} from './InferMutableRangesForAlias';
1818
import {inferMutableRangesForComutation} from './InferMutableRangesForComutation';
1919
import {inferTryCatchAliases} from './InferTryCatchAliases';
20-
import {printIdentifier, printMutableRange} from '../HIR/PrintHIR';
20+
import {printIdentifier} from '../HIR/PrintHIR';
2121

2222
export function inferMutableRanges(ir: HIRFunction): DisjointSet<Identifier> {
2323
// Infer mutable ranges for non fields
@@ -105,7 +105,8 @@ export function debugAliases(aliases: DisjointSet<Identifier>): void {
105105
.buildSets()
106106
.map(set =>
107107
[...set].map(
108-
ident => printIdentifier(ident) + printMutableRange(ident),
108+
ident =>
109+
`${printIdentifier(ident)}:${ident.mutableRange.start}:${ident.mutableRange.end}`,
109110
),
110111
),
111112
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ function computeSignatureForInstruction(
986986
value.args,
987987
)
988988
: null;
989-
if (signatureEffects != null && signature?.aliasing != null) {
989+
if (signatureEffects != null) {
990990
effects.push(...signatureEffects);
991991
} else if (signature != null) {
992992
effects.push(

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import DisjointSet from '../Utils/DisjointSet';
2121
import {assertExhaustive} from '../Utils/utils';
2222
import {inferMutableRangesForAlias} from './InferMutableRangesForAlias';
2323

24+
/**
25+
* Infers mutable ranges for all values.
26+
*/
2427
export function inferMutationAliasingRanges(fn: HIRFunction): void {
2528
/**
2629
* Part 1
@@ -64,13 +67,34 @@ export function inferMutationAliasingRanges(fn: HIRFunction): void {
6467
}
6568
}
6669
}
70+
/**
71+
* TODO: this will incorrectly mark values as mutated in the following case:
72+
* 1. Create value x
73+
* 2. Create value y
74+
* 3. Transitively mutate y
75+
* 4. Capture x -> y
76+
*
77+
* We will put these all into one alias set in captures, and then InferMutableRangesForAlias
78+
* will look at all identifiers in the set that start before the mutation. Thus it will see
79+
* that x is created before the mutation, and consider it mutated. But the capture doesn't
80+
* occur until after the mutation!
81+
*
82+
* The fix is to use a graph to precisely describe what is captured where at each instruction,
83+
* so that on a transitive mutation we can iterate all the captured values and mark them.
84+
*
85+
* This then needs a fixpoint: although we would track captures for phi operands, the operands'
86+
* own capture values won't be populated until we do a fixpoint.
87+
*/
6788
inferMutableRangesForAlias(fn, captures);
6889

6990
/**
7091
* Part 2
7192
* Infer ranges for local (non-transitive) mutations. We build a disjoint set
7293
* that only tracks direct value aliasing, and look only at local mutations
7394
* to extend ranges
95+
*
96+
* TODO: similar design to the above todo for captures, use a directed graph instead of disjoint union,
97+
* with fixpoint.
7498
*/
7599
const aliases = new DisjointSet<Identifier>();
76100
for (const block of fn.body.blocks.values()) {

0 commit comments

Comments
 (0)