[compiler] Fix module-level 'use memo' not compiling in annotation mode#35870
Open
sleitor wants to merge 1 commit intofacebook:mainfrom
Open
[compiler] Fix module-level 'use memo' not compiling in annotation mode#35870sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor wants to merge 1 commit intofacebook:mainfrom
Conversation
When compilationMode is set to 'annotation', module-level opt-in directives such as 'use memo' (placed at the top of a file) were silently ignored. Only function-level directives triggered compilation, contrary to the documented behavior that "place directives at the top of a file to affect all functions in that module". Root cause: both getReactFunctionType() and processFn() only inspected the function body's own directives (fn.node.body.directives) when deciding whether to compile in annotation mode. The program-level directives (program.node.directives) were never consulted. Fix: - Add hasModuleScopeOptIn to ProgramContext, computed once from tryFindDirectiveEnablingMemoization(program.node.directives). - In getReactFunctionType(), when compilationMode is 'annotation' and no function-level opt-in is found, fall back to hasModuleScopeOptIn before returning null. This ensures functions in the module are queued for compilation. - In processFn(), add !programContext.hasModuleScopeOptIn to the annotation mode skip guard so that the compiled function is emitted. Fixes facebook#35868
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
compilationModeis set to'annotation', module-level opt-in directives such as'use memo'placed at the top of a file were silently ignored. Only function-level directives (inside the function body) triggered compilation, contrary to the documented behavior:Root cause
Both
getReactFunctionType()andprocessFn()only inspected the function body's own directives (fn.node.body.directives) when deciding whether to compile in annotation mode. The program-level directives (program.node.directives) were never consulted.Fix
hasModuleScopeOptIntoProgramContext(computed once fromtryFindDirectiveEnablingMemoization(program.node.directives)).getReactFunctionType(): whencompilationModeis'annotation'and no function-level opt-in is found, fall back tohasModuleScopeOptInbefore returningnull. This ensures functions in the module are queued for compilation.processFn(): add!programContext.hasModuleScopeOptInto the annotation-mode skip guard so that the compiled function is actually emitted.use-memo-module-levelthat verifies'use memo'at module scope in annotation mode compiles the component.Behaviour table
'use memo''use memo''use memo'Fixes #35868