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