Home / Function/ areArgumentsImmutableAndNonMutating() — react Function Reference

areArgumentsImmutableAndNonMutating() — react Function Reference

Architecture documentation for the areArgumentsImmutableAndNonMutating() function in InferMutationAliasingEffects.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  10386ad8_f999_3e46_b390_aba6afce2aec["areArgumentsImmutableAndNonMutating()"]
  d24875c3_c045_4414_2cc9_16f96d59c629["InferMutationAliasingEffects.ts"]
  10386ad8_f999_3e46_b390_aba6afce2aec -->|defined in| d24875c3_c045_4414_2cc9_16f96d59c629
  fc22e84f_49a6_8d04_faba_43cbf926c0aa["computeEffectsForLegacySignature()"]
  fc22e84f_49a6_8d04_faba_43cbf926c0aa -->|calls| 10386ad8_f999_3e46_b390_aba6afce2aec
  2ac23db5_db05_5656_41fc_d176ddafebe2["isKnownMutableEffect()"]
  10386ad8_f999_3e46_b390_aba6afce2aec -->|calls| 2ac23db5_db05_5656_41fc_d176ddafebe2
  8f06f55e_0851_0d44_0a89_d6dee31fdbb5["kind()"]
  10386ad8_f999_3e46_b390_aba6afce2aec -->|calls| 8f06f55e_0851_0d44_0a89_d6dee31fdbb5
  bcbdcfbc_a2a4_dd2d_09f6_b6643e95eb6e["values()"]
  10386ad8_f999_3e46_b390_aba6afce2aec -->|calls| bcbdcfbc_a2a4_dd2d_09f6_b6643e95eb6e
  style 10386ad8_f999_3e46_b390_aba6afce2aec fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 2506–2561

function areArgumentsImmutableAndNonMutating(
  state: InferenceState,
  args: Array<Place | SpreadPattern | Hole>,
): boolean {
  for (const arg of args) {
    if (arg.kind === 'Hole') {
      continue;
    }
    if (arg.kind === 'Identifier' && arg.identifier.type.kind === 'Function') {
      const fnShape = state.env.getFunctionSignature(arg.identifier.type);
      if (fnShape != null) {
        return (
          !fnShape.positionalParams.some(isKnownMutableEffect) &&
          (fnShape.restParam == null ||
            !isKnownMutableEffect(fnShape.restParam))
        );
      }
    }
    const place = arg.kind === 'Identifier' ? arg : arg.place;

    const kind = state.kind(place).kind;
    switch (kind) {
      case ValueKind.Primitive:
      case ValueKind.Frozen: {
        /*
         * Only immutable values, or frozen lambdas are allowed.
         * A lambda may appear frozen even if it may mutate its inputs,
         * so we have a second check even for frozen value types
         */
        break;
      }
      default: {
        /**
         * Globals, module locals, and other locally defined functions may
         * mutate their arguments.
         */
        return false;
      }
    }
    const values = state.values(place);
    for (const value of values) {
      if (
        value.kind === 'FunctionExpression' &&
        value.loweredFunc.func.params.some(param => {
          const place = param.kind === 'Identifier' ? param : param.place;
          const range = place.identifier.mutableRange;
          return range.end > range.start + 1;
        })
      ) {
        // This is a function which may mutate its inputs
        return false;
      }
    }
  }
  return true;
}

Domain

Subdomains

Frequently Asked Questions

What does areArgumentsImmutableAndNonMutating() do?
areArgumentsImmutableAndNonMutating() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is areArgumentsImmutableAndNonMutating() defined?
areArgumentsImmutableAndNonMutating() is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 2506.
What does areArgumentsImmutableAndNonMutating() call?
areArgumentsImmutableAndNonMutating() calls 3 function(s): isKnownMutableEffect, kind, values.
What calls areArgumentsImmutableAndNonMutating()?
areArgumentsImmutableAndNonMutating() is called by 1 function(s): computeEffectsForLegacySignature.

Analyze Your Own Codebase

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

Try Supermodel Free