Skip to content

Commit 9538e20

Browse files
committed
moved test impl
1 parent 417ed76 commit 9538e20

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

mlir/test/python/ir/diagnostic_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import gc
44
from mlir.ir import *
55
from mlir._mlir_libs._mlirPythonTestNanobind import (
6-
test_diagnostics_with_errors_and_notes,
6+
test_diagnostics_with_errors_and_notes,
77
)
88

99

@@ -236,5 +236,5 @@ def testBuiltInDiagnosticsHandler():
236236
test_diagnostics_with_errors_and_notes(ctx)
237237
except ValueError as e:
238238
# CHECK: created error
239-
# CHECK: MLIRPythonCAPI
239+
# CHECK: attached note
240240
print(e)

mlir/test/python/lib/PythonTestCAPI.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "mlir-c/BuiltinTypes.h"
1212
#include "mlir/CAPI/Registration.h"
1313
#include "mlir/CAPI/Wrap.h"
14+
#include "mlir/IR/Diagnostics.h"
15+
#include "mlir/IR/Location.h"
1416

1517
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PythonTest, python_test,
1618
python_test::PythonTestDialect)
@@ -42,3 +44,9 @@ MlirTypeID mlirPythonTestTestTypeGetTypeID(void) {
4244
bool mlirTypeIsAPythonTestTestTensorValue(MlirValue value) {
4345
return mlirTypeIsATensor(wrap(unwrap(value).getType()));
4446
}
47+
48+
void mlirPythonTestEmitDiagnosticWithNote(MlirContext ctx) {
49+
auto diag =
50+
mlir::emitError(unwrap(mlirLocationUnknownGet(ctx)), "created error");
51+
diag.attachNote() << "attached note";
52+
}

mlir/test/python/lib/PythonTestCAPI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define MLIR_TEST_PYTHON_LIB_PYTHONTESTCAPI_H
1111

1212
#include "mlir-c/IR.h"
13+
#include "mlir-c/Support.h"
1314

1415
#ifdef __cplusplus
1516
extern "C" {
@@ -33,6 +34,8 @@ MLIR_CAPI_EXPORTED MlirTypeID mlirPythonTestTestTypeGetTypeID(void);
3334

3435
MLIR_CAPI_EXPORTED bool mlirTypeIsAPythonTestTestTensorValue(MlirValue value);
3536

37+
MLIR_CAPI_EXPORTED void mlirPythonTestEmitDiagnosticWithNote(MlirContext ctx);
38+
3639
#ifdef __cplusplus
3740
}
3841
#endif

mlir/test/python/lib/PythonTestModuleNanobind.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ NB_MODULE(_mlirPythonTestNanobind, m) {
5252
mlirContextPrintStackTraceOnDiagnostic(ctx, true);
5353
mlir::python::CollectDiagnosticsToStringScope handler(ctx);
5454

55-
auto loc = mlirLocationUnknownGet(ctx);
56-
mlirEmitError(loc, "created error");
55+
mlirPythonTestEmitDiagnosticWithNote(ctx);
5756
throw nb::value_error(handler.takeMessage().c_str());
5857
});
5958

0 commit comments

Comments
 (0)