feat: Collect new constants in repl

This commit is contained in:
Leni Aniva 2024-12-09 20:57:25 -08:00
parent 9a69c48cb2
commit eb0374dfb3
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
3 changed files with 16 additions and 2 deletions

View File

@ -312,6 +312,8 @@ structure FrontendProcess where
invocations: Bool := false invocations: Bool := false
-- If set to true, collect `sorry`s -- If set to true, collect `sorry`s
sorrys: Bool := false sorrys: Bool := false
-- If set to true, extract new constants
newConstants: Bool := false
deriving Lean.FromJson deriving Lean.FromJson
structure InvokedTactic where structure InvokedTactic where
goalBefore: String goalBefore: String
@ -332,6 +334,7 @@ structure CompilationUnit where
-- Code segments which generated the goals -- Code segments which generated the goals
goalSrcBoundaries: Array (Nat × Nat) := #[] goalSrcBoundaries: Array (Nat × Nat) := #[]
messages: Array String := #[] messages: Array String := #[]
newConstants: Option (Array String) := .none
deriving Lean.ToJson deriving Lean.ToJson
structure FrontendProcessResult where structure FrontendProcessResult where
units: List CompilationUnit units: List CompilationUnit

View File

@ -262,9 +262,17 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
else else
pure [] pure []
let messages ← step.messageStrings let messages ← step.messageStrings
return (step.before, boundary, invocations?, sorrys, messages) let newConstants ← if args.newConstants then
Frontend.collectNewDefinedConstants step
else
pure []
return (step.before, boundary, invocations?, sorrys, messages, newConstants)
let li ← frontendM.run context |>.run' state let li ← frontendM.run context |>.run' state
let units ← li.mapM λ (env, boundary, invocations?, sorrys, messages) => Lean.withEnv env do let units ← li.mapM λ (env, boundary, invocations?, sorrys, messages, newConstants) => Lean.withEnv env do
let newConstants := if args.newConstants then
.some $ newConstants.toArray.map λ name => name.toString
else
.none
let (goalStateId?, goals, goalSrcBoundaries) ← if sorrys.isEmpty then do let (goalStateId?, goals, goalSrcBoundaries) ← if sorrys.isEmpty then do
pure (.none, #[], #[]) pure (.none, #[], #[])
else do else do
@ -279,6 +287,7 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
goals, goals,
goalSrcBoundaries, goalSrcBoundaries,
messages, messages,
newConstants,
} }
return .ok { units } return .ok { units }
catch e => catch e =>

View File

@ -174,6 +174,7 @@ def test_frontend_process : Test :=
("file", .str file), ("file", .str file),
("invocations", .bool true), ("invocations", .bool true),
("sorrys", .bool false), ("sorrys", .bool false),
("newConstants", .bool false),
] ]
({ ({
units := [{ units := [{
@ -214,6 +215,7 @@ def test_frontend_process_sorry : Test :=
("file", .str file), ("file", .str file),
("invocations", .bool false), ("invocations", .bool false),
("sorrys", .bool true), ("sorrys", .bool true),
("newConstants", .bool false),
] ]
({ ({
units := [{ units := [{