[Mlir-commits] [mlir] [mlir][python] Make the Context/Operation capsule creation methods work as documented. (PR #76010)

Stella Laurenzo llvmlistbot at llvm.org
Thu Dec 21 08:20:32 PST 2023


stellaraccident wrote:

> Reverting for now. 
> 
> I think it's either a matter of (a) updating the caster in PybindAdaptors.h so that it can interpret `MlirOperation` as reference when the corresponding operation itself (and maybe one of its ancestors) is already owned by python or (b) somehow providing a mechanism for downstream binding implementers to indicate whether they intend to transfer ownership. But I'm rusty on this whole ownership business. 

I might add an arg to indicate whether ownership must be transferred. The case I was running into was subtle non-determinism based on access pattern when a completely external API with its own ownership semantics was negotiating to give ownership to the python API. The implicit ownership capture of context and operation makes this very easy to get wrong with perfectly valid Python sequences. I thought it was a Windows ghost for months but it just turned out to be more sensitive to the fallout. I finally had evidence that a real program was also triggering the issue on Linux (but it was in the bowels of an integration, and what I sent upstream was my reduced test case). That is what made me trade it seriously.

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


More information about the Mlir-commits mailing list