[mlir][python] Update `PyOpResult.owner` to get the parent object.
authorMike Urbach <mikeurbach@gmail.com>
Sat, 24 Apr 2021 02:32:54 +0000 (20:32 -0600)
committerMike Urbach <mikeurbach@gmail.com>
Wed, 28 Apr 2021 20:39:59 +0000 (14:39 -0600)
Previously, this API would return the PyObjectRef, rather than the
underlying PyOperation.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D101416

mlir/lib/Bindings/Python/IRCore.cpp
mlir/test/Bindings/Python/ir_value.py

index 0945753..781e9ae 100644 (file)
@@ -1566,7 +1566,7 @@ public:
           mlirOperationEqual(self.getParentOperation()->get(),
                              mlirOpResultGetOwner(self.get())) &&
           "expected the owner of the value in Python to match that in the IR");
-      return self.getParentOperation();
+      return self.getParentOperation().getObject();
     });
     c.def_property_readonly("result_number", [](PyOpResult &self) {
       return mlirOpResultGetResultNumber(self.get());
index 3b88fee..1db9f33 100644 (file)
@@ -25,3 +25,16 @@ def testCapsuleConversions():
 
 
 run(testCapsuleConversions)
+
+
+# CHECK-LABEL: TEST: testOpResultOwner
+def testOpResultOwner():
+  ctx = Context()
+  ctx.allow_unregistered_dialects = True
+  with Location.unknown(ctx):
+    i32 = IntegerType.get_signless(32)
+    op = Operation.create("custom.op1", results=[i32])
+    assert op.result.owner == op
+
+
+run(testOpResultOwner)