Meta initializer uses runtime-initialized data with specialized instance
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Description
Consider the following project
lakefile.toml
name = "repro"
leanOptions = { experimental.module = true }
[[lean_lib]]
name = "Repro"
Repro/Helper.lean
module
public section
class Description (α : Type) where
pieces : List String
def describe (α : Type) [Description α] : Option String :=
some <| (Description.pieces α).foldl (init := "") (· ++ ·)
instance : Description Unit where
pieces := ["un", "it"]
Repro/A.lean
module
public meta import Repro.Helper
public section
meta def unitDescription : Option String :=
describe Unit
Repro/B.lean
module
public import Repro.A
Then running
lake env $(elan which lean) ./Repro/B.lean \
--load-dynlib=$(lake query Repro.A:dynlib) \
--load-dynlib=$(lake query Repro.Helper:dynlib)
will result in a segfault.
The compiler puts code to initialize the generated specialization lp_repro_describe___at___00unitDescription_spec__0 in runtime_initialize_repro_Repro_A, while the meta def that reads it is initialized in meta_initialize_repro_Repro_A. With --load-dynlib, only the latter is run.
Context
Exposed by #14326.
Expected behavior: Project builds.
Actual behavior: Crash.
Versions
nightly-2026-07-10
Darwin Kernel Version 25.4.0
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the crash with lakefile.toml and the Repro/Helper.lean, Repro/A.lean, and Repro/B.lean files using the shown lake and lean command. Start by tracing the generated runtime_initialize_repro_Repro_A and meta_initialize_repro_Repro_A entry points, then verify that the project builds without a segmentation fault when using --load-dynlib.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100