-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir] explicitly delete copy ctor for DialectRegistry and OperationState #140963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ With the latest revision this PR passed the C/C++ code formatter. |
e9c59f7
to
2ab8db2
Compare
2ab8db2
to
3953c73
Compare
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Maksim Levental (makslevental) ChangesBoth of these classes have fields involving Fixes #118388 Full diff: https://github.com/llvm/llvm-project/pull/140963.diff 2 Files Affected:
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
|
cc @0xddom |
I checked |
Is this expected that explicitly deleting these should change the behavior compared to have them implicitly deleted because of the unique_ptr member? I feel like the title/description should elaborate bit more on what's going on here and what are we "fixing". |
For |
the problem is they are not being implicitly deleted because (as the original issue documents)
updated |
I don't get it what you mean by "they are not being implicitly deleted", we can't copy DialectRegistry right now can we?
Maybe but neither the description/title here neither the bug are very clear to me on what's happening actually. The title here says: "explicitly delete copy ctor to prevent copying DialectRegistry and OperationState", which implies that right now without explicitly deleting them we can copy them. But how do you copy them today? Here is a minimal test cases showing why the current description of the issue is confusing to me:
Yield:
(same with the copy ctor). Can you provide a test showing what was failing before and is failing now? |
Or is this patch an "improve diagnostics" kind of thing? Having |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG with the updated description.
@@ -143,6 +143,8 @@ class DialectRegistry { | |||
|
|||
public: | |||
explicit DialectRegistry(); | |||
DialectRegistry(const DialectRegistry &) = delete; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this unintentionally changes the behavior to not allowing moving of DialectRegistry
, I'll create a patch to add the explicit move constructor
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:
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 ableto be copied/assigned. Explicitly deleting the ctors provides an immediate diagnostic about the issue.
Fixes #118388