Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions REPL/Frontend.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def processCommandsWithInfoTrees
(commandState : Command.State) : IO (Command.State × List Message × List InfoTree) := do
let commandState := { commandState with infoState.enabled := true }
let s ← IO.processCommands inputCtx parserState commandState <&> Frontend.State.commandState
let msgs := s.messages.toList.drop commandState.messages.toList.length
let trees := s.infoState.trees.toList.drop commandState.infoState.trees.size

pure (s, msgs, trees)
pure (s, s.messages.toList, s.infoState.trees.toList)

/--
Process some text input, with or without an existing command state.
Expand Down
6 changes: 3 additions & 3 deletions REPL/JSON.lean
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ structure Sorry where
deriving FromJson

instance : ToJson Sorry where
toJson r := Json.mkObj <| .join [
toJson r := Json.mkObj <| .flatten [
[("goal", r.goal)],
[("proofState", toJson r.proofState)],
if r.pos.line ≠ 0 then [("pos", toJson r.pos)] else [],
Expand Down Expand Up @@ -132,7 +132,7 @@ def Json.nonemptyList [ToJson α] (k : String) : List α → List (String × Jso
| l => [⟨k, toJson l⟩]

instance : ToJson CommandResponse where
toJson r := Json.mkObj <| .join [
toJson r := Json.mkObj <| .flatten [
[("env", r.env)],
Json.nonemptyList "messages" r.messages,
Json.nonemptyList "sorries" r.sorries,
Expand All @@ -153,7 +153,7 @@ structure ProofStepResponse where
deriving ToJson, FromJson

instance : ToJson ProofStepResponse where
toJson r := Json.mkObj <| .join [
toJson r := Json.mkObj <| .flatten [
[("proofState", r.proofState)],
[("goals", toJson r.goals)],
Json.nonemptyList "messages" r.messages,
Expand Down
2 changes: 1 addition & 1 deletion REPL/Lean/Environment.lean
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ and then replace the new constants.
def unpickle (path : FilePath) : IO (Environment × CompactedRegion) := unsafe do
let ((imports, map₂), region) ← _root_.unpickle (Array Import × PHashMap Name ConstantInfo) path
let env ← importModules imports {} 0
return (← env.replay (HashMap.ofList map₂.toList), region)
return (← env.replay (Std.HashMap.ofList map₂.toList), region)

end Lean.Environment
6 changes: 3 additions & 3 deletions REPL/Lean/InfoTree.lean
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ partial def filter (p : Info → Bool) (m : MVarId → Bool := fun _ => false) :
| .context ctx tree => tree.filter p m |>.map (.context ctx)
| .node info children =>
if p info then
[.node info (children.toList.map (filter p m)).join.toPArray']
[.node info (children.toList.map (filter p m)).flatten.toPArray']
else
(children.toList.map (filter p m)).join
(children.toList.map (filter p m)).flatten
| .hole mvar => if m mvar then [.hole mvar] else []

/-- Discard all nodes besides `.context` nodes and `TacticInfo` nodes. -/
Expand All @@ -156,7 +156,7 @@ partial def findAllInfo (t : InfoTree) (ctx? : Option ContextInfo) (p : Info →
| context ctx t => t.findAllInfo (ctx.mergeIntoOuter? ctx?) p
| node i ts =>
let info := if p i then [(i, ctx?)] else []
let rest := ts.toList.bind (fun t => t.findAllInfo ctx? p)
let rest := ts.toList.flatMap (fun t => t.findAllInfo ctx? p)
info ++ rest
| _ => []

Expand Down
34 changes: 18 additions & 16 deletions REPL/Main.lean
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,20 @@ def recordProofSnapshot (proofState : ProofSnapshot) : M m Nat := do
return id

def sorries (trees : List InfoTree) (env? : Option Environment) : M m (List Sorry) :=
trees.bind InfoTree.sorries |>.mapM
fun ⟨ctx, g, pos, endPos⟩ => do
let (goal, proofState) ← match g with
| .tactic g => do
let s ← ProofSnapshot.create ctx none env? [g]
pure ("\n".intercalate <| (← s.ppGoals).map fun s => s!"{s}", some s)
| .term lctx (some t) => do
let s ← ProofSnapshot.create ctx lctx env? [] [t]
pure ("\n".intercalate <| (← s.ppGoals).map fun s => s!"{s}", some s)
| .term _ none => unreachable!
let proofStateId ← proofState.mapM recordProofSnapshot
return Sorry.of goal pos endPos proofStateId
trees.flatMap InfoTree.sorries |>.filter (fun t => match t.2.1 with
| .term _ none => false
| _ => true ) |>.mapM
fun ⟨ctx, g, pos, endPos⟩ => do
let (goal, proofState) ← match g with
| .tactic g => do
let s ← ProofSnapshot.create ctx none env? [g]
pure ("\n".intercalate <| (← s.ppGoals).map fun s => s!"{s}", some s)
| .term lctx (some t) => do
let s ← ProofSnapshot.create ctx lctx env? [] [t]
pure ("\n".intercalate <| (← s.ppGoals).map fun s => s!"{s}", some s)
| .term _ none => unreachable!
let proofStateId ← proofState.mapM recordProofSnapshot
return Sorry.of goal pos endPos proofStateId

def ppTactic (ctx : ContextInfo) (stx : Syntax) : IO Format :=
ctx.runMetaM {} try
Expand All @@ -115,7 +117,7 @@ def ppTactic (ctx : ContextInfo) (stx : Syntax) : IO Format :=
pure "<failed to pretty print>"

def tactics (trees : List InfoTree) : M m (List Tactic) :=
trees.bind InfoTree.tactics |>.mapM
trees.flatMap InfoTree.tactics |>.mapM
fun ⟨ctx, stx, goals, pos, endPos, ns⟩ => do
let proofState := some (← ProofSnapshot.create ctx none none goals)
let goals := s!"{(← ctx.ppGoals goals)}".trim
Expand Down Expand Up @@ -216,9 +218,9 @@ def runCommand (s : Command) : M IO (CommandResponse ⊕ Error) := do
let env ← recordCommandSnapshot cmdSnapshot
let jsonTrees := match s.infotree with
| some "full" => trees
| some "tactics" => trees.bind InfoTree.retainTacticInfo
| some "original" => trees.bind InfoTree.retainTacticInfo |>.bind InfoTree.retainOriginal
| some "substantive" => trees.bind InfoTree.retainTacticInfo |>.bind InfoTree.retainSubstantive
| some "tactics" => trees.flatMap InfoTree.retainTacticInfo
| some "original" => trees.flatMap InfoTree.retainTacticInfo |>.flatMap InfoTree.retainOriginal
| some "substantive" => trees.flatMap InfoTree.retainTacticInfo |>.flatMap InfoTree.retainSubstantive
| _ => []
let infotree ← if jsonTrees.isEmpty then
pure none
Expand Down
7 changes: 3 additions & 4 deletions REPL/Snapshots.lean
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def unpickle (path : FilePath) : IO (CommandSnapshot × CompactedRegion) := unsa
let ((imports, map₂, cmdState, cmdContext), region) ←
_root_.unpickle (Array Import × PHashMap Name ConstantInfo × CompactableCommandSnapshot ×
Command.Context) path
let env ← (← importModules imports {} 0).replay (HashMap.ofList map₂.toList)
let env ← (← importModules imports {} 0).replay (Std.HashMap.ofList map₂.toList)
let p' : CommandSnapshot :=
{ cmdState := { cmdState with env }
cmdContext }
Expand Down Expand Up @@ -194,7 +194,6 @@ def create (ctx : ContextInfo) (lctx? : Option LocalContext) (env? : Option Envi
(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
let s ← getThe Core.State
let s := match env? with
| none => s
Expand Down Expand Up @@ -285,9 +284,9 @@ def unpickle (path : FilePath) (cmd? : Option CommandSnapshot) :
let env ← match cmd? with
| none =>
enableInitializersExecution
(← importModules imports {} 0).replay (HashMap.ofList map₂.toList)
(← importModules imports {} 0).replay (Std.HashMap.ofList map₂.toList)
| some cmd =>
cmd.cmdState.env.replay (HashMap.ofList map₂.toList)
cmd.cmdState.env.replay (Std.HashMap.ofList map₂.toList)
let p' : ProofSnapshot :=
{ coreState := { coreState with env }
coreContext
Expand Down
2 changes: 1 addition & 1 deletion lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.11.0
leanprover/lean4:v4.14.0-rc1
42 changes: 31 additions & 11 deletions test/Mathlib/lake-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "9c6c2d647e57b2b7a0b42dd8080c698bd33a1b6f",
"rev": "76e9ebe4176d29cb9cc89c669ab9f1ce32b33c3d",
"name": "batteries",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.lean"},
"configFile": "lakefile.toml"},
{"url": "https://github.com/leanprover-community/quote4",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "9d0bdd07bdfe53383567509348b1fe917fc08de4",
"rev": "303b23fbcea94ac4f96e590c1cad6618fd4f5f41",
"name": "Qq",
"manifestFile": "lake-manifest.json",
"inputRev": "master",
Expand All @@ -25,7 +25,7 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "deb279eb7be16848d0bc8387f80d6e41bcdbe738",
"rev": "45d016d59cf45bcf8493a203e9564cfec5203d9b",
"name": "aesop",
"manifestFile": "lake-manifest.json",
"inputRev": "master",
Expand All @@ -35,17 +35,17 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "a96aee5245720f588876021b6a0aa73efee49c76",
"rev": "1383e72b40dd62a566896a6e348ffe868801b172",
"name": "proofwidgets",
"manifestFile": "lake-manifest.json",
"inputRev": "v0.0.41",
"inputRev": "v0.0.46",
"inherited": true,
"configFile": "lakefile.lean"},
{"url": "https://github.com/leanprover/lean4-cli",
"type": "git",
"subDir": null,
"scope": "",
"rev": "2cf1030dc2ae6b3632c84a09350b675ef3e347d0",
"scope": "leanprover",
"rev": "726b3c9ad13acca724d4651f14afc4804a7b0e4d",
"name": "Cli",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
Expand All @@ -55,20 +55,40 @@
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "1ef0b288623337cb37edd1222b9c26b4b77c6620",
"rev": "ac7b989cbf99169509433124ae484318e953d201",
"name": "importGraph",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.toml"},
{"url": "https://github.com/leanprover-community/LeanSearchClient",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "7bedaed1ef024add1e171cc17706b012a9a37802",
"name": "LeanSearchClient",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.toml"},
{"url": "https://github.com/leanprover-community/plausible",
"type": "git",
"subDir": null,
"scope": "leanprover-community",
"rev": "0f1430e6f1193929f13905d450b2a44a54f3927e",
"name": "plausible",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
"configFile": "lakefile.toml"},
{"url": "https://github.com/leanprover-community/mathlib4",
"type": "git",
"subDir": null,
"scope": "",
"rev": "8edf04f0977c3183d3b633792e03fd570be1777f",
"rev": "a7fc949f1b05c2a01e01c027fd9f480496a1253e",
"name": "mathlib",
"manifestFile": "lake-manifest.json",
"inputRev": "master",
"inputRev": "v4.14.0-rc1",
"inherited": false,
"configFile": "lakefile.lean"}],
"name": "«repl-mathlib-tests»",
Expand Down
2 changes: 1 addition & 1 deletion test/Mathlib/lakefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defaultTargets = ["ReplMathlibTests"]
[[require]]
name = "mathlib"
git = "https://github.com/leanprover-community/mathlib4"
rev = "master"
rev = "v4.14.0-rc1"

[[lean_lib]]
name = "ReplMathlibTests"
Expand Down
2 changes: 1 addition & 1 deletion test/Mathlib/lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.11.0
leanprover/lean4:v4.14.0-rc1
2 changes: 1 addition & 1 deletion test/all_tactics.expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"tactic": "exact t",
"proofState": 1,
"pos": {"line": 1, "column": 32},
"goals": "t : Nat ⊢ Nat",
"goals": "t : Nat\n⊢ Nat",
"endPos": {"line": 1, "column": 39}}],
"env": 0}

19 changes: 16 additions & 3 deletions test/calc.expected.out
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
{"tactics":
[{"usedConstants":
["Trans.trans", "instOfNatNat", "instTransEq", "Nat", "OfNat.ofNat", "Eq"],
["Trans.trans",
"sorryAx",
"instOfNatNat",
"instTransEq",
"Nat",
"OfNat.ofNat",
"Bool.false",
"Eq"],
"tactic": "calc\n 3 = 4 := by sorry\n 4 = 5 := by sorry",
"proofState": 2,
"pos": {"line": 1, "column": 22},
"goals": "⊢ 3 = 5",
"endPos": {"line": 3, "column": 19}},
{"usedConstants": [],
"tactic": "\n 3 = 4 := by sorry\n 4 = 5 := by sorry",
"proofState": 3,
"pos": {"line": 2, "column": 2},
"goals": "no goals",
"endPos": {"line": 3, "column": 19}},
{"usedConstants":
["sorryAx", "instOfNatNat", "Nat", "OfNat.ofNat", "Bool.false", "Eq"],
"tactic": "sorry",
"proofState": 3,
"proofState": 4,
"pos": {"line": 2, "column": 14},
"goals": "⊢ 3 = 4",
"endPos": {"line": 2, "column": 19}},
{"usedConstants":
["sorryAx", "instOfNatNat", "Nat", "OfNat.ofNat", "Bool.false", "Eq"],
"tactic": "sorry",
"proofState": 4,
"proofState": 5,
"pos": {"line": 3, "column": 14},
"goals": "⊢ 4 = 5",
"endPos": {"line": 3, "column": 19}}],
Expand Down
Loading