[Mlir-commits] [mlir] [docs]: Add a note about using custom types with diagnostics (PR #73818)

Jeremy Kun llvmlistbot at llvm.org
Thu Feb 8 11:03:58 PST 2024


https://github.com/j2kun updated https://github.com/llvm/llvm-project/pull/73818

>From 0cf9fca9e0c19bb35a17f339fe2772647dd8a92c Mon Sep 17 00:00:00 2001
From: Jeremy Kun <jkun at google.com>
Date: Wed, 29 Nov 2023 08:46:49 -0800
Subject: [PATCH] add note about custom types with diagnostics

---
 mlir/docs/Diagnostics.md | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mlir/docs/Diagnostics.md b/mlir/docs/Diagnostics.md
index 9819843c563ca4..82bc61dd8c3adf 100644
--- a/mlir/docs/Diagnostics.md
+++ b/mlir/docs/Diagnostics.md
@@ -119,6 +119,14 @@ op->emitError() << anotherOp;
 op->emitRemark() << anotherOp;
 ```
 
+To make a custom type compatible with Diagnostics, one must implement the
+following friend function.
+
+```c++
+friend mlir::Diagnostic &operator<<(
+    mlir::Diagnostic &diagnostic, const MyType &foo);
+```
+
 ### Attaching notes
 
 Unlike many other compiler frameworks, notes in MLIR cannot be emitted directly.



More information about the Mlir-commits mailing list