Skip to content

Commit d8f70b5

Browse files
committed
fix(cli): restore direct script cache behavior
2 parents e9baf1b + 26286d2 commit d8f70b5

3 files changed

Lines changed: 26 additions & 47 deletions

File tree

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -941,19 +941,22 @@ namespace vix::commands::RunCommand::detail
941941
// ===========================================================================
942942

943943
/**
944-
* @brief Return the file modification time as Unix nanoseconds.
944+
* @brief Return a stable, order-preserving file modification timestamp.
945945
*
946-
* std::filesystem::file_time_type may use a clock whose epoch differs from
947-
* std::chrono::system_clock. Converting file_time_type::time_since_epoch()
948-
* directly to an unsigned Unix timestamp is therefore not portable and can
949-
* yield negative values for perfectly valid files.
946+
* std::filesystem::file_time_type may use an implementation-defined epoch,
947+
* so its timestamp must not be interpreted directly as a Unix timestamp.
950948
*
951-
* This helper translates the filesystem clock to system_clock before
952-
* producing a nanosecond timestamp.
949+
* For cache fingerprints we need the value to be stable across repeated
950+
* reads of the same file. For timestamp comparisons we also need the encoded
951+
* unsigned value to preserve the ordering of the underlying signed
952+
* filesystem-clock timestamp.
953+
*
954+
* Flipping the sign bit maps the signed nanosecond representation into an
955+
* unsigned value while preserving chronological ordering.
953956
*
954957
* @param p File whose modification time should be queried.
955958
* @param ec Receives any filesystem error.
956-
* @return Modification time in Unix nanoseconds, or 0 on failure.
959+
* @return Stable encoded modification timestamp, or 0 on failure.
957960
*/
958961
inline std::uint64_t file_mtime_ns(
959962
const fs::path &p,
@@ -971,26 +974,16 @@ namespace vix::commands::RunCommand::detail
971974

972975
using namespace std::chrono;
973976

974-
const auto fileNow =
975-
fs::file_time_type::clock::now();
976-
977-
const auto systemNow =
978-
system_clock::now();
979-
980-
const auto systemTime =
981-
systemNow +
982-
duration_cast<system_clock::duration>(
983-
fileTime - fileNow);
984-
985977
const auto ns =
986978
duration_cast<nanoseconds>(
987-
systemTime.time_since_epoch())
979+
fileTime.time_since_epoch())
988980
.count();
989981

990-
if (ns <= 0)
991-
return 0;
982+
const auto signedNs =
983+
static_cast<std::int64_t>(ns);
992984

993-
return static_cast<std::uint64_t>(ns);
985+
return static_cast<std::uint64_t>(signedNs) ^
986+
(std::uint64_t{1} << 63);
994987
}
995988

996989
/**

src/commands/run/detail/DirectScriptRunner.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,20 +1186,23 @@ namespace vix::commands::RunCommand::detail
11861186
out.needsRebuild = true;
11871187

11881188
/*
1189-
* A deterministic failed build is also a valid cache result.
1189+
* A previous compilation failure may keep its diagnostic payload,
1190+
* but it must never suppress a future compilation attempt.
11901191
*
1191-
* Check it before requiring the binary: failed compilations and
1192-
* link steps intentionally have no executable.
1192+
* Source files, generated headers, compiler state, or external
1193+
* dependencies may have changed independently of the cached failure,
1194+
* so failed builds are informational only and are not cache hits.
11931195
*/
11941196
if (load_direct_failure_cache(
11951197
plan,
11961198
out))
11971199
{
1198-
out.cacheHit = true;
1199-
out.cachedFailure = true;
1200-
out.needsRebuild = false;
1200+
out.cacheHit = false;
1201+
out.cachedFailure = false;
1202+
out.needsRebuild = true;
1203+
out.cachedFailureExitCode = 0;
12011204
out.rebuildReason =
1202-
"cached compile failure";
1205+
"previous compile failure";
12031206

12041207
return out;
12051208
}

src/commands/run/detail/ScriptProbe.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -919,23 +919,6 @@ namespace vix::commands::RunCommand::detail
919919
return out;
920920
}
921921

922-
/*
923-
* Direct compilation does not yet have a reliable representation of
924-
* Vix's transitive runtime link graph.
925-
*
926-
* Keep plain standalone C++ on the fast Direct path, but route scripts
927-
* using Vix through the generated CMake project where exported Vix
928-
* targets provide the complete link graph.
929-
*/
930-
if (out.features.usesVix)
931-
{
932-
out.strategy = ScriptExecutionStrategy::CMakeFallback;
933-
out.fallbackReason = ScriptFallbackReason::UsesVixRuntime;
934-
out.canUseDirectCompile = false;
935-
out.shouldUseCMakeFallback = true;
936-
return out;
937-
}
938-
939922
const bool allowDirect =
940923
!unsupportedFlags &&
941924
(!out.usesCompiledDeps || onlyVixIncludesAdded) &&

0 commit comments

Comments
 (0)