Skip to content

Commit 7f9b639

Browse files
committed
[compiler][optim] Add Effect.ConditionallyMutateIterator (#32698)
Adds Effect.ConditionallyMutateIterator, which has the following effects: - capture for known array, map, and sets - mutate for all other values An alternative to this approach could be to add polymorphic shape definitions DiffTrain build for [7c908bc](7c908bc)
1 parent 9744c3a commit 7f9b639

35 files changed

Lines changed: 134 additions & 97 deletions

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

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16938,6 +16938,7 @@ var Effect;
1693816938
Effect["Freeze"] = "freeze";
1693916939
Effect["Read"] = "read";
1694016940
Effect["Capture"] = "capture";
16941+
Effect["ConditionallyMutateIterator"] = "mutate-iterator?";
1694116942
Effect["ConditionallyMutate"] = "mutate?";
1694216943
Effect["Mutate"] = "mutate";
1694316944
Effect["Store"] = "store";
@@ -16946,6 +16947,7 @@ const EffectSchema = zod.z.enum([
1694616947
Effect.Read,
1694716948
Effect.Mutate,
1694816949
Effect.ConditionallyMutate,
16950+
Effect.ConditionallyMutateIterator,
1694916951
Effect.Capture,
1695016952
Effect.Store,
1695116953
Effect.Freeze,
@@ -16955,6 +16957,7 @@ function isMutableEffect(effect, location) {
1695516957
case Effect.Capture:
1695616958
case Effect.Store:
1695716959
case Effect.ConditionallyMutate:
16960+
case Effect.ConditionallyMutateIterator:
1695816961
case Effect.Mutate: {
1695916962
return true;
1696016963
}
@@ -17049,6 +17052,12 @@ function isPrimitiveType(id) {
1704917052
function isArrayType(id) {
1705017053
return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInArray';
1705117054
}
17055+
function isMapType(id) {
17056+
return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInMap';
17057+
}
17058+
function isSetType(id) {
17059+
return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInSet';
17060+
}
1705217061
function isPropsType(id) {
1705317062
return id.type.kind === 'Object' && id.type.shapeId === 'BuiltInProps';
1705417063
}
@@ -36491,8 +36500,6 @@ const UNTYPED_GLOBALS = new Set([
3649136500
'Int8Array',
3649236501
'Int16Array',
3649336502
'Int32Array',
36494-
'Map',
36495-
'Set',
3649636503
'WeakMap',
3649736504
'Uint8Array',
3649836505
'Uint8ClampedArray',
@@ -36546,7 +36553,7 @@ const TYPED_GLOBALS = [
3654636553
'from',
3654736554
addFunction(DEFAULT_SHAPES, [], {
3654836555
positionalParams: [
36549-
Effect.ConditionallyMutate,
36556+
Effect.ConditionallyMutateIterator,
3655036557
Effect.ConditionallyMutate,
3655136558
Effect.ConditionallyMutate,
3655236559
],
@@ -36860,7 +36867,7 @@ const TYPED_GLOBALS = [
3686036867
[
3686136868
'Map',
3686236869
addFunction(DEFAULT_SHAPES, [], {
36863-
positionalParams: [Effect.ConditionallyMutate],
36870+
positionalParams: [Effect.ConditionallyMutateIterator],
3686436871
restParam: null,
3686536872
returnType: { kind: 'Object', shapeId: BuiltInMapId },
3686636873
calleeEffect: Effect.Read,
@@ -36870,7 +36877,7 @@ const TYPED_GLOBALS = [
3687036877
[
3687136878
'Set',
3687236879
addFunction(DEFAULT_SHAPES, [], {
36873-
positionalParams: [Effect.ConditionallyMutate],
36880+
positionalParams: [Effect.ConditionallyMutateIterator],
3687436881
restParam: null,
3687536882
returnType: { kind: 'Object', shapeId: BuiltInSetId },
3687636883
calleeEffect: Effect.Read,
@@ -45290,6 +45297,23 @@ class InferenceState {
4529045297
}
4529145298
break;
4529245299
}
45300+
case Effect.ConditionallyMutateIterator: {
45301+
if (valueKind.kind === ValueKind.Mutable ||
45302+
valueKind.kind === ValueKind.Context) {
45303+
if (isArrayType(place.identifier) ||
45304+
isSetType(place.identifier) ||
45305+
isMapType(place.identifier)) {
45306+
effect = Effect.Capture;
45307+
}
45308+
else {
45309+
effect = Effect.ConditionallyMutate;
45310+
}
45311+
}
45312+
else {
45313+
effect = Effect.Read;
45314+
}
45315+
break;
45316+
}
4529345317
case Effect.Mutate: {
4529445318
effect = Effect.Mutate;
4529545319
break;
@@ -45554,9 +45578,7 @@ function inferBlock(env, state, block, functionEffects) {
4555445578
};
4555545579
for (const element of instrValue.elements) {
4555645580
if (element.kind === 'Spread') {
45557-
state.referenceAndRecordEffects(freezeActions, element.place, isArrayType(element.place.identifier)
45558-
? Effect.Capture
45559-
: Effect.ConditionallyMutate, ValueReason.Other);
45581+
state.referenceAndRecordEffects(freezeActions, element.place, Effect.ConditionallyMutateIterator, ValueReason.Other);
4556045582
}
4556145583
else if (element.kind === 'Identifier') {
4556245584
state.referenceAndRecordEffects(freezeActions, element, Effect.Capture, ValueReason.Other);
@@ -46038,7 +46060,11 @@ function inferBlock(env, state, block, functionEffects) {
4603846060
const isMutable = kind === ValueKind.Mutable || kind === ValueKind.Context;
4603946061
let effect;
4604046062
let valueKind;
46041-
if (!isMutable || isArrayType(instrValue.collection.identifier)) {
46063+
const iterator = instrValue.collection.identifier;
46064+
if (!isMutable ||
46065+
isArrayType(iterator) ||
46066+
isMapType(iterator) ||
46067+
isSetType(iterator)) {
4604246068
effect = {
4604346069
kind: Effect.Read,
4604446070
reason: ValueReason.Other,
@@ -46065,7 +46091,7 @@ function inferBlock(env, state, block, functionEffects) {
4606546091
break;
4606646092
}
4606746093
case 'IteratorNext': {
46068-
state.referenceAndRecordEffects(freezeActions, instrValue.iterator, Effect.ConditionallyMutate, ValueReason.Other);
46094+
state.referenceAndRecordEffects(freezeActions, instrValue.iterator, Effect.ConditionallyMutateIterator, ValueReason.Other);
4606946095
state.referenceAndRecordEffects(freezeActions, instrValue.collection, Effect.Capture, ValueReason.Other);
4607046096
state.initialize(instrValue, state.kind(instrValue.collection));
4607146097
state.define(instr.lvalue, instrValue);
@@ -46168,6 +46194,7 @@ function isKnownMutableEffect(effect) {
4616846194
switch (effect) {
4616946195
case Effect.Store:
4617046196
case Effect.ConditionallyMutate:
46197+
case Effect.ConditionallyMutateIterator:
4617146198
case Effect.Mutate: {
4617246199
return true;
4617346200
}
@@ -46240,7 +46267,7 @@ function getArgumentEffect(signatureEffect, arg) {
4624046267
loc: arg.place.loc,
4624146268
});
4624246269
}
46243-
return Effect.ConditionallyMutate;
46270+
return Effect.ConditionallyMutateIterator;
4624446271
}
4624546272
}
4624646273
else {
@@ -47432,6 +47459,15 @@ function inferPlace(place, instrId, inferMutableRangeForStores) {
4743247459
infer$1(place, instrId);
4743347460
}
4743447461
return;
47462+
case Effect.ConditionallyMutateIterator: {
47463+
const identifier = place.identifier;
47464+
if (!isArrayType(identifier) &&
47465+
!isSetType(identifier) &&
47466+
!isMapType(identifier)) {
47467+
infer$1(place, instrId);
47468+
}
47469+
return;
47470+
}
4743547471
case Effect.ConditionallyMutate:
4743647472
case Effect.Mutate: {
4743747473
infer$1(place, instrId);
@@ -48047,6 +48083,7 @@ function inferReactivePlaces(fn) {
4804748083
case Effect.Capture:
4804848084
case Effect.Store:
4804948085
case Effect.ConditionallyMutate:
48086+
case Effect.ConditionallyMutateIterator:
4805048087
case Effect.Mutate: {
4805148088
if (isMutable(instruction, operand)) {
4805248089
reactiveIdentifiers.markReactive(operand);

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a8e503dce0ec386eef752a1219dd6ef861c48ced
1+
7c908bcf4e6b46135164be961972f0d756378517
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a8e503dce0ec386eef752a1219dd6ef861c48ced
1+
7c908bcf4e6b46135164be961972f0d756378517

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ __DEV__ &&
15371537
exports.useTransition = function () {
15381538
return resolveDispatcher().useTransition();
15391539
};
1540-
exports.version = "19.1.0-www-classic-a8e503dc-20250323";
1540+
exports.version = "19.1.0-www-classic-7c908bcf-20250323";
15411541
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15421542
"function" ===
15431543
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
@@ -1537,7 +1537,7 @@ __DEV__ &&
15371537
exports.useTransition = function () {
15381538
return resolveDispatcher().useTransition();
15391539
};
1540-
exports.version = "19.1.0-www-modern-a8e503dc-20250323";
1540+
exports.version = "19.1.0-www-modern-7c908bcf-20250323";
15411541
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15421542
"function" ===
15431543
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-a8e503dc-20250323";
644+
exports.version = "19.1.0-www-classic-7c908bcf-20250323";

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-a8e503dc-20250323";
644+
exports.version = "19.1.0-www-modern-7c908bcf-20250323";

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-a8e503dc-20250323";
648+
exports.version = "19.1.0-www-classic-7c908bcf-20250323";
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-a8e503dc-20250323";
648+
exports.version = "19.1.0-www-modern-7c908bcf-20250323";
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
@@ -18483,10 +18483,10 @@ __DEV__ &&
1848318483
(function () {
1848418484
var internals = {
1848518485
bundleType: 1,
18486-
version: "19.1.0-www-classic-a8e503dc-20250323",
18486+
version: "19.1.0-www-classic-7c908bcf-20250323",
1848718487
rendererPackageName: "react-art",
1848818488
currentDispatcherRef: ReactSharedInternals,
18489-
reconcilerVersion: "19.1.0-www-classic-a8e503dc-20250323"
18489+
reconcilerVersion: "19.1.0-www-classic-7c908bcf-20250323"
1849018490
};
1849118491
internals.overrideHookState = overrideHookState;
1849218492
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -18520,7 +18520,7 @@ __DEV__ &&
1852018520
exports.Shape = Shape;
1852118521
exports.Surface = Surface;
1852218522
exports.Text = Text;
18523-
exports.version = "19.1.0-www-classic-a8e503dc-20250323";
18523+
exports.version = "19.1.0-www-classic-7c908bcf-20250323";
1852418524
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
1852518525
"function" ===
1852618526
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)