Repository: facebook/react
File: compiler/packages/babel-plugin-react-compiler/src/Inference/InferReferenceEffects.ts (TypeScript)

Code before:
                    ValueReason.KnownReturnSignature,
                ]),
                context: new Set(),
              }
            : {
                kind: ValueKind.Mutable,
                reason: new Set([ValueReason.Other]),
                context: new Set(),
              };

        if (
          signature !== null &&
          signature.mutableOnlyIfOperandsAreMutable &&
          areArgumentsImmutableAndNonMutating(state, instrValue.args)
        ) {
          /*
           * None of the args are mutable or mutate their params, we can downgrade to
           * treating as all reads (except that the receiver may be captured)
           */
          for (const arg of instrValue.args) {
            const place = arg.kind === 'Identifier' ? arg : arg.place;
            state.referenceAndRecordEffects(
              freezeActions,
              place,
              // see call-spread-argument-mutable-iterator test fixture
              arg.kind === 'Spread' ? Effect.ConditionallyMutate : Effect.Read,
              ValueReason.Other,
            );
          }
          state.referenceAndRecordEffects(
            freezeActions,
            instrValue.receiver,
            Effect.Capture,
            ValueReason.Other,
          );
          state.initialize(instrValue, returnValueKind);
          state.define(instr.lvalue, instrValue);
          instr.lvalue.effect =
            instrValue.receiver.effect === Effect.Capture
              ? Effect.Store
              : Effect.ConditionallyMutate;
          continuation = {kind: 'funeffects'};
          break;
        }

        const effects =
          signature !== null ? getFunctionEffects(instrValue, signature) : null;
        let hasCaptureArgument = false;
        for (let i = 0; i < instrValue.args.length; i++) {
          const arg = instrValue.args[i];
          const place = arg.kind === 'Identifier' ? arg : arg.place;

Review comment (suggestion):
hmm this doesn't seem like it should be necessary - we're inside an `if (areArgumentsImmutableAndNonMutating())` check

Code after:
                reason: new Set([
                  signature.returnValueReason ??
                    ValueReason.KnownReturnSignature,
                ]),
                context: new Set(),
              }
            : {
                kind: ValueKind.Mutable,
                reason: new Set([ValueReason.Other]),
                context: new Set(),
              };

        if (
          signature !== null &&
          signature.mutableOnlyIfOperandsAreMutable &&
          areArgumentsImmutableAndNonMutating(state, instrValue.args)
        ) {
          /*
           * None of the args are mutable or mutate their params, we can downgrade to
           * treating as all reads (except that the receiver may be captured)
           */
          for (const arg of instrValue.args) {
            const place = arg.kind === 'Identifier' ? arg : arg.place;
            state.referenceAndRecordEffects(
              freezeActions,
              place,
              Effect.Read,
              ValueReason.Other,
            );
          }
          state.referenceAndRecordEffects(
            freezeActions,
            instrValue.receiver,
            Effect.Capture,
            ValueReason.Other,
          );
          state.initialize(instrValue, returnValueKind);
          state.define(instr.lvalue, instrValue);
          instr.lvalue.effect =
            instrValue.receiver.effect === Effect.Capture
              ? Effect.Store
              : Effect.ConditionallyMutate;
          continuation = {kind: 'funeffects'};
          break;
        }

        const effects =
          signature !== null ? getFunctionEffects(instrValue, signature) : null;
        let hasCaptureArgument = false;
        for (let i = 0; i < instrValue.args.length; i++) {
          const arg = instrValue.args[i];