[Mlir-commits] [mlir] e6d738e - [mlir][python] Mark operator== overloads as const

Rahul Kayaith llvmlistbot at llvm.org
Tue Mar 28 08:06:19 PDT 2023


Author: Rahul Kayaith
Date: 2023-03-28T11:06:13-04:00
New Revision: e6d738e0c76b2fb63ee3f90740678b4e4a4c0b32

URL: https://github.com/llvm/llvm-project/commit/e6d738e0c76b2fb63ee3f90740678b4e4a4c0b32
DIFF: https://github.com/llvm/llvm-project/commit/e6d738e0c76b2fb63ee3f90740678b4e4a4c0b32.diff

LOG: [mlir][python] Mark operator== overloads as const

This resolves some warnings when building with C++20, e.g.:
```
llvm-project/mlir/lib/Bindings/Python/IRAffine.cpp:545:60: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'mlir::python::PyAffineExpr' and 'mlir::python::PyAffineExpr') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
                        PyAffineExpr &other) { return self == other; })
                                                      ~~~~ ^  ~~~~~
llvm-project/mlir/lib/Bindings/Python/IRAffine.cpp:350:20: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
bool PyAffineExpr::operator==(const PyAffineExpr &other) {
                   ^
```

Reviewed By: ftynse

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

Added: 
    

Modified: 
    mlir/lib/Bindings/Python/IRAffine.cpp
    mlir/lib/Bindings/Python/IRCore.cpp
    mlir/lib/Bindings/Python/IRModule.h

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index 09f36b07cd793..9a2ea6b68c693 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -347,7 +347,7 @@ class PyAffineCeilDivExpr
 
 } // namespace
 
-bool PyAffineExpr::operator==(const PyAffineExpr &other) {
+bool PyAffineExpr::operator==(const PyAffineExpr &other) const {
   return mlirAffineExprEqual(affineExpr, other.affineExpr);
 }
 
@@ -406,7 +406,7 @@ class PyAffineMapExprList
 };
 } // namespace
 
-bool PyAffineMap::operator==(const PyAffineMap &other) {
+bool PyAffineMap::operator==(const PyAffineMap &other) const {
   return mlirAffineMapEqual(affineMap, other.affineMap);
 }
 
@@ -483,7 +483,7 @@ class PyIntegerSetConstraintList
 };
 } // namespace
 
-bool PyIntegerSet::operator==(const PyIntegerSet &other) {
+bool PyIntegerSet::operator==(const PyIntegerSet &other) const {
   return mlirIntegerSetEqual(integerSet, other.integerSet);
 }
 

diff  --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index 8d637ea2b4abf..f2d3780a4aa3c 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -1736,7 +1736,7 @@ void PyInsertionPoint::contextExit(const pybind11::object &excType,
 // PyAttribute.
 //------------------------------------------------------------------------------
 
-bool PyAttribute::operator==(const PyAttribute &other) {
+bool PyAttribute::operator==(const PyAttribute &other) const {
   return mlirAttributeEqual(attr, other.attr);
 }
 
@@ -1768,7 +1768,7 @@ PyNamedAttribute::PyNamedAttribute(MlirAttribute attr, std::string ownedName)
 // PyType.
 //------------------------------------------------------------------------------
 
-bool PyType::operator==(const PyType &other) {
+bool PyType::operator==(const PyType &other) const {
   return mlirTypeEqual(type, other.type);
 }
 

diff  --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h
index fc236b1c68ecb..920e6f467c5bc 100644
--- a/mlir/lib/Bindings/Python/IRModule.h
+++ b/mlir/lib/Bindings/Python/IRModule.h
@@ -808,7 +808,7 @@ class PyType : public BaseContextObject {
 public:
   PyType(PyMlirContextRef contextRef, MlirType type)
       : BaseContextObject(std::move(contextRef)), type(type) {}
-  bool operator==(const PyType &other);
+  bool operator==(const PyType &other) const;
   operator MlirType() const { return type; }
   MlirType get() const { return type; }
 
@@ -878,7 +878,7 @@ class PyAttribute : public BaseContextObject {
 public:
   PyAttribute(PyMlirContextRef contextRef, MlirAttribute attr)
       : BaseContextObject(std::move(contextRef)), attr(attr) {}
-  bool operator==(const PyAttribute &other);
+  bool operator==(const PyAttribute &other) const;
   operator MlirAttribute() const { return attr; }
   MlirAttribute get() const { return attr; }
 
@@ -1003,7 +1003,7 @@ class PyAffineExpr : public BaseContextObject {
 public:
   PyAffineExpr(PyMlirContextRef contextRef, MlirAffineExpr affineExpr)
       : BaseContextObject(std::move(contextRef)), affineExpr(affineExpr) {}
-  bool operator==(const PyAffineExpr &other);
+  bool operator==(const PyAffineExpr &other) const;
   operator MlirAffineExpr() const { return affineExpr; }
   MlirAffineExpr get() const { return affineExpr; }
 
@@ -1030,7 +1030,7 @@ class PyAffineMap : public BaseContextObject {
 public:
   PyAffineMap(PyMlirContextRef contextRef, MlirAffineMap affineMap)
       : BaseContextObject(std::move(contextRef)), affineMap(affineMap) {}
-  bool operator==(const PyAffineMap &other);
+  bool operator==(const PyAffineMap &other) const;
   operator MlirAffineMap() const { return affineMap; }
   MlirAffineMap get() const { return affineMap; }
 
@@ -1051,7 +1051,7 @@ class PyIntegerSet : public BaseContextObject {
 public:
   PyIntegerSet(PyMlirContextRef contextRef, MlirIntegerSet integerSet)
       : BaseContextObject(std::move(contextRef)), integerSet(integerSet) {}
-  bool operator==(const PyIntegerSet &other);
+  bool operator==(const PyIntegerSet &other) const;
   operator MlirIntegerSet() const { return integerSet; }
   MlirIntegerSet get() const { return integerSet; }
 


        


More information about the Mlir-commits mailing list