Skip to content

Commit 46fa6c2

Browse files
committed
[compiler] More fbt compatibility
In my previous PR I fixed some cases but broke others. So, new approach. Two phase algorithm: * First pass is forward data flow to determine all usages of macros. This is necessary because many of Meta's macros have variants that can be accessed via properties, eg you can do `macro(...)` but also `macro.variant(...)`. * Second pass is backwards data flow to find macro invocations (JSX and calls) and then merge their operands into the same scope as the macro call. Note that this required updating PromoteUsedTemporaries to avoid promoting macro calls that have interposing instructions between their creation and usage. Macro calls in general are pure so it should be safe to reorder them.
1 parent 1324e1b commit 46fa6c2

15 files changed

+475
-295
lines changed

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Pipeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ function runWithEnvironment(
499499
value: reactiveFunction,
500500
});
501501

502-
promoteUsedTemporaries(reactiveFunction);
502+
promoteUsedTemporaries(reactiveFunction, fbtOperands);
503503
log({
504504
kind: 'reactive',
505505
name: 'PromoteUsedTemporaries',

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,11 @@ export type ExternalFunction = z.infer<typeof ExternalFunctionSchema>;
8383
export const USE_FIRE_FUNCTION_NAME = 'useFire';
8484
export const EMIT_FREEZE_GLOBAL_GATING = '__DEV__';
8585

86-
export const MacroMethodSchema = z.union([
87-
z.object({type: z.literal('wildcard')}),
88-
z.object({type: z.literal('name'), name: z.string()}),
89-
]);
90-
91-
// Would like to change this to drop the string option, but breaks compatibility with existing configs
92-
export const MacroSchema = z.union([
93-
z.string(),
94-
z.tuple([z.string(), z.array(MacroMethodSchema)]),
95-
]);
86+
export const MacroSchema = z.string();
9687

9788
export type CompilerMode = 'all_features' | 'no_inferred_memo';
9889

9990
export type Macro = z.infer<typeof MacroSchema>;
100-
export type MacroMethod = z.infer<typeof MacroMethodSchema>;
10191

10292
const HookSchema = z.object({
10393
/*

0 commit comments

Comments
 (0)