Skip to content

Commit

Permalink
[compiler][eslint] Add donotuse flag for bailouts
Browse files Browse the repository at this point in the history
---
Adding an experimental / donotuse flag for small Meta internal usecase

ghstack-source-id: 908ef1e150c9fef1347616c9c4dc6bf3316900b0
Pull Request resolved: #30342
  • Loading branch information
mofeiZ committed Jul 15, 2024
1 parent 735d3d2 commit 1f60a41
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <div>{y * x}</div>;
}`,
errors: [
{
message:
"[ReactCompilerBailout] (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration (@:3:2)",
},
],
},
],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -154,7 +183,7 @@ const rule: Rule.RuleModule = {
context.report({
message: detail.reason,
loc,
suggest: makeSuggestions(detail),
suggest,
});
}
}
Expand Down

0 comments on commit 1f60a41

Please sign in to comment.