Persist record signatures and list observed overloads

SymbolRecord carries the optional compiler signature and the snapshot
schema moves to 3; restore accepts schemas 1-3, verifies the digest for
3 and persists the upgrade. Registered index tests cover signature
persistence, a schema-2 migration keeping records and oversized
rejection. Signature help merges every observed signature for the
name (document occurrences and index) with the compiler-selected one
first; a real stdio session with two called overloads returned both
labels. This is a candidate list, not overload resolution.
This commit is contained in:
faumaray committed 2026-12-05 18:45:37 +03:00
1 parent 816c38da1e
commit a5b9f34c9e
7 files changed
+113 -13

No files matched your search

+49 -5
View File
@@ -134,7 +134,7 @@ VOID_TEST(SymbolIndex, rejects_incompatible_or_corrupt_snapshots) {
return std::string{std::istreambuf_iterator<char>{stream}, {}};
}();
auto incompatible = bytes;
const auto schema = incompatible.find("\"schema\":2");
const auto schema = incompatible.find("\"schema\":3");
require(schema != std::string::npos);
incompatible.replace(schema, 10, "\"schema\":9");
{
@@ -210,7 +210,7 @@ VOID_TEST(SymbolIndex, quarantines_incompatible_snapshots_and_rebuilds) {
std::ifstream stream{path, std::ios::binary};
return std::string{std::istreambuf_iterator<char>{stream}, {}};
}();
const auto schema = bytes.find("\"schema\":2");
const auto schema = bytes.find("\"schema\":3");
require(schema != std::string::npos);
bytes.replace(schema, 10, "\"schema\":9");
{
@@ -350,7 +350,7 @@ std::string downgrade(std::string bytes) {
const auto end = bytes.find('"', digest + 12);
require(end != std::string::npos);
bytes.erase(digest, end + 1 - digest);
const auto schema = bytes.find("\"schema\":2");
const auto schema = bytes.find("\"schema\":3");
require(schema != std::string::npos);
bytes.replace(schema, 10, "\"schema\":1");
return bytes;
@@ -373,7 +373,7 @@ VOID_TEST(SymbolIndex, snapshot_schema_migration_is_reported_and_rewritten) {
const auto upgraded = temp.path() / "upgraded.json";
require(loaded.save(upgraded));
const auto bytes = file_text(upgraded);
expect(bytes.find("\"schema\":2") != std::string::npos);
expect(bytes.find("\"schema\":3") != std::string::npos);
expect(bytes.find("\"digest\":\"") != std::string::npos);
SymbolIndex reread;
expect(reread.load(upgraded));
@@ -394,7 +394,7 @@ VOID_TEST(SymbolIndex, generation_restore_persists_the_migrated_schema) {
expect(restored->migrated);
expect(count(loaded.find({.name = "a"})) == 1);
const auto bytes = file_text(root / "snapshot.json");
expect(bytes.find("\"schema\":2") != std::string::npos);
expect(bytes.find("\"schema\":3") != std::string::npos);
expect(bytes.find("\"digest\":\"") != std::string::npos);
expect(fs::is_regular_file(root / "snapshot.prev.json"));
SymbolIndex reread;
@@ -458,3 +458,47 @@ VOID_TEST(SymbolIndex, finds_records_by_path_with_overlay_shadowing) {
expect(result.symbols.front().name == "d");
expect(index.find_by_path("/project/absent.cpp").symbols.empty());
}
VOID_TEST(SymbolIndex, signatures_survive_persistence) {
Void::FileSystem::TempDir temp{"vls_symbol_index_"};
const auto path = temp.path() / "index.json";
SymbolIndex index;
auto signed_record = record("f", "/project/unit.cpp", 3);
signed_record.signature = "int f(int, double)";
require(index.publish(context("debug:unit", {signed_record})));
require(index.save(path));
SymbolIndex loaded;
require(loaded.load(path));
const auto result = loaded.find({.name = "f"});
require(count(result) == 1);
require(result.symbols.front().signature.has_value());
expect(*result.symbols.front().signature == "int f(int, double)");
}
VOID_TEST(SymbolIndex, schema_2_snapshots_migrate_with_their_records) {
Void::FileSystem::TempDir temp{"vls_symbol_index_"};
const auto path = temp.path() / "index.json";
SymbolIndex index;
require(index.publish(context("debug:unit", {record("f", "/project/unit.cpp", 3)})));
require(index.save(path));
auto bytes = file_text(path);
const auto schema = bytes.find("\"schema\":3");
require(schema != std::string::npos);
bytes.replace(schema, 10, "\"schema\":2");
put_text(path, bytes);
SymbolIndex loaded;
const auto restored = loaded.restore(path);
require(restored.has_value());
expect(restored->status == SymbolIndex::LoadStatus::loaded);
expect(restored->migrated);
expect(count(loaded.find({.name = "f"})) == 1);
require(loaded.save(path));
expect(file_text(path).find("\"schema\":3") != std::string::npos);
}
VOID_TEST(SymbolIndex, rejects_an_oversized_signature) {
SymbolIndex index;
auto signed_record = record("f", "/project/unit.cpp", 3);
signed_record.signature = std::string(400, 'x');
expect(!index.publish(context("debug:unit", {signed_record})));
}