From b15ccd436aef320802635984f336fcfe5b69ff0b Mon Sep 17 00:00:00 2001 From: Nikhil Kalra Date: Mon, 10 Mar 2025 15:59:47 -0700 Subject: [mlir] Better Python diagnostics (#128581) Updated the Python diagnostics handler to emit notes (in addition to errors) into the output stream so that users have more context as to where in the IR the error is occurring. --- mlir/test/python/lib/PythonTestCAPI.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'mlir/test/python/lib/PythonTestCAPI.cpp') diff --git a/mlir/test/python/lib/PythonTestCAPI.cpp b/mlir/test/python/lib/PythonTestCAPI.cpp index cb7d7677714f..ee6a5ae2d9c3 100644 --- a/mlir/test/python/lib/PythonTestCAPI.cpp +++ b/mlir/test/python/lib/PythonTestCAPI.cpp @@ -11,6 +11,8 @@ #include "mlir-c/BuiltinTypes.h" #include "mlir/CAPI/Registration.h" #include "mlir/CAPI/Wrap.h" +#include "mlir/IR/Diagnostics.h" +#include "mlir/IR/Location.h" MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PythonTest, python_test, python_test::PythonTestDialect) @@ -42,3 +44,9 @@ MlirTypeID mlirPythonTestTestTypeGetTypeID(void) { bool mlirTypeIsAPythonTestTestTensorValue(MlirValue value) { return mlirTypeIsATensor(wrap(unwrap(value).getType())); } + +void mlirPythonTestEmitDiagnosticWithNote(MlirContext ctx) { + auto diag = + mlir::emitError(unwrap(mlirLocationUnknownGet(ctx)), "created error"); + diag.attachNote() << "attached note"; +} -- cgit v1.2.3