You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
type error in example, sensitive to simp attribute #1829
Reduced the issue to a self-contained, reproducible test case.
Description
A type error that comes and goes depending on whether we use simp [attribute] X in ... on an earlier declaration.
Steps to Reproduce
theorem eq_iff_true_of_subsingleton [Subsingleton α] (x y : α) : x = y ↔ True :=
⟨fun _ => ⟨⟩, fun _ => (Subsingleton.elim ..)⟩
/- comment out following `attribute [simp]` to make the example below work -/
attribute [simp] eq_iff_true_of_subsingleton in
example : True := trivial
structure Func' (α : Sort _) (β : Sort _) :=
(toFun : α → β)
def r : Func' α α := ⟨id⟩
@[simp] theorem r_toFun {α : Sort u_1} (a : α) : Func'.toFun r a = id a := rfl
example (x y : α) (h : x = y) : r.toFun x = y := by simp <;> rw [h]
/-
in the presence of `attribute [simp] eq_iff_true_of_subsingleton in`, one gets
application type mismatch
Eq
argument has type
Sort u_1
but function has type
{α : Prop} → α → α → Prop
-/
-- If we change `example` to `theorem`, it doesn't care about the `attribute [simp]`.
theorem noissue (x y : α) (h : x = y) : r.toFun x = y := by simp <;> rw [h]
With the attribute [simp] eq_iff_true_of_subsingleton in line, we get an error on the later example. Without the attribute, the error goes away.
What happens is that the typeclass synthesis in simp assigns the universe metavariable (since it finds the instance Subsingleton (α : Prop)). Simplified repro:
theoremeq_iff_true_of_subsingleton [Subsingleton α] (x y : α) : x = y ↔ True :=
⟨fun _ => ⟨⟩, fun _ => (Subsingleton.elim ..)⟩
example (x y : α) : x = y := by simp [eq_iff_true_of_subsingleton]
Okay, now I'm really surprised. Apparently @leodemoura added this bug/feature explicitly for simp lemmas in 99e8a98:
We claim it is reasonable to ignore this restriction for universe metavariables because their values are often
contrained by the terms is instances and simp theorems.
Looking through the commit, I believe the motivation was to make CoeSort work. If that is the only application, we could just remove ignoreLevelMVarDepth entirely, and add the coerceSort? case to coerce?.
Looking through the commit, I believe the motivation was to make CoeSort work. If that is the only application, we could just remove ignoreLevelMVarDepth entirely, and add the coerceSort? case to coerce?.
It was just the first example we hit in practice, there are many more now.
Activity
kbuzzard commentedon Nov 14, 2022
#1814 also mentioned the same simp lemma
gebner commentedon Nov 15, 2022
The
in example ..is a red herring.attribute [simp] foo in ...does exactly the same asattribute [simp] foo.gebner commentedon Nov 15, 2022
Another change that makes the issue disappear is to write
example {α : Sort u} .... It seems to be related to the universe level metavariable.gebner commentedon Nov 15, 2022
What happens is that the typeclass synthesis in simp assigns the universe metavariable (since it finds the instance
Subsingleton (α : Prop)). Simplified repro:gebner commentedon Nov 15, 2022
Okay, now I'm really surprised. Apparently @leodemoura added this bug/feature explicitly for simp lemmas in 99e8a98:
digama0 commentedon Nov 15, 2022
The commit references leanprover-community/mathport#16 as motivation, although I'm not sure what is going on there.
gebner commentedon Nov 15, 2022
Looking through the commit, I believe the motivation was to make
CoeSortwork. If that is the only application, we could just removeignoreLevelMVarDepthentirely, and add thecoerceSort?case tocoerce?.leodemoura commentedon Nov 15, 2022
It was just the first example we hit in practice, there are many more now.
fix: fixes leanprover#1829