llvm / llvm/llvm-project

[MLIR][Python] opview somehow mutates something...

Open
#165,126 2 comments 0 reactions 1 assignee Claimed by @makslevental View on GitHub
mlir:python
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```diff
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index cda4fe19c16f..bd66bbd02ebd 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -1626,12 +1626,12 @@ public:

static void bindDerived(ClassTy &c) {
c.def_prop_ro(
- "owner", [](PyOpResult &self) -> nb::typed {
+ "owner", [](PyOpResult &self) -> nb::typed {
assert(mlirOperationEqual(self.getParentOperation()->get(),
mlirOpResultGetOwner(self.get())) &&
"expected the owner of the value in Python to match that in "
"the IR");
- return self.getParentOperation().getObject();
+ return self.getParentOperation()->createOpView();
});
c.def_prop_ro("result_number", [](PyOpResult &self) {
return mlirOpResultGetResultNumber(self.get());
@@ -3553,10 +3553,10 @@ void mlir::python::populateIRCore(nb::module_ &m) {
"or derived from."))
.def_prop_ro("parent",
[](PyOperationBase &self)
- -> std::optional> {
+ -> std::optional> {
auto parent = self.getOperation().getParentOperation();
if (parent)
- return parent->getObject();
+ return {(*parent)->createOpView()};
return {};
})
.def(
@@ -4301,7 +4301,7 @@ void mlir::python::populateIRCore(nb::module_ &m) {
"expected the owner of the value in Python to match "
"that in "
"the IR");
- return self.getParentOperation().getObject();
+ return self.getParentOperation()->createOpView();
}

if (mlirValueIsABlockArgument(v)) {
```

causes

```
# CHECK: %{{.*}} = memref.subview %[[ALLOC]][1, 1] [3, 3] [1, 1] : memref<10x10xi32> to memref<3x3xi32, strided<[10, 1], offset: 11>>
print(z.owner)
```
in `testSubViewOpInferReturnTypeSemantics` in `mlir/test/python/dialects/memref.py` to break because suddenly the printed op has dynamic offset (i.e., `?`). Very weird...

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.