Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em committed Feb 5, 2024
1 parent 0444a39 commit 8684522
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
9 changes: 6 additions & 3 deletions REPL/Main.lean
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def runProofStep (s : ProofStep) : M IO (ProofStepResponse ⊕ Error) := do
let proofState' ← proofState.runString s.tactic
return .inl (← createProofStepReponse proofState' proofState)
catch ex =>
return .inr ⟨ex.toString⟩
return .inr ⟨"Lean error:\n" ++ ex.toString⟩

end REPL

Expand Down Expand Up @@ -272,7 +272,8 @@ inductive Input
def parse (query : String) : IO Input := do
let json := Json.parse query
match json with
| .error e => throw <| IO.userError <| toString <| toJson (⟨e⟩ : Error)
| .error e => throw <| IO.userError <| toString <| toJson <|
(⟨"Could not parse JSON:\n" ++ e⟩ : Error)
| .ok j => match fromJson? j with
| .ok (r : REPL.ProofStep) => return .proofStep r
| .error _ => match fromJson? j with
Expand All @@ -285,7 +286,8 @@ def parse (query : String) : IO Input := do
| .ok (r : REPL.UnpickleProofState) => return .unpickleProofSnapshot r
| .error _ => match fromJson? j with
| .ok (r : REPL.Command) => return .command r
| .error e => throw <| IO.userError <| toString <| toJson (⟨e⟩ : Error)
| .error e => throw <| IO.userError <| toString <| toJson <|
(⟨"Could not parse as a valid JSON command:\n" ++ e⟩ : Error)

/-- Read-eval-print loop for Lean. -/
unsafe def repl : IO Unit :=
Expand All @@ -294,6 +296,7 @@ where loop : M IO Unit := do
let query ← getLines
if query = "" then
return ()
if query.startsWith "#" || query.startsWith "--" then loop else
IO.println <| toString <| ← match ← parse query with
| .command r => return toJson (← runCommand r)
| .proofStep r => return toJson (← runProofStep r)
Expand Down
2 changes: 1 addition & 1 deletion REPL/Snapshots.lean
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def runString (p : ProofSnapshot) (t : String) : IO ProofSnapshot :=
/-- Pretty print the current goals in the `ProofSnapshot`. -/
def ppGoals (p : ProofSnapshot) : IO (List Format) :=
Prod.fst <$> p.runMetaM do p.tacticState.goals.mapM (Meta.ppGoal ·)

/--
Construct a `ProofSnapshot` from a `ContextInfo` and optional `LocalContext`, and a list of goals.
Expand All @@ -193,6 +192,7 @@ def create (ctx : ContextInfo) (lctx? : Option LocalContext)
(goals : List MVarId) (types : List Expr := []) : IO ProofSnapshot := do
ctx.runMetaM (lctx?.getD {}) do
let goals := goals ++ (← types.mapM fun t => Expr.mvarId! <$> Meta.mkFreshExprMVar (some t))
goals.head!.withContext do
pure <|
{ coreState := ← getThe Core.State
coreContext := ← readThe Core.Context
Expand Down
22 changes: 20 additions & 2 deletions test/Mathlib/test/20240202/min.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
{"cmd": "example {x : Int} (h0 : x > 0) : False := by sorry"}
{"cmd": "set_option trace.Meta.Tactic.simp true\nexample {x : Int} (h0 : x > 0) : False := by sorry"}

{"tactic": "have h : x > 0 := by sorry", "proofState": 0}

{"tactic": "simp [h0]", "proofState": 1}
-- Some things work:

{"tactic": "exact h0", "proofState": 1}

{"tactic": "assumption", "proofState": 1}

{"tactic": "simp only [of_eq_true (eq_true h0)]", "proofState": 1}

-- These all fail with nonsensical "application type mismatch":

{"tactic": "{ simp [h0] }", "proofState": 1}

{"tactic": "{ simp (config := {memoize := false}) [h0] }", "proofState": 1}

{"tactic": "{ rw (config := {}) [(show x = x from rfl)] }", "proofState": 1}

--- This fails with "motive is not type correct"

{"tactic": "{ rw [(show x = x from rfl)] }", "proofState": 1}

2 changes: 1 addition & 1 deletion test/Mathlib/test/H20240202.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sorry

have h3 := calc
2 * x = 2 * |x| := by sorry
_ > 2 := by try simp [h0]
_ > 2 := by (trace_state; rw [(show x = x from rfl)]; simp [h0])

sorry
}
2 changes: 1 addition & 1 deletion test/unknown_tactic.expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"data": "declaration uses 'sorry'"}],
"env": 0}

{"message": "<input>:1:1: unknown tactic"}
{"message": "Lean error:\n<input>:1:1: unknown tactic"}

0 comments on commit 8684522

Please sign in to comment.