feat: add Plan 20 Slice 1 CMake native translation, self-test smoke target, VL-009 VOID_TEST check, and warm-cache hardening
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 5s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 5s
This commit is contained in:
1 parent
363fb8200e
commit
d3d2666965
19 files changed
+1466
-65
No files matched your search
+54
-13
@@ -19,6 +19,7 @@
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Void::Build::Execution {
|
||||
namespace {
|
||||
@@ -28,7 +29,42 @@ Void::Result::Error make_error(std::string msg) {
|
||||
std::move(msg));
|
||||
}
|
||||
|
||||
std::string compute_effective_action_key(const Graph::ActionNode &action) {
|
||||
// Run-scoped thread-safe SHA-256 memo table. Every path is hashed at most once per
|
||||
// execute_graph() run across all worker threads, and invalidated immediately whenever an
|
||||
// action actually executes and writes its declared outputs.
|
||||
class RunDigestCache {
|
||||
public:
|
||||
[[nodiscard]] std::optional<std::string> hash_file(const std::filesystem::path &path) {
|
||||
const std::string key = path.lexically_normal().string();
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
if (const auto it = cache_.find(key); it != cache_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
auto d = Util::sha256_file_hex(path);
|
||||
std::optional<std::string> val =
|
||||
d ? std::optional<std::string>{std::move(*d)} : std::nullopt;
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
cache_.insert_or_assign(key, val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
void invalidate(const std::filesystem::path &path) {
|
||||
const std::string key = path.lexically_normal().string();
|
||||
std::lock_guard lk{mu_};
|
||||
cache_.erase(key);
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex mu_;
|
||||
std::unordered_map<std::string, std::optional<std::string>> cache_;
|
||||
};
|
||||
|
||||
std::string compute_effective_action_key(const Graph::ActionNode &action,
|
||||
RunDigestCache &digest_cache) {
|
||||
// Re-hash declared input file bytes at execution time (including generated upstream outputs!)
|
||||
// so downstream compile/archive/link actions invalidate immediately when an upstream artifact
|
||||
// changes.
|
||||
@@ -36,7 +72,7 @@ std::string compute_effective_action_key(const Graph::ActionNode &action) {
|
||||
hasher.update_length_prefixed(action.action_key);
|
||||
for (const auto &in_path : action.declared_inputs) {
|
||||
hasher.update_length_prefixed(in_path.string());
|
||||
if (auto digest = Util::sha256_file_hex(in_path); digest) {
|
||||
if (auto digest = digest_cache.hash_file(in_path); digest) {
|
||||
hasher.update_length_prefixed(*digest);
|
||||
} else {
|
||||
hasher.update_length_prefixed("<missing>");
|
||||
@@ -46,9 +82,10 @@ std::string compute_effective_action_key(const Graph::ActionNode &action) {
|
||||
}
|
||||
|
||||
bool verify_discovered_inputs_unchanged(
|
||||
const std::map<std::string, std::string, std::less<>> &discovered_inputs) {
|
||||
const std::map<std::string, std::string, std::less<>> &discovered_inputs,
|
||||
RunDigestCache &digest_cache) {
|
||||
for (const auto &[path_str, expected_sha] : discovered_inputs) {
|
||||
auto actual = Util::sha256_file_hex(std::filesystem::path{path_str});
|
||||
auto actual = digest_cache.hash_file(std::filesystem::path{path_str});
|
||||
if (!actual || *actual != expected_sha) {
|
||||
return false;
|
||||
}
|
||||
@@ -57,13 +94,14 @@ bool verify_discovered_inputs_unchanged(
|
||||
}
|
||||
|
||||
bool verify_outputs_match_record(const Graph::ActionNode &action,
|
||||
const State::ActionSuccessRecord &record) {
|
||||
const State::ActionSuccessRecord &record,
|
||||
RunDigestCache &digest_cache) {
|
||||
for (const auto &out_path : action.declared_outputs) {
|
||||
const auto it = record.outputs.find(out_path.string());
|
||||
if (it == record.outputs.end()) {
|
||||
return false;
|
||||
}
|
||||
auto actual = Util::sha256_file_hex(out_path);
|
||||
auto actual = digest_cache.hash_file(out_path);
|
||||
if (!actual || *actual != it->second.sha256) {
|
||||
return false;
|
||||
}
|
||||
@@ -73,7 +111,7 @@ bool verify_outputs_match_record(const Graph::ActionNode &action,
|
||||
|
||||
bool restore_outputs_from_cache(const Graph::ActionNode &action,
|
||||
const State::ActionSuccessRecord &record,
|
||||
const State::StateStore &state) {
|
||||
const State::StateStore &state, RunDigestCache &digest_cache) {
|
||||
for (const auto &out_path : action.declared_outputs) {
|
||||
const auto it = record.outputs.find(out_path.string());
|
||||
if (it == record.outputs.end()) {
|
||||
@@ -83,6 +121,7 @@ bool restore_outputs_from_cache(const Graph::ActionNode &action,
|
||||
if (!mat) {
|
||||
return false;
|
||||
}
|
||||
digest_cache.invalidate(out_path);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -269,6 +308,7 @@ execute_graph(const Graph::BuildGraph &graph, State::StateStore &state,
|
||||
std::size_t completed_count = 0;
|
||||
std::atomic<std::size_t> started_exec_count{0};
|
||||
bool abort_scheduling = false;
|
||||
RunDigestCache digest_cache;
|
||||
|
||||
auto action_label = [&](const Graph::ActionNode &act) -> std::string {
|
||||
auto rel_name = [&](const std::filesystem::path &p) -> std::string {
|
||||
@@ -325,16 +365,16 @@ execute_graph(const Graph::BuildGraph &graph, State::StateStore &state,
|
||||
return res;
|
||||
}
|
||||
|
||||
const std::string effective_key = compute_effective_action_key(act);
|
||||
const std::string effective_key = compute_effective_action_key(act, digest_cache);
|
||||
|
||||
// 1. Cache lookup (ONLY when action is deterministic & cacheable!).
|
||||
if (act.cacheable && !act.nondeterministic && options.use_cache) {
|
||||
auto cached = state.lookup_action(effective_key);
|
||||
if (cached && cached->has_value()) {
|
||||
const auto &rec = **cached;
|
||||
if (verify_discovered_inputs_unchanged(rec.discovered_inputs)) {
|
||||
if (verify_outputs_match_record(act, rec) ||
|
||||
restore_outputs_from_cache(act, rec, state)) {
|
||||
if (verify_discovered_inputs_unchanged(rec.discovered_inputs, digest_cache)) {
|
||||
if (verify_outputs_match_record(act, rec, digest_cache) ||
|
||||
restore_outputs_from_cache(act, rec, state, digest_cache)) {
|
||||
res.succeeded = true;
|
||||
res.from_cache = true;
|
||||
res.exit_code = 0;
|
||||
@@ -422,8 +462,9 @@ execute_graph(const Graph::BuildGraph &graph, State::StateStore &state,
|
||||
return res;
|
||||
}
|
||||
|
||||
// 4. Validate ALL declared outputs exist after zero exit!
|
||||
// 4. Validate ALL declared outputs exist after zero exit and drop stale memo entries!
|
||||
for (const auto &out : act.declared_outputs) {
|
||||
digest_cache.invalidate(out);
|
||||
auto meta = Platform::stat_lstat(out);
|
||||
if (!meta || !meta->exists || !meta->is_regular) {
|
||||
res.error_message =
|
||||
@@ -456,7 +497,7 @@ execute_graph(const Graph::BuildGraph &graph, State::StateStore &state,
|
||||
act.id, dep_abs.string(), prod_it->second);
|
||||
return res;
|
||||
}
|
||||
if (auto digest = Util::sha256_file_hex(dep_abs); digest) {
|
||||
if (auto digest = digest_cache.hash_file(dep_abs); digest) {
|
||||
discovered_inputs[dep_abs.string()] = std::move(*digest);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user