Skip to content

Commit 8a728a1

Browse files
committed
[compiler] Patch array and argument spread mutability (#32521)
Array and argument spreads may mutate stateful iterables. Spread sites should have `ConditionallyMutate` effects (e.g. mutate if the ValueKind is mutable, otherwise read). See - [ecma spec (13.2.4.1 Runtime Semantics: ArrayAccumulation. SpreadElement : ... AssignmentExpression)](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-runtime-semantics-arrayaccumulation). - [ecma spec 13.3.8.1 Runtime Semantics: ArgumentListEvaluation](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-runtime-semantics-argumentlistevaluation) Note that - Object and JSX Attribute spreads do not evaluate iterables (srcs [mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#description), [ecma](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-runtime-semantics-propertydefinitionevaluation)) - An ideal mutability inference system could model known collections (i.e. Arrays or Sets) as a "mutated collection of non-mutable objects" (see `todo-granular-iterator-semantics`), but this is not what we do today. As such, an array / argument spread will always extend the range of built-in arrays, sets, etc - Due to HIR limitations, call expressions with argument spreads may cause unnecessary bailouts and/or scope merging when we know the call itself has `freeze`, `capture`, or `read` semantics (e.g. `useHook(...mutableValue)`) We can deal with this by rewriting these call instructions to (1) create an intermediate array to consume the iterator and (2) capture and spread the array at the callsite --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32521). * #32596 * #32595 * #32594 * #32593 * #32522 * __->__ #32521 DiffTrain build for [ed1264f](ed1264f)
1 parent bb873cb commit 8a728a1

33 files changed

+84
-98
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ __DEV__ &&
15321532
exports.useTransition = function () {
15331533
return resolveDispatcher().useTransition();
15341534
};
1535-
exports.version = "19.1.0-www-classic-38a76009-20250313";
1535+
exports.version = "19.1.0-www-classic-ed1264f0-20250313";
15361536
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15371537
"function" ===
15381538
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
@@ -1532,7 +1532,7 @@ __DEV__ &&
15321532
exports.useTransition = function () {
15331533
return resolveDispatcher().useTransition();
15341534
};
1535-
exports.version = "19.1.0-www-modern-38a76009-20250313";
1535+
exports.version = "19.1.0-www-modern-ed1264f0-20250313";
15361536
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15371537
"function" ===
15381538
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-38a76009-20250313";
644+
exports.version = "19.1.0-www-classic-ed1264f0-20250313";

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-38a76009-20250313";
644+
exports.version = "19.1.0-www-modern-ed1264f0-20250313";

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-38a76009-20250313";
648+
exports.version = "19.1.0-www-classic-ed1264f0-20250313";
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-38a76009-20250313";
648+
exports.version = "19.1.0-www-modern-ed1264f0-20250313";
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
@@ -18546,10 +18546,10 @@ __DEV__ &&
1854618546
(function () {
1854718547
var internals = {
1854818548
bundleType: 1,
18549-
version: "19.1.0-www-classic-38a76009-20250313",
18549+
version: "19.1.0-www-classic-ed1264f0-20250313",
1855018550
rendererPackageName: "react-art",
1855118551
currentDispatcherRef: ReactSharedInternals,
18552-
reconcilerVersion: "19.1.0-www-classic-38a76009-20250313"
18552+
reconcilerVersion: "19.1.0-www-classic-ed1264f0-20250313"
1855318553
};
1855418554
internals.overrideHookState = overrideHookState;
1855518555
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -18583,7 +18583,7 @@ __DEV__ &&
1858318583
exports.Shape = Shape;
1858418584
exports.Surface = Surface;
1858518585
exports.Text = Text;
18586-
exports.version = "19.1.0-www-classic-38a76009-20250313";
18586+
exports.version = "19.1.0-www-classic-ed1264f0-20250313";
1858718587
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1858818588
"function" ===
1858918589
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18318,10 +18318,10 @@ __DEV__ &&
1831818318
(function () {
1831918319
var internals = {
1832018320
bundleType: 1,
18321-
version: "19.1.0-www-modern-38a76009-20250313",
18321+
version: "19.1.0-www-modern-ed1264f0-20250313",
1832218322
rendererPackageName: "react-art",
1832318323
currentDispatcherRef: ReactSharedInternals,
18324-
reconcilerVersion: "19.1.0-www-modern-38a76009-20250313"
18324+
reconcilerVersion: "19.1.0-www-modern-ed1264f0-20250313"
1832518325
};
1832618326
internals.overrideHookState = overrideHookState;
1832718327
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -18355,7 +18355,7 @@ __DEV__ &&
1835518355
exports.Shape = Shape;
1835618356
exports.Surface = Surface;
1835718357
exports.Text = Text;
18358-
exports.version = "19.1.0-www-modern-38a76009-20250313";
18358+
exports.version = "19.1.0-www-modern-ed1264f0-20250313";
1835918359
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1836018360
"function" ===
1836118361
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11341,10 +11341,10 @@ var slice = Array.prototype.slice,
1134111341
})(React.Component);
1134211342
var internals$jscomp$inline_1587 = {
1134311343
bundleType: 0,
11344-
version: "19.1.0-www-classic-38a76009-20250313",
11344+
version: "19.1.0-www-classic-ed1264f0-20250313",
1134511345
rendererPackageName: "react-art",
1134611346
currentDispatcherRef: ReactSharedInternals,
11347-
reconcilerVersion: "19.1.0-www-classic-38a76009-20250313"
11347+
reconcilerVersion: "19.1.0-www-classic-ed1264f0-20250313"
1134811348
};
1134911349
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1135011350
var hook$jscomp$inline_1588 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -11370,4 +11370,4 @@ exports.RadialGradient = RadialGradient;
1137011370
exports.Shape = TYPES.SHAPE;
1137111371
exports.Surface = Surface;
1137211372
exports.Text = Text;
11373-
exports.version = "19.1.0-www-classic-38a76009-20250313";
11373+
exports.version = "19.1.0-www-classic-ed1264f0-20250313";

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11056,10 +11056,10 @@ var slice = Array.prototype.slice,
1105611056
})(React.Component);
1105711057
var internals$jscomp$inline_1560 = {
1105811058
bundleType: 0,
11059-
version: "19.1.0-www-modern-38a76009-20250313",
11059+
version: "19.1.0-www-modern-ed1264f0-20250313",
1106011060
rendererPackageName: "react-art",
1106111061
currentDispatcherRef: ReactSharedInternals,
11062-
reconcilerVersion: "19.1.0-www-modern-38a76009-20250313"
11062+
reconcilerVersion: "19.1.0-www-modern-ed1264f0-20250313"
1106311063
};
1106411064
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1106511065
var hook$jscomp$inline_1561 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -11085,4 +11085,4 @@ exports.RadialGradient = RadialGradient;
1108511085
exports.Shape = TYPES.SHAPE;
1108611086
exports.Surface = Surface;
1108711087
exports.Text = Text;
11088-
exports.version = "19.1.0-www-modern-38a76009-20250313";
11088+
exports.version = "19.1.0-www-modern-ed1264f0-20250313";

0 commit comments

Comments
 (0)