Skip to content

Commit 40af6fd

Browse files
committed
[compiler][bugfix] Don't insert hook guards in retry pipeline (#32665)
Fixing bug from #32164 -- prior to this PR, we inserted hook guards even for functions that bailed out of compilation. DiffTrain build for [0962f68](0962f68)
1 parent 56171be commit 40af6fd

35 files changed

+100
-94
lines changed

compiled/eslint-plugin-react-hooks/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41898,7 +41898,7 @@ function codegenFunction(fn, { uniqueIdentifiers, fbtOperands, }) {
4189841898
}
4189941899
const compiled = compileResult.unwrap();
4190041900
const hookGuard = fn.env.config.enableEmitHookGuards;
41901-
if (hookGuard != null) {
41901+
if (hookGuard != null && fn.env.isInferredMemoEnabled) {
4190241902
compiled.body = libExports.blockStatement([
4190341903
createHookGuard(hookGuard, compiled.body.body, GuardKind.PushHookGuard, GuardKind.PopHookGuard),
4190441904
]);
@@ -41925,7 +41925,9 @@ function codegenFunction(fn, { uniqueIdentifiers, fbtOperands, }) {
4192541925
compiled.body.body.unshift(...preface);
4192641926
}
4192741927
const emitInstrumentForget = fn.env.config.enableEmitInstrumentForget;
41928-
if (emitInstrumentForget != null && fn.id != null) {
41928+
if (emitInstrumentForget != null &&
41929+
fn.id != null &&
41930+
fn.env.isInferredMemoEnabled) {
4192941931
let gating;
4193041932
if (emitInstrumentForget.gating != null &&
4193141933
emitInstrumentForget.globalGating != null) {
@@ -42136,7 +42138,7 @@ function codegenBlockNoReset(cx, block) {
4213642138
return libExports.blockStatement(statements);
4213742139
}
4213842140
function wrapCacheDep(cx, value) {
42139-
if (cx.env.config.enableEmitFreeze != null) {
42141+
if (cx.env.config.enableEmitFreeze != null && cx.env.isInferredMemoEnabled) {
4214042142
return libExports.conditionalExpression(libExports.identifier('true'), libExports.callExpression(libExports.identifier(cx.env.config.enableEmitFreeze.importSpecifierName), [value, libExports.stringLiteral(cx.fnName)]), value);
4214142143
}
4214242144
else {
@@ -42826,13 +42828,13 @@ function createHookGuard(guard, stmts, before, after) {
4282642828
}
4282742829
return libExports.tryStatement(libExports.blockStatement([createHookGuardImpl(before), ...stmts]), null, libExports.blockStatement([createHookGuardImpl(after)]));
4282842830
}
42829-
function createCallExpression(config, callee, args, loc, isHook) {
42831+
function createCallExpression(env, callee, args, loc, isHook) {
4283042832
const callExpr = libExports.callExpression(callee, args);
4283142833
if (loc != null && loc != GeneratedSource) {
4283242834
callExpr.loc = loc;
4283342835
}
42834-
const hookGuard = config.enableEmitHookGuards;
42835-
if (hookGuard != null && isHook) {
42836+
const hookGuard = env.config.enableEmitHookGuards;
42837+
if (hookGuard != null && isHook && env.isInferredMemoEnabled) {
4283642838
const iife = libExports.functionExpression(null, [], libExports.blockStatement([
4283742839
createHookGuard(hookGuard, [libExports.returnStatement(callExpr)], GuardKind.AllowHook, GuardKind.DisallowHook),
4283842840
]));
@@ -42924,7 +42926,7 @@ function codegenInstructionValue(cx, instrValue) {
4292442926
const isHook = getHookKind(cx.env, instrValue.callee.identifier) != null;
4292542927
const callee = codegenPlaceToExpression(cx, instrValue.callee);
4292642928
const args = instrValue.args.map(arg => codegenArgument(cx, arg));
42927-
value = createCallExpression(cx.env.config, callee, args, instrValue.loc, isHook);
42929+
value = createCallExpression(cx.env, callee, args, instrValue.loc, isHook);
4292842930
break;
4292942931
}
4293042932
case 'OptionalExpression': {
@@ -42983,7 +42985,7 @@ function codegenInstructionValue(cx, instrValue) {
4298342985
suggestions: null,
4298442986
});
4298542987
const args = instrValue.args.map(arg => codegenArgument(cx, arg));
42986-
value = createCallExpression(cx.env.config, memberExpr, args, instrValue.loc, isHook);
42988+
value = createCallExpression(cx.env, memberExpr, args, instrValue.loc, isHook);
4298742989
break;
4298842990
}
4298942991
case 'NewExpression': {
@@ -54175,6 +54177,10 @@ function compileProgram(program, pass) {
5417554177
kind: 'compile',
5417654178
compiledFn: compileFn(fn, environment, fnType, 'no_inferred_memo', useMemoCacheIdentifier.name, pass.opts.logger, pass.filename, pass.code),
5417754179
};
54180+
if (!compileResult.compiledFn.hasFireRewrite &&
54181+
!compileResult.compiledFn.hasLoweredContextAccess) {
54182+
return null;
54183+
}
5417854184
}
5417954185
catch (err) {
5418054186
if (err instanceof CompilerError) {

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b630219b1377f3117036b1c6118676c16fdb21b7
1+
0962f684a066df4fd2a7db7489cb1984799ad674
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b630219b1377f3117036b1c6118676c16fdb21b7
1+
0962f684a066df4fd2a7db7489cb1984799ad674

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ __DEV__ &&
15101510
exports.useTransition = function () {
15111511
return resolveDispatcher().useTransition();
15121512
};
1513-
exports.version = "19.1.0-www-classic-b630219b-20250320";
1513+
exports.version = "19.1.0-www-classic-0962f684-20250320";
15141514
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15151515
"function" ===
15161516
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ __DEV__ &&
15101510
exports.useTransition = function () {
15111511
return resolveDispatcher().useTransition();
15121512
};
1513-
exports.version = "19.1.0-www-modern-b630219b-20250320";
1513+
exports.version = "19.1.0-www-modern-0962f684-20250320";
15141514
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15151515
"function" ===
15161516
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,4 @@ exports.useSyncExternalStore = function (
641641
exports.useTransition = function () {
642642
return ReactSharedInternals.H.useTransition();
643643
};
644-
exports.version = "19.1.0-www-classic-b630219b-20250320";
644+
exports.version = "19.1.0-www-classic-0962f684-20250320";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,4 @@ exports.useSyncExternalStore = function (
641641
exports.useTransition = function () {
642642
return ReactSharedInternals.H.useTransition();
643643
};
644-
exports.version = "19.1.0-www-modern-b630219b-20250320";
644+
exports.version = "19.1.0-www-modern-0962f684-20250320";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ exports.useSyncExternalStore = function (
645645
exports.useTransition = function () {
646646
return ReactSharedInternals.H.useTransition();
647647
};
648-
exports.version = "19.1.0-www-classic-b630219b-20250320";
648+
exports.version = "19.1.0-www-classic-0962f684-20250320";
649649
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
650650
"function" ===
651651
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ exports.useSyncExternalStore = function (
645645
exports.useTransition = function () {
646646
return ReactSharedInternals.H.useTransition();
647647
};
648-
exports.version = "19.1.0-www-modern-b630219b-20250320";
648+
exports.version = "19.1.0-www-modern-0962f684-20250320";
649649
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
650650
"function" ===
651651
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18529,10 +18529,10 @@ __DEV__ &&
1852918529
(function () {
1853018530
var internals = {
1853118531
bundleType: 1,
18532-
version: "19.1.0-www-classic-b630219b-20250320",
18532+
version: "19.1.0-www-classic-0962f684-20250320",
1853318533
rendererPackageName: "react-art",
1853418534
currentDispatcherRef: ReactSharedInternals,
18535-
reconcilerVersion: "19.1.0-www-classic-b630219b-20250320"
18535+
reconcilerVersion: "19.1.0-www-classic-0962f684-20250320"
1853618536
};
1853718537
internals.overrideHookState = overrideHookState;
1853818538
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -18566,7 +18566,7 @@ __DEV__ &&
1856618566
exports.Shape = Shape;
1856718567
exports.Surface = Surface;
1856818568
exports.Text = Text;
18569-
exports.version = "19.1.0-www-classic-b630219b-20250320";
18569+
exports.version = "19.1.0-www-classic-0962f684-20250320";
1857018570
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1857118571
"function" ===
1857218572
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)