You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remove Incref/Decref of Specific Immortal Objects #117425
In various places we incref or decref an object that we already know is a specific immortal object, like None. For example, see gh-117393. These operations are unnecessary and the (small) cost can be avoided.
We could simply drop the increfs and decrefs, but there is value in communicating that we would have done the op if the object weren't known to be immortal. (Furthermore, there's the very, very remote chance that some known-immortal object might be made mortal again some day, for some currently unknown reason. It would be quite hard at the point to know that we should add back in the incref or decref we had removed.)
Here are the options I see:
leave the existing code alone
replace the existing code with comments
replace the existing code with a noop macro (in the internal API)
We probably wouldn't make all the changes we could find all at once, but could at the least point to this issue for the decision on what should be done. If we do add a macro then we'd do it relative to this issue.
Personally, I'd go with the macro. It would communicate the intent to readers just as well as the existing code does or as a comment would. I imagine it would look something like the following:
The sentiment makes sense to me, but the proposed naming makes me pause.
"inc/dec ref immortal", just from the name, looks like an oxymoron, and a hacky way to "force" manipulating the refcnt of an immortal object (e.g. "I know what I'm doing, ignore the fact this object is immortal and go ahead with modifying its refcnt").
Unfortunately I don't have a less confusing name to suggest for this...
Activity
[-]Remove Incref/Decref of Specific Immotral Objects[/-][+]Remove Incref/Decref of Specific Immortal Objects[/+]itamaro commentedon Apr 6, 2024
The sentiment makes sense to me, but the proposed naming makes me pause.
"inc/dec ref immortal", just from the name, looks like an oxymoron, and a hacky way to "force" manipulating the refcnt of an immortal object (e.g. "I know what I'm doing, ignore the fact this object is immortal and go ahead with modifying its refcnt").
Unfortunately I don't have a less confusing name to suggest for this...
ericsnowcurrently commentedon Apr 11, 2024
Yeah, I'm open to other names. At the least, I wanted to capture the intention..
eduardo-elizondo commentedon Apr 21, 2024
I'm more supportive of the macro - it also gives the flexibility to have extra assertions in debug more as you've outlined in your example