Skip to content

Commit 7b244da

Browse files
committed
[compiler] Foundation of new mutability and aliasing (alternate take)
Alternate take at a new mutability and alising model, aiming to replace `InferReferenceEffects` and `InferMutableRanges`. My initial passes at this were more complicated than necessary, and I've iterated to refine and distill this down to the core concepts. There are two effects that track information flow: `capture` and `alias`: * Given distinct values A and B. After capture A -> B, mutate(B) does *not* modify A. This more precisely captures the semantic of the previous `Store` effect. As an example, `array.push(item)` has the effect `capture item -> array` and `mutate(array)`. The array is modified, not the item. * Given distinct values A and B. After alias A -> B, mutate(B) *does* modify A. This is because B now refers to the same value as A. * Given distinct values A and B, after *either* capture A -> B *or* alias A -> B, transitiveMutate(B) counts as a mutation of A. Conceptually "capture A -> B" means that a reference to A was "captured" (or stored) within A, but there is not a directly aliasing. Whereas "alias A -> B" means literal value aliasing. The idea is that our previous sequential fixpoint loops in InferMutableRanges can instead work by first looking at transitive mutations, then look at non-transitive mutations. And aliasing groups can be built purely based on the `alias` effect. Lots more to do here but the structure is coming together. ghstack-source-id: c4f311d Pull Request resolved: #33346
1 parent 807350b commit 7b244da

File tree

4 files changed

+1225
-17
lines changed

4 files changed

+1225
-17
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import {CompilerError} from '../CompilerError';
9+
import {AliasingSignature} from '../Inference/InferMutationAliasingEffects';
910
import {Effect, ValueKind, ValueReason} from './HIR';
1011
import {
1112
BuiltInType,
@@ -179,6 +180,8 @@ export type FunctionSignature = {
179180
impure?: boolean;
180181

181182
canonicalName?: string;
183+
184+
aliasing?: AliasingSignature | null;
182185
};
183186

184187
/*
@@ -332,6 +335,7 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
332335
returnValueKind: ValueKind.Mutable,
333336
noAlias: true,
334337
mutableOnlyIfOperandsAreMutable: true,
338+
aliasing: null,
335339
}),
336340
],
337341
[

0 commit comments

Comments
 (0)