From 821986529af465ff5b45fa8308a476ce4bd3fd42 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Mon, 15 Jul 2024 12:17:38 +0900 Subject: [PATCH] [compiler][be] Promote destructured params to temporaries Addresses a follow-up from the previous PR. Destructured function params are currently not eagerly promoted to temporaries: we wait until PromotedUsedTemporaries. But params _always_ have to be named, so we can promote when constructing HIR. ghstack-source-id: 0e8cbc3a6ccdd331930cab46c77db6ae88d1e4f7 Pull Request resolved: https://github.com/facebook/react/pull/30332 --- .../babel-plugin-react-compiler/src/HIR/BuildHIR.ts | 1 + .../src/ReactiveScopes/CodegenReactiveFunction.ts | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts index 233a5e4b32fc6..a75c7d9f4c667 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts @@ -129,6 +129,7 @@ export function lower( reactive: false, loc: param.node.loc ?? GeneratedSource, }; + promoteTemporary(place.identifier); params.push(place); lowerAssignment( builder, diff --git a/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts b/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts index 37f596514b819..818aeee5fcf63 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts @@ -278,16 +278,6 @@ export function codegenFunction( pruneUnusedLValues(reactiveFunction); pruneHoistedContexts(reactiveFunction); - /* - * TODO: temporary function params (due to destructuring) should always be - * promoted so that they can be renamed - */ - for (const param of reactiveFunction.params) { - const place = param.kind === "Identifier" ? param : param.place; - if (place.identifier.name === null) { - promoteTemporary(place.identifier); - } - } const identifiers = renameVariables(reactiveFunction); logReactiveFunction("Outline", reactiveFunction); const codegen = codegenReactiveFunction(