Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -44,7 +44,6 @@ import {
} from '../Optimization';
import {
CodegenFunction,
alignObjectMethodScopes,
assertScopeInstructionsWithinScopes,
assertWellFormedBreakTargets,
buildReactiveFunction,
Expand Down Expand Up @@ -333,13 +332,6 @@ function runWithEnvironment(
value: hir,
});

alignObjectMethodScopes(hir);
log({
kind: 'hir',
name: 'AlignObjectMethodScopes',
value: hir,
});

pruneUnusedLabelsHIR(hir);
log({
kind: 'hir',
Expand Down
28 changes: 12 additions & 16 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1564,19 +1564,6 @@ function lowerStatement(
}
}

function lowerObjectMethod(
builder: HIRBuilder,
property: NodePath<t.ObjectMethod>,
): InstructionValue {
const loc = property.node.loc ?? GeneratedSource;
const loweredFunc = lowerFunction(builder, property);

return {
kind: 'ObjectMethod',
loc,
loweredFunc,
};
}

function lowerObjectPropertyKey(
builder: HIRBuilder,
Expand Down Expand Up @@ -1703,15 +1690,24 @@ function lowerExpression(
);
continue;
}
const method = lowerObjectMethod(builder, propertyPath);
const place = lowerValueToTemporary(builder, method);
const loweredKey = lowerObjectPropertyKey(builder, propertyPath);
if (!loweredKey) {
continue;
}
const loc = propertyPath.node.loc ?? GeneratedSource;
const loweredFunc = lowerFunction(builder, propertyPath);
const fnValue: InstructionValue = {
kind: 'FunctionExpression',
name: loweredFunc.func.id,
nameHint: null,
type: 'FunctionExpression',
loc,
loweredFunc,
};
const place = lowerValueToTemporary(builder, fnValue);
properties.push({
kind: 'ObjectProperty',
type: 'method',
type: 'property',
place,
key: loweredKey,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ function getAssumedInvokedFunctions(
for (const {lvalue, value} of block.instructions) {
/**
* Conservatively only match function expressions which can have guaranteed ssa.
* ObjectMethods and ObjectProperties do not.
* ObjectProperties do not.
*/
if (value.kind === 'FunctionExpression') {
temporaries.set(lvalue.identifier.id, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ function traverseFunction(
): void {
for (const [_, block] of fn.body.blocks) {
for (const instr of block.instructions) {
if (
instr.value.kind === 'FunctionExpression' ||
instr.value.kind === 'ObjectMethod'
) {
if (instr.value.kind === 'FunctionExpression') {
traverseFunction(instr.value.loweredFunc.func, {
...context,
currFn: instr.value.loweredFunc.func,
Expand Down
12 changes: 1 addition & 11 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,20 +724,14 @@ export type ObjectPropertyKey =
export type ObjectProperty = {
kind: 'ObjectProperty';
key: ObjectPropertyKey;
type: 'property' | 'method';
type: 'property';
place: Place;
};

export type LoweredFunction = {
func: HIRFunction;
};

export type ObjectMethod = {
kind: 'ObjectMethod';
loc: SourceLocation;
loweredFunc: LoweredFunction;
};

export enum InstructionKind {
// const declaration
Const = 'Const',
Expand Down Expand Up @@ -984,7 +978,6 @@ export type InstructionValue =
properties: Array<ObjectProperty | SpreadPattern>;
loc: SourceLocation;
}
| ObjectMethod
| ArrayExpression
| {kind: 'JsxFragment'; children: Array<Place>; loc: SourceLocation}
| {
Expand Down Expand Up @@ -1783,9 +1776,6 @@ export function makeInstructionId(id: number): InstructionId {
return id as InstructionId;
}

export function isObjectMethodType(id: Identifier): boolean {
return id.type.kind == 'ObjectMethod';
}

export function isObjectType(id: Identifier): boolean {
return id.type.kind === 'Object';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ export function mergeConsecutiveBlocks(fn: HIRFunction): void {
}

for (const instr of block.instructions) {
if (
instr.value.kind === 'FunctionExpression' ||
instr.value.kind === 'ObjectMethod'
) {
if (instr.value.kind === 'FunctionExpression') {
mergeConsecutiveBlocks(instr.value.loweredFunc.func);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ function getOverlappingReactiveScopes(
visitInstructionId(instr.id, context, state);
for (const place of eachInstructionOperand(instr)) {
if (
(instr.value.kind === 'FunctionExpression' ||
instr.value.kind === 'ObjectMethod') &&
instr.value.kind === 'FunctionExpression' &&
place.identifier.type.kind === 'Primitive'
) {
continue;
Expand Down
14 changes: 3 additions & 11 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
LValue,
ManualMemoDependency,
MutableRange,
ObjectMethod,
ObjectPropertyKey,
Pattern,
Phi,
Expand Down Expand Up @@ -547,10 +546,8 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
)}]`;
break;
}
case 'ObjectMethod':
case 'FunctionExpression': {
const kind =
instrValue.kind === 'FunctionExpression' ? 'Function' : 'ObjectMethod';
const kind = 'Function';
const name = getFunctionName(instrValue, '');
const fn = printFunction(instrValue.loweredFunc.func)
.split('\n')
Expand Down Expand Up @@ -917,15 +914,10 @@ export function printAliases(aliases: DisjointSet<Identifier>): string {
}

function getFunctionName(
instrValue: ObjectMethod | FunctionExpression,
instrValue: FunctionExpression,
defaultValue: string,
): string {
switch (instrValue.kind) {
case 'FunctionExpression':
return instrValue.name ?? defaultValue;
case 'ObjectMethod':
return defaultValue;
}
return instrValue.name ?? defaultValue;
}

export function printAliasingEffect(effect: AliasingEffect): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
ReactiveScopeDependency,
Identifier,
ReactiveScope,
isObjectMethodType,
isRefValueType,
isUseRefType,
makeInstructionId,
Expand All @@ -28,7 +27,6 @@ import {
LoadContext,
TInstruction,
FunctionExpression,
ObjectMethod,
PropertyLiteral,
convertHoistedLValueKind,
SourceLocation,
Expand Down Expand Up @@ -323,10 +321,7 @@ function collectTemporariesSidemapImpl(
loc: value.loc,
});
}
} else if (
value.kind === 'FunctionExpression' ||
value.kind === 'ObjectMethod'
) {
} else if (value.kind === 'FunctionExpression') {
collectTemporariesSidemapImpl(
value.loweredFunc.func,
usedOutsideDeclaringScope,
Expand Down Expand Up @@ -501,14 +496,6 @@ export class DependencyCollectionContext {
return false;
}

/*
* object methods are not deps because they will be codegen'ed back in to
* the object literal.
*/
if (isObjectMethodType(maybeDependency.identifier)) {
return false;
}

const identifier = maybeDependency.identifier;
/*
* If this operand is used in a scope, has a dynamic value, and was defined
Expand Down Expand Up @@ -646,7 +633,7 @@ export class DependencyCollectionContext {
}
}
enterInnerFn<T>(
innerFn: TInstruction<FunctionExpression> | TInstruction<ObjectMethod>,
innerFn: TInstruction<FunctionExpression>,
cb: () => T,
): T {
const prevContext = this.#innerFnContext;
Expand Down Expand Up @@ -805,10 +792,7 @@ function collectDependencies(
}
}
for (const instr of block.instructions) {
if (
instr.value.kind === 'FunctionExpression' ||
instr.value.kind === 'ObjectMethod'
) {
if (instr.value.kind === 'FunctionExpression') {
context.declare(instr.lvalue.identifier, {
id: instr.id,
scope: context.currentScope,
Expand All @@ -818,9 +802,7 @@ function collectDependencies(
*/
const innerFn = instr.value.loweredFunc.func;
context.enterInnerFn(
instr as
| TInstruction<FunctionExpression>
| TInstruction<ObjectMethod>,
instr as TInstruction<FunctionExpression>,
() => {
handleFunction(innerFn);
},
Expand Down
17 changes: 2 additions & 15 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export type Type =
| PhiType
| TypeVar
| PolyType
| PropType
| ObjectMethod;
| PropType;
export type PrimitiveType = {kind: 'Primitive'};

/*
Expand Down Expand Up @@ -72,10 +71,6 @@ export type PropType = {
};
};

export type ObjectMethod = {
kind: 'ObjectMethod';
};

/*
* Simulated opaque type for TypeId to prevent using normal numbers as ids
* accidentally.
Expand Down Expand Up @@ -116,9 +111,6 @@ export function duplicateType(type: Type): Type {
case 'Object': {
return {kind: 'Object', shapeId: type.shapeId};
}
case 'ObjectMethod': {
return {kind: 'ObjectMethod'};
}
case 'Phi': {
return {
kind: 'Phi',
Expand Down Expand Up @@ -154,8 +146,7 @@ export function typeEquals(tA: Type, tB: Type): boolean {
primitiveTypeEquals(tA, tB) ||
polyTypeEquals(tA, tB) ||
phiTypeEquals(tA, tB) ||
propTypeEquals(tA, tB) ||
objectMethodTypeEquals(tA, tB)
propTypeEquals(tA, tB)
);
}

Expand All @@ -170,10 +161,6 @@ function typeKindCheck(tA: Type, tb: Type, type: string): boolean {
return tA.kind === type && tb.kind === type;
}

function objectMethodTypeEquals(tA: Type, tB: Type): boolean {
return typeKindCheck(tA, tB, 'ObjectMethod');
}

function propTypeEquals(tA: Type, tB: Type): boolean {
if (tA.kind === 'Property' && tB.kind === 'Property') {
if (!typeEquals(tA.objectType, tB.objectType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export function* eachInstructionValueOperand(
}
break;
}
case 'ObjectMethod':
case 'FunctionExpression': {
yield* instrValue.loweredFunc.func.context;
break;
Expand Down Expand Up @@ -587,7 +586,6 @@ export function mapInstructionValueOperands(
instrValue.children = instrValue.children.map(e => fn(e));
break;
}
case 'ObjectMethod':
case 'FunctionExpression': {
instrValue.loweredFunc.func.context =
instrValue.loweredFunc.func.context.map(d => fn(d));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
GeneratedSource,
Hole,
IdentifierId,
ObjectMethod,
Place,
SourceLocation,
SpreadPattern,
Expand Down Expand Up @@ -144,7 +143,7 @@ export type AliasingEffect =
| {
kind: 'CreateFunction';
captures: Array<Place>;
function: FunctionExpression | ObjectMethod;
function: FunctionExpression;
into: Place;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default function analyseFunctions(func: HIRFunction): void {
for (const [_, block] of func.body.blocks) {
for (const instr of block.instructions) {
switch (instr.value.kind) {
case 'ObjectMethod':
case 'FunctionExpression': {
lowerWithMutationAliasing(instr.value.loweredFunc.func);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,7 @@ function applySignature(
* TODO: make sure we're also validating against global mutations somewhere, but
* account for this being allowed in effects/event handlers.
*/
if (
instruction.value.kind === 'FunctionExpression' ||
instruction.value.kind === 'ObjectMethod'
) {
if (instruction.value.kind === 'FunctionExpression') {
const aliasingEffects =
instruction.value.loweredFunc.func.aliasingEffects ?? [];
const context = new Set(
Expand Down Expand Up @@ -1903,7 +1900,6 @@ function computeSignatureForInstruction(
});
break;
}
case 'ObjectMethod':
case 'FunctionExpression': {
/**
* We've already analyzed the function expression in AnalyzeFunctions. There, we assign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,7 @@ export function inferReactivePlaces(fn: HIRFunction): void {
reactiveIdentifiers.isReactive(operand);
}
}
if (
instr.value.kind === 'ObjectMethod' ||
instr.value.kind === 'FunctionExpression'
) {
if (instr.value.kind === 'FunctionExpression') {
propagateReactivityToInnerFunctions(
instr.value.loweredFunc.func,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ function evaluateInstruction(
}
return placeValue;
}
case 'ObjectMethod':
case 'FunctionExpression': {
constantPropagationImpl(value.loweredFunc.func, constants);
return null;
Expand Down
Loading