Skip to content

Commit 4e70edc

Browse files
authored
fix: NameGenerator bug (#32)
1 parent c210906 commit 4e70edc

6 files changed

+79
-7
lines changed

REPL/Lean/InfoTree.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def findSorryTermNodes (t : InfoTree) : List (TermInfo × ContextInfo) :=
189189
inductive SorryType
190190
| tactic : MVarId → SorryType
191191
| term : LocalContext → Option Expr → SorryType
192-
192+
#check MVarId
193193
/--
194194
Finds all appearances of `sorry` in an `InfoTree`, reporting
195195
* the `ContextInfo` at that point,
@@ -199,7 +199,9 @@ Finds all appearances of `sorry` in an `InfoTree`, reporting
199199
-/
200200
def sorries (t : InfoTree) : List (ContextInfo × SorryType × Position × Position) :=
201201
(t.findSorryTacticNodes.map fun ⟨i, ctx⟩ =>
202-
({ ctx with mctx := i.mctxBefore }, .tactic i.goalsBefore.head!, stxRange ctx.fileMap i.stx)) ++
202+
let g := i.goalsBefore.head!
203+
let ngen := { ctx.ngen with namePrefix := g.name }
204+
({ ctx with mctx := i.mctxBefore, ngen := ngen }, .tactic g, stxRange ctx.fileMap i.stx)) ++
203205
(t.findSorryTermNodes.map fun ⟨i, ctx⟩ =>
204206
(ctx, .term i.lctx i.expectedType?, stxRange ctx.fileMap i.stx))
205207

