19#ifndef MLIR_DIALECT_TRANSFORM_UTILS_DIAGNOSEDSILENCEABLEFAILURE_H
20#define MLIR_DIALECT_TRANSFORM_UTILS_DIAGNOSEDSILENCEABLEFAILURE_H
72 LogicalResult checkAndReport();
76 return ::mlir::succeeded(result) && diagnostics.empty();
81 return ::mlir::failed(result) && diagnostics.empty();
91 for (
auto &diagnostic : diagnostics) {
92 res.append(diagnostic.str());
103 return "silenceable failure";
104 return "definite failure";
110 if (!diagnostics.empty()) {
112 result = ::mlir::success();
119 assert(!diagnostics.empty() &&
"expected a diagnostic to be present");
120 diags.append(std::make_move_iterator(diagnostics.begin()),
121 std::make_move_iterator(diagnostics.end()));
126 template <
typename T>
129 "can only append output in silenceable failure state");
130 diagnostics.back() << std::forward<T>(value);
133 template <
typename T>
135 return std::move(this->
operator<<(std::forward<T>(value)));
142 "can only attach notes to silenceable failures");
143 return diagnostics.back().attachNote(loc);
148 explicit DiagnosedSilenceableFailure(Diagnostic &&diagnostic)
150 diagnostics.emplace_back(std::move(diagnostic));
152 explicit DiagnosedSilenceableFailure(SmallVector<Diagnostic> &&diagnostics)
153 : diagnostics(std::move(diagnostics)),
result(failure()) {}
158 SmallVector<Diagnostic, 1> diagnostics;
164#if LLVM_ENABLE_ABI_BREAKING_CHECKS
169 bool reported =
false;
176 const Twine &message = {});
186 const Twine &message);
193 template <
typename T>
195 diag << std::forward<T>(value);
198 template <
typename T>
200 return std::move(this->
operator<<(std::forward<T>(value)));
217 operator LogicalResult() {
236 InFlightDiagnostic
diag;
244 const Twine &message) {
248 const Twine &message = {}) {
static std::string diag(const llvm::Value &value)
A compatibility class connecting InFlightDiagnostic to DiagnosedSilenceableFailure while providing an...
DiagnosedDefiniteFailure & operator<<(T &&value) &
Forward the message to the diagnostic.
friend DiagnosedDefiniteFailure emitDefiniteFailure(Location loc, const Twine &message)
Emits a definite failure with the given message.
DiagnosedDefiniteFailure && operator<<(T &&value) &&
DiagnosedDefiniteFailure(DiagnosedDefiniteFailure &&)=default
Only move-constructible because it carries an in-flight diagnostic.
Diagnostic & attachNote(std::optional< Location > loc=std::nullopt)
Attaches a note to the error.
The result of a transform IR operation application.
LogicalResult silence()
Converts silenceable failure into LogicalResult success without reporting the diagnostic,...
DiagnosedSilenceableFailure & operator=(DiagnosedSilenceableFailure &&)=default
static DiagnosedSilenceableFailure success()
Constructs a DiagnosedSilenceableFailure in the success state.
std::string getStatusString() const
Returns a string representation of the failure mode (for error reporting).
std::string getMessage() const
Returns the diagnostic message without emitting it.
DiagnosedSilenceableFailure(DiagnosedSilenceableFailure &&)=default
bool isDefiniteFailure() const
Returns true if this is a definite failure.
static DiagnosedSilenceableFailure silenceableFailure(SmallVector< Diagnostic > &&diag)
Diagnostic & attachNote(std::optional< Location > loc=std::nullopt)
Attaches a note to the last diagnostic.
DiagnosedSilenceableFailure(const DiagnosedSilenceableFailure &)=delete
static DiagnosedSilenceableFailure silenceableFailure(Diagnostic &&diag)
Constructs a DiagnosedSilenceableFailure in the silenceable failure state, ready to emit the given di...
void takeDiagnostics(SmallVectorImpl< Diagnostic > &diags)
Take the diagnostics and silence.
DiagnosedSilenceableFailure & operator=(const DiagnosedSilenceableFailure &)=delete
bool succeeded() const
Returns true if this is a success.
static DiagnosedSilenceableFailure definiteFailure()
Constructs a DiagnosedSilenceableFailure in the failure state.
DiagnosedSilenceableFailure && operator<<(T &&value) &&
DiagnosedSilenceableFailure & operator<<(T &&value) &
Streams the given values into the last diagnostic.
bool isSilenceableFailure() const
Returns true if this is a silenceable failure.
This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine.
Diagnostic & attachNote(std::optional< Location > noteLoc=std::nullopt)
Attaches a note to this diagnostic.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Operation is the basic unit of execution within MLIR.
Location getLoc()
The source location the operation was defined or derived from.
Include the generated interface declarations.
DiagnosedSilenceableFailure emitSilenceableFailure(Location loc, const Twine &message={})
Emits a silenceable failure with the given message.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
DiagnosedDefiniteFailure emitDefiniteFailure(Location loc, const Twine &message={})
Emits a definite failure with the given message.