Skip to content

Commit c05ce9b

Browse files
authored
[MLIR][Python] fix getOwner to return (typed) nb::object instead of abstract PyOpView (#165053)
#157930 changed `nb::object getOwner()` to `PyOpView getOwner()` which implicitly constructs the generic OpView against from a (possibly) concrete OpView. This PR fixes that.
1 parent c8f5c60 commit c05ce9b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

mlir/lib/Bindings/Python/IRCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ class PyOpOperand {
598598
public:
599599
PyOpOperand(MlirOpOperand opOperand) : opOperand(opOperand) {}
600600

601-
PyOpView getOwner() {
601+
nb::typed<nb::object, PyOpView> getOwner() {
602602
MlirOperation owner = mlirOpOperandGetOwner(opOperand);
603603
PyMlirContextRef context =
604604
PyMlirContext::forContext(mlirOperationGetContext(owner));

mlir/test/python/ir/operation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,3 +1187,15 @@ def callback(op):
11871187
module.operation.walk(callback)
11881188
except RuntimeError:
11891189
print("Exception raised")
1190+
1191+
1192+
# CHECK-LABEL: TEST: testGetOwnerConcreteOpview
1193+
@run
1194+
def testGetOwnerConcreteOpview():
1195+
with Context() as ctx, Location.unknown():
1196+
module = Module.create()
1197+
with InsertionPoint(module.body):
1198+
a = arith.ConstantOp(value=42, result=IntegerType.get_signless(32))
1199+
r = arith.AddIOp(a, a, overflowFlags=arith.IntegerOverflowFlags.nsw)
1200+
for u in a.result.uses:
1201+
assert isinstance(u.owner, arith.AddIOp)

0 commit comments

Comments
 (0)