Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd1889a
[compiler] Add Instruction.effects property
josephsavona May 23, 2025
49af4db
Update on "[compiler] Add Instruction.effects property"
josephsavona May 27, 2025
dd7ecd2
Update on "[compiler] Add Instruction.effects property"
josephsavona May 27, 2025
b359bc0
Update on "[compiler] Add Instruction.effects property"
josephsavona May 28, 2025
8859534
Update on "[compiler] Add Instruction.effects property"
josephsavona May 28, 2025
53aaf42
Update on "[compiler] Add Instruction.effects property"
josephsavona May 29, 2025
7a56b0e
Update on "[compiler] Add Instruction.effects property"
josephsavona May 29, 2025
633087c
Update on "[compiler] Add Instruction.effects property"
josephsavona May 30, 2025
88da18d
Update on "[compiler] Add Instruction.effects property"
josephsavona May 30, 2025
21884de
Update on "[compiler] Add Instruction.effects property"
josephsavona May 30, 2025
ff1a47c
Update on "[compiler] Add Instruction.effects property"
josephsavona May 30, 2025
0c49d97
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 2, 2025
14c5592
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 3, 2025
87fb2b7
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 3, 2025
4082ef4
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 3, 2025
b33f67a
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 4, 2025
1b15150
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 5, 2025
7890bfc
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 5, 2025
c33c9cf
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 5, 2025
1459075
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 6, 2025
07d4ced
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 6, 2025
768c75e
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 6, 2025
903bde4
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 6, 2025
e00de1b
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 7, 2025
5f6666b
Update on "[compiler] Add Instruction.effects property"
josephsavona Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ function lowerStatement(
kind: 'Debugger',
loc,
},
effects: null,
loc,
});
return;
Expand Down Expand Up @@ -1892,6 +1893,7 @@ function lowerExpression(
place: leftValue,
loc: exprLoc,
},
effects: null,
loc: exprLoc,
});
builder.terminateWithContinuation(
Expand Down Expand Up @@ -2827,6 +2829,7 @@ function lowerOptionalCallExpression(
args,
loc,
},
effects: null,
loc,
});
} else {
Expand All @@ -2840,6 +2843,7 @@ function lowerOptionalCallExpression(
args,
loc,
},
effects: null,
loc,
});
}
Expand Down Expand Up @@ -3466,9 +3470,10 @@ function lowerValueToTemporary(
const place: Place = buildTemporaryPlace(builder, value.loc);
builder.push({
id: makeInstructionId(0),
lvalue: {...place},
value: value,
effects: null,
loc: value.loc,
lvalue: {...place},
});
return place;
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {Environment, ReactFunctionType} from './Environment';
import type {HookKind} from './ObjectShape';
import {Type, makeType} from './Types';
import {z} from 'zod';
import {AliasingEffect} from '../Inference/InferMutationAliasingEffects';

/*
* *******************************************************************************************
Expand Down Expand Up @@ -649,12 +650,18 @@ export type Instruction = {
lvalue: Place;
value: InstructionValue;
loc: SourceLocation;
effects: Array<AliasingEffect> | null;
};

export function todoPopulateAliasingEffects(): Array<AliasingEffect> | null {
return null;
}

export type TInstruction<T extends InstructionValue> = {
id: InstructionId;
lvalue: Place;
value: T;
effects: Array<AliasingEffect> | null;
loc: SourceLocation;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
GeneratedSource,
HIRFunction,
Instruction,
Place,
} from './HIR';
import {markPredecessors} from './HIRBuilder';
import {terminalFallthrough, terminalHasFallthrough} from './visitors';
Expand Down Expand Up @@ -80,20 +81,22 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
suggestions: null,
});
const operand = Array.from(phi.operands.values())[0]!;
const lvalue: Place = {
kind: 'Identifier',
identifier: phi.place.identifier,
effect: Effect.ConditionallyMutate,
reactive: false,
loc: GeneratedSource,
};
const instr: Instruction = {
id: predecessor.terminal.id,
lvalue: {
kind: 'Identifier',
identifier: phi.place.identifier,
effect: Effect.ConditionallyMutate,
reactive: false,
loc: GeneratedSource,
},
lvalue: {...lvalue},
value: {
kind: 'LoadLocal',
place: {...operand},
loc: GeneratedSource,
},
effects: [{kind: 'Alias', from: {...operand}, into: {...lvalue}}],
loc: GeneratedSource,
};
predecessor.instructions.push(instr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function makeManualMemoizationMarkers(
deps: depsList,
loc: fnExpr.loc,
},
effects: null,
loc: fnExpr.loc,
},
{
Expand All @@ -208,6 +209,7 @@ function makeManualMemoizationMarkers(
decl: {...memoDecl},
loc: fnExpr.loc,
},
effects: null,
loc: fnExpr.loc,
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
isSetStateType,
isFireFunctionType,
makeScopeId,
todoPopulateAliasingEffects,
} from '../HIR';
import {collectHoistablePropertyLoadsInInnerFn} from '../HIR/CollectHoistablePropertyLoads';
import {collectOptionalChainSidemap} from '../HIR/CollectOptionalChainDependencies';
Expand Down Expand Up @@ -236,9 +237,10 @@ export function inferEffectDependencies(fn: HIRFunction): void {

newInstructions.push({
id: makeInstructionId(0),
loc: GeneratedSource,
lvalue: {...depsPlace, effect: Effect.Mutate},
effects: todoPopulateAliasingEffects(),
value: deps,
loc: GeneratedSource,
});

// Step 2: push the inferred deps array as an argument of the useEffect
Expand All @@ -249,9 +251,10 @@ export function inferEffectDependencies(fn: HIRFunction): void {
// Global functions have no reactive dependencies, so we can insert an empty array
newInstructions.push({
id: makeInstructionId(0),
loc: GeneratedSource,
lvalue: {...depsPlace, effect: Effect.Mutate},
effects: todoPopulateAliasingEffects(),
value: deps,
loc: GeneratedSource,
});
value.args.push({...depsPlace, effect: Effect.Freeze});
rewriteInstrs.set(instr.id, newInstructions);
Expand Down Expand Up @@ -316,21 +319,25 @@ function writeDependencyToInstructions(
const instructions: Array<Instruction> = [];
let currValue = createTemporaryPlace(env, GeneratedSource);
currValue.reactive = reactive;
const dependencyPlace: Place = {
kind: 'Identifier',
identifier: dep.identifier,
effect: Effect.Capture,
reactive,
loc: loc,
};
instructions.push({
id: makeInstructionId(0),
loc: GeneratedSource,
lvalue: {...currValue, effect: Effect.Mutate},
value: {
kind: 'LoadLocal',
place: {
kind: 'Identifier',
identifier: dep.identifier,
effect: Effect.Capture,
reactive,
loc: loc,
},
place: {...dependencyPlace},
loc: loc,
},
effects: [
{kind: 'Alias', from: {...dependencyPlace}, into: {...currValue}},
],
});
for (const path of dep.path) {
if (path.optional) {
Expand Down Expand Up @@ -359,6 +366,7 @@ function writeDependencyToInstructions(
property: path.property,
loc: loc,
},
effects: [{kind: 'Capture', from: {...currValue}, into: {...nextValue}}],
});
currValue = nextValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function rewriteBlock(
type: null,
loc: terminal.loc,
},
effects: null,
});
block.terminal = {
kind: 'goto',
Expand Down Expand Up @@ -263,5 +264,6 @@ function declareTemporary(
type: null,
loc: result.loc,
},
effects: null,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Place,
promoteTemporary,
SpreadPattern,
todoPopulateAliasingEffects,
} from '../HIR';
import {
createTemporaryPlace,
Expand Down Expand Up @@ -151,6 +152,7 @@ export function inlineJsxTransform(
type: null,
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
currentBlockInstructions.push(varInstruction);
Expand All @@ -167,6 +169,7 @@ export function inlineJsxTransform(
},
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
currentBlockInstructions.push(devGlobalInstruction);
Expand Down Expand Up @@ -220,6 +223,7 @@ export function inlineJsxTransform(
type: null,
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
thenBlockInstructions.push(reassignElseInstruction);
Expand Down Expand Up @@ -292,6 +296,7 @@ export function inlineJsxTransform(
],
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
elseBlockInstructions.push(reactElementInstruction);
Expand All @@ -309,6 +314,7 @@ export function inlineJsxTransform(
type: null,
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
elseBlockInstructions.push(reassignConditionalInstruction);
Expand Down Expand Up @@ -436,6 +442,7 @@ function createSymbolProperty(
binding: {kind: 'Global', name: 'Symbol'},
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
nextInstructions.push(symbolInstruction);
Expand All @@ -450,6 +457,7 @@ function createSymbolProperty(
property: makePropertyLiteral('for'),
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
nextInstructions.push(symbolForInstruction);
Expand All @@ -463,6 +471,7 @@ function createSymbolProperty(
value: symbolName,
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
nextInstructions.push(symbolValueInstruction);
Expand All @@ -478,6 +487,7 @@ function createSymbolProperty(
args: [symbolValueInstruction.lvalue],
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
const $$typeofProperty: ObjectProperty = {
Expand Down Expand Up @@ -508,6 +518,7 @@ function createTagProperty(
value: componentTag.name,
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
tagProperty = {
Expand Down Expand Up @@ -634,6 +645,7 @@ function createPropsProperties(
elements: [...children],
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
nextInstructions.push(childrenPropInstruction);
Expand All @@ -657,6 +669,7 @@ function createPropsProperties(
value: null,
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
refProperty = {
Expand All @@ -678,6 +691,7 @@ function createPropsProperties(
value: null,
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
keyProperty = {
Expand Down Expand Up @@ -711,6 +725,7 @@ function createPropsProperties(
properties: props,
loc: instr.value.loc,
},
effects: todoPopulateAliasingEffects(),
loc: instr.loc,
};
propsProperty = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
markInstructionIds,
promoteTemporary,
reversePostorderBlocks,
todoPopulateAliasingEffects,
} from '../HIR';
import {createTemporaryPlace} from '../HIR/HIRBuilder';
import {enterSSA} from '../SSA';
Expand Down Expand Up @@ -146,6 +147,7 @@ function emitLoadLoweredContextCallee(
id: makeInstructionId(0),
loc: GeneratedSource,
lvalue: createTemporaryPlace(env, GeneratedSource),
effects: todoPopulateAliasingEffects(),
value: loadGlobal,
};
}
Expand Down Expand Up @@ -192,6 +194,7 @@ function emitPropertyLoad(
lvalue: object,
value: loadObj,
id: makeInstructionId(0),
effects: todoPopulateAliasingEffects(),
loc: GeneratedSource,
};

Expand All @@ -206,6 +209,7 @@ function emitPropertyLoad(
lvalue: element,
value: loadProp,
id: makeInstructionId(0),
effects: todoPopulateAliasingEffects(),
loc: GeneratedSource,
};
return {
Expand Down Expand Up @@ -278,6 +282,7 @@ function emitSelectorFn(env: Environment, keys: Array<string>): Instruction {
loc: GeneratedSource,
},
lvalue: createTemporaryPlace(env, GeneratedSource),
effects: todoPopulateAliasingEffects(),
loc: GeneratedSource,
};
return fnInstr;
Expand All @@ -294,6 +299,7 @@ function emitArrayInstr(elements: Array<Place>, env: Environment): Instruction {
id: makeInstructionId(0),
value: array,
lvalue: arrayLvalue,
effects: todoPopulateAliasingEffects(),
loc: GeneratedSource,
};
return arrayInstr;
Expand Down
Loading
Loading