[Mlir-commits] [mlir] [mlir][python] Add location source composition to loc_tracebacks() (PR #192310)
Alisson Azzolini
llvmlistbot at llvm.org
Fri Apr 17 10:01:20 PDT 2026
================
@@ -2734,17 +2735,71 @@ MlirLocation tracebackToLocation(MlirContext ctx) {
#endif
}
+/// Apply currentLocAction: wrap or fuse Location.current onto baseLoc.
+static MlirLocation
+applyCurrentLocAction(MlirContext ctx, MlirLocation baseLoc,
+ PyGlobals::TracebackLoc::CurrentLocAction action) {
+ using Action = PyGlobals::TracebackLoc::CurrentLocAction;
+ if (action == Action::Fallback)
+ return baseLoc;
+
+ auto *currentLoc = PyThreadContextEntry::getDefaultLocation();
+ if (!currentLoc)
+ return baseLoc;
+ assert(mlirLocationGetContext(currentLoc->get()).ptr == ctx.ptr &&
+ "Location.current must belong to the current MLIR context");
+
+ // NamelocWrap: walk the NameLoc chain on Location.current, collect scope
+ // names, wrap baseLoc innermost-first so result is Outer(Inner(baseLoc)).
+ // If Location.current is not a NameLoc, scopeNames is empty and baseLoc
+ // is returned unchanged (nameloc_wrap is a no-op for non-NameLoc contexts).
+ thread_local std::vector<MlirStringRef> scopeNames;
+ scopeNames.clear();
+ MlirLocation walk = currentLoc->get();
+ while (mlirLocationIsAName(walk)) {
----------------
aazzolini wrote:
we can change in the next PR, any concerns about API changes / backwards compat for this one?
https://github.com/llvm/llvm-project/pull/192310
More information about the Mlir-commits
mailing list