Skip to content

Commit 80b0859

Browse files
committed
chore: minor review-related touchups
1 parent 14bc481 commit 80b0859

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

src/LeanIR.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ public def main (args : List String) : IO UInt32 := do
9191
-- level exported because otherwise we would try to load the current module's `.ir`
9292
finalizeImport (leakEnv := true) (loadExts := false) (level := .exported) (loadIRSig := true) s imports opts
9393
let env := env.setMainModule modName
94-
-- As the environment imports the module to compile, it does not inherit its package.
95-
-- Take it from the setup.
9694
let env := env.setModulePackage setup.package?
9795

9896
let initExt {α β σ} [Inhabited σ] (ext : PersistentEnvExtension α β σ) (env : Environment) : IO Environment := do

src/lake/Lake/Build/Common.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,19 @@ public def cacheFileHash (file : FilePath) (text := false) : IO Unit := do
387387
let hash ← computeFileHash file text
388388
writeFileHash file hash
389389

390+
/--
391+
If `file` exists, computes its hash and saves it to a `.hash` file.
392+
393+
If `text := true`, `file` is hashed as a text file rather than a binary file.
394+
-/
395+
public def cacheFileHashIfExists (file : FilePath) (text := false) : IO Unit := do
396+
try
397+
let hash ← computeFileHash file text
398+
writeFileHash file hash
399+
catch
400+
| .noFileOrDirectory .. => pure ()
401+
| e => throw e
402+
390403
/-- Remove the cached hash of a file (its `.hash` file) if it exists. -/
391404
public def clearFileHash (file : FilePath) : IO Unit := do
392405
removeFileIfExists <| file.toString ++ ".hash"

src/lake/Lake/Build/Module.lean

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -768,22 +768,20 @@ public def Module.clearOutputHashes (mod : Module) : IO PUnit := do
768768

769769
/-- Cache the file hashes of the module build outputs in `.hash` files. -/
770770
public def Module.cacheOutputHashes (mod : Module) : IO PUnit := do
771-
if (← mod.ltarFile.pathExists) then
772-
cacheFileHash mod.ltarFile
773-
cacheFileHash mod.oleanFile
774-
if (← mod.oleanServerFile.pathExists) then
775-
cacheFileHash mod.oleanServerFile
776-
if (← mod.oleanPrivateFile.pathExists) then
777-
cacheFileHash mod.oleanPrivateFile
778-
cacheFileHash mod.ileanFile
779-
if (← mod.irSigFile.pathExists) then
780-
cacheFileHash mod.irSigFile
781-
if (← mod.irFile.pathExists) then
782-
cacheFileHash mod.irFile
783-
if (← mod.cFile.pathExists) then
784-
cacheFileHash mod.cFile
785-
if Lean.Internal.hasLLVMBackend () then
786-
cacheFileHash mod.bcFile
771+
-- Hashes on not conditional on module metadata (e.g., `isModule`).
772+
-- Lake will determine which files to use (and which to delete) as part of the build proccess.
773+
try
774+
cacheFileHashIfExists mod.ltarFile
775+
cacheFileHashIfExists mod.oleanFile
776+
cacheFileHashIfExists mod.oleanServerFile
777+
cacheFileHashIfExists mod.oleanPrivateFile
778+
cacheFileHashIfExists mod.ileanFile
779+
cacheFileHashIfExists mod.irSigFile
780+
cacheFileHashIfExists mod.irFile
781+
cacheFileHashIfExists mod.cFile
782+
cacheFileHashIfExists mod.bcFile
783+
catch e =>
784+
error s!"failed to save output hashes: {e}"
787785

788786
def ModuleOutputDescrs.resolve
789787
(descrs : ModuleOutputDescrs) (service? : Option CacheServiceName) (scope? : Option CacheServiceScope)

0 commit comments

Comments
 (0)