Skip to content

[Compiler] Align memoization of function expression properties with method shorthand #36151#36153

Open
Bobadu wants to merge 4 commits intofacebook:mainfrom
Bobadu:fix/issue-36151-consistent-object-memoization
Open

[Compiler] Align memoization of function expression properties with method shorthand #36151#36153
Bobadu wants to merge 4 commits intofacebook:mainfrom
Bobadu:fix/issue-36151-consistent-object-memoization

Conversation

@Bobadu
Copy link
Copy Markdown

@Bobadu Bobadu commented Mar 27, 2026

The compiler memoizes { foo() {} } and { foo: () => {} } differently — method shorthand gets the whole object in one scope, function expressions get split into separate cache slots. Same semantics, different output.

The issue is in AlignObjectMethodScopes — it only looks at ObjectMethod instructions when deciding what to merge. This extends it to also pick up FunctionExpression values used as object properties.

Fixes #36151

@meta-cla meta-cla bot added the CLA Signed label Mar 27, 2026
Copy link
Copy Markdown
Member

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! However, this is backwards. The reason we merge object methods with their object is that we're currently trying to preserve the fact that they are object methods at all (i mean syntactically in our codegen output). But since we don't support this, we actually don't have to keep object methods as object methods. So the more optimal thing to do here is actually rewrite object methods into function expressions, and remove AlignObjectMethodScopes altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compiler Bug]: Inconsistent memoization strategy for object with method shorthand vs function properties

2 participants