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:
faumaray committed 2026-12-05 14:06:50 +03:00
1 parent ca04975d54
commit da8003f6d4
310 files changed
+47552 -480

No files matched your search

+217
View File
@@ -0,0 +1,217 @@
"""Exercise the private compiler supervisor, live controls, cleanup and offline replay."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import re
import select
import shutil
import subprocess
import tempfile
import time
ROOT = Path(__file__).resolve().parents[2]
WITNESS = r"""
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(void) {
char mode[32] = {0};
FILE *file = fopen("input.cpp", "r");
if (!file || fscanf(file, "%31s", mode) != 1) return 3;
fclose(file);
dprintf(4, "{\"v\":1,\"nonce\":\"%s\",\"seq\":0,\"kind\":\"hello\","
"\"backend\":\"gcc-16.2.0/vls-eval-1\",\"pid\":%ld,"
"\"capabilities\":[\"integralReturn\",\"cooperativeStep\"],"
"\"kinds\":[\"hello\",\"enter\",\"body\",\"value\",\"cached\",\"stopped\","
"\"resumed\",\"leave\",\"terminal\",\"frontendEnd\"]}\n",
getenv("VLS_GCC_NONCE"), (long)getpid());
if (!strcmp(mode, "partial")) { dprintf(4, "{\"v\":"); return 0; }
if (!strcmp(mode, "flood")) {
char block[4096]; memset(block, 'a', sizeof block);
for (int i=0; i<80; ++i) if (write(2, block, sizeof block) < 0) break;
return 0;
}
if (!strcmp(mode, "descendant")) {
pid_t sub = fork();
if (sub < 0) return 2;
if (sub == 0) { sleep(20); _exit(0); }
dprintf(2, "descendant=%ld\n", (long)sub);
return 0;
}
if (!strcmp(mode, "running")) { sleep(20); return 0; }
return 2;
}
"""
def check(value, message):
if not value:
raise RuntimeError(message)
def digest(path):
with path.open("rb") as source:
return hashlib.file_digest(source, "sha256").hexdigest()
class Client:
def __init__(self, probe, compiler, sha, source, trace, step):
args = [probe, "run", compiler, sha, source, trace, *(["--step"] if step else [])]
self.process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, bufsize=0)
self.buffer = bytearray()
def __enter__(self):
return self
def __exit__(self, *unused):
if self.process.poll() is None:
self.process.terminate()
try:
self.process.wait(timeout=5)
except subprocess.TimeoutExpired:
self.process.kill()
self.process.wait(timeout=3)
for pipe in (self.process.stdin, self.process.stdout, self.process.stderr):
pipe.close()
def read(self, expected):
deadline = time.monotonic() + 18
while b"\n" not in self.buffer:
left = deadline - time.monotonic()
check(left > 0 and select.select([self.process.stdout], [], [], left)[0],
f"timed out waiting for {expected}")
chunk = os.read(self.process.stdout.fileno(), 8192)
check(chunk, f"probe closed stdout before {expected}")
self.buffer.extend(chunk)
check(len(self.buffer) <= 73728, "oversized probe notice")
line, _, self.buffer = self.buffer.partition(b"\n")
data = json.loads(line)
check(data["kind"] == expected, f"expected {expected}, got {data!r}")
return data
def send(self, control):
self.process.stdin.write((control + "\n").encode("ascii"))
def finish(self, expected, code):
message = self.read("finished")
actual = self.process.wait(timeout=5)
check(message["outcome"] == expected and actual == code, f"unexpected completion: {actual}, {message}")
check(not self.buffer and not self.process.stdout.read(1), "trailing process output")
check(not self.process.stderr.read(8192), "unexpected supervisor stderr")
def replay(probe, trace, seq=None):
cmd = [probe, "replay", trace, *([str(seq)] if seq is not None else [])]
result = subprocess.run(cmd, capture_output=True, timeout=8, check=True)
check(not result.stderr, f"unexpected replay stderr {result.stderr!r}")
return json.loads(result.stdout)
def integral(snapshot):
frame = snapshot["frames"][-1]
value = frame["value"]
check(value["kind"] == "integer" and value["signed"] and value["precision"] == 32,
f"unexpected scalar {value}")
return frame["name"], int(value["bitsHex"], 16)
def stepped(probe, compiler, sha, source, trace, inner, outer, cancel=False):
with Client(probe, compiler, sha, source, trace, True) as client:
start = client.read("started")
nonce, pid = start["nonce"], start["pid"]
stop = client.read("stopped")
seq = stop["stop"]
check(nonce == stop["nonce"] and client.process.poll() is None, "invalid initial stop")
os.kill(pid, 0)
client.send(f"{nonce} {seq} inspect")
live = client.read("inspection")["snapshot"]
check(integral(live) == ("reflected_value", inner), "wrong live inner value")
check(live["stop"] == seq and not live["frontendEnded"], "incorrect live generation")
client.send(f"{'0'*32} {seq} step")
client.read("rejected")
client.send(f"{nonce} {seq + 1} continue")
client.read("rejected")
check(not select.select([client.process.stdout], [], [], .035)[0], "compiler advanced on stale controls")
if cancel:
client.send(f"{nonce} {seq} cancel")
client.finish("cancelled", 125)
view = replay(probe, trace)
check(view["partial"] and view["terminal"] == "cancelled" and integral(view)[1] == inner,
"cancel lost its verified prefix")
return [seq]
client.send(f"{nonce} {seq} step")
stepped_stop = client.read("stopped")["stop"]
check(stepped_stop > seq, "stop generation did not advance")
client.send(f"{nonce} {seq} step")
client.read("rejected")
client.send(f"{nonce} {stepped_stop} inspect")
check(integral(client.read("inspection")["snapshot"]) == ("twice", outer), "wrong live outer value")
client.send(f"{nonce} {stepped_stop} continue")
client.finish("completed", 0)
return [seq, stepped_stop]
def verify(probe, compiler, cc, work):
fixture = work / "user.cpp"
original = (ROOT / "tests/corpus/frontend/gcc-live.cpp").read_text()
selected = work / "private-cc1plus"
shutil.copy2(compiler, selected)
sha = digest(selected)
old, new, cancelled = (work / name for name in ("old.trace", "edited.trace", "cancelled.trace"))
fixture.write_text(original)
stops = stepped(probe, selected, sha, fixture, old, 17, 34)
fixture.write_text(original.replace("Ready = 17", "Ready = 41"))
stepped(probe, selected, sha, fixture, new, 41, 82)
stepped(probe, selected, sha, fixture, cancelled, 41, 82, cancel=True)
selected.unlink()
fixture.unlink()
for seq, value in zip(stops, (17, 34)):
view = replay(probe, old, seq)
check(view["sequence"] == seq and view["stop"] == seq and integral(view)[1] == value,
"offline replay disagrees with the old live value")
check(view["source"] == original and view["compilerSha256"] == sha and view["outcome"] == "completed",
"offline identity or completion differs")
print("Live and offline GCC sessions agree on 17/34 and 41/82, stale controls and cancellation")
incomplete = work / "partial.trace"
incomplete.write_bytes(old.read_bytes()[:-5])
view = replay(probe, incomplete, stops[0])
check(view["partial"] and view["outcome"] is None and integral(view)[1] == 17, "incomplete tail promoted")
witness_c, witness = work / "witness.c", work / "witness"
witness_c.write_text(WITNESS)
subprocess.run([cc, witness_c, "-o", witness], check=True, timeout=30)
witness_sha = digest(witness)
for mode in ("partial", "flood", "descendant", "running"):
fixture.write_text(mode)
journal = work / f"{mode}.vls"
with Client(probe, witness, witness_sha, fixture, journal, mode == "running") as client:
started = client.read("started")
if mode == "running":
client.send(started["nonce"] + " cancel")
client.finish("cancelled", 125)
else:
client.finish("truncated", 126)
state = replay(probe, journal)
check(state["partial"], f"incomplete witness {mode} declared complete")
if mode == "descendant":
pid = int(re.search(r"descendant=(\d+)", state["diagnostics"]).group(1))
check(not Path(f"/proc/{pid}").exists(), "adopted descendant was not reaped")
if mode == "flood":
check(0 < len(state["diagnostics"]) <= 256*1024, "diagnostics escaped the capture limit")
print("Verified truncated input, bounded stderr, running cancellation and leader-first process cleanup")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--probe", type=Path, required=True)
parser.add_argument("--cc1plus", type=Path, required=True)
parser.add_argument("--cc", default="cc")
opts = parser.parse_args()
with tempfile.TemporaryDirectory(prefix="vls-gcc-supervisor-") as directory:
verify(opts.probe.resolve(strict=True), opts.cc1plus.resolve(strict=True), opts.cc, Path(directory))