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,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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user