diff --git a/AGENTS.md b/AGENTS.md index 06824a3b..dc4e6adc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -29,12 +29,22 @@ Protocol) stdio server. No AI / vector / LLM anywhere in the binary — output i `reference/golden/cpp/` (corpus `crates/codegraph-bench/fixtures/cpp/`; guards #1043 C++ class/struct inheritance incl. templated-base stripping byte-for-byte, and retroactively - the earlier C++ extraction work). + the earlier C++ extraction work; grown to 17 files by Tier 3 with the MSVC COM + `interface` positives + five guard negatives (#1519) and the C / C++ / ObjC + `union` fixtures incl. both `typedef union` re-kinds and both instantiation + paths (PR #1516) — it is the C-FAMILY corpus, not a strictly-C++ one, since it + holds `.c` and `.mm` files too), and `reference/golden/rust/` + (corpus `crates/codegraph-bench/fixtures/rust/`; the repo's only Rust corpus, + guards #1513/PR #1514 unit structs — 3 `struct` nodes and 4 `implements` edges, + where the unit struct produced NO node before — plus the Rust half of PR #1516's + first-class `union` kind, byte-for-byte; it deliberately claims NO `instantiates` + edge, because that edge fires only for the call-expression construction form and + a Rust union is constructible only as `U { … }`). The Python cross-file edge is resolved by Gate 3a's unique-name fallback; import Gate 3b is deliberately unreachable for real Python nodes because the extractor does not mark them exported. Regen recipe: `docs/equivalence.md` "Godot fixture" / "Ruby fixture" / "Python fixture" / "Kotlin fixture" / - "TypeScript resolution fixture" / "C++ fixture" sections. + "TypeScript resolution fixture" / "C++ fixture" / "Rust fixture" sections. - **node-id formula**: `{kind}:{sha256("{filePath}:{kind}:{name}:{line}").hex[:32]}`; file nodes are the literal `file:{relpath}`; lines are 1-based; paths relative with `/`. - **No AI / vector / LLM crates** — enforced by `scripts/guardrail.sh` (CI gate): @@ -45,7 +55,11 @@ Protocol) stdio server. No AI / vector / LLM anywhere in the binary — output i `codegraph-core` (types/config/logger) · `codegraph-store` (SQLite+FTS5) · `codegraph-extract` (tree-sitter walker + embedded + custom extractors; incl. C++ `base_class_clause` → `Extends` -inheritance extraction with templated-base stripping, #1043) · `codegraph-graph` (traversal + FTS search) · +inheritance extraction with templated-base stripping, #1043; a shared `extract_aggregate` behind +`extract_struct`/`extract_union` so the `union` kind — C/C++/ObjC `union_specifier`, Rust +`union_item`, PR #1516 — inherits struct behaviour by construction, plus the opt-in +`allow_bodiless_struct()` that makes a Rust `struct Unit;` a definition rather than a forward +declaration, #1513) · `codegraph-graph` (traversal + FTS search) · `codegraph-resolve` (import + name matcher + FrameworkResolver; concrete `GodotResolver` impl — autoload-call + signal-handler resolution) · `codegraph-mcp` (stdio JSON-RPC; `codegraph_explore` runs a change-surface rescue, #1064, that surfaces a callable's buried parameter/return-type files into the explored subgraph; every source-emitting diff --git a/crates/codegraph-bench/fixtures/cpp/com_interface.hpp b/crates/codegraph-bench/fixtures/cpp/com_interface.hpp new file mode 100644 index 00000000..fde44ddb --- /dev/null +++ b/crates/codegraph-bench/fixtures/cpp/com_interface.hpp @@ -0,0 +1,20 @@ +struct SControl : IBase { + virtual void Ping() = 0; + void Run() { } +}; + +interface IWidget : IBase { + virtual void Ping() = 0; + void Run() { } +}; + +interface IPlain { + virtual void Ping() = 0; +}; + +interface INewlineBrace +{ + virtual void Ping() = 0; +}; + +int interface_count = 0; diff --git a/crates/codegraph-bench/fixtures/cpp/instantiate_agg.cpp b/crates/codegraph-bench/fixtures/cpp/instantiate_agg.cpp new file mode 100644 index 00000000..78ad77d7 --- /dev/null +++ b/crates/codegraph-bench/fixtures/cpp/instantiate_agg.cpp @@ -0,0 +1,4 @@ +union Reg { int raw; float val; }; +struct Ctl { int id; }; +void mk_union() { Reg r = Reg(); (void)r; } +void mk_struct() { Ctl c = Ctl(); (void)c; } diff --git a/crates/codegraph-bench/fixtures/cpp/instantiate_rank.cpp b/crates/codegraph-bench/fixtures/cpp/instantiate_rank.cpp new file mode 100644 index 00000000..bc8fdc46 --- /dev/null +++ b/crates/codegraph-bench/fixtures/cpp/instantiate_rank.cpp @@ -0,0 +1,5 @@ +union Value { int i; float f; }; +struct Packet { int id; }; +void Value() { } +void ctor_union() { Value v{1}; (void)v; } +void ctor_struct() { Packet p{2}; (void)p; } diff --git a/crates/codegraph-bench/fixtures/cpp/neg_interface.hpp b/crates/codegraph-bench/fixtures/cpp/neg_interface.hpp new file mode 100644 index 00000000..e417cb8d --- /dev/null +++ b/crates/codegraph-bench/fixtures/cpp/neg_interface.hpp @@ -0,0 +1,11 @@ +/* + interface INegComment; +*/ +interface class INegCli { public: virtual void B()=0; }; +interface struct INegStructKw { int x; }; +const char* idl = R"( +interface INegGhost { virtual void B() = 0; }; +)"; +#define NEG_DECL \ + interface INegMacro +struct NegReal { int x; }; diff --git a/crates/codegraph-bench/fixtures/cpp/union_agg.c b/crates/codegraph-bench/fixtures/cpp/union_agg.c new file mode 100644 index 00000000..8f5e405f --- /dev/null +++ b/crates/codegraph-bench/fixtures/cpp/union_agg.c @@ -0,0 +1,9 @@ +union Named { int i; float f; }; +struct Ctl { int x; }; +typedef union { int a; float b; } AnonU; +typedef struct { int a; int b; } AnonS; +typedef union NamedTag { int c; } NamedU; +union Fwd; +struct FwdS; +union { int q; } anon_var; +int read_named(union Named *p) { return p->i; } diff --git a/crates/codegraph-bench/fixtures/cpp/union_agg.cpp b/crates/codegraph-bench/fixtures/cpp/union_agg.cpp new file mode 100644 index 00000000..1f6b690e --- /dev/null +++ b/crates/codegraph-bench/fixtures/cpp/union_agg.cpp @@ -0,0 +1,10 @@ +union WithMethod { + int i; float f; + int read_field() { return i; } +}; +struct SWithMethod { + int i; + int read_field() { return i; } +}; +void drive_union() { WithMethod w; w.read_field(); } +void drive_struct() { SWithMethod s; s.read_field(); } diff --git a/crates/codegraph-bench/fixtures/cpp/union_agg.mm b/crates/codegraph-bench/fixtures/cpp/union_agg.mm new file mode 100644 index 00000000..89c5949a --- /dev/null +++ b/crates/codegraph-bench/fixtures/cpp/union_agg.mm @@ -0,0 +1,2 @@ +union ObjcU { int i; float f; }; +struct ObjcS { int i; }; diff --git a/crates/codegraph-bench/fixtures/rust/consumer.rs b/crates/codegraph-bench/fixtures/rust/consumer.rs new file mode 100644 index 00000000..010c3e5a --- /dev/null +++ b/crates/codegraph-bench/fixtures/rust/consumer.rs @@ -0,0 +1,9 @@ +use crate::{Bits, Greet, UnitStruct}; + +pub fn describe_unit(u: &UnitStruct) -> String { + u.greet() +} + +pub fn describe_bits(b: &Bits) -> String { + b.greet() +} diff --git a/crates/codegraph-bench/fixtures/rust/lib.rs b/crates/codegraph-bench/fixtures/rust/lib.rs new file mode 100644 index 00000000..f38cdb38 --- /dev/null +++ b/crates/codegraph-bench/fixtures/rust/lib.rs @@ -0,0 +1,54 @@ +pub trait Greet { + fn greet(&self) -> String; +} + +pub struct UnitStruct; + +pub struct BraceStruct { + pub x: u32, +} + +pub struct TupleStruct(pub u8); + +impl Greet for UnitStruct { + fn greet(&self) -> String { + "unit".to_string() + } +} + +impl Greet for BraceStruct { + fn greet(&self) -> String { + "brace".to_string() + } +} + +impl Greet for TupleStruct { + fn greet(&self) -> String { + "tuple".to_string() + } +} + +pub union Bits { + pub i: u32, + pub f: f32, +} + +impl Bits { + pub fn raw(&self) -> u32 { + unsafe { self.i } + } +} + +impl Greet for Bits { + fn greet(&self) -> String { + "bits".to_string() + } +} + +pub fn make_unit() -> UnitStruct { + UnitStruct +} + +pub fn make_bits() -> Bits { + Bits { i: 0 } +} diff --git a/crates/codegraph-bench/tests/equivalence.rs b/crates/codegraph-bench/tests/equivalence.rs index e42afef0..76296097 100644 --- a/crates/codegraph-bench/tests/equivalence.rs +++ b/crates/codegraph-bench/tests/equivalence.rs @@ -110,6 +110,24 @@ fn cpp_db_is_self_equivalent_to_cpp_golden() { assert_equivalent(&cpp_db(), &cpp_golden_dir()).unwrap(); } +#[test] +fn generated_golden_matches_committed_rust_fixture() { + // Guards item 7 (Rust unit structs are indexed, so `impl Trait for Unit` + // forms) and item 9-Rust (`union` is a first-class kind) against byte-drift. + let tempdir = TestDir::new("generated-golden-rust"); + write_golden(&rust_db(), tempdir.path()).unwrap(); + + let expected = load_golden(&rust_golden_dir()).unwrap(); + let actual = load_golden(tempdir.path()).unwrap(); + + diff_canonical(&expected, &actual, None).unwrap(); +} + +#[test] +fn rust_db_is_self_equivalent_to_rust_golden() { + assert_equivalent(&rust_db(), &rust_golden_dir()).unwrap(); +} + #[test] fn generated_golden_matches_committed_python_fixture() { let tempdir = TestDir::new("generated-golden-python"); @@ -412,6 +430,14 @@ fn cpp_golden_dir() -> PathBuf { workspace_root().join("reference/golden/cpp") } +fn rust_db() -> PathBuf { + workspace_root().join("reference/golden/rust/colby.db") +} + +fn rust_golden_dir() -> PathBuf { + workspace_root().join("reference/golden/rust") +} + fn python_db() -> PathBuf { workspace_root().join("reference/golden/python/colby.db") } diff --git a/crates/codegraph-core/src/types.rs b/crates/codegraph-core/src/types.rs index a03b2546..7d5f6056 100644 --- a/crates/codegraph-core/src/types.rs +++ b/crates/codegraph-core/src/types.rs @@ -6,10 +6,12 @@ use std::fmt; // protocol, function, method, property, field, variable, constant, enum, // enum_member, type_alias, namespace, parameter, import, export, route, // component. +// `union` is APPENDED (upstream PR #1516): appending keeps every other +// variant's discriminant, and therefore every existing node id, stable. // EdgeKind lines 48-60: contains, calls, imports, exports, extends, // implements, references, type_of, returns, instantiates, overrides, // decorates. -pub const NODE_KIND_STRINGS: [&str; 22] = [ +pub const NODE_KIND_STRINGS: [&str; 23] = [ "file", "module", "class", @@ -32,6 +34,7 @@ pub const NODE_KIND_STRINGS: [&str; 22] = [ "export", "route", "component", + "union", ]; pub const EDGE_KIND_STRINGS: [&str; 12] = [ @@ -140,10 +143,12 @@ pub enum NodeKind { Route, #[serde(rename = "component")] Component, + #[serde(rename = "union")] + Union, } impl NodeKind { - pub const ALL: [Self; 22] = [ + pub const ALL: [Self; 23] = [ Self::File, Self::Module, Self::Class, @@ -166,6 +171,7 @@ impl NodeKind { Self::Export, Self::Route, Self::Component, + Self::Union, ]; pub const fn as_str(self) -> &'static str { @@ -192,6 +198,7 @@ impl NodeKind { Self::Export => "export", Self::Route => "route", Self::Component => "component", + Self::Union => "union", } } } diff --git a/crates/codegraph-extract/src/lang/c.rs b/crates/codegraph-extract/src/lang/c.rs index fe40c524..b2852df8 100644 --- a/crates/codegraph-extract/src/lang/c.rs +++ b/crates/codegraph-extract/src/lang/c.rs @@ -36,6 +36,9 @@ impl LanguageSpec for CSpec { fn struct_types(&self) -> &'static [&'static str] { &["struct_specifier"] } + fn union_types(&self) -> &'static [&'static str] { + &["union_specifier"] + } fn enum_types(&self) -> &'static [&'static str] { &["enum_specifier"] } @@ -77,6 +80,9 @@ impl LanguageSpec for CSpec { if child.kind() == "struct_specifier" && child_by_field(child, "body").is_some() { return Some(NodeKind::Struct); } + if child.kind() == "union_specifier" && child_by_field(child, "body").is_some() { + return Some(NodeKind::Union); + } } None } diff --git a/crates/codegraph-extract/src/lang/cpp.rs b/crates/codegraph-extract/src/lang/cpp.rs index 8c8162d5..9815a40d 100644 --- a/crates/codegraph-extract/src/lang/cpp.rs +++ b/crates/codegraph-extract/src/lang/cpp.rs @@ -36,6 +36,9 @@ impl LanguageSpec for CppSpec { fn struct_types(&self) -> &'static [&'static str] { &["struct_specifier"] } + fn union_types(&self) -> &'static [&'static str] { + &["union_specifier"] + } fn enum_types(&self) -> &'static [&'static str] { &["enum_specifier"] } @@ -117,6 +120,9 @@ impl LanguageSpec for CppSpec { if child.kind() == "struct_specifier" && child_by_field(child, "body").is_some() { return Some(NodeKind::Struct); } + if child.kind() == "union_specifier" && child_by_field(child, "body").is_some() { + return Some(NodeKind::Union); + } } None } @@ -143,8 +149,8 @@ impl LanguageSpec for CppSpec { /// on char boundaries, so byte length (and thus line/column) is preserved. Each /// pass is `contains`-gated, so macro-free C++ is returned byte-identical. fn pre_parse_cpp_source(source: &str, file_path: &str) -> String { - let bytes = blank_cpp_annotation_macro_calls(blank_cpp_inline_annotation_macros( - blank_cpp_api_prefix_macros(source.as_bytes().to_vec()), + let bytes = blank_msvc_com_interface_keyword(blank_cpp_annotation_macro_calls( + blank_cpp_inline_annotation_macros(blank_cpp_api_prefix_macros(source.as_bytes().to_vec())), )); let lower = file_path.to_ascii_lowercase(); let bytes = if lower.ends_with(".metal") { @@ -438,6 +444,239 @@ fn blank_cpp_annotation_macro_calls(bytes: Vec) -> Vec { bytes } +/// Rewrite a line-leading MSVC COM `interface` keyword to `struct` + 3 spaces +/// (#1519). `interface` is 9 bytes and `struct` is 6, so the 3 trailing spaces +/// keep the byte length — and therefore every node's line and column — exactly +/// as it was, the same contract every other pass in this file honours. +/// +/// `interface` is not a C++ keyword, so tree-sitter-cpp reads +/// `interface IFoo : IBase { … };` as a `function_definition`: the container +/// becomes a `function`, its members become free `function`s instead of +/// `method`s, and the base clause is lost entirely. A COM `interface` IS +/// `#define`d to `struct`, so rewriting the token recovers all three at once. +/// +/// Declined unless EVERY byte of the token is ordinary code per +/// [`cpp_code_mask`], and declined when the next token is `class`, `struct`, +/// `union` or `enum` — C++/CLI `interface class IFoo` is valid input today and +/// the naive rewrite would emit the INVALID `struct class IFoo`. +/// `contains`-gated, so C++ without the token is returned byte-identical. +fn blank_msvc_com_interface_keyword(bytes: Vec) -> Vec { + const KEYWORD: &[u8] = b"interface"; + let source = match std::str::from_utf8(&bytes) { + Ok(source) => source, + Err(_) => return bytes, + }; + if !source.contains("interface") { + return bytes; + } + let mask = cpp_code_mask(source); + let src = source.as_bytes(); + let mut starts: Vec = Vec::new(); + let mut pos = 0usize; + loop { + let line_end = src[pos..] + .iter() + .position(|&b| b == b'\n') + .map_or(src.len(), |offset| pos + offset); + let mut i = pos; + while i < line_end && matches!(src[i], b' ' | b'\t') { + i += 1; + } + if i + KEYWORD.len() <= line_end && &src[i..i + KEYWORD.len()] == KEYWORD { + let all_code = (i..i + KEYWORD.len()).all(|k| mask[k]); + let mut j = i + KEYWORD.len(); + let mut saw_space = false; + while j < line_end && matches!(src[j], b' ' | b'\t') { + saw_space = true; + j += 1; + } + let ident_start = src + .get(j) + .is_some_and(|b| b.is_ascii_alphabetic() || *b == b'_'); + let mut k = j; + while k < line_end && (src[k].is_ascii_alphanumeric() || src[k] == b'_') { + k += 1; + } + let excluded = matches!(&src[j..k], b"class" | b"struct" | b"union" | b"enum"); + if all_code && saw_space && ident_start && !excluded { + starts.push(i); + } + } + if line_end >= src.len() { + break; + } + pos = line_end + 1; + } + let mut bytes = bytes; + for start in starts { + bytes[start..start + 6].copy_from_slice(b"struct"); + for b in bytes[start + 6..start + KEYWORD.len()].iter_mut() { + *b = b' '; + } + } + bytes +} + +/// Byte mask over `src`: `true` where the byte is ordinary code. One forward +/// scan tracking the five lexical states a textual match could hide in — line +/// comments, block comments, char and string literals, C++ raw strings +/// (`R"delim( … )delim"`, delimiter captured so a custom delimiter still closes +/// correctly), and whole LOGICAL preprocessor lines including backslash +/// continuations. Lexical state is not optional for #1519: a comment can hold a +/// COMPLETE declaration (`/* interface IFoo; */`) that becomes the FOLLOWING +/// node's docstring, so a purely textual match corrupts extraction output even +/// though it never mints a node. +fn cpp_code_mask(src: &str) -> Vec { + let bytes = src.as_bytes(); + let mut mask = vec![true; bytes.len()]; + let mut i = 0usize; + let mut at_line_start = true; + while i < bytes.len() { + let b = bytes[i]; + if b == b'\n' { + at_line_start = true; + i += 1; + continue; + } + if at_line_start { + if matches!(b, b' ' | b'\t' | b'\r') { + i += 1; + continue; + } + at_line_start = false; + if b == b'#' { + i = mask_preprocessor_line(bytes, &mut mask, i); + at_line_start = true; + continue; + } + } + if b == b'/' && bytes.get(i + 1) == Some(&b'/') { + while i < bytes.len() && bytes[i] != b'\n' { + mask[i] = false; + i += 1; + } + continue; + } + if b == b'/' && bytes.get(i + 1) == Some(&b'*') { + mask[i] = false; + mask[i + 1] = false; + i += 2; + while i < bytes.len() { + let closing = bytes[i] == b'*' && bytes.get(i + 1) == Some(&b'/'); + mask[i] = false; + i += 1; + if closing { + mask[i] = false; + i += 1; + break; + } + } + continue; + } + // A raw string is recognised by the `R` immediately before the quote, + // which also covers every encoding prefix (`LR"`, `u8R"`, `uR"`, `UR"`). + if b == b'"' && i > 0 && bytes[i - 1] == b'R' { + i = mask_raw_string(bytes, &mut mask, i); + continue; + } + if b == b'"' || b == b'\'' { + i = mask_quoted_literal(bytes, &mut mask, i, b); + continue; + } + i += 1; + } + mask +} + +/// Mask a whole LOGICAL preprocessor line starting at `start` (the `#`), +/// following every backslash-newline continuation. Returns the index just past +/// the logical line. The continuation matters: `#define D \` + a following +/// ` interface IFoo` line is one directive, and its second physical line is +/// not code. +fn mask_preprocessor_line(bytes: &[u8], mask: &mut [bool], start: usize) -> usize { + let mut i = start; + loop { + while i < bytes.len() && bytes[i] != b'\n' { + mask[i] = false; + i += 1; + } + let mut back = i; + if back > start && bytes[back - 1] == b'\r' { + back -= 1; + } + let continued = back > start && bytes[back - 1] == b'\\'; + if i < bytes.len() { + mask[i] = false; + i += 1; + } + if !continued || i >= bytes.len() { + return i; + } + } +} + +/// Mask `R"delim( … )delim"` from its opening quote. The delimiter is captured +/// so a custom one (`R"xy( … )xy"`) closes on its own terminator instead of the +/// first `)"`. A malformed opener falls back to ordinary string rules. +fn mask_raw_string(bytes: &[u8], mask: &mut [bool], quote: usize) -> usize { + let mut delim_end = quote + 1; + while delim_end < bytes.len() + && bytes[delim_end] != b'(' + && delim_end - (quote + 1) < 16 + && !bytes[delim_end].is_ascii_whitespace() + { + delim_end += 1; + } + if delim_end >= bytes.len() || bytes[delim_end] != b'(' { + return mask_quoted_literal(bytes, mask, quote, b'"'); + } + let mut closer = Vec::with_capacity(delim_end - quote + 1); + closer.push(b')'); + closer.extend_from_slice(&bytes[quote + 1..delim_end]); + closer.push(b'"'); + let mut k = delim_end + 1; + let end = loop { + if k + closer.len() > bytes.len() { + break bytes.len(); + } + if bytes[k..k + closer.len()] == closer[..] { + break k + closer.len(); + } + k += 1; + }; + for m in mask.iter_mut().take(end).skip(quote) { + *m = false; + } + end +} + +/// Mask a `"…"` or `'…'` literal from its opening quote, honouring backslash +/// escapes. An unterminated literal stops at the newline rather than swallowing +/// the rest of the file. +fn mask_quoted_literal(bytes: &[u8], mask: &mut [bool], start: usize, quote: u8) -> usize { + mask[start] = false; + let mut i = start + 1; + while i < bytes.len() { + let c = bytes[i]; + if c == b'\n' { + break; + } + mask[i] = false; + i += 1; + if c == b'\\' { + if i < bytes.len() && bytes[i] != b'\n' { + mask[i] = false; + i += 1; + } + continue; + } + if c == quote { + break; + } + } + i +} + /// Recover the real function name from the macro-definition idiom /// `MACRO_NAME(real_name, typed args…) { body }` (flash-attention's /// `DEFINE_FLASH_FORWARD_KERNEL(flash_fwd_kernel, bool Is_dropout, …) { … }`): @@ -823,6 +1062,113 @@ mod tests { assert_eq!(out, src); } + #[test] + fn msvc_com_interface_rewrite_preserves_byte_offsets() { + // `interface` (9 bytes) -> `struct` (6) + 3 spaces, so every subsequent + // byte offset — and therefore every node's line and column — is exactly + // where it was. A shorter or longer replacement would silently shift the + // whole file's positions. + let src = "interface IWidget : IBase {\n void Run() { }\n};\n"; + let out = pre_parse_cpp_source(src, "com.hpp"); + assert_eq!( + out.len(), + src.len(), + "the rewrite must preserve byte length" + ); + assert_eq!(out, "struct IWidget : IBase {\n void Run() { }\n};\n"); + // The rewritten declaration must land on the same line and column as the + // equivalent struct written by hand. + let control = "struct SControl : IBase {\n void Run() { }\n};\n"; + let control_out = pre_parse_cpp_source(control, "ctl.hpp"); + assert_eq!( + control_out, control, + "the control must be returned unchanged" + ); + assert_eq!( + out.find("IWidget").expect("name present"), + control.find("SControl").expect("control name present"), + "the rewritten name must start at the control's column" + ); + } + + /// Every §3.3.3 shape, as a direct unit test of the pass: 11 that must NOT + /// fire and 4 that must, each also asserting byte length is preserved. This + /// is the ONLY isolated proof of the `class`/`struct`/`union`/`enum` + /// exclusion — the end-to-end `neg_interface.hpp` invariance test cannot see + /// it, because dropping the exclusion emits `struct class INegCli`, which + /// tree-sitter's error recovery happens to extract identically for that + /// file's text (measured). The exclusion is still required: it stops the pass + /// emitting invalid C++ from input that parses correctly today. + #[test] + fn cpp_code_mask_covers_comments_strings_and_preproc() { + let must_not_fire: &[(&str, &str)] = &[ + ( + "block comment", + "/*\ninterface IFoo;\n*/\nstruct R { int x; };\n", + ), + ( + "block cmt full decl", + "/*\ninterface IGhost { virtual void B() = 0; };\n*/\nstruct R { int x; };\n", + ), + ("line comment", "// interface IFoo;\nstruct R { int x; };\n"), + ( + "cpp/cli class", + "interface class IFoo { public: virtual void B()=0; };\n", + ), + ("interface struct", "interface struct IBar { int x; };\n"), + ("__interface", "__interface IFoo { virtual void B()=0; };\n"), + ("raw string", "const char* s = R\"(\ninterface IFoo\n)\";\n"), + ( + "raw string full decl", + "const char* s = R\"(\ninterface IGhost { virtual void B() = 0; };\n)\";\n", + ), + ( + "raw delim", + "const char* s = R\"xy(\ninterface IFoo )\" still inside\n)xy\";\n", + ), + ( + "macro continuation", + "#define DECL \\\n interface IMacro\nstruct R { int x; };\n", + ), + ("interface_ptr", "int interface_ptr = 0;\n"), + ]; + for (label, src) in must_not_fire { + let out = pre_parse_cpp_source(src, "n.hpp"); + assert_eq!(out.len(), src.len(), "{label}: byte length moved"); + assert_eq!(out, *src, "{label}: the substitution must NOT fire"); + } + + let must_fire: &[(&str, &str, &str)] = &[ + ( + "plain", + "interface IWidget : IBase {\n};\n", + "struct IWidget : IBase {\n};\n", + ), + ( + "newline brace", + "interface INewline\n{\n};\n", + "struct INewline\n{\n};\n", + ), + ( + "indented", + " interface IIndent {\n};\n", + " struct IIndent {\n};\n", + ), + ( + // The discriminating case: the masked `#define` directive is left + // alone while the real declaration beneath it IS rewritten. + "define interface", + "#define interface struct\ninterface IDefined {\n};\n", + "#define interface struct\nstruct IDefined {\n};\n", + ), + ]; + for (label, src, want) in must_fire { + let out = pre_parse_cpp_source(src, "p.hpp"); + assert_eq!(out.len(), src.len(), "{label}: byte length moved"); + assert_eq!(out, *want, "{label}: the substitution must fire"); + } + } + #[test] fn blank_cpp_annotation_in_expression_untouched() { let src = "if (CHECK(x)) {}"; diff --git a/crates/codegraph-extract/src/lang/objc.rs b/crates/codegraph-extract/src/lang/objc.rs index dbdef3f7..95f194c9 100644 --- a/crates/codegraph-extract/src/lang/objc.rs +++ b/crates/codegraph-extract/src/lang/objc.rs @@ -45,6 +45,10 @@ impl LanguageSpec for ObjCSpec { &["struct_specifier"] } + fn union_types(&self) -> &'static [&'static str] { + &["union_specifier"] + } + fn enum_types(&self) -> &'static [&'static str] { &["enum_specifier"] } @@ -112,6 +116,9 @@ impl LanguageSpec for ObjCSpec { if child.kind() == "struct_specifier" && child_by_field(child, "body").is_some() { return Some(NodeKind::Struct); } + if child.kind() == "union_specifier" && child_by_field(child, "body").is_some() { + return Some(NodeKind::Union); + } } None } diff --git a/crates/codegraph-extract/src/lang/rust.rs b/crates/codegraph-extract/src/lang/rust.rs index 6d80b11c..461fb237 100644 --- a/crates/codegraph-extract/src/lang/rust.rs +++ b/crates/codegraph-extract/src/lang/rust.rs @@ -30,6 +30,9 @@ impl LanguageSpec for RustSpec { fn struct_types(&self) -> &'static [&'static str] { &["struct_item"] } + fn union_types(&self) -> &'static [&'static str] { + &["union_item"] + } fn enum_types(&self) -> &'static [&'static str] { &["enum_item"] } @@ -51,6 +54,9 @@ impl LanguageSpec for RustSpec { fn interface_kind(&self) -> NodeKind { NodeKind::Trait } + fn allow_bodiless_struct(&self) -> bool { + true + } fn name_field(&self) -> &'static str { "name" } diff --git a/crates/codegraph-extract/src/spec.rs b/crates/codegraph-extract/src/spec.rs index 7a4b6aac..033a62c2 100644 --- a/crates/codegraph-extract/src/spec.rs +++ b/crates/codegraph-extract/src/spec.rs @@ -35,6 +35,15 @@ pub trait LanguageSpec: Sync { fn interface_types(&self) -> &'static [&'static str]; fn struct_types(&self) -> &'static [&'static str]; fn enum_types(&self) -> &'static [&'static str]; + + /// Node types extracted as [`NodeKind::Union`] through the shared aggregate + /// path. Empty by default: only C, C++, ObjC (`union_specifier`) and Rust + /// (`union_item`) have a union declaration. TypeScript's `A | B` is + /// deliberately NOT here — it stays a `type_alias`, as upstream PR #1516 + /// decided. + fn union_types(&self) -> &'static [&'static str] { + &[] + } fn enum_member_types(&self) -> &'static [&'static str]; fn type_alias_types(&self) -> &'static [&'static str]; fn import_types(&self) -> &'static [&'static str]; @@ -91,6 +100,16 @@ pub trait LanguageSpec: Sync { false } + /// A bodiless `struct NAME;` is a COMPLETE definition, not a forward + /// declaration. Opt-in, because the default is the C-shaped rule: in + /// C/C++/ObjC `struct Foo;` really is a forward declaration and must stay + /// unindexed (`c_bodiless_forward_struct_is_skipped`). Rust has no forward + /// declarations, so the unit form is always a definition + /// (upstream #1513/PR #1514). + fn allow_bodiless_struct(&self) -> bool { + false + } + fn get_signature(&self, _node: Node<'_>, _source: &str) -> Option { None } diff --git a/crates/codegraph-extract/src/walker.rs b/crates/codegraph-extract/src/walker.rs index 0c4459bc..7d21d553 100644 --- a/crates/codegraph-extract/src/walker.rs +++ b/crates/codegraph-extract/src/walker.rs @@ -268,6 +268,9 @@ impl<'a, 'tree> TreeSitterWalker<'a, 'tree> { } else if has_type(self.spec.struct_types(), node_type) { self.extract_struct(node); skip_children = true; + } else if has_type(self.spec.union_types(), node_type) { + self.extract_union(node); + skip_children = true; } else if has_type(self.spec.enum_types(), node_type) { self.extract_enum(node); skip_children = true; @@ -2159,12 +2162,31 @@ impl<'a, 'tree> TreeSitterWalker<'a, 'tree> { } fn extract_struct(&mut self, node: SyntaxNode<'tree>) { - let Some(body) = self.resolve_body(node) else { + self.extract_aggregate(node, NodeKind::Struct); + } + + fn extract_union(&mut self, node: SyntaxNode<'tree>) { + self.extract_aggregate(node, NodeKind::Union); + } + + /// Shared struct/union extractor (upstream `6978acc`'s `extractAggregate`). + /// One body, so a union's members, methods, containment and inheritance + /// behave like a struct's BY CONSTRUCTION rather than by parallel + /// maintenance — which is what every downstream `Union`-in-a-kind-set port + /// assumes. + fn extract_aggregate(&mut self, node: SyntaxNode<'tree>, kind: NodeKind) { + // #1093 / #1513 — a bodiless aggregate is a C/C++/ObjC forward + // declaration and stays unindexed, but a Rust `struct Unit;` is a + // complete definition, so the spec decides. The node is minted BEFORE + // the body walk (PR #1514) and the walk is conditional, which is the + // shape `extract_interface` already has. + let body = self.resolve_body(node); + if body.is_none() && !self.spec.allow_bodiless_struct() { return; - }; + } let name = self.extract_name(node); - let struct_node = self.create_node( - NodeKind::Struct, + let aggregate_node = self.create_node( + kind, &name, node, NodeExtra { @@ -2174,13 +2196,15 @@ impl<'a, 'tree> TreeSitterWalker<'a, 'tree> { ..NodeExtra::default() }, ); - let Some(struct_node) = struct_node else { + let Some(aggregate_node) = aggregate_node else { return; }; - self.extract_inheritance(node, &struct_node.id); - self.node_stack.push(struct_node.id); - self.visit_named_children(body); - self.node_stack.pop(); + self.extract_inheritance(node, &aggregate_node.id); + if let Some(body) = body { + self.node_stack.push(aggregate_node.id); + self.visit_named_children(body); + self.node_stack.pop(); + } } fn extract_method(&mut self, node: SyntaxNode<'tree>) { @@ -2239,6 +2263,7 @@ impl<'a, 'tree> TreeSitterWalker<'a, 'tree> { && matches!( n.kind, NodeKind::Struct + | NodeKind::Union | NodeKind::Class | NodeKind::Enum | NodeKind::Trait @@ -2404,6 +2429,7 @@ impl<'a, 'tree> TreeSitterWalker<'a, 'tree> { alias_kind, NodeKind::Class | NodeKind::Struct + | NodeKind::Union | NodeKind::Interface | NodeKind::Trait | NodeKind::Enum @@ -3732,6 +3758,7 @@ impl<'a, 'tree> TreeSitterWalker<'a, 'tree> { node.kind, NodeKind::Class | NodeKind::Struct + | NodeKind::Union | NodeKind::Interface | NodeKind::Trait | NodeKind::Enum @@ -7504,4 +7531,357 @@ g() ->\n\ "an identifier receiver must still emit `s.trim`, got: {java:?}" ); } + + // ---- Tier 3 / item 7 — Rust unit structs (upstream #1513, PR #1514) ---- + + #[test] + fn rust_unit_struct_is_indexed_with_its_impl_edge() { + // A bodiless `struct NAME;` is a COMPLETE definition in Rust, not a + // forward declaration, so it must mint a node and its `impl Trait for` + // must produce an Implements ref exactly as the bodied controls do. + let src = r#" +pub trait Greet { fn greet(&self) -> String; } + +pub struct UnitStruct; +pub struct BraceStruct { pub x: u32 } +pub struct TupleStruct(pub u8); + +impl Greet for UnitStruct { fn greet(&self) -> String { "unit".to_string() } } +impl Greet for BraceStruct { fn greet(&self) -> String { "brace".to_string() } } +impl Greet for TupleStruct { fn greet(&self) -> String { "tuple".to_string() } } +"#; + let (nodes, refs) = run("lib.rs", src, Language::Rust); + assert!( + has_node(&nodes, NodeKind::Struct, "UnitStruct"), + "the unit struct must be indexed" + ); + // Controls: both bodied forms are indexed today and must stay indexed. + assert!(has_node(&nodes, NodeKind::Struct, "BraceStruct")); + assert!(has_node(&nodes, NodeKind::Struct, "TupleStruct")); + let implements = refs + .iter() + .filter(|r| r.reference_kind == EdgeKind::Implements) + .count(); + assert_eq!( + implements, 3, + "each of the three structs must carry an Implements ref, got {implements}" + ); + } + + // ---- Tier 3 / item 8 — MSVC COM `interface` (upstream #1519) ---- + + /// The §7.2 `com_interface.hpp` fixture text, shared by the extraction test + /// and the byte-offset test so both speak about the same bytes. + const COM_INTERFACE_SRC: &str = "\ +struct SControl : IBase { + virtual void Ping() = 0; + void Run() { } +}; + +interface IWidget : IBase { + virtual void Ping() = 0; + void Run() { } +}; + +interface IPlain { + virtual void Ping() = 0; +}; + +interface INewlineBrace +{ + virtual void Ping() = 0; +}; + +int interface_count = 0; +"; + + /// The §7.2 `neg_interface.hpp` fixture text: the five shapes the guard must + /// decline. Written as an escaped literal because a raw string cannot nest + /// the `R"( … )"` it needs to contain. + const NEG_INTERFACE_SRC: &str = concat!( + "/*\n interface INegComment;\n*/\n", + "interface class INegCli { public: virtual void B()=0; };\n", + "interface struct INegStructKw { int x; };\n", + "const char* idl = R\"(\ninterface INegGhost { virtual void B() = 0; };\n)\";\n", + "#define NEG_DECL \\\n interface INegMacro\n", + "struct NegReal { int x; };\n", + ); + + #[test] + fn cpp_msvc_com_interface_extracts_as_struct() { + let (nodes, refs) = run("com_interface.hpp", COM_INTERFACE_SRC, Language::Cpp); + // Loss 1 — the COM interface must be a container, not a function. + for name in ["IWidget", "IPlain", "INewlineBrace"] { + assert!( + has_node(&nodes, NodeKind::Struct, name), + "`interface {name}` must extract as a struct" + ); + } + assert!(has_node(&nodes, NodeKind::Struct, "SControl")); + assert!( + !nodes + .iter() + .any(|n| n.kind == NodeKind::Function && n.file_path == "com_interface.hpp"), + "no node in this file may stay a function: {:?}", + nodes + .iter() + .filter(|n| n.kind == NodeKind::Function) + .map(|n| (n.name.as_str(), n.start_line)) + .collect::>() + ); + // Loss 2 — the member is a method of the interface, not a free function. + let mut runs = nodes + .iter() + .filter(|n| n.kind == NodeKind::Method && n.name == "Run") + .map(|n| n.qualified_name.as_str()) + .collect::>(); + runs.sort_unstable(); + assert_eq!( + runs, + ["IWidget::Run", "SControl::Run"], + "both members must be methods of their own container" + ); + // Loss 3 — the base type is visible. The control emits one today; the + // rewritten interface must emit the second. + let extends_ibase = refs + .iter() + .filter(|r| r.reference_kind == EdgeKind::Extends && r.reference_name == "IBase") + .count(); + assert_eq!( + extends_ibase, 2, + "SControl and IWidget must each emit `extends IBase`, got {extends_ibase}" + ); + } + + // ---- Tier 3 / item 9 — first-class `union` nodes (upstream PR #1516) ---- + + #[test] + fn rust_union_is_indexed_with_its_impl_edge() { + let src = r#" +pub trait Greet { fn greet(&self) -> String; } +pub union Bits { pub i: u32, pub f: f32 } +impl Bits { pub fn raw(&self) -> u32 { unsafe { self.i } } } +impl Greet for Bits { fn greet(&self) -> String { "bits".to_string() } } +"#; + let (nodes, refs) = run("lib.rs", src, Language::Rust); + assert!( + has_node(&nodes, NodeKind::Union, "Bits"), + "a Rust union must be a first-class union node" + ); + assert!( + !has_node(&nodes, NodeKind::Struct, "Bits"), + "a union must not be re-kinded to a struct" + ); + assert!( + has_ref(&refs, EdgeKind::Implements, "Greet"), + "the union's `impl Greet for` must produce an Implements ref" + ); + } + + #[test] + fn c_cpp_objc_union_is_indexed_not_a_struct() { + for (file, src, lang) in [ + ( + "m.c", + "union Named { int i; float f; };\nstruct Ctl { int x; };\n", + Language::C, + ), + ( + "m.cpp", + "union Named { int i; float f; };\nstruct Ctl { int x; };\n", + Language::Cpp, + ), + ( + "m.mm", + "union Named { int i; float f; };\nstruct Ctl { int x; };\n", + Language::ObjC, + ), + ] { + let (nodes, _) = run(file, src, lang); + assert!( + has_node(&nodes, NodeKind::Union, "Named"), + "{file}: `union Named` must be a union node" + ); + assert!( + !has_node(&nodes, NodeKind::Struct, "Named"), + "{file}: the union must not be kinded as a struct" + ); + // Control: the struct beside it is unchanged. + assert!( + has_node(&nodes, NodeKind::Struct, "Ctl"), + "{file}: the struct control must stay a struct" + ); + } + } + + #[test] + fn cpp_union_member_method_belongs_to_the_union() { + // Pre-fix this member leaked to FILE scope as `function:read_field` with + // no container, which is what let a call on the union bind the SAME-NAMED + // struct method instead (the false edge in upstream #1515). + let src = concat!( + "union WithMethod {\n", + " int i; float f;\n", + " int read_field() { return i; }\n", + "};\n", + "struct SWithMethod {\n", + " int i;\n", + " int read_field() { return i; }\n", + "};\n", + ); + let (nodes, _) = run("union_agg.cpp", src, Language::Cpp); + let union_node = node(&nodes, NodeKind::Union, "WithMethod"); + let mut members = nodes + .iter() + .filter(|n| n.kind == NodeKind::Method && n.name == "read_field") + .map(|n| n.qualified_name.as_str()) + .collect::>(); + members.sort_unstable(); + assert_eq!( + members, + ["SWithMethod::read_field", "WithMethod::read_field"], + "the union's member must be a method qualified by the union" + ); + assert!( + !nodes + .iter() + .any(|n| n.kind == NodeKind::Function && n.name == "read_field"), + "no `read_field` may remain a free function at file scope" + ); + assert!( + union_node.start_line == 1 && union_node.end_line >= 4, + "the union must span its whole body: {union_node:?}" + ); + } + + #[test] + fn cpp_out_of_line_union_method_gets_its_contains_edge() { + // The receiver-owner lookup is the widening that fails SILENTLY: an + // out-of-line `Union::method` still becomes a method with the right + // qualified name, so only the missing `contains union -> method` edge + // reveals the omission. + let src = concat!( + "union WithMethod {\n", + " int i;\n", + " int read_field();\n", + "};\n", + "int WithMethod::read_field() { return i; }\n", + ); + let result = extract_source("u.cpp", src, Some(Language::Cpp)); + assert!(result.errors.is_empty(), "errors: {:?}", result.errors); + let union_id = &node(&result.nodes, NodeKind::Union, "WithMethod").id; + let method_id = &node(&result.nodes, NodeKind::Method, "read_field").id; + assert!( + result.edges.iter().any(|e| e.kind == EdgeKind::Contains + && &e.source == union_id + && &e.target == method_id), + "the out-of-line method must be contained by its union" + ); + } + + #[test] + fn c_typedef_union_is_one_union_node_named_by_the_typedef() { + let src = concat!( + "typedef union { int a; float b; } AnonU;\n", + "typedef struct { int a; int b; } AnonS;\n", + "typedef union NamedTag { int c; } NamedU;\n", + ); + let (nodes, _) = run("m.c", src, Language::C); + let named = nodes + .iter() + .filter(|n| n.name == "NamedU") + .collect::>(); + assert_eq!( + named.len(), + 1, + "`typedef union NamedTag {{…}} NamedU;` must mint exactly ONE node, got {named:?}" + ); + assert_eq!(named[0].kind, NodeKind::Union); + // The inner tag is not a separate node: extract_type_alias consumes the + // union_specifier, so it is never re-dispatched. + assert!( + !nodes.iter().any(|n| n.name == "NamedTag"), + "the union's tag must not become its own node" + ); + assert!(has_node(&nodes, NodeKind::Union, "AnonU")); + // Control: the struct typedef beside it keeps its kind. + assert!(has_node(&nodes, NodeKind::Struct, "AnonS")); + } + + #[test] + fn bodiless_and_anonymous_unions_are_not_indexed() { + let src = concat!( + "union Fwd;\n", + "struct FwdS;\n", + "union { int q; } anon_var;\n", + "struct { int r; } anon_struct_var;\n", + "union Named { int i; };\n", + ); + let (nodes, _) = run("m.c", src, Language::C); + // A bodiless C union is a forward declaration: the shared aggregate guard + // drops it, the same rule that keeps `struct Foo;` out. + assert!(!nodes.iter().any(|n| n.name == "Fwd")); + assert!(!nodes.iter().any(|n| n.name == "FwdS")); + // An anonymous union mints nothing, because the anonymous struct beside it + // mints nothing — both are consumed by the `declaration` arm. + assert!( + !nodes.iter().any(|n| n.name == ""), + "an anonymous aggregate must mint no node: {:?}", + nodes.iter().map(|n| &n.name).collect::>() + ); + // Positive control, so the negatives cannot pass by the file failing to parse. + assert!(has_node(&nodes, NodeKind::Union, "Named")); + } + + #[test] + fn cpp_interface_guard_negatives_are_extraction_invariant() { + // GREEN BEFORE THE FIX: this encodes today's measured output, so it is an + // invariance guard rather than a regression test written afterwards. Each + // row is a value a leaking mask would change — `INegCli`'s docstring is + // the sharpest, because a comment-blind substitution rewrites the comment + // text itself. + let (nodes, _) = run("neg_interface.hpp", NEG_INTERFACE_SRC, Language::Cpp); + let mut got = nodes + .iter() + .filter(|n| n.kind != NodeKind::File) + .map(|n| { + ( + n.kind, + n.name.as_str(), + n.start_line, + n.docstring.as_deref(), + ) + }) + .collect::>(); + got.sort_by_key(|row| row.2); + assert_eq!( + got, + vec![ + ( + NodeKind::Function, + "INegCli", + 4, + Some("interface INegComment;") + ), + (NodeKind::Function, "INegStructKw", 5, None), + (NodeKind::Struct, "NegReal", 11, None), + ], + "the guard leaked: extraction output moved" + ); + // A count catches a PHANTOM node that a name list would miss. + assert_eq!(got.len(), 3, "expected exactly 3 nodes, got {got:?}"); + // Survives tree-sitter error-recovery differences in the garbage names. + assert!( + !nodes + .iter() + .any(|n| n.kind == NodeKind::Struct && n.name.starts_with("INeg")), + "an INeg* name became a struct: the interface class/struct exclusion failed" + ); + for phantom in ["INegGhost", "INegMacro"] { + assert!( + !nodes.iter().any(|n| n.name == phantom), + "{phantom} must mint no node of any kind" + ); + } + } } diff --git a/crates/codegraph-graph/src/graph/mod.rs b/crates/codegraph-graph/src/graph/mod.rs index b49cb0cb..bf40377c 100644 --- a/crates/codegraph-graph/src/graph/mod.rs +++ b/crates/codegraph-graph/src/graph/mod.rs @@ -15,10 +15,11 @@ use serde::Serialize; // upstream graph/traversal.ts:506 — container kinds whose `contains` // children are pulled into the impact set at the same depth as the container. -const CONTAINER_KINDS: [NodeKind; 7] = [ +const CONTAINER_KINDS: [NodeKind; 8] = [ NodeKind::Class, NodeKind::Interface, NodeKind::Struct, + NodeKind::Union, NodeKind::Trait, NodeKind::Protocol, NodeKind::Module, diff --git a/crates/codegraph-graph/src/query/scoring.rs b/crates/codegraph-graph/src/query/scoring.rs index 2c13d1fa..59c3dd18 100644 --- a/crates/codegraph-graph/src/query/scoring.rs +++ b/crates/codegraph-graph/src/query/scoring.rs @@ -652,6 +652,7 @@ pub fn kind_bonus(kind: NodeKind) -> f64 { NodeKind::Interface => 9.0, NodeKind::TypeAlias => 6.0, NodeKind::Struct => 6.0, + NodeKind::Union => 6.0, NodeKind::Trait => 9.0, NodeKind::Enum => 5.0, NodeKind::Component => 8.0, diff --git a/crates/codegraph-mcp/src/engine.rs b/crates/codegraph-mcp/src/engine.rs index 9a14efed..b418bdd5 100644 --- a/crates/codegraph-mcp/src/engine.rs +++ b/crates/codegraph-mcp/src/engine.rs @@ -49,9 +49,10 @@ const CALLABLE_KINDS: [NodeKind; 4] = [ /// Type node kinds a signature edge may point at — the rescue only surfaces /// these. Mirrors upstream `TYPE_KINDS` (`tools.ts:2621`). -const TYPE_KINDS: [NodeKind; 7] = [ +const TYPE_KINDS: [NodeKind; 8] = [ NodeKind::Class, NodeKind::Struct, + NodeKind::Union, NodeKind::Interface, NodeKind::Trait, NodeKind::Protocol, @@ -2853,6 +2854,7 @@ fn is_container(kind: NodeKind) -> bool { NodeKind::Class | NodeKind::Interface | NodeKind::Struct + | NodeKind::Union | NodeKind::Trait | NodeKind::Protocol | NodeKind::Enum @@ -2867,6 +2869,7 @@ fn is_meaningful_kind(kind: NodeKind) -> bool { | NodeKind::Class | NodeKind::Interface | NodeKind::Struct + | NodeKind::Union | NodeKind::Trait | NodeKind::Protocol | NodeKind::Enum diff --git a/crates/codegraph-resolve/src/context.rs b/crates/codegraph-resolve/src/context.rs index 54a2cc0b..acc9f218 100644 --- a/crates/codegraph-resolve/src/context.rs +++ b/crates/codegraph-resolve/src/context.rs @@ -198,9 +198,10 @@ impl ResolutionContext for StoreResolutionContext<'_> { fn get_supertypes(&self, type_name: &str, language: Language) -> Vec { // Union implements/extends targets of every same-named type node // (index.ts:425-442). - const SUPERTYPE_BEARING: [NodeKind; 6] = [ + const SUPERTYPE_BEARING: [NodeKind; 7] = [ NodeKind::Class, NodeKind::Struct, + NodeKind::Union, NodeKind::Interface, NodeKind::Trait, NodeKind::Protocol, diff --git a/crates/codegraph-resolve/src/import_resolver.rs b/crates/codegraph-resolve/src/import_resolver.rs index 05627117..6b4c21c6 100644 --- a/crates/codegraph-resolve/src/import_resolver.rs +++ b/crates/codegraph-resolve/src/import_resolver.rs @@ -1947,6 +1947,7 @@ fn is_static_member_container(kind: NodeKind) -> bool { kind, NodeKind::Class | NodeKind::Struct + | NodeKind::Union | NodeKind::Interface | NodeKind::Enum | NodeKind::Trait @@ -2213,6 +2214,7 @@ fn resolve_rust_path_reference( n.kind, NodeKind::Function | NodeKind::Struct + | NodeKind::Union | NodeKind::Enum | NodeKind::Trait | NodeKind::TypeAlias diff --git a/crates/codegraph-resolve/src/name_matcher.rs b/crates/codegraph-resolve/src/name_matcher.rs index 99130b50..b22d85c9 100644 --- a/crates/codegraph-resolve/src/name_matcher.rs +++ b/crates/codegraph-resolve/src/name_matcher.rs @@ -495,12 +495,13 @@ fn cpp_last_segment(name: &str) -> &str { .unwrap_or(name) } -/// Does the graph hold a class/struct named `name`'s last segment? +/// Does the graph hold a class/struct/union named `name`'s last segment? /// (`cppClassExists`, `name-matcher.ts:621-626`). fn cpp_class_exists(name: &str, reference: &RefView, context: &dyn ResolutionContext) -> bool { let last = cpp_last_segment(name); context.get_nodes_by_name(last).iter().any(|n| { - matches!(n.kind, NodeKind::Class | NodeKind::Struct) && n.language == reference.language + matches!(n.kind, NodeKind::Class | NodeKind::Struct | NodeKind::Union) + && n.language == reference.language }) } @@ -1436,7 +1437,7 @@ pub fn match_method_call( ) { if matches!( class_node.kind, - NodeKind::Class | NodeKind::Struct | NodeKind::Interface + NodeKind::Class | NodeKind::Struct | NodeKind::Union | NodeKind::Interface ) { if class_node.language != reference.language { continue; @@ -1462,7 +1463,7 @@ pub fn match_method_call( ) { if matches!( class_node.kind, - NodeKind::Class | NodeKind::Struct | NodeKind::Interface + NodeKind::Class | NodeKind::Struct | NodeKind::Union | NodeKind::Interface ) { if class_node.language != reference.language { continue; @@ -1867,7 +1868,7 @@ fn find_best_match<'a>(reference: &RefView, candidates: &'a [Node]) -> Option<&' EdgeKind::Instantiates => { if matches!( candidate.kind, - NodeKind::Class | NodeKind::Struct | NodeKind::Interface + NodeKind::Class | NodeKind::Struct | NodeKind::Union | NodeKind::Interface ) { score += 25.0; } diff --git a/crates/codegraph-resolve/src/resolver.rs b/crates/codegraph-resolve/src/resolver.rs index 44c8e3e3..f825dd13 100644 --- a/crates/codegraph-resolve/src/resolver.rs +++ b/crates/codegraph-resolve/src/resolver.rs @@ -1186,6 +1186,7 @@ impl ReferenceResolver { from_node.kind, NodeKind::Class | NodeKind::Struct + | NodeKind::Union | NodeKind::Interface | NodeKind::Trait | NodeKind::Protocol @@ -1371,7 +1372,10 @@ impl ReferenceResolver { // Promote calls → instantiates (index.ts:771-776). if kind == EdgeKind::Calls { if let Ok(Some(target_node)) = store.node_by_id(&reference.target_node_id) { - if matches!(target_node.kind, NodeKind::Class | NodeKind::Struct) { + if matches!( + target_node.kind, + NodeKind::Class | NodeKind::Struct | NodeKind::Union + ) { kind = EdgeKind::Instantiates; } } @@ -2055,6 +2059,7 @@ fn is_supertype_bearing_or_module(kind: NodeKind) -> bool { kind, NodeKind::Class | NodeKind::Struct + | NodeKind::Union | NodeKind::Interface | NodeKind::Trait | NodeKind::Protocol diff --git a/crates/codegraph-resolve/src/snapshot_context.rs b/crates/codegraph-resolve/src/snapshot_context.rs index a65143df..6a407612 100644 --- a/crates/codegraph-resolve/src/snapshot_context.rs +++ b/crates/codegraph-resolve/src/snapshot_context.rs @@ -268,9 +268,10 @@ impl ResolutionContext for SnapshotResolutionContext { // Union implements/extends targets of every same-named type node, // reading the per-chunk edge adjacency instead of the live store // (matches `StoreResolutionContext::get_supertypes`). - const SUPERTYPE_BEARING: [NodeKind; 6] = [ + const SUPERTYPE_BEARING: [NodeKind; 7] = [ NodeKind::Class, NodeKind::Struct, + NodeKind::Union, NodeKind::Interface, NodeKind::Trait, NodeKind::Protocol, diff --git a/crates/codegraph-resolve/src/types.rs b/crates/codegraph-resolve/src/types.rs index d0ee6b73..d6826c5f 100644 --- a/crates/codegraph-resolve/src/types.rs +++ b/crates/codegraph-resolve/src/types.rs @@ -43,12 +43,13 @@ pub fn is_esm_language(language: Language) -> bool { /// `namespace Foo {}` binds `Foo` as much as a `class Foo` does, which is why /// `Module`/`Namespace` belong here too. /// -/// Upstream's set carries 11 kinds including `union`; we have no -/// `NodeKind::Union` yet, so this is the other 10 and `Union` must join it when -/// the kind exists. -pub const TYPE_DECLARING_KINDS: [NodeKind; 10] = [ +/// Matches upstream's 11-kind set: `Union` joined it when `NodeKind::Union` was +/// added (PR #1516), because a C/C++/ObjC/Rust `union` declares a type name +/// exactly as a `struct` does. +pub const TYPE_DECLARING_KINDS: [NodeKind; 11] = [ NodeKind::Class, NodeKind::Struct, + NodeKind::Union, NodeKind::Interface, NodeKind::Trait, NodeKind::Protocol, @@ -389,7 +390,7 @@ mod tests { #[test] fn all_node_kinds_classified_against_supertype_and_import_sets() { - // Every one of the 22 kinds is classified explicitly, so a kind added + // Every one of the 23 kinds is classified explicitly, so a kind added // later cannot be silently omitted from either gate: the two expected // lists below are exhaustive and the assertion compares whole sets. let type_declaring: Vec = NodeKind::ALL @@ -409,8 +410,9 @@ mod tests { NodeKind::TypeAlias, NodeKind::Namespace, NodeKind::Component, + NodeKind::Union, ], - "10 supertype-eligible kinds — no `Union` yet, which Tier 3 must add" + "11 supertype-eligible kinds, `Union` among them since Tier 3" ); let non_importable: Vec = NodeKind::ALL @@ -430,7 +432,7 @@ mod tests { assert_eq!( NodeKind::ALL.len(), - 22, + 23, "kind count changed — revisit both sets" ); } diff --git a/crates/codegraph-resolve/tests/fixtures/tier3/instantiate_agg/instantiate_agg.cpp b/crates/codegraph-resolve/tests/fixtures/tier3/instantiate_agg/instantiate_agg.cpp new file mode 100644 index 00000000..78ad77d7 --- /dev/null +++ b/crates/codegraph-resolve/tests/fixtures/tier3/instantiate_agg/instantiate_agg.cpp @@ -0,0 +1,4 @@ +union Reg { int raw; float val; }; +struct Ctl { int id; }; +void mk_union() { Reg r = Reg(); (void)r; } +void mk_struct() { Ctl c = Ctl(); (void)c; } diff --git a/crates/codegraph-resolve/tests/fixtures/tier3/instantiate_rank/instantiate_rank.cpp b/crates/codegraph-resolve/tests/fixtures/tier3/instantiate_rank/instantiate_rank.cpp new file mode 100644 index 00000000..bc8fdc46 --- /dev/null +++ b/crates/codegraph-resolve/tests/fixtures/tier3/instantiate_rank/instantiate_rank.cpp @@ -0,0 +1,5 @@ +union Value { int i; float f; }; +struct Packet { int id; }; +void Value() { } +void ctor_union() { Value v{1}; (void)v; } +void ctor_struct() { Packet p{2}; (void)p; } diff --git a/crates/codegraph-resolve/tests/fixtures/tier3/union_method/union_agg.cpp b/crates/codegraph-resolve/tests/fixtures/tier3/union_method/union_agg.cpp new file mode 100644 index 00000000..1f6b690e --- /dev/null +++ b/crates/codegraph-resolve/tests/fixtures/tier3/union_method/union_agg.cpp @@ -0,0 +1,10 @@ +union WithMethod { + int i; float f; + int read_field() { return i; } +}; +struct SWithMethod { + int i; + int read_field() { return i; } +}; +void drive_union() { WithMethod w; w.read_field(); } +void drive_struct() { SWithMethod s; s.read_field(); } diff --git a/crates/codegraph-resolve/tests/tier3_union_edges.rs b/crates/codegraph-resolve/tests/tier3_union_edges.rs new file mode 100644 index 00000000..22b2d848 --- /dev/null +++ b/crates/codegraph-resolve/tests/tier3_union_edges.rs @@ -0,0 +1,277 @@ +//! Tier 3 union-reachability regression tests (upstream PR #1516, `e922563`). +//! +//! A `union` node nothing points at would be worse than no union node at all, so +//! each test here drives the FULL extract → resolve pipeline over a committed +//! fixture under `tests/fixtures/tier3/` and asserts an edge REACHES the union — +//! and, where a wrong edge existed before, that the wrong edge is GONE. Both +//! directions, because "the right edge appeared" alone cannot notice that the +//! false one survived beside it. +//! +//! The three cases exercise three INDEPENDENT code paths, each with its own +//! same-shaped struct control: +//! * `instantiate_agg` — `resolver.rs`'s `Calls` → `Instantiates` promotion +//! * `instantiate_rank` — `name_matcher.rs`'s `Instantiates` candidate bonus +//! * `union_method` — `name_matcher.rs`'s `matchMethodCall` candidate kinds +//! +//! They are separate fixtures on purpose: one file mixing the mechanisms would +//! make every isolated revert-proof ambiguous. +//! +//! Fixtures are read in place and never written to; the store lives in a temp +//! file, so the worktree stays clean. + +use std::path::{Path, PathBuf}; + +use codegraph_core::types::{Edge, EdgeKind, FileRecord, Node, NodeKind}; +use codegraph_extract::{detect_language, extract_file}; +use codegraph_resolve::ReferenceResolver; +use codegraph_store::Store; + +fn fixture_root(name: &str) -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests") + .join("fixtures") + .join("tier3") + .join(name) +} + +fn temp_db_path(test_name: &str) -> PathBuf { + let mut path = std::env::temp_dir(); + let nanos = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .expect("clock after epoch") + .as_nanos(); + path.push(format!( + "codegraph-tier3-{test_name}-{}-{nanos}.db", + std::process::id() + )); + path +} + +fn fixture_files(root: &Path) -> Vec { + let mut out = Vec::new(); + for entry in std::fs::read_dir(root).expect("read fixture dir") { + let path = entry.expect("dir entry").path(); + if let Ok(relative) = path.strip_prefix(root) { + out.push(relative.to_string_lossy().replace('\\', "/")); + } + } + out.sort(); + out +} + +struct Resolved { + store: Store, + edges: Vec, + refs: Vec, +} + +impl Resolved { + fn node(&self, id: &str) -> Node { + self.store + .node_by_id(id) + .expect("node lookup") + .expect("node exists") + } + + /// The single node of `kind` named `name`. Panics on 0 or >1, so a fixture + /// that stops producing the node fails loudly instead of silently skipping. + fn only(&self, kind: NodeKind, name: &str) -> Node { + let mut found: Vec = self + .store + .nodes_by_name(name) + .expect("nodes by name") + .into_iter() + .filter(|n| n.kind == kind) + .collect(); + assert_eq!( + found.len(), + 1, + "want exactly one {kind:?} named {name}, got {found:?}" + ); + found.pop().expect("checked len") + } + + /// `(edge kind, "targetkind:targetname")` for every non-`Contains` edge out + /// of `source_id`. + fn out_of(&self, source_id: &str) -> Vec<(EdgeKind, String)> { + let mut rows: Vec<(EdgeKind, String)> = self + .edges + .iter() + .filter(|e| e.source == source_id) + .map(|e| { + let t = self.node(&e.target); + (e.kind, format!("{:?}:{}", t.kind, t.name)) + }) + .collect(); + rows.sort_by(|a, b| format!("{a:?}").cmp(&format!("{b:?}"))); + rows + } +} + +fn resolve_fixture(name: &str) -> Resolved { + let root = fixture_root(name); + assert!(root.is_dir(), "missing committed fixture {name}"); + let relative = fixture_files(&root); + assert!(!relative.is_empty(), "fixture {name} has no files"); + + let mut store = Store::open(&temp_db_path(name)).expect("open store"); + for path in &relative { + let language = detect_language(path); + let result = extract_file(&root, path).expect("extract file"); + store + .upsert_file(&FileRecord { + path: path.clone(), + content_hash: "fixture".to_string(), + language, + size: 0, + modified_at: 0, + indexed_at: 0, + node_count: result.nodes.len() as i64, + errors: Vec::new(), + }) + .expect("upsert file"); + store.upsert_nodes(&result.nodes).expect("upsert nodes"); + store + .insert_edges(&result.edges) + .expect("insert contains edges"); + store + .insert_unresolved_refs(&result.unresolved_references) + .expect("insert unresolved refs"); + } + + let root_str = root.to_string_lossy().to_string(); + let mut resolver = ReferenceResolver::new(root_str.clone()); + { + let context = codegraph_resolve::StoreResolutionContext::new(&store, &root_str); + resolver.initialize(&context); + } + resolver + .resolve_and_persist(&mut store) + .expect("resolve and persist"); + + let mut edges = Vec::new(); + for kind in NodeKind::ALL { + for node in store.nodes_by_kind(kind).expect("nodes by kind") { + for edge in store + .edges_by_source_kind(&node.id, None) + .expect("edges by source") + { + if edge.kind != EdgeKind::Contains { + edges.push(edge); + } + } + } + } + let refs = store + .all_unresolved_refs() + .expect("all unresolved refs") + .into_iter() + .map(|r| format!("{:?}|{}", r.reference_kind, r.reference_name)) + .collect(); + Resolved { store, edges, refs } +} + +#[test] +fn cpp_union_call_construction_is_promoted_to_instantiates() { + // Given `Reg r = Reg();` where `Reg` is a union and the ONLY node of that + // name, and `Ctl c = Ctl();` as the struct control, + // When the pipeline resolves, + // Then the union's ref — extracted as `Calls`, measured PRE-FIX as a DANGLING + // unresolved ref because no union node existed to bind — both resolves and is + // promoted to `Instantiates`, leaving NO `Calls` edge behind. + let g = resolve_fixture("instantiate_agg"); + let mk_union = g.only(NodeKind::Function, "mk_union"); + let out = g.out_of(&mk_union.id); + + assert!( + out.contains(&(EdgeKind::Instantiates, "Union:Reg".to_string())), + "the union construction must be promoted to instantiates: {out:?}" + ); + assert!( + !out.iter().any(|(kind, _)| *kind == EdgeKind::Calls), + "a Calls edge must NOT survive the promotion: {out:?}" + ); + assert!( + !g.refs.iter().any(|r| r == "Calls|Reg"), + "the `Reg` ref must no longer be dangling: {:?}", + g.refs + ); + + let mk_struct = g.only(NodeKind::Function, "mk_struct"); + assert!( + g.out_of(&mk_struct.id) + .contains(&(EdgeKind::Instantiates, "Struct:Ctl".to_string())), + "the struct control regressed: {:?}", + g.out_of(&mk_struct.id) + ); +} + +#[test] +fn cpp_union_wins_instantiates_ranking_over_a_same_named_function() { + // Given `Value v{1};` — a brace construction, so the ref is extracted as + // `Instantiates` — competing against a SAME-NAMED `void Value()`, + // When the pipeline ranks the candidates, + // Then the `+25` aggregate bonus makes the union win. Measured PRE-FIX this + // bound `function:Value`, the WRONG target, so the assertion is stated in both + // directions: the union is hit and the function is not touched at all. + let g = resolve_fixture("instantiate_rank"); + let ctor_union = g.only(NodeKind::Function, "ctor_union"); + let out = g.out_of(&ctor_union.id); + + assert!( + out.contains(&(EdgeKind::Instantiates, "Union:Value".to_string())), + "the union must win the Instantiates ranking: {out:?}" + ); + assert!( + !out.iter().any(|(_, target)| target == "Function:Value"), + "no edge may reach the same-named function: {out:?}" + ); + + let ctor_struct = g.only(NodeKind::Function, "ctor_struct"); + assert!( + g.out_of(&ctor_struct.id) + .contains(&(EdgeKind::Instantiates, "Struct:Packet".to_string())), + "the struct control regressed: {:?}", + g.out_of(&ctor_struct.id) + ); +} + +#[test] +fn cpp_union_method_call_binds_the_union_not_the_struct() { + // Given a union and a struct in one file that each define `read_field`, and + // one INSTANCE call on each receiver, + // When the pipeline resolves the method calls, + // Then each binds its OWN receiver's member. Measured PRE-FIX: the union had + // no node, so its member was a free function and `w.read_field()` bound + // `SWithMethod::read_field` — a false edge to the wrong type, not merely a + // missing one. Receiver type has to decide, since the names are identical. + // + // The load-bearing fix here is the EXTRACTION-side `is_inside_class_like_node` + // widening, which makes the member a `method` owned by the union; reverting it + // alone reproduces the false edge. Reverting either `match_method_call` + // candidate filter does NOT: receiver-type inference resolves this shape + // before that strategy runs. Three other shapes were tried and each is + // claimed by an earlier path too — a Rust `Bits::raw(b)` by exact + // qualified-name matching, and a C++ `Cfg::probe()` never even reaches the + // resolver as a qualified ref because the extractor emits the bare `probe`. + // So `match_method_call`'s union widening is a symmetric port hunk with no + // reachable fixture in this tree; it is compile-verified, not behaviour-proven. + let g = resolve_fixture("union_method"); + for (caller, want_owner) in [ + ("drive_union", "WithMethod::read_field"), + ("drive_struct", "SWithMethod::read_field"), + ] { + let from = g.only(NodeKind::Function, caller); + let bound: Vec = g + .edges + .iter() + .filter(|e| e.source == from.id && e.kind == EdgeKind::Calls) + .map(|e| g.node(&e.target).qualified_name) + .collect(); + assert_eq!( + bound, + vec![want_owner.to_string()], + "{caller} must bind exactly {want_owner}" + ); + } +} diff --git a/crates/codegraph-store/src/index_state.rs b/crates/codegraph-store/src/index_state.rs index 09f0568d..0bfb9f3f 100644 --- a/crates/codegraph-store/src/index_state.rs +++ b/crates/codegraph-store/src/index_state.rs @@ -115,7 +115,7 @@ pub const CURRENT_STORAGE_PROTOCOL: u64 = 2; /// The extraction-pipeline version this binary produces. This is the single /// source of truth: no other crate may define its own copy. -pub const CURRENT_EXTRACTION_VERSION: u64 = 6; +pub const CURRENT_EXTRACTION_VERSION: u64 = 7; /// The `project_metadata` key under which a built index records the extraction /// version it was produced with. Single source of truth for the key spelling. diff --git a/crates/codegraph-store/src/queries.rs b/crates/codegraph-store/src/queries.rs index fec11174..bc972211 100644 --- a/crates/codegraph-store/src/queries.rs +++ b/crates/codegraph-store/src/queries.rs @@ -1706,6 +1706,7 @@ fn parse_node_kind(value: String) -> rusqlite::Result { "export" => NodeKind::Export, "route" => NodeKind::Route, "component" => NodeKind::Component, + "union" => NodeKind::Union, _ => return Err(enum_error(value, "node kind")), }; Ok(kind) @@ -1982,6 +1983,24 @@ mod tests { ); } + #[test] + fn union_node_round_trips_kind_through_sqlite() { + // `parse_node_kind` is a string match with a rejecting `_` arm, so a new + // NodeKind that extraction can WRITE but this cannot READ fails only at + // runtime, with `unknown node kind: union`. The extractor never round-trips + // through SQLite, so no extraction test can catch that. + let mut store = store("union-round-trip"); + store.upsert_file(&file("src/bits.rs")).unwrap(); + let mut inserted = node("union:bits", "Bits", "src/bits.rs"); + inserted.kind = NodeKind::Union; + + store.upsert_nodes(std::slice::from_ref(&inserted)).unwrap(); + + let read_back = store.node_by_id("union:bits").unwrap(); + assert_eq!(read_back, Some(inserted.clone())); + assert_eq!(read_back.unwrap().kind, NodeKind::Union); + } + #[test] fn gdscript_node_round_trips_language_through_sqlite() { let mut store = store("gdscript-round-trip"); diff --git a/crates/codegraph-store/tests/index_state.rs b/crates/codegraph-store/tests/index_state.rs index 0da480ae..6493cb72 100644 --- a/crates/codegraph-store/tests/index_state.rs +++ b/crates/codegraph-store/tests/index_state.rs @@ -119,7 +119,7 @@ fn assert_corrupt( fn index_state_constants_and_canonical_payload_are_exact() { /// The extraction version the immediately preceding release wrote. Read from /// `index_state.rs` at implementation time; see plan decision C1 step 0. - const PREVIOUS_EXTRACTION_VERSION: u64 = 5; + const PREVIOUS_EXTRACTION_VERSION: u64 = 6; assert_eq!(CURRENT_STORAGE_PROTOCOL, 2); assert_eq!(CURRENT_EXTRACTION_VERSION, PREVIOUS_EXTRACTION_VERSION + 1); diff --git a/docs/equivalence.md b/docs/equivalence.md index 2850e097..172f0503 100644 --- a/docs/equivalence.md +++ b/docs/equivalence.md @@ -422,10 +422,74 @@ A further file exercises the Batch B explicit-operator gain (upstream #1268): `instance-method` at confidence 0.9 (`Vec2::operator+` twice, `Vec2::operator[]`, `Vec2::get`). +Seven further files exercise the Tier 3 aggregate work — MSVC COM `interface` +(upstream #1519) and first-class `union` nodes (upstream PR #1516). **This corpus +is the C-FAMILY corpus, not a strictly-C++ one**: it already held a `.c` file, and +Tier 3 adds a `.mm` file whose extension maps to the ObjC spec, so `cpp/` names the +family rather than the dialect. + +- **MSVC COM `interface` positives** — `com_interface.hpp` carries `struct SControl` + as the control plus three `interface` shapes (`IWidget : IBase` with a base clause, + `IPlain` without one, and `INewlineBrace` with the brace on the next line). The + keyword is not C++, so tree-sitter reads each as a `function_definition`: the + container became a `function`, its member `Run` a free `function` instead of a + `method`, and the base clause vanished. The offset-preserving pre-parse rewrites + the line-leading keyword to `struct` + 3 spaces (9 bytes → 9 bytes, so every line + and column is unchanged), and the golden now pins all three as `struct` with + `IWidget::Run` a `method` and TWO `extends IBase` refs. `int interface_count = 0;` + is the mid-line negative in the same file. +- **MSVC COM `interface` negatives** — `neg_interface.hpp` holds the five shapes the + guard must DECLINE, and pins them by extraction-INVARIANCE rather than by "the + substitution did not fire": a block comment containing `interface INegComment;`, a + C++/CLI `interface class`, an `interface struct`, a raw string containing a full + `interface INegGhost {…};` declaration, and a `#define` continuation line carrying + `interface INegMacro`. The golden pins exactly THREE nodes, the sharpest value + being `INegCli`'s `docstring` — the verbatim `interface INegComment;`. A + comment-blind substitution rewrites that string to `struct INegComment;`, which + is how a leaking guard is caught. `INegCli`/`INegStructKw` staying `function` is + pre-existing garbage from the C++/CLI misparse and is deliberately preserved. +- **C union** — `union_agg.c` (the second `.c` file, so the C walker is under test) + covers `union Named` plus both `typedef union` RE-KINDS (`AnonU` and `NamedU` were + `type_alias` before and are `union` now — node ids change), with `struct Ctl` / + `AnonS` as controls and three negatives: `union Fwd;` (bodiless forward + declaration, stays unindexed, `struct FwdS;` as its control) and + `union { int q; } anon_var;` (anonymous, mints nothing, as the anonymous struct + already did). `typedef union NamedTag { … } NamedU;` mints exactly ONE node named + `NamedU`; the tag never becomes a node. +- **C++ union member method** — `union_agg.cpp` gives `union WithMethod` and + `struct SWithMethod` a SAME-NAMED `read_field`, plus one call on each receiver. + Before the fix the union's member leaked to file scope as a free `function`, so + `w.read_field()` bound `SWithMethod::read_field` — a FALSE edge to the wrong type, + not merely a missing one. The golden pins each call on its own receiver's member, + so receiver type has to decide. +- **ObjC union** — `union_agg.mm` is the repo's ONLY Objective-C fixture (`.mm` maps + to the ObjC spec). It pins `union ObjcU` beside `struct ObjcS`. +- **`Calls` → `Instantiates` promotion** — `instantiate_agg.cpp` has `Reg r = Reg();` + where the union is the only node of that name (measured pre-fix: a DANGLING `calls +Reg` ref, because no union node existed to bind), with `Ctl c = Ctl();` as the + control. The golden pins `instantiates mk_union -> union:Reg` and NO surviving + `calls` edge. +- **`Instantiates` candidate ranking** — `instantiate_rank.cpp` has `Value v{1};` + competing against a same-named `void Value()`. Measured pre-fix it bound + `function:Value`, the WRONG target; the golden pins the union winning, with + `Packet p{2};` as the control. Kept in a SEPARATE file from the promotion case on + purpose: one file mixing both mechanisms would make either revert-proof ambiguous. + +**Why the union/struct members are named `read_field` and not `get`.** `get` is the +only duplicated symbol name in this corpus already (`operators.cpp:5` `Vec2::get` +and `template_method.cpp:12` `Box::get`), and one of those carries a live +2-candidate `calls` edge. Naming the new members `get` would take that candidate set +to four and put an existing, unrelated golden edge at risk of re-pointing — drift in +files this change has no business touching. `read_field` keeps the property that +matters (two same-named members inside the new file, so receiver type must +disambiguate) and drops the one that only adds risk. + The minimal source corpus lives at `crates/codegraph-bench/fixtures/cpp/` -(`attr_macro.c`, `base.hpp`, `derived.cpp`, `namespaced.cpp`, -`namespaced_member.cpp`, `namespaced_member.hpp`, `operators.cpp`, -`template_method.cpp`, `templated_call.cpp`, `ue_actor.h`). The inheritance base +(`attr_macro.c`, `base.hpp`, `com_interface.hpp`, `derived.cpp`, +`instantiate_agg.cpp`, `instantiate_rank.cpp`, `namespaced.cpp`, +`namespaced_member.cpp`, `namespaced_member.hpp`, `neg_interface.hpp`, +`operators.cpp`, `template_method.cpp`, `templated_call.cpp`, `ue_actor.h`, +`union_agg.c`, `union_agg.cpp`, `union_agg.mm` — 17 files). The inheritance base classes live in a `.hpp` file (not `.h`, which maps to `Language::C` by extension); `ue_actor.h` deliberately uses `.h` to guard the content-based C++ reclassification, and `attr_macro.c` uses `.c` so the @@ -456,6 +520,54 @@ Like the Ruby fixture, both the index and the dump are byte-stable, and the `cpp_db_is_self_equivalent_to_cpp_golden` tests in `crates/codegraph-bench/tests/equivalence.rs` enforce it. +### Rust fixture + +`reference/golden/rust/` guards the two Tier 3 items that need Rust source, which +no other corpus could reach — before it there was no `.rs` file anywhere under +`crates/codegraph-bench/fixtures/`: + +- **unit structs are indexed** (upstream #1513 / PR #1514) — `lib.rs` declares + `struct UnitStruct;` beside `BraceStruct { … }` and `TupleStruct(u8)`, and gives + all three an `impl Greet for`. A bodiless `struct NAME;` is a COMPLETE definition + in Rust, not a forward declaration, so before the fix the unit struct produced no + node at all — and its `implements` edge went with it, leaving `UnitStruct::greet` + an orphan naming a type the graph did not contain. The golden pins exactly three + `struct` nodes and **four** `implements` edges (three structs + the union). +- **`union` is a first-class kind** (upstream PR #1516) — `union Bits` carries an + inherent `impl` (`raw`) and a trait `impl` (`greet`). The golden pins `union:Bits` + with `contains union:Bits -> method:raw`, `contains union:Bits -> method:greet` and + `implements union:Bits -> trait:Greet`. +- **cross-file resolution** — `consumer.rs` calls `u.greet()` / `b.greet()` on a + `&UnitStruct` and a `&Bits`, so `implements` and method resolution have to work + across files rather than only within one. + +**The Rust corpus deliberately makes NO instantiation claim.** An `instantiates` edge +fires only for the CALL-EXPRESSION construction form: `TupleStruct(2)` yes, a bare +path `UnitStruct` no, a struct literal `Bits { i: 0 }` no. A Rust union is +constructible only as `Bits { … }`, so no Rust union can ever emit that edge — +`make_unit` / `make_bits` are return-type references, not instantiation assertions, +and the golden carries zero `instantiates` edges. Instantiation is pinned in C++ +instead (`instantiate_agg.cpp` / `instantiate_rank.cpp`), which is upstream's own +shape. The corpus carries **no `Cargo.toml`**: it is indexed, not compiled, and a +manifest inside the workspace tree could confuse `cargo`. + +Regenerate reproducibly (identical recipe to the C++ fixture, substituting `rust`): + +```bash +mkdir -p reference/golden/rust +rm -rf /tmp/cg-fixture-rust +cp -r crates/codegraph-bench/fixtures/rust /tmp/cg-fixture-rust +cargo build --release -p codegraph-rs +CODEGRAPH_NO_DAEMON=1 CODEGRAPH_NO_WATCH=1 \ + ./target/release/codegraph init /tmp/cg-fixture-rust +cp /tmp/cg-fixture-rust/.codegraph/codegraph.db reference/golden/rust/colby.db +cargo run -p codegraph-bench --bin bench -- \ + --gen-golden reference/golden/rust/colby.db reference/golden/rust +``` + +`generated_golden_matches_committed_rust_fixture` and +`rust_db_is_self_equivalent_to_rust_golden` enforce byte-stability. + ### Metal fixture A fifth golden fixture, `reference/golden/metal/`, guards Metal Shading Language diff --git a/reference/golden/cpp/colby.db b/reference/golden/cpp/colby.db index 45edc05b..6e558a3a 100644 Binary files a/reference/golden/cpp/colby.db and b/reference/golden/cpp/colby.db differ diff --git a/reference/golden/cpp/edges.json b/reference/golden/cpp/edges.json index 76282c41..9db3af11 100644 --- a/reference/golden/cpp/edges.json +++ b/reference/golden/cpp/edges.json @@ -155,6 +155,78 @@ "source": "class:1f9695d61900e851f6609231a60ccd9a", "target": "class:e436be77a00102552decf9de5d7cc052" }, + { + "col": 21, + "kind": "instantiates", + "line": 4, + "metadata": { + "confidence": 0.4, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "function:11828c01c4fcb2dfca7b6d330852fb2f", + "target": "union:613e56ffd95a092fdcb8cb389be3e17d" + }, + { + "col": 21, + "kind": "instantiates", + "line": 5, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "function:22779c7ef8b93c5a53baefaca5b875ec", + "target": "struct:860b4dfc2d8e87f389dbeb7e3370cac2" + }, + { + "col": 27, + "kind": "instantiates", + "line": 3, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "function:4dccaf3de3a587133eff8059afc5fe3b", + "target": "union:a2d1fd60ce557850c54ea94728f0d587" + }, + { + "col": 27, + "kind": "instantiates", + "line": 4, + "metadata": { + "confidence": 0.4, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "function:a16b7e532610cf732865db2029f22026", + "target": "struct:56b403b06683b2fb3f6682df6301cba3" + }, + { + "col": 37, + "kind": "calls", + "line": 10, + "metadata": { + "confidence": 0.9, + "resolvedBy": "instance-method" + }, + "provenance": null, + "source": "function:8f2000822dd901aada3e0c5e902274fb", + "target": "method:05778772a7074d234e86f89aae6b8fd4" + }, + { + "col": 37, + "kind": "calls", + "line": 9, + "metadata": { + "confidence": 0.9, + "resolvedBy": "instance-method" + }, + "provenance": null, + "source": "function:2ae5d01268ba71490a736bc108e76245", + "target": "method:715248b9cda9caac9e3841d433bd5ef2" + }, { "col": 4, "kind": "calls", @@ -362,6 +434,42 @@ "source": "file:base.hpp", "target": "class:e436be77a00102552decf9de5d7cc052" }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:com_interface.hpp", + "target": "struct:3968c80a1532766ec076463fa574d507" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:com_interface.hpp", + "target": "struct:5009f722baa64c277a025aa26625b3dd" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:com_interface.hpp", + "target": "struct:7c06a13aa42a9d9b3bc5b16852f42d10" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:com_interface.hpp", + "target": "struct:f8ed8b93742d867912fe2dd218c2819e" + }, { "col": null, "kind": "contains", @@ -416,6 +524,87 @@ "source": "file:derived.cpp", "target": "struct:418731e230da99cc3237d0e7e35385f1" }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_agg.cpp", + "target": "function:4dccaf3de3a587133eff8059afc5fe3b" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_agg.cpp", + "target": "function:a16b7e532610cf732865db2029f22026" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_agg.cpp", + "target": "struct:56b403b06683b2fb3f6682df6301cba3" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_agg.cpp", + "target": "union:a2d1fd60ce557850c54ea94728f0d587" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_rank.cpp", + "target": "function:11828c01c4fcb2dfca7b6d330852fb2f" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_rank.cpp", + "target": "function:22779c7ef8b93c5a53baefaca5b875ec" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_rank.cpp", + "target": "function:e5f5a61a0bbee32c1ff58badf9189a8a" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_rank.cpp", + "target": "struct:860b4dfc2d8e87f389dbeb7e3370cac2" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:instantiate_rank.cpp", + "target": "union:613e56ffd95a092fdcb8cb389be3e17d" + }, { "col": null, "kind": "contains", @@ -479,6 +668,33 @@ "source": "file:namespaced_member.hpp", "target": "class:2e7e24e7488b3868c5b2924a018549c9" }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:neg_interface.hpp", + "target": "function:44427549a820cd14e23ed35cf868c40b" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:neg_interface.hpp", + "target": "function:ff4411379b691a6c177968baf5751651" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:neg_interface.hpp", + "target": "struct:9bd27f85c031e707e087a6add300d143" + }, { "col": null, "kind": "contains", @@ -578,6 +794,123 @@ "source": "file:ue_actor.h", "target": "class:ade92bd69bacb920c05c0d123d2a5130" }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.c", + "target": "function:05c9d179ecb1608cc56fb556b6cdf3e7" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.c", + "target": "struct:43b6e695f93a9ab87d1106a7d5b2a4ca" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.c", + "target": "struct:9a7a504b38e595f1a2d8030cdd4ff5c2" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.c", + "target": "union:43de8da9a133883a87808eeb4ec391be" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.c", + "target": "union:585e8a9d12fd43888a0e3ba79274d877" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.c", + "target": "union:9189436be51568f4955e50e2435c9b00" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.cpp", + "target": "function:2ae5d01268ba71490a736bc108e76245" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.cpp", + "target": "function:8f2000822dd901aada3e0c5e902274fb" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.cpp", + "target": "struct:3f0a102a7fa58ace6484079ab8820207" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.cpp", + "target": "union:07d2cc76b74099c2a3b894086faa18c7" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.mm", + "target": "struct:94f6722864eceb3ce91cb0ad43c60444" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:union_agg.mm", + "target": "union:e37aaff4aa26c664b0b839456f0024e1" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:3f0a102a7fa58ace6484079ab8820207", + "target": "method:05778772a7074d234e86f89aae6b8fd4" + }, { "col": null, "kind": "contains", @@ -587,6 +920,15 @@ "source": "struct:418731e230da99cc3237d0e7e35385f1", "target": "method:eaf644a1dae18b22184dd0d0b882e1bd" }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:5009f722baa64c277a025aa26625b3dd", + "target": "method:d039853bf1b1d17f861ce23c69804568" + }, { "col": null, "kind": "contains", @@ -613,5 +955,23 @@ "provenance": null, "source": "struct:a79c39917f9987d43250fce7bde68405", "target": "method:533a20574d92cc309a832441bc372dbc" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:f8ed8b93742d867912fe2dd218c2819e", + "target": "method:bcd194fb631c427de05b59f0f228f0e4" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "union:07d2cc76b74099c2a3b894086faa18c7", + "target": "method:715248b9cda9caac9e3841d433bd5ef2" } ] diff --git a/reference/golden/cpp/files.json b/reference/golden/cpp/files.json index 239fad0d..0b31b98c 100644 --- a/reference/golden/cpp/files.json +++ b/reference/golden/cpp/files.json @@ -15,6 +15,14 @@ "path": "base.hpp", "size": 270 }, + { + "content_hash": "6b55a06389ed10d1d23bcab95a9ae02421e1cf0aa566526df2f367e29270e7c2", + "errors": null, + "language": "cpp", + "node_count": 7, + "path": "com_interface.hpp", + "size": 294 + }, { "content_hash": "7866bdbba877acfa0b4b8e7e4be58875893da925ac91aa333a4c3658bea64e69", "errors": null, @@ -23,6 +31,22 @@ "path": "derived.cpp", "size": 363 }, + { + "content_hash": "e3331a39e14456236ae24d3d0cc31562b65008bf1027a065d8f403066d74a46e", + "errors": null, + "language": "cpp", + "node_count": 5, + "path": "instantiate_agg.cpp", + "size": 151 + }, + { + "content_hash": "5d9bf2ad4d29787d69c168a79c0efb471614f5996f9b065b206da7170bc0fe70", + "errors": null, + "language": "cpp", + "node_count": 6, + "path": "instantiate_rank.cpp", + "size": 167 + }, { "content_hash": "bfd6da256b748444e2bfdff365e7d56daa640afa638e50b294db94cca1f2a7f8", "errors": null, @@ -47,6 +71,14 @@ "path": "namespaced_member.hpp", "size": 106 }, + { + "content_hash": "e934b42dfe376e8b29355a6ed84d713d44ba9b6f898df4d774f6bda378562bb3", + "errors": null, + "language": "cpp", + "node_count": 4, + "path": "neg_interface.hpp", + "size": 270 + }, { "content_hash": "61ac8b93b7094d0633203791513f3394c7f76e2993a50d75b9f8e32454dcccf6", "errors": null, @@ -78,5 +110,29 @@ "node_count": 2, "path": "ue_actor.h", "size": 191 + }, + { + "content_hash": "fd0d7579d620457505815a1d6829820f5512859858153568086bdebddcd0ead2", + "errors": null, + "language": "c", + "node_count": 7, + "path": "union_agg.c", + "size": 278 + }, + { + "content_hash": "d0f696b07337c1d1fcda49b0222d9b43a5c45a3932ff58cee2cd87b8d68caf53", + "errors": null, + "language": "cpp", + "node_count": 7, + "path": "union_agg.cpp", + "size": 257 + }, + { + "content_hash": "96f43a0f8244169fcc8281ef0f62de430a43436f39853e254ec27a840ccbe7c7", + "errors": null, + "language": "objc", + "node_count": 3, + "path": "union_agg.mm", + "size": 58 } ] diff --git a/reference/golden/cpp/nodes.json b/reference/golden/cpp/nodes.json index 544c11ea..25709e6c 100644 --- a/reference/golden/cpp/nodes.json +++ b/reference/golden/cpp/nodes.json @@ -285,6 +285,28 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 21, + "file_path": "com_interface.hpp", + "id": "file:com_interface.hpp", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "cpp", + "name": "com_interface.hpp", + "qualified_name": "com_interface.hpp", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -307,6 +329,50 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 5, + "file_path": "instantiate_agg.cpp", + "id": "file:instantiate_agg.cpp", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "cpp", + "name": "instantiate_agg.cpp", + "qualified_name": "instantiate_agg.cpp", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 6, + "file_path": "instantiate_rank.cpp", + "id": "file:instantiate_rank.cpp", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "cpp", + "name": "instantiate_rank.cpp", + "qualified_name": "instantiate_rank.cpp", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -373,6 +439,28 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 12, + "file_path": "neg_interface.hpp", + "id": "file:neg_interface.hpp", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "cpp", + "name": "neg_interface.hpp", + "qualified_name": "neg_interface.hpp", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -461,6 +549,116 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 10, + "file_path": "union_agg.c", + "id": "file:union_agg.c", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "c", + "name": "union_agg.c", + "qualified_name": "union_agg.c", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 11, + "file_path": "union_agg.cpp", + "id": "file:union_agg.cpp", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "cpp", + "name": "union_agg.cpp", + "qualified_name": "union_agg.cpp", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 3, + "file_path": "union_agg.mm", + "id": "file:union_agg.mm", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "objc", + "name": "union_agg.mm", + "qualified_name": "union_agg.mm", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 47, + "end_line": 9, + "file_path": "union_agg.c", + "id": "function:05c9d179ecb1608cc56fb556b6cdf3e7", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "c", + "name": "read_named", + "qualified_name": "read_named", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 9, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 44, + "end_line": 4, + "file_path": "instantiate_rank.cpp", + "id": "function:11828c01c4fcb2dfca7b6d330852fb2f", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "ctor_union", + "qualified_name": "ctor_union", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 4, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -483,6 +681,28 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 44, + "end_line": 5, + "file_path": "instantiate_rank.cpp", + "id": "function:22779c7ef8b93c5a53baefaca5b875ec", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "ctor_struct", + "qualified_name": "ctor_struct", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -505,6 +725,72 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 54, + "end_line": 9, + "file_path": "union_agg.cpp", + "id": "function:2ae5d01268ba71490a736bc108e76245", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "drive_union", + "qualified_name": "drive_union", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 9, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 40, + "end_line": 5, + "file_path": "neg_interface.hpp", + "id": "function:44427549a820cd14e23ed35cf868c40b", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "INegStructKw", + "qualified_name": "INegStructKw", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 45, + "end_line": 3, + "file_path": "instantiate_agg.cpp", + "id": "function:4dccaf3de3a587133eff8059afc5fe3b", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "mk_union", + "qualified_name": "mk_union", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -637,6 +923,28 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 54, + "end_line": 10, + "file_path": "union_agg.cpp", + "id": "function:8f2000822dd901aada3e0c5e902274fb", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "drive_struct", + "qualified_name": "drive_struct", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 10, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -684,22 +992,44 @@ { "decorators": null, "docstring": null, - "end_column": 1, - "end_line": 7, - "file_path": "attr_macro.c", - "id": "function:a424497bfe1ede5cb33b9d2d07d055de", + "end_column": 45, + "end_line": 4, + "file_path": "instantiate_agg.cpp", + "id": "function:a16b7e532610cf732865db2029f22026", "is_abstract": 0, "is_async": 0, "is_exported": 0, "is_static": 0, "kind": "function", - "language": "c", - "name": "GoodName", - "qualified_name": "GoodName", - "return_type": "VOID", + "language": "cpp", + "name": "mk_struct", + "qualified_name": "mk_struct", + "return_type": null, "signature": null, - "start_column": 9, - "start_line": 6, + "start_column": 0, + "start_line": 4, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 7, + "file_path": "attr_macro.c", + "id": "function:a424497bfe1ede5cb33b9d2d07d055de", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "c", + "name": "GoodName", + "qualified_name": "GoodName", + "return_type": "VOID", + "signature": null, + "start_column": 9, + "start_line": 6, "type_parameters": null, "visibility": null }, @@ -747,6 +1077,50 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 16, + "end_line": 3, + "file_path": "instantiate_rank.cpp", + "id": "function:e5f5a61a0bbee32c1ff58badf9189a8a", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "Value", + "qualified_name": "Value", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": "interface INegComment;", + "end_column": 55, + "end_line": 4, + "file_path": "neg_interface.hpp", + "id": "function:ff4411379b691a6c177968baf5751651", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "INegCli", + "qualified_name": "INegCli", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 4, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -813,6 +1187,28 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 34, + "end_line": 7, + "file_path": "union_agg.cpp", + "id": "method:05778772a7074d234e86f89aae6b8fd4", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "cpp", + "name": "read_field", + "qualified_name": "SWithMethod::read_field", + "return_type": null, + "signature": null, + "start_column": 4, + "start_line": 7, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -945,6 +1341,28 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 34, + "end_line": 3, + "file_path": "union_agg.cpp", + "id": "method:715248b9cda9caac9e3841d433bd5ef2", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "cpp", + "name": "read_field", + "qualified_name": "WithMethod::read_field", + "return_type": null, + "signature": null, + "start_column": 4, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -1055,6 +1473,28 @@ "type_parameters": null, "visibility": "public" }, + { + "decorators": null, + "docstring": null, + "end_column": 18, + "end_line": 3, + "file_path": "com_interface.hpp", + "id": "method:bcd194fb631c427de05b59f0f228f0e4", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "cpp", + "name": "Run", + "qualified_name": "SControl::Run", + "return_type": null, + "signature": null, + "start_column": 4, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -1077,6 +1517,28 @@ "type_parameters": null, "visibility": "public" }, + { + "decorators": null, + "docstring": null, + "end_column": 18, + "end_line": 8, + "file_path": "com_interface.hpp", + "id": "method:d039853bf1b1d17f861ce23c69804568", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "cpp", + "name": "Run", + "qualified_name": "IWidget::Run", + "return_type": null, + "signature": null, + "start_column": 4, + "start_line": 8, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -1143,6 +1605,50 @@ "type_parameters": null, "visibility": "public" }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 13, + "file_path": "com_interface.hpp", + "id": "struct:3968c80a1532766ec076463fa574d507", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "IPlain", + "qualified_name": "IPlain", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 11, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 8, + "file_path": "union_agg.cpp", + "id": "struct:3f0a102a7fa58ace6484079ab8820207", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "SWithMethod", + "qualified_name": "SWithMethod", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -1165,6 +1671,182 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 21, + "end_line": 2, + "file_path": "union_agg.c", + "id": "struct:43b6e695f93a9ab87d1106a7d5b2a4ca", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "c", + "name": "Ctl", + "qualified_name": "Ctl", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 2, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 9, + "file_path": "com_interface.hpp", + "id": "struct:5009f722baa64c277a025aa26625b3dd", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "IWidget", + "qualified_name": "IWidget", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 6, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 22, + "end_line": 2, + "file_path": "instantiate_agg.cpp", + "id": "struct:56b403b06683b2fb3f6682df6301cba3", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "Ctl", + "qualified_name": "Ctl", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 2, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 18, + "file_path": "com_interface.hpp", + "id": "struct:7c06a13aa42a9d9b3bc5b16852f42d10", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "INewlineBrace", + "qualified_name": "INewlineBrace", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 15, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 25, + "end_line": 2, + "file_path": "instantiate_rank.cpp", + "id": "struct:860b4dfc2d8e87f389dbeb7e3370cac2", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "Packet", + "qualified_name": "Packet", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 2, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 23, + "end_line": 2, + "file_path": "union_agg.mm", + "id": "struct:94f6722864eceb3ce91cb0ad43c60444", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "objc", + "name": "ObjcS", + "qualified_name": "ObjcS", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 2, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 39, + "end_line": 4, + "file_path": "union_agg.c", + "id": "struct:9a7a504b38e595f1a2d8030cdd4ff5c2", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "c", + "name": "AnonS", + "qualified_name": "AnonS", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 4, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 25, + "end_line": 11, + "file_path": "neg_interface.hpp", + "id": "struct:9bd27f85c031e707e087a6add300d143", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "NegReal", + "qualified_name": "NegReal", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 11, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -1187,6 +1869,28 @@ "type_parameters": null, "visibility": null }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 4, + "file_path": "com_interface.hpp", + "id": "struct:f8ed8b93742d867912fe2dd218c2819e", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "SControl", + "qualified_name": "SControl", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, { "decorators": null, "docstring": null, @@ -1208,5 +1912,159 @@ "start_line": 4, "type_parameters": null, "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 4, + "file_path": "union_agg.cpp", + "id": "union:07d2cc76b74099c2a3b894086faa18c7", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "union", + "language": "cpp", + "name": "WithMethod", + "qualified_name": "WithMethod", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 41, + "end_line": 5, + "file_path": "union_agg.c", + "id": "union:43de8da9a133883a87808eeb4ec391be", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "union", + "language": "c", + "name": "NamedU", + "qualified_name": "NamedU", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 31, + "end_line": 1, + "file_path": "union_agg.c", + "id": "union:585e8a9d12fd43888a0e3ba79274d877", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "union", + "language": "c", + "name": "Named", + "qualified_name": "Named", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 31, + "end_line": 1, + "file_path": "instantiate_rank.cpp", + "id": "union:613e56ffd95a092fdcb8cb389be3e17d", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "union", + "language": "cpp", + "name": "Value", + "qualified_name": "Value", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 40, + "end_line": 3, + "file_path": "union_agg.c", + "id": "union:9189436be51568f4955e50e2435c9b00", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "union", + "language": "c", + "name": "AnonU", + "qualified_name": "AnonU", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 33, + "end_line": 1, + "file_path": "instantiate_agg.cpp", + "id": "union:a2d1fd60ce557850c54ea94728f0d587", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "union", + "language": "cpp", + "name": "Reg", + "qualified_name": "Reg", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 31, + "end_line": 1, + "file_path": "union_agg.mm", + "id": "union:e37aaff4aa26c664b0b839456f0024e1", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "union", + "language": "objc", + "name": "ObjcU", + "qualified_name": "ObjcU", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null } ] diff --git a/reference/golden/cpp/refs.json b/reference/golden/cpp/refs.json index fed34718..fdde11e7 100644 --- a/reference/golden/cpp/refs.json +++ b/reference/golden/cpp/refs.json @@ -1,4 +1,24 @@ [ + { + "candidates": null, + "col": 18, + "file_path": "com_interface.hpp", + "from_node_id": "struct:f8ed8b93742d867912fe2dd218c2819e", + "language": "cpp", + "line": 1, + "reference_kind": "extends", + "reference_name": "IBase" + }, + { + "candidates": null, + "col": 20, + "file_path": "com_interface.hpp", + "from_node_id": "struct:5009f722baa64c277a025aa26625b3dd", + "language": "cpp", + "line": 6, + "reference_kind": "extends", + "reference_name": "IBase" + }, { "candidates": null, "col": 31, diff --git a/reference/golden/rust/colby.db b/reference/golden/rust/colby.db new file mode 100644 index 00000000..7e760535 Binary files /dev/null and b/reference/golden/rust/colby.db differ diff --git a/reference/golden/rust/edges.json b/reference/golden/rust/edges.json new file mode 100644 index 00000000..f52b6a93 --- /dev/null +++ b/reference/golden/rust/edges.json @@ -0,0 +1,275 @@ +[ + { + "col": 0, + "kind": "imports", + "line": 1, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "file:consumer.rs", + "target": "import:b45211470cf011dde09b7990d7e238e4" + }, + { + "col": 4, + "kind": "calls", + "line": 4, + "metadata": { + "confidence": 0.9, + "resolvedBy": "instance-method" + }, + "provenance": null, + "source": "function:c8e1506aa2c158eff8b9790ef4ebfa5c", + "target": "method:7fc738eac7790ac49dfa4b6a7cd6b9a9" + }, + { + "col": 4, + "kind": "calls", + "line": 8, + "metadata": { + "confidence": 0.9, + "resolvedBy": "instance-method" + }, + "provenance": null, + "source": "function:88c7f6ab9fc2123a08f9ecf37298bd40", + "target": "method:332692d36b049f0071041145d30d687c" + }, + { + "col": 5, + "kind": "implements", + "line": 13, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "struct:280f7daaeca096946aa3484658c88063", + "target": "trait:822b89fd17ee8e49a50fbe03e4fe72de" + }, + { + "col": 5, + "kind": "implements", + "line": 19, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "struct:ba608806a3b56b3964d9f8172341f9d2", + "target": "trait:822b89fd17ee8e49a50fbe03e4fe72de" + }, + { + "col": 5, + "kind": "implements", + "line": 25, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "struct:1ef30d9d3f298b426fbbbd5910139ecc", + "target": "trait:822b89fd17ee8e49a50fbe03e4fe72de" + }, + { + "col": 5, + "kind": "implements", + "line": 42, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "union:466d8ec81e4f465f813cbcac35562ca9", + "target": "trait:822b89fd17ee8e49a50fbe03e4fe72de" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.rs", + "target": "function:88c7f6ab9fc2123a08f9ecf37298bd40" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.rs", + "target": "function:c8e1506aa2c158eff8b9790ef4ebfa5c" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:consumer.rs", + "target": "import:b45211470cf011dde09b7990d7e238e4" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "function:190b8fbf32e627648ed53f2ce8cc285c" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "function:e7de8b9d2d442c9a564bee08c82b145a" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "method:15074a95e078da927a780dccd5ed2448" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "method:332692d36b049f0071041145d30d687c" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "method:7fc738eac7790ac49dfa4b6a7cd6b9a9" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "method:8cb04e8ca5d9379a7bdf1b71236238cf" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "method:f1fe944ca0591095cb695294229acbb1" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "struct:1ef30d9d3f298b426fbbbd5910139ecc" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "struct:280f7daaeca096946aa3484658c88063" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "struct:ba608806a3b56b3964d9f8172341f9d2" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "trait:822b89fd17ee8e49a50fbe03e4fe72de" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:lib.rs", + "target": "union:466d8ec81e4f465f813cbcac35562ca9" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:1ef30d9d3f298b426fbbbd5910139ecc", + "target": "method:15074a95e078da927a780dccd5ed2448" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:280f7daaeca096946aa3484658c88063", + "target": "method:7fc738eac7790ac49dfa4b6a7cd6b9a9" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:ba608806a3b56b3964d9f8172341f9d2", + "target": "method:8cb04e8ca5d9379a7bdf1b71236238cf" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "trait:822b89fd17ee8e49a50fbe03e4fe72de", + "target": "method:28764bbfc23c2fe8ec24a7d1b72b1330" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "union:466d8ec81e4f465f813cbcac35562ca9", + "target": "method:332692d36b049f0071041145d30d687c" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "union:466d8ec81e4f465f813cbcac35562ca9", + "target": "method:f1fe944ca0591095cb695294229acbb1" + } +] diff --git a/reference/golden/rust/files.json b/reference/golden/rust/files.json new file mode 100644 index 00000000..4ac637ce --- /dev/null +++ b/reference/golden/rust/files.json @@ -0,0 +1,18 @@ +[ + { + "content_hash": "8121cdd4bac4cf4e031fa69ca8b2ceea14f7f61e2357a339025afdcb51ea6585", + "errors": null, + "language": "rust", + "node_count": 4, + "path": "consumer.rs", + "size": 164 + }, + { + "content_hash": "32fd3f5a2c8b2054c3197394a04d39f75f8ad52de6afe38e76ec0e4ee7358960", + "errors": null, + "language": "rust", + "node_count": 14, + "path": "lib.rs", + "size": 767 + } +] diff --git a/reference/golden/rust/nodes.json b/reference/golden/rust/nodes.json new file mode 100644 index 00000000..02874e21 --- /dev/null +++ b/reference/golden/rust/nodes.json @@ -0,0 +1,398 @@ +[ + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 10, + "file_path": "consumer.rs", + "id": "file:consumer.rs", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "rust", + "name": "consumer.rs", + "qualified_name": "consumer.rs", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 55, + "file_path": "lib.rs", + "id": "file:lib.rs", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "rust", + "name": "lib.rs", + "qualified_name": "lib.rs", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 54, + "file_path": "lib.rs", + "id": "function:190b8fbf32e627648ed53f2ce8cc285c", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "rust", + "name": "make_bits", + "qualified_name": "make_bits", + "return_type": "Bits", + "signature": "() -> Bits", + "start_column": 0, + "start_line": 52, + "type_parameters": null, + "visibility": "public" + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 9, + "file_path": "consumer.rs", + "id": "function:88c7f6ab9fc2123a08f9ecf37298bd40", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "rust", + "name": "describe_bits", + "qualified_name": "describe_bits", + "return_type": "String", + "signature": "(b: &Bits) -> String", + "start_column": 0, + "start_line": 7, + "type_parameters": null, + "visibility": "public" + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 5, + "file_path": "consumer.rs", + "id": "function:c8e1506aa2c158eff8b9790ef4ebfa5c", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "rust", + "name": "describe_unit", + "qualified_name": "describe_unit", + "return_type": "String", + "signature": "(u: &UnitStruct) -> String", + "start_column": 0, + "start_line": 3, + "type_parameters": null, + "visibility": "public" + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 50, + "file_path": "lib.rs", + "id": "function:e7de8b9d2d442c9a564bee08c82b145a", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "rust", + "name": "make_unit", + "qualified_name": "make_unit", + "return_type": "UnitStruct", + "signature": "() -> UnitStruct", + "start_column": 0, + "start_line": 48, + "type_parameters": null, + "visibility": "public" + }, + { + "decorators": null, + "docstring": null, + "end_column": 37, + "end_line": 1, + "file_path": "consumer.rs", + "id": "import:b45211470cf011dde09b7990d7e238e4", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "rust", + "name": "crate", + "qualified_name": "crate", + "return_type": null, + "signature": "use crate::{Bits, Greet, UnitStruct};", + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 5, + "end_line": 28, + "file_path": "lib.rs", + "id": "method:15074a95e078da927a780dccd5ed2448", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "rust", + "name": "greet", + "qualified_name": "TupleStruct::greet", + "return_type": "String", + "signature": "(&self) -> String", + "start_column": 4, + "start_line": 26, + "type_parameters": null, + "visibility": "private" + }, + { + "decorators": null, + "docstring": null, + "end_column": 30, + "end_line": 2, + "file_path": "lib.rs", + "id": "method:28764bbfc23c2fe8ec24a7d1b72b1330", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "rust", + "name": "greet", + "qualified_name": "Greet::greet", + "return_type": "String", + "signature": "(&self) -> String", + "start_column": 4, + "start_line": 2, + "type_parameters": null, + "visibility": "private" + }, + { + "decorators": null, + "docstring": null, + "end_column": 5, + "end_line": 45, + "file_path": "lib.rs", + "id": "method:332692d36b049f0071041145d30d687c", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "rust", + "name": "greet", + "qualified_name": "Bits::greet", + "return_type": "String", + "signature": "(&self) -> String", + "start_column": 4, + "start_line": 43, + "type_parameters": null, + "visibility": "private" + }, + { + "decorators": null, + "docstring": null, + "end_column": 5, + "end_line": 16, + "file_path": "lib.rs", + "id": "method:7fc738eac7790ac49dfa4b6a7cd6b9a9", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "rust", + "name": "greet", + "qualified_name": "UnitStruct::greet", + "return_type": "String", + "signature": "(&self) -> String", + "start_column": 4, + "start_line": 14, + "type_parameters": null, + "visibility": "private" + }, + { + "decorators": null, + "docstring": null, + "end_column": 5, + "end_line": 22, + "file_path": "lib.rs", + "id": "method:8cb04e8ca5d9379a7bdf1b71236238cf", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "rust", + "name": "greet", + "qualified_name": "BraceStruct::greet", + "return_type": "String", + "signature": "(&self) -> String", + "start_column": 4, + "start_line": 20, + "type_parameters": null, + "visibility": "private" + }, + { + "decorators": null, + "docstring": null, + "end_column": 5, + "end_line": 39, + "file_path": "lib.rs", + "id": "method:f1fe944ca0591095cb695294229acbb1", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "rust", + "name": "raw", + "qualified_name": "Bits::raw", + "return_type": null, + "signature": "(&self) -> u32", + "start_column": 4, + "start_line": 37, + "type_parameters": null, + "visibility": "public" + }, + { + "decorators": null, + "docstring": null, + "end_column": 31, + "end_line": 11, + "file_path": "lib.rs", + "id": "struct:1ef30d9d3f298b426fbbbd5910139ecc", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "rust", + "name": "TupleStruct", + "qualified_name": "TupleStruct", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 11, + "type_parameters": null, + "visibility": "public" + }, + { + "decorators": null, + "docstring": null, + "end_column": 22, + "end_line": 5, + "file_path": "lib.rs", + "id": "struct:280f7daaeca096946aa3484658c88063", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "rust", + "name": "UnitStruct", + "qualified_name": "UnitStruct", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 5, + "type_parameters": null, + "visibility": "public" + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 9, + "file_path": "lib.rs", + "id": "struct:ba608806a3b56b3964d9f8172341f9d2", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "rust", + "name": "BraceStruct", + "qualified_name": "BraceStruct", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 7, + "type_parameters": null, + "visibility": "public" + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 3, + "file_path": "lib.rs", + "id": "trait:822b89fd17ee8e49a50fbe03e4fe72de", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "trait", + "language": "rust", + "name": "Greet", + "qualified_name": "Greet", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 34, + "file_path": "lib.rs", + "id": "union:466d8ec81e4f465f813cbcac35562ca9", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "union", + "language": "rust", + "name": "Bits", + "qualified_name": "Bits", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 31, + "type_parameters": null, + "visibility": "public" + } +] diff --git a/reference/golden/rust/refs.json b/reference/golden/rust/refs.json new file mode 100644 index 00000000..1cb3eab3 --- /dev/null +++ b/reference/golden/rust/refs.json @@ -0,0 +1,32 @@ +[ + { + "candidates": null, + "col": 12, + "file_path": "consumer.rs", + "from_node_id": "file:consumer.rs", + "language": "rust", + "line": 1, + "reference_kind": "imports", + "reference_name": "crate::Bits" + }, + { + "candidates": null, + "col": 18, + "file_path": "consumer.rs", + "from_node_id": "file:consumer.rs", + "language": "rust", + "line": 1, + "reference_kind": "imports", + "reference_name": "crate::Greet" + }, + { + "candidates": null, + "col": 25, + "file_path": "consumer.rs", + "from_node_id": "file:consumer.rs", + "language": "rust", + "line": 1, + "reference_kind": "imports", + "reference_name": "crate::UnitStruct" + } +] diff --git a/reference/golden/rust/schema.sql b/reference/golden/rust/schema.sql new file mode 100644 index 00000000..d36218fe --- /dev/null +++ b/reference/golden/rust/schema.sql @@ -0,0 +1,117 @@ +CREATE TABLE schema_versions ( +version INTEGER PRIMARY KEY, +applied_at INTEGER NOT NULL, +description TEXT +); +CREATE TABLE nodes ( +id TEXT PRIMARY KEY, +kind TEXT NOT NULL, +name TEXT NOT NULL, +qualified_name TEXT NOT NULL, +file_path TEXT NOT NULL, +language TEXT NOT NULL, +start_line INTEGER NOT NULL, +end_line INTEGER NOT NULL, +start_column INTEGER NOT NULL, +end_column INTEGER NOT NULL, +docstring TEXT, +signature TEXT, +visibility TEXT, +is_exported INTEGER DEFAULT 0, +is_async INTEGER DEFAULT 0, +is_static INTEGER DEFAULT 0, +is_abstract INTEGER DEFAULT 0, +decorators TEXT, -- JSON array +type_parameters TEXT, -- JSON array +return_type TEXT, -- normalized return/result type name (e.g. C++ method return, for receiver-type inference) +updated_at INTEGER NOT NULL +); +CREATE TABLE edges ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +source TEXT NOT NULL, +target TEXT NOT NULL, +kind TEXT NOT NULL, +metadata TEXT, -- JSON object +line INTEGER, +col INTEGER, +provenance TEXT DEFAULT NULL, +FOREIGN KEY (source) REFERENCES nodes(id) ON DELETE CASCADE, +FOREIGN KEY (target) REFERENCES nodes(id) ON DELETE CASCADE +); +CREATE TABLE sqlite_sequence(name,seq); +CREATE TABLE files ( +path TEXT PRIMARY KEY, +content_hash TEXT NOT NULL, +language TEXT NOT NULL, +size INTEGER NOT NULL, +modified_at INTEGER NOT NULL, +indexed_at INTEGER NOT NULL, +node_count INTEGER DEFAULT 0, +errors TEXT -- JSON array +); +CREATE TABLE unresolved_refs ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +from_node_id TEXT NOT NULL, +reference_name TEXT NOT NULL, +reference_kind TEXT NOT NULL, +line INTEGER NOT NULL, +col INTEGER NOT NULL, +candidates TEXT, -- JSON array +file_path TEXT NOT NULL DEFAULT '', +language TEXT NOT NULL DEFAULT 'unknown', +reference_subkind TEXT, +FOREIGN KEY (from_node_id) REFERENCES nodes(id) ON DELETE CASCADE +); +CREATE INDEX idx_nodes_kind ON nodes(kind); +CREATE INDEX idx_nodes_name ON nodes(name); +CREATE INDEX idx_nodes_qualified_name ON nodes(qualified_name); +CREATE INDEX idx_nodes_file_path ON nodes(file_path); +CREATE INDEX idx_nodes_language ON nodes(language); +CREATE INDEX idx_nodes_file_line ON nodes(file_path, start_line); +CREATE INDEX idx_nodes_lower_name ON nodes(lower(name)); +CREATE VIRTUAL TABLE nodes_fts USING fts5( +id, +name, +qualified_name, +docstring, +signature, +content='nodes', +content_rowid='rowid' +) +/* nodes_fts(id,name,qualified_name,docstring,signature) */; +CREATE TABLE 'nodes_fts_data'(id INTEGER PRIMARY KEY, block BLOB); +CREATE TABLE 'nodes_fts_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID; +CREATE TABLE 'nodes_fts_docsize'(id INTEGER PRIMARY KEY, sz BLOB); +CREATE TABLE 'nodes_fts_config'(k PRIMARY KEY, v) WITHOUT ROWID; +CREATE TRIGGER nodes_ai AFTER INSERT ON nodes BEGIN +INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature) +VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature); +END; +CREATE TRIGGER nodes_ad AFTER DELETE ON nodes BEGIN +INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature) +VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature); +END; +CREATE TRIGGER nodes_au AFTER UPDATE ON nodes BEGIN +INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature) +VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature); +INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature) +VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature); +END; +CREATE INDEX idx_edges_kind ON edges(kind); +CREATE INDEX idx_edges_source_kind ON edges(source, kind); +CREATE INDEX idx_edges_target_kind ON edges(target, kind); +CREATE UNIQUE INDEX idx_edges_identity +ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); +CREATE INDEX idx_files_language ON files(language); +CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); +CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); +CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); +CREATE INDEX idx_unresolved_from_name ON unresolved_refs(from_node_id, reference_name); +CREATE INDEX idx_edges_provenance ON edges(provenance); +CREATE TABLE project_metadata ( +key TEXT PRIMARY KEY, +value TEXT NOT NULL, +updated_at INTEGER NOT NULL +); +CREATE TABLE sqlite_stat1(tbl,idx,stat);