[Mlir-commits] [mlir] [mlir][py] invalidate nested operations when parent is deleted (PR #93339)

Stella Laurenzo llvmlistbot at llvm.org
Fri May 24 15:07:03 PDT 2024


stellaraccident wrote:

> How would that work? I think I vaguely understand that `Py_XINCREF`/`Py_XDECREF` is for something like that?

There are multiple ways to implement a weak reference system, and this would be one of them. If you had a nonce value that could be initialized for each operation, then you could provide a query mechanism to check whether the reference is still alive. That could give a safe way to detect invalidation and act accordingly. 

You *could* use the Operation* itself as the key into such a table of weak reference objects, but the accounting would have to be done by the operation/context and tied to the Operation destructor, or else the pointer reuse could not be bounded.

So such a system would require either a nonce slot on each operation instance or additional context scoped accounting in the Operation destructor. So a memory overhead or a destruction overhead. No other thing is possible with non managed pointers.

https://github.com/llvm/llvm-project/pull/93339


More information about the Mlir-commits mailing list