Zulip Chat Archive
Stream: general
Topic: Unexpected Compiler Crash
Wang Jingting (Apr 07 2025 at 01:39):
I came across the following example, in which the compiler reported "Server process for ... crashed, likely due to a stack overflow or a bug." Does anyone know why that's happening?
A mwe:
import Mathlib
open CategoryTheory
def hello (R : Type u) [CommRing R] : R ā+* (End š (ModuleCat R)) := by sorry
It seems that a stack overflow is occurring, but I don't really know why.
Bhavik Mehta (Apr 07 2025 at 01:44):
The same thing happens with just def hello (R : Type u) [CommRing R] : End š (ModuleCat R) := by sorry
Wang Jingting (Apr 07 2025 at 01:48):
Bhavik Mehta said:
The same thing happens with just
def hello (R : Type u) [CommRing R] : End š (ModuleCat R) := by sorry
Yes, you're right. I also find #check End š (ModuleCat R)
working fine, #synth Ring (End š (ModuleCat R))
, #synth Monoid (End š (ModuleCat R))
causing stack overflow.
Notification Bot (Apr 07 2025 at 12:51):
This topic was moved here from #general > Weird Compiler Crash by Wang Jingting.
Wang Jingting (Apr 07 2025 at 12:52):
Does anyone know why that's happening? I'd really appreciate your help!
Kevin Buzzard (Apr 07 2025 at 13:55):
Can you try and minimise? Can you get the crash without any imports by just copying definitions from mathlib? If so then you can ask in #lean4 .
Bhavik Mehta (Apr 07 2025 at 14:44):
My expectation is that this is some dodgy instance resolution using instances in mathlib
Kevin Buzzard (Apr 07 2025 at 15:05):
import Mathlib.CategoryTheory.Endomorphism
#check CategoryTheory.End -- fine
#check CategoryTheory.Functor.id -- fine
#check CategoryTheory.End CategoryTheory.Functor.id -- stack overflow
Kevin Buzzard (Apr 07 2025 at 15:16):
--import Mathlib.CategoryTheory.Pi.Basic -- uncomment for stackoverflow
-- these are the imports in `Mathlib.CategoryTheory.Pi.Basic`
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.NatIso
import Mathlib.CategoryTheory.Products.Basic
universe v u
namespace CategoryTheory
def End {C : Type u} [CategoryStruct.{v} C] (X : C) := X ā¶ X
end CategoryTheory
#check CategoryTheory.End CategoryTheory.Functor.id
Kevin Buzzard (Apr 07 2025 at 15:32):
OK I need to stop now but here's what I got it down to so far: it's the instance CategoryTheory.pi'
. Make it an instance to get a stack overflow. This was on v4.19.0-rc2
(of mathlib and lean) BTW
import Mathlib.CategoryTheory.Functor.Category
namespace CategoryTheory
universe wā wā wā vā vā vā uā uā uā
variable {I : Type wā} {J : Type wā} (C : I ā Type uā) [ā i, Category.{vā} (C i)]
/-- `pi C` gives the cartesian product of an indexed family of categories.
-/
instance pi : Category.{max wā vā} (ā i, C i) where
Hom X Y := ā i, X i ā¶ Y i
id X i := š (X i)
comp f g i := f i ā« g i
/-- This provides some assistance to typeclass search in a common situation,
which otherwise fails. (Without this `CategoryTheory.Pi.has_limit_of_has_limit_comp_eval` fails.)
-/
abbrev pi' {I : Type vā} (C : I ā Type uā) [ā i, Category.{vā} (C i)] : Category.{vā} (ā i, C i) :=
CategoryTheory.pi C
-- uncomment the next line for a stack overflow
--attribute [instance] pi'
universe v u
def End {C : Type u} [CategoryStruct.{v} C] (X : C) := X ā¶ X
end CategoryTheory
#check CategoryTheory.End CategoryTheory.Functor.id
Kevin Buzzard (Apr 07 2025 at 15:33):
I left the mathlib docstrings but CategoryTheory.Pi.has_limit_of_has_limit_comp_eval
doesn't seem to exist any more?
Bhavik Mehta (Apr 07 2025 at 15:34):
It looks like the docstring wasn't ported, and it refers to docs#CategoryTheory.pi.hasLimit_of_hasLimit_comp_eval
Kevin Buzzard (Apr 08 2025 at 08:12):
Mathlib seems to compile with pi'
deleted. I'll make a PR.
Kevin Buzzard (Apr 08 2025 at 08:24):
#23812 (let's see what benchmarking says)
Last updated: May 02 2025 at 03:31 UTC