diff --git a/KLR/Compile.lean b/KLR/Compile.lean index 311ef673..4ca83113 100644 --- a/KLR/Compile.lean +++ b/KLR/Compile.lean @@ -30,11 +30,15 @@ open Pass (CompileResult) private partial def uniqueName (dst : String) (base : String) : IO String := do let fName := s!"{dst}/{base}.npy" - if ← FilePath.pathExists (FilePath.mk fName) then - let suffix ← IO.rand 0 (2^64 - 1) - uniqueName dst s!"{base}_{suffix}" - else + if !(← FilePath.pathExists (FilePath.mk fName)) then return base + let entries ← System.FilePath.readDir (FilePath.mk dst) + let count := entries.filter (fun e => + e.fileName.startsWith s!"{base}_" && e.fileName.endsWith ".npy") |>.size + let gen := mkStdGen count + let (suffix, _) := RandomGen.next gen + let suffix := suffix % (2^64) + uniqueName dst s!"{base}_{suffix}" private def sharedConstant (outfolder : String)