Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] Validate against locals being reassigned after render #30107

Merged
merged 4 commits into from
Jun 26, 2024

Commits on Jun 26, 2024

  1. Configuration menu
    Copy the full SHA
    17d23f4 View commit details
    Browse the repository at this point in the history
  2. Update on "[compiler] Validate against locals being reassigned after …

    …render"
    
    Adds a pass which validates that local variables are not reassigned by functions which may be called after render. This is a straightforward forward data-flow analysis, where we:
    1. Build up a mapping of context variables in the outer component/hook
    2. Find ObjectMethod/FunctionExpressions which may reassign those context variables
    3. Propagate aliases of those functions via StoreLocal/LoadLocal
    4. Disallow passing those functions with a Freeze effect. This includes JSX arguments, hook arguments, hook return types, etc.
    
    Conceptually, a function that reassigns a local is inherently mutable. Frozen functions must be side-effect free, so these two categories are incompatible and we can use the freeze effect to find all instances of where such functions are disallowed rather than special-casing eg hook calls and JSX.
    
    [ghstack-poisoned]
    josephsavona committed Jun 26, 2024
    Configuration menu
    Copy the full SHA
    9a5525f View commit details
    Browse the repository at this point in the history
  3. Update on "[compiler] Validate against locals being reassigned after …

    …render"
    
    Adds a pass which validates that local variables are not reassigned by functions which may be called after render. This is a straightforward forward data-flow analysis, where we:
    1. Build up a mapping of context variables in the outer component/hook
    2. Find ObjectMethod/FunctionExpressions which may reassign those context variables
    3. Propagate aliases of those functions via StoreLocal/LoadLocal
    4. Disallow passing those functions with a Freeze effect. This includes JSX arguments, hook arguments, hook return types, etc.
    
    Conceptually, a function that reassigns a local is inherently mutable. Frozen functions must be side-effect free, so these two categories are incompatible and we can use the freeze effect to find all instances of where such functions are disallowed rather than special-casing eg hook calls and JSX.
    
    [ghstack-poisoned]
    josephsavona committed Jun 26, 2024
    Configuration menu
    Copy the full SHA
    9b9537e View commit details
    Browse the repository at this point in the history
  4. s/InvalidJS/InvalidReact/ on "[compiler] Validate against locals bein…

    …g reassigned after render"
    
    Adds a pass which validates that local variables are not reassigned by functions which may be called after render. This is a straightforward forward data-flow analysis, where we:
    1. Build up a mapping of context variables in the outer component/hook
    2. Find ObjectMethod/FunctionExpressions which may reassign those context variables
    3. Propagate aliases of those functions via StoreLocal/LoadLocal
    4. Disallow passing those functions with a Freeze effect. This includes JSX arguments, hook arguments, hook return types, etc.
    
    Conceptually, a function that reassigns a local is inherently mutable. Frozen functions must be side-effect free, so these two categories are incompatible and we can use the freeze effect to find all instances of where such functions are disallowed rather than special-casing eg hook calls and JSX.
    
    [ghstack-poisoned]
    josephsavona committed Jun 26, 2024
    Configuration menu
    Copy the full SHA
    9f6ff54 View commit details
    Browse the repository at this point in the history