[Mlir-commits] [mlir] 6179131 - [mlir] explicitly delete copy ctor for DialectRegistry and OperationState (#140963)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri May 23 04:23:56 PDT 2025


Author: Maksim Levental
Date: 2025-05-23T07:23:53-04:00
New Revision: 617913150a0965ac2d549a569c0ce6ed14a05aed

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

LOG: [mlir] explicitly delete copy ctor for DialectRegistry and OperationState (#140963)

Both of these classes have fields involving `unique_ptr`s and thus can't
be copied.
Holding a unique_ptr should trigger implicit deletion of the
copy/assignment constructors, however
not when held through a container:

```
struct Foo {  
  explicit Foo();
  std::vector<std::unique_ptr<Bar>> ptr; // Does not implicitly delete its cpy/assign ctors
};
```

This results in a complicated diagnostics when attempting to copy such a
class (it'll point to the
inner implementation of the container), instead of a nicer error message
about `Foo` not being able
to be copied/assigned. Explicitly deleting the ctors provides an
immediate diagnostic about the issue.

Fixes https://github.com/llvm/llvm-project/issues/118388

Added: 
    

Modified: 
    mlir/include/mlir/IR/DialectRegistry.h
    mlir/include/mlir/IR/OperationSupport.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/DialectRegistry.h b/mlir/include/mlir/IR/DialectRegistry.h
index d3d53488fe72d..7bcf1eda7c636 100644
--- a/mlir/include/mlir/IR/DialectRegistry.h
+++ b/mlir/include/mlir/IR/DialectRegistry.h
@@ -143,6 +143,8 @@ class DialectRegistry {
 
 public:
   explicit DialectRegistry();
+  DialectRegistry(const DialectRegistry &) = delete;
+  DialectRegistry &operator=(const DialectRegistry &other) = delete;
 
   template <typename ConcreteDialect>
   void insert() {

diff  --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 2d9fb2bc5859e..0046d977c68f4 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -985,9 +985,9 @@ struct OperationState {
                  BlockRange successors = {},
                  MutableArrayRef<std::unique_ptr<Region>> regions = {});
   OperationState(OperationState &&other) = default;
-  OperationState(const OperationState &other) = default;
   OperationState &operator=(OperationState &&other) = default;
-  OperationState &operator=(const OperationState &other) = default;
+  OperationState(const OperationState &other) = delete;
+  OperationState &operator=(const OperationState &other) = delete;
   ~OperationState();
 
   /// Get (or create) a properties of the provided type to be set on the


        


More information about the Mlir-commits mailing list