[Mlir-commits] [mlir] [MLIR] [Python] a few more fixes to type annotaitons (PR #186106)
Sergei Lebedev
llvmlistbot at llvm.org
Thu Mar 12 09:57:44 PDT 2026
================
@@ -2774,6 +2774,74 @@ namespace mlir {
namespace python {
namespace MLIR_BINDINGS_PYTHON_DOMAIN {
+static std::string formatMLIRError(const MLIRError &e) {
+ auto locStr = [](const PyLocation &loc) {
+ PyPrintAccumulator accum;
+ mlirLocationPrint(loc, accum.getCallback(), accum.getUserData());
+ std::string s = nb::cast<std::string>(nb::str(accum.join()));
+ std::string_view sv(s);
+ if (sv.size() > 5) {
+ sv.remove_prefix(4); // "loc("
+ sv.remove_suffix(1); // ")"
+ }
+ return std::string(sv);
+ };
+ auto indent = [](std::string s) {
+ size_t pos = 0;
+ while ((pos = s.find('\n', pos)) != std::string::npos) {
+ s.replace(pos, 1, "\n ");
+ pos += 3;
+ }
+ return s;
+ };
+
+ std::ostringstream os;
+ os << e.message;
+ if (!e.errorDiagnostics.empty())
+ os << ":";
+ for (const auto &diag : e.errorDiagnostics) {
+ os << "\nerror: " << locStr(diag.location) << ": " << indent(diag.message);
+ for (const auto ¬e : diag.notes)
+ os << "\n note: " << locStr(note.location) << ": "
+ << indent(note.message);
----------------
superbobry wrote:
Done. I'm surprised clang-format didn't do it automatically.
https://github.com/llvm/llvm-project/pull/186106
More information about the Mlir-commits
mailing list