Skip to content

Commit 6179131

Browse files
authored
[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 #118388
1 parent 6db8490 commit 6179131

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

mlir/include/mlir/IR/DialectRegistry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class DialectRegistry {
143143

144144
public:
145145
explicit DialectRegistry();
146+
DialectRegistry(const DialectRegistry &) = delete;
147+
DialectRegistry &operator=(const DialectRegistry &other) = delete;
146148

147149
template <typename ConcreteDialect>
148150
void insert() {

mlir/include/mlir/IR/OperationSupport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,9 @@ struct OperationState {
985985
BlockRange successors = {},
986986
MutableArrayRef<std::unique_ptr<Region>> regions = {});
987987
OperationState(OperationState &&other) = default;
988-
OperationState(const OperationState &other) = default;
989988
OperationState &operator=(OperationState &&other) = default;
990-
OperationState &operator=(const OperationState &other) = default;
989+
OperationState(const OperationState &other) = delete;
990+
OperationState &operator=(const OperationState &other) = delete;
991991
~OperationState();
992992

993993
/// Get (or create) a properties of the provided type to be set on the

0 commit comments

Comments
 (0)