Skip to content

chore: remove unreachable C++ code - #15268

Merged
Kha merged 6 commits into
masterfrom
dead-cpp-removal
Sep 22, 2026
Merged

Kha merged 6 commits into
masterfrom
dead-cpp-removal

Conversation

@Kha

@Kha Kha commented Sep 22, 2026

Copy link
Copy Markdown
Member

This PR removes about 500 C++ functions under src/ that nothing reaches any more: not the C++ itself, not the compiled standard library, not an @[extern] binding, and not the public lean.h API.

The set was computed by recompiling every C++ translation unit at -O0 -fno-inline -ffunction-sections, building a reference graph from the ELF relocations, and computing reachability from main, static initializers, every symbol referenced by the compiled stdlib and Lake objects, every lean_* identifier and @[extern] name in .lean sources, and every lean_* function declared in src/include/lean/*.h, for both the GMP and the no-GMP runtime. Functions that are only used in LEAN_DEBUG assertions, under LEAN_LLVM, or by mpn.cpp in the no-GMP build were kept, as were the global print(...) debugger helpers.

  • library: delete bin_app.{h,cpp}, num.{h,cpp}, expr_pair.h; trim util.{h,cpp} to mk_unit, mk_unit_mk, mk_bool_true, mk_bool_false, get_short_version_string; drop the no_level_params variants from expr_lt, the C++ load_dynlib/load_plugin overloads, unused IR accessors in ir_interpreter.cpp, lean_llvm_build_ret_void; prune constants.txt from 106 to the 5 entries that are still used and regenerate constants.{h,cpp}.
  • kernel: delete expr_cache.{h,cpp}; remove environment::for_each_constant, unused declaration/constant_info/local_decl/type_checker/literal/axiom_val constructors, mk_axiom, mk_theorem, mk_opaque, mk_definition(env, ...), mk_definition_val, mk_definition_inferring_unsafe(env, ...), abstract(expr, name), mk_app(expr, list<expr>), instantiate(expr, initializer_list), head_beta_reduce, is_head_beta, the free is_inductive/is_recursor, is_bi_equal and the expr_bi_map aliases, local_ctx::{empty,get_local,clear}, type_checker::{ensure_pi(e, t),ensure_fun,eta_expand}, unused level and expr helpers, and the lean_level_eqv export.
  • util: delete timer.{h,cpp}, map_foreach.{h,cpp}, ascii.{h,cpp}, lbool.cpp, list_fn.cpp, name_set.cpp; remove the kvmap accessor API, get_option_declarations and the option_declaration class, the never-defined mk_option_declaration, the verbose/max_memory/timeout option globals, options::update(name, bool), name::mk_internal_unique_name, and other unused name and name_generator members. name::escape was the only caller of the identifier-escaping path in display_name_core, so that path and its is_id_first/is_id_rest helpers go too; operator<< output is unchanged.
  • runtime: remove scope_heartbeat, sleep_for, the max-heartbeat/rec-depth/memory setters, the thread-local reset and post-thread-finalizer registries (run_post_thread_finalizers could never run anything), unused UTF-8 helpers including utf8_to_unicode, string_eq(obj, char const*) and the string_ref comparisons with char const*, initialize_openssl/finalize_openssl, lean_io_prim_handle_is_eof, get_available_stack_size, and mpz operators that only exist with GMP and were never called.

This PR removes about 500 C++ functions under `src/` that nothing reaches any more: not the C++ itself, not the compiled standard library, not an `@[extern]` binding, and not the public `lean.h` API.

The set was computed by recompiling every C++ translation unit at `-O0 -fno-inline -ffunction-sections`, building a reference graph from the ELF relocations, and computing reachability from `main`, static initializers, every symbol referenced by the compiled stdlib and Lake objects, every `lean_*` identifier and `@[extern]` name in `.lean` sources, and every `lean_*` function declared in `src/include/lean/*.h`, for both the GMP and the no-GMP runtime. Functions that are only used in `LEAN_DEBUG` assertions, under `LEAN_LLVM`, or by `mpn.cpp` in the no-GMP build were kept, as were the global `print(...)` debugger helpers.

* `library`: delete `bin_app.{h,cpp}`, `num.{h,cpp}`, `expr_pair.h`; trim `util.{h,cpp}` to `mk_unit`, `mk_unit_mk`, `mk_bool_true`, `mk_bool_false`, `get_short_version_string`; drop the `no_level_params` variants from `expr_lt`, the C++ `load_dynlib`/`load_plugin` overloads, unused IR accessors in `ir_interpreter.cpp`, `lean_llvm_build_ret_void`; prune `constants.txt` from 106 to the 5 entries that are still used and regenerate `constants.{h,cpp}`.
* `kernel`: delete `expr_cache.{h,cpp}`; remove `environment::for_each_constant`, unused `declaration`/`constant_info`/`local_decl`/`type_checker`/`literal`/`axiom_val` constructors, `mk_axiom`, `mk_theorem`, `mk_opaque`, `mk_definition(env, ...)`, `mk_definition_val`, `mk_definition_inferring_unsafe(env, ...)`, `abstract(expr, name)`, `mk_app(expr, list<expr>)`, `instantiate(expr, initializer_list)`, `head_beta_reduce`, `is_head_beta`, the free `is_inductive`/`is_recursor`, `is_bi_equal` and the `expr_bi_map` aliases, `local_ctx::{empty,get_local,clear}`, `type_checker::{ensure_pi(e, t),ensure_fun,eta_expand}`, unused level and expr helpers, and the `lean_level_eqv` export.
* `util`: delete `timer.{h,cpp}`, `map_foreach.{h,cpp}`, `ascii.{h,cpp}`, `lbool.cpp`, `list_fn.cpp`, `name_set.cpp`; remove the `kvmap` accessor API, `get_option_declarations` and the `option_declaration` class, the never-defined `mk_option_declaration`, the `verbose`/`max_memory`/`timeout` option globals, `options::update(name, bool)`, `name::mk_internal_unique_name`, and other unused `name` and `name_generator` members. `name::escape` was the only caller of the identifier-escaping path in `display_name_core`, so that path and its `is_id_first`/`is_id_rest` helpers go too; `operator<<` output is unchanged.
* `runtime`: remove `scope_heartbeat`, `sleep_for`, the max-heartbeat/rec-depth/memory setters, the thread-local reset and post-thread-finalizer registries (`run_post_thread_finalizers` could never run anything), unused UTF-8 helpers including `utf8_to_unicode`, `string_eq(obj, char const*)` and the `string_ref` comparisons with `char const*`, `initialize_openssl`/`finalize_openssl`, `lean_io_prim_handle_is_eof`, `get_available_stack_size`, and `mpz` operators that only exist with GMP and were never called.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Kha
Kha requested a review from leodemoura as a code owner September 22, 2026 09:54
@Kha Kha added the awaiting-review Waiting for someone to review the PR label Sep 22, 2026
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Sep 22, 2026
Comment thread src/runtime/openssl.cpp Resolved
This PR restores the `initialize_openssl`/`finalize_openssl` pair in `runtime/openssl.cpp` that the dead-code removal had dropped.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Kha Kha added the release-ci Enable all CI checks for a PR, like is done for releases label Sep 22, 2026
This PR restores `options::update(name, bool)`, which `stdlib_flags.h` calls inside its `LEAN_IS_STAGE0` block; the removal only looked at the stage1 build and so missed the use, which broke the rebootstrap check in CI.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Kha Kha added downstream Request a downstream-lean4 adaptation PR. and removed awaiting-review Waiting for someone to review the PR labels Sep 22, 2026
Comment thread src/runtime/uv/event_loop.cpp Resolved
Kha and others added 3 commits September 22, 2026 15:21
This PR removes the `@[export]` attributes that existed solely for C++ callers deleted in the dead-code removal. The bridge-only wrappers `mkMVarEx`, `mkLevelMVarEx`, `mkAxiomValEx`, `mkTheoremValEx`, `mkOpaqueValEx`, `mkReducibilityHintsRegularEx`, `QuotVal.kindEx`, and `getOptionDeclsArray` are deleted outright (`script/find-deprecations.lean`, its one Lean caller, iterates `getOptionDecls` directly instead); `DataValue.str`, `LocalContext.isEmpty`, `LocalContext.erase`, and `Name.appendBefore` keep their definitions and lose only the attribute. `lean_load_dynlib` and `lean_load_plugin` stay exported.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This PR restores `mpz::operator=(unsigned)`, `cmp(mpz, unsigned)` with its comparison operators, and the `unsigned`/`uint64` overloads of `operator-=`, `operator*=` and `operator/=` that the dead-code removal had dropped.

Nothing calls them out of line, but the inline friends `mpz - uint64`, `mpz * unsigned`, `mpz / uint64` and friends still forward to them, and since every integer constructor of `mpz` is `explicit`, overload resolution silently fell back to the `int` versions: `mpz(0) - (uint64(1) << 40)` evaluated to `0` and `mpz(1 << 41) / uint64(1 << 40)` divided by zero. Only `operator=(char const *)` and `power`/`_power`/`pow`, which have no such forwarding callers, stay removed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This PR restores the last two removals in `runtime/mpz.{h,cpp}`, `operator=(char const *)` and `power`/`_power`/`pow`, so the `mpz` wrapper is left exactly as on master.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@downstream-lean4

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#101.

Merged via the queue into master with commit f03441b Sep 22, 2026
24 checks passed
nomeata pushed a commit to leanprover/lean-kernel-arena that referenced this pull request Nov 22, 2026
Bumps the `lean4lean` checker from `bce3448` (Lean v4.33.0-rc2) to
`932afa1` (Lean v4.36.0), the tip of lean4lean's `arena` branch.

This takes in lean4lean's ports of the kernel changes from v4.33.0
through v4.36.0, including:
- a fix to the inductive adder, which now reads every constructor field
from a single normalization (the issue fixed upstream in
leanprover/lean4#14806). At `bce3448`, lean4lean could be made to accept
a recursor missing an inductive hypothesis, and from that a proof of
`False`.
- bounds on the size of `Nat` literals and on the results of `Nat`
operations (leanprover/lean4#14849).
- removal of native reduction (leanprover/lean4#14953) and of
`etaExpand` (leanprover/lean4#15268).

The old rev stays reachable on lean4lean's `arena-v4.33.0-rc2` branch.

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

Co-authored-by: Claude Opus 5.5 <[email protected]>
github-actions Bot pushed a commit to argumentcomputer/lean4lean that referenced this pull request Nov 23, 2026
leanprover/lean4#15268 deletes C++ code nothing reaches any more, among it the
kernel's `type_checker::eta_expand`, which the old compiler used and which was
never exposed to Lean. Lean4lean's `TypeChecker.etaExpand` mirrored it from the
first commit, and nothing calls it either; it goes, with its fuel counter
`FuelConfig.etaExpand`. A fuel configuration that still sets `etaExpand` is now
rejected as naming an unknown field.

The rest of #15268 has no counterpart here, apart from `ensure_pi`, whose
counterpart `ensureForall` stays as part of the `M`-level API next to
`ensureSort`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

downstream Request a downstream-lean4 adaptation PR. release-ci Enable all CI checks for a PR, like is done for releases toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants