Skip to content

Commit

Permalink
fix: lake: properly prepend job log in ensureJob
Browse files Browse the repository at this point in the history
  • Loading branch information
tydeu committed Dec 2, 2024
1 parent 27df5e9 commit 1fc5c25
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/lake/Lake/Build/Fetch.lean
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ def ensureJob (x : FetchM (Job α))
let iniPos := log.endPos
match (← (withLoggedIO x) fetch stack ctx log store) with
| (.ok job log, store) =>
let (log, jobLog) := log.split iniPos
let job := if jobLog.isEmpty then job else job.mapResult (sync := true)
(·.modifyState (.modifyLog (jobLog ++ ·)))
return (.ok job log, store)
if iniPos < log.endPos then
let (log, jobLog) := log.split iniPos
let job := job.mapResult (sync := true) (·.prependLog jobLog)
return (.ok job log, store)
else
return (.ok job log, store)
| (.error _ log, store) =>
let (log, jobLog) := log.split iniPos
return (.ok (.error jobLog) log, store)
Expand Down
6 changes: 6 additions & 0 deletions src/lake/Lake/Build/Job.lean
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def JobState.merge (a b : JobState) : JobState where
/-- The result of a Lake job. -/
abbrev JobResult α := EResult Log.Pos JobState α

/-- Add log entries to the beginning of the job's log. -/
def JobResult.prependLog (log : Log) (self : JobResult α) : JobResult α :=
match self with
| .ok a s => .ok a <| s.modifyLog (log ++ ·)
| .error e s => .error ⟨log.size + e.val⟩ <| s.modifyLog (log ++ ·)

/-- The `Task` of a Lake job. -/
abbrev JobTask α := BaseIOTask (JobResult α)

Expand Down
11 changes: 10 additions & 1 deletion src/lake/Lake/Util/Log.lean
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,18 @@ instance : FromJson Log := ⟨(Log.mk <$> fromJson? ·)⟩
/-- A position in a `Log` (i.e., an array index). Can be past the log's end. -/
structure Log.Pos where
val : Nat
deriving Inhabited
deriving Inhabited, DecidableEq

instance : OfNat Log.Pos (nat_lit 0) := ⟨⟨0⟩⟩
instance : Ord Log.Pos := ⟨(compare ·.val ·.val)⟩
instance : LT Log.Pos := ⟨(·.val < ·.val)⟩
instance : DecidableRel (LT.lt (α := Log.Pos)) :=
inferInstanceAs (DecidableRel (α := Log.Pos) (·.val < ·.val))
instance : LE Log.Pos := ⟨(·.val ≤ ·.val)⟩
instance : DecidableRel (LE.le (α := Log.Pos)) :=
inferInstanceAs (DecidableRel (α := Log.Pos) (·.val ≤ ·.val))
instance : Min Log.Pos := minOfLe
instance : Max Log.Pos := maxOfLe

namespace Log

Expand Down

0 comments on commit 1fc5c25

Please sign in to comment.