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

remove inactive case fields from VM object constructor nodes #24441

Closed
wants to merge 1 commit into from

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Nov 15, 2024

fixes #17571

Objects in the VM are represented as object constructor nodes that contain every single field, including ones in different case branches. This is so that every field has a unique invariant index in the object constructor that can be written to and read from. However when converting this node back into semantic code, fields from inactive case branches can remain in the constructor which causes bad codegen, generating assignments to fields from other case branches.

To fix this, fields from inactive branches are now detected in semmacrosanity.annotateType (called in fixupTypeAfterEval) and excluded from the resulting node. annotateType needed to be refactored to have a return value to do this.

@metagn
Copy link
Collaborator Author

metagn commented Nov 15, 2024

Doesn't work because const values also call fixupTypeAfterEval. Interestingly using const instead of static already works though, probably because it goes through genBracedInit instead.

An option is to prevent codegen for these fields via nfPreventCg instead but the AST would still contain them.

@metagn metagn marked this pull request as draft November 15, 2024 21:40
Araq pushed a commit that referenced this pull request Nov 16, 2024
#24442)

fixes #17571

Objects in the VM are represented as object constructor nodes that
contain every single field, including ones in different case branches.
This is so that every field has a unique invariant index in the object
constructor that can be written to and read from. However when
converting this node back into semantic code, fields from inactive case
branches can remain in the constructor which causes bad codegen,
generating assignments to fields from other case branches.

To fix this, fields from inactive branches are now detected in
`semmacrosanity.annotateType` (called in `fixupTypeAfterEval`) and
marked to prevent the codegen of their assignments. In #24441 these
fields were excluded from the resulting node, but this causes issues
when the node is directly supposed to go back into the VM, for example
as `const` values. I don't know if this is the only case where this
happens, so I wasn't sure about how to keep that implementation working.
@metagn
Copy link
Collaborator Author

metagn commented Nov 17, 2024

Closing for now since #24442 was merged

@metagn metagn closed this Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

static(ObjectWithCaseInit(...)) generates invalid code
1 participant