lean4-htt/src/runtime
Leonardo de Moura a79c6c44ff
feat: add Lean name demangling to runtime backtraces (#12533)
This PR adds human-friendly demangling of Lean symbol names in runtime
backtraces. When a Lean program panics, stack traces now show readable
names instead of mangled C identifiers.

**Before:**
```
3   libleanshared.dylib  0x1119afab4 l_Lean_Meta_Grind_main___redArg___lam__0___boxed + 52
5   libleanshared.dylib  0x10db232fc l_Lean_profileitIOUnsafe___redArg___lam__0 + 20
14  libleanshared.dylib  0x11204ec80 l___private_Lean_Meta_Tactic_Grind_Main_0__Lean_Meta_Grind_withProtectedMCtx_main___at___00Lean_Meta_Grind_withProtectedMCtx___at___00Lean_Elab_Tactic_grind_spec__1_spec__1___redArg___lam__0 + 516
17  libleanshared.dylib  0x10de2aa24 l___private_Lean_Meta_Basic_0__Lean_Meta_withNewMCtxDepthImp___redArg + 648
```

**After:**
```
3   libleanshared.dylib  0x1119afab4 Lean.Meta.Grind.main [boxed, λ, arity↓] + 52
5   libleanshared.dylib  0x10db232fc Lean.profileitIOUnsafe [λ, arity↓] + 20
14  libleanshared.dylib  0x11204ec80 Lean.Meta.Grind.withProtectedMCtx.main [private] spec at Lean.Meta.Grind.withProtectedMCtx spec at Lean.Elab.Tactic.grind[arity↓, λ] + 516
17  libleanshared.dylib  0x10de2aa24 Lean.Meta.withNewMCtxDepthImp [arity↓, private] + 648
```

The demangler is a C++ port of `Name.demangleAux` from
`NameMangling.lean` with human-friendly postprocessing:
- Suffix folding: `_redArg` → `[arity↓]`, `_boxed` → `[boxed]`, `_lam_N`
→ `[λ]`, `_closed_N` → `[closed]`, `_jp_N` → `[jp]`
- Private name cleanup: `_private.Module.0.Name.foo` → `Name.foo
[private]`
- Specialization context: `_at_`/`_spec` → `spec at ...`
- Hygienic suffix stripping: `_@` onward removed
- Runtime helpers: `lean_apply_N` → `<apply/N>`
- LLVM artifacts: `.cold.N` suffix preserved

Supports both macOS and Linux `backtrace_symbols` formats.

Set `LEAN_BACKTRACE_RAW=1` to disable demangling and get raw symbol
names.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 19:20:54 +00:00
..
uv fix: Signal.Handler segmentation fault with Selector (#11724) 2025-12-27 02:07:00 +00:00
alloc.cpp fix: heartbeats from realizeConst should be ignored (#7473) 2025-03-13 15:10:29 +00:00
alloc.h fix: heartbeats from realizeConst should be ignored (#7473) 2025-03-13 15:10:29 +00:00
allocprof.cpp
allocprof.h
apply.cpp fix: deallocation for closures in non default configurations (#11217) 2025-11-17 16:27:20 +00:00
apply.h
array_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
buffer.h chore: update to c++20 (#12117) 2026-02-11 01:17:40 +00:00
byteslice.cpp feat: add useful functions in Parsec, add error variant and Std.Data.ByteSlice (#9599) 2025-09-11 14:53:41 +00:00
byteslice.h feat: add useful functions in Parsec, add error variant and Std.Data.ByteSlice (#9599) 2025-09-11 14:53:41 +00:00
CMakeLists.txt feat: add Lean name demangling to runtime backtraces (#12533) 2026-02-17 19:20:54 +00:00
compact.cpp fix: ensure padding bytes for lean::mpz objects in olean files are zero (#11485) 2025-12-09 10:59:15 +00:00
compact.h fix: ensure padding bytes for lean::mpz objects in olean files are zero (#11485) 2025-12-09 10:59:15 +00:00
debug.cpp refactor: port shell option processing to Lean (v2) (#11434) 2025-12-02 17:41:51 +00:00
debug.h
demangle.cpp feat: add Lean name demangling to runtime backtraces (#12533) 2026-02-17 19:20:54 +00:00
demangle.h feat: add Lean name demangling to runtime backtraces (#12533) 2026-02-17 19:20:54 +00:00
exception.cpp doc: add link to reference manual in stack overflow message (#12157) 2026-01-26 07:56:48 +00:00
exception.h
flet.h
hash.cpp fix: avoid unaligned pointer dereference (#12318) 2026-02-10 20:40:24 +00:00
hash.h
init_module.cpp
init_module.h
int.h
interrupt.cpp chore: update to c++20 (#12117) 2026-02-11 01:17:40 +00:00
interrupt.h
io.cpp fix: handle 0 sized reads from handles correctly (#12466) 2026-02-13 10:56:00 +00:00
io.h fix: handle NUL bytes in IO functions (#9616) 2025-08-01 06:12:53 +00:00
libuv.cpp feat: add signal handling support using libuv (#9258) 2025-09-15 13:09:50 +00:00
libuv.h feat: add signal handling support using libuv (#9258) 2025-09-15 13:09:50 +00:00
list_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
memory.cpp feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
memory.h
mpn.cpp
mpn.h
mpz.cpp fix: call delete [] on array allocations (#11453) 2025-12-10 16:51:54 +00:00
mpz.h feat: optimized division without remainder for Int and Nat (#8089) 2025-04-29 07:23:35 +00:00
mutex.cpp refactor: don't use shared_timed_mutex when not required anymore (#12434) 2026-02-11 12:53:42 +00:00
mutex.h
object.cpp feat: add Lean name demangling to runtime backtraces (#12533) 2026-02-17 19:20:54 +00:00
object.h fix: revert the waitAny refactoring (#11000) 2025-10-29 08:27:16 +00:00
object_ref.cpp
object_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
option_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
optional.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
pair_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
platform.cpp feat: ignore lean -R if module name is in setup (#8874) 2025-06-23 17:55:52 +00:00
platform.h
process.cpp fix: IO.Process.spawn empty env var on Windows (#12220) 2026-01-31 19:17:26 +00:00
process.h
sharecommon.cpp feat: support mpz in the shareCommon APIs (#7838) 2025-04-06 19:52:50 +00:00
sharecommon.h perf: use mimalloc with important C++ hash maps (#7868) 2025-04-11 16:23:33 +00:00
sstream.h
stack_overflow.cpp
stack_overflow.h
stackinfo.cpp
stackinfo.h
string_ref.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
thread.cpp refactor: port shell option processing to Lean (v2) (#11434) 2025-12-02 17:41:51 +00:00
thread.h refactor: don't use shared_timed_mutex when not required anymore (#12434) 2026-02-11 12:53:42 +00:00
utf8.cpp
utf8.h