Home / File/ repro-aliased-capture-aliased-mutate.js — react Source File

repro-aliased-capture-aliased-mutate.js — react Source File

Architecture documentation for repro-aliased-capture-aliased-mutate.js, a javascript file in the react codebase. 1 imports, 0 dependents.

File javascript TestingUtilities Fixtures 1 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  378fb54b_2f06_ff8f_cc5c_e76c1a14b147["repro-aliased-capture-aliased-mutate.js"]
  006eec3d_77a9_4a47_e6c1_a96d7a6c9c05["shared-runtime"]
  378fb54b_2f06_ff8f_cc5c_e76c1a14b147 --> 006eec3d_77a9_4a47_e6c1_a96d7a6c9c05
  style 378fb54b_2f06_ff8f_cc5c_e76c1a14b147 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// @flow @enableTransitivelyFreezeFunctionExpressions:false @enableNewMutationAliasingModel
import {arrayPush, setPropertyByKey, Stringify} from 'shared-runtime';

/**
 * Repro of a bug fixed in the new aliasing model.
 *
 * 1. `InferMutableRanges` derives the mutable range of identifiers and their
 *     aliases from `LoadLocal`, `PropertyLoad`, etc
 *   - After this pass, y's mutable range only extends to `arrayPush(x, y)`
 *   - We avoid assigning mutable ranges to loads after y's mutable range, as
 *     these are working with an immutable value. As a result, `LoadLocal y` and
 *     `PropertyLoad y` do not get mutable ranges
 * 2. `InferReactiveScopeVariables` extends mutable ranges and creates scopes,
 *    as according to the 'co-mutation' of different values
 *   - Here, we infer that
 *     - `arrayPush(y, x)` might alias `x` and `y` to each other
 *     - `setPropertyKey(x, ...)` may mutate both `x` and `y`
 *   - This pass correctly extends the mutable range of `y`
 *   - Since we didn't run `InferMutableRange` logic again, the LoadLocal /
 *     PropertyLoads still don't have a mutable range
 *
 * Note that the this bug is an edge case. Compiler output is only invalid for:
 *  - function expressions with
 *    `enableTransitivelyFreezeFunctionExpressions:false`
 *  - functions that throw and get retried without clearing the memocache
 *
 * Found differences in evaluator results
 * Non-forget (expected):
 *   (kind: ok)
 *   <div>{"cb":{"kind":"Function","result":10},"shouldInvokeFns":true}</div>
 *   <div>{"cb":{"kind":"Function","result":11},"shouldInvokeFns":true}</div>
 * Forget:
 *   (kind: ok)
 *   <div>{"cb":{"kind":"Function","result":10},"shouldInvokeFns":true}</div>
 *   <div>{"cb":{"kind":"Function","result":10},"shouldInvokeFns":true}</div>
 */
function useFoo({a, b}: {a: number, b: number}) {
  const x = [];
  const y = {value: a};

  arrayPush(x, y); // x and y co-mutate
  const y_alias = y;
  const cb = () => y_alias.value;
  setPropertyByKey(x[0], 'value', b); // might overwrite y.value
  return <Stringify cb={cb} shouldInvokeFns={true} />;
}

export const FIXTURE_ENTRYPOINT = {
  fn: useFoo,
  params: [{a: 2, b: 10}],
  sequentialRenders: [
    {a: 2, b: 10},
    {a: 2, b: 11},
  ],
};

Subdomains

Functions

Dependencies

  • shared-runtime

Frequently Asked Questions

What does repro-aliased-capture-aliased-mutate.js do?
repro-aliased-capture-aliased-mutate.js is a source file in the react codebase, written in javascript. It belongs to the TestingUtilities domain, Fixtures subdomain.
What functions are defined in repro-aliased-capture-aliased-mutate.js?
repro-aliased-capture-aliased-mutate.js defines 1 function(s): useFoo.
What does repro-aliased-capture-aliased-mutate.js depend on?
repro-aliased-capture-aliased-mutate.js imports 1 module(s): shared-runtime.
Where is repro-aliased-capture-aliased-mutate.js in the architecture?
repro-aliased-capture-aliased-mutate.js is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-aliased-capture-aliased-mutate.js (domain: TestingUtilities, subdomain: Fixtures, directory: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler).

Analyze Your Own Codebase

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

Try Supermodel Free