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

View File

@ -262,9 +262,17 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
else
pure []
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 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
pure (.none, #[], #[])
else do
@ -279,6 +287,7 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
goals,
goalSrcBoundaries,
messages,
newConstants,
}
return .ok { units }
catch e =>

View File

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