Stack overflow during elaboration
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
From this example, it there seems there could be an invalid level metavariable assignment during elaboration, one that forms a loop.
Context
Steps to Reproduce
namespace CategoryTheory
universe v v₁ v₂ v₃ u u₁ u₂ u₃ w₀ w₁
class Quiver (V : Type u) where Hom : V → V → Sort v
structure Functor (V : Type u₁) [Quiver.{v₁} V] (W : Type u₂) [Quiver.{v₂} W] where
class Cat (obj : Type u) extends Quiver.{v + 1} obj : Type max u (v + 1) where
structure Iso {C : Type u} [Cat.{v} C] (X Y : C) where
def Functor.id (C : Type u₁) [Cat.{v₁} C] : Functor C C where
instance pi' {I : Type v₁} (C : I → Type u₁) [∀ i, Cat.{v₁} (C i)] :
Cat (∀ i, C i) := sorry
variable {C : Type u₁} [Cat.{v₁} C] {D : Type u₂} [Cat.{v₂} D]
(F : Functor C C)
instance Functor.category :
Cat.{max u₁ v₂} (Functor C D) := sorry
#check Iso Functor.id F
Expected behavior: This raises a normal error.
Actual behavior: At #check there is a stack overflow.
Versions
Lean 4.15.0-nightly-2024-11-26
Target: x86_64-unknown-linux-gnuLean 4
Additional Information
I tested this locally too on macOS. There are tens of thousands of stack frames for libleanshared.dylib`lean::instantiate_lmvars_fn::visit(lean::level const&). This is what leads me to guess that there is an invalid universe level assignment somewhere.
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
Run the self-contained example against the reported Lean nightly version and inspect the #check expression where elaboration overflows. Start with the reported instantiate_lmvars_fn::visit stack frames and investigate the suspected looping universe-level metavariable assignment; done means the example produces a normal error instead of a stack overflow.
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
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100