[MLIR] Add a non-const ActionHandler getter to MLIRContext#199652
Conversation
|
Hello @akigyosi 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Kigyosi Alexandru (akigyosi) ChangesFull diff: https://github.com/llvm/llvm-project/pull/199652.diff 2 Files Affected:
diff --git a/mlir/include/mlir/IR/MLIRContext.h b/mlir/include/mlir/IR/MLIRContext.h
index ab121777a1296..d2e0c4a9a1b7f 100644
--- a/mlir/include/mlir/IR/MLIRContext.h
+++ b/mlir/include/mlir/IR/MLIRContext.h
@@ -269,7 +269,8 @@ class MLIRContext {
/// Return a reference to the currently registered action handler. Its target
/// can be used to gain access to the handler's state, if any.
- const HandlerTy &getActionHandler();
+ const HandlerTy &getActionHandler() const;
+ HandlerTy &getActionHandler();
/// Return true if a valid ActionHandler is set.
bool hasActionHandler();
diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index 624121c2733ba..da891a7e6e014 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -380,7 +380,11 @@ void MLIRContext::registerActionHandler(HandlerTy handler) {
getImpl().actionHandler = std::move(handler);
}
-const MLIRContext::HandlerTy &MLIRContext::getActionHandler() {
+const MLIRContext::HandlerTy &MLIRContext::getActionHandler() const {
+ return getImpl().actionHandler;
+}
+
+MLIRContext::HandlerTy &MLIRContext::getActionHandler() {
return getImpl().actionHandler;
}
|
|
You have some CI failures to look at here. Here is copilot report: Root cause The failing compile is in mlir/lib/IR/MLIRContext.cpp at line 384: const MLIRContext::HandlerTy &MLIRContext::getActionHandler() const {
return getImpl().actionHandler;
}But in mlir/include/mlir/IR/MLIRContext.h, getImpl() is only declared as non-const: MLIRContextImpl &getImpl() { return *impl; }So the const overload of getActionHandler() tries to call a non-const member on const MLIRContext, which Clang correctly rejects: error in MLIRContext.cpp:384 Add a const overload of getImpl() in MLIRContext.h. Suggested patch: // This is effectively private given that only MLIRContext.cpp can see the
// MLIRContextImpl type.
MLIRContextImpl &getImpl() { return *impl; }
const MLIRContextImpl &getImpl() const { return *impl; }Why this is the right fix
Other const member functions can then safely access implementation state through getImpl(). In mlir/include/mlir/IR/MLIRContext.h, change: MLIRContextImpl &getImpl() { return *impl; }to: MLIRContextImpl &getImpl() { return *impl; }
const MLIRContextImpl &getImpl() const { return *impl; } |
Head branch was pushed to by a user without write access
3e3ec69 to
9255e23
Compare
|
@akigyosi Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/44980 Here is the relevant piece of the build log for the reference |
#197230 added a getter for the ActionHandler, but only returns a const ref with a non-const accessor.
Instead provide both variants: a const accessor returning a const ref and non-const one returning a mutable ref.