leanprover / leanprover/lean4

Meta initializer uses runtime-initialized data with specialized instance

Open
#14,359 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-high
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.