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

Code before:
    value: {
      kind: 'LoadLocal',
      place: {
        kind: 'Identifier',
        identifier: dep.identifier,
        effect: Effect.Capture,
        reactive,
        loc: loc,
      },
      loc: loc,
    },
  });
  for (const path of dep.path) {
    if (path.optional) {
      /**
       * TODO: instead of truncating optional paths, reuse
       * instructions from hoisted dependencies block(s)
       */
      break;
    }
    if (path.property === 'current') {
      /*
       * Prune ref.current accesses. This may over-capture for non-ref values with
       * a current property, but that's fine.
       */
      currValue.effect = Effect.Freeze;
      break;
    }
    const nextValue = createTemporaryPlace(env, GeneratedSource);
    nextValue.reactive = reactive;
    instructions.push({
      id: makeInstructionId(0),
      loc: GeneratedSource,
      lvalue: {...nextValue, effect: Effect.Mutate},
      value: {
        kind: 'PropertyLoad',
        object: {...currValue, effect: Effect.Capture},
        property: path.property,
        loc: loc,
      },
    });
    currValue = nextValue;
  }
  currValue.effect = Effect.Freeze;
  return {place: currValue, instructions};
}

function inferReactiveIdentifiers(fn: HIRFunction): Set<IdentifierId> {
  const reactiveIds: Set<IdentifierId> = new Set();
  for (const [, block] of fn.body.blocks) {
    for (const instr of block.instructions) {

Review comment (suggestion):
i haven't followed the implementation of auto-deps, but why are we changing the effects here? if we're pruning i'd expect that to be operating on the dependency path but not changing effects, which should have already been inferred.

Code after:
    value: {
      kind: 'LoadLocal',
      place: {
        kind: 'Identifier',
        identifier: dep.identifier,
        effect: Effect.Capture,
        reactive,
        loc: loc,
      },
      loc: loc,
    },
  });
  for (const path of dep.path) {
    if (path.optional) {
      /**
       * TODO: instead of truncating optional paths, reuse
       * instructions from hoisted dependencies block(s)
       */
      break;
    }
    if (path.property === 'current') {
      /*
       * Prune ref.current accesses. This may over-capture for non-ref values with
       * a current property, but that's fine.
       */
      break;
    }
    const nextValue = createTemporaryPlace(env, GeneratedSource);
    nextValue.reactive = reactive;
    instructions.push({
      id: makeInstructionId(0),
      loc: GeneratedSource,
      lvalue: {...nextValue, effect: Effect.Mutate},
      value: {
        kind: 'PropertyLoad',
        object: {...currValue, effect: Effect.Capture},
        property: path.property,
        loc: loc,
      },
    });
    currValue = nextValue;
  }
  currValue.effect = Effect.Freeze;
  return {place: currValue, instructions};
}

function inferReactiveIdentifiers(fn: HIRFunction): Set<IdentifierId> {
  const reactiveIds: Set<IdentifierId> = new Set();
  for (const [, block] of fn.body.blocks) {
    for (const instr of block.instructions) {
      /**