From e93beb34b046b70bd14163acae0cf0922f7e4d9d Mon Sep 17 00:00:00 2001 From: Lucas Hosseini Date: Tue, 8 Oct 2024 14:05:25 +0200 Subject: [PATCH] [skc] Merge `fileTimeDir` into `allFilesDir`. --- skiplang/compiler/src/compile.sk | 1 - skiplang/compiler/src/skipParse.sk | 56 +++++++++--------------------- 2 files changed, 17 insertions(+), 40 deletions(-) diff --git a/skiplang/compiler/src/compile.sk b/skiplang/compiler/src/compile.sk index f790a5400..223b41560 100644 --- a/skiplang/compiler/src/compile.sk +++ b/skiplang/compiler/src/compile.sk @@ -204,7 +204,6 @@ fun getOrInitializeBackend( }; _ = context.mkdir(x ~> x, x ~> x, FileCache.fileDirName); - _ = context.mkdir(x ~> x, x ~> x, FileCache.fileTimeDirName); _ = context.mkdir(x ~> x, x ~> x, FileCache.allFilesDirName); backendDir = context.mkdir( SKStore.IID::keyType, diff --git a/skiplang/compiler/src/skipParse.sk b/skiplang/compiler/src/skipParse.sk index 05e37b4f7..7afa12ffb 100644 --- a/skiplang/compiler/src/skipParse.sk +++ b/skiplang/compiler/src/skipParse.sk @@ -22,7 +22,10 @@ const fileDir: SKStore.EHandle< fileDirName, ); -class InputPackage(name: ?String, srcs: Array) extends SKStore.File +class InputPackage( + name: ?String, + srcs: Array<(String, Int)>, +) extends SKStore.File // Contains the paths of all source files the analysis of which has // been kept so far. @@ -35,22 +38,10 @@ const allFilesDir: SKStore.EHandle = SKStore.EHandle( allFilesDirName, ); -const fileTimeDirName: SKStore.DirName = SKStore.DirName::create( - "/fileTimeCache/", -); -const fileTimeDir: SKStore.EHandle< - SKStore.SID, - SKStore.IntFile, -> = SKStore.EHandle( - SKStore.SID::keyType, - SKStore.IntFile::type, - fileTimeDirName, -); - fun pkgDelta( old_srcs: Array<(String, Int)>, new_srcs: Array<(String, Int)>, -): (Array<(String, Int)>, Array<(String, Int)>, Array<(String, Int)>) { +): (Array, Array, Array) { added_files = mutable Vector[]; modified_files = mutable Vector[]; deleted_files = mutable Vector[]; @@ -60,16 +51,16 @@ fun pkgDelta( old_srcs.find(s -> s.i0 == src) match { | Some((_, old_mtime)) -> if (mtime != old_mtime) { - modified_files.push((src, mtime)) + modified_files.push(src) } - | None() -> added_files.push((src, mtime)) + | None() -> added_files.push(src) } }; // FIXME: This is O(n^2). - for ((src, mtime) in old_srcs) { + for ((src, _) in old_srcs) { if (!new_srcs.any(s -> s.i0 == src)) { - deleted_files.push((src, mtime)) + deleted_files.push(src) } }; @@ -110,14 +101,7 @@ fun writeFiles( // Files kept in the previous run. old_files = mutable Map[]; for (pkg in allFilesDir.unsafeGetArray(context, SKStore.IID(0))) { - srcs_with_mtime = pkg.srcs - .map(fn -> { - key = formatPkgSrc(pkg.name, fn); - mtime = fileTimeDir.unsafeGetArray(context, SKStore.SID(key))[0].value; - (fn, mtime) - }) - .collect(Array); - old_files.set(pkg.name, srcs_with_mtime) + old_files.set(pkg.name, pkg.srcs) }; stale_pkgs = mutable Vector[]; @@ -132,7 +116,7 @@ fun writeFiles( ) { pkgDelta(old_files[pkg_opt], srcs.map(src -> (src.i0, src.i1))); } else { - (srcs.map(src -> (src.i0, src.i1)), Array[], Array[]) + (srcs.map(src -> src.i0), Array[], Array[]) }; if ( @@ -145,15 +129,10 @@ fun writeFiles( stale_pkgs.push(pkg_opt); // Update added/modified files. - for ((src_path, src_mtime) in added_files.concat(modified_files)) { + for (src_path in added_files.concat(modified_files)) { key = formatPkgSrc(pkg_opt, src_path); // FIXME: This is O(n). src_contents = srcs.find(src ~> src.i0 == src_path).fromSome().i2; - fileTimeDir.writeArray( - context, - SKStore.SID(key), - Array[SKStore.IntFile(src_mtime)], - ); fileDir.writeArray( context, SKStore.SID(key), @@ -161,27 +140,26 @@ fun writeFiles( ) }; // Invalidate deleted files. - for ((src_path, _) in deleted_files) { + for (src_path in deleted_files) { key = formatPkgSrc(pkg_opt, src_path); fileDir.writeArray( context, SKStore.SID(key), Array[SKStore.StringFile("")], - ); - fileTimeDir.writeArray(context, SKStore.SID(key), Array[]) + ) } }; - // Keep analysis for all non-stale packages. new_old_files = current_files - .map((_, srcs) -> srcs.map(src -> src.i0)) + .map((_, srcs) -> srcs.map(src -> (src.i0, src.i1))) .clone(); + // Keep analysis for all non-stale packages. for (pkg_opt => srcs in old_files) { // FIXME: This is O(n). if (stale_pkgs.contains(pkg_opt)) { continue }; - new_old_files.set(pkg_opt, srcs.map(src -> src.i0).collect(Array)) + new_old_files.set(pkg_opt, srcs) }; allFilesDir.writeArray(