lean4-htt/src/Init
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
..
Control fix: re-apply "mark Id.run as [implicit_reducible]" (#12802) 2026-03-05 08:03:09 +00:00
Data feat: unify name demangling with single Lean implementation (#12539) 2026-03-06 12:29:35 +00:00
Grind perf: add high priority to OfSemiring.Q instances (#12782) 2026-03-04 12:58:15 +00:00
GrindInstances feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Internal chore: revert reducibility change PartialOrder.rel (#12407) 2026-02-10 19:46:36 +00:00
Meta feat: new, extensible do elaborator (#12459) 2026-02-21 17:17:29 +00:00
Omega chore: prefer cons_cons over cons₂ in names (#12710) 2026-02-27 08:58:08 +00:00
Sym feat: add simpDecideCbv simproc for cbv decide (#12766) 2026-03-03 14:24:14 +00:00
System feat: lazy initialization of closed terms (#12044) 2026-02-20 08:45:15 +00:00
BinderNameHint.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
BinderPredicates.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
ByCases.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Classical.lean feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Coe.lean doc: fix typo in Init.Coe module docstring (#11567) 2025-12-10 08:48:55 +00:00
Control.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Conv.lean doc: improve docstrings for cbv and decide_cbv (#12439) 2026-02-12 10:31:17 +00:00
Core.lean feat: overriding binder kinds of parameters in inductive constructors (#12603) 2026-02-25 02:30:12 +00:00
Data.lean chore: more reorganization of strings (#10928) 2025-10-23 11:56:11 +00:00
Dynamic.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Ext.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
GetElem.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Grind.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
GrindInstances.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Guard.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Hints.lean feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Internal.lean
LawfulBEqTactics.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
MacroTrace.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Meta.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
MetaTypes.lean refactor: rename instance_reducible to implicit_reducible (#12567) 2026-02-18 22:19:16 +00:00
MethodSpecsSimp.lean feat: @[method_specs_simp] in Init (#10407) 2025-09-16 10:27:33 +00:00
Notation.lean fix: use _fvar._ instead of _ for anonymous fvars (#12745) 2026-03-01 09:59:13 +00:00
NotationExtra.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Omega.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Prelude.lean feat: non exponential codegen for reset-reuse (#12665) 2026-02-26 09:35:45 +00:00
PropLemmas.lean feat: more lemmas relating Bool and (d)ite (#12371) 2026-02-07 09:05:46 +00:00
RCases.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
ShareCommon.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
SimpLemmas.lean feat: improves simpArrowTelescope simproc (#12153) 2026-01-25 22:29:38 +00:00
Simproc.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
SizeOf.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
SizeOfLemmas.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Sym.lean feat: add Sym.Simp.evalGround simproc (#12031) 2026-01-17 05:13:12 +00:00
Syntax.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
System.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Tactics.lean feat: add cbv at location syntax (#12773) 2026-03-03 16:12:07 +00:00
TacticsExtra.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Task.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Try.lean feat: add first_par combinator for try? with grind +locals (#11949) 2026-01-09 21:09:41 +00:00
Util.lean feat: new, extensible do elaborator (#12459) 2026-02-21 17:17:29 +00:00
WF.lean feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
WFComputable.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
WFExtrinsicFix.lean feat: enable partial termination proofs about WellFounded.extrinsicFix (#12430) 2026-02-25 12:43:39 +00:00
WFTactics.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
While.lean feat: new, extensible do elaborator (#12459) 2026-02-21 17:17:29 +00:00