Skip to content

Commit be97757

Browse files
committed
chore: lake: code cleanup
* remove MTime `checkIfNewer` * remove unnecessary `@[noinline]` * inline `MainM` combinators
1 parent 3be4d74 commit be97757

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

src/lake/Lake/Build/Monad.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ where
7878
| e => throw e
7979

8080
/-- The name of the Lake build lock file name (i.e., `lake.lock`). -/
81-
@[noinline] def lockFileName : String :=
81+
def lockFileName : String :=
8282
"lake.lock"
8383

8484
/-- The workspace's build lock file. -/

src/lake/Lake/Build/Trace.lean

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,6 @@ instance [GetMTime α] : ComputeTrace α IO MTime := ⟨getMTime⟩
205205
instance : GetMTime FilePath := ⟨getFileMTime⟩
206206
instance : GetMTime TextFilePath := ⟨(getFileMTime ·.path)⟩
207207

208-
/-- Check if the info's `MTIme` is at least `depMTime`. -/
209-
@[inline] def checkIfNewer [GetMTime i] (info : i) (depMTime : MTime) : BaseIO Bool :=
210-
(return (depMTime < (← getMTime info) : Bool)).catchExceptions fun _ => pure false
211-
212208
--------------------------------------------------------------------------------
213209
/-! # Lake Build Trace (Hash + MTIme) -/
214210
--------------------------------------------------------------------------------
@@ -260,7 +256,8 @@ That is, check if the info is newer than this input trace's modification time.
260256
-/
261257
@[inline] def checkAgainstTime [GetMTime i]
262258
(info : i) (self : BuildTrace) : BaseIO Bool :=
263-
checkIfNewer info self.mtime
259+
EIO.catchExceptions (h := fun _ => pure false) do
260+
return self.mtime < (← getMTime info)
264261

265262
/--
266263
Check if the info is up-to-date using a trace file.

src/lake/Lake/CLI/Main.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ abbrev CliM := ArgsT CliStateM
8585

8686
def CliM.run (self : CliM α) (args : List String) : BaseIO ExitCode := do
8787
let (elanInstall?, leanInstall?, lakeInstall?) ← findInstall?
88-
let main := self args |>.run' {elanInstall?, leanInstall?, lakeInstall?}
88+
let main := self.run' args |>.run' {elanInstall?, leanInstall?, lakeInstall?}
8989
let main := main.run >>= fun | .ok a => pure a | .error e => error e.toString
9090
main.run
9191

@@ -416,4 +416,4 @@ def lake : CliM PUnit := do
416416
throw <| CliError.missingCommand
417417

418418
def cli (args : List String) : BaseIO ExitCode :=
419-
(lake).run args
419+
inline <| (lake).run args

src/lake/Lake/Config/Module.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ abbrev pkg (self : Module) : Package :=
8686
self.irPath "o"
8787

8888
/-- Suffix for single module dynlibs (e.g., for precompilation). -/
89-
@[noinline] def dynlibSuffix := "-1"
89+
def dynlibSuffix := "-1"
9090

9191
@[inline] def dynlibName (self : Module) : String :=
9292
-- NOTE: file name MUST be unique on Windows

src/lake/Lake/Util/Git.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ namespace Lake
1111

1212
namespace Git
1313

14-
@[noinline] def defaultRemote :=
14+
def defaultRemote :=
1515
"origin"
1616

17-
@[noinline] def upstreamBranch :=
17+
def upstreamBranch :=
1818
"master"
1919

2020
/--
@@ -42,7 +42,7 @@ instance : ToString GitRepo := ⟨(·.dir.toString)⟩
4242

4343
namespace GitRepo
4444

45-
@[noinline] def cwd : GitRepo := ⟨"."
45+
def cwd : GitRepo := ⟨"."
4646

4747
@[inline] def dirExists (repo : GitRepo) : BaseIO Bool :=
4848
repo.dir.isDir

src/lake/Lake/Util/MainM.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,31 @@ namespace MainM
3333
@[inline] protected def toBaseIO (self : MainM α) : BaseIO (Except ExitCode α) :=
3434
self.toEIO.toBaseIO
3535

36-
protected def run (self : MainM α) : BaseIO ExitCode :=
36+
@[inline] protected def run (self : MainM α) : BaseIO ExitCode :=
3737
self.toBaseIO.map fun | Except.ok _ => 0 | Except.error rc => rc
3838

3939
/-! # Exits -/
4040

4141
/-- Exit with given return code. -/
42-
protected def exit (rc : ExitCode) : MainM α :=
42+
@[inline] protected def exit (rc : ExitCode) : MainM α :=
4343
MainM.mk <| throw rc
4444

4545
instance : MonadExit MainM := ⟨MainM.exit⟩
4646

4747
/-- Try this and catch exits. -/
48-
protected def tryCatchExit (f : ExitCode → MainM α) (self : MainM α) : MainM α :=
48+
@[inline] protected def tryCatchExit (f : ExitCode → MainM α) (self : MainM α) : MainM α :=
4949
self.toEIO.tryCatch f
5050

5151
/-- Try this and catch error codes (i.e., non-zero exits). -/
52-
protected def tryCatchError (f : ExitCode → MainM α) (self : MainM α) : MainM α :=
52+
@[inline] protected def tryCatchError (f : ExitCode → MainM α) (self : MainM α) : MainM α :=
5353
self.tryCatchExit fun rc => if rc = 0 then exit 0 else f rc
5454

5555
/-- Exit with a generic error code (i.e., 1). -/
56-
protected def failure : MainM α :=
56+
@[inline] protected def failure : MainM α :=
5757
exit 1
5858

5959
/-- If this exits with an error code (i.e., not 0), perform other. -/
60-
protected def orElse (self : MainM α) (other : Unit → MainM α) : MainM α :=
60+
@[inline] protected def orElse (self : MainM α) (other : Unit → MainM α) : MainM α :=
6161
self.tryCatchExit fun rc => if rc = 0 then exit 0 else other ()
6262

6363
instance : Alternative MainM where
@@ -69,14 +69,14 @@ instance : Alternative MainM where
6969
instance : MonadLog MainM := MonadLog.eio
7070

7171
/-- Print out a error line with the given message and then exit with an error code. -/
72-
protected def error (msg : String) (rc : ExitCode := 1) : MainM α := do
72+
@[inline] protected def error (msg : String) (rc : ExitCode := 1) : MainM α := do
7373
logError msg
7474
exit rc
7575

7676
instance : MonadError MainM := ⟨MainM.error⟩
7777
instance : MonadLift IO MainM := ⟨MonadError.runEIO⟩
7878

79-
def runLogIO (x : LogIO α) (verbosity := Verbosity.normal) : MainM α :=
79+
@[inline] def runLogIO (x : LogIO α) (verbosity := Verbosity.normal) : MainM α :=
8080
liftM <| x.run <| MonadLog.eio verbosity
8181

8282
instance : MonadLift LogIO MainM := ⟨runLogIO⟩

0 commit comments

Comments
 (0)