-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mypyc] Refactor: use primitive op for initializing list item (#17056)
Add a new primitive op for initializing list items. Also add support for primitive ops that steal operands (reference counting wise). This will also remove most instances of `WORD_SIZE` in irbuild tests, which were a bit painful, since running tests with `--update-data` removed these and they had to be manually added back for 32-bit tests to pass.
- Loading branch information
Showing
22 changed files
with
463 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from mypyc.common import PLATFORM_SIZE | ||
from mypyc.ir.ops import Integer, IntOp, SetMem, Value | ||
from mypyc.ir.rtypes import c_pyssize_t_rprimitive, object_rprimitive, pointer_rprimitive | ||
from mypyc.irbuild.ll_builder import LowLevelIRBuilder | ||
from mypyc.lower.registry import lower_primitive_op | ||
|
||
|
||
@lower_primitive_op("buf_init_item") | ||
def buf_init_item(builder: LowLevelIRBuilder, args: list[Value], line: int) -> Value: | ||
"""Initialize an item in a buffer of "PyObject *" values at given index. | ||
This can be used to initialize the data buffer of a freshly allocated list | ||
object. | ||
""" | ||
base = args[0] | ||
index_value = args[1] | ||
value = args[2] | ||
assert isinstance(index_value, Integer) | ||
index = index_value.numeric_value() | ||
if index == 0: | ||
ptr = base | ||
else: | ||
ptr = builder.add( | ||
IntOp( | ||
pointer_rprimitive, | ||
base, | ||
Integer(index * PLATFORM_SIZE, c_pyssize_t_rprimitive), | ||
IntOp.ADD, | ||
line, | ||
) | ||
) | ||
return builder.add(SetMem(object_rprimitive, ptr, value, line)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.