[Mlir-commits] [mlir] [MLIR] Add a non-const ActionHandler getter to MLIRContext (PR #199652)
Mehdi Amini
llvmlistbot at llvm.org
Tue May 26 03:29:07 PDT 2026
joker-eph wrote:
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](https://github.com/llvm/llvm-project/blob/fd161348c045112ae0a4511264ccb7dc05f1dfee/mlir/lib/IR/MLIRContext.cpp) at line 384:
```C++
const MLIRContext::HandlerTy &MLIRContext::getActionHandler() const {
return getImpl().actionHandler;
}
```
But in [mlir/include/mlir/IR/MLIRContext.h](https://github.com/llvm/llvm-project/blob/fd161348c045112ae0a4511264ccb7dc05f1dfee/mlir/include/mlir/IR/MLIRContext.h#L213), getImpl() is only declared as non-const:
```C++
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
note pointing to MLIRContext.h:213
Fix
Add a const overload of getImpl() in MLIRContext.h.
Suggested patch:
```C++
// 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
- It preserves the existing API shape.
- It matches the intended use of getActionHandler() const.
- It avoids unsafe casts or making getActionHandler() const non-const.
Other const member functions can then safely access implementation state through getImpl().
Minimal code change
In [mlir/include/mlir/IR/MLIRContext.h](https://github.com/llvm/llvm-project/blob/fd161348c045112ae0a4511264ccb7dc05f1dfee/mlir/include/mlir/IR/MLIRContext.h), change:
```C++
MLIRContextImpl &getImpl() { return *impl; }
```
to:
```C++
MLIRContextImpl &getImpl() { return *impl; }
const MLIRContextImpl &getImpl() const { return *impl; }
```
https://github.com/llvm/llvm-project/pull/199652
More information about the Mlir-commits
mailing list