diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h --- a/mlir/include/mlir/IR/Diagnostics.h +++ b/mlir/include/mlir/IR/Diagnostics.h @@ -265,6 +265,9 @@ /// Allow a diagnostic to be converted to 'failure'. operator LogicalResult() const; + /// Allow a diagnostic to be converted to 'failure'. + operator ParseResult() const { return ParseResult(LogicalResult(*this)); } + /// Allow a diagnostic to be converted to FailureOr. Always results in /// 'failure' because this cast cannot possibly return an object of 'T'. template @@ -354,6 +357,10 @@ /// 'success' if this is an empty diagnostic. operator LogicalResult() const; + /// Allow an inflight diagnostic to be converted to 'failure', otherwise + /// 'success' if this is an empty diagnostic. + operator ParseResult() const { return ParseResult(LogicalResult(*this)); } + /// Allow an inflight diagnostic to be converted to FailureOr. Always /// results in 'failure' because this cast cannot possibly return an object of /// 'T'. diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -29,21 +29,6 @@ class Builder; class OpBuilder; -/// This class represents success/failure for operation parsing. It is -/// essentially a simple wrapper class around LogicalResult that allows for -/// explicit conversion to bool. This allows for the parser to chain together -/// parse rules without the clutter of "failed/succeeded". -class ParseResult : public LogicalResult { -public: - ParseResult(LogicalResult result = success()) : LogicalResult(result) {} - - // Allow diagnostics emitted during parsing to be converted to failure. - ParseResult(const InFlightDiagnostic &) : LogicalResult(failure()) {} - ParseResult(const Diagnostic &) : LogicalResult(failure()) {} - - /// Failure is true in a boolean context. - explicit operator bool() const { return failed(); } -}; /// This class implements `Optional` functionality for ParseResult. We don't /// directly use Optional here, because it provides an implicit conversion /// to 'bool' which we want to avoid. This class is used to implement tri-state diff --git a/mlir/include/mlir/Support/LogicalResult.h b/mlir/include/mlir/Support/LogicalResult.h --- a/mlir/include/mlir/Support/LogicalResult.h +++ b/mlir/include/mlir/Support/LogicalResult.h @@ -71,6 +71,18 @@ /// to a failure value. inline bool failed(LogicalResult result) { return result.failed(); } +/// This class represents success/failure for operation parsing. It is +/// essentially a simple wrapper class around LogicalResult that allows for +/// explicit conversion to bool. This allows for the parser to chain together +/// parse rules without the clutter of "failed/succeeded". +class ParseResult : public LogicalResult { +public: + ParseResult(LogicalResult result = success()) : LogicalResult(result) {} + + /// Failure is true in a boolean context. + explicit operator bool() const { return failed(); } +}; + /// This class provides support for representing a failure result, or a valid /// value of type `T`. This allows for integrating with LogicalResult, while /// also providing a value on the success path. diff --git a/mlir/lib/Tools/PDLL/AST/Diagnostic.cpp b/mlir/lib/Tools/PDLL/AST/Diagnostic.cpp --- a/mlir/lib/Tools/PDLL/AST/Diagnostic.cpp +++ b/mlir/lib/Tools/PDLL/AST/Diagnostic.cpp @@ -15,7 +15,7 @@ // InFlightDiagnostic //===----------------------------------------------------------------------===// -void InFlightDiagnostic::report() { +void mlir::pdll::ast::InFlightDiagnostic::report() { // If this diagnostic is still inflight and it hasn't been abandoned, then // report it. if (isInFlight()) {