Home / Function/ getSetStateCall() — react Function Reference

getSetStateCall() — react Function Reference

Architecture documentation for the getSetStateCall() function in ValidateNoSetStateInEffects.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  3b48551f_7fdf_a2e3_1a73_61107c6532fd["getSetStateCall()"]
  71d73648_b3a1_c2f2_a010_106a2a2c80f6["ValidateNoSetStateInEffects.ts"]
  3b48551f_7fdf_a2e3_1a73_61107c6532fd -->|defined in| 71d73648_b3a1_c2f2_a010_106a2a2c80f6
  9122e965_d8f6_df86_dd39_3a5721b58d49["validateNoSetStateInEffects()"]
  9122e965_d8f6_df86_dd39_3a5721b58d49 -->|calls| 3b48551f_7fdf_a2e3_1a73_61107c6532fd
  1c6dc7ec_72e1_b907_d23f_94b6a80c2a2d["createControlDominators()"]
  3b48551f_7fdf_a2e3_1a73_61107c6532fd -->|calls| 1c6dc7ec_72e1_b907_d23f_94b6a80c2a2d
  527555c0_9544_ae6b_5f83_952272d2caa1["Iterable_some()"]
  3b48551f_7fdf_a2e3_1a73_61107c6532fd -->|calls| 527555c0_9544_ae6b_5f83_952272d2caa1
  b2fc2985_a7ba_9865_c2a3_2a7531f27d44["eachInstructionValueOperand()"]
  3b48551f_7fdf_a2e3_1a73_61107c6532fd -->|calls| b2fc2985_a7ba_9865_c2a3_2a7531f27d44
  10043bf1_f7ee_9ed9_307a_fe3edfd02b09["eachInstructionLValue()"]
  3b48551f_7fdf_a2e3_1a73_61107c6532fd -->|calls| 10043bf1_f7ee_9ed9_307a_fe3edfd02b09
  11746e9a_2fdf_98bb_bb3c_a63d8b200df2["isMutable()"]
  3b48551f_7fdf_a2e3_1a73_61107c6532fd -->|calls| 11746e9a_2fdf_98bb_bb3c_a63d8b200df2
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  3b48551f_7fdf_a2e3_1a73_61107c6532fd -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"]
  3b48551f_7fdf_a2e3_1a73_61107c6532fd -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6
  style 3b48551f_7fdf_a2e3_1a73_61107c6532fd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts lines 188–347

function getSetStateCall(
  fn: HIRFunction,
  setStateFunctions: Map<IdentifierId, Place>,
  env: Environment,
): Place | null {
  const enableAllowSetStateFromRefsInEffects =
    env.config.enableAllowSetStateFromRefsInEffects;
  const refDerivedValues: Set<IdentifierId> = new Set();

  const isDerivedFromRef = (place: Place): boolean => {
    return (
      refDerivedValues.has(place.identifier.id) ||
      isUseRefType(place.identifier) ||
      isRefValueType(place.identifier)
    );
  };

  const isRefControlledBlock: (id: BlockId) => boolean =
    enableAllowSetStateFromRefsInEffects
      ? createControlDominators(fn, place => isDerivedFromRef(place))
      : (): boolean => false;

  for (const [, block] of fn.body.blocks) {
    if (enableAllowSetStateFromRefsInEffects) {
      for (const phi of block.phis) {
        if (isDerivedFromRef(phi.place)) {
          continue;
        }
        let isPhiDerivedFromRef = false;
        for (const [, operand] of phi.operands) {
          if (isDerivedFromRef(operand)) {
            isPhiDerivedFromRef = true;
            break;
          }
        }
        if (isPhiDerivedFromRef) {
          refDerivedValues.add(phi.place.identifier.id);
        } else {
          for (const [pred] of phi.operands) {
            if (isRefControlledBlock(pred)) {
              refDerivedValues.add(phi.place.identifier.id);
              break;
            }
          }
        }
      }
    }
    for (const instr of block.instructions) {
      if (enableAllowSetStateFromRefsInEffects) {
        const hasRefOperand = Iterable_some(
          eachInstructionValueOperand(instr.value),
          isDerivedFromRef,
        );

        if (hasRefOperand) {
          for (const lvalue of eachInstructionLValue(instr)) {
            refDerivedValues.add(lvalue.identifier.id);
          }
          // Ref-derived values can also propagate through mutation
          for (const operand of eachInstructionValueOperand(instr.value)) {
            switch (operand.effect) {
              case Effect.Capture:
              case Effect.Store:
              case Effect.ConditionallyMutate:
              case Effect.ConditionallyMutateIterator:
              case Effect.Mutate: {
                if (isMutable(instr, operand)) {
                  refDerivedValues.add(operand.identifier.id);
                }
                break;
              }
              case Effect.Freeze:
              case Effect.Read: {
                // no-op
                break;
              }
              case Effect.Unknown: {
                CompilerError.invariant(false, {
                  reason: 'Unexpected unknown effect',
                  loc: operand.loc,
                });

Domain

Subdomains

Frequently Asked Questions

What does getSetStateCall() do?
getSetStateCall() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts.
Where is getSetStateCall() defined?
getSetStateCall() is defined in compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts at line 188.
What does getSetStateCall() call?
getSetStateCall() calls 7 function(s): Iterable_some, assertExhaustive, createControlDominators, eachInstructionLValue, eachInstructionValueOperand, invariant, isMutable.
What calls getSetStateCall()?
getSetStateCall() is called by 1 function(s): validateNoSetStateInEffects.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free