-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[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
Conversation
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unclear.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derivable from src; @Property?
There was a problem hiding this comment.
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)
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.