Skip to content

Commit

Permalink
[compiler] Always emit variable decl in gating mode
Browse files Browse the repository at this point in the history
This PR makes it so we always emit a const VariableDeclaration for
compiled functions in gating mode. If the original declaration's parent
was an ExportDefaultDeclaration we'll also append a new
ExportDefaultDeclaration pointing to the new identifier. This allows
code that adds optional properties to the function declaration to still
work in gating mode

ghstack-source-id: 5705479135baa268eeb3c85bfbf1883964e84916
Pull Request resolved: #29806

DiffTrain build for commit 20841f9.
  • Loading branch information
poteto committed Jun 7, 2024
1 parent 1cb60db commit 3ffc777
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 150 deletions.
2 changes: 1 addition & 1 deletion compiled-rn/VERSION_NATIVE_FB
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.0.0-native-fb-0a5e0b0c2e-20240607
19.0.0-native-fb-20841f9a62-20240607
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<56b66450b90e3080649426a2a426e482>>
* @generated SignedSource<<1e3975bb7b9fe350a36865e6c41276e8>>
*/

'use strict';
Expand Down Expand Up @@ -5650,7 +5650,7 @@ var ownerHasKeyUseWarning;
var ownerHasFunctionTypeWarning;
var ownerHasSymbolTypeWarning;

var warnForMissingKey = function (child, returnFiber) {};
var warnForMissingKey = function (returnFiber, workInProgress, child) {};

{
didWarnAboutMaps = false;
Expand All @@ -5665,7 +5665,7 @@ var warnForMissingKey = function (child, returnFiber) {};
ownerHasFunctionTypeWarning = {};
ownerHasSymbolTypeWarning = {};

warnForMissingKey = function (child, returnFiber) {
warnForMissingKey = function (returnFiber, workInProgress, child) {
if (child === null || typeof child !== 'object') {
return;
}
Expand Down Expand Up @@ -5724,15 +5724,9 @@ var warnForMissingKey = function (child, returnFiber) {};
// Give the component that originally created this child.
childOwnerAppendix = " It was passed a child from " + ownerName + ".";
}
} // We create a fake Fiber for the child to log the stack trace from.
// TODO: Refactor the warnForMissingKey calls to happen after fiber creation
// so that we can get access to the fiber that will eventually be created.
// That way the log can show up associated with the right instance in DevTools.

}

