Repository navigation
chore: remove unreachable C++ code - #15268
Merged
Merged
Conversation
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]>
TwoFX
reviewed
Sep 22, 2026
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]>
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
commented
Sep 22, 2026
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]>
|
The adaptation PR for this PR is leanprover/downstream-lean4#101. |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 publiclean.hAPI.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 frommain, static initializers, every symbol referenced by the compiled stdlib and Lake objects, everylean_*identifier and@[extern]name in.leansources, and everylean_*function declared insrc/include/lean/*.h, for both the GMP and the no-GMP runtime. Functions that are only used inLEAN_DEBUGassertions, underLEAN_LLVM, or bympn.cppin the no-GMP build were kept, as were the globalprint(...)debugger helpers.library: deletebin_app.{h,cpp},num.{h,cpp},expr_pair.h; trimutil.{h,cpp}tomk_unit,mk_unit_mk,mk_bool_true,mk_bool_false,get_short_version_string; drop theno_level_paramsvariants fromexpr_lt, the C++load_dynlib/load_pluginoverloads, unused IR accessors inir_interpreter.cpp,lean_llvm_build_ret_void; pruneconstants.txtfrom 106 to the 5 entries that are still used and regenerateconstants.{h,cpp}.kernel: deleteexpr_cache.{h,cpp}; removeenvironment::for_each_constant, unuseddeclaration/constant_info/local_decl/type_checker/literal/axiom_valconstructors,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 freeis_inductive/is_recursor,is_bi_equaland theexpr_bi_mapaliases,local_ctx::{empty,get_local,clear},type_checker::{ensure_pi(e, t),ensure_fun,eta_expand}, unused level and expr helpers, and thelean_level_eqvexport.util: deletetimer.{h,cpp},map_foreach.{h,cpp},ascii.{h,cpp},lbool.cpp,list_fn.cpp,name_set.cpp; remove thekvmapaccessor API,get_option_declarationsand theoption_declarationclass, the never-definedmk_option_declaration, theverbose/max_memory/timeoutoption globals,options::update(name, bool),name::mk_internal_unique_name, and other unusednameandname_generatormembers.name::escapewas the only caller of the identifier-escaping path indisplay_name_core, so that path and itsis_id_first/is_id_resthelpers go too;operator<<output is unchanged.runtime: removescope_heartbeat,sleep_for, the max-heartbeat/rec-depth/memory setters, the thread-local reset and post-thread-finalizer registries (run_post_thread_finalizerscould never run anything), unused UTF-8 helpers includingutf8_to_unicode,string_eq(obj, char const*)and thestring_refcomparisons withchar const*,initialize_openssl/finalize_openssl,lean_io_prim_handle_is_eof,get_available_stack_size, andmpzoperators that only exist with GMP and were never called.