From 3b1eabb7ca658e2a22a2e15039dc147f69da3e73 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Mon, 15 Jul 2024 16:20:00 -0400 Subject: [PATCH] [compiler][eslint] Add donotuse flag for bailouts [ghstack-poisoned] --- .../__tests__/ReactCompilerRule-test.ts | 20 ++++++++++++ .../src/rules/ReactCompilerRule.ts | 31 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts b/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts index dc4f6b7f88f..55690a67cd5 100644 --- a/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts +++ b/compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRule-test.ts @@ -179,6 +179,26 @@ const tests: CompilerTestCases = { }, ], }, + { + name: "Test experimental/unstable report all bailouts mode", + options: [ + { + reportableLevels: new Set([ErrorSeverity.InvalidReact]), + __unstable_donotuse_reportAllBailouts: true, + }, + ], + code: normalizeIndent` + function Foo(x) { + var y = 1; + return
{y * x}
; + }`, + errors: [ + { + message: + "[ReactCompilerBailout] (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration (@:3:2)", + }, + ], + }, ], }; diff --git a/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts b/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts index 5ab464eb001..a407748898b 100644 --- a/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts +++ b/compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts @@ -129,6 +129,22 @@ const rule: Rule.RuleModule = { } else { reportableLevels = DEFAULT_REPORTABLE_LEVELS; } + /** + * Experimental setting to report all compilation bailouts on the compilation + * unit (e.g. function or hook) instead of the offensive line. + * Intended to be used when a codebase is 100% reliant on the compiler for + * memoization (i.e. deleted all manual memo) and needs compilation success + * signals for perf debugging. + */ + let __unstable_donotuse_reportAllBailouts: boolean = false; + if ( + userOpts["__unstable_donotuse_reportAllBailouts"] != null && + typeof userOpts["__unstable_donotuse_reportAllBailouts"] === "boolean" + ) { + __unstable_donotuse_reportAllBailouts = + userOpts["__unstable_donotuse_reportAllBailouts"]; + } + const options: PluginOptions = { ...parsePluginOptions(userOpts), ...COMPILER_OPTIONS, @@ -139,6 +155,19 @@ const rule: Rule.RuleModule = { userLogger?.logEvent(filename, event); if (event.kind === "CompileError") { const detail = event.detail; + const suggest = makeSuggestions(detail); + if (__unstable_donotuse_reportAllBailouts && event.fnLoc != null) { + const locStr = + detail.loc != null && typeof detail.loc !== "symbol" + ? ` (@:${detail.loc.start.line}:${detail.loc.start.column})` + : ""; + context.report({ + message: `[ReactCompilerBailout] ${detail.reason}${locStr}`, + loc: event.fnLoc, + suggest, + }); + } + if (!isReportableDiagnostic(detail)) { return; } @@ -154,7 +183,7 @@ const rule: Rule.RuleModule = { context.report({ message: detail.reason, loc, - suggest: makeSuggestions(detail), + suggest, }); } }