Skip to content

Conversation

Small patch to pass aliased context values into `Object|ArrayExpression`s
@mofeiZ mofeiZ changed the title [compiler] rewrite invariant in InferReferenceEffects [compiler][ez] rewrite invariant in InferReferenceEffects Jan 16, 2025
Copy link
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.

approving since this is a strict improvement, but in a follow up we should generalize the check for context operands influencing the result kind

Comment on lines +860 to +872
const contextRefOperands = getContextRefOperand(state, instrValue);
const valueKind: AbstractValue =
contextRefOperands.length > 0
? {
kind: ValueKind.Context,
reason: new Set([ValueReason.Other]),
context: new Set(contextRefOperands),
}
: {
kind: ValueKind.Mutable,
reason: new Set([ValueReason.Other]),
context: new Set(),
};
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm it seems wrong to do this only for array and object expressions: there could just as easily be a function call or constructor that captures context values in the same way. I think we missed this when we originally added the context ref check — let's generalize this check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just slightly ahead of you, see repro here #31770

+1 on generalizing this check -- although I'm curious how many changes to compilation output this would result in

@mofeiZ mofeiZ marked this pull request as ready for review January 22, 2025 18:46
@mofeiZ mofeiZ merged commit b6b33bf into main Jan 22, 2025
22 checks passed
mofeiZ added a commit that referenced this pull request Jan 22, 2025
See test fixture
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32094).
* #32099
* #32104
* #32098
* #32097
* #32096
* #32095
* __->__ #32094
* #32093
mofeiZ added a commit that referenced this pull request Jan 22, 2025
See test fixture
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32095).
* #32099
* #32104
* #32098
* #32097
* #32096
* __->__ #32095
* #32094
* #32093
@poteto poteto deleted the pr32093 branch March 11, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants