fix: add missing release() and adopt_lock_t to single-threaded unique_lock stub#13233
Merged
hargoniX merged 1 commit intoleanprover:masterfrom Apr 7, 2026
Merged
Conversation
…_lock stub When building with LEAN_MULTI_THREAD undefined (required for Emscripten/ WASM targets), the stub unique_lock<T> in thread.h is missing: - release() — called by runtime code, causes compile error - unique_lock(T const &, std::adopt_lock_t) — required by code that acquires a lock before constructing the unique_lock The real std::unique_lock provides both. The stub should too. Discovered while building Lean4 to WASM via Emscripten for a production project (specify-lean) since v4.27.0. The fix has been proven stable across multiple Lean version bumps.
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
hargoniX
approved these changes
Apr 7, 2026
wkrozowski
pushed a commit
to wkrozowski/lean4
that referenced
this pull request
Apr 10, 2026
…_lock stub (leanprover#13233) This PR fixes runtime build issues when `LEAN_MULTI_THREAD` is not set. ## Problem When building with `LEAN_MULTI_THREAD` undefined (required for Emscripten/WASM targets), the stub `unique_lock<T>` in `src/runtime/thread.h` is missing two members that the real `std::unique_lock` provides: 1. **`release()`** — called by runtime code paths, causes a compile error when the stub is active 2. **`unique_lock(T const &, std::adopt_lock_t)`** — required by code that acquires a lock before constructing the `unique_lock` The other stubs in this file (`mutex`, `lock_guard`, `condition_variable`) are complete; only `unique_lock` is missing API surface. ## Fix Add the two missing members to the single-threaded `unique_lock` stub: ```cpp unique_lock(T const &, std::adopt_lock_t) {} T * release() { return nullptr; } ``` Both are no-ops, matching the semantics of a single-threaded environment. `release()` returns `nullptr` (no mutex to release). The `adopt_lock_t` constructor is a no-op (no lock to adopt). ## Evidence I've been using this fix in a production project ([specify-lean](https://github.com/kjsdesigns/specify)) since v4.27.0 to build the Lean4 runtime to WASM via Emscripten. The fix has been stable across multiple Lean version bumps. I posted about this on [Zulip](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/WASM.20build.20fixes.3A.20libuv.20symbol.20leakage.20.28.236817.29.20and.20unique_lo/with/580836892) on 2026-03-21. Co-authored-by: Keith Seim <keith@MacBook-Pro.local>
volodeyka
pushed a commit
that referenced
this pull request
Apr 16, 2026
…_lock stub (#13233) This PR fixes runtime build issues when `LEAN_MULTI_THREAD` is not set. ## Problem When building with `LEAN_MULTI_THREAD` undefined (required for Emscripten/WASM targets), the stub `unique_lock<T>` in `src/runtime/thread.h` is missing two members that the real `std::unique_lock` provides: 1. **`release()`** — called by runtime code paths, causes a compile error when the stub is active 2. **`unique_lock(T const &, std::adopt_lock_t)`** — required by code that acquires a lock before constructing the `unique_lock` The other stubs in this file (`mutex`, `lock_guard`, `condition_variable`) are complete; only `unique_lock` is missing API surface. ## Fix Add the two missing members to the single-threaded `unique_lock` stub: ```cpp unique_lock(T const &, std::adopt_lock_t) {} T * release() { return nullptr; } ``` Both are no-ops, matching the semantics of a single-threaded environment. `release()` returns `nullptr` (no mutex to release). The `adopt_lock_t` constructor is a no-op (no lock to adopt). ## Evidence I've been using this fix in a production project ([specify-lean](https://github.com/kjsdesigns/specify)) since v4.27.0 to build the Lean4 runtime to WASM via Emscripten. The fix has been stable across multiple Lean version bumps. I posted about this on [Zulip](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/WASM.20build.20fixes.3A.20libuv.20symbol.20leakage.20.28.236817.29.20and.20unique_lo/with/580836892) on 2026-03-21. Co-authored-by: Keith Seim <keith@MacBook-Pro.local>
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 runtime build issues when
LEAN_MULTI_THREADis not set.Problem
When building with
LEAN_MULTI_THREADundefined (required for Emscripten/WASM targets), the stubunique_lock<T>insrc/runtime/thread.his missing two members that the realstd::unique_lockprovides:release()— called by runtime code paths, causes a compile error when the stub is activeunique_lock(T const &, std::adopt_lock_t)— required by code that acquires a lock before constructing theunique_lockThe other stubs in this file (
mutex,lock_guard,condition_variable) are complete; onlyunique_lockis missing API surface.Fix
Add the two missing members to the single-threaded
unique_lockstub:Both are no-ops, matching the semantics of a single-threaded environment.
release()returnsnullptr(no mutex to release). Theadopt_lock_tconstructor is a no-op (no lock to adopt).Evidence
I've been using this fix in a production project (specify-lean) since v4.27.0 to build the Lean4 runtime to WASM via Emscripten. The fix has been stable across multiple Lean version bumps.
I posted about this on Zulip on 2026-03-21.