REPL/Main.lean

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def runProofStep (s : ProofStep) : M IO (ProofStepResponse ⊕ Error) := do
240240
let proofState' ← proofState.runString s.tactic
241241
return .inl (← createProofStepReponse proofState' proofState)
242242
catch ex =>
243-
return .inr ⟨ex.toString⟩
243+
return .inr ⟨"Lean error:\n" ++ ex.toString⟩
244244

245245
end REPL
246246

@@ -272,7 +272,8 @@ inductive Input
272272
def parse (query : String) : IO Input := do
273273
let json := Json.parse query
274274
match json with
275-
| .error e => throw <| IO.userError <| toString <| toJson (⟨e⟩ : Error)
275+
| .error e => throw <| IO.userError <| toString <| toJson <|
276+
(⟨"Could not parse JSON:\n" ++ e⟩ : Error)
276277
| .ok j => match fromJson? j with
277278
| .ok (r : REPL.ProofStep) => return .proofStep r
278279
| .error _ => match fromJson? j with
@@ -285,7 +286,8 @@ def parse (query : String) : IO Input := do
285286
| .ok (r : REPL.UnpickleProofState) => return .unpickleProofSnapshot r
286287
| .error _ => match fromJson? j with
287288
| .ok (r : REPL.Command) => return .command r
288-
| .error e => throw <| IO.userError <| toString <| toJson (⟨e⟩ : Error)
289+
| .error e => throw <| IO.userError <| toString <| toJson <|
290+
(⟨"Could not parse as a valid JSON command:\n" ++ e⟩ : Error)
289291

290292
/-- Read-eval-print loop for Lean. -/
291293
unsafe def repl : IO Unit :=
@@ -294,6 +296,7 @@ where loop : M IO Unit := do
294296
let query ← getLines
295297
if query = "" then
296298
return ()
299+
if query.startsWith "#" || query.startsWith "--" then loop else
297300
IO.println <| toString <| ← match ← parse query with
298301
| .command r => return toJson (← runCommand r)
299302
| .proofStep r => return toJson (← runProofStep r)

REPL/Snapshots.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ def runString (p : ProofSnapshot) (t : String) : IO ProofSnapshot :=
182182
/-- Pretty print the current goals in the `ProofSnapshot`. -/
183183
def ppGoals (p : ProofSnapshot) : IO (List Format) :=
184184
Prod.fst <$> p.runMetaM do p.tacticState.goals.mapM (Meta.ppGoal ·)
185-
186185
/--
187186
Construct a `ProofSnapshot` from a `ContextInfo` and optional `LocalContext`, and a list of goals.
188187
@@ -193,6 +192,7 @@ def create (ctx : ContextInfo) (lctx? : Option LocalContext)
193192
(goals : List MVarId) (types : List Expr := []) : IO ProofSnapshot := do
194193
ctx.runMetaM (lctx?.getD {}) do
195194
let goals := goals ++ (← types.mapM fun t => Expr.mvarId! <$> Meta.mkFreshExprMVar (some t))
195+
goals.head!.withContext do
196196
pure <|
197197
{ coreState := ← getThe Core.State
198198
coreContext := ← readThe Core.Context

test/name_generator.expected.out

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{"sorries":
2+
[{"proofState": 0,
3+
"pos": {"line": 2, "column": 45},
4+
"goal": "x : Int\nh0 : x > 0\n⊢ False",
5+
"endPos": {"line": 2, "column": 50}}],
6+
"messages":
7+
[{"severity": "warning",
8+
"pos": {"line": 2, "column": 0},
9+
"endPos": {"line": 2, "column": 7},
10+
"data": "declaration uses 'sorry'"}],
11+
"env": 0}
12+
13+
{"sorries": [{"proofState": 1, "goal": "x : Int\nh0 : x > 0\n⊢ x > 0"}],
14+
"proofState": 2,
15+
"goals": ["x : Int\nh0 h : x > 0\n⊢ False"]}
16+
17+
{"proofState": 3, "goals": []}
18+
19+
{"proofState": 4, "goals": []}
20+
21+
{"traces":
22+
["[Meta.Tactic.simp.rewrite] of_eq_true (eq_true h0):1000, x > 0 ==> True"],
23+
"proofState": 5,
24+
"goals": []}
25+
26+
{"traces": ["[Meta.Tactic.simp.rewrite] h0:1000, x > 0 ==> True"],
27+
"proofState": 6,
28+
"goals": []}
29+
30+
{"traces": ["[Meta.Tactic.simp.rewrite] h0:1000, x > 0 ==> True"],
31+
"proofState": 7,
32+
"goals": []}
33+
34+
{"proofState": 8,
35+
"messages":
36+
[{"severity": "error",
37+
"pos": {"line": 0, "column": 0},
38+
"endPos": {"line": 0, "column": 0},
39+
"data": "unsolved goals\nx : Int\nh0 : x > 0\n⊢ x > 0"}],
40+
"goals": []}
41+
42+
{"proofState": 9,
43+
"messages":
44+
[{"severity": "error",
45+
"pos": {"line": 0, "column": 0},
46+
"endPos": {"line": 0, "column": 0},
47+
"data": "unsolved goals\nx : Int\nh0 : x > 0\n⊢ x > 0"}],
48+
"goals": []}
49+

test/name_generator.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{"cmd": "set_option trace.Meta.Tactic.simp true\nexample {x : Int} (h0 : x > 0) : False := by sorry"}
2+
3+
{"tactic": "have h : x > 0 := by sorry", "proofState": 0}
4+
5+
{"tactic": "exact h0", "proofState": 1}
6+
7+
{"tactic": "assumption", "proofState": 1}
8+
9+
{"tactic": "simp only [of_eq_true (eq_true h0)]", "proofState": 1}
10+
11+
{"tactic": "{ simp [h0] }", "proofState": 1}
12+
13+
{"tactic": "{ simp (config := {memoize := false}) [h0] }", "proofState": 1}
14+
15+
{"tactic": "{ rw (config := {}) [(show x = x from rfl)] }", "proofState": 1}
16+
17+
{"tactic": "{ rw [(show x = x from rfl)] }", "proofState": 1}
18+

test/unknown_tactic.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"data": "declaration uses 'sorry'"}],
1111
"env": 0}
1212

13-
{"message": "<input>:1:1: unknown tactic"}
13+
{"message": "Lean error:\n<input>:1:1: unknown tactic"}
1414

0 commit comments

Comments
 (0)