[Mlir-commits] [mlir] 9cd2413 - [MLIR][EmitC][NFC] Use `llvm::function_ref<>` instead of `std::optional<llvm::function_ref<>>` (#146478)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 24 17:59:12 PDT 2025
Author: Yanzuo Liu
Date: 2025-07-25T08:59:09+08:00
New Revision: 9cd2413601f809fdb6c011743eb37b1321d5ab17
URL: https://github.com/llvm/llvm-project/commit/9cd2413601f809fdb6c011743eb37b1321d5ab17
DIFF: https://github.com/llvm/llvm-project/commit/9cd2413601f809fdb6c011743eb37b1321d5ab17.diff
LOG: [MLIR][EmitC][NFC] Use `llvm::function_ref<>` instead of `std::optional<llvm::function_ref<>>` (#146478)
There is no need to distinguish between null `optional` and null
`function_ref` in this case.
Added:
Modified:
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index 568da8905cbc8..4c0902293cbf9 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -171,10 +171,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.
@@ -197,8 +196,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];
@@ -214,8 +212,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