Skip to content

fix: run shell main on a thread with the configured stack size#14343

Merged
Kha merged 1 commit into
masterfrom
shell-thread-stack
Jul 9, 2026
Merged

fix: run shell main on a thread with the configured stack size#14343
Kha merged 1 commit into
masterfrom
shell-thread-stack

Conversation

@Kha

@Kha Kha commented Jul 9, 2026

Copy link
Copy Markdown
Member

This PR fixes the new 1GB stack size not being used for the main lean thread itself, e.g. for serialization or --run.

This PR makes the `lean` driver run its main logic on a thread with the configured Lean stack size (1 GiB by default) instead of directly on the OS main thread, whose fixed default stack (often 8 MiB) is easily exhausted by the runtime's recursive algorithms. Previously, saving a deeply nested object graph to an `.olean` file (e.g. a persistent environment extension entry containing a list with about 100000 elements) aborted the whole process with a stack overflow, and `lean --run` failed on moderately deep non-tail recursion with a `deep recursion` error that `--tstack` could not actually raise.

Compiled Lean executables already run `main` on a large-stack thread via `lean_run_main`; `lean_main` now mirrors this by running `run_shell_main` through a shared `run_with_thread_stack` helper. The driver now also honors `LEAN_STACK_SIZE_KB`, with `--tstack` taking precedence.

Co-Authored-By: Claude <noreply@anthropic.com>
@Kha Kha added the changelog-compiler Compiler, runtime, and FFI label Jul 9, 2026
@Kha Kha enabled auto-merge July 9, 2026 16:23
@Kha Kha added this pull request to the merge queue Jul 9, 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 Jul 9, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase fd3a07a66a5e6a2cb818c1d1b086b8468f0d208a --onto da19ea085d7cdba0131ec59b4f678b0910304878. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-09 16:55:46)

@leanprover-bot

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase fd3a07a66a5e6a2cb818c1d1b086b8468f0d208a --onto da19ea085d7cdba0131ec59b4f678b0910304878. You can force reference manual CI using the force-manual-ci label. (2026-07-09 16:55:47)

Merged via the queue into master with commit 804bb12 Jul 9, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-compiler Compiler, runtime, and FFI 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.

2 participants