From de9a6374f182586ad597dc7d720cfc2139f488f3 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Wed, 14 Dec 2022 13:03:20 +0100 Subject: [PATCH] feat: make `#check ` always show the signature without elaboration --- src/Lean/Elab/BuiltinCommand.lean | 21 ++++++++++--------- tests/lean/1026.lean | 2 +- tests/lean/1098.lean | 2 +- tests/lean/604.lean.expected.out | 2 +- tests/lean/714.lean.expected.out | 2 +- tests/lean/974.lean | 6 +++--- tests/lean/986.lean | 4 ++-- tests/lean/LE.lean | 2 +- tests/lean/autoBoundImplicits1.lean | 2 +- .../autoBoundImplicits2.lean.expected.out | 2 +- tests/lean/autoImplicitChainNameIssue.lean | 2 +- tests/lean/autoIssue.lean | 4 ++-- tests/lean/binderCacheIssue.lean.expected.out | 4 ++-- tests/lean/ctorUnivTooBig.lean | 2 +- tests/lean/derivingRpcEncoding.lean | 12 +++++------ tests/lean/diamond2.lean | 4 ++-- tests/lean/diamond5.lean | 2 +- tests/lean/diamond6.lean | 4 ++-- tests/lean/diamond7.lean | 6 +++--- tests/lean/heapSort.lean | 2 +- tests/lean/levelNGen.lean | 6 +++--- tests/lean/match1.lean.expected.out | 4 ++-- tests/lean/openScoped.lean | 8 +++---- tests/lean/openScoped.lean.expected.out | 6 +++--- tests/lean/precissues.lean.expected.out | 6 +++--- tests/lean/sizeof.lean | 2 +- tests/lean/strictImplicit.lean.expected.out | 2 +- tests/lean/varBinderUpdate.lean | 12 +++++------ 28 files changed, 67 insertions(+), 66 deletions(-) diff --git a/src/Lean/Elab/BuiltinCommand.lean b/src/Lean/Elab/BuiltinCommand.lean index 2c6a26cb07..9a39fe8fee 100644 --- a/src/Lean/Elab/BuiltinCommand.lean +++ b/src/Lean/Elab/BuiltinCommand.lean @@ -235,22 +235,23 @@ open Meta def elabCheckCore (ignoreStuckTC : Bool) : CommandElab | `(#check%$tk $term) => withoutModifyingEnv <| runTermElabM fun _ => Term.withDeclName `_check do + -- show signature for `#check id`/`#check @id` + if let `($_:ident) := term then + try + for c in (← resolveGlobalConstWithInfos term) do + addCompletionInfo <| .id term c (danglingDot := false) {} none + logInfoAt tk <| .ofPPFormat { pp := fun + | some ctx => ctx.runMetaM <| PrettyPrinter.ppSignature c + | none => return f!"{c}" -- should never happen + } + return + catch _ => pure () -- identifier might not be a constant but constant + projection let e ← Term.elabTerm term none Term.synthesizeSyntheticMVarsNoPostponing (ignoreStuckTC := ignoreStuckTC) let e ← Term.levelMVarToParam (← instantiateMVars e) let type ← inferType e if e.isSyntheticSorry then return - -- show signature for `#check id`/`#check @id` - match term with - | `($_:ident) | `(@$_:ident) => - if let .const c _ := e then - logInfoAt tk <| .ofPPFormat { pp := fun - | some ctx => ctx.runMetaM <| PrettyPrinter.ppSignature c - | none => return f!"{c}" -- should never happen - } - return - | _ => pure () logInfoAt tk m!"{e} : {type}" | _ => throwUnsupportedSyntax diff --git a/tests/lean/1026.lean b/tests/lean/1026.lean index 6b6ee12c78..c9b15c96d6 100644 --- a/tests/lean/1026.lean +++ b/tests/lean/1026.lean @@ -10,4 +10,4 @@ theorem ex : foo 0 = 0 := by unfold foo sorry -#check @foo._unfold +#check foo._unfold diff --git a/tests/lean/1098.lean b/tests/lean/1098.lean index c689743222..025806205c 100644 --- a/tests/lean/1098.lean +++ b/tests/lean/1098.lean @@ -9,7 +9,7 @@ inductive R : FoldImpl α β → FoldImpl α β → Prop where #print R -#check @R.intro +#check R.intro -- @R.intro : ∀ {α β γ γ' : Type u_1} {x₀ : γ} {y₀ : γ'} {f : γ → α → γ} {g : γ' → α → γ'} {out : γ → β} {out' : γ' → β}, -- R { γ := γ, x₀ := x₀, f := f, out := out } { γ := γ', x₀ := y₀, f := g, out := out' } diff --git a/tests/lean/604.lean.expected.out b/tests/lean/604.lean.expected.out index 0e7384100d..09ab311dd9 100644 --- a/tests/lean/604.lean.expected.out +++ b/tests/lean/604.lean.expected.out @@ -1,4 +1,4 @@ foo ⦃u : Unit⦄ : Unit foo : ⦃u : Unit⦄ → Unit -bla : Unit +bla {u : Unit} : Unit fun {u} => bla : {u : Unit} → Unit diff --git a/tests/lean/714.lean.expected.out b/tests/lean/714.lean.expected.out index 1010ce36fc..3b2a4c4368 100644 --- a/tests/lean/714.lean.expected.out +++ b/tests/lean/714.lean.expected.out @@ -1 +1 @@ -test : Type +test {α : Type} [inst✝ : LT α] : Type diff --git a/tests/lean/974.lean b/tests/lean/974.lean index 195fb2bf85..0be5d5203b 100644 --- a/tests/lean/974.lean +++ b/tests/lean/974.lean @@ -10,9 +10,9 @@ def Formula.count_quantifiers : {n:Nat} → Formula n → Nat attribute [simp] Formula.count_quantifiers -#check @Formula.count_quantifiers._eq_1 -#check @Formula.count_quantifiers._eq_2 -#check @Formula.count_quantifiers._eq_3 +#check Formula.count_quantifiers._eq_1 +#check Formula.count_quantifiers._eq_2 +#check Formula.count_quantifiers._eq_3 @[simp] def Formula.count_quantifiers2 : Formula n → Nat | imp f₁ f₂ => f₁.count_quantifiers2 + f₂.count_quantifiers2 diff --git a/tests/lean/986.lean b/tests/lean/986.lean index 3f88415f86..b5ba6793e2 100644 --- a/tests/lean/986.lean +++ b/tests/lean/986.lean @@ -1,4 +1,4 @@ attribute [simp] Array.insertionSort.swapLoop -#check @Array.insertionSort.swapLoop._eq_1 -#check @Array.insertionSort.swapLoop._eq_2 +#check Array.insertionSort.swapLoop._eq_1 +#check Array.insertionSort.swapLoop._eq_2 diff --git a/tests/lean/LE.lean b/tests/lean/LE.lean index 63df043f46..cecf470432 100644 --- a/tests/lean/LE.lean +++ b/tests/lean/LE.lean @@ -1,5 +1,5 @@ inductive LE' : Nat → Nat → Prop where | refl (n : Nat) : LE' n n -#check @LE'.refl +#check LE'.refl #print LE' diff --git a/tests/lean/autoBoundImplicits1.lean b/tests/lean/autoBoundImplicits1.lean index 7352980ebf..bd3bfc9f7c 100644 --- a/tests/lean/autoBoundImplicits1.lean +++ b/tests/lean/autoBoundImplicits1.lean @@ -30,7 +30,7 @@ variable (xs : Vec α n) -- works def f := xs -#check @f +#check f #check f mkVec diff --git a/tests/lean/autoBoundImplicits2.lean.expected.out b/tests/lean/autoBoundImplicits2.lean.expected.out index 09869920fa..e2c4fb154d 100644 --- a/tests/lean/autoBoundImplicits2.lean.expected.out +++ b/tests/lean/autoBoundImplicits2.lean.expected.out @@ -1,4 +1,4 @@ -g1 : ?m → ?m +g1.{u} {α : Type u} (a : α) : α autoBoundImplicits2.lean:30:17-30:18: error: unknown universe level 'u' autoBoundImplicits2.lean:33:17-33:18: error: unknown universe level 'β' def h1.{u} : {m : Type u → Type u} → {α : Type u} → m α → m α := diff --git a/tests/lean/autoImplicitChainNameIssue.lean b/tests/lean/autoImplicitChainNameIssue.lean index b5b40e6575..258cb270ed 100644 --- a/tests/lean/autoImplicitChainNameIssue.lean +++ b/tests/lean/autoImplicitChainNameIssue.lean @@ -9,4 +9,4 @@ theorem palindrome_reverse (h : Palindrome as) : Palindrome as.reverse := by | single a => exact Palindrome.single a | sandwish a h ih => simp; exact Palindrome.sandwish _ ih -#check @palindrome_reverse +#check palindrome_reverse diff --git a/tests/lean/autoIssue.lean b/tests/lean/autoIssue.lean index fd4b9dec24..a400028baa 100644 --- a/tests/lean/autoIssue.lean +++ b/tests/lean/autoIssue.lean @@ -3,7 +3,7 @@ structure A := x : Nat a' : x = 1 := by trivial -#check @A.a' +#check A.a' example (z : A) : z.x = 1 := by have := z.a' @@ -15,7 +15,7 @@ example (z : A) : z.x = 1 := by trace_state exact this -#check @A.rec +#check A.rec example (z : A) : z.x = 1 := by have ⟨x, a'⟩ := z diff --git a/tests/lean/binderCacheIssue.lean.expected.out b/tests/lean/binderCacheIssue.lean.expected.out index 37e7de1b64..af30f8320c 100644 --- a/tests/lean/binderCacheIssue.lean.expected.out +++ b/tests/lean/binderCacheIssue.lean.expected.out @@ -1,4 +1,4 @@ -LNot.unpackFun : LNot ?m → ∀ (p : ?m), ¬?m p +LNot.unpackFun.{u} {P : Sort u} {L : P → Prop} (K : LNot L) (p : P) : ¬L p Funtype.unpack : LNot ?m → ∀ (p : ?m), ¬?m p -LNot.applyFun : LNot ?m → ∀ {p : ?m}, ¬?m p +LNot.applyFun.{u} {P : Sort u} {L : P → Prop} (K : LNot L) {p : P} : ¬L p Funtype.apply : LNot ?m → ∀ {p : ?m}, ¬?m p diff --git a/tests/lean/ctorUnivTooBig.lean b/tests/lean/ctorUnivTooBig.lean index c55ec46566..b7248e31fa 100644 --- a/tests/lean/ctorUnivTooBig.lean +++ b/tests/lean/ctorUnivTooBig.lean @@ -21,7 +21,7 @@ inductive Member : α → List α → Type u | head : Member a (a::as) | tail : Member a bs → Member a (b::bs) -#check @Member.head +#check Member.head end Ex1 namespace Ex2 diff --git a/tests/lean/derivingRpcEncoding.lean b/tests/lean/derivingRpcEncoding.lean index de5eb9233f..e2383b903d 100644 --- a/tests/lean/derivingRpcEncoding.lean +++ b/tests/lean/derivingRpcEncoding.lean @@ -50,7 +50,7 @@ structure FooGeneric (α : Type) where b? : Option α deriving RpcEncodable, Inhabited -#check @instRpcEncodableFooGeneric +#check instRpcEncodableFooGeneric #eval test (FooGeneric Nat) default #eval test (FooGeneric Nat) { a := 3, b? := some 42 } @@ -58,7 +58,7 @@ inductive BazInductive | baz (arr : Array Bar) deriving RpcEncodable, Inhabited -#check @instRpcEncodableBazInductive +#check instRpcEncodableBazInductive #eval test BazInductive ⟨#[default, default]⟩ inductive FooInductive (α : Type) where @@ -66,7 +66,7 @@ inductive FooInductive (α : Type) where | b : (n : Nat) → (a : α) → (m : Nat) → FooInductive α deriving RpcEncodable, Inhabited -#check @instRpcEncodableFooInductive +#check instRpcEncodableFooInductive #eval test (FooInductive BazInductive) (.a default default) #eval test (FooInductive BazInductive) (.b 42 default default) @@ -80,20 +80,20 @@ inductive FooParam (n : Nat) where | a : Nat → FooParam n deriving RpcEncodable, Inhabited -#check @instRpcEncodableFooParam +#check instRpcEncodableFooParam #eval test (FooParam 10) (.a 42) inductive Unused (α : Type) | a deriving RpcEncodable, Inhabited -#check @instRpcEncodableUnused +#check instRpcEncodableUnused structure NoRpcEncodable #eval test (Unused NoRpcEncodable) default structure UnusedStruct (α : Type) deriving RpcEncodable, Inhabited -#check @instRpcEncodableUnusedStruct +#check instRpcEncodableUnusedStruct #eval test (UnusedStruct NoRpcEncodable) default deriving instance Repr, RpcEncodable for Empty diff --git a/tests/lean/diamond2.lean b/tests/lean/diamond2.lean index 5493ddb789..42cbf3ac98 100644 --- a/tests/lean/diamond2.lean +++ b/tests/lean/diamond2.lean @@ -11,7 +11,7 @@ set_option structureDiamondWarning false structure Foo1 (α : Type) extends Bar (α → α), Baz α -#check @Foo1.mk +#check Foo1.mk def f1 (x : Nat) : Foo1 Nat := { a := id @@ -26,7 +26,7 @@ structure Boo2 (α : Type) extends Boo1 α where structure Foo2 (α : Type) extends Bar (α → α), Boo2 α -#check @Foo2.mk +#check Foo2.mk def f2 (v : Nat) : Foo2 Nat := { a := id diff --git a/tests/lean/diamond5.lean b/tests/lean/diamond5.lean index c08e318988..f359a4bb62 100644 --- a/tests/lean/diamond5.lean +++ b/tests/lean/diamond5.lean @@ -14,4 +14,4 @@ def D.toC (x : Nat) := x class D (α : Type) extends B α, C α -#check @D.toC_1 +#check D.toC_1 diff --git a/tests/lean/diamond6.lean b/tests/lean/diamond6.lean index 27b9786096..50ebd663f3 100644 --- a/tests/lean/diamond6.lean +++ b/tests/lean/diamond6.lean @@ -14,7 +14,7 @@ class FooAC (α : Type) extends FooComm α, FooAssoc α where mul_comm (a b : α) : a * b = b * a set_option pp.all true -#check @FooAC.mk +#check FooAC.mk #print FooAC.toFooAssoc @@ -24,7 +24,7 @@ class FooAssoc' (α : Type) extends FooAssoc α where class FooAC' (α : Type) extends FooComm α, FooAssoc' α where mul_comm (a b : α) : a * b = b * a -#check @FooAC'.mk +#check FooAC'.mk #print FooAC'.toFooAssoc' diff --git a/tests/lean/diamond7.lean b/tests/lean/diamond7.lean index 1afb70a2e2..df96abc8dc 100644 --- a/tests/lean/diamond7.lean +++ b/tests/lean/diamond7.lean @@ -17,7 +17,7 @@ class Monoid (α : Type u) extends Semigroup α, One α where class CommMonoid (α : Type u) extends Monoid α, CommSemigroup α set_option pp.all true -#check @CommMonoid.mk +#check CommMonoid.mk #print CommMonoid.toCommSemigroup class Inv (α : Type u) where @@ -30,7 +30,7 @@ class Group (α : Type u) extends Monoid α, Inv α where class CommGroup (α : Type u) extends Group α, CommMonoid α -#check @CommGroup.mk +#check CommGroup.mk #print CommGroup.toCommMonoid class AddSemigroup (α : Type u) extends Add α where @@ -87,6 +87,6 @@ class DivisionRing (α : Type u) extends Ring α, Inv α, ZeroNeOne α where class Field (α : Type u) extends DivisionRing α, CommRing α set_option pp.all false in -#check @Field.mk +#check Field.mk #print Field.toDivisionRing #print Field.toCommRing diff --git a/tests/lean/heapSort.lean b/tests/lean/heapSort.lean index 34a8b68ffe..a92bcca95a 100644 --- a/tests/lean/heapSort.lean +++ b/tests/lean/heapSort.lean @@ -173,6 +173,6 @@ termination_by _ => a.size decreasing_by assumption attribute [simp] Array.heapSort.loop -#check @Array.heapSort.loop._eq_1 +#check Array.heapSort.loop._eq_1 attribute [simp] BinaryHeap.heapifyDown diff --git a/tests/lean/levelNGen.lean b/tests/lean/levelNGen.lean index 46153e2075..c071d396f0 100644 --- a/tests/lean/levelNGen.lean +++ b/tests/lean/levelNGen.lean @@ -1,6 +1,6 @@ opaque test1 {α : Sort _} : α → Sort u_1 -#check @test1 +#check test1 def test2 {α : Sort _} : α → Sort u_1 := sorry -#check @test2 +#check test2 variable {α : Sort _} in theorem test3 : α → Sort _ := sorry -#check @test3 +#check test3 diff --git a/tests/lean/match1.lean.expected.out b/tests/lean/match1.lean.expected.out index d03dedefc3..ec02890f18 100644 --- a/tests/lean/match1.lean.expected.out +++ b/tests/lean/match1.lean.expected.out @@ -46,6 +46,6 @@ fun x => | #[] => 0 | #[3, 4, 5] => 3 | x => 4 : Array Nat → Nat -g.match_1 : (motive : List ?m → Sort u_2) → - (x : List ?m) → ((a : ?m) → motive [a]) → ((x : List ?m) → motive x) → motive x +g.match_1.{u_1, u_2} {α : Type u_1} (motive : List α → Sort u_2) (x✝ : List α) (h_1 : (a : α) → motive [a]) + (h_2 : (x : List α) → motive x) : motive x✝ fun e => nomatch e : Empty → False diff --git a/tests/lean/openScoped.lean b/tests/lean/openScoped.lean index c030cde018..9b8e02ef98 100644 --- a/tests/lean/openScoped.lean +++ b/tests/lean/openScoped.lean @@ -1,4 +1,4 @@ -#check @epsilon -- Error +#check epsilon -- Error noncomputable def foo1 (f g : Nat → Nat) : Nat := if f = g then 1 else 2 -- Error @@ -6,18 +6,18 @@ noncomputable def foo1 (f g : Nat → Nat) : Nat := section open Classical -#check @epsilon +#check epsilon noncomputable def foo2 (f g : Nat → Nat) : Nat := if f = g then 1 else 2 -- Ok end -#check @epsilon -- Error +#check epsilon -- Error section open scoped Classical -#check @epsilon -- Error +#check epsilon -- Error noncomputable def foo3 (f g : Nat → Nat) : Nat := if f = g then 1 else 2 -- Ok diff --git a/tests/lean/openScoped.lean.expected.out b/tests/lean/openScoped.lean.expected.out index 966271cb67..b44c5cfebe 100644 --- a/tests/lean/openScoped.lean.expected.out +++ b/tests/lean/openScoped.lean.expected.out @@ -1,6 +1,6 @@ -openScoped.lean:1:8-1:15: error: unknown identifier 'epsilon' +openScoped.lean:1:7-1:14: error: unknown identifier 'epsilon' openScoped.lean:4:2-4:24: error: failed to synthesize instance Decidable (f = g) Classical.epsilon.{u} {α : Sort u} [h : Nonempty α] (p : α → Prop) : α -openScoped.lean:15:8-15:15: error: unknown identifier 'epsilon' -openScoped.lean:20:8-20:15: error: unknown identifier 'epsilon' +openScoped.lean:15:7-15:14: error: unknown identifier 'epsilon' +openScoped.lean:20:7-20:14: error: unknown identifier 'epsilon' diff --git a/tests/lean/precissues.lean.expected.out b/tests/lean/precissues.lean.expected.out index 24a48746ba..3dd4b22ee6 100644 --- a/tests/lean/precissues.lean.expected.out +++ b/tests/lean/precissues.lean.expected.out @@ -3,9 +3,9 @@ id fun x => x : ?m → ?m f 1 fun x => x : Nat 0 : Nat f 1 fun x => x : Nat -id : ?m → ?m +id.{u} {α : Sort u} (a : α) : α precissues.lean:15:10: error: expected command -id : ?m → ?m +id.{u} {α : Sort u} (a : α) : α precissues.lean:17:10: error: expected command 1 : Nat id @@ -26,5 +26,5 @@ p ∧ ¬q : Prop ¬p = q : Prop id ¬p : Prop Nat → ∀ (a : Nat), a = a : Prop -id : ?m → ?m +id.{u} {α : Sort u} (a : α) : α precissues.lean:41:10: error: expected command diff --git a/tests/lean/sizeof.lean b/tests/lean/sizeof.lean index ac30de9c06..c82a953cd7 100644 --- a/tests/lean/sizeof.lean +++ b/tests/lean/sizeof.lean @@ -15,4 +15,4 @@ inductive InfTree (α : Type u) #reduce sizeOf <| InfTree.leaf 10 -#check @InfTree.node.sizeOf_spec +#check InfTree.node.sizeOf_spec diff --git a/tests/lean/strictImplicit.lean.expected.out b/tests/lean/strictImplicit.lean.expected.out index de6fe0a879..d56a1b982e 100644 --- a/tests/lean/strictImplicit.lean.expected.out +++ b/tests/lean/strictImplicit.lean.expected.out @@ -1,4 +1,4 @@ -g : ?m → ?m +g {α : Type} (a : α) : α f ⦃α : Type⦄ (a : α) : α g 1 : Nat f 1 : Nat diff --git a/tests/lean/varBinderUpdate.lean b/tests/lean/varBinderUpdate.lean index 94c6942cee..2710b16bdb 100644 --- a/tests/lean/varBinderUpdate.lean +++ b/tests/lean/varBinderUpdate.lean @@ -8,8 +8,8 @@ def f (a : α) := a + a variable {α} def g (b : α) := b #check g 5 -#check @f -#check @g +#check f +#check g end Ex1 namespace Ex2 @@ -20,8 +20,8 @@ def f (a : α) := a def g (b : β) := b #check f Nat 5 #check g 5 -#check @f -#check @g +#check f +#check g variable (α) end Ex2 @@ -31,10 +31,10 @@ variable {α : Type} variable (f : α → α) variable (α) def g (a : α) := f a -#check @g +#check g variable {f} def h (a : α) := f a -#check @h +#check h end Ex3 namespace Ex4