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.
157 lines
7.6 KiB
Python
157 lines
7.6 KiB
Python
"""Exercise GCC 16's observable query, recovery, module and metaprogram data."""
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
import time
|
|
|
|
|
|
FIXTURES = Path(__file__).resolve().parent
|
|
|
|
|
|
def run(argv, work, expected=0):
|
|
start = time.monotonic()
|
|
result = subprocess.run(argv, cwd=work, env={**os.environ, "LC_ALL": "C"},
|
|
capture_output=True, text=True, timeout=60)
|
|
if result.returncode != expected:
|
|
raise RuntimeError(f"{argv}: expected {expected}, got {result.returncode}\n{result.stderr}")
|
|
return result, round((time.monotonic() - start) * 1000, 2)
|
|
|
|
|
|
def require(value, reason):
|
|
if not value:
|
|
raise ValueError(reason)
|
|
|
|
|
|
def fixture_tree(path):
|
|
# This fixture has a single invocation and a single field access. Its node
|
|
# numbers and declaration ordering may change independently of its bindings.
|
|
nodes = {}
|
|
for match in re.finditer(r"^@(\d+)\s+(\w+)\s+(.*?)(?=^@\d+|\Z)",
|
|
path.read_text(), re.MULTILINE | re.DOTALL):
|
|
nodes[match[1]] = (match[2], match[3])
|
|
return nodes
|
|
|
|
|
|
def edge(nodes, node, key, expected_kind=None):
|
|
target = re.search(r"(?<!\w)" + re.escape(key) + r"\s*:\s*@(\d+)", node[1])
|
|
require(target, f"missing {key} on {node[0]}")
|
|
result = nodes[target[1]]
|
|
require(expected_kind is None or result[0] == expected_kind, f"{key} leads to {result[0]}")
|
|
return result
|
|
|
|
|
|
def unique_node(nodes, kind):
|
|
found = [node for node in nodes.values() if node[0] == kind]
|
|
require(len(found) == 1, f"fixture has {len(found)} {kind} nodes")
|
|
return found[0]
|
|
|
|
|
|
def spelling(nodes, declaration):
|
|
identifier = edge(nodes, declaration, "name", "identifier_node")
|
|
return re.search(r"strg:\s*(\S+)", identifier[1])[1]
|
|
|
|
|
|
def declaration_line(node):
|
|
return int(re.search(r"srcp:\s*query\.cpp:(\d+)", node[1])[1])
|
|
|
|
|
|
def check_query(flags, work, source, name, target_line, result_type):
|
|
(work / "query.cpp").write_text(source)
|
|
dump = work / "query.raw"
|
|
_, elapsed = run([*flags, f"-fdump-lang-raw={dump}", "-fsyntax-only", "query.cpp"], work)
|
|
nodes = fixture_tree(dump)
|
|
call = unique_node(nodes, "call_expr")
|
|
declaration = edge(nodes, edge(nodes, call, "fn", "addr_expr"), "op 0", "function_decl")
|
|
actual_type = spelling(nodes, edge(nodes, edge(nodes, call, "type"), "name", "type_decl"))
|
|
require((spelling(nodes, declaration), declaration_line(declaration), actual_type) ==
|
|
("coordinate", target_line, result_type), "overload binding or type mismatch")
|
|
field = edge(nodes, unique_node(nodes, "component_ref"), "op 1", "field_decl")
|
|
require((spelling(nodes, field), declaration_line(field)) == ("x", 3), "field resolution")
|
|
return {"case": name, "definition_line": target_line, "type": actual_type,
|
|
"field_definition_line": 3, "compile_ms": elapsed}
|
|
|
|
|
|
def diagnostic(stderr, source_name, line, needle):
|
|
report = json.loads(stderr)
|
|
require(report["version"] == "2.1.0", "unexpected SARIF version")
|
|
for entry in report["runs"][0]["results"]:
|
|
if entry["level"] != "error" or needle not in entry["message"]["text"]:
|
|
continue
|
|
for location in entry["locations"]:
|
|
physical = location["physicalLocation"]
|
|
region = physical["region"]
|
|
if Path(physical["artifactLocation"]["uri"]).name == source_name and region["startLine"] == line:
|
|
require(region["startColumn"] >= 1, "missing source column")
|
|
return {"message": entry["message"]["text"], "region": region,
|
|
"related_locations": len(entry.get("relatedLocations", []))}
|
|
raise ValueError(f"missing {source_name}:{line} diagnostic containing {needle}")
|
|
|
|
|
|
def check_modules(flags, work, value):
|
|
# A content generation gets an isolated GCC module cache. Compile an
|
|
# importer against the new interface and a control expecting the old value.
|
|
work.mkdir()
|
|
provider = (FIXTURES / "gate.cppm").read_text()
|
|
require(provider.count("Ready = 17") == 1, "expected one serialized enum value")
|
|
(work / "gate.cppm").write_text(provider.replace("Ready = 17", f"Ready = {value}"))
|
|
importer = (FIXTURES / "importer.cpp").read_text()
|
|
importer += f"\nstatic_assert(int([:gate::ready_info():]) == {value});\n"
|
|
(work / "importer.cpp").write_text(importer)
|
|
_, compile_ms = run([*flags, "-fmodules", "-x", "c++", "-c", "gate.cppm", "-o", "gate.o"], work)
|
|
_, import_ms = run([*flags, "-fmodules", "-fsyntax-only", "importer.cpp"], work)
|
|
other = 41 if value == 17 else 17
|
|
(work / "control.cpp").write_text(importer + f"static_assert(int([:gate::ready_info():]) == {other});\n")
|
|
failed, _ = run([*flags, "-fmodules", "-fsyntax-only", "-fdiagnostics-format=sarif-stderr",
|
|
"control.cpp"], work, expected=1)
|
|
diagnostic(failed.stderr, "control.cpp", len((work / "control.cpp").read_text().splitlines()),
|
|
"static assertion failed")
|
|
return {"case": f"private module generation {value}", "imported_value": value,
|
|
"interface_ms": compile_ms, "import_ms": import_ms}
|
|
|
|
|
|
def probe(compiler, work):
|
|
version, _ = run([compiler, "-dumpfullversion"], work)
|
|
require(version.stdout.startswith("16."), f"expected GCC 16, got {version.stdout}")
|
|
flags = [compiler, "-std=c++26", "-freflection"]
|
|
saved = (FIXTURES / "gcc-queries.cpp").read_text()
|
|
projected = saved.replace("shapes::Point point)", "shapes::Point point, double weight)").replace(
|
|
"coordinate(point)", "coordinate(weight)")
|
|
cases = [check_query(flags, work, saved, "saved overload", 6, "int"),
|
|
check_query(flags, work, projected, "projected edit", 7, "double")]
|
|
(work / "query.cpp").write_text(projected.replace("coordinate(weight)", "missing(weight)"))
|
|
failed, _ = run([*flags, "-fsyntax-only", "-fdiagnostics-format=sarif-stderr", "query.cpp"],
|
|
work, expected=1)
|
|
cases.append({"case": "malformed edit", **diagnostic(failed.stderr, "query.cpp", 11, "missing")})
|
|
cases.append(check_query(flags, work, saved, "recovered overload", 6, "int"))
|
|
for value in (17, 41):
|
|
cases.append(check_modules(flags, work / f"module-{value}", value))
|
|
source = FIXTURES / "gcc-evaluation.cpp"
|
|
trace = work / "template.txt"
|
|
run([*flags, f"-fdump-lang-tinst={trace}", "-fsyntax-only", source], work)
|
|
lines = trace.read_text().splitlines()
|
|
outer = next(i for i, line in enumerate(lines) if re.match(r"I consteval int twice\(\).*State", line))
|
|
require(any(re.match(r" I consteval int reflected_value\(\).*State", line)
|
|
for line in lines[outer + 1:]), "missing nested consteval instantiation")
|
|
cases.append({"case": "template instantiation dump", "outer": "twice<State>",
|
|
"inner": "reflected_value<State>"})
|
|
failed, _ = run([*flags, "-DCHECK_CONSTRAINT_DIAGNOSTIC", "-fconcepts-diagnostics-depth=3",
|
|
"-fsyntax-only", "-fdiagnostics-format=sarif-stderr", source], work, expected=1)
|
|
constraint = diagnostic(failed.stderr, source.name, 11, "reflected_value<int>")
|
|
require(constraint["related_locations"] > 0, "constraint failure has no related source locations")
|
|
cases.append({"case": "constraint rejection", **constraint})
|
|
require((FIXTURES / "gcc-queries.cpp").read_text() == saved, "saved input changed")
|
|
return {"gcc": version.stdout.strip(), "cases": cases}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--cxx", default="g++")
|
|
args = parser.parse_args()
|
|
with tempfile.TemporaryDirectory(prefix="vls-gcc-tooling-") as temp:
|
|
print(json.dumps(probe(args.cxx, Path(temp)), indent=2))
|