Repository navigation
[compiler] Retain declared Freeze effects on already-frozen values for ref validation - #37975
Merged
javache merged 1 commit intoOct 23, 2026
Conversation
…r ref validation Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
5ffhb27r6p-max
approved these changes
Oct 23, 2026
javache
approved these changes
Oct 23, 2026
github-actions Bot
pushed a commit
that referenced
this pull request
Oct 23, 2026
…r ref validation (#37975) ## Summary When an operand is already frozen (e.g. a memoized value), `applyEffect` drops a declared `Freeze` effect because nothing new gets frozen. Ref validation reads the declared `Freeze` effects of known signatures, so it misses them in this case. For example, with `PanResponder.create`'s signature: ```js const ref = useRef(0); const config = useMemo(() => ({onPanResponderRelease: () => { ref.current = 0; }}), []); const responder = PanResponder.create(config); // false positive: ref access reported ``` This keeps the declared effect on the instruction when the value is already frozen, as suggested by @javache in #37970. This is metadata only: nothing extra is frozen. **Note:** the literal diff from review (always `effects.push(effect)`) regressed 11 snapshot fixtures. A retained `Freeze` sets `operand.effect === Effect.Freeze` in `InferMutationAliasingRanges`, which `ValidateNoFreezingKnownMutableFunctions` reads, so it started reporting an extra "Cannot modify local variables after render completes" error on already-frozen operands. It also made the valid `allow-mutate-global-in-effect-fixpoint` fixture fail, and added a duplicate error to e.g. `error.assign-ref-in-effect-hint`, `error.invalid-mutate-hook-value-in-intersection-observer` and `error.todo-reassign-const`. So this PR keeps the effect for ref validation only: the retained effect is marked `alreadyFrozen`, and `InferMutationAliasingRanges` skips it when computing operand effects. All other passes see what they saw before. The same change is made in the Rust port (`already_frozen`). ## How did you test this change? - Added `panresponder-ref-in-memoized-config.js` (the `useMemo` example above, using the `shared-runtime` `PanResponder.create` signature). It fails with "Cannot access refs during render" without this change and passes with it. - `yarn snap` in `compiler/`: the failure list is identical to `main` (the same 20 pre-existing failures, mostly fbt fixtures in my local setup); no snapshots changed other than the new fixture. - `yarn workspace babel-plugin-react-compiler tsc --noEmit` and `lint`, prettier: pass. - `cargo fmt --all`, `cargo check --workspace`, and `cargo test` for `react_compiler_hir`, `react_compiler_inference` and `react_compiler_validation`: pass. I did not run the Rust fixture comparison against snap. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 5.5 <[email protected]> DiffTrain build for [a6b912f](a6b912f)
github-actions Bot
pushed a commit
that referenced
this pull request
Oct 23, 2026
…r ref validation (#37975) ## Summary When an operand is already frozen (e.g. a memoized value), `applyEffect` drops a declared `Freeze` effect because nothing new gets frozen. Ref validation reads the declared `Freeze` effects of known signatures, so it misses them in this case. For example, with `PanResponder.create`'s signature: ```js const ref = useRef(0); const config = useMemo(() => ({onPanResponderRelease: () => { ref.current = 0; }}), []); const responder = PanResponder.create(config); // false positive: ref access reported ``` This keeps the declared effect on the instruction when the value is already frozen, as suggested by @javache in #37970. This is metadata only: nothing extra is frozen. **Note:** the literal diff from review (always `effects.push(effect)`) regressed 11 snapshot fixtures. A retained `Freeze` sets `operand.effect === Effect.Freeze` in `InferMutationAliasingRanges`, which `ValidateNoFreezingKnownMutableFunctions` reads, so it started reporting an extra "Cannot modify local variables after render completes" error on already-frozen operands. It also made the valid `allow-mutate-global-in-effect-fixpoint` fixture fail, and added a duplicate error to e.g. `error.assign-ref-in-effect-hint`, `error.invalid-mutate-hook-value-in-intersection-observer` and `error.todo-reassign-const`. So this PR keeps the effect for ref validation only: the retained effect is marked `alreadyFrozen`, and `InferMutationAliasingRanges` skips it when computing operand effects. All other passes see what they saw before. The same change is made in the Rust port (`already_frozen`). ## How did you test this change? - Added `panresponder-ref-in-memoized-config.js` (the `useMemo` example above, using the `shared-runtime` `PanResponder.create` signature). It fails with "Cannot access refs during render" without this change and passes with it. - `yarn snap` in `compiler/`: the failure list is identical to `main` (the same 20 pre-existing failures, mostly fbt fixtures in my local setup); no snapshots changed other than the new fixture. - `yarn workspace babel-plugin-react-compiler tsc --noEmit` and `lint`, prettier: pass. - `cargo fmt --all`, `cargo check --workspace`, and `cargo test` for `react_compiler_hir`, `react_compiler_inference` and `react_compiler_validation`: pass. I did not run the Rust fixture comparison against snap. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 5.5 <[email protected]> DiffTrain build for [a6b912f](a6b912f)
Gourav224
deleted the
compiler/preserve-freeze-effect-for-ref-validation
branch
October 26, 2026 04:10
javache
pushed a commit
that referenced
this pull request
Oct 26, 2026
…efs false positive (#37970) Fixes #37955 **Depends on #37975** (retains declared `Freeze` effects for already-frozen values, as suggested by @javache). Until that merges this PR's diff also shows its commit. ## Summary `react-hooks/refs` reports "Passing a ref to a function may read its value during render" for callbacks passed to React Native's `PanResponder.create({...})`, because the compiler treats `PanResponder` imported from `react-native` as an unknown function that may call its arguments during render. `PanResponder.create()` only stores the handlers and invokes them later from gesture events. The compiler already has a signature for exactly this (`PanResponder.create` freezes its config and doesn't call it during render), but it only exists in the test-only `shared-runtime` type provider in `snap`, so real code never gets it. This adds the same signature for `react-native` to `defaultModuleTypeProvider` (TypeScript, and the Rust port in `default_module_type_provider.rs`), so the callbacks are treated as deferred, like the `IntersectionObserver` fix in #37764. Other unknown functions still report errors when given ref-accessing callbacks. ## How did you test this change? Added a valid case to `packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleTypescript-test.ts` (the repro shape from the issue). Snap fixtures can't cover this because `snap` replaces the module type provider with its own. - Without the fix: `cd packages/eslint-plugin-react-hooks && npx jest ReactCompilerRuleTypescript` → `1 failed, 15 passed` (the new case). - With the fix: `yarn build:compiler && npx jest` in `packages/eslint-plugin-react-hooks` → `4 suites passed, 5087 tests passed`. - `yarn workspace babel-plugin-react-compiler tsc --noEmit` and `lint` (in `compiler/`) pass; `yarn lint` at the root passes; prettier check passes on the changed TS files. - `cargo check -p react_compiler_hir` and `cargo fmt --check` pass for the Rust change (I did not run the Rust test suite). - `yarn snap` in `compiler/`: identical results with and without this change (1812 passed, 20 failed; the failures are pre-existing, mostly fbt fixtures in my local setup). - Also added a memoized-config case (`useMemo` config passed to `PanResponder.create`); with #37975 the eslint-plugin suite passes (5088 tests). - `yarn flow` not run: the change touches no Flow-typed code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
github-actions Bot
pushed a commit
that referenced
this pull request
Oct 26, 2026
…efs false positive (#37970) Fixes #37955 **Depends on #37975** (retains declared `Freeze` effects for already-frozen values, as suggested by @javache). Until that merges this PR's diff also shows its commit. ## Summary `react-hooks/refs` reports "Passing a ref to a function may read its value during render" for callbacks passed to React Native's `PanResponder.create({...})`, because the compiler treats `PanResponder` imported from `react-native` as an unknown function that may call its arguments during render. `PanResponder.create()` only stores the handlers and invokes them later from gesture events. The compiler already has a signature for exactly this (`PanResponder.create` freezes its config and doesn't call it during render), but it only exists in the test-only `shared-runtime` type provider in `snap`, so real code never gets it. This adds the same signature for `react-native` to `defaultModuleTypeProvider` (TypeScript, and the Rust port in `default_module_type_provider.rs`), so the callbacks are treated as deferred, like the `IntersectionObserver` fix in #37764. Other unknown functions still report errors when given ref-accessing callbacks. ## How did you test this change? Added a valid case to `packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleTypescript-test.ts` (the repro shape from the issue). Snap fixtures can't cover this because `snap` replaces the module type provider with its own. - Without the fix: `cd packages/eslint-plugin-react-hooks && npx jest ReactCompilerRuleTypescript` → `1 failed, 15 passed` (the new case). - With the fix: `yarn build:compiler && npx jest` in `packages/eslint-plugin-react-hooks` → `4 suites passed, 5087 tests passed`. - `yarn workspace babel-plugin-react-compiler tsc --noEmit` and `lint` (in `compiler/`) pass; `yarn lint` at the root passes; prettier check passes on the changed TS files. - `cargo check -p react_compiler_hir` and `cargo fmt --check` pass for the Rust change (I did not run the Rust test suite). - `yarn snap` in `compiler/`: identical results with and without this change (1812 passed, 20 failed; the failures are pre-existing, mostly fbt fixtures in my local setup). - Also added a memoized-config case (`useMemo` config passed to `PanResponder.create`); with #37975 the eslint-plugin suite passes (5088 tests). - `yarn flow` not run: the change touches no Flow-typed code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]> DiffTrain build for [9ca7a27](9ca7a27)
github-actions Bot
pushed a commit
that referenced
this pull request
Oct 26, 2026
…efs false positive (#37970) Fixes #37955 **Depends on #37975** (retains declared `Freeze` effects for already-frozen values, as suggested by @javache). Until that merges this PR's diff also shows its commit. ## Summary `react-hooks/refs` reports "Passing a ref to a function may read its value during render" for callbacks passed to React Native's `PanResponder.create({...})`, because the compiler treats `PanResponder` imported from `react-native` as an unknown function that may call its arguments during render. `PanResponder.create()` only stores the handlers and invokes them later from gesture events. The compiler already has a signature for exactly this (`PanResponder.create` freezes its config and doesn't call it during render), but it only exists in the test-only `shared-runtime` type provider in `snap`, so real code never gets it. This adds the same signature for `react-native` to `defaultModuleTypeProvider` (TypeScript, and the Rust port in `default_module_type_provider.rs`), so the callbacks are treated as deferred, like the `IntersectionObserver` fix in #37764. Other unknown functions still report errors when given ref-accessing callbacks. ## How did you test this change? Added a valid case to `packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleTypescript-test.ts` (the repro shape from the issue). Snap fixtures can't cover this because `snap` replaces the module type provider with its own. - Without the fix: `cd packages/eslint-plugin-react-hooks && npx jest ReactCompilerRuleTypescript` → `1 failed, 15 passed` (the new case). - With the fix: `yarn build:compiler && npx jest` in `packages/eslint-plugin-react-hooks` → `4 suites passed, 5087 tests passed`. - `yarn workspace babel-plugin-react-compiler tsc --noEmit` and `lint` (in `compiler/`) pass; `yarn lint` at the root passes; prettier check passes on the changed TS files. - `cargo check -p react_compiler_hir` and `cargo fmt --check` pass for the Rust change (I did not run the Rust test suite). - `yarn snap` in `compiler/`: identical results with and without this change (1812 passed, 20 failed; the failures are pre-existing, mostly fbt fixtures in my local setup). - Also added a memoized-config case (`useMemo` config passed to `PanResponder.create`); with #37975 the eslint-plugin suite passes (5088 tests). - `yarn flow` not run: the change touches no Flow-typed code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]> DiffTrain build for [9ca7a27](9ca7a27)
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an operand is already frozen (e.g. a memoized value),
applyEffectdrops a declaredFreezeeffect because nothing new gets frozen. Ref validation reads the declaredFreezeeffects of known signatures, so it misses them in this case. For example, withPanResponder.create's signature:This keeps the declared effect on the instruction when the value is already frozen, as suggested by @javache in #37970. This is metadata only: nothing extra is frozen.
Note: the literal diff from review (always
effects.push(effect)) regressed 11 snapshot fixtures. A retainedFreezesetsoperand.effect === Effect.FreezeinInferMutationAliasingRanges, whichValidateNoFreezingKnownMutableFunctionsreads, so it started reporting an extra "Cannot modify local variables after render completes" error on already-frozen operands. It also made the validallow-mutate-global-in-effect-fixpointfixture fail, and added a duplicate error to e.g.error.assign-ref-in-effect-hint,error.invalid-mutate-hook-value-in-intersection-observeranderror.todo-reassign-const.So this PR keeps the effect for ref validation only: the retained effect is marked
alreadyFrozen, andInferMutationAliasingRangesskips it when computing operand effects. All other passes see what they saw before. The same change is made in the Rust port (already_frozen).How did you test this change?
panresponder-ref-in-memoized-config.js(theuseMemoexample above, using theshared-runtimePanResponder.createsignature). It fails with "Cannot access refs during render" without this change and passes with it.yarn snapincompiler/: the failure list is identical tomain(the same 20 pre-existing failures, mostly fbt fixtures in my local setup); no snapshots changed other than the new fixture.yarn workspace babel-plugin-react-compiler tsc --noEmitandlint, prettier: pass.cargo fmt --all,cargo check --workspace, andcargo testforreact_compiler_hir,react_compiler_inferenceandreact_compiler_validation: pass. I did not run the Rust fixture comparison against snap.🤖 Generated with Claude Code