Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check if passed value is refcounted
  • Loading branch information
p-sawicki committed Mar 23, 2026
commit e548a8208c8eba2393b49adcbb0842c191a7323b
4 changes: 3 additions & 1 deletion mypyc/codegen/emitfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ def visit_set_attr(self, op: SetAttr) -> None:
)
# The property setter method increfs the passed value (src) so we need to decref it here
# to avoid leaking.
self.emitter.emit_dec_ref(src, op.src.type)
src_rtype = op.src.type
if src_rtype.is_refcounted:
self.emitter.emit_dec_ref(src, src_rtype)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A potentially cleaner approach would be to adjust stolen of SetAttr for properties -- i.e. don't steal the value if it's a property. Thoughts?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ah good call, this way the decref is visible in the IR which makes for better tests.

i've removed the leak test from the run test as it seemed a little flaky when running it multiple times in a row.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

looks like the failures were actually an implementation mistake - using ClassIR.methods during IR generation may not work in multimodule compilation because the SetAttr constructor might run before the property setter method is added in the other module.

i've changed it to use ClassIR.method_decls instead which is populated in prepare.py so it's safe to use.

else:
# ...and struct access for normal attributes.
attr_expr = self.get_attr_expr(obj, op, decl_cl)
Expand Down
Loading