lean4-htt/src/Init/Data
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
..
Array perf: inline a few Array functions (#9661) 2026-03-04 10:31:58 +00:00
BitVec perf: fixup BitVec.cpop termination proof performance (#12764) 2026-03-02 16:53:45 +00:00
ByteArray feat: backward.isDefEq.respectTransparency (#12179) 2026-02-16 15:57:21 +00:00
Char feat: unify name demangling with single Lean implementation (#12539) 2026-03-06 12:29:35 +00:00
Dyadic chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Fin feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
FloatArray chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Format feat: use StateT.run instead of function application (#5121) 2026-03-03 03:12:26 +00:00
Int feat: upstream Rat.abs and Int/Rat lemmas from human-eval-lean (#12412) 2026-02-11 11:07:08 +00:00
Iterators feat: move instance-class check to declaration site (#12325) 2026-03-06 03:23:27 +00:00
List fix: remove @[grind →] from getElem_of_getElem? (#12821) 2026-03-06 04:18:21 +00:00
Nat feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Option feat: injectivity lemmas for getElem(?) on List and Option (#12435) 2026-03-02 09:44:45 +00:00
Ord feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Order feat: move instance-class check to declaration site (#12325) 2026-03-06 03:23:27 +00:00
Range feat: move instance-class check to declaration site (#12325) 2026-03-06 03:23:27 +00:00
Rat chore: make Rat.abs lemmas protected (#12504) 2026-02-16 15:49:04 +00:00
SInt feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Slice feat: enable backward.whnf.reducibleClassField (#12538) 2026-02-22 23:22:14 +00:00
String fix: export String.find? and String.contains lemmas (#12807) 2026-03-05 10:00:17 +00:00
Subtype chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Sum doc: correct typos in documentation and comments (#11465) 2025-12-02 06:38:05 +00:00
ToString chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
UInt feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
Vector fix: remove @[grind →] from getElem_of_getElem? (#12821) 2026-03-06 04:18:21 +00:00
AC.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Array.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
BEq.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
BitVec.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Bool.lean feat: enable implicit argument transparency bump (part 2) (#12572) 2026-02-20 03:28:48 +00:00
ByteArray.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Cast.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Char.lean feat: Fin and Char ranges (#12058) 2026-01-22 07:44:55 +00:00
Dyadic.lean feat: (approximate) inverses of dyadic rationals (#10194) 2025-09-02 03:43:53 +00:00
Fin.lean feat: Fin and Char ranges (#12058) 2026-01-22 07:44:55 +00:00
Float.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Float32.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
FloatArray.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Format.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Function.lean chore: remove redundant imports in core (#10750) 2025-10-16 20:27:46 +00:00
Hashable.lean feat: order instances for string positions (#12641) 2026-02-23 08:20:52 +00:00
Int.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
Iterators.lean feat: List slices (#11019) 2025-11-14 11:33:25 +00:00
LawfulHashable.lean style: fix typos in Init/ and Std/ docstrings (#11864) 2026-01-09 07:24:07 +00:00
List.lean feat: upstream List.splitOn(P) (#12702) 2026-02-26 13:45:34 +00:00
Nat.lean feat: verification of Nat.toDigits, Nat.repr and ToString Nat (#12445) 2026-02-18 12:33:01 +00:00
NeZero.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
OfScientific.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Option.lean feat: Fin and Char ranges (#12058) 2026-01-22 07:44:55 +00:00
Ord.lean perf: shorten critical build path around String.Basic (#10614) 2025-09-29 19:45:21 +00:00
Order.lean feat: projected minima and maxima (#11938) 2026-01-31 16:16:32 +00:00
PLift.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Prod.lean chore: grind attributes for Prod (#11085) 2025-11-05 20:52:28 +00:00
Queue.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Random.lean chore: reorganize Init imports around strings (#10289) 2025-09-07 17:09:14 +00:00
Range.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
RArray.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
Rat.lean feat: upstream definition of Rat from Batteries (#9957) 2025-08-19 01:58:24 +00:00
Repr.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00
SInt.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Slice.lean feat: List slices (#11019) 2025-11-14 11:33:25 +00:00
Stream.lean refactor: move Std.Range to Std.Legacy.Range (#11438) 2025-12-18 02:07:33 +00:00
String.lean feat: order instances for string positions (#12641) 2026-02-23 08:20:52 +00:00
Subtype.lean feat: high-level order typeclasses (#9729) 2025-08-11 14:55:17 +00:00
Sum.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
ToString.lean fix: turn meta import into import in Init.Data.ToString (#10754) 2025-10-13 09:20:48 +00:00
UInt.lean chore: remove public section from end of files (#10684) 2025-10-06 13:30:48 +00:00
ULift.lean feat: make private the default in module (#9044) 2025-06-28 16:30:53 +00:00
Vector.lean feat: lemmas about sums of lists/arrays/vectors (#11994) 2026-02-02 07:52:36 +00:00
Zero.lean chore: shake core (#12276) 2026-02-05 09:10:32 +00:00