Skip to content

[mypyc] Add SetElement op for initializing struct values #19437

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

Merged
merged 4 commits into from
Jul 15, 2025

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 14, 2025

Also add Undef value type that can currently only used as the
operand for SetElement to signify that we are creating a new
value instead of modifying an existing value.

A new struct value can be created by starting with Undef and
setting each element sequentially. Each operation produces a
new struct value, but the temporaries will be optimized away
in the later passes (currently by the C compiler, but we could
do something more clever here in the future).

This is needed to support packed arrays, which are represented
as structs. I extracted this from my packed array branch, and
it's currently unused outside tests.

JukkaL added 2 commits July 14, 2025 16:36
Also add Undef value type that can currently only used as the
operand for SetElement to signify that we are creating a new
value instead of modifying an existing value.
mypyc/ir/ops.py Outdated
# r1 now has new struct value with two fields set

Warning: The generated code can use an arbitrary runtime values for
this (likely not explicitly initialized).

Choose a reason for hiding this comment

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

this is unclear.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

def __init__(self, src: Value, field: str, item: Value, line: int = -1) -> None:
super().__init__(line)
assert isinstance(src.type, RStruct), src.type
self.type = src.type
Copy link

@peturingi peturingi Jul 14, 2025

Choose a reason for hiding this comment

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

Derivable from src; @Property?

Choose a reason for hiding this comment

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

Irrelevant as it won't play nice with

def visit_set_element(self, op: SetElement) -> None:
        op.src = self.fix_op(op.src)

@JukkaL JukkaL merged commit 32f57e4 into master Jul 15, 2025
13 checks passed
@JukkaL JukkaL deleted the mypyc-set-element branch July 15, 2025 11:30
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.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy