Implement the VLS roadmap on the native VBS build
Native VBS and CMake builds of the server and every registered suite: protocol and document sync, VBS/compdb providers, stock GCC diagnostics (including in-process default profile preparation), the stock occurrence observer and hover/definition, the bounded Scheduler, C++ module graph, scan and artifact cache with real CMI production, the context-aware symbol index with schema-2 snapshot migration, navigation and guarded rename, reflection provenance with splice-origin extraction, index-backed completion and signature help, live GCC worker control with a registered DAP suite, and the Neovim and VS Code clients. VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced from the versioned patches and verified stepping reflection/template code with projected values 17/34 and 41/82.
This commit is contained in:
1 parent
ca04975d54
commit
da8003f6d4
310 files changed
+47552
-480
No files matched your search
@@ -0,0 +1,307 @@
|
||||
#include <vls/modules/ArtifactCache.hpp>
|
||||
#include <vls/modules/ScheduledArtifacts.hpp>
|
||||
#include <vls/scheduler/Scheduler.hpp>
|
||||
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <condition_variable>
|
||||
#include <fstream>
|
||||
#include <latch>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
namespace fs = std::filesystem;
|
||||
using namespace vls::modules;
|
||||
namespace Sched = vls::scheduler;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
ArtifactKey key(std::string context, std::string inputs = "inputs") {
|
||||
return {"gcc-16.2.0/x86_64", std::move(context), std::move(inputs), "cmi"};
|
||||
}
|
||||
|
||||
fs::path write(const fs::path &root, std::string_view name, std::string_view text) {
|
||||
const auto path = root / name;
|
||||
fs::create_directories(path.parent_path());
|
||||
std::ofstream stream{path, std::ios::binary};
|
||||
stream << text;
|
||||
stream.close();
|
||||
require(stream.good());
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string read(const fs::path &path) {
|
||||
std::ifstream stream{path, std::ios::binary};
|
||||
require(stream.good());
|
||||
return {std::istreambuf_iterator<char>{stream}, {}};
|
||||
}
|
||||
|
||||
std::size_t files(const fs::path &root) {
|
||||
std::size_t count{};
|
||||
for (const auto &entry : fs::directory_iterator{root})
|
||||
if (entry.is_regular_file())
|
||||
++count;
|
||||
return count;
|
||||
}
|
||||
|
||||
ModulePlan ready_plan(std::vector<Build::ContextKey> &keys) {
|
||||
ModulePlan plan;
|
||||
plan.domain.compatibility = "gcc-16.2.0/x86_64";
|
||||
plan.claims_complete = true;
|
||||
for (std::size_t index = 0; index != 3; ++index) {
|
||||
const auto name = "unit" + std::to_string(index);
|
||||
Build::ContextKey context{
|
||||
{}, {}, Build::ContextRole::target, name, fs::path{"/project"} / (name + ".cpp")};
|
||||
CensusMember member{context,
|
||||
{"/project", name + ".o"},
|
||||
{"command-" + name, "source-" + name, "closure-" + name, {}},
|
||||
"scan-" + name,
|
||||
{}};
|
||||
plan.units.push_back({member, UnitKind::primary_interface, {}});
|
||||
plan.order.push_back(context);
|
||||
keys.push_back(context);
|
||||
}
|
||||
return plan;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(ArtifactCache, publishes_and_finds) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
const auto first = write(temp.path() / "src", "first.gcm", "first artifact");
|
||||
const auto second = write(temp.path() / "src", "second.gcm", "second artifact");
|
||||
auto published = cache.publish({{key("one"), first}, {key("two"), second}});
|
||||
require(published.has_value());
|
||||
const auto generation = *published;
|
||||
expect(generation->id().size() == 64);
|
||||
expect(cache.current() == generation);
|
||||
const auto one = generation->find(key("one"));
|
||||
require(one.has_value());
|
||||
expect(read(one->path) == "first artifact" && one->sha256.size() == 64);
|
||||
require(generation->find(key("two")).has_value());
|
||||
expect(!generation->find(key("missing")).has_value());
|
||||
expect(cache.generations() == 1);
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, failed_publication_leaves_nothing) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
const auto valid = write(temp.path(), "valid.gcm", "valid");
|
||||
auto published =
|
||||
cache.publish({{key("valid"), valid}, {key("missing"), temp.path() / "missing.gcm"}});
|
||||
require(!published.has_value());
|
||||
expect(!cache.current());
|
||||
expect(cache.generations() == 0);
|
||||
expect(fs::is_empty(temp.path() / "cache" / "tmp"));
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, identical_contents_share_one_file) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
const auto first = write(temp.path(), "first.gcm", "same bytes");
|
||||
const auto second = write(temp.path(), "second.gcm", "same bytes");
|
||||
auto published = cache.publish({{key("one"), first}, {key("two"), second}});
|
||||
require(published.has_value());
|
||||
expect(files((*published)->root()) == 2); // manifest plus one content file
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, readers_retain_generations_across_collect) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache", 1};
|
||||
const auto source = write(temp.path(), "artifact.gcm", "retained");
|
||||
auto first = cache.publish({{key("one"), source}});
|
||||
require(first.has_value());
|
||||
const auto first_root = (*first)->root();
|
||||
require(cache.publish({{key("two"), source}}).has_value());
|
||||
require(cache.publish({{key("three"), source}}).has_value());
|
||||
cache.collect();
|
||||
expect(fs::is_directory(first_root));
|
||||
first = {};
|
||||
cache.collect();
|
||||
expect(!fs::exists(first_root));
|
||||
expect(cache.generations() == 2);
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, eviction_respects_the_retained_limit) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache", 1};
|
||||
for (int index = 0; index != 5; ++index) {
|
||||
const auto source = write(temp.path(), "artifact.gcm", "content " + std::to_string(index));
|
||||
require(cache.publish({{key("unit" + std::to_string(index)), source}}).has_value());
|
||||
}
|
||||
expect(cache.generations() == 5);
|
||||
cache.collect();
|
||||
expect(cache.generations() == 2);
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, producer_publishes_in_dependency_order) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
std::vector<Build::ContextKey> keys;
|
||||
const auto plan = ready_plan(keys);
|
||||
std::vector<std::string> order;
|
||||
auto produced = produce_module_artifacts(
|
||||
plan, cache, temp.path() / "staging",
|
||||
[&](std::stop_token, const Build::ContextKey &context,
|
||||
const fs::path &output) -> std::expected<fs::path, std::string> {
|
||||
order.push_back(context.alternative);
|
||||
fs::create_directories(output.parent_path());
|
||||
std::ofstream stream{output, std::ios::binary};
|
||||
stream << "artifact for " << context.alternative;
|
||||
stream.close();
|
||||
if (!stream)
|
||||
return std::unexpected(std::string{"write failed"});
|
||||
return output;
|
||||
});
|
||||
require(produced.has_value());
|
||||
expect(order.size() == 3);
|
||||
for (std::size_t index = 0; index != 3; ++index)
|
||||
expect(order[index] == keys[index].alternative);
|
||||
expect((*produced)
|
||||
->find(key(keys[0].alternative, "command-unit0|source-unit0|closure-unit0|"))
|
||||
.has_value());
|
||||
expect(!fs::exists(temp.path() / "staging"));
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, producer_failure_publishes_nothing) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
std::vector<Build::ContextKey> keys;
|
||||
const auto plan = ready_plan(keys);
|
||||
std::size_t calls{};
|
||||
auto produced = produce_module_artifacts(
|
||||
plan, cache, temp.path() / "staging",
|
||||
[&](std::stop_token, const Build::ContextKey &,
|
||||
const fs::path &output) -> std::expected<fs::path, std::string> {
|
||||
if (++calls == 2)
|
||||
return std::unexpected("compile failed");
|
||||
fs::create_directories(output.parent_path());
|
||||
std::ofstream{output} << "artifact";
|
||||
return output;
|
||||
});
|
||||
require(!produced.has_value());
|
||||
expect(produced.error() == "compile failed");
|
||||
expect(!cache.current());
|
||||
expect(cache.generations() == 0);
|
||||
expect(!fs::exists(temp.path() / "staging"));
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, producer_cancellation_publishes_nothing) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
std::vector<Build::ContextKey> keys;
|
||||
const auto plan = ready_plan(keys);
|
||||
std::stop_source cancellation;
|
||||
cancellation.request_stop();
|
||||
auto produced = produce_module_artifacts(
|
||||
plan, cache, temp.path() / "staging",
|
||||
[](std::stop_token, const Build::ContextKey &, const fs::path &output) {
|
||||
return std::expected<fs::path, std::string>{output};
|
||||
},
|
||||
cancellation.get_token());
|
||||
require(!produced.has_value());
|
||||
expect(cache.generations() == 0);
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, refuses_an_unready_plan) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
ModulePlan plan;
|
||||
plan.domain.compatibility = "gcc-16.2.0/x86_64";
|
||||
auto produced = produce_module_artifacts(
|
||||
plan, cache, temp.path() / "staging",
|
||||
[](std::stop_token, const Build::ContextKey &, const fs::path &output) {
|
||||
return std::expected<fs::path, std::string>{output};
|
||||
});
|
||||
require(!produced.has_value());
|
||||
expect(produced.error() == "module plan is not ready");
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, scheduled_production_publishes_in_order) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
Sched::Scheduler pool{Sched::Budget{.foreground = 1,
|
||||
.background = 1,
|
||||
.artifact = 1,
|
||||
.queued = 8,
|
||||
.memory_mib = 64,
|
||||
.watchdog = std::chrono::seconds{5}}};
|
||||
std::vector<Build::ContextKey> keys;
|
||||
const auto plan = ready_plan(keys);
|
||||
std::vector<std::string> order;
|
||||
auto produced = produce_module_artifacts_scheduled(
|
||||
plan, cache, temp.path() / "staging",
|
||||
[&](std::stop_token, const Build::ContextKey &context,
|
||||
const fs::path &output) -> std::expected<fs::path, std::string> {
|
||||
order.push_back(context.alternative);
|
||||
fs::create_directories(output.parent_path());
|
||||
std::ofstream{output} << "artifact " << context.alternative;
|
||||
return output;
|
||||
},
|
||||
pool);
|
||||
require(produced.has_value());
|
||||
expect(order.size() == 3);
|
||||
for (std::size_t index = 0; index != 3; ++index)
|
||||
expect(order[index] == keys[index].alternative);
|
||||
expect((*produced)
|
||||
->find(key(keys[0].alternative, "command-unit0|source-unit0|closure-unit0|"))
|
||||
.has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(ArtifactCache, superseded_scheduled_production_publishes_nothing) {
|
||||
Void::FileSystem::TempDir temp{"vls_artifact_cache_"};
|
||||
ArtifactCache cache{temp.path() / "cache"};
|
||||
Sched::Scheduler pool{Sched::Budget{.foreground = 1,
|
||||
.background = 1,
|
||||
.artifact = 1,
|
||||
.queued = 8,
|
||||
.memory_mib = 64,
|
||||
.watchdog = std::chrono::seconds{5}}};
|
||||
std::vector<Build::ContextKey> keys;
|
||||
const auto plan = ready_plan(keys);
|
||||
std::latch started{1};
|
||||
std::mutex mutex;
|
||||
std::condition_variable changed;
|
||||
bool release{};
|
||||
std::expected<std::shared_ptr<const ArtifactGeneration>, std::string> result =
|
||||
std::unexpected("not run");
|
||||
std::thread producer{[&] {
|
||||
result = produce_module_artifacts_scheduled(
|
||||
plan, cache, temp.path() / "staging",
|
||||
[&](std::stop_token stop, const Build::ContextKey &,
|
||||
const fs::path &output) -> std::expected<fs::path, std::string> {
|
||||
started.count_down();
|
||||
std::unique_lock lock{mutex};
|
||||
changed.wait(lock, [&] { return release; });
|
||||
if (stop.stop_requested())
|
||||
return std::unexpected("cancelled");
|
||||
fs::create_directories(output.parent_path());
|
||||
std::ofstream{output} << "artifact";
|
||||
return output;
|
||||
},
|
||||
pool);
|
||||
}};
|
||||
started.wait();
|
||||
require(pool.submit(
|
||||
{.priority = Sched::Priority::artifact,
|
||||
.key = keys[0].alternative,
|
||||
.revision = 2,
|
||||
.memory_mib = 0},
|
||||
[](std::stop_token) { return std::string{}; }, [](Sched::Result) {}));
|
||||
{
|
||||
std::lock_guard lock{mutex};
|
||||
release = true;
|
||||
changed.notify_all();
|
||||
}
|
||||
producer.join();
|
||||
require(!result.has_value());
|
||||
expect(result.error() == "artifact production cancelled");
|
||||
expect(!cache.current());
|
||||
expect(cache.generations() == 0);
|
||||
}
|
||||
Reference in new issue
Block a user