var fiber = createFiberFromElement(child, returnFiber.mode, 0);
fiber.return = returnFiber;
runWithFiberInDEV(fiber, function () {
runWithFiberInDEV(workInProgress, function () {
error('Each child in a list should have a unique "key" prop.' + '%s%s See https://react.dev/link/warning-keys for more information.', currentComponentErrorInfo, childOwnerAppendix);
});
};
Expand Down Expand Up @@ -6329,7 +6323,7 @@ function createChildReconciler(shouldTrackSideEffects) {
*/


function warnOnInvalidKey(child, knownKeys, returnFiber) {
function warnOnInvalidKey(returnFiber, workInProgress, child, knownKeys) {
{
if (typeof child !== 'object' || child === null) {
return knownKeys;
Expand All @@ -6338,7 +6332,7 @@ function createChildReconciler(shouldTrackSideEffects) {
switch (child.$$typeof) {
case REACT_ELEMENT_TYPE:
case REACT_PORTAL_TYPE:
warnForMissingKey(child, returnFiber);
warnForMissingKey(returnFiber, workInProgress, child);
var key = child.key;

if (typeof key !== 'string') {
Expand All @@ -6356,8 +6350,9 @@ function createChildReconciler(shouldTrackSideEffects) {
break;
}

error('Encountered two children with the same key, `%s`. ' + 'Keys should be unique so that components maintain their identity ' + 'across updates. Non-unique keys may cause children to be ' + 'duplicated and/or omitted — the behavior is unsupported and ' + 'could change in a future version.', key);

runWithFiberInDEV(workInProgress, function () {
error('Encountered two children with the same key, `%s`. ' + 'Keys should be unique so that components maintain their identity ' + 'across updates. Non-unique keys may cause children to be ' + 'duplicated and/or omitted — the behavior is unsupported and ' + 'could change in a future version.', key);
});
break;

case REACT_LAZY_TYPE:
Expand All @@ -6368,7 +6363,7 @@ function createChildReconciler(shouldTrackSideEffects) {
resolvedChild = callLazyInitInDEV(child);
}

warnOnInvalidKey(resolvedChild, knownKeys, returnFiber);
warnOnInvalidKey(returnFiber, workInProgress, resolvedChild, knownKeys);
break;
}
}
Expand All @@ -6393,16 +6388,7 @@ function createChildReconciler(shouldTrackSideEffects) {
// (adding everything to a Map) in for every insert/move.
// If you change this code, also update reconcileChildrenIterator() which
// uses the same algorithm.
{
// First, validate keys.
var knownKeys = null;

for (var i = 0; i < newChildren.length; i++) {
var child = newChildren[i];
knownKeys = warnOnInvalidKey(child, knownKeys, returnFiber);
}
}

var knownKeys = null;
var resultingFirstChild = null;
var previousNewFiber = null;
var oldFiber = currentFirstChild;
Expand Down Expand Up @@ -6432,6 +6418,10 @@ function createChildReconciler(shouldTrackSideEffects) {
break;
}

{
knownKeys = warnOnInvalidKey(returnFiber, newFiber, newChildren[newIdx], knownKeys);
}

if (shouldTrackSideEffects) {
if (oldFiber && newFiber.alternate === null) {
// We matched the slot, but we didn't reuse the existing fiber, so we
Expand Down Expand Up @@ -6474,6 +6464,10 @@ function createChildReconciler(shouldTrackSideEffects) {
continue;
}

{
knownKeys = warnOnInvalidKey(returnFiber, _newFiber, newChildren[newIdx], knownKeys);
}

lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);

if (previousNewFiber === null) {
Expand All @@ -6496,6 +6490,10 @@ function createChildReconciler(shouldTrackSideEffects) {
var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], lanes, debugInfo);

if (_newFiber2 !== null) {
{
knownKeys = warnOnInvalidKey(returnFiber, _newFiber2, newChildren[newIdx], knownKeys);
}

if (shouldTrackSideEffects) {
if (_newFiber2.alternate !== null) {
// The new fiber is a work in progress, but if there exists a
Expand Down Expand Up @@ -6585,11 +6583,7 @@ function createChildReconciler(shouldTrackSideEffects) {
var knownKeys = null;
var step = newChildren.next();

{
knownKeys = warnOnInvalidKey(step.value, knownKeys, returnFiber);
}

for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next(), knownKeys = warnOnInvalidKey(step.value, knownKeys, returnFiber) ) {
for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {
if (oldFiber.index > newIdx) {
nextOldFiber = oldFiber;
oldFiber = null;
Expand All @@ -6611,6 +6605,10 @@ function createChildReconciler(shouldTrackSideEffects) {
break;
}

{
knownKeys = warnOnInvalidKey(returnFiber, newFiber, step.value, knownKeys);
}

if (shouldTrackSideEffects) {
if (oldFiber && newFiber.alternate === null) {
// We matched the slot, but we didn't reuse the existing fiber, so we
Expand Down Expand Up @@ -6646,13 +6644,17 @@ function createChildReconciler(shouldTrackSideEffects) {
if (oldFiber === null) {
// If we don't have any more existing children we can choose a fast path
// since the rest will all be insertions.
for (; !step.done; newIdx++, step = newChildren.next(), knownKeys = warnOnInvalidKey(step.value, knownKeys, returnFiber) ) {
for (; !step.done; newIdx++, step = newChildren.next()) {
var _newFiber3 = createChild(returnFiber, step.value, lanes, debugInfo);

if (_newFiber3 === null) {
continue;
}

{
knownKeys = warnOnInvalidKey(returnFiber, _newFiber3, step.value, knownKeys);
}

lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);

if (previousNewFiber === null) {
Expand All @@ -6671,10 +6673,14 @@ function createChildReconciler(shouldTrackSideEffects) {

var existingChildren = mapRemainingChildren(oldFiber); // Keep scanning and use the map to restore deleted items as moves.

for (; !step.done; newIdx++, step = newChildren.next(), knownKeys = warnOnInvalidKey(step.value, knownKeys, returnFiber) ) {
for (; !step.done; newIdx++, step = newChildren.next()) {
var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, lanes, debugInfo);

if (_newFiber4 !== null) {
{
knownKeys = warnOnInvalidKey(returnFiber, _newFiber4, step.value, knownKeys);
}

if (shouldTrackSideEffects) {
if (_newFiber4.alternate !== null) {
// The new fiber is a work in progress, but if there exists a
Expand Down Expand Up @@ -23580,7 +23586,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
return root;
}

var ReactVersion = '19.0.0-native-fb-0a5e0b0c2e-20240607';
var ReactVersion = '19.0.0-native-fb-20841f9a62-20240607';

/*
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<686c8c65b3c5a43aa1a8872c8cfe89a3>>
* @generated SignedSource<<a11af6f9b212cf2aeebb79b52de06240>>
*/

"use strict";
Expand Down Expand Up @@ -1975,7 +1975,7 @@ function createChildReconciler(shouldTrackSideEffects) {
nextOldFiber = null,
step = newChildren.next();
null !== oldFiber && !step.done;
newIdx++, step = newChildren.next(), null
newIdx++, step = newChildren.next()
) {
oldFiber.index > newIdx
? ((nextOldFiber = oldFiber), (oldFiber = null))
Expand All @@ -2001,7 +2001,7 @@ function createChildReconciler(shouldTrackSideEffects) {
deleteRemainingChildren(returnFiber, oldFiber), resultingFirstChild
);
if (null === oldFiber) {
for (; !step.done; newIdx++, step = newChildren.next(), null)
for (; !step.done; newIdx++, step = newChildren.next())
(step = createChild(returnFiber, step.value, lanes)),
null !== step &&
((currentFirstChild = placeChild(step, currentFirstChild, newIdx)),
Expand All @@ -2014,7 +2014,7 @@ function createChildReconciler(shouldTrackSideEffects) {
for (
oldFiber = mapRemainingChildren(oldFiber);
!step.done;
newIdx++, step = newChildren.next(), null
newIdx++, step = newChildren.next()
)
(step = updateFromMap(oldFiber, returnFiber, newIdx, step.value, lanes)),
null !== step &&
Expand Down Expand Up @@ -9336,7 +9336,7 @@ var devToolsConfig$jscomp$inline_1048 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "19.0.0-native-fb-0a5e0b0c2e-20240607",
version: "19.0.0-native-fb-20841f9a62-20240607",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1235 = {
Expand Down Expand Up @@ -9367,7 +9367,7 @@ var internals$jscomp$inline_1235 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-native-fb-0a5e0b0c2e-20240607"
reconcilerVersion: "19.0.0-native-fb-20841f9a62-20240607"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1236 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<275d830e3f5f7f8a5624cb71a826ce7e>>
* @generated SignedSource<<d5ac2136799fa3f299d972c903df46a7>>
*/

"use strict";
Expand Down Expand Up @@ -2063,7 +2063,7 @@ function createChildReconciler(shouldTrackSideEffects) {
nextOldFiber = null,
step = newChildren.next();
null !== oldFiber && !step.done;
newIdx++, step = newChildren.next(), null
newIdx++, step = newChildren.next()
) {
oldFiber.index > newIdx
? ((nextOldFiber = oldFiber), (oldFiber = null))
Expand All @@ -2089,7 +2089,7 @@ function createChildReconciler(shouldTrackSideEffects) {
deleteRemainingChildren(returnFiber, oldFiber), resultingFirstChild
);
if (null === oldFiber) {
for (; !step.done; newIdx++, step = newChildren.next(), null)
for (; !step.done; newIdx++, step = newChildren.next())
(step = createChild(returnFiber, step.value, lanes)),
null !== step &&
((currentFirstChild = placeChild(step, currentFirstChild, newIdx)),
Expand All @@ -2102,7 +2102,7 @@ function createChildReconciler(shouldTrackSideEffects) {
for (
oldFiber = mapRemainingChildren(oldFiber);
!step.done;
newIdx++, step = newChildren.next(), null
newIdx++, step = newChildren.next()
)
(step = updateFromMap(oldFiber, returnFiber, newIdx, step.value, lanes)),
null !== step &&
Expand Down Expand Up @@ -9958,7 +9958,7 @@ var devToolsConfig$jscomp$inline_1131 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "19.0.0-native-fb-0a5e0b0c2e-20240607",
version: "19.0.0-native-fb-20841f9a62-20240607",
rendererPackageName: "react-test-renderer"
};
(function (internals) {
Expand Down Expand Up @@ -10002,7 +10002,7 @@ var devToolsConfig$jscomp$inline_1131 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "19.0.0-native-fb-0a5e0b0c2e-20240607"
reconcilerVersion: "19.0.0-native-fb-20841f9a62-20240607"
});
exports._Scheduler = Scheduler;
exports.act = act;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<388ba1226b56953ba4b069bec36aa5ee>>
* @generated SignedSource<<ff060bbd88a6beeead57e84d35a86af9>>
*/

'use strict';
Expand All @@ -24,7 +24,7 @@ if (
}
var dynamicFlagsUntyped = require('ReactNativeInternalFeatureFlags');

var ReactVersion = '19.0.0-native-fb-0a5e0b0c2e-20240607';
var ReactVersion = '19.0.0-native-fb-20841f9a62-20240607';

// Re-export dynamic flags from the internal module.
var dynamicFlags = dynamicFlagsUntyped; // We destructure each value before re-exporting to avoid a dynamic look-up on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<00d12dd76f3b7ce5e22c6db377b2aefe>>
* @generated SignedSource<<2ffd656ec0297ecbc31dc231e472fdcc>>
*/

"use strict";
Expand Down Expand Up @@ -604,4 +604,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-0a5e0b0c2e-20240607";
exports.version = "19.0.0-native-fb-20841f9a62-20240607";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<afdf4890e7b39e7a9b5fff59a0f258ea>>
* @generated SignedSource<<f0f71fc7f22a13063a2728358a9bb19f>>
*/

"use strict";
Expand Down Expand Up @@ -608,7 +608,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-0a5e0b0c2e-20240607";
exports.version = "19.0.0-native-fb-20841f9a62-20240607";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0a5e0b0c2e496f335136c34663e8763cfa160b82
20841f9a6205a633e6d08a274db974481daaca23
Loading

0 comments on commit 3ffc777

Please sign in to comment.