lean4-htt/src
Kim Morrison 5f3ca3ac3d
feat: unify name demangling with single Lean implementation (#12539)
This PR replaces three independent name demangling implementations
(Lean, C++, Python) with a single source of truth in
`Lean.Compiler.NameDemangling`. The new module handles the full
pipeline: prefix parsing (`l_`, `lp_`, `_init_`, `initialize_`,
`lean_apply_N`, `_lean_main`), postprocessing (suffix flags, private
name stripping, hygienic suffix stripping, specialization contexts),
backtrace line parsing, and C exports via `@[export]`.

The C++ runtime backtrace handler now calls the Lean-exported functions
instead of its own 792-line reimplementation. This is safe because
`print_backtrace` is only called from `lean_panic_impl` (soft panics),
not `lean_internal_panic`.

The Python profiler demangler (`script/profiler/lean_demangle.py`) is
replaced with a thin subprocess wrapper around a Lean CLI tool,
preserving the `demangle_lean_name` API so downstream scripts work
unchanged.

**New files:**
- `src/Lean/Compiler/NameDemangling.lean` — single source of truth (483
lines)
- `tests/lean/run/demangling.lean` — comprehensive tests (281 lines)
- `script/profiler/lean_demangle_cli.lean` — `c++filt`-style CLI tool

**Deleted files:**
- `src/runtime/demangle.cpp` (792 lines)
- `src/runtime/demangle.h` (26 lines)
- `script/profiler/test_demangle.py` (670 lines)

Net: −1,381 lines of duplicated C++/Python code.

🤖 Prepared with Claude Code

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 12:29:35 +00:00
..
bin perf: separate meta and non-meta initializers (#12016) 2026-02-26 08:05:19 +00:00
cmake chore: reformat all cmake files (#12218) 2026-01-28 18:23:08 +00:00
include/lean feat: non exponential codegen for reset-reuse (#12665) 2026-02-26 09:35:45 +00:00
Init feat: unify name demangling with single Lean implementation (#12539) 2026-03-06 12:29:35 +00:00
initialize
kernel fix: kernel: move level parameter count and thm-is-prop checks for robustness (#12817) 2026-03-05 17:03:01 +00:00
lake feat: lake: use trace mtime for arts when possible (#12799) 2026-03-05 04:53:59 +00:00
Lean feat: unify name demangling with single Lean implementation (#12539) 2026-03-06 12:29:35 +00:00
LeanChecker feat: add declaration name to leanchecker error messages (#12525) 2026-02-17 16:08:00 +00:00
library feat: non exponential codegen for reset-reuse (#12665) 2026-02-26 09:35:45 +00:00
runtime feat: unify name demangling with single Lean implementation (#12539) 2026-03-06 12:29:35 +00:00
shell chore: move test suite setup to tests/CMakeLists.txt (#12278) 2026-02-03 13:22:20 +00:00
Std feat: move instance-class check to declaration site (#12325) 2026-03-06 03:23:27 +00:00
util chore: update to c++20 (#12117) 2026-02-11 01:17:40 +00:00
cadical.mk
CMakeLists.txt fix: validate stage0 version matches release version (#12700) 2026-03-04 01:31:29 +00:00
config.h.in
githash.h.in
Init.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
lakefile.toml.in feat: re-integrate lean4checker as leanchecker (#11887) 2026-01-08 09:41:33 +00:00
lean-toolchain chore: relative lean-toolchains (#12652) 2026-02-25 10:23:35 +00:00
Lean.lean refactor: move getOriginalConstKind? into its own module to avoid future import cycle (#12265) 2026-02-01 16:18:51 +00:00
lean.mk.in
Leanc.lean
LeanChecker.lean feat: re-integrate lean4checker as leanchecker (#11887) 2026-01-08 09:41:33 +00:00
out
Std.lean
stdlib.make.in chore: clean up stdlib.make.in (#12614) 2026-02-20 16:59:34 +00:00
stdlib_flags.h Revert "chore: temporarily disable proofs for bootstrap" 2026-02-05 13:41:34 +11:00
version.h.in