Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lake: properly prepend job log in ensureJob #6291

Merged
merged 1 commit into from
Dec 3, 2024
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
10 changes: 6 additions & 4 deletions src/lake/Lake/Build/Fetch.lean
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,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 @@ -64,6 +64,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 @@ -262,9 +262,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
Loading