Repository navigation
Conversation
This PR fixes a quadratic slowdown in the kernel when a term contains many `Nat` literals that are equal modulo `2^64`, such as the powers `65536 ^ i`. The `Expr` hash of a `Nat` literal used `hash n`, which is `n % 2^64`. Thus all multiples of `2^64` had the same hash. Each lookup in the kernel caches then compared these literals one by one. This PR adds `Literal.natHash`. For `n < 2^64`, it returns `n`, so the hash of these literals does not change. For larger `n`, it combines all 64-bit words of `n` with `mixHash`. `Hashable Nat` does not change. Closes #15686 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new hash of large `Nat` literals changes the hashes stored in `.olean` files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dies This PR gives `Expr.mkData`, `Expr.mkAppData` and `Level.mkData` Lean bodies that state what their C implementations compute, so that the cached expression and level fields can be reasoned about. The C still runs. `mixHash32` is `lean_uint32_mix_hash`, with which `lean_expr_mk_app_data` combines the hashes, so `mkAppData`'s body hashes with it. The test compares the C-backed calls with a transcription of the C and proves the fields of an application's data from the bodies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t used This PR adds InLean, a Lean implementation of the kernel's type checker ported from con-leche's verified checker, in `src/Lean/Kernel/InLean/`, generated by con-leche's `scripts/inlean-sync.py` (with the Nat-operation pins under `pins/`). `Lean` imports it so that the stdlib build compiles it, but nothing calls it: the C++ kernel stays active. Its top module is `Lean.Kernel.InLean.AddDecl`; the glue that makes it the kernel comes separately. `csimpCore` lists InLean's `@[csimp]` lemmas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
!bench |
|
Benchmark results for 1c92992 against da4295a are in. There are significant results. @nomeata
Large changes (52🟥)
Medium changes (1✅, 20🟥)
Small changes (3✅, 874🟥)
|
This branch has not been deployed
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 adds InLean, a Lean port of the con-leche kernel checker, to the stdlib without using it. It is an experiment: the companion PR #16353 replaces the C++ kernel by InLean, and its benchmark results mix two costs, compiling InLean's code and switching the kernel. This PR only adds the code, so that its compile cost can be measured on its own; #16353 is based on it, and its diff is the switch. The C++ kernel stays active here.
It contains:
Natliterals inExpr#16146 (by Jason Gross), which hashes all bits of largeNatliterals inExpr(Literal.natHash), with its stage0 checkbox commit; feat: replace the C++ kernel with InLean, a verified Lean port (experiment) #16353 carries it, so this PR does too, and the two benchmark against each other on the same footing;Expr.mkData,Expr.mkAppDataandLevel.mkDatathat state what their C implementations compute, so that the cached expression and level fields can be reasoned about. They keep their@[extern]attributes, so the compiled code still runs C.tests/elab/expr_mkData_bodies.leancompares the C-backed calls with a transcription of the C on sample and boundary inputs, and proves the fields of an application's data from the bodies;src/Lean/Kernel/InLean/, generated from con-leche'sInLean/by con-leche'sscripts/inlean-sync.py(it only adds the copyright header andprelude, renames the namespace and drops InLean's copy ofInit.Util'swithIsExclusive), with the Nat-operation pins underpins/.Leanimports its top moduleLean.Kernel.InLean.AddDecl, so the stdlib build compiles it. The module that exports the kernel entry points (Lean.Kernel.InLean.Core) is not part of this PR;tests/elab/csimpCore.leanlists InLean's@[csimp]lemmas.All tests pass locally (stage1) except
elab/async_systems_info, which fails in our sandbox on an unmodified build too.🤖 Generated with Claude Code