[Mlir-commits] [mlir] [MLIR][EmitC][NFC] Use `llvm::function_ref<>` instead of `std::optional<llvm::function_ref<>>` (PR #146478)
Yanzuo Liu
llvmlistbot at llvm.org
Mon Jun 30 23:58:56 PDT 2025
https://github.com/zwuis created https://github.com/llvm/llvm-project/pull/146478
There is no need to distinguish between null `optional` and null `function_ref` in this case.
>From 00892a4ef1c110a7e968c226aec65a100c63b6cd Mon Sep 17 00:00:00 2001
From: Yanzuo Liu <zwuis at outlook.com>
Date: Tue, 1 Jul 2025 14:45:01 +0800
Subject: [PATCH] Use `llvm::function_ref<>` instead of
`std::optional<llvm::function_ref<>>`
---
mlir/lib/Dialect/EmitC/IR/EmitC.cpp | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index 27298e892e599..ba1d010d29062 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -174,10 +174,9 @@ static LogicalResult verifyInitializationAttribute(Operation *op,
/// In the format string, all `{}` are replaced by Placeholders, except if the
/// `{` is escaped by `{{` - then it doesn't start a placeholder.
template <class ArgType>
-FailureOr<SmallVector<ReplacementItem>>
-parseFormatString(StringRef toParse, ArgType fmtArgs,
- std::optional<llvm::function_ref<mlir::InFlightDiagnostic()>>
- emitError = {}) {
+FailureOr<SmallVector<ReplacementItem>> parseFormatString(
+ StringRef toParse, ArgType fmtArgs,
+ llvm::function_ref<mlir::InFlightDiagnostic()> emitError = {}) {
SmallVector<ReplacementItem> items;
// If there are not operands, the format string is not interpreted.
@@ -200,8 +199,7 @@ parseFormatString(StringRef toParse, ArgType fmtArgs,
continue;
}
if (toParse.size() < 2) {
- return (*emitError)()
- << "expected '}' after unescaped '{' at end of string";
+ return emitError() << "expected '}' after unescaped '{' at end of string";
}
// toParse contains at least two characters and starts with `{`.
char nextChar = toParse[1];
@@ -217,8 +215,8 @@ parseFormatString(StringRef toParse, ArgType fmtArgs,
continue;
}
- if (emitError.has_value()) {
- return (*emitError)() << "expected '}' after unescaped '{'";
+ if (emitError) {
+ return emitError() << "expected '}' after unescaped '{'";
}
return failure();
}
More information about the Mlir-commits
mailing list