Skip to content

Commit

Permalink
[skc] Merge fileTimeDir into allFilesDir.
Browse files Browse the repository at this point in the history
  • Loading branch information
beauby committed Oct 8, 2024
1 parent ae10b81 commit e93beb3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 40 deletions.
1 change: 0 additions & 1 deletion skiplang/compiler/src/compile.sk
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
56 changes: 17 additions & 39 deletions skiplang/compiler/src/skipParse.sk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const fileDir: SKStore.EHandle<
fileDirName,
);

class InputPackage(name: ?String, srcs: Array<String>) 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.
Expand All @@ -35,22 +38,10 @@ const allFilesDir: SKStore.EHandle<SKStore.IID, InputPackage> = 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<String>, Array<String>, Array<String>) {
added_files = mutable Vector[];
modified_files = mutable Vector[];
deleted_files = mutable Vector[];
Expand All @@ -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)
}
};

Expand Down Expand Up @@ -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<?String>[];
Expand All @@ -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 (
Expand All @@ -145,43 +129,37 @@ 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),
Array[SKStore.StringFile(src_contents)],
)
};
// 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(
Expand Down

0 comments on commit e93beb3

Please sign in to comment.