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);
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
#include <Void/LanguageServer/Protocol/Json.hpp>
|
||||
#include <vls/modules/ModuleGraph.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
namespace Modules = vls::modules;
|
||||
namespace Build = Modules::Build;
|
||||
namespace Protocol = Void::LanguageServer::Protocol;
|
||||
namespace fs = std::filesystem;
|
||||
using Json = Protocol::Json;
|
||||
|
||||
constexpr std::size_t max_manifest_bytes = 2 * 1024 * 1024;
|
||||
constexpr std::size_t max_report_bytes = 8192;
|
||||
|
||||
const Json &field(const Json::Object &object, std::string_view name) {
|
||||
if (const auto *value = Protocol::find_member(object, name))
|
||||
return *value;
|
||||
throw std::runtime_error("missing field " + std::string(name));
|
||||
}
|
||||
|
||||
const Json::Object &object(const Json &value) {
|
||||
if (const auto *fields = Protocol::as_object(&value))
|
||||
return *fields;
|
||||
throw std::runtime_error("expected an object");
|
||||
}
|
||||
|
||||
const Json::Array &array(const Json &value, std::size_t limit) {
|
||||
if (const auto *items = Protocol::as_array(&value); items && items->size() <= limit)
|
||||
return *items;
|
||||
throw std::runtime_error("expected a bounded array");
|
||||
}
|
||||
|
||||
const std::string &string(const Json &value, std::size_t limit = Modules::max_field_bytes) {
|
||||
if (const auto *text = Protocol::as_string(&value); text && text->size() <= limit)
|
||||
return *text;
|
||||
throw std::runtime_error("expected a bounded string");
|
||||
}
|
||||
|
||||
const std::string &string(const Json::Object &value, std::string_view name) {
|
||||
return string(field(value, name));
|
||||
}
|
||||
|
||||
bool flag(const Json::Object &value, std::string_view name) {
|
||||
if (const auto bit = Protocol::as_bool(&field(value, name)))
|
||||
return *bit;
|
||||
throw std::runtime_error("expected a boolean field " + std::string(name));
|
||||
}
|
||||
|
||||
int exit_status(const Json::Object &value) {
|
||||
if (const auto *code = std::get_if<std::int64_t>(&field(value, "exit").value);
|
||||
code && *code >= 0 && *code <= 255)
|
||||
return static_cast<int>(*code);
|
||||
throw std::runtime_error("expected an exit status");
|
||||
}
|
||||
|
||||
Modules::ScanMethod scan_method(const std::vector<std::string> &argv) {
|
||||
const auto has = [&](std::string_view option) { return std::ranges::contains(argv, option); };
|
||||
if (has("-E") && has("-MD"))
|
||||
return Modules::ScanMethod::preprocess_md;
|
||||
if (has("-M") && has("-MG"))
|
||||
return Modules::ScanMethod::missing_allowed;
|
||||
throw std::runtime_error("unexpected fixture scan mode");
|
||||
}
|
||||
|
||||
std::string_view kind_name(Modules::UnitKind kind) {
|
||||
using enum Modules::UnitKind;
|
||||
switch (kind) {
|
||||
case unknown:
|
||||
return "unknown";
|
||||
case ordinary:
|
||||
return "ordinary";
|
||||
case implementation:
|
||||
return "implementation";
|
||||
case primary_interface:
|
||||
return "primary_interface";
|
||||
case interface_partition:
|
||||
return "interface_partition";
|
||||
case internal_partition:
|
||||
return "internal_partition";
|
||||
case header_unit:
|
||||
return "header_unit";
|
||||
}
|
||||
throw std::runtime_error("unexpected unit kind");
|
||||
}
|
||||
|
||||
Json report(const Modules::ModulePlan &plan, const Modules::ModuleCensus &census) {
|
||||
Json::Array order, blockers;
|
||||
Json::Object units;
|
||||
for (const auto &key : plan.order)
|
||||
order.push_back(Json{key.alternative});
|
||||
for (const auto &unit : plan.units) {
|
||||
Json::Array consumers;
|
||||
for (const auto consumer : unit.consumers)
|
||||
consumers.push_back(Json{plan.units.at(consumer).member.context.alternative});
|
||||
units.emplace(unit.member.context.alternative,
|
||||
Json{Json::Object{{"kind", Json{std::string(kind_name(unit.kind))}},
|
||||
{"consumers", Json{std::move(consumers)}}}});
|
||||
}
|
||||
for (const auto &blocker : plan.blockers) {
|
||||
using enum Modules::PlanIssue;
|
||||
const auto code = blocker.code;
|
||||
std::string name = std::to_string(static_cast<int>(code));
|
||||
if (code == scan_failed)
|
||||
name = "scan_failed";
|
||||
else if (code == invalid_rule)
|
||||
name = "invalid_rule";
|
||||
else if (code == incomplete_scan)
|
||||
name = "incomplete_scan";
|
||||
else if (code == unproven_mapping)
|
||||
name = "unproven_mapping";
|
||||
Json::Object status{{"code", Json{std::move(name)}}, {"detail", Json{blocker.detail}}};
|
||||
if (blocker.unit)
|
||||
status.emplace("unit", Json{plan.units.at(*blocker.unit).member.context.alternative});
|
||||
if (blocker.scan_error == Modules::ScanError::invalid_json)
|
||||
status.emplace("scan_error", Json{std::string("invalid_json")});
|
||||
else if (blocker.scan_error == Modules::ScanError::wrong_output)
|
||||
status.emplace("scan_error", Json{std::string("wrong_output")});
|
||||
else if (blocker.scan_error)
|
||||
status.emplace("scan_error", Json{static_cast<std::int64_t>(*blocker.scan_error)});
|
||||
blockers.push_back(Json{std::move(status)});
|
||||
}
|
||||
return Json{Json::Object{{"ready", Json{plan.ready()}},
|
||||
{"claims_complete", Json{plan.claims_complete}},
|
||||
{"matches_census", Json{plan.matches_census(census)}},
|
||||
{"order", Json{std::move(order)}},
|
||||
{"units", Json{std::move(units)}},
|
||||
{"blockers", Json{std::move(blockers)}}}};
|
||||
}
|
||||
|
||||
// verify.py attests the closed fixture and passes data only. No path in the
|
||||
// manifest is opened and none of the recorded argv is run by this executable.
|
||||
Json plan_fixture(const Json::Object &manifest) {
|
||||
const fs::path root = string(manifest, "cwd");
|
||||
const auto &toolchain = string(manifest, "toolchain");
|
||||
const auto &revision = string(manifest, "revision");
|
||||
const auto &requested = string(manifest, "requested");
|
||||
Modules::ModuleCensus census{
|
||||
{{}, string(manifest, "compatibility"), string(manifest, "lookup")}, revision, true, {}};
|
||||
std::vector<Build::BuildContext> contexts;
|
||||
std::vector<Modules::ScanEvidence> scans;
|
||||
|
||||
for (const auto &item : array(field(manifest, "members"), 5)) {
|
||||
const auto &entry = object(item);
|
||||
const auto &name = string(entry, "name");
|
||||
const auto &source = string(entry, "source");
|
||||
const auto &primary = string(entry, "primary_output");
|
||||
const auto &scan_revision = string(entry, "scan_revision");
|
||||
const Build::ContextKey key{
|
||||
{}, {}, Build::ContextRole::target, name, root / string(entry, "owning_source")};
|
||||
const Modules::ExpectedOutput expected{root, primary};
|
||||
const Modules::UnitInputs inputs{string(entry, "command_id"),
|
||||
string(entry, "source_id"),
|
||||
string(entry, "textual_closure"),
|
||||
{}};
|
||||
std::vector<std::string> argv;
|
||||
for (const auto &argument : array(field(entry, "argv"), 64))
|
||||
argv.push_back(string(argument));
|
||||
const auto scan_filename = "scan-" + name + ".json";
|
||||
if (argv.empty() || argv.back() != source ||
|
||||
!std::ranges::contains(argv, "-fdeps-target=" + primary) ||
|
||||
!std::ranges::contains(argv, "-fdeps-file=" + scan_filename))
|
||||
throw std::runtime_error("invocation does not match scan label " + name);
|
||||
|
||||
const auto method = scan_method(argv);
|
||||
Build::BuildContext context;
|
||||
context.key = key;
|
||||
context.source_language = "c++";
|
||||
context.working_directory = root;
|
||||
context.toolchain = toolchain;
|
||||
context.original =
|
||||
Build::OriginalCommand{root / scan_filename, scan_revision, std::move(argv), {}, {}};
|
||||
context.sources = {{key.owning_tu, key.owning_tu, Build::SourceOrigin::workspace,
|
||||
Build::Editability::read_only, inputs.source}};
|
||||
contexts.push_back(std::move(context));
|
||||
|
||||
census.members.push_back({key, expected, inputs, scan_revision, {}});
|
||||
Modules::ScanEvidence scan;
|
||||
scan.context = key;
|
||||
scan.inputs = inputs;
|
||||
scan.scan_revision = scan_revision;
|
||||
scan.exit_status = exit_status(entry);
|
||||
scan.rule =
|
||||
Modules::decode_scan(string(field(entry, "p1689"), Modules::max_scan_bytes), expected);
|
||||
scan.method = method;
|
||||
scan.complete = flag(entry, "complete");
|
||||
if (flag(entry, "no_header_units"))
|
||||
scan.header_uses.emplace();
|
||||
if (flag(entry, "header_provider"))
|
||||
scan.provided_headers.push_back({0, key.owning_tu.string()});
|
||||
scan.writers = {(root / string(entry, "writer")).string()};
|
||||
scans.push_back(std::move(scan));
|
||||
}
|
||||
|
||||
auto generation = Build::BuildGeneration::create(
|
||||
{{root, "gcc-module-corpus"}, "stock-gcc-scanner", revision}, contexts);
|
||||
if (!generation)
|
||||
throw std::runtime_error("fixture BuildGeneration rejected");
|
||||
census.domain.generation = *generation;
|
||||
for (auto &scan : scans)
|
||||
scan.domain = census.domain;
|
||||
const auto selected = std::ranges::find_if(census.members, [&](const auto &member) {
|
||||
return member.context.alternative == requested;
|
||||
});
|
||||
if (selected == census.members.end())
|
||||
throw std::runtime_error("missing requested fixture command");
|
||||
return report(Modules::build_module_plan(census, scans, selected->context), census);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **) {
|
||||
try {
|
||||
if (argc != 1)
|
||||
throw std::runtime_error("expected one fixture manifest on stdin");
|
||||
std::string bytes;
|
||||
std::array<char, 4096> buffer{};
|
||||
while (std::cin) {
|
||||
std::cin.read(buffer.data(), buffer.size());
|
||||
bytes.append(buffer.data(), static_cast<std::size_t>(std::cin.gcount()));
|
||||
if (bytes.size() > max_manifest_bytes)
|
||||
throw std::runtime_error("fixture manifest too large");
|
||||
}
|
||||
if (std::cin.bad())
|
||||
throw std::runtime_error("fixture manifest read failed");
|
||||
const auto input = Protocol::parse_json(bytes, Modules::max_scan_depth);
|
||||
if (!input)
|
||||
throw std::runtime_error(input.error());
|
||||
const auto output = Protocol::serialize_json(plan_fixture(object(*input)));
|
||||
if (!output)
|
||||
throw std::runtime_error(output.error());
|
||||
if (output->size() >= max_report_bytes)
|
||||
throw std::runtime_error("fixture report too large");
|
||||
std::cout << *output << '\n';
|
||||
return std::cout ? 0 : 2;
|
||||
} catch (const std::exception &error) {
|
||||
std::cerr << "vls_module_scan_fixture: " << error.what() << '\n';
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
#include <vls/modules/ArtifactCache.hpp>
|
||||
#include <vls/modules/GccArtifacts.hpp>
|
||||
#include <vls/modules/GccScan.hpp>
|
||||
#include <vls/modules/ModuleWorkQueue.hpp>
|
||||
#include <vls/modules/ScheduledArtifacts.hpp>
|
||||
#include <vls/scheduler/Scheduler.hpp>
|
||||
|
||||
#include <Void/LanguageServer/Protocol/Json.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <iostream>
|
||||
#include <latch>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
namespace Modules = vls::modules;
|
||||
namespace Build = Modules::Build;
|
||||
namespace Protocol = Void::LanguageServer::Protocol;
|
||||
namespace fs = std::filesystem;
|
||||
using Json = Protocol::Json;
|
||||
|
||||
constexpr std::size_t max_manifest_bytes = 2 * 1024 * 1024;
|
||||
|
||||
const Json::Object &object(const Json &value) {
|
||||
if (const auto *fields = Protocol::as_object(&value))
|
||||
return *fields;
|
||||
throw std::runtime_error("expected an object");
|
||||
}
|
||||
|
||||
const Json &field(const Json::Object &object, std::string_view name) {
|
||||
if (const auto *value = Protocol::find_member(object, name))
|
||||
return *value;
|
||||
throw std::runtime_error("missing field " + std::string(name));
|
||||
}
|
||||
|
||||
const std::string &string(const Json &value, std::size_t limit = 4096) {
|
||||
if (const auto *text = Protocol::as_string(&value); text && text->size() <= limit)
|
||||
return *text;
|
||||
throw std::runtime_error("expected a bounded string");
|
||||
}
|
||||
|
||||
std::vector<std::string> strings(const Json &value, std::size_t limit) {
|
||||
const auto *items = Protocol::as_array(&value);
|
||||
if (!items || items->size() > limit)
|
||||
throw std::runtime_error("expected a bounded array");
|
||||
std::vector<std::string> result;
|
||||
for (const auto &item : *items)
|
||||
result.push_back(string(item));
|
||||
return result;
|
||||
}
|
||||
|
||||
struct Unit {
|
||||
std::string alternative;
|
||||
Modules::ModuleCommand command;
|
||||
Modules::UnitInputs inputs;
|
||||
};
|
||||
|
||||
Json run(const Json::Object &manifest) {
|
||||
if (const auto *mode = Protocol::as_string(Protocol::find_member(manifest, "mode"));
|
||||
mode && *mode == "scan") {
|
||||
namespace Sched = vls::scheduler;
|
||||
const fs::path directory = string(field(manifest, "directory"));
|
||||
const fs::path working = string(field(manifest, "working_directory"));
|
||||
const auto command = strings(field(manifest, "command"), 1024);
|
||||
const auto &output_fields = object(field(manifest, "output"));
|
||||
const Modules::ExpectedOutput output{string(field(output_fields, "working_directory")),
|
||||
string(field(output_fields, "spelling"))};
|
||||
auto product = std::make_shared<Modules::ScanProduct>();
|
||||
Sched::Scheduler pool{Sched::Budget{.foreground = 1,
|
||||
.background = 1,
|
||||
.artifact = 1,
|
||||
.queued = 4,
|
||||
.memory_mib = 64,
|
||||
.watchdog = std::chrono::seconds{120}}};
|
||||
Modules::ModuleWorkQueue queue{pool};
|
||||
std::string failure;
|
||||
auto work = Modules::gcc_module_scan_work(
|
||||
[&](const Build::ContextKey &) -> std::optional<Modules::ScanCommand> {
|
||||
return Modules::ScanCommand{working, command, output};
|
||||
},
|
||||
Build::ContextKey{{}, {}, Build::ContextRole::target, "scan", working / "unit.cpp"},
|
||||
product,
|
||||
Modules::ScanOptions{directory, std::chrono::milliseconds{120000},
|
||||
Modules::max_scan_bytes});
|
||||
if (!queue.submit("scan-document", Modules::ModuleWorkKind::scan, 1, std::move(work),
|
||||
[&](Modules::ModuleTaskResult result) {
|
||||
if (result.outcome != Sched::Outcome::completed)
|
||||
failure = result.detail;
|
||||
}))
|
||||
throw std::runtime_error("scan admission was refused");
|
||||
pool.drain();
|
||||
if (!failure.empty())
|
||||
throw std::runtime_error(failure);
|
||||
Json::Array provides, imports;
|
||||
for (const auto &module : product->rule->provides())
|
||||
provides.push_back(Json{module.logical_name});
|
||||
for (const auto &module : product->rule->requirements())
|
||||
imports.push_back(Json{module.logical_name});
|
||||
std::string generation;
|
||||
if (!product->rule->provides().empty()) {
|
||||
Modules::ArtifactCache cache{directory / "artifacts"};
|
||||
Modules::ModulePlan plan;
|
||||
plan.domain.compatibility = "gcc-corpus/x86_64";
|
||||
plan.claims_complete = true;
|
||||
const Build::ContextKey context{{}, {}, Build::ContextRole::target, "artifact",
|
||||
working / "artifact.cpp"};
|
||||
const Modules::UnitInputs inputs{"artifact-command", "artifact-source",
|
||||
"artifact-closure", {}};
|
||||
plan.units.push_back({{context, {working, "artifact.o"}, inputs, "artifact-scan", {}},
|
||||
Modules::UnitKind::primary_interface, {}});
|
||||
plan.order.push_back(context);
|
||||
Modules::ModuleCommand artifact_command{
|
||||
working, {command.front(), "-std=c++26", "-fmodules-ts", "-c", command.back(),
|
||||
"-o", (directory / "module.o").native()}};
|
||||
auto produced = Modules::produce_module_artifacts_scheduled(
|
||||
plan, cache, directory / "artifact-staging",
|
||||
Modules::gcc_module_artifact_work(
|
||||
[&](const Build::ContextKey &) -> std::optional<Modules::ModuleCommand> {
|
||||
return artifact_command;
|
||||
}),
|
||||
pool);
|
||||
if (!produced)
|
||||
throw std::runtime_error(produced.error());
|
||||
generation = (*produced)->id();
|
||||
}
|
||||
return Json{Json::Object{{"p1689", Json{product->p1689}},
|
||||
{"provides", Json{std::move(provides)}},
|
||||
{"requires", Json{std::move(imports)}},
|
||||
{"generation", Json{std::move(generation)}}}};
|
||||
}
|
||||
const fs::path staging = string(field(manifest, "staging"));
|
||||
const fs::path cache_path = string(field(manifest, "cache"));
|
||||
const std::string &compatibility = string(field(manifest, "compatibility"));
|
||||
std::vector<Unit> units;
|
||||
for (const auto &item : *Protocol::as_array(&field(manifest, "units"))) {
|
||||
const auto &entry = object(item);
|
||||
Unit unit;
|
||||
unit.alternative = string(field(entry, "alternative"));
|
||||
unit.command.working_directory = string(field(entry, "working_directory"));
|
||||
unit.command.arguments = strings(field(entry, "command"), 1024);
|
||||
unit.inputs = {string(field(entry, "command_id")), string(field(entry, "source_id")),
|
||||
string(field(entry, "textual_closure")), std::nullopt};
|
||||
units.push_back(std::move(unit));
|
||||
}
|
||||
if (units.empty() || units.size() > 64)
|
||||
throw std::runtime_error("expected a bounded unit list");
|
||||
|
||||
Modules::ModulePlan plan;
|
||||
plan.domain.compatibility = compatibility;
|
||||
plan.claims_complete = true;
|
||||
std::map<std::string, Modules::ModuleCommand> commands;
|
||||
for (const auto &unit : units) {
|
||||
Build::ContextKey context{{},
|
||||
{},
|
||||
Build::ContextRole::target,
|
||||
unit.alternative,
|
||||
fs::path{"/fixture"} / (unit.alternative + ".cpp")};
|
||||
Modules::CensusMember member{context,
|
||||
{"/fixture", unit.alternative + ".o"},
|
||||
unit.inputs,
|
||||
"scan-" + unit.alternative,
|
||||
{}};
|
||||
plan.units.push_back({member, Modules::UnitKind::primary_interface, {}});
|
||||
plan.order.push_back(context);
|
||||
commands.emplace(unit.alternative, unit.command);
|
||||
}
|
||||
Modules::ArtifactCache cache{cache_path};
|
||||
const Modules::ModuleCommandLookup lookup =
|
||||
[&](const Build::ContextKey &context) -> std::optional<Modules::ModuleCommand> {
|
||||
const auto command = commands.find(context.alternative);
|
||||
if (command == commands.end())
|
||||
return std::nullopt;
|
||||
return command->second;
|
||||
};
|
||||
if (Protocol::as_bool(Protocol::find_member(manifest, "supersede")).value_or(false)) {
|
||||
namespace Sched = vls::scheduler;
|
||||
Sched::Scheduler pool{Sched::Budget{.foreground = 1,
|
||||
.background = 1,
|
||||
.artifact = 1,
|
||||
.queued = 8,
|
||||
.memory_mib = 1024,
|
||||
.watchdog = std::chrono::seconds{120}}};
|
||||
std::latch started{1};
|
||||
std::mutex mutex;
|
||||
std::condition_variable changed;
|
||||
bool release{};
|
||||
const Modules::ArtifactWork real = Modules::gcc_module_artifact_work(lookup);
|
||||
std::expected<std::shared_ptr<const Modules::ArtifactGeneration>, std::string> superseded =
|
||||
std::unexpected("not run");
|
||||
std::thread producer{[&] {
|
||||
superseded = Modules::produce_module_artifacts_scheduled(
|
||||
plan, cache, staging,
|
||||
[&](std::stop_token stop, const Build::ContextKey &context,
|
||||
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");
|
||||
return real(stop, context, output);
|
||||
},
|
||||
pool);
|
||||
}};
|
||||
started.wait();
|
||||
if (!pool.submit(
|
||||
{.priority = Sched::Priority::artifact,
|
||||
.key = units.front().alternative,
|
||||
.revision = 2,
|
||||
.memory_mib = 0},
|
||||
[](std::stop_token) { return std::string{}; }, [](Sched::Result) {})) {
|
||||
release = true;
|
||||
changed.notify_all();
|
||||
producer.join();
|
||||
throw std::runtime_error("superseding submission was refused");
|
||||
}
|
||||
{
|
||||
std::lock_guard lock{mutex};
|
||||
release = true;
|
||||
changed.notify_all();
|
||||
}
|
||||
producer.join();
|
||||
if (superseded)
|
||||
throw std::runtime_error("a superseded module build published a generation");
|
||||
if (cache.current() || cache.generations() != 0)
|
||||
throw std::runtime_error("a superseded module build left artifacts behind");
|
||||
auto clean = Modules::produce_module_artifacts_scheduled(
|
||||
plan, cache, staging, Modules::gcc_module_artifact_work(lookup), pool);
|
||||
if (!clean)
|
||||
throw std::runtime_error(clean.error());
|
||||
return Json{Json::Object{{"superseded", Json{true}},
|
||||
{"published", Json{false}},
|
||||
{"clean_generation", Json{(*clean)->id()}}}};
|
||||
}
|
||||
auto produced = Modules::produce_module_artifacts(plan, cache, staging,
|
||||
Modules::gcc_module_artifact_work(lookup));
|
||||
if (!produced)
|
||||
throw std::runtime_error(produced.error());
|
||||
Json::Array artifacts;
|
||||
for (const auto &unit : units) {
|
||||
const Modules::ArtifactKey key{compatibility, unit.alternative,
|
||||
unit.inputs.command + "|" + unit.inputs.source + "|" +
|
||||
unit.inputs.textual_closure + "|" +
|
||||
unit.inputs.system_closure.value_or(""),
|
||||
"cmi"};
|
||||
const auto entry = (*produced)->find(key);
|
||||
if (!entry)
|
||||
throw std::runtime_error("published generation is missing " + unit.alternative);
|
||||
artifacts.push_back(Json{Json::Object{{"alternative", Json{unit.alternative}},
|
||||
{"path", Json{entry->path.native()}},
|
||||
{"sha256", Json{entry->sha256}}}});
|
||||
}
|
||||
return Json{Json::Object{{"generation", Json{(*produced)->id()}},
|
||||
{"artifacts", Json{std::move(artifacts)}}}};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
try {
|
||||
std::string bytes;
|
||||
char buffer[4096];
|
||||
while (std::cin) {
|
||||
std::cin.read(buffer, sizeof buffer);
|
||||
bytes.append(buffer, static_cast<std::size_t>(std::cin.gcount()));
|
||||
if (bytes.size() > max_manifest_bytes)
|
||||
throw std::runtime_error("fixture manifest too large");
|
||||
}
|
||||
if (std::cin.bad())
|
||||
throw std::runtime_error("fixture manifest read failed");
|
||||
const auto input = Protocol::parse_json(bytes, 8);
|
||||
if (!input)
|
||||
throw std::runtime_error(input.error());
|
||||
const auto output = Protocol::serialize_json(run(object(*input)));
|
||||
if (!output)
|
||||
throw std::runtime_error(output.error());
|
||||
std::cout << *output << '\n';
|
||||
return std::cout ? 0 : 2;
|
||||
} catch (const std::exception &error) {
|
||||
std::cerr << "vls_module_artifact_fixture: " << error.what() << '\n';
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,593 @@
|
||||
#include <vls/modules/ModuleGraph.hpp>
|
||||
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
using namespace vls::modules;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
const ExpectedOutput invocation{"/project/private", "same.o"};
|
||||
|
||||
// The extra rule fields are literal JSON from small scanner fixtures.
|
||||
std::string wire(std::string_view fields = {}) {
|
||||
std::string json = R"({"version":0,"revision":0,"rules":[{"primary-output":"same.o")";
|
||||
if (!fields.empty()) {
|
||||
json += ',';
|
||||
json += fields;
|
||||
}
|
||||
return json + "}]}";
|
||||
}
|
||||
|
||||
std::string named(std::string_view provision, std::vector<std::string> imports = {},
|
||||
bool is_interface = true) {
|
||||
std::string fields = R"("provides":[)";
|
||||
if (!provision.empty()) {
|
||||
fields += R"({"logical-name":")" + std::string(provision) + R"(","is-interface":)" +
|
||||
(is_interface ? "true}" : "false}");
|
||||
}
|
||||
fields += R"(],"requires":[)";
|
||||
for (std::size_t i = 0; i < imports.size(); ++i) {
|
||||
if (i)
|
||||
fields += ',';
|
||||
fields += R"({"logical-name":")" + imports[i] + R"("})";
|
||||
}
|
||||
return fields + ']';
|
||||
}
|
||||
|
||||
struct Fixture {
|
||||
ModuleCensus census;
|
||||
std::vector<ScanEvidence> scans;
|
||||
|
||||
explicit Fixture(std::size_t count) {
|
||||
std::vector<Build::BuildContext> records;
|
||||
for (std::size_t i = 0; i < count; ++i) {
|
||||
const auto name = "unit" + std::to_string(i);
|
||||
Build::BuildContext record;
|
||||
record.key = {"debug", "app", Build::ContextRole::target, name,
|
||||
std::filesystem::path("/project") / (name + ".cpp")};
|
||||
record.working_directory = invocation.working_directory;
|
||||
record.sources.push_back({record.key.owning_tu,
|
||||
{},
|
||||
Build::SourceOrigin::workspace,
|
||||
Build::Editability::editable,
|
||||
{}});
|
||||
CensusMember member{record.key,
|
||||
invocation,
|
||||
{"command:" + name, "source:" + name, "closure:" + name, {}},
|
||||
"pass-0",
|
||||
{}};
|
||||
census.members.push_back(member);
|
||||
records.push_back(std::move(record));
|
||||
}
|
||||
const auto generation =
|
||||
Build::BuildGeneration::create({{"/project", "editor"}, "fixture", "gen-1"}, records);
|
||||
require(generation.has_value());
|
||||
census.domain = {*generation, "gcc16/target/stdlib/abi", "lookup-v1"};
|
||||
census.revision = "app-members-v1";
|
||||
census.closed = true;
|
||||
for (const auto &member : census.members) {
|
||||
ScanEvidence scan;
|
||||
scan.domain = census.domain;
|
||||
scan.context = member.context;
|
||||
scan.inputs = member.inputs;
|
||||
scan.scan_revision = member.scan_revision;
|
||||
scan.exit_status = 0;
|
||||
scan.rule = decode_scan(wire(), member.output);
|
||||
scan.method = ScanMethod::preprocess_md;
|
||||
scan.complete = true;
|
||||
scan.header_uses.emplace();
|
||||
scan.writers = {"private-output:" + member.context.alternative};
|
||||
scans.push_back(std::move(scan));
|
||||
}
|
||||
}
|
||||
|
||||
void record(std::size_t n, std::string_view fields) {
|
||||
auto &member = census.members[n];
|
||||
member.scan_revision += '+';
|
||||
auto &scan = scans[n];
|
||||
scan.scan_revision = member.scan_revision;
|
||||
scan.inputs = member.inputs;
|
||||
scan.domain = census.domain;
|
||||
scan.rule = decode_scan(wire(fields), member.output);
|
||||
require(scan.rule->has_value());
|
||||
}
|
||||
void stage(std::size_t n, std::string id, std::string source) {
|
||||
auto &member = census.members[n];
|
||||
member.staged_header = StagedHeader{std::move(id), std::move(source), census.domain,
|
||||
member.context, member.inputs};
|
||||
}
|
||||
ModulePlan plan(std::size_t n) const {
|
||||
return build_module_plan(census, scans, census.members[n].context);
|
||||
}
|
||||
std::vector<Build::ContextKey> keys(std::initializer_list<std::size_t> ids) const {
|
||||
std::vector<Build::ContextKey> result;
|
||||
for (auto i : ids)
|
||||
result.push_back(census.members[i].context);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
bool blocked(const ModulePlan &plan, PlanIssue code) {
|
||||
return !plan.ready() && plan.order.empty() &&
|
||||
std::ranges::any_of(plan.blockers,
|
||||
[code](const auto &issue) { return issue.code == code; });
|
||||
}
|
||||
|
||||
const PlannedUnit &unit(const ModulePlan &plan, const Build::ContextKey &context) {
|
||||
const auto it = std::ranges::find_if(
|
||||
plan.units, [&](const auto &node) { return node.member.context == context; });
|
||||
require(it != plan.units.end());
|
||||
return *it;
|
||||
}
|
||||
|
||||
std::vector<Build::ContextKey> consumers(const ModulePlan &plan, const Build::ContextKey &key) {
|
||||
std::vector<Build::ContextKey> result;
|
||||
for (auto i : unit(plan, key).consumers)
|
||||
result.push_back(plan.units.at(i).member.context);
|
||||
return result;
|
||||
}
|
||||
|
||||
void rejects(std::string_view json, ScanError expected) {
|
||||
auto rule = decode_scan(json, invocation);
|
||||
require(!rule);
|
||||
expect(rule.error() == expected);
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, gcc_dialect_preserves_optional_lookup_and_partition_evidence) {
|
||||
auto rule = decode_scan(wire(R"("work-directory":"/project/private","outputs":["other.o"],
|
||||
"provides":[{"logical-name":"m:p","is-interface":false},{"logical-name":"m"}],
|
||||
"requires":[{"logical-name":"<h>","source-path":"./a/h","unique-on-source-path":true,
|
||||
"lookup-method":"include-angle","compiled-module-path":"slot/opaque"},
|
||||
{"logical-name":"h","lookup-method":"include-quote"},{"logical-name":"m:p"}],
|
||||
"_vendor_advisory":{"more":[true]})"),
|
||||
invocation);
|
||||
require(rule.has_value());
|
||||
expect(rule->output() == invocation);
|
||||
expect(rule->additional_outputs() == std::vector<std::string>{"other.o"});
|
||||
expect(!rule->provides()[0].is_interface && rule->provides()[1].is_interface);
|
||||
const auto &entry = rule->requirements()[0];
|
||||
expect(entry.unique_on_source_path && entry.logical_name == "<h>" &&
|
||||
entry.source_path == "./a/h");
|
||||
expect(entry.compiled_module_path == "slot/opaque" &&
|
||||
entry.lookup == LookupMethod::include_angle);
|
||||
expect(rule->requirements()[1].lookup == LookupMethod::include_quote);
|
||||
expect(rule->requirements()[2].lookup == LookupMethod::by_name);
|
||||
rule = decode_scan(R"({"version":0,"rules":[{"primary-output":"same.o"}]})", invocation);
|
||||
require(rule.has_value());
|
||||
expect(rule->provides().empty() && rule->requirements().empty() &&
|
||||
rule->additional_outputs().empty());
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, decoder_binds_exact_invocation_and_refuses_other_versions) {
|
||||
rejects(R"({"version":1,"revision":0,"rules":[]})", ScanError::unsupported_version);
|
||||
rejects(R"({"version":0,"revision":1,"rules":[]})", ScanError::unsupported_version);
|
||||
rejects(R"({"version":"0","rules":[]})", ScanError::invalid_shape);
|
||||
rejects(R"({"version":0.0,"rules":[]})", ScanError::invalid_shape);
|
||||
rejects(R"({"version":0,"rules":[]})", ScanError::invalid_shape);
|
||||
rejects(R"({"version":0,"rules":[{},{}]})", ScanError::invalid_shape);
|
||||
rejects(R"({"version":0,"rules":[{}]})", ScanError::invalid_shape);
|
||||
rejects(R"({"version":0,"rules":[{"primary-output":"./same.o"}]})", ScanError::wrong_output);
|
||||
rejects(wire(R"("work-directory":"/project/link/../private")"), ScanError::wrong_directory);
|
||||
auto result = decode_scan(wire(), {"relative", "same.o"});
|
||||
require(!result);
|
||||
expect(result.error() == ScanError::invalid_invocation);
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, decoder_rejects_malformed_or_unknown_semantic_fields) {
|
||||
for (auto fields :
|
||||
{R"("provides":null)", R"("requires":[null])", R"("requires":[{}])",
|
||||
R"("requires":[{"logical-name":""}])", R"("outputs":[null])", R"("outputs":["same.o"])",
|
||||
R"("outputs":["x","x"])", R"("provides":[{"logical-name":"m","is-interface":null}])",
|
||||
R"("requires":[{"logical-name":"m","unique-on-source-path":true}])",
|
||||
R"("requires":[{"logical-name":"m","source-path":false}])",
|
||||
R"("requires":[{"logical-name":"m","compiled-module-path":17}])",
|
||||
R"("requires":[{"logical-name":"m"},{"logical-name":"m"}])",
|
||||
R"("requires":[{"logical-name":"m\u0000n"}])"})
|
||||
rejects(wire(fields), ScanError::invalid_shape);
|
||||
for (auto fields : {R"("new-provider-semantics":true)",
|
||||
R"("requires":[{"logical-name":"m","lookup-method":"another"}])",
|
||||
R"("requires":[{"logical-name":"m","is-interface":false}])"})
|
||||
rejects(wire(fields), ScanError::unsupported_field);
|
||||
rejects(wire(R"("requires":[],"requires":[])"), ScanError::invalid_json);
|
||||
rejects("[", ScanError::invalid_json);
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, decoder_bounds_wire_tree_strings_and_aggregate_rule_items) {
|
||||
rejects(std::string(max_scan_bytes + 1, ' '), ScanError::limit);
|
||||
// The envelope, rules array and its rule object account for three open containers.
|
||||
auto nested = [](std::size_t depth) {
|
||||
return wire(R"("_vendor_x":)" + std::string(depth, '[') + "0" + std::string(depth, ']'));
|
||||
};
|
||||
expect(decode_scan(nested(max_scan_depth - 3), invocation).has_value());
|
||||
rejects(nested(max_scan_depth - 2), ScanError::limit);
|
||||
expect(decode_scan(wire(named(std::string(max_field_bytes, 'a'))), invocation).has_value());
|
||||
rejects(wire(named(std::string(max_field_bytes + 1, 'a'))), ScanError::limit);
|
||||
std::vector<std::string> names;
|
||||
for (std::size_t i = 0; i < max_rule_items; ++i)
|
||||
names.push_back("m" + std::to_string(i));
|
||||
expect(decode_scan(wire(named("", names)), invocation).has_value());
|
||||
rejects(wire(named("one_more", names)), ScanError::limit);
|
||||
names.push_back("beyond");
|
||||
rejects(wire(named("", names)), ScanError::limit);
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, orders_transitive_partitions_and_retains_reverse_consumers) {
|
||||
Fixture f{5};
|
||||
f.record(0, named("m:detail", {}, false));
|
||||
f.record(1, named("m:api", {"m:detail"}));
|
||||
f.record(2, named("m", {"m:api"}));
|
||||
f.record(3, named("", {"m", "m:detail"}));
|
||||
f.census.members[4].inputs.command += " -DEXPECT_READY=48 -o importer.o";
|
||||
f.record(4, named("", {"m"}));
|
||||
const auto plan = f.plan(4);
|
||||
require(plan.ready());
|
||||
expect(plan.order == f.keys({0, 1, 2, 4}));
|
||||
expect(consumers(plan, f.scans[0].context) == f.keys({1, 3}));
|
||||
expect(consumers(plan, f.scans[2].context) == f.keys({3, 4}));
|
||||
expect(unit(plan, f.scans[0].context).kind == UnitKind::internal_partition);
|
||||
expect(unit(plan, f.scans[1].context).kind == UnitKind::interface_partition);
|
||||
expect(unit(plan, f.scans[2].context).kind == UnitKind::primary_interface);
|
||||
expect(unit(plan, f.scans[4].context).kind == UnitKind::unknown);
|
||||
expect(f.plan(3).order == f.keys({0, 1, 2, 3}));
|
||||
const auto request = f.scans[4].context;
|
||||
std::ranges::reverse(f.census.members);
|
||||
std::ranges::reverse(f.scans);
|
||||
expect(plan.matches_census(f.census));
|
||||
expect(build_module_plan(f.census, f.scans, request).order == plan.order);
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, noninterface_named_provision_requires_a_partition) {
|
||||
Fixture f{2};
|
||||
f.record(0, named("m", {}, false));
|
||||
f.record(1, named("", {"m"}));
|
||||
const auto invalid = f.plan(1);
|
||||
expect(blocked(invalid, PlanIssue::unproven_mapping));
|
||||
expect(!invalid.claims_complete);
|
||||
f.record(0, named("m:inside", {}, false));
|
||||
f.record(1, named("", {"m:inside"}));
|
||||
const auto partition = f.plan(1);
|
||||
require(partition.ready());
|
||||
expect(unit(partition, f.scans[0].context).kind == UnitKind::internal_partition);
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, import_only_rules_do_not_distinguish_implementation_or_ordinary_tu) {
|
||||
Fixture f{3};
|
||||
f.record(0, named("lib"));
|
||||
f.record(1, named("", {"lib"}));
|
||||
f.record(2, named("", {"lib"}));
|
||||
auto plan = f.plan(2);
|
||||
require(plan.ready());
|
||||
expect(unit(plan, f.scans[1].context).kind == UnitKind::unknown);
|
||||
expect(unit(plan, f.scans[2].context).kind == UnitKind::unknown);
|
||||
f.scans[1].import_only_kind = UnitKind::implementation;
|
||||
f.scans[2].import_only_kind = UnitKind::ordinary;
|
||||
plan = f.plan(1);
|
||||
require(plan.ready());
|
||||
expect(unit(plan, f.scans[1].context).kind == UnitKind::implementation);
|
||||
expect(unit(plan, f.scans[2].context).kind == UnitKind::ordinary);
|
||||
f.scans[0].import_only_kind = UnitKind::implementation;
|
||||
expect(blocked(f.plan(0), PlanIssue::unproven_mapping));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, census_visibility_precedes_name_and_abi_compatibility) {
|
||||
Fixture f{3};
|
||||
f.record(0, named("lib"));
|
||||
f.record(1, named("lib"));
|
||||
f.record(2, named("", {"lib"}));
|
||||
expect(blocked(f.plan(2), PlanIssue::duplicate_provider));
|
||||
auto selected = f.census;
|
||||
selected.members.erase(selected.members.begin() + 1);
|
||||
const auto request = f.scans[2].context;
|
||||
const auto chosen = build_module_plan(selected, f.scans, request);
|
||||
require(chosen.ready());
|
||||
expect(chosen.order == f.keys({0, 2}));
|
||||
expect(!chosen.matches_census(f.census));
|
||||
f.scans[0].domain.compatibility = "different-abi";
|
||||
expect(blocked(build_module_plan(selected, f.scans, request), PlanIssue::wrong_domain));
|
||||
f.scans[0].domain = selected.domain;
|
||||
f.scans[0].domain.generation = Fixture{3}.census.domain.generation;
|
||||
expect(blocked(build_module_plan(selected, f.scans, request), PlanIssue::wrong_domain));
|
||||
selected.members.erase(selected.members.begin());
|
||||
expect(blocked(build_module_plan(selected, f.scans, request), PlanIssue::missing_provider));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, unknown_or_duplicate_eligible_claims_withhold_the_plan) {
|
||||
Fixture f{2};
|
||||
f.record(0, named("known"));
|
||||
f.record(1, named("otherwise_independent"));
|
||||
require(f.plan(0).ready());
|
||||
f.scans[1].exit_status = 1;
|
||||
const auto failed = f.plan(0);
|
||||
expect(blocked(failed, PlanIssue::scan_failed) && !failed.claims_complete);
|
||||
expect(unit(failed, f.scans[1].context).kind == UnitKind::unknown);
|
||||
f.scans[1].exit_status.reset();
|
||||
expect(blocked(f.plan(0), PlanIssue::incomplete_scan));
|
||||
f.scans[1].exit_status = 0;
|
||||
f.scans[1].rule.reset();
|
||||
expect(blocked(f.plan(0), PlanIssue::missing_rule));
|
||||
f.scans[1].rule = decode_scan("not JSON", invocation);
|
||||
const auto invalid = f.plan(0);
|
||||
expect(blocked(invalid, PlanIssue::invalid_rule));
|
||||
expect(std::ranges::any_of(invalid.blockers, [](const auto &issue) {
|
||||
return issue.scan_error == ScanError::invalid_json;
|
||||
}));
|
||||
f.record(1, named("restored"));
|
||||
f.scans.push_back(f.scans[1]);
|
||||
expect(blocked(f.plan(0), PlanIssue::duplicate_scan));
|
||||
f.scans.resize(1);
|
||||
expect(blocked(f.plan(0), PlanIssue::missing_scan));
|
||||
f.census.members[1].inputs.source.clear();
|
||||
expect(blocked(f.plan(0), PlanIssue::missing_source));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, missing_census_authority_and_scan_freshness_are_explicit) {
|
||||
Fixture f{2};
|
||||
f.census.closed = false;
|
||||
expect(blocked(f.plan(0), PlanIssue::incomplete_census));
|
||||
f.census.closed = true;
|
||||
f.census.members.push_back(f.census.members[1]);
|
||||
expect(blocked(f.plan(0), PlanIssue::duplicate_member));
|
||||
f.census.members.pop_back();
|
||||
f.census.members[1].context.alternative = "not in provider generation";
|
||||
expect(blocked(f.plan(0), PlanIssue::invalid_context));
|
||||
f.census.members[1].context = f.scans[1].context;
|
||||
f.scans[1].inputs.command += "-DOTHER";
|
||||
expect(blocked(f.plan(0), PlanIssue::stale_scan));
|
||||
f.scans[1].inputs = f.census.members[1].inputs;
|
||||
f.scans[1].rule = decode_scan(wire(), {"/different/invocation", "same.o"});
|
||||
expect(blocked(f.plan(0), PlanIssue::stale_scan));
|
||||
f.scans[1].rule = decode_scan(wire(), invocation);
|
||||
f.scans[1].scan_revision = "previous pass";
|
||||
expect(blocked(f.plan(0), PlanIssue::stale_scan));
|
||||
f.scans[1].scan_revision = f.census.members[1].scan_revision;
|
||||
f.census.domain.lookup.clear();
|
||||
expect(blocked(f.plan(0), PlanIssue::incomplete_census));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, missing_modules_and_conflicts_only_block_their_known_component) {
|
||||
Fixture f{5};
|
||||
f.record(0, named("one", {"std"}));
|
||||
f.record(1, named("two"));
|
||||
f.record(2, named("duplicate"));
|
||||
f.record(3, named("duplicate"));
|
||||
f.record(4, named("", {"two"}));
|
||||
expect(blocked(f.plan(0), PlanIssue::missing_provider));
|
||||
expect(blocked(f.plan(2), PlanIssue::duplicate_provider));
|
||||
expect(f.plan(4).order == f.keys({1, 4}));
|
||||
f.record(0, named("", {"./include/unit.hpp"}));
|
||||
expect(blocked(f.plan(0), PlanIssue::unproven_mapping));
|
||||
f.scans[0].header_uses = std::vector<HeaderUse>{{0, "header-file", "loaded-cmi"}};
|
||||
expect(blocked(f.plan(0), PlanIssue::missing_provider));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, self_and_multi_node_cycles_leave_independent_tu_buildable) {
|
||||
Fixture f{5};
|
||||
f.record(0, named("a", {"b"}));
|
||||
f.record(1, named("b", {"a"}));
|
||||
f.record(2, named("self", {"self"}));
|
||||
f.record(3, named("healthy"));
|
||||
f.record(4, named("", {"healthy"}));
|
||||
const auto cycle = f.plan(0);
|
||||
expect(blocked(cycle, PlanIssue::cycle) && cycle.claims_complete);
|
||||
expect(blocked(f.plan(1), PlanIssue::cycle));
|
||||
expect(blocked(f.plan(2), PlanIssue::cycle));
|
||||
expect(f.plan(4).order == f.keys({3, 4}));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, renamed_provider_invalidates_an_old_plan_with_identical_membership) {
|
||||
Fixture f{3};
|
||||
f.record(0, named("m"));
|
||||
f.record(1, named("independent"));
|
||||
f.record(2, named("", {"m"}));
|
||||
const auto old = f.plan(2);
|
||||
require(old.ready());
|
||||
expect(consumers(old, f.scans[1].context).empty());
|
||||
f.census.members[1].inputs.source = "edited unrelated declaration";
|
||||
f.record(1, named("m"));
|
||||
expect(!old.matches_census(f.census));
|
||||
expect(blocked(f.plan(2), PlanIssue::duplicate_provider));
|
||||
expect(old.order == f.keys({0, 2}));
|
||||
f.record(1, named("fixed"));
|
||||
require(f.plan(2).ready());
|
||||
std::ranges::reverse(f.census.members);
|
||||
auto duplicate = f.census;
|
||||
duplicate.members[0] = duplicate.members[1];
|
||||
expect(!f.plan(0).matches_census(duplicate));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, new_file_changes_has_include_and_adds_an_import_edge) {
|
||||
Fixture f{2};
|
||||
f.record(0, named("optional"));
|
||||
f.record(1, named(""));
|
||||
const auto before = f.plan(1);
|
||||
expect(before.order == f.keys({1}));
|
||||
// The TU bytes did not change. A previously missing optional.hpp now exists and
|
||||
// activates 'import optional' in the compiler scan.
|
||||
f.census.domain.lookup = "lookup-v2 optional.hpp present";
|
||||
expect(!before.matches_census(f.census));
|
||||
expect(blocked(f.plan(1), PlanIssue::wrong_domain));
|
||||
f.census.members[1].inputs.textual_closure = "closure includes new optional.hpp";
|
||||
f.record(0, named("optional"));
|
||||
f.record(1, named("", {"optional"}));
|
||||
const auto after = f.plan(1);
|
||||
expect(after.order == f.keys({0, 1}));
|
||||
expect(consumers(after, f.scans[0].context) == f.keys({1}));
|
||||
expect(consumers(before, f.scans[0].context).empty());
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, adding_an_eligible_provider_invalidates_the_previous_missing_lookup) {
|
||||
Fixture f{2};
|
||||
f.record(0, named("réseau.узел"));
|
||||
f.record(1, named("", {"réseau.узел"}));
|
||||
auto original = f.census;
|
||||
original.members.erase(original.members.begin());
|
||||
const auto &request = f.scans[1].context;
|
||||
const auto missing = build_module_plan(original, f.scans, request);
|
||||
expect(blocked(missing, PlanIssue::missing_provider) && missing.claims_complete);
|
||||
expect(missing.matches_census(original));
|
||||
expect(!missing.matches_census(f.census));
|
||||
f.census.revision = "app-members-v2";
|
||||
expect(f.plan(1).order == f.keys({0, 1}));
|
||||
f.record(1, named("", {"réseau.Узел"}));
|
||||
expect(blocked(f.plan(1), PlanIssue::missing_provider));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, cold_and_stale_header_cmi_cannot_attest_conditional_imports) {
|
||||
Fixture f{3};
|
||||
f.record(0, named("./h"));
|
||||
f.scans[0].provided_headers = {{0, "physical-header"}};
|
||||
f.record(1, named("conditioned"));
|
||||
f.record(2, named("", {"./h"}));
|
||||
f.scans[2].method = ScanMethod::missing_allowed;
|
||||
f.scans[2].header_uses = std::vector<HeaderUse>{{0, "physical-header", {}}};
|
||||
f.scans[2].complete = false;
|
||||
expect(blocked(f.plan(2), PlanIssue::incomplete_scan));
|
||||
f.scans[2].complete = true;
|
||||
expect(blocked(f.plan(2), PlanIssue::stale_header));
|
||||
f.stage(0, "stage-17", "physical-header");
|
||||
(*f.scans[2].header_uses)[0].loaded_generation = "stage-17";
|
||||
const auto first = f.plan(2);
|
||||
expect(first.order == f.keys({0, 2}));
|
||||
f.census.members[0].inputs.textual_closure = "header and transitive macro changed to true";
|
||||
f.record(0, named("./h"));
|
||||
// The process exited zero with the OLD CMI and missed 'conditioned'.
|
||||
f.record(2, named("", {"./h"}));
|
||||
expect(!first.matches_census(f.census));
|
||||
expect(blocked(f.plan(2), PlanIssue::stale_header));
|
||||
f.stage(0, "stage-41", "physical-header");
|
||||
expect(blocked(f.plan(2), PlanIssue::stale_header));
|
||||
(*f.scans[2].header_uses)[0].loaded_generation = "stage-41";
|
||||
f.record(2, named("", {"./h", "conditioned"}));
|
||||
const auto warm = f.plan(2);
|
||||
expect(warm.order == f.keys({0, 1, 2}));
|
||||
expect(unit(warm, f.scans[0].context).kind == UnitKind::header_unit);
|
||||
expect(first.order == f.keys({0, 2}));
|
||||
f.census.members[0].staged_header->producer = f.scans[1].context;
|
||||
expect(blocked(f.plan(2), PlanIssue::stale_header));
|
||||
f.stage(0, "stage-41", "physical-header");
|
||||
f.census.members[0].staged_header->domain.lookup = "stale lookup";
|
||||
expect(blocked(f.plan(2), PlanIssue::stale_header));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, header_source_bindings_converge_across_spellings_and_distinguish_shadow) {
|
||||
Fixture f{3};
|
||||
const auto provides =
|
||||
R"("provides":[{"logical-name":"h","source-path":"./h","unique-on-source-path":true}])";
|
||||
f.record(0, provides);
|
||||
f.record(1, provides);
|
||||
f.scans[0].provided_headers = {{0, "first/h"}};
|
||||
f.scans[1].provided_headers = {{0, "shadow/h"}};
|
||||
f.stage(0, "first-stage", "first/h");
|
||||
f.stage(1, "shadow-stage", "shadow/h");
|
||||
f.record(2, R"("requires":[{"logical-name":"<h>","source-path":"./selected/h",
|
||||
"unique-on-source-path":true,"lookup-method":"include-angle"},
|
||||
{"logical-name":"h","source-path":"./selected/h","unique-on-source-path":true,
|
||||
"lookup-method":"include-quote"}])");
|
||||
f.scans[2].header_uses =
|
||||
std::vector<HeaderUse>{{0, "first/h", "first-stage"}, {1, "first/h", "first-stage"}};
|
||||
const auto first = f.plan(2);
|
||||
expect(first.order == f.keys({0, 2}));
|
||||
expect(consumers(first, f.scans[0].context) == f.keys({2}));
|
||||
(*f.scans[2].header_uses)[1] = {1, "shadow/h", "shadow-stage"};
|
||||
expect(blocked(f.plan(2), PlanIssue::unproven_mapping));
|
||||
f.census.domain.lookup = "shadow first";
|
||||
for (auto &scan : f.scans)
|
||||
scan.domain = f.census.domain;
|
||||
(*f.scans[2].header_uses)[0] = {0, "shadow/h", "shadow-stage"};
|
||||
expect(blocked(f.plan(2), PlanIssue::stale_header));
|
||||
f.stage(1, "shadow-stage-2", "shadow/h");
|
||||
for (auto &use : *f.scans[2].header_uses)
|
||||
use.loaded_generation = "shadow-stage-2";
|
||||
expect(f.plan(2).order == f.keys({1, 2}));
|
||||
expect(!first.matches_census(f.census));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, missing_header_bindings_or_artifact_path_authority_stays_pending) {
|
||||
Fixture f{1};
|
||||
f.scans[0].header_uses.reset();
|
||||
expect(blocked(f.plan(0), PlanIssue::incomplete_scan));
|
||||
f.scans[0].header_uses.emplace();
|
||||
f.record(0, R"("requires":[{"logical-name":"header","lookup-method":"include-angle"}])");
|
||||
expect(blocked(f.plan(0), PlanIssue::unproven_mapping));
|
||||
f.scans[0].header_uses = std::vector<HeaderUse>{{1, "file", "one"}};
|
||||
expect(blocked(f.plan(0), PlanIssue::unproven_mapping));
|
||||
f.scans[0].header_uses = std::vector<HeaderUse>{{0, "file", "one"}, {0, "other", "two"}};
|
||||
expect(blocked(f.plan(0), PlanIssue::unproven_mapping));
|
||||
f.scans[0].header_uses->clear();
|
||||
f.record(0, R"("provides":[{"logical-name":"m","compiled-module-path":"external/unchecked"}])");
|
||||
expect(blocked(f.plan(0), PlanIssue::unproven_mapping));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, mmd_requires_immutable_system_closure_and_modes_never_imply_completeness) {
|
||||
Fixture f{1};
|
||||
f.scans[0].method = ScanMethod::preprocess_mmd;
|
||||
expect(blocked(f.plan(0), PlanIssue::incomplete_inputs));
|
||||
f.census.members[0].inputs.system_closure = "sealed sysroot contents";
|
||||
f.record(0, named("plain"));
|
||||
require(f.plan(0).ready());
|
||||
for (auto mode :
|
||||
{ScanMethod::preprocess_mmd, ScanMethod::preprocess_md, ScanMethod::missing_allowed}) {
|
||||
f.scans[0].method = mode;
|
||||
f.scans[0].complete = false;
|
||||
expect(blocked(f.plan(0), PlanIssue::incomplete_scan));
|
||||
}
|
||||
f.scans[0].complete = true;
|
||||
f.scans[0].method = ScanMethod::unknown;
|
||||
expect(blocked(f.plan(0), PlanIssue::incomplete_scan));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, actual_writer_identity_distinguishes_private_outputs_from_collisions) {
|
||||
Fixture f{3};
|
||||
f.record(0, R"("outputs":["private-extra"])");
|
||||
f.scans[0].writers.push_back("verified shared destination");
|
||||
const auto private_outputs = f.plan(0);
|
||||
require(private_outputs.ready());
|
||||
expect(f.census.members[0].output == f.census.members[1].output);
|
||||
f.scans[1].writers[0] = "verified shared destination";
|
||||
expect(blocked(f.plan(0), PlanIssue::writer_collision));
|
||||
expect(blocked(f.plan(1), PlanIssue::writer_collision));
|
||||
expect(f.plan(2).order == f.keys({2}));
|
||||
f.scans[0].writers.pop_back();
|
||||
expect(blocked(f.plan(0), PlanIssue::unproven_mapping));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, deep_legal_chain_orders_once_and_graph_limits_fail_closed) {
|
||||
Fixture f{max_units};
|
||||
for (std::size_t i = 0; i < max_units; ++i) {
|
||||
std::vector<std::string> imports;
|
||||
if (i)
|
||||
imports.push_back("m" + std::to_string(i - 1));
|
||||
f.record(i, named("m" + std::to_string(i), imports));
|
||||
}
|
||||
const auto plan = f.plan(max_units - 1);
|
||||
require(plan.ready() && plan.order.size() == max_units);
|
||||
bool ordered = true;
|
||||
for (std::size_t i = 0; i < max_units; ++i)
|
||||
ordered &= plan.order[i] == f.scans[i].context;
|
||||
expect(ordered);
|
||||
f.census.members.push_back(f.census.members[0]);
|
||||
expect(blocked(f.plan(0), PlanIssue::limit));
|
||||
f.census.members.pop_back();
|
||||
f.scans[0].writers.front().resize(max_field_bytes + 1, 'x');
|
||||
expect(blocked(f.plan(0), PlanIssue::limit));
|
||||
f.scans[0].writers.front() = "restored";
|
||||
for (auto &member : f.census.members)
|
||||
member.inputs.textual_closure.resize(max_field_bytes, 'x');
|
||||
expect(blocked(f.plan(0), PlanIssue::limit));
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleGraph, aggregate_edge_budget_is_enforced_before_resolution) {
|
||||
Fixture f{80};
|
||||
std::vector<std::string> names(450);
|
||||
for (std::size_t i = 0; i < names.size(); ++i)
|
||||
names[i] = "m" + std::to_string(i);
|
||||
const auto fields = named("", names);
|
||||
for (std::size_t i = 0; i < f.scans.size(); ++i)
|
||||
f.record(i, fields);
|
||||
expect(blocked(f.plan(0), PlanIssue::limit));
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,198 @@
|
||||
#include <vls/modules/ModuleWorkQueue.hpp>
|
||||
#include <vls/scheduler/Scheduler.hpp>
|
||||
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace vls::modules;
|
||||
namespace Sched = vls::scheduler;
|
||||
using namespace std::chrono_literals;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
constexpr Sched::Budget budget{
|
||||
.foreground = 1, .background = 1, .artifact = 1, .queued = 8, .memory_mib = 64, .watchdog = 5s};
|
||||
|
||||
struct Gate {
|
||||
std::mutex mutex;
|
||||
std::condition_variable changed;
|
||||
bool open{};
|
||||
void wait() {
|
||||
std::unique_lock lock{mutex};
|
||||
changed.wait(lock, [&] { return open; });
|
||||
}
|
||||
void release() {
|
||||
std::lock_guard lock{mutex};
|
||||
open = true;
|
||||
changed.notify_all();
|
||||
}
|
||||
};
|
||||
|
||||
struct Results {
|
||||
mutable std::mutex mutex;
|
||||
std::condition_variable changed;
|
||||
std::vector<ModuleTaskResult> values;
|
||||
|
||||
void add(ModuleTaskResult result) {
|
||||
std::lock_guard lock{mutex};
|
||||
values.push_back(std::move(result));
|
||||
changed.notify_all();
|
||||
}
|
||||
std::optional<ModuleTaskResult> wait(std::string_view document, ModuleWorkKind kind,
|
||||
std::uint64_t revision,
|
||||
std::chrono::milliseconds timeout = 5000ms) {
|
||||
std::unique_lock lock{mutex};
|
||||
changed.wait_for(lock, timeout, [&] {
|
||||
for (const auto &result : values)
|
||||
if (result.document == document && result.kind == kind &&
|
||||
result.revision == revision)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
for (const auto &result : values)
|
||||
if (result.document == document && result.kind == kind && result.revision == revision)
|
||||
return result;
|
||||
return std::nullopt;
|
||||
}
|
||||
std::size_t size() const {
|
||||
std::lock_guard lock{mutex};
|
||||
return values.size();
|
||||
}
|
||||
};
|
||||
|
||||
ModuleWork cooperative(std::atomic<bool> &started, std::string detail = "stopped") {
|
||||
return [&started, detail](std::stop_token token) {
|
||||
started = true;
|
||||
std::mutex mutex;
|
||||
std::condition_variable changed;
|
||||
bool stopped{};
|
||||
std::stop_callback callback{token, [&] {
|
||||
std::lock_guard lock{mutex};
|
||||
stopped = true;
|
||||
changed.notify_all();
|
||||
}};
|
||||
std::unique_lock lock{mutex};
|
||||
changed.wait(lock, [&] { return stopped; });
|
||||
return detail;
|
||||
};
|
||||
}
|
||||
|
||||
template <class Predicate>
|
||||
bool eventually(Predicate predicate, std::chrono::milliseconds timeout = 5000ms) {
|
||||
const auto deadline = std::chrono::steady_clock::now() + timeout;
|
||||
while (std::chrono::steady_clock::now() < deadline) {
|
||||
if (predicate())
|
||||
return true;
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
return predicate();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(ModuleWorkQueue, priorities_are_separated) {
|
||||
Sched::Scheduler scheduler{budget};
|
||||
ModuleWorkQueue queue{scheduler};
|
||||
Gate gate;
|
||||
Results results;
|
||||
std::atomic<bool> first_started{}, second_started{};
|
||||
queue.submit(
|
||||
"a", ModuleWorkKind::scan, 1,
|
||||
[&](std::stop_token) {
|
||||
first_started = true;
|
||||
gate.wait();
|
||||
return std::string{"held"};
|
||||
},
|
||||
[&](ModuleTaskResult result) { results.add(std::move(result)); });
|
||||
require(eventually([&] { return first_started.load(); }));
|
||||
require(queue.submit(
|
||||
"b", ModuleWorkKind::scan, 1,
|
||||
[&](std::stop_token) {
|
||||
second_started = true;
|
||||
return std::string{};
|
||||
},
|
||||
[&](ModuleTaskResult result) { results.add(std::move(result)); }));
|
||||
require(queue.submit(
|
||||
"c", ModuleWorkKind::artifact, 1, [](std::stop_token) { return std::string{"artifact"}; },
|
||||
[&](ModuleTaskResult result) { results.add(std::move(result)); }));
|
||||
const auto artifact = results.wait("c", ModuleWorkKind::artifact, 1);
|
||||
require(artifact.has_value());
|
||||
expect(artifact->outcome == Sched::Outcome::completed);
|
||||
expect(!second_started.load());
|
||||
gate.release();
|
||||
scheduler.drain();
|
||||
expect(second_started.load());
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleWorkQueue, newer_revision_supersedes) {
|
||||
Sched::Scheduler scheduler{budget};
|
||||
ModuleWorkQueue queue{scheduler};
|
||||
Results results;
|
||||
std::atomic<bool> started{};
|
||||
require(queue.submit("document", ModuleWorkKind::scan, 1, cooperative(started),
|
||||
[&](ModuleTaskResult result) { results.add(std::move(result)); }));
|
||||
require(eventually([&] { return started.load(); }));
|
||||
require(queue.submit(
|
||||
"document", ModuleWorkKind::scan, 2, [](std::stop_token) { return std::string{"second"}; },
|
||||
[&](ModuleTaskResult result) { results.add(std::move(result)); }));
|
||||
const auto first = results.wait("document", ModuleWorkKind::scan, 1);
|
||||
require(first.has_value());
|
||||
expect(first->outcome == Sched::Outcome::cancelled);
|
||||
const auto second = results.wait("document", ModuleWorkKind::scan, 2);
|
||||
require(second.has_value());
|
||||
expect(second->outcome == Sched::Outcome::completed);
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleWorkQueue, cancel_document_stops_both_kinds) {
|
||||
Sched::Scheduler scheduler{budget};
|
||||
ModuleWorkQueue queue{scheduler};
|
||||
Results results;
|
||||
std::atomic<bool> scan_started{}, artifact_started{};
|
||||
require(queue.submit("document", ModuleWorkKind::scan, 1, cooperative(scan_started),
|
||||
[&](ModuleTaskResult result) { results.add(std::move(result)); }));
|
||||
require(queue.submit("document", ModuleWorkKind::artifact, 1, cooperative(artifact_started),
|
||||
[&](ModuleTaskResult result) { results.add(std::move(result)); }));
|
||||
require(eventually([&] { return scan_started.load() && artifact_started.load(); }));
|
||||
queue.cancel("document");
|
||||
const auto scan = results.wait("document", ModuleWorkKind::scan, 1);
|
||||
const auto artifact = results.wait("document", ModuleWorkKind::artifact, 1);
|
||||
require(scan.has_value() && artifact.has_value());
|
||||
expect(scan->outcome == Sched::Outcome::cancelled);
|
||||
expect(artifact->outcome == Sched::Outcome::cancelled);
|
||||
scheduler.drain();
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleWorkQueue, refuses_stale_revisions) {
|
||||
Sched::Scheduler scheduler{budget};
|
||||
ModuleWorkQueue queue{scheduler};
|
||||
require(queue.submit("document", ModuleWorkKind::scan, 2,
|
||||
[](std::stop_token) { return std::string{}; }));
|
||||
expect(!queue.submit("document", ModuleWorkKind::scan, 1,
|
||||
[](std::stop_token) { return std::string{}; }));
|
||||
expect(
|
||||
!queue.submit("", ModuleWorkKind::scan, 3, [](std::stop_token) { return std::string{}; }));
|
||||
scheduler.drain();
|
||||
}
|
||||
|
||||
VOID_TEST(ModuleWorkQueue, counts_track_terminal_outcomes) {
|
||||
Sched::Scheduler scheduler{budget};
|
||||
ModuleWorkQueue queue{scheduler};
|
||||
require(
|
||||
queue.submit("ok", ModuleWorkKind::scan, 1, [](std::stop_token) { return std::string{}; }));
|
||||
require(queue.submit("failed", ModuleWorkKind::artifact, 1,
|
||||
[](std::stop_token) -> std::string { throw std::runtime_error{"boom"}; }));
|
||||
scheduler.drain();
|
||||
const auto counts = queue.counts();
|
||||
expect(counts.submitted == 2 && counts.completed == 1 && counts.failed == 1 &&
|
||||
counts.cancelled == 0);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <vls/modules/ScanCommand.hpp>
|
||||
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace vls::modules;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
Build::BuildContext context(std::vector<std::string> arguments) {
|
||||
Build::BuildContext row;
|
||||
row.key = {{}, {}, Build::ContextRole::target, "unit", "/project/unit.cpp"};
|
||||
row.working_directory = "/project";
|
||||
row.semantic_arguments = std::move(arguments);
|
||||
return row;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(ScanCommand, derives_a_bounded_p1689_invocation) {
|
||||
auto row = context({"/tool/g++", "-std=c++26", "-I", "/include", "-c", "/project/unit.cpp",
|
||||
"-o", "/out/unit.o", "-fdeps-format=p1689r5"});
|
||||
auto built = build_scan_invocation(row, {"/project", "unit.o"}, "/private/deps.json");
|
||||
require(built.has_value());
|
||||
const auto &arguments = built->arguments;
|
||||
expect(arguments.front() == "/tool/g++");
|
||||
expect(std::ranges::find(arguments, std::string{"-c"}) == arguments.end());
|
||||
expect(std::ranges::find(arguments, std::string{"/out/unit.o"}) == arguments.end());
|
||||
expect(std::ranges::find(arguments, std::string{"/include"}) != arguments.end());
|
||||
expect(std::ranges::find(arguments, std::string{"-fdeps-file=/private/deps.json"}) !=
|
||||
arguments.end());
|
||||
expect(std::ranges::find(arguments, std::string{"-fdeps-target=unit.o"}) != arguments.end());
|
||||
expect(arguments.back() == "/project/unit.cpp");
|
||||
}
|
||||
|
||||
VOID_TEST(ScanCommand, refuses_missing_duplicate_or_relative_inputs) {
|
||||
const ExpectedOutput output{"/project", "unit.o"};
|
||||
expect(
|
||||
!build_scan_invocation(context({"/tool/g++"}), output, "/private/deps.json").has_value());
|
||||
expect(!build_scan_invocation(context({"/tool/g++", "/project/unit.cpp", "/project/unit.cpp"}),
|
||||
output, "/private/deps.json")
|
||||
.has_value());
|
||||
expect(
|
||||
!build_scan_invocation(context({"/tool/g++", "/project/unit.cpp"}), output, "relative.json")
|
||||
.has_value());
|
||||
Build::BuildContext empty;
|
||||
expect(!build_scan_invocation(empty, output, "/private/deps.json").has_value());
|
||||
}
|
||||
Reference in new issue
Block a user