Home / Function/ visitValueBlock() — react Function Reference

visitValueBlock() — react Function Reference

Architecture documentation for the visitValueBlock() function in BuildReactiveFunction.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66["visitValueBlock()"]
  e20dc57f_069b_7065_293d_92b4bae116ae["Driver"]
  21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66 -->|defined in| e20dc57f_069b_7065_293d_92b4bae116ae
  59c4bc0e_ec5f_af0c_d67c_d518b3f117bc["visitBlock()"]
  59c4bc0e_ec5f_af0c_d67c_d518b3f117bc -->|calls| 21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66
  bae7b350_498b_eec1_68c2_7ca15568b2bb["visitTestBlock()"]
  bae7b350_498b_eec1_68c2_7ca15568b2bb -->|calls| 21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66
  69119c39_6bb5_7c2b_0712_73f7e045a58d["visitValueBlockTerminal()"]
  69119c39_6bb5_7c2b_0712_73f7e045a58d -->|calls| 21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66
  a043b9e3_4ef5_e5b0_f9fd_9ba1c267ff17["extractValueBlockResult()"]
  21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66 -->|calls| a043b9e3_4ef5_e5b0_f9fd_9ba1c267ff17
  632db8c1_f225_c12d_1878_21c605802e1a["wrapWithSequence()"]
  21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66 -->|calls| 632db8c1_f225_c12d_1878_21c605802e1a
  69119c39_6bb5_7c2b_0712_73f7e045a58d["visitValueBlockTerminal()"]
  21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66 -->|calls| 69119c39_6bb5_7c2b_0712_73f7e045a58d
  041ca752_10c1_3cda_1f5c_02f44a01310e["invariant()"]
  21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66 -->|calls| 041ca752_10c1_3cda_1f5c_02f44a01310e
  style 21ce7ec8_0512_fc1a_b5e4_cc6bfd19ca66 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts lines 894–987

  visitValueBlock(
    blockId: BlockId,
    loc: SourceLocation,
    fallthrough: BlockId | null = null,
  ): {block: BlockId; value: ReactiveValue; place: Place; id: InstructionId} {
    const block = this.cx.ir.blocks.get(blockId)!;
    // If we've reached the fallthrough block, stop recursing
    if (fallthrough !== null && blockId === fallthrough) {
      CompilerError.invariant(false, {
        reason: 'Did not expect to reach the fallthrough of a value block',
        description: `Reached bb${blockId}, which is the fallthrough for this value block`,
        loc,
      });
    }
    if (block.terminal.kind === 'branch') {
      if (block.instructions.length === 0) {
        return {
          block: block.id,
          place: block.terminal.test,
          value: {
            kind: 'LoadLocal',
            place: block.terminal.test,
            loc: block.terminal.test.loc,
          },
          id: block.terminal.id,
        };
      }
      return this.extractValueBlockResult(block.instructions, block.id, loc);
    } else if (block.terminal.kind === 'goto') {
      if (block.instructions.length === 0) {
        CompilerError.invariant(false, {
          reason: 'Unexpected empty block with `goto` terminal',
          description: `Block bb${block.id} is empty`,
          loc,
        });
      }
      return this.extractValueBlockResult(block.instructions, block.id, loc);
    } else if (block.terminal.kind === 'maybe-throw') {
      /*
       * ReactiveFunction does not explicitly model maybe-throw semantics,
       * so maybe-throw terminals in value blocks flatten away. In general
       * we recurse to the continuation block.
       *
       * However, if the last portion
       * of the value block is a potentially throwing expression, then the
       * value block could be of the form
       * ```
       * bb1:
       *   ...StoreLocal for the value block...
       *   maybe-throw continuation=bb2
       * bb2:
       *   goto (exit the value block)
       * ```
       *
       * Ie what would have been a StoreLocal+goto is split up because of
       * the maybe-throw. We detect this case and return the value of the
       * current block as the result of the value block
       */
      const continuationId = block.terminal.continuation;
      const continuationBlock = this.cx.ir.blocks.get(continuationId)!;
      if (
        continuationBlock.instructions.length === 0 &&
        continuationBlock.terminal.kind === 'goto'
      ) {
        return this.extractValueBlockResult(
          block.instructions,
          continuationBlock.id,
          loc,
        );
      }

      const continuation = this.visitValueBlock(
        continuationId,
        loc,
        fallthrough,
      );
      return this.wrapWithSequence(block.instructions, continuation, loc);
    } else {
      /*
       * The value block ended in a value terminal, recurse to get the value
       * of that terminal and stitch them together in a sequence.

Domain

Subdomains

Frequently Asked Questions

What does visitValueBlock() do?
visitValueBlock() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts.
Where is visitValueBlock() defined?
visitValueBlock() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/BuildReactiveFunction.ts at line 894.
What does visitValueBlock() call?
visitValueBlock() calls 4 function(s): extractValueBlockResult, invariant, visitValueBlockTerminal, wrapWithSequence.
What calls visitValueBlock()?
visitValueBlock() is called by 3 function(s): visitBlock, visitTestBlock, visitValueBlockTerminal.

Analyze Your Own Codebase

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

Try Supermodel Free