llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.2k stars 11.64k forks source link

Python bidings don't know that modules are operations #93337

Open ftynse opened 4 months ago

ftynse commented 4 months ago

The following trivial code crashes:

from mlir.ir import *

m = ir.Module.create()
m.operation.erase()

because erase erases the module operation, and then the destructor of PyModule attempts to erase it the second time (transitively through the module object).

We should connect PyModule to the corresponding PyOperation in the bindings and avoid calling mlirModuleDestroy if the operation was already destroyed, using the valid flag on the operation.

llvmbot commented 4 months ago

@llvm/issue-subscribers-mlir-python

Author: Oleksandr "Alex" Zinenko (ftynse)

The following trivial code crashes: ``` from mlir.ir import * m = ir.Module.create() m.operation.erase() ``` because `erase` erases the module operation, and then the destructor of `PyModule` attempts to erase it the second time (transitively through the module object). We should connect `PyModule` to the corresponding `PyOperation` in the bindings and avoid calling `mlirModuleDestroy` if the operation was already destroyed, using the `valid` flag on the operation.