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,83 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ModuleGraph.hpp>
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
// Identity of one private module artifact. Compatibility covers frontend,
|
||||
// target ABI, stdlib and flags; context names the producer; inputs binds the
|
||||
// exact command, source and textual closure; kind distinguishes CMI/object.
|
||||
struct ArtifactKey {
|
||||
std::string compatibility, context, inputs, kind;
|
||||
auto operator<=>(const ArtifactKey &) const = default;
|
||||
[[nodiscard]] std::string identity() const;
|
||||
};
|
||||
|
||||
struct ArtifactEntry {
|
||||
ArtifactKey key;
|
||||
std::filesystem::path path;
|
||||
std::string sha256;
|
||||
};
|
||||
|
||||
// An immutable, completely published generation. Readers retain it while
|
||||
// eviction removes only generations no reader references.
|
||||
class ArtifactGeneration {
|
||||
public:
|
||||
[[nodiscard]] const std::string &id() const noexcept { return id_; }
|
||||
[[nodiscard]] const std::filesystem::path &root() const noexcept { return root_; }
|
||||
[[nodiscard]] std::optional<ArtifactEntry> find(const ArtifactKey &key) const;
|
||||
|
||||
private:
|
||||
friend class ArtifactCache;
|
||||
ArtifactGeneration(std::string id, std::filesystem::path root,
|
||||
std::map<ArtifactKey, ArtifactEntry> entries)
|
||||
: id_(std::move(id)), root_(std::move(root)), entries_(std::move(entries)) {}
|
||||
std::string id_;
|
||||
std::filesystem::path root_;
|
||||
std::map<ArtifactKey, ArtifactEntry> entries_;
|
||||
};
|
||||
|
||||
// Private artifact cache. Publication is all-or-nothing and content addressed;
|
||||
// a failed publication leaves no generation behind.
|
||||
class ArtifactCache {
|
||||
public:
|
||||
explicit ArtifactCache(std::filesystem::path root, std::size_t retained = 2);
|
||||
~ArtifactCache();
|
||||
ArtifactCache(const ArtifactCache &) = delete;
|
||||
ArtifactCache &operator=(const ArtifactCache &) = delete;
|
||||
|
||||
[[nodiscard]] std::expected<std::shared_ptr<const ArtifactGeneration>, std::string>
|
||||
publish(const std::map<ArtifactKey, std::filesystem::path> &artifacts);
|
||||
[[nodiscard]] std::shared_ptr<const ArtifactGeneration> current() const;
|
||||
// Removes unreferenced generations beyond the retained limit.
|
||||
std::size_t collect();
|
||||
[[nodiscard]] std::size_t generations() const;
|
||||
|
||||
private:
|
||||
struct State;
|
||||
std::shared_ptr<State> state_;
|
||||
};
|
||||
|
||||
// Produces one artifact per planned unit in dependency order. Any failure or
|
||||
// cancellation removes the staging directory and publishes nothing.
|
||||
using ArtifactWork = std::function<std::expected<std::filesystem::path, std::string>(
|
||||
std::stop_token, const Build::ContextKey &, const std::filesystem::path &output)>;
|
||||
|
||||
[[nodiscard]] std::expected<std::shared_ptr<const ArtifactGeneration>, std::string>
|
||||
produce_module_artifacts(const ModulePlan &plan, ArtifactCache &cache,
|
||||
const std::filesystem::path &staging, ArtifactWork work,
|
||||
std::stop_token stop = std::stop_token{});
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ArtifactCache.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
struct ModuleCommand {
|
||||
std::filesystem::path working_directory;
|
||||
// Absolute compiler path first. Arguments must not depend on the caller's
|
||||
// working directory: the work runs in a private directory.
|
||||
std::vector<std::string> arguments;
|
||||
};
|
||||
|
||||
using ModuleCommandLookup = std::function<std::optional<ModuleCommand>(const Build::ContextKey &)>;
|
||||
|
||||
struct GccArtifactOptions {
|
||||
std::chrono::milliseconds deadline{60000};
|
||||
std::size_t max_output_bytes{64 * 1024 * 1024};
|
||||
std::size_t max_artifact_bytes{512 * 1024 * 1024};
|
||||
};
|
||||
|
||||
// Real GCC module artifact production for one planned unit: runs the looked-up
|
||||
// command in a private working directory with a private module cache, requires
|
||||
// exactly one verified CMI and copies it to `output`. Tool authority, the
|
||||
// command's environment and its provenance are the caller's responsibility.
|
||||
[[nodiscard]] ArtifactWork
|
||||
gcc_module_artifact_work(ModuleCommandLookup lookup,
|
||||
GccArtifactOptions options = GccArtifactOptions{});
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ModuleGraph.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
struct ScanCommand {
|
||||
std::filesystem::path working_directory;
|
||||
// Absolute compiler first. Must contain exactly one absolute -fdeps-file=.
|
||||
std::vector<std::string> arguments;
|
||||
ExpectedOutput output;
|
||||
};
|
||||
|
||||
using ScanCommandLookup = std::function<std::optional<ScanCommand>(const Build::ContextKey &)>;
|
||||
|
||||
struct ScanProduct {
|
||||
std::string p1689;
|
||||
std::optional<ScanRule> rule;
|
||||
};
|
||||
|
||||
struct ScanOptions {
|
||||
std::filesystem::path directory; // private output directory
|
||||
std::chrono::milliseconds deadline{60000};
|
||||
std::size_t max_bytes{max_scan_bytes};
|
||||
};
|
||||
|
||||
// Runs one checked P1689 scan command and decodes its dependency file. The
|
||||
// product is filled only on success; a failure throws so the scheduler records
|
||||
// a failed task. No compiler option comes from project metadata here.
|
||||
[[nodiscard]] std::function<std::string(std::stop_token)>
|
||||
gcc_module_scan_work(ScanCommandLookup lookup, Build::ContextKey context,
|
||||
std::shared_ptr<ScanProduct> product, ScanOptions options = ScanOptions{});
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,227 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/LanguageServer/Build/Model.hpp>
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
namespace Build = Void::LanguageServer::Build;
|
||||
|
||||
inline constexpr std::size_t max_scan_bytes = 256 * 1024, max_scan_depth = 16;
|
||||
inline constexpr std::size_t max_field_bytes = 4096, max_rule_items = 512;
|
||||
inline constexpr std::size_t max_units = 4096, max_graph_items = 32768;
|
||||
inline constexpr std::size_t max_graph_bytes = 16 * 1024 * 1024;
|
||||
|
||||
struct ExpectedOutput {
|
||||
std::filesystem::path working_directory;
|
||||
std::string spelling;
|
||||
bool operator==(const ExpectedOutput &other) const {
|
||||
return working_directory.native() == other.working_directory.native() &&
|
||||
spelling == other.spelling;
|
||||
}
|
||||
};
|
||||
|
||||
enum class LookupMethod { by_name, include_angle, include_quote };
|
||||
struct ModuleDescription {
|
||||
std::string logical_name;
|
||||
std::optional<std::string> source_path, compiled_module_path;
|
||||
bool unique_on_source_path{};
|
||||
auto operator<=>(const ModuleDescription &) const = default;
|
||||
};
|
||||
struct ProvidedModule : ModuleDescription {
|
||||
bool is_interface{true};
|
||||
auto operator<=>(const ProvidedModule &) const = default;
|
||||
};
|
||||
struct RequiredModule : ModuleDescription {
|
||||
LookupMethod lookup{LookupMethod::by_name};
|
||||
auto operator<=>(const RequiredModule &) const = default;
|
||||
};
|
||||
|
||||
enum class ScanError {
|
||||
invalid_json,
|
||||
invalid_shape,
|
||||
unsupported_version,
|
||||
unsupported_field,
|
||||
invalid_invocation,
|
||||
wrong_directory,
|
||||
wrong_output,
|
||||
limit
|
||||
};
|
||||
|
||||
// GCC 16.2 single-rule version 0, revision 0. Only the decoder constructs rules.
|
||||
class ScanRule {
|
||||
public:
|
||||
const ExpectedOutput &output() const { return output_; }
|
||||
const auto &additional_outputs() const { return additional_outputs_; }
|
||||
const auto &provides() const { return provides_; }
|
||||
const auto &requirements() const { return requirements_; }
|
||||
std::size_t wire_bytes() const { return wire_bytes_; }
|
||||
|
||||
private:
|
||||
friend std::expected<ScanRule, ScanError> decode_scan(std::string_view, const ExpectedOutput &);
|
||||
ScanRule() = default;
|
||||
ExpectedOutput output_;
|
||||
std::vector<std::string> additional_outputs_;
|
||||
std::vector<ProvidedModule> provides_;
|
||||
std::vector<RequiredModule> requirements_;
|
||||
std::size_t wire_bytes_{};
|
||||
};
|
||||
using ScanResult = std::expected<ScanRule, ScanError>;
|
||||
[[nodiscard]] ScanResult decode_scan(std::string_view bytes, const ExpectedOutput &expected);
|
||||
|
||||
// The input owner admits this compatible set. Compatibility identifies frontend, target ABI,
|
||||
// stdlib, flags/environment affecting module interchange. Lookup covers all ordered search
|
||||
// roots, including misses, shadowing, overlays and generated inputs.
|
||||
struct ModuleDomain {
|
||||
Build::Generation generation;
|
||||
std::string compatibility, lookup;
|
||||
bool operator==(const ModuleDomain &) const = default;
|
||||
};
|
||||
|
||||
// Collision-checked identities for the exact invocation, owning source and immutable transitive
|
||||
// inputs. textual_closure includes header contents behind staged imports and their relevant
|
||||
// artifact generations. A user-only depfile additionally needs independently sealed system inputs.
|
||||
struct UnitInputs {
|
||||
std::string command, source, textual_closure;
|
||||
std::optional<std::string> system_closure;
|
||||
bool operator==(const UnitInputs &) const = default;
|
||||
};
|
||||
|
||||
// Provenance from staging an immutable header CMI. The scanner separately identifies the
|
||||
// generation it actually consumed. source_identity names the resolved header across spellings.
|
||||
struct StagedHeader {
|
||||
std::string generation, source_identity;
|
||||
ModuleDomain domain;
|
||||
Build::ContextKey producer;
|
||||
UnitInputs inputs;
|
||||
bool operator==(const StagedHeader &) const = default;
|
||||
};
|
||||
|
||||
struct CensusMember {
|
||||
Build::ContextKey context;
|
||||
ExpectedOutput output;
|
||||
UnitInputs inputs;
|
||||
// Changes on scanner replacement, even for equal source/command or a formerly absent rule.
|
||||
std::string scan_revision;
|
||||
std::optional<StagedHeader> staged_header;
|
||||
bool operator==(const CensusMember &) const = default;
|
||||
};
|
||||
struct ModuleCensus {
|
||||
ModuleDomain domain;
|
||||
std::string revision;
|
||||
bool closed{};
|
||||
// All eligible commands in this dependency domain. Other BuildGeneration alternatives
|
||||
// remain invisible. Distinct visibility sets require distinct censuses.
|
||||
std::vector<CensusMember> members;
|
||||
};
|
||||
|
||||
enum class ScanMethod { unknown, preprocess_md, preprocess_mmd, missing_allowed };
|
||||
enum class UnitKind {
|
||||
unknown,
|
||||
ordinary,
|
||||
implementation,
|
||||
primary_interface,
|
||||
interface_partition,
|
||||
internal_partition,
|
||||
header_unit
|
||||
};
|
||||
struct HeaderProvision {
|
||||
std::size_t index{}; // Index in ScanRule::provides().
|
||||
std::string source_identity;
|
||||
};
|
||||
struct HeaderUse {
|
||||
std::size_t index{}; // Index in ScanRule::requirements().
|
||||
std::string source_identity;
|
||||
std::optional<std::string> loaded_generation;
|
||||
};
|
||||
struct ScanEvidence {
|
||||
ModuleDomain domain;
|
||||
Build::ContextKey context;
|
||||
UnitInputs inputs;
|
||||
std::string scan_revision;
|
||||
std::optional<int> exit_status;
|
||||
std::optional<ScanResult> rule;
|
||||
ScanMethod method{ScanMethod::unknown};
|
||||
// The owner proves a complete pass under these inputs (including generated inputs) and
|
||||
// classifies every header-unit provision from its actual invocation and resolved source.
|
||||
bool complete{};
|
||||
// Implementation and ordinary importer can have identical rules. Only independent frontend
|
||||
// evidence can set one of these two kinds on an import-only TU.
|
||||
UnitKind import_only_kind{UnitKind::unknown};
|
||||
std::vector<HeaderProvision> provided_headers;
|
||||
// Engaged empty means the owner positively established absence of header-unit imports.
|
||||
// Bindings attest every reported lookup/source spelling to the resolved source identity.
|
||||
std::optional<std::vector<HeaderUse>> header_uses;
|
||||
// Verified writer identities in primary-output, then additional_outputs() order. An
|
||||
// isolated invocation can bind the same spelling to a different private destination.
|
||||
std::vector<std::string> writers;
|
||||
};
|
||||
|
||||
enum class PlanIssue {
|
||||
incomplete_census,
|
||||
invalid_context,
|
||||
wrong_domain,
|
||||
duplicate_member,
|
||||
missing_scan,
|
||||
duplicate_scan,
|
||||
scan_failed,
|
||||
missing_rule,
|
||||
invalid_rule,
|
||||
stale_scan,
|
||||
missing_source,
|
||||
incomplete_inputs,
|
||||
incomplete_scan,
|
||||
unproven_mapping,
|
||||
missing_provider,
|
||||
duplicate_provider,
|
||||
stale_header,
|
||||
writer_collision,
|
||||
cycle,
|
||||
limit
|
||||
};
|
||||
struct Blocker {
|
||||
PlanIssue code{};
|
||||
std::optional<std::size_t> unit; // Index in ModulePlan::units, when available.
|
||||
std::string detail;
|
||||
std::optional<ScanError> scan_error;
|
||||
auto operator<=>(const Blocker &) const = default;
|
||||
};
|
||||
struct PlannedUnit {
|
||||
CensusMember member;
|
||||
UnitKind kind{UnitKind::unknown};
|
||||
// Indices in ModulePlan::units. These are direct consumers across the admitted census.
|
||||
std::vector<std::size_t> consumers;
|
||||
};
|
||||
struct ModulePlan {
|
||||
ModuleDomain domain;
|
||||
std::string census_revision;
|
||||
std::vector<PlannedUnit> units; // Ascending ContextKey order.
|
||||
// Prerequisites first, requested TU last. Failure leaves the order empty.
|
||||
std::vector<Build::ContextKey> order;
|
||||
std::vector<Blocker> blockers;
|
||||
// All eligible scans can establish provider claims. A complete census may still have
|
||||
// missing imports, duplicate providers, conflicting writers or cycles. Unproven claims
|
||||
// withhold unit kinds and reverse edges.
|
||||
bool claims_complete{};
|
||||
[[nodiscard]] bool ready() const {
|
||||
return claims_complete && !order.empty() && blockers.empty();
|
||||
}
|
||||
// Also checks non-reachable members. A renamed or newly visible provider can change a
|
||||
// previous successful or missing lookup without having had any positive reverse edge.
|
||||
[[nodiscard]] bool matches_census(const ModuleCensus ¤t) const;
|
||||
};
|
||||
|
||||
[[nodiscard]] ModulePlan build_module_plan(const ModuleCensus &census,
|
||||
std::span<const ScanEvidence> scans,
|
||||
const Build::ContextKey &requested);
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/scheduler/Scheduler.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
enum class ModuleWorkKind { scan, artifact };
|
||||
|
||||
struct ModuleTaskResult {
|
||||
std::string document;
|
||||
ModuleWorkKind kind{ModuleWorkKind::scan};
|
||||
std::uint64_t revision{};
|
||||
scheduler::Outcome outcome{scheduler::Outcome::failed};
|
||||
std::string detail;
|
||||
};
|
||||
|
||||
using ModuleWork = std::function<std::string(std::stop_token)>;
|
||||
|
||||
// Editor-facing module work admission on the shared bounded scheduler.
|
||||
// Scans run at background priority and artifact preparation at artifact
|
||||
// priority, so neither delays foreground editor requests. A newer revision of
|
||||
// one kind supersedes queued work and cancels running work; closing or editing
|
||||
// a document cancels both kinds.
|
||||
class ModuleWorkQueue {
|
||||
public:
|
||||
explicit ModuleWorkQueue(scheduler::Scheduler &scheduler);
|
||||
ModuleWorkQueue(const ModuleWorkQueue &) = delete;
|
||||
ModuleWorkQueue &operator=(const ModuleWorkQueue &) = delete;
|
||||
|
||||
// False for a stale revision, an empty key or a refused scheduler admission.
|
||||
[[nodiscard]] bool submit(
|
||||
std::string document, ModuleWorkKind kind, std::uint64_t revision, ModuleWork work,
|
||||
std::function<void(ModuleTaskResult)> completion = std::function<void(ModuleTaskResult)>{});
|
||||
void cancel(std::string_view document);
|
||||
void cancel_all();
|
||||
|
||||
struct Counts {
|
||||
std::uint64_t submitted{}, completed{}, cancelled{}, failed{};
|
||||
};
|
||||
[[nodiscard]] Counts counts() const;
|
||||
|
||||
private:
|
||||
[[nodiscard]] static std::string key(std::string_view document, ModuleWorkKind kind);
|
||||
scheduler::Scheduler &scheduler_;
|
||||
mutable std::mutex mutex_;
|
||||
std::map<std::string, std::uint64_t> revisions_[2];
|
||||
Counts counts_;
|
||||
};
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ModuleGraph.hpp>
|
||||
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
enum class ScanCommandError {
|
||||
invalid_context,
|
||||
missing_source,
|
||||
duplicate_source,
|
||||
relative_dependency_file,
|
||||
limit
|
||||
};
|
||||
|
||||
struct ScanInvocation {
|
||||
// Driver first, then the original checked arguments with the scan options
|
||||
// appended. The owning source is the final operand.
|
||||
std::vector<std::string> arguments;
|
||||
};
|
||||
|
||||
// Derives a P1689 scan command from a checked compiler context. The driver and
|
||||
// owning source come from the context itself; the dependency file must be
|
||||
// absolute. Existing output, preprocess and dependency options are removed so
|
||||
// project metadata cannot select or duplicate the scan outputs.
|
||||
[[nodiscard]] std::expected<ScanInvocation, ScanCommandError>
|
||||
build_scan_invocation(const Build::BuildContext &context, const ExpectedOutput &output,
|
||||
const std::filesystem::path &dependency_file);
|
||||
|
||||
} // namespace vls::modules
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/modules/ArtifactCache.hpp>
|
||||
#include <vls/scheduler/Scheduler.hpp>
|
||||
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
|
||||
namespace vls::modules {
|
||||
|
||||
// Produces the planned units in dependency order through the shared scheduler
|
||||
// at artifact priority. A superseded, cancelled, timed-out or failed unit
|
||||
// publishes nothing; the staging directory is always removed.
|
||||
[[nodiscard]] std::expected<std::shared_ptr<const ArtifactGeneration>, std::string>
|
||||
produce_module_artifacts_scheduled(const ModulePlan &plan, ArtifactCache &cache,
|
||||
const std::filesystem::path &staging, ArtifactWork work,
|
||||
scheduler::Scheduler &scheduler,
|
||||
std::stop_token stop = std::stop_token{});
|
||||
|
||||
} // namespace vls::modules
|
||||
Reference in new issue
Block a user