[Mlir-commits] [mlir] [mlir][python] Add location source composition to loc_tracebacks() (PR #192310)
Maksim Levental
llvmlistbot at llvm.org
Fri Apr 17 09:59:42 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)) {
----------------
makslevental wrote:
lol man unrelated to this PR - i definitely named this `mlirLocationIsAName` thing wrong lol (should probably be `mlirLocationIsANameLoc`)
https://github.com/llvm/llvm-project/pull/192310
More information about the Mlir-commits
mailing list