Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
79760fe
[compiler] Effect inference across signatures and user-provided callb…
josephsavona May 30, 2025
e444154
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona May 30, 2025
f61f8ab
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona May 30, 2025
4642ec4
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 2, 2025
b71fb92
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 3, 2025
5a1bd21
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 3, 2025
e016f45
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 4, 2025
bd43c5e
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 4, 2025
d2b0091
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 5, 2025
147ff97
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 5, 2025
2409b55
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 5, 2025
50d168f
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 6, 2025
98dda9f
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 6, 2025
eeb11ab
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 6, 2025
b77909d
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 6, 2025
f6bb933
Update on "[compiler] Effect inference across signatures and user-pro…
josephsavona Jun 7, 2025
a964bac
Update on "[compiler] Effect inference across signatures and user-pro…
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 @@ -246,7 +246,7 @@ export const EnvironmentConfigSchema = z.object({
/**
* Enable a new model for mutability and aliasing inference
*/
enableNewMutationAliasingModel: z.boolean().default(false),
enableNewMutationAliasingModel: z.boolean().default(true),

/**
* Enables inference of optional dependency chains. Without this flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export type FunctionSignature = {
canonicalName?: string;

aliasing?: AliasingSignature | null;
todo_aliasing?: AliasingSignature | null;
};

/*
Expand Down Expand Up @@ -320,6 +321,7 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
params: [],
rest: makeIdentifierId(1),
returns: makeIdentifierId(2),
temporaries: [],
effects: [
// Push directly mutates the array itself
{kind: 'Mutate', value: signatureArgument(0)},
Expand Down Expand Up @@ -367,7 +369,59 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [
returnValueKind: ValueKind.Mutable,
noAlias: true,
mutableOnlyIfOperandsAreMutable: true,
aliasing: null,
aliasing: {
receiver: makeIdentifierId(0),
params: [makeIdentifierId(1)],
rest: null,
returns: makeIdentifierId(2),
temporaries: [
// Temporary representing captured items of the receiver
signatureArgument(3),
// Temporary representing the result of the callback
signatureArgument(4),
/*
* Undefined `this` arg to the callback. Note the signature does not
* support passing an explicit thisArg second param
*/
signatureArgument(5),
],
effects: [
// Map creates a new mutable array
{
kind: 'Create',
into: signatureArgument(2),
value: ValueKind.Mutable,
},
// The first arg to the callback is an item extracted from the receiver array
{
kind: 'CreateFrom',
from: signatureArgument(0),
into: signatureArgument(3),
},
// The undefined this for the callback
{
kind: 'Create',
into: signatureArgument(5),
value: ValueKind.Primitive,
},
// calls the callback, returning the result into a temporary
{
kind: 'Apply',
receiver: signatureArgument(5),
args: [signatureArgument(3), {kind: 'Hole'}, signatureArgument(0)],
function: signatureArgument(1),
into: signatureArgument(4),
signature: null,
mutatesFunction: false,
},
// captures the result of the callback into the return array
{
kind: 'Capture',
from: signatureArgument(4),
into: signatureArgument(2),
},
],
},
}),
],
[
Expand Down
12 changes: 12 additions & 0 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,8 @@ export function printAliasingEffect(effect: AliasingEffect): string {
.map(arg => {
if (arg.kind === 'Identifier') {
return printPlaceForAliasEffect(arg);
} else if (arg.kind === 'Hole') {
return ' ';
}
return `...${printPlaceForAliasEffect(arg.place)}`;
})
Expand All @@ -986,6 +988,9 @@ export function printAliasingEffect(effect: AliasingEffect): string {
}
return `Apply ${printPlaceForAliasEffect(effect.into)} = ${receiverCallee}(${args})${signature != '' ? '\n ' : ''}${signature}`;
}
case 'CreateFunction': {
return `Function ${printPlaceForAliasEffect(effect.into)} = Function captures=[${effect.captures.map(printPlaceForAliasEffect).join(', ')}]`;
}
case 'Freeze': {
return `Freeze ${printPlaceForAliasEffect(effect.value)} ${effect.reason}`;
}
Expand All @@ -1007,6 +1012,13 @@ function printPlaceForAliasEffect(place: Place): string {

export function printAliasingSignature(signature: AliasingSignature): string {
const tokens: Array<string> = ['function '];
if (signature.temporaries.length !== 0) {
tokens.push('<');
tokens.push(
signature.temporaries.map(temp => `$${temp.identifier.id}`).join(', '),
);
tokens.push('>');
}
tokens.push('(');
tokens.push('this=$' + String(signature.receiver));
for (const param of signature.params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function lowerWithMutationAliasing(fn: HIRFunction): void {
capturedOrMutated.add(effect.value.identifier.id);
break;
}
case 'CreateFunction':
case 'Create':
case 'Freeze':
case 'ImmutableCapture': {
Expand Down
Loading
Loading