refactor: Optionalize CompilationUnit

This commit is contained in:
Leni Aniva 2024-12-09 21:00:33 -08:00
parent eb0374dfb3
commit 1527743900
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
3 changed files with 17 additions and 14 deletions

View File

@ -327,14 +327,16 @@ structure InvokedTactic where
structure CompilationUnit where structure CompilationUnit where
-- String boundaries of compilation units -- String boundaries of compilation units
boundary: (Nat × Nat) boundary: (Nat × Nat)
messages: Array String := #[]
-- Tactic invocations -- Tactic invocations
invocations?: Option (List InvokedTactic) := .none invocations?: Option (List InvokedTactic) := .none
goalStateId?: Option Nat := .none goalStateId?: Option Nat := .none
goals: Array Goal := #[] goals?: Option (Array Goal) := .none
-- Code segments which generated the goals -- Code segments which generated the goals
goalSrcBoundaries: Array (Nat × Nat) := #[] goalSrcBoundaries?: Option (Array (Nat × Nat)) := .none
messages: Array String := #[]
newConstants: Option (Array String) := .none -- New constants defined in compilation unit
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

@ -269,25 +269,26 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
return (step.before, boundary, invocations?, sorrys, messages, newConstants) 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, newConstants) => Lean.withEnv env do let units ← li.mapM λ (env, boundary, invocations?, sorrys, messages, newConstants) => Lean.withEnv env do
let newConstants := if args.newConstants then let newConstants? := if args.newConstants then
.some $ newConstants.toArray.map λ name => name.toString .some $ newConstants.toArray.map λ name => name.toString
else else
.none .none
let (goalStateId?, goals, goalSrcBoundaries) ← if sorrys.isEmpty then do let (goalStateId?, goals?, goalSrcBoundaries?) ← if sorrys.isEmpty then do
pure (.none, #[], #[]) pure (.none, .none, .none)
else do else do
let { state, srcBoundaries } ← runMetaInMainM $ Frontend.sorrysToGoalState sorrys let { state, srcBoundaries } ← runMetaInMainM $ Frontend.sorrysToGoalState sorrys
let stateId ← newGoalState state let stateId ← newGoalState state
let goals ← goalSerialize state options let goals ← goalSerialize state options
pure (.some stateId, goals, srcBoundaries.toArray.map (λ (b, e) => (b.byteIdx, e.byteIdx))) let srcBoundaries := srcBoundaries.toArray.map (λ (b, e) => (b.byteIdx, e.byteIdx))
pure (.some stateId, .some goals, .some srcBoundaries)
return { return {
boundary, boundary,
messages,
invocations?, invocations?,
goalStateId?, goalStateId?,
goals, goals?,
goalSrcBoundaries, goalSrcBoundaries?,
messages, newConstants?,
newConstants,
} }
return .ok { units } return .ok { units }
catch e => catch e =>

View File

@ -223,8 +223,8 @@ def test_frontend_process_sorry : Test :=
}, { }, {
boundary := (solved.utf8ByteSize, solved.utf8ByteSize + withSorry.utf8ByteSize), boundary := (solved.utf8ByteSize, solved.utf8ByteSize + withSorry.utf8ByteSize),
goalStateId? := .some 0, goalStateId? := .some 0,
goals := #[goal1], goals? := .some #[goal1],
goalSrcBoundaries := #[(57, 62)], goalSrcBoundaries? := .some #[(57, 62)],
messages := #["<anonymous>:2:0: warning: declaration uses 'sorry'\n"], messages := #["<anonymous>:2:0: warning: declaration uses 'sorry'\n"],
}], }],
}: Protocol.FrontendProcessResult), }: Protocol.FrontendProcessResult),