[Mlir-commits] [mlir] 4fec44b - [mlir] Allow Diagnostic/InFlightDiagnostic to convert to FailureOr.

River Riddle llvmlistbot at llvm.org
Wed Mar 30 01:47:08 PDT 2022


Author: bzcheeseman
Date: 2022-03-30T01:37:20-07:00
New Revision: 4fec44b0e63d0dcde0897cf55670ccc1748c8654

URL: https://github.com/llvm/llvm-project/commit/4fec44b0e63d0dcde0897cf55670ccc1748c8654
DIFF: https://github.com/llvm/llvm-project/commit/4fec44b0e63d0dcde0897cf55670ccc1748c8654.diff

LOG: [mlir] Allow Diagnostic/InFlightDiagnostic to convert to FailureOr.

Allow conversion of a diagnostic to FailureOr. This conversion only results
in `failure` because in the case where operator LogicalResult would return
success, the FailureOr constructor would assert.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D122596

Added: 
    

Modified: 
    mlir/include/mlir/IR/Diagnostics.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h
index 97f333abc2288..600a6f97ca3b5 100644
--- a/mlir/include/mlir/IR/Diagnostics.h
+++ b/mlir/include/mlir/IR/Diagnostics.h
@@ -265,6 +265,13 @@ class Diagnostic {
   /// Allow a diagnostic to be converted to 'failure'.
   operator LogicalResult() const;
 
+  /// Allow a diagnostic to be converted to FailureOr<T>. Always results in
+  /// 'failure' because this cast cannot possibly return an object of 'T'.
+  template <typename T>
+  operator FailureOr<T>() const {
+    return failure();
+  }
+
 private:
   Diagnostic(const Diagnostic &rhs) = delete;
   Diagnostic &operator=(const Diagnostic &rhs) = delete;
@@ -347,6 +354,14 @@ class InFlightDiagnostic {
   /// 'success' if this is an empty diagnostic.
   operator LogicalResult() const;
 
+  /// Allow an inflight diagnostic to be converted to FailureOr<T>. Always
+  /// results in 'failure' because this cast cannot possibly return an object of
+  /// 'T'.
+  template <typename T>
+  operator FailureOr<T>() const {
+    return failure();
+  }
+
 private:
   InFlightDiagnostic &operator=(const InFlightDiagnostic &) = delete;
   InFlightDiagnostic &operator=(InFlightDiagnostic &&) = delete;


        


More information about the Mlir-commits mailing list