Repository navigation
fix: stop truncating kernel counts and indices to 32 bits - #16279
Merged
Merged
Conversation
This PR fixes `Expr.hasLooseBVar`, `Expr.liftLooseBVars`, `Expr.lowerLooseBVars` and the kernel's handling of the number of parameters of an inductive declaration, which silently truncated values of `2^32` and above to 32 bits. For example, the kernel accepted an inductive declaration with `numParams := 2^32` and recorded `numParams = 0`. The kernel's counts and indices are now `size_t`, so that any value that fits in memory is represented exactly. To keep it that way, the kernel is now compiled with `-Werror=shorten-64-to-32` under Clang. Truncations of 64-bit hashes are intended and are now explicit casts that compute the same values; `lean.h` is exempt from the flag. This changes neither the `.olean` format nor any `extern "C"` signature: these values cross into Lean as boxed `Nat`s. Only C++ signatures internal to the toolchain change, and their headers are not installed. Closes #12746 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This PR compiles the kernel with `-Werror=conversion` instead of `-Werror=shorten-64-to-32`, which also rejects implicit narrowing to 8 and 16 bits and signedness changes. `gmp.h` is exempt alongside `lean.h`, as it is not kernel code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
!bench |
|
Benchmark results for 54c06e5 against c029d91 are in. There are significant results. @nomeata
Large changes (2🟥)
Medium changes (4🟥)
Small changes (1✅, 64🟥)
|
This PR removes the kernel slowdown introduced by widening the start index of `instantiate`, `lift_loose_bvars`, `lower_loose_bvars` and `has_loose_bvar`, by narrowing the index again once it is known to be below the 20-bit loose bound variable range. The filter that runs on every visited expression then uses the same 32-bit arithmetic as before, and indices of `2^32` and above are still handled correctly by the early return. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
!bench |
|
Benchmark results for bd44d6c against c029d91 are in. No significant results found. @nomeata
Small changes (4✅, 1🟥)
|
This PR adds `unsigned long long` overloads of the `nat` constructor and comparison operators, as that is what `size_t` is on Windows, so that `nat(n)` and `nat == n` do the right thing for a `size_t` on every platform. This replaces the separate `nat::of_size_t`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nomeata
marked this pull request as ready for review
November 5, 2026 16:21
This PR replaces the `--system-header-prefix` flags on the kernel target with `#pragma clang diagnostic` around `lean.h` and `gmp.h`. Those flags treated the headers as system headers, which turned off all of their warnings in kernel code, while the pragmas turn off only `-Wconversion`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This PR fixes `Task` and `BaseIO` task functions truncating their priority to 32 bits. A priority of `2^32 - 1` ran the task synchronously in the caller, and other priorities of `2^32` and above could end up in the shared thread pool instead of on the dedicated thread that their documentation promises. This also fixes a cast to `int16_t` in `lean_uint16_of_nat` to be `uint16_t`, which does not change its result. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nomeata
enabled auto-merge
November 5, 2026 17:29
This PR ends the `-Wconversion` exemption in `lean.h` before its existing `-Wunused-parameter` pragma. Popping the diagnostic state at the end of the file also undid that pragma, which has so far applied to everything that includes `lean.h`, and failed the `-Werror` build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 fixes
Expr.hasLooseBVar,Expr.liftLooseBVars,Expr.lowerLooseBVars, task priorities and the kernel's handling of the number of parameters of an inductive declaration, which silently truncated values of2^32and above to 32 bits. For example, the kernel accepted an inductive declaration withnumParams := 2^32and recordednumParams = 0, and a task with priority2^32 - 1ran synchronously in the caller rather than on a dedicated thread.The kernel's counts and indices are now
size_t, so that any value that fits in memory is represented exactly. The hot bound variable traversals still compute at 32 bits, as their start index is first checked against the 20-bit loose bound variable range. To keep it that way, the kernel is now compiled with-Werror=conversionunder Clang, which rejects implicit narrowing and signedness changes;lean.handgmp.hare exempt. Truncations of 64-bit hashes are intended and are now explicit casts that compute the same values.This changes neither the
.oleanformat nor anyextern "C"signature: these values cross into Lean as boxedNats. Only C++ signatures internal to the toolchain change, and their headers are not installed.Expr.liftLooseBVarswith a shift of2^32or more on an expression with loose bound variables now reaches the existing "too many bound variables" panic, like any shift above2^20.Closes #12746. This also covers its closed duplicates #13602 and #13618.
🤖 Generated with Claude Code