feat: remove space before propositions with inaccessible names

This commit is contained in:
Leonardo de Moura 2022-04-07 07:54:17 -07:00
parent 9de6961906
commit fa9b0f6c7e
16 changed files with 65 additions and 52 deletions

View file

@ -164,8 +164,8 @@ private def addLine (fmt : Format) : Format :=
def ppGoal (mvarId : MVarId) : MetaM Format := do
match (← getMCtx).findDecl? mvarId with
| none => pure "unknown goal"
| some mvarDecl => do
| none => return "unknown goal"
| some mvarDecl =>
let indent := 2 -- Use option
let ppAuxDecls := pp.auxDecls.get (← getOptions)
let lctx := mvarDecl.lctx
@ -174,34 +174,34 @@ def ppGoal (mvarId : MVarId) : MetaM Format := do
let (hidden, hiddenProp) ← ToHide.collect mvarDecl.type
-- The followint two `let rec`s are being used to control the generated code size.
-- Then should be remove after we rewrite the compiler in Lean
let rec pushPending (ids : List Name) (type? : Option Expr) (fmt : Format) : MetaM Format :=
let rec pushPending (ids : List Name) (type? : Option Expr) (fmt : Format) : MetaM Format := do
if ids.isEmpty then
pure fmt
return fmt
else
let fmt := addLine fmt
match type? with
| none => pure fmt
| some type => do
| none => return fmt
| some type =>
let typeFmt ← ppExpr type
pure $ fmt ++ (Format.joinSep ids.reverse (format " ") ++ " :" ++ Format.nest indent (Format.line ++ typeFmt)).group
return fmt ++ (Format.joinSep ids.reverse (format " ") ++ " :" ++ Format.nest indent (Format.line ++ typeFmt)).group
let rec ppVars (varNames : List Name) (prevType? : Option Expr) (fmt : Format) (localDecl : LocalDecl) : MetaM (List Name × Option Expr × Format) := do
if hiddenProp.contains localDecl.fvarId then
let fmt ← pushPending varNames prevType? fmt
let fmt := addLine fmt
let type ← instantiateMVars localDecl.type
let typeFmt ← ppExpr type
let fmt := fmt ++ " : " ++ typeFmt
pure ([], none, fmt)
let fmt := fmt ++ ": " ++ typeFmt
return ([], none, fmt)
else
match localDecl with
| LocalDecl.cdecl _ _ varName type _ =>
let varName := varName.simpMacroScopes
let type ← instantiateMVars type
if prevType? == none || prevType? == some type then
pure (varName :: varNames, some type, fmt)
return (varName :: varNames, some type, fmt)
else do
let fmt ← pushPending varNames prevType? fmt
pure ([varName], some type, fmt)
return ([varName], some type, fmt)
| LocalDecl.ldecl _ _ varName type val _ => do
let varName := varName.simpMacroScopes
let fmt ← pushPending varNames prevType? fmt
@ -211,10 +211,10 @@ def ppGoal (mvarId : MVarId) : MetaM Format := do
let typeFmt ← ppExpr type
let valFmt ← ppExpr val
let fmt := fmt ++ (format varName ++ " : " ++ typeFmt ++ " :=" ++ Format.nest indent (Format.line ++ valFmt)).group
pure ([], none, fmt)
return ([], none, fmt)
let (varNames, type?, fmt) ← lctx.foldlM (init := ([], none, Format.nil)) fun (varNames, prevType?, fmt) (localDecl : LocalDecl) =>
if !ppAuxDecls && localDecl.isAuxDecl || hidden.contains localDecl.fvarId then
pure (varNames, prevType?, fmt)
return (varNames, prevType?, fmt)
else
ppVars varNames prevType? fmt localDecl
let fmt ← pushPending varNames type? fmt
@ -222,7 +222,7 @@ def ppGoal (mvarId : MVarId) : MetaM Format := do
let typeFmt ← ppExpr (← instantiateMVars mvarDecl.type)
let fmt := fmt ++ "⊢ " ++ Format.nest indent typeFmt
match mvarDecl.userName with
| Name.anonymous => pure fmt
| Name.anonymous => return fmt
| name => return "case " ++ format name.eraseMacroScopes ++ Format.line ++ fmt
end Lean.Meta

View file

@ -38,12 +38,16 @@ def pretty (g : InteractiveGoal) : Format := Id.run <| do
| none => Format.nil
for hyp in g.hyps do
ret := addLine ret
let names := " ".intercalate hyp.names.toList
match hyp.val? with
| some val =>
ret := ret ++ Format.group f!"{names} : {hyp.type.stripTags} :={Format.nest indent (Format.line ++ val.stripTags)}"
| none =>
ret := ret ++ Format.group f!"{names} :{Format.nest indent (Format.line ++ hyp.type.stripTags)}"
match hyp.names.toList with
| [] =>
ret := ret ++ Format.group f!":{Format.nest indent (Format.line ++ hyp.type.stripTags)}"
| _ =>
let names := " ".intercalate hyp.names.toList
match hyp.val? with
| some val =>
ret := ret ++ Format.group f!"{names} : {hyp.type.stripTags} :={Format.nest indent (Format.line ++ val.stripTags)}"
| none =>
ret := ret ++ Format.group f!"{names} :{Format.nest indent (Format.line ++ hyp.type.stripTags)}"
ret := addLine ret
ret ++ f!"⊢ {Format.nest indent g.type.stripTags}"

View file

@ -5,5 +5,5 @@ a n : Term
1074b.lean:11:9-11:55: error: unsolved goals
case id
a n z✝ : Term
: Brx z✝
: Brx z✝
⊢ True ∧ Brx (sorryAx Term)

View file

@ -8,11 +8,11 @@ h2 : p → q
361.lean:5:11-5:13: error: unsolved goals
p q r : Prop
h2 : p → q
: p
: p
⊢ q
361.lean:3:60-5:13: error: unsolved goals
case inr
p q r : Prop
h2 : p → q
: q
: q
⊢ q

View file

@ -4,5 +4,5 @@ case z
case s
a✝ : Nat
: add Nat.z a✝ = a✝
: add Nat.z a✝ = a✝
⊢ add Nat.z (Nat.s a✝) = Nat.s a✝

View file

@ -11,10 +11,10 @@ value : β
right : Tree β
ihl : BST left → Tree.find? (Tree.insert left k v) k = some v
ihr : BST right → Tree.find? (Tree.insert right k v) k = some v
: k < key
: BST left
: ForallTree (fun k v => k < key) left
: BST right
: ForallTree (fun k v => key < k) right
: k < key
: BST left
: ForallTree (fun k v => k < key) left
: BST right
: ForallTree (fun k v => key < k) right
⊢ BST left
bintreeGoal.lean:67:6-67:11: warning: declaration uses 'sorry'

View file

@ -4,42 +4,42 @@ context:
hidingInaccessibleNames.lean:3:19-3:20: error: don't know how to synthesize placeholder
context:
a b : Nat
: [a, b] ≠ []
: [a, b] ≠ []
⊢ Nat
hidingInaccessibleNames.lean:2:16-2:17: error: don't know how to synthesize placeholder
context:
: [] ≠ []
: [] ≠ []
⊢ Nat
hidingInaccessibleNames.lean:9:19-9:20: error: don't know how to synthesize placeholder
context:
a b x✝¹ : Nat
: [a, b] ≠ []
: [a, b] ≠ []
⊢ Nat
hidingInaccessibleNames.lean:8:16-8:17: error: don't know how to synthesize placeholder
context:
x✝¹ : Nat
: [] ≠ []
: [] ≠ []
⊢ Nat
hidingInaccessibleNames.lean:10:16-10:17: error: don't know how to synthesize placeholder
context:
x✝² : List Nat
x✝¹ : Nat
: x✝² ≠ []
: x✝² ≠ []
⊢ Nat
case inl
p q : Prop
: p
: p
⊢ q p
case inr
p q : Prop
: q
: q
⊢ q p
hidingInaccessibleNames.lean:23:25-23:26: error: don't know how to synthesize placeholder
context:
x✝² : Prop
x✝¹ : x✝²
: x✝²
: x✝²
⊢ decide x✝² = true
hidingInaccessibleNames.lean:27:17-27:18: error: don't know how to synthesize placeholder
context:

View file

@ -30,8 +30,8 @@ h : Expr.boolVal a✝ = b
case eq
α α✝ : ExprType
a✝¹ a✝ : Expr α✝
: ∀ (b : Expr α✝), a✝¹ = b → eval (constProp a✝¹) = eval b
: ∀ (b : Expr α✝), a✝ = b → eval (constProp a✝) = eval b
: ∀ (b : Expr α✝), a✝¹ = b → eval (constProp a✝¹) = eval b
: ∀ (b : Expr α✝), a✝ = b → eval (constProp a✝) = eval b
b : Expr ExprType.bool
h : Expr.eq a✝¹ a✝ = b
⊢ eval (constProp (Expr.eq a✝¹ a✝)) = eval b
@ -39,8 +39,8 @@ h : Expr.eq a✝¹ a✝ = b
case add
α : ExprType
a✝¹ a✝ : Expr ExprType.nat
: ∀ (b : Expr ExprType.nat), a✝¹ = b → eval (constProp a✝¹) = eval b
: ∀ (b : Expr ExprType.nat), a✝ = b → eval (constProp a✝) = eval b
: ∀ (b : Expr ExprType.nat), a✝¹ = b → eval (constProp a✝¹) = eval b
: ∀ (b : Expr ExprType.nat), a✝ = b → eval (constProp a✝) = eval b
b : Expr ExprType.nat
h : Expr.add a✝¹ a✝ = b
⊢ eval (constProp (Expr.add a✝¹ a✝)) = eval b

View file

@ -0,0 +1,4 @@
example (x : Nat) : x + 1 > 0 := by
induction x
decide
--^ $/lean/plainGoal

View file

@ -0,0 +1,5 @@
{"textDocument": {"uri": "file://anonHyp.lean"},
"position": {"line": 2, "character": 4}}
{"rendered":
"```lean\ncase succ\nn✝ : Nat\n: n✝ + 1 > 0\n⊢ Nat.succ n✝ + 1 > 0\n```",
"goals": ["case succ\nn✝ : Nat\n: n✝ + 1 > 0\n⊢ Nat.succ n✝ + 1 > 0"]}

View file

@ -29,9 +29,9 @@
{"textDocument": {"uri": "file://plainGoal.lean"},
"position": {"line": 17, "character": 5}}
{"rendered":
"```lean\ncase succ\nn✝ : Nat\n : 0 + n✝ = n✝\n⊢ 0 + Nat.succ n✝ = Nat.succ n✝\n```",
"```lean\ncase succ\nn✝ : Nat\n: 0 + n✝ = n✝\n⊢ 0 + Nat.succ n✝ = Nat.succ n✝\n```",
"goals":
["case succ\nn✝ : Nat\n : 0 + n✝ = n✝\n⊢ 0 + Nat.succ n✝ = Nat.succ n✝"]}
["case succ\nn✝ : Nat\n: 0 + n✝ = n✝\n⊢ 0 + Nat.succ n✝ = Nat.succ n✝"]}
{"textDocument": {"uri": "file://plainGoal.lean"},
"position": {"line": 21, "character": 9}}
{"rendered": "```lean\nα : Sort ?u\na : α\n⊢ α\n```",

View file

@ -4,13 +4,13 @@ a : p ∧ q
⊢ p
case hp
p q : Prop
: p ∧ q
: p ∧ q
a : p
b : q
⊢ p
case hp
p q : Prop
: p ∧ q
: p ∧ q
a : p
b : q
⊢ p

View file

@ -16,7 +16,7 @@ h₁ : 0 + x = y
h₂ : 0 + y = z
⊢ x = z
m n k : Nat
: n = m
: n = m
h : k = m
⊢ k = n
rewrite.lean:49:69-50:10: error: unsolved goals

View file

@ -24,23 +24,23 @@ tacUnsolvedGoalsErrors.lean:17:9-17:10: error: unsolved goals
case inl
p q r : Prop
h2 : p → q
: p
: p
⊢ q
tacUnsolvedGoalsErrors.lean:19:9-19:10: error: unsolved goals
case inr
p q r : Prop
h2 : p → q
: q
: q
⊢ q
tacUnsolvedGoalsErrors.lean:26:2-27:8: error: unsolved goals
case inl
p q r : Prop
h2 : p → q
: p
: p
⊢ q
tacUnsolvedGoalsErrors.lean:28:2-29:8: error: unsolved goals
case inr
p q r : Prop
h2 : p → q
: q
: q
⊢ q

View file

@ -1,7 +1,7 @@
unknownTactic.lean:3:3: error: unknown tactic
unknownTactic.lean:1:41-3:8: error: unsolved goals
x : Nat
: x = x
: x = x
⊢ x = x
---
unknownTactic.lean:8:22: error: unknown tactic

View file

@ -3,5 +3,5 @@ wf2.lean:3:8-3:17: error: failed to prove termination, possible solutions:
- Use `termination_by` to specify a different well-founded relation
- Use `decreasing_by` to specify your own tactic for discharging this kind of goal
x y : Nat
: x < y
: x < y
⊢ x - 1 < x