Home / Class/ Context Class — react Architecture

Context Class — react Architecture

Architecture documentation for the Context class in InferMutationAliasingEffects.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  0e22a644_fb0d_df7b_1432_f6d30878a62a["Context"]
  d24875c3_c045_4414_2cc9_16f96d59c629["InferMutationAliasingEffects.ts"]
  0e22a644_fb0d_df7b_1432_f6d30878a62a -->|defined in| d24875c3_c045_4414_2cc9_16f96d59c629
  d0aec9b8_4c63_724a_9e22_c098b94d3c76["constructor()"]
  0e22a644_fb0d_df7b_1432_f6d30878a62a -->|method| d0aec9b8_4c63_724a_9e22_c098b94d3c76
  86dd37df_aa77_e57f_86b5_809912afc646["cacheApplySignature()"]
  0e22a644_fb0d_df7b_1432_f6d30878a62a -->|method| 86dd37df_aa77_e57f_86b5_809912afc646
  97fe1d23_4f7c_ef28_ca5a_de2c6e376163["internEffect()"]
  0e22a644_fb0d_df7b_1432_f6d30878a62a -->|method| 97fe1d23_4f7c_ef28_ca5a_de2c6e376163

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts lines 263–314

class Context {
  internedEffects: Map<string, AliasingEffect> = new Map();
  instructionSignatureCache: Map<Instruction, InstructionSignature> = new Map();
  effectInstructionValueCache: Map<AliasingEffect, InstructionValue> =
    new Map();
  applySignatureCache: Map<
    AliasingSignature,
    Map<AliasingEffect, Array<AliasingEffect> | null>
  > = new Map();
  catchHandlers: Map<BlockId, Place> = new Map();
  functionSignatureCache: Map<FunctionExpression, AliasingSignature> =
    new Map();
  isFuctionExpression: boolean;
  fn: HIRFunction;
  hoistedContextDeclarations: Map<DeclarationId, Place | null>;
  nonMutatingSpreads: Set<IdentifierId>;

  constructor(
    isFunctionExpression: boolean,
    fn: HIRFunction,
    hoistedContextDeclarations: Map<DeclarationId, Place | null>,
    nonMutatingSpreads: Set<IdentifierId>,
  ) {
    this.isFuctionExpression = isFunctionExpression;
    this.fn = fn;
    this.hoistedContextDeclarations = hoistedContextDeclarations;
    this.nonMutatingSpreads = nonMutatingSpreads;
  }

  cacheApplySignature(
    signature: AliasingSignature,
    effect: Extract<AliasingEffect, {kind: 'Apply'}>,
    f: () => Array<AliasingEffect> | null,
  ): Array<AliasingEffect> | null {
    const inner = getOrInsertDefault(
      this.applySignatureCache,
      signature,
      new Map(),
    );
    return getOrInsertWith(inner, effect, f);
  }

  internEffect(effect: AliasingEffect): AliasingEffect {
    const hash = hashEffect(effect);
    let interned = this.internedEffects.get(hash);
    if (interned == null) {
      this.internedEffects.set(hash, effect);
      interned = effect;
    }
    return interned;
  }
}

Domain

Frequently Asked Questions

What is the Context class?
Context is a class in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts.
Where is Context defined?
Context is defined in compiler/packages/babel-plugin-react-compiler/src/Inference/InferMutationAliasingEffects.ts at line 263.

Analyze Your Own Codebase

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

Try Supermodel Free