From 52a34e4fa0c953f62a62e38d8fbf978da9bef341 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 9 May 2025 10:42:51 -0700 Subject: [PATCH] Update base for Update on "[compiler] Fix for PropertyStore object effect" Fix for the issue in the previous PR. Long-term the ideal thing would be to make InferMutableRanges smarter about Store effects, and recognize that they are also transitive mutations of whatever was captured into the object. So in the following: ``` const x = {y: {z: {}}}; x.y.z.key = value; ``` That the `PropertyStore z . 'key' = value` is a transitive mutation of x and all three object expressions (x, x.y, x.y.z). But for now it's simpler to stick to the original idea of Store only counting if we know that the type is an object. [ghstack-poisoned] --- .../src/HIR/PrintHIR.ts | 2 +- .../src/Inference/InferMutableRanges.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts index 93acb4c944..5325494f57 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts @@ -731,7 +731,7 @@ function isMutable(range: MutableRange): boolean { } const DEBUG_MUTABLE_RANGES = false; -function printMutableRange(identifier: Identifier): string { +export function printMutableRange(identifier: Identifier): string { if (DEBUG_MUTABLE_RANGES) { // if debugging, print both the identifier and scope range if they differ const range = identifier.mutableRange; diff --git a/compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutableRanges.ts b/compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutableRanges.ts index 1236bae799..3b022c13f7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutableRanges.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutableRanges.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import prettyFormat from 'pretty-format'; import {HIRFunction, Identifier} from '../HIR/HIR'; import DisjointSet from '../Utils/DisjointSet'; import {inferAliasForUncalledFunctions} from './InerAliasForUncalledFunctions'; @@ -16,6 +17,7 @@ import {inferMutableLifetimes} from './InferMutableLifetimes'; import {inferMutableRangesForAlias} from './InferMutableRangesForAlias'; import {inferMutableRangesForComutation} from './InferMutableRangesForComutation'; import {inferTryCatchAliases} from './InferTryCatchAliases'; +import {printIdentifier, printMutableRange} from '../HIR/PrintHIR'; export function inferMutableRanges(ir: HIRFunction): DisjointSet { // Infer mutable ranges for non fields @@ -96,6 +98,20 @@ export function inferMutableRanges(ir: HIRFunction): DisjointSet { return aliases; } +export function debugAliases(aliases: DisjointSet): void { + console.log( + prettyFormat( + aliases + .buildSets() + .map(set => + [...set].map( + ident => printIdentifier(ident) + printMutableRange(ident), + ), + ), + ), + ); +} + /** * Canonicalizes the alias set and mutable range information calculated at the current time. * The returned value maps each identifier in the program to the root identifier of its alias