Skip to content

Commit 9cd2413

Browse files
authored
[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.
1 parent 5199489 commit 9cd2413

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,9 @@ static LogicalResult verifyInitializationAttribute(Operation *op,
171171
/// In the format string, all `{}` are replaced by Placeholders, except if the
172172
/// `{` is escaped by `{{` - then it doesn't start a placeholder.
173173
template <class ArgType>
174-
FailureOr<SmallVector<ReplacementItem>>
175-
parseFormatString(StringRef toParse, ArgType fmtArgs,
176-
std::optional<llvm::function_ref<mlir::InFlightDiagnostic()>>
177-
emitError = {}) {
174+
FailureOr<SmallVector<ReplacementItem>> parseFormatString(
175+
StringRef toParse, ArgType fmtArgs,
176+
llvm::function_ref<mlir::InFlightDiagnostic()> emitError = {}) {
178177
SmallVector<ReplacementItem> items;
179178

180179
// If there are not operands, the format string is not interpreted.
@@ -197,8 +196,7 @@ parseFormatString(StringRef toParse, ArgType fmtArgs,
197196
continue;
198197
}
199198
if (toParse.size() < 2) {
200-
return (*emitError)()
201-
<< "expected '}' after unescaped '{' at end of string";
199+
return emitError() << "expected '}' after unescaped '{' at end of string";
202200
}
203201
// toParse contains at least two characters and starts with `{`.
204202
char nextChar = toParse[1];
@@ -214,8 +212,8 @@ parseFormatString(StringRef toParse, ArgType fmtArgs,
214212
continue;
215213
}
216214

217-
if (emitError.has_value()) {
218-
return (*emitError)() << "expected '}' after unescaped '{'";
215+
if (emitError) {
216+
return emitError() << "expected '}' after unescaped '{'";
219217
}
220218
return failure();
221219
}

0 commit comments

Comments
 (0)