Skip to content

Commit 4c52b4c

Browse files
committed
Log casts
1 parent 9f5b4f9 commit 4c52b4c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mypyc/transform/log_trace.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Box,
1717
Call,
1818
CallC,
19+
Cast,
1920
CString,
2021
DecRef,
2122
GetAttr,
@@ -57,7 +58,7 @@ def get_load_global_name(op: CallC) -> str | None:
5758

5859

5960
# These primitives perform an implicit IncRef for the return value. Only some of the most common ones
60-
# are included.
61+
# are included, and mostly ops that could be switched to use borrowing in some contexts.
6162
primitives_that_inc_ref: Final = {
6263
"list_get_item_unsafe",
6364
"CPyList_GetItemShort",
@@ -121,6 +122,12 @@ def visit_box(self, op: Box) -> Value:
121122
def visit_unbox(self, op: Unbox) -> Value:
122123
return self.log(op, "unbox", str(op.type))
123124

125+
def visit_cast(self, op: Cast) -> Value | None:
126+
value = self.log(op, "cast", str(op.type))
127+
if not op.is_borrowed:
128+
self.log_inc_ref(value)
129+
return value
130+
124131
def visit_inc_ref(self, op: IncRef) -> Value:
125132
return self.log(op, "inc_ref", str(op.src.type))
126133

0 commit comments

Comments
 (0)