From 655aacab3de5e18f906e2d3c89c4fa1d149876b0 Mon Sep 17 00:00:00 2001 From: sunerpy Date: Tue, 14 Jul 2026 23:16:23 +0800 Subject: [PATCH] feat(extraction): index Metal (.metal) and CUDA (.cu/.cuh) via the C++ grammar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ports the Metal and CUDA language support from upstream colby 1.2.0..1.4.1 (the two cheapest additions, since both dialects are close enough to C++ that the existing tree-sitter-cpp grammar extracts them). Both map to Language::Cpp — no new language variant, no new grammar crate, no new dependency, and the golden .schema is unchanged. - Metal (#1121): .metal maps to the C++ grammar. MSL puts attributes after the declarator (`float4 pos [[position]];`), a shape tree-sitter-cpp misparses into a spurious inheritance edge from the struct to a field's type. An offset-preserving pre-parse pass blanks `[[attribute]]` annotations, gated to .metal files only — in regular C++ the pre-declarator `[[nodiscard]]` position is legal syntax the grammar parses natively and is left byte-identical. - CUDA (#1172, language parts only — the namespace-qualified-name and template-argument-call work from the same upstream commit already shipped in v0.31.0 and is not re-ported here): .cu/.cuh map to the C++ grammar, and CUDA in a plain .h/.hpp is recognized by content. The host->kernel call edge now survives the `<<>>` launch syntax — an offset-preserving, brace-balanced pre-parse blank of the launch config leaves `kernel(args)` as an ordinary resolvable call (templated launches ride the existing template-arg stripping). Kernels defined through a name-in-first-argument macro (`DEFINE_FLASH_FORWARD_KERNEL(name, ...)`) are indexed under their real name, with the macro-name recovery tightly gated so gtest-style `TEST(...)` and ordinary macro calls are untouched. The `<<<>>>` and CUDA-construct blanks fire only for CUDA files/content, so non-CUDA C++ is byte-identical. New dedicated `metal` and `cuda` golden fixtures guard the behavior; the existing cpp/godot/ruby/mini goldens and the .schema are byte-identical (no regen). Local function-pointer launch dispatch is deferred. --- .../codegraph-bench/fixtures/cuda/kernel.cu | 18 + .../fixtures/metal/shader.metal | 24 ++ crates/codegraph-bench/tests/equivalence.rs | 53 +++ crates/codegraph-extract/src/engine.rs | 14 +- crates/codegraph-extract/src/lang/c.rs | 25 ++ crates/codegraph-extract/src/lang/cpp.rs | 313 +++++++++++++++++- crates/codegraph-extract/src/lang/csharp.rs | 2 +- crates/codegraph-extract/src/spec.rs | 3 +- crates/codegraph-extract/src/walker.rs | 57 ++++ docs/equivalence.md | 62 ++++ reference/golden/cuda/colby.db | Bin 0 -> 151552 bytes reference/golden/cuda/edges.json | 62 ++++ reference/golden/cuda/files.json | 10 + reference/golden/cuda/nodes.json | 112 +++++++ reference/golden/cuda/refs.json | 1 + reference/golden/cuda/schema.sql | 117 +++++++ reference/golden/metal/colby.db | Bin 0 -> 151552 bytes reference/golden/metal/edges.json | 59 ++++ reference/golden/metal/files.json | 10 + reference/golden/metal/nodes.json | 134 ++++++++ reference/golden/metal/refs.json | 1 + reference/golden/metal/schema.sql | 117 +++++++ 22 files changed, 1179 insertions(+), 15 deletions(-) create mode 100644 crates/codegraph-bench/fixtures/cuda/kernel.cu create mode 100644 crates/codegraph-bench/fixtures/metal/shader.metal create mode 100644 reference/golden/cuda/colby.db create mode 100644 reference/golden/cuda/edges.json create mode 100644 reference/golden/cuda/files.json create mode 100644 reference/golden/cuda/nodes.json create mode 100644 reference/golden/cuda/refs.json create mode 100644 reference/golden/cuda/schema.sql create mode 100644 reference/golden/metal/colby.db create mode 100644 reference/golden/metal/edges.json create mode 100644 reference/golden/metal/files.json create mode 100644 reference/golden/metal/nodes.json create mode 100644 reference/golden/metal/refs.json create mode 100644 reference/golden/metal/schema.sql diff --git a/crates/codegraph-bench/fixtures/cuda/kernel.cu b/crates/codegraph-bench/fixtures/cuda/kernel.cu new file mode 100644 index 00000000..45fc4646 --- /dev/null +++ b/crates/codegraph-bench/fixtures/cuda/kernel.cu @@ -0,0 +1,18 @@ +__global__ void add_kernel(int* out, const int* a, const int* b) { + int i = 0; + out[i] = a[i] + b[i]; +} + +template +__global__ void scale_kernel(T* x, T factor) { + x[0] = x[0] * factor; +} + +DEFINE_FLASH_FORWARD_KERNEL(my_kernel, int n) { + int i = n; +} + +void launch(int* out, const int* a, const int* b, float* data) { + add_kernel<<>>(out, a, b); + scale_kernel<<>>(data, 2.0f); +} diff --git a/crates/codegraph-bench/fixtures/metal/shader.metal b/crates/codegraph-bench/fixtures/metal/shader.metal new file mode 100644 index 00000000..fdb400c8 --- /dev/null +++ b/crates/codegraph-bench/fixtures/metal/shader.metal @@ -0,0 +1,24 @@ +struct float4 { + float x; + float y; + float z; + float w; +}; + +struct float2 { + float u; + float v; +}; + +struct VertexIn { + float4 position [[position]]; + float2 uv [[user(locn0)]]; +}; + +float4 tint(float4 color) { + return color; +} + +vertex float4 vertex_main(VertexIn in [[stage_in]]) { + return tint(in.position); +} diff --git a/crates/codegraph-bench/tests/equivalence.rs b/crates/codegraph-bench/tests/equivalence.rs index b2afe4a2..9f978623 100644 --- a/crates/codegraph-bench/tests/equivalence.rs +++ b/crates/codegraph-bench/tests/equivalence.rs @@ -79,6 +79,43 @@ fn cpp_db_is_self_equivalent_to_cpp_golden() { assert_equivalent(&cpp_db(), &cpp_golden_dir()).unwrap(); } +#[test] +fn generated_golden_matches_committed_metal_fixture() { + // Guards Metal (#1121): `.metal`→cpp mapping + the `[[attribute]]` blank that + // prevents the spurious `VertexIn extends float4` inheritance edge. + let tempdir = TestDir::new("generated-golden-metal"); + write_golden(&metal_db(), tempdir.path()).unwrap(); + + let expected = load_golden(&metal_golden_dir()).unwrap(); + let actual = load_golden(tempdir.path()).unwrap(); + + diff_canonical(&expected, &actual, None).unwrap(); +} + +#[test] +fn metal_db_is_self_equivalent_to_metal_golden() { + assert_equivalent(&metal_db(), &metal_golden_dir()).unwrap(); +} + +#[test] +fn generated_golden_matches_committed_cuda_fixture() { + // Guards CUDA (#1172 CUDA-lang parts): `.cu`→cpp mapping, the `<<<…>>>` + // launch-config blank that preserves the host→kernel Calls edge (plain + + // templated), and macro-defined-kernel name recovery (`my_kernel`). + let tempdir = TestDir::new("generated-golden-cuda"); + write_golden(&cuda_db(), tempdir.path()).unwrap(); + + let expected = load_golden(&cuda_golden_dir()).unwrap(); + let actual = load_golden(tempdir.path()).unwrap(); + + diff_canonical(&expected, &actual, None).unwrap(); +} + +#[test] +fn cuda_db_is_self_equivalent_to_cuda_golden() { + assert_equivalent(&cuda_db(), &cuda_golden_dir()).unwrap(); +} + #[test] fn tier1_node_drift_is_reported() { let expected = load_golden(&mini_golden_dir()).unwrap(); @@ -157,6 +194,22 @@ fn cpp_golden_dir() -> PathBuf { workspace_root().join("reference/golden/cpp") } +fn metal_db() -> PathBuf { + workspace_root().join("reference/golden/metal/colby.db") +} + +fn metal_golden_dir() -> PathBuf { + workspace_root().join("reference/golden/metal") +} + +fn cuda_db() -> PathBuf { + workspace_root().join("reference/golden/cuda/colby.db") +} + +fn cuda_golden_dir() -> PathBuf { + workspace_root().join("reference/golden/cuda") +} + struct TestDir { path: PathBuf, } diff --git a/crates/codegraph-extract/src/engine.rs b/crates/codegraph-extract/src/engine.rs index 01fa73b9..aa71de28 100644 --- a/crates/codegraph-extract/src/engine.rs +++ b/crates/codegraph-extract/src/engine.rs @@ -58,6 +58,10 @@ pub fn builtin_language_for_ext(ext: &str) -> Option { "java" => Language::Java, "c" | "h" => Language::C, "cpp" | "cc" | "cxx" | "hpp" | "hxx" => Language::Cpp, + // Metal Shading Language (≈ C++14) and CUDA (≈ C++ + dialect tokens) both + // ride the C++ grammar with a dialect-specific pre-parse blank; no new + // `Language` variant (upstream maps all three to `cpp`). + "metal" | "cu" | "cuh" => Language::Cpp, "cs" => Language::CSharp, "php" | "module" | "install" | "theme" | "inc" => Language::Php, "rb" | "rake" => Language::Ruby, @@ -203,7 +207,7 @@ pub fn extract_source( duration_ms: start.elapsed().as_millis() as i64, }; } - let parsed_source = spec.pre_parse(source); + let parsed_source = spec.pre_parse(source, file_path); let Some(tree) = parser.parse(&parsed_source, None) else { return ExtractionResult { nodes: Vec::new(), @@ -859,6 +863,14 @@ mod tests { assert_eq!(detect_language("src/lib.rs"), Language::Rust); } + #[test] + fn metal_cu_cuh_map_to_cpp() { + assert_eq!(detect_language("s.metal"), Language::Cpp); + assert_eq!(detect_language("k.cu"), Language::Cpp); + assert_eq!(detect_language("k.cuh"), Language::Cpp); + assert_eq!(Language::ALL.len(), 36); + } + #[test] fn extract_source_unknown_language_yields_empty_no_error() { let result = extract_source("mystery.unknownext", "content", None); diff --git a/crates/codegraph-extract/src/lang/c.rs b/crates/codegraph-extract/src/lang/c.rs index a498e410..e4e16d10 100644 --- a/crates/codegraph-extract/src/lang/c.rs +++ b/crates/codegraph-extract/src/lang/c.rs @@ -79,6 +79,13 @@ impl LanguageSpec for CSpec { fn extract_import(&self, node: Node<'_>, source: &str) -> Option { include_import(node, source) } + fn pre_parse(&self, source: &str, _file_path: &str) -> String { + if crate::lang::cpp::looks_like_cuda_source(source) { + crate::lang::cpp::blank_cuda_constructs_str(source) + } else { + source.to_string() + } + } } pub(crate) fn include_import(node: Node<'_>, source: &str) -> Option { @@ -177,3 +184,21 @@ fn valid_ident(text: &str) -> bool { .is_some_and(|c| c == '_' || c.is_ascii_alphabetic()) && chars.all(|c| c == '_' || c.is_ascii_alphanumeric()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn c_header_cuda_content_blanked() { + let out = CSpec.pre_parse("__device__ int helper() { return 0; }", "h.h"); + assert!(!out.contains("__device__")); + assert_eq!(out.len(), "__device__ int helper() { return 0; }".len()); + } + + #[test] + fn c_plain_untouched() { + let src = "int add(int a, int b) { return a + b; }"; + assert_eq!(CSpec.pre_parse(src, "m.c"), src); + } +} diff --git a/crates/codegraph-extract/src/lang/cpp.rs b/crates/codegraph-extract/src/lang/cpp.rs index fdb339e1..2f9f95a2 100644 --- a/crates/codegraph-extract/src/lang/cpp.rs +++ b/crates/codegraph-extract/src/lang/cpp.rs @@ -67,6 +67,9 @@ impl LanguageSpec for CppSpec { "type" } fn resolve_name(&self, node: Node<'_>, source: &str) -> Option { + if let Some(name) = recover_cpp_macro_defined_name(node, source) { + return Some(name); + } let qid = declarator_qualified_id(child_by_field(node, "declarator")?)?; node_text(qid, source) .rsplit("::") @@ -116,8 +119,8 @@ impl LanguageSpec for CppSpec { fn extract_import(&self, node: Node<'_>, source: &str) -> Option { include_import(node, source) } - fn pre_parse(&self, source: &str) -> String { - pre_parse_cpp_source(source) + fn pre_parse(&self, source: &str, file_path: &str) -> String { + pre_parse_cpp_source(source, file_path) } } @@ -128,10 +131,133 @@ impl LanguageSpec for CppSpec { /// ASCII spaces — tree-sitter consumes byte offsets, and every blanked span lies /// 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) -> String { +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 lower = file_path.to_ascii_lowercase(); + let bytes = if lower.ends_with(".metal") { + blank_metal_attributes(bytes) + } else if lower.ends_with(".cu") || lower.ends_with(".cuh") || looks_like_cuda_source(source) { + blank_cuda_constructs(bytes) + } else { + bytes + }; + String::from_utf8(bytes).unwrap_or_else(|_| source.to_string()) +} + +/// Blank Metal Shading Language `[[attribute]]` annotations (`[[position]]`, +/// `[[buffer(0)]]`, comma-lists like `[[buffer(0), raster_order_group(0)]]`) to +/// equal-length spaces. MSL puts attributes AFTER the declarator +/// (`float4 position [[position]];`), which tree-sitter-cpp misparses into a +/// spurious `extends` ref from the struct to the field's own type (#1121). +/// `[[`-gated fast-exit; offset-preserving. The `regex` crate is lookahead-free +/// so the tight shape (after `[[`, an identifier then `]]`) alone excludes a +/// subscripted lambda `arr[[]{…}()]`. +fn blank_metal_attributes(bytes: Vec) -> Vec { + let source = match std::str::from_utf8(&bytes) { + Ok(source) => source, + Err(_) => return bytes, + }; + if !source.contains("[[") { + return bytes; + } + static RE: OnceLock = OnceLock::new(); + let re = RE.get_or_init(|| { + Regex::new( + r"\[\[\s*[A-Za-z_]\w*(?:\s*\([^()\n]*\))?(?:\s*,\s*[A-Za-z_]\w*(?:\s*\([^()\n]*\))?)*\s*\]\]", + ) + .expect("metal-attribute regex") + }); + let spans: Vec<(usize, usize)> = re.find_iter(source).map(|m| (m.start(), m.end())).collect(); + let mut bytes = bytes; + for (start, end) in spans { + blank_span(&mut bytes, start, end); + } + bytes +} + +/// Blank CUDA-specific constructs (`.cu`/`.cuh` or content-detected) so the +/// residual parses as plain C++ (#387, CUDA-lang parts of #1172): +/// - `__launch_bounds__(...)` then execution-space/storage specifiers +/// (`__global__` family) — gated by `__`; blanked to equal-length spaces. +/// `__restrict__` is deliberately excluded (grammar parses it natively). +/// - `<<>>` launch configs — gated by `<<<`; +/// the chevrons otherwise lex as shift operators and destroy the host→kernel +/// call edge. Blanking the span leaves a plain `kernel(args)` call. Only a +/// BRACE-BALANCED match is blanked (a stray `<<<` from a merge-conflict marker +/// opens braces it never closes and is left untouched), matching upstream's +/// char-scan replacer. Offset-preserving. +fn blank_cuda_constructs(bytes: Vec) -> Vec { + let source = match std::str::from_utf8(&bytes) { + Ok(source) => source, + Err(_) => return bytes, + }; + let mut spans: Vec<(usize, usize)> = Vec::new(); + if source.contains("__") { + static BOUNDS_RE: OnceLock = OnceLock::new(); + let bounds_re = BOUNDS_RE.get_or_init(|| { + Regex::new(r"\b__launch_bounds__\s*\([^()\n]*\)").expect("bounds regex") + }); + static SPEC_RE: OnceLock = OnceLock::new(); + let spec_re = SPEC_RE.get_or_init(|| { + Regex::new( + r"\b__(?:global|device|host|constant|shared|managed|grid_constant|forceinline|noinline|launch_bounds)__\b", + ) + .expect("specifier regex") + }); + spans.extend(bounds_re.find_iter(source).map(|m| (m.start(), m.end()))); + spans.extend(spec_re.find_iter(source).map(|m| (m.start(), m.end()))); + } + if source.contains("<<<") { + static LAUNCH_RE: OnceLock = OnceLock::new(); + let launch_re = + LAUNCH_RE.get_or_init(|| Regex::new(r"<<<[^;]{0,400}?>>>").expect("launch regex")); + for m in launch_re.find_iter(source) { + if is_brace_balanced(m.as_str()) { + spans.push((m.start(), m.end())); + } + } + } + let mut bytes = bytes; + for (start, end) in spans { + blank_span(&mut bytes, start, end); + } + bytes +} + +/// True when every `{` in `text` is matched by a later `}` and no `}` precedes +/// its opener (net depth stays non-negative and ends at zero). Used to reject a +/// launch-config match that spills across a merge-conflict marker. +fn is_brace_balanced(text: &str) -> bool { + let mut depth: i32 = 0; + for b in text.bytes() { + if b == b'{' { + depth += 1; + } else if b == b'}' { + depth -= 1; + if depth < 0 { + return false; + } + } + } + depth == 0 +} + +/// Strong content markers for CUDA in files without a `.cu`/`.cuh` extension +/// (much CUDA lives in `.h`/`.hpp`). The dunder specifiers are nvcc-only and +/// `cudaStream_t` is the runtime stream handle; none is valid C++ anywhere, so +/// a content-triggered blank on a non-CUDA file is inert. Weak markers (`dim3`, +/// `<<<`) are deliberately excluded. +pub(crate) fn looks_like_cuda_source(source: &str) -> bool { + source.contains("__global__") + || source.contains("__device__") + || source.contains("__constant__") + || source.contains("cudaStream_t") +} + +pub(crate) fn blank_cuda_constructs_str(source: &str) -> String { + let bytes = blank_cuda_constructs(source.as_bytes().to_vec()); String::from_utf8(bytes).unwrap_or_else(|_| source.to_string()) } @@ -301,6 +427,58 @@ fn blank_cpp_annotation_macro_calls(bytes: Vec) -> Vec { bytes } +/// 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, …) { … }`): +/// tree-sitter parses it as a `function_definition` named after the macro, so +/// every such kernel collapses onto one name (#1172). Narrow gate — ALL of: +/// the parsed name is macro-shaped (`^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$`); the +/// first "parameter" is a LONE lowercase-bearing `type_identifier` (the name); +/// ≥2 params and no OTHER param is a lone identifier (so gtest `TEST_F(Fixture, +/// Name)` / `PYBIND11_MODULE(ext, m)` / `BENCHMARK_DEFINE_F(Fix, name)` bail). +fn recover_cpp_macro_defined_name(node: Node<'_>, source: &str) -> Option { + if node.kind() != "function_definition" { + return None; + } + let declarator = child_by_field(node, "declarator")?; + if declarator.kind() != "function_declarator" { + return None; + } + let inner = child_by_field(declarator, "declarator")?; + if inner.kind() != "identifier" { + return None; + } + let macro_name = node_text(inner, source); + static RE: OnceLock = OnceLock::new(); + let re = RE + .get_or_init(|| Regex::new(r"^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$").expect("macro-name regex")); + if !re.is_match(¯o_name) { + return None; + } + let params = child_by_field(declarator, "parameters")?; + let named: Vec> = params.named_children(&mut params.walk()).collect(); + if named.len() < 2 { + return None; + } + let lone_ident_text = |p: Node<'_>| -> Option { + if p.kind() != "parameter_declaration" || p.named_child_count() != 1 { + return None; + } + let child = p.named_child(0)?; + (child.kind() == "type_identifier").then(|| node_text(child, source)) + }; + let name = lone_ident_text(named[0])?; + if !name.chars().any(|c| c.is_ascii_lowercase()) { + return None; + } + for p in &named[1..] { + if lone_ident_text(*p).is_some() { + return None; + } + } + Some(name) +} + fn declarator_qualified_id<'tree>(declarator: Node<'tree>) -> Option> { let mut queue = vec![declarator]; while let Some(current) = queue.pop() { @@ -522,7 +700,7 @@ mod tests { #[test] fn blank_cpp_api_prefix_member() { let src = "ENGINE_API virtual void Tick();"; - let out = pre_parse_cpp_source(src); + let out = pre_parse_cpp_source(src, "t.cpp"); assert_eq!(out.len(), src.len()); assert!(out.starts_with(" virtual void Tick();")); } @@ -530,14 +708,14 @@ mod tests { #[test] fn blank_cpp_api_prefix_bare_value_untouched() { let src = "int x = MY_API;"; - let out = pre_parse_cpp_source(src); + let out = pre_parse_cpp_source(src, "t.cpp"); assert_eq!(out, src); } #[test] fn blank_cpp_annotation_macro_calls_ue() { let src = "UPROPERTY(EditAnywhere)\nint X;"; - let out = pre_parse_cpp_source(src); + let out = pre_parse_cpp_source(src, "t.cpp"); assert_eq!(out.len(), src.len()); assert!(out.starts_with(" \nint X;")); } @@ -545,21 +723,21 @@ mod tests { #[test] fn blank_cpp_annotation_statement_call_untouched() { let src = "FOO(x);"; - let out = pre_parse_cpp_source(src); + let out = pre_parse_cpp_source(src, "t.cpp"); assert_eq!(out, src); } #[test] fn blank_cpp_annotation_in_expression_untouched() { let src = "if (CHECK(x)) {}"; - let out = pre_parse_cpp_source(src); + let out = pre_parse_cpp_source(src, "t.cpp"); assert_eq!(out, src); } #[test] fn blank_cpp_inline_annotation_umeta() { let src = "Foo UMETA(DisplayName=\"Foo\"),"; - let out = pre_parse_cpp_source(src); + let out = pre_parse_cpp_source(src, "t.cpp"); assert_eq!(out.len(), src.len()); assert!(out.starts_with("Foo ")); assert!(out.ends_with(",")); @@ -569,7 +747,7 @@ mod tests { #[test] fn blank_cpp_inline_annotation_lowercase_untouched() { let src = "auto v = meta(1);"; - let out = pre_parse_cpp_source(src); + let out = pre_parse_cpp_source(src, "t.cpp"); assert_eq!(out, src); } @@ -584,7 +762,7 @@ mod tests { void Bar(); }; "#; - let out = pre_parse_cpp_source(src); + let out = pre_parse_cpp_source(src, "t.cpp"); assert_eq!(out.len(), src.len()); assert_eq!( out.bytes().filter(|&b| b == b'\n').count(), @@ -601,6 +779,117 @@ public: }; } "#; - assert_eq!(pre_parse_cpp_source(src), src); + assert_eq!(pre_parse_cpp_source(src, "t.cpp"), src); + } + + #[test] + fn blank_metal_attributes_blanks_field_attribute() { + let src = "float4 position [[position]];"; + let out = blank_metal_attributes(src.as_bytes().to_vec()); + let out = String::from_utf8(out).unwrap(); + assert_eq!(out.len(), src.len()); + assert_eq!(out, "float4 position ;"); + assert!(!out.contains("[[")); + } + + #[test] + fn blank_metal_attributes_ignores_no_double_bracket() { + let src = "float4 position;"; + let out = blank_metal_attributes(src.as_bytes().to_vec()); + assert_eq!(String::from_utf8(out).unwrap(), src); + } + + #[test] + fn blank_metal_attributes_ignores_lambda_subscript() { + let src = "arr[[]{return 0;}()]"; + let out = blank_metal_attributes(src.as_bytes().to_vec()); + assert_eq!(String::from_utf8(out).unwrap(), src); + } + + #[test] + fn metal_attribute_blanked_only_for_dot_metal() { + let metal = pre_parse_cpp_source("struct S { float4 p [[position]]; };", "s.metal"); + assert!(!metal.contains("[[position]]")); + assert!(metal.contains("float4 p")); + let cpp = "[[nodiscard]] int f();"; + assert_eq!(pre_parse_cpp_source(cpp, "s.cpp"), cpp); + } + + #[test] + fn blank_cuda_specifier() { + let src = "__global__ void f() {}"; + let out = blank_cuda_constructs(src.as_bytes().to_vec()); + let out = String::from_utf8(out).unwrap(); + assert_eq!(out.len(), src.len()); + assert!(out.starts_with(" void f()")); + assert!(!out.contains("__global__")); + } + + #[test] + fn blank_cuda_launch_config() { + let src = "f<<>>(x);"; + let out = blank_cuda_constructs(src.as_bytes().to_vec()); + let out = String::from_utf8(out).unwrap(); + assert_eq!(out.len(), src.len()); + assert_eq!(out, "f (x);"); + } + + #[test] + fn blank_cuda_launch_unbalanced_braces_untouched() { + let src = "a <<< b } c >>> d;"; + let out = blank_cuda_constructs(src.as_bytes().to_vec()); + assert_eq!(String::from_utf8(out).unwrap(), src); + } + + #[test] + fn looks_like_cuda_source_markers() { + assert!(looks_like_cuda_source("__global__ void f();")); + assert!(looks_like_cuda_source("cudaStream_t s;")); + assert!(!looks_like_cuda_source("int main() { return 0; }")); + } + + #[test] + fn cuda_blanked_for_dot_cu() { + let out = pre_parse_cpp_source("void h() { k<<>>(x); }", "k.cu"); + assert!(!out.contains("<<<")); + assert!(out.contains("k (x);")); + } + + #[test] + fn cuda_blanked_by_content_in_hpp() { + let out = pre_parse_cpp_source("__global__ void k() {}", "k.hpp"); + assert!(!out.contains("__global__")); + } + + #[test] + fn recover_macro_kernel_name() { + assert_eq!( + resolve_macro_name("DEFINE_KERNEL(my_kernel, int n) {}"), + Some("my_kernel".to_string()) + ); + } + + #[test] + fn recover_macro_ignores_gtest_shape() { + assert_eq!(resolve_macro_name("TEST_F(Fixture, Name) {}"), None); + } + + #[test] + fn recover_macro_ignores_lowercase_macro() { + assert_eq!(resolve_macro_name("define_x(a, int b) {}"), None); + } + + fn resolve_macro_name(src: &str) -> Option { + let mut parser = tree_sitter::Parser::new(); + parser + .set_language(&tree_sitter_cpp::LANGUAGE.into()) + .unwrap(); + let tree = parser.parse(src, None).unwrap(); + let mut cursor = tree.root_node().walk(); + let func = tree + .root_node() + .named_children(&mut cursor) + .find(|c| c.kind() == "function_definition")?; + recover_cpp_macro_defined_name(func, src) } } diff --git a/crates/codegraph-extract/src/lang/csharp.rs b/crates/codegraph-extract/src/lang/csharp.rs index c72ecfaf..936437e4 100644 --- a/crates/codegraph-extract/src/lang/csharp.rs +++ b/crates/codegraph-extract/src/lang/csharp.rs @@ -71,7 +71,7 @@ impl LanguageSpec for CSharpSpec { fn return_field(&self) -> &'static str { "returns" } - fn pre_parse(&self, source: &str) -> String { + fn pre_parse(&self, source: &str, _file_path: &str) -> String { blank_csharp_preprocessor_directives(source) } fn get_return_type(&self, node: Node<'_>, source: &str) -> Option { diff --git a/crates/codegraph-extract/src/spec.rs b/crates/codegraph-extract/src/spec.rs index 3761d736..2b87fe09 100644 --- a/crates/codegraph-extract/src/spec.rs +++ b/crates/codegraph-extract/src/spec.rs @@ -57,7 +57,8 @@ pub trait LanguageSpec: Sync { fn params_field(&self) -> &'static str; fn return_field(&self) -> &'static str; - fn pre_parse(&self, source: &str) -> String { + fn pre_parse(&self, source: &str, file_path: &str) -> String { + let _ = file_path; source.to_string() } diff --git a/crates/codegraph-extract/src/walker.rs b/crates/codegraph-extract/src/walker.rs index 0ce993b2..3384bde1 100644 --- a/crates/codegraph-extract/src/walker.rs +++ b/crates/codegraph-extract/src/walker.rs @@ -4631,6 +4631,63 @@ void f() { Calculator* c = new Calculator(0); } assert!(has_ref(&refs, EdgeKind::Instantiates, "Calculator")); } + // #1172 — CUDA kernel-launch call edge survives the `<<<…>>>` blank. + #[test] + fn cuda_kernel_launch_call_edge() { + let src = r#" +__global__ void add_kernel(int* p) {} +void host() { + int* p; + add_kernel<<>>(p); +} +"#; + let (nodes, refs) = run("k.cu", src, Language::Cpp); + assert!(has_node(&nodes, NodeKind::Function, "add_kernel")); + assert!( + has_ref(&refs, EdgeKind::Calls, "add_kernel"), + "host launch should Call add_kernel, got: {:?}", + refs.iter() + .map(|r| (r.reference_kind, r.reference_name.as_str())) + .collect::>() + ); + } + + #[test] + fn cuda_templated_launch_call_edge() { + let src = r#" +template +__global__ void scale_kernel(T* x) {} +void host() { + float* x; + scale_kernel<<>>(x); +} +"#; + let (_, refs) = run("k.cu", src, Language::Cpp); + assert!( + has_ref(&refs, EdgeKind::Calls, "scale_kernel"), + "templated launch should Call scale_kernel (template args stripped), got: {:?}", + refs.iter() + .map(|r| (r.reference_kind, r.reference_name.as_str())) + .collect::>() + ); + } + + #[test] + fn cuda_macro_defined_kernel_recovered() { + let src = r#" +DEFINE_FLASH_FORWARD_KERNEL(my_kernel, int n) { } +"#; + let (nodes, _) = run("k.cu", src, Language::Cpp); + assert!( + has_node(&nodes, NodeKind::Function, "my_kernel"), + "macro-defined kernel should be named my_kernel, got: {:?}", + nodes + .iter() + .map(|n| (n.kind, n.name.as_str())) + .collect::>() + ); + } + #[test] fn cpp_primitive_declaration_no_instantiates() { // NEGATIVE: a plain primitive/local declaration must not create an edge. diff --git a/docs/equivalence.md b/docs/equivalence.md index f1bd31d8..3a15ba2e 100644 --- a/docs/equivalence.md +++ b/docs/equivalence.md @@ -304,6 +304,68 @@ 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. +### Metal fixture + +A fifth golden fixture, `reference/golden/metal/`, guards Metal Shading Language +support (upstream #1121 / `cc89146`). MSL ≈ C++14 and rides the existing +`tree-sitter-cpp` grammar — `.metal` maps to `Language::Cpp` with **no new +`Language` variant**. It guards the `.metal`-gated `[[attribute]]` blank: MSL's +post-declarator attributes (`float4 position [[position]];`) otherwise misparse a +struct field into a spurious `extends` edge from the struct to the field's own +type. The corpus (`crates/codegraph-bench/fixtures/metal/shader.metal`) defines +`float4`/`float2` structs, a `VertexIn` struct whose fields carry +`[[position]]`/`[[user(locn0)]]` attributes on those self-defined types, and a +`vertex_main` function that calls a `tint` helper. The golden must show: + +- `shader.metal` with `"language": "cpp"`; +- `VertexIn`/`float4`/`float2` as ordinary structs with **no `Extends` edge** + (the attribute blank prevents the spurious `VertexIn extends float4`); +- the intra-shader `vertex_main` → `tint` `Calls` edge. + +The `[[attribute]]` blank fires ONLY for `.metal` files; a `.cpp`/`.hpp` with a +regular `[[nodiscard]]` attribute is byte-identical through pre-parse (proven by +the `metal_attribute_blanked_only_for_dot_metal` unit test in `lang/cpp.rs`). + +### CUDA fixture + +A sixth golden fixture, `reference/golden/cuda/`, guards CUDA support (the +CUDA-language parts of upstream #1172 / `e1a8d88`). CUDA ≈ C++ + dialect tokens +and likewise rides `tree-sitter-cpp` — `.cu`/`.cuh` map to `Language::Cpp` with +**no new `Language` variant**. It guards the CUDA pre-parse blank (execution-space +specifiers + `<<>>` launch configs, offset-preserving and +brace-balance-checked) and macro-defined-kernel name recovery. The corpus +(`crates/codegraph-bench/fixtures/cuda/kernel.cu`) defines a `__global__ void +add_kernel`, a templated `__global__ scale_kernel`, a +`DEFINE_FLASH_FORWARD_KERNEL(my_kernel, …)` macro-defined kernel, and a `launch` +host function with a plain launch and a templated launch. The golden must show: + +- `kernel.cu` with `"language": "cpp"`; +- `add_kernel`, `scale_kernel`, `my_kernel`, `launch` as functions — the + macro kernel under its real name `my_kernel`, NOT `DEFINE_FLASH_FORWARD_KERNEL`; +- host→kernel `Calls` edges `launch` → `add_kernel` and `launch` → `scale_kernel` + (the `<<<…>>>` blank restores the call; the templated launch rides the + already-landed template-argument strip). + +The CUDA blank fires for `.cu`/`.cuh` files OR any C/C++-family file whose content +carries a strong CUDA marker (`__global__`/`__device__`/`__constant__`/ +`cudaStream_t`), so CUDA living in `.h`/`.hpp` headers is recognized. + +Regenerate both new fixtures reproducibly (identical recipe to the C++ fixture, +substituting `metal`/`cuda`): + +```bash +rm -rf /tmp/cg-fixture-metal && cp -r crates/codegraph-bench/fixtures/metal /tmp/cg-fixture-metal +cargo build --release -p codegraph-rs +CODEGRAPH_NO_DAEMON=1 CODEGRAPH_NO_WATCH=1 ./target/release/codegraph init /tmp/cg-fixture-metal +cp /tmp/cg-fixture-metal/.codegraph/codegraph.db reference/golden/metal/colby.db +cargo run -p codegraph-bench --bin bench -- --gen-golden reference/golden/metal/colby.db reference/golden/metal +# …and the same for cuda. +``` + +The `generated_golden_matches_committed_{metal,cuda}_fixture` and +`{metal,cuda}_db_is_self_equivalent_to_{metal,cuda}_golden` tests in +`crates/codegraph-bench/tests/equivalence.rs` enforce byte-stability. + ### KNOWN_DIFFS.md format Tier-3 differences are allowlisted by grep-able lines in repo-root diff --git a/reference/golden/cuda/colby.db b/reference/golden/cuda/colby.db new file mode 100644 index 0000000000000000000000000000000000000000..0981683f1d8e1118cf8288ccddf1ac44a8a61d7c GIT binary patch literal 151552 zcmeI5TW}lKdB=CLxDcSorA*1N?8sbEQpt@-i2zBElB*_^2+4?O&>=xvij$y=-37T8 zxS(*MM0;G9R@`KoWTv;5K4da^NT1Taq;1B@WTu_EGfAdxrcEYIGKnW?>NaiDcATVX zQ)lX)%VHM`0R&~swk-d5NbH{5_nq@Q_j48p%kN#VYNk>wSJt(fGARrQfq?LCMG*u+ zBL7Fpf8!b^4?)LpnA}C@xp8-lzMCW*-~333dX`_N4oBseW1osG_Pi215*ZACDg0D; zF!Wrg5PUiK3F*7imB34ZrvrOM*(c+TG;BY;KXTu}c+d5fTE$vjH7j=6FspgZV)wI4 z>A755$t`8hpHD9-4L4=(T#gts+2!<7PFc)y2jxuqd?p)H$mO_XvbjYkP_b4Wt(31? z#+X9?ZEf8gQ?Astl2x=!BhSr7S+A04*sEho)mpW+TD@YbOyDDP3oGemWi*?9^tdC2 zK2lNi&V$pZR*}@MNh~#bq92H*v-72Wk@)zyxZPXR3MG>#k;FEym+c~n1jFH(_cxHt zomogLBdyLOqnDM3mog8{EnQMBq%Vyro2v3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p$s&XyLVko<`$e`v+Js?EN8Ok6_VT2eB?}$ z%o;k@@UW+rhKJdC4G%NA4G#}X%2AE<;iq|78Sz=>S(P|F!fqom_5Cs%5I^bmx;$#7 z@>R3K29nIY*GYxf|F?Q`yPHuKbd<(lRn2}f79?Ygz83Lx(2}QP0VZakgLK!IC!AT) zfh*~MNatQ-Le!PMmLZZ8J7FBwN<1T8uGA zE?9?_Z%XQGfo;z#s zJCPNjPA-~lSaeyq%9N6IqH*Ot%VhSaRVvyR8~VCqDu1+;`SiKDm4%!#;tYQqgSt-M z>h@*3eARY*dnvBg3vQBlO3p1Vr8DQVbV*zBEy1eFQuNCUPNIV`FKXjPoHBCd6ef0S9m03BtNynQ!?#)v!hQJx_=hw8V|>=edCLU{*uUX@b$`eE^Z-ocSU%J#x@NL<5iGyfo|fk;?Z35c$lUN$1S`)46eG7 zN#5>^uh8@O@3y#e6+QtxnY$GbQ=i=ou-y1)(+hFv-pOy4}GGm9V1+cO`)rApdeglij9O zwF(y5c;g#;JX5VIc@cc0Tp{~*uKq^ZaVj|RqE)wSeFt}vjGDER2dzNXoXOkfon#oM zUan}hMnmG&0ZEeszs*qVNSy1ZSom5P+qHX7?cb<6KD%s`AI#~vPf~1nWpCFrh z^-@h?-dMpIHIJ_zSI!o$qnx-?E*3I=*hc&M># zk>QeFu{P+p1sK$r+84MY92DOr$bTX~E(mNKkCQ+e~nJX2qrcf9&K!i^Fbc=|GhU0 zu>X(!e=;1#{y+Br*$bE0|8IVkwCT+T?EmxEuh?wdzW~7}-tMfO8?pb7{eS0ezfpg2 Nxdr?Gug7M`{{wXqm74$n literal 0 HcmV?d00001 diff --git a/reference/golden/cuda/edges.json b/reference/golden/cuda/edges.json new file mode 100644 index 00000000..4edd05cf --- /dev/null +++ b/reference/golden/cuda/edges.json @@ -0,0 +1,62 @@ +[ + { + "col": 4, + "kind": "calls", + "line": 16, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "function:8fcfc4f43bf1b07028d15edababdbdf7", + "target": "function:290ca38de34bc728b62b2c22dce9be77" + }, + { + "col": 4, + "kind": "calls", + "line": 17, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "function:8fcfc4f43bf1b07028d15edababdbdf7", + "target": "function:d566ed55561eb4c96162668d7f78d9fb" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:kernel.cu", + "target": "function:290ca38de34bc728b62b2c22dce9be77" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:kernel.cu", + "target": "function:8ad1cefc2328c8b073c2e06a7d984a1d" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:kernel.cu", + "target": "function:8fcfc4f43bf1b07028d15edababdbdf7" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:kernel.cu", + "target": "function:d566ed55561eb4c96162668d7f78d9fb" + } +] diff --git a/reference/golden/cuda/files.json b/reference/golden/cuda/files.json new file mode 100644 index 00000000..e8c574ba --- /dev/null +++ b/reference/golden/cuda/files.json @@ -0,0 +1,10 @@ +[ + { + "content_hash": "3f2656febed2ea1c1ae2498e3361ad5d667edc05d4abf561a0b189eddfe4d113", + "errors": null, + "language": "cpp", + "node_count": 5, + "path": "kernel.cu", + "size": 452 + } +] diff --git a/reference/golden/cuda/nodes.json b/reference/golden/cuda/nodes.json new file mode 100644 index 00000000..cdfb2900 --- /dev/null +++ b/reference/golden/cuda/nodes.json @@ -0,0 +1,112 @@ +[ + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 19, + "file_path": "kernel.cu", + "id": "file:kernel.cu", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "cpp", + "name": "kernel.cu", + "qualified_name": "kernel.cu", + "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": 4, + "file_path": "kernel.cu", + "id": "function:290ca38de34bc728b62b2c22dce9be77", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "add_kernel", + "qualified_name": "add_kernel", + "return_type": null, + "signature": null, + "start_column": 11, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 13, + "file_path": "kernel.cu", + "id": "function:8ad1cefc2328c8b073c2e06a7d984a1d", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "my_kernel", + "qualified_name": "my_kernel", + "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": 18, + "file_path": "kernel.cu", + "id": "function:8fcfc4f43bf1b07028d15edababdbdf7", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "launch", + "qualified_name": "launch", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 15, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 9, + "file_path": "kernel.cu", + "id": "function:d566ed55561eb4c96162668d7f78d9fb", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "scale_kernel", + "qualified_name": "scale_kernel", + "return_type": null, + "signature": null, + "start_column": 11, + "start_line": 7, + "type_parameters": null, + "visibility": null + } +] diff --git a/reference/golden/cuda/refs.json b/reference/golden/cuda/refs.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/reference/golden/cuda/refs.json @@ -0,0 +1 @@ +[] diff --git a/reference/golden/cuda/schema.sql b/reference/golden/cuda/schema.sql new file mode 100644 index 00000000..d36218fe --- /dev/null +++ b/reference/golden/cuda/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); diff --git a/reference/golden/metal/colby.db b/reference/golden/metal/colby.db new file mode 100644 index 0000000000000000000000000000000000000000..9d849d30f61baf4a88a627d98759d657a71f4977 GIT binary patch literal 151552 zcmeI5eQX?QeaB~Z_SKF(Nt|Racla`w#I=XmiS1o`?OdbQi8o;{KKpRicb6VwnVp$+ z=CYo3c4zZ;I-kvEQu0>M(ZoRf zbMa^61F=uX%F)-NACbNxU5UIJc`mX?lmjx}OvlD^`x6fgrjswMICX1v)vVh!!)%l^ ziyhA_=jV!frMO%;cP_uIcwx%i*&=Zk7BA$Ni^|d>4^U3$&lMJX6!LLH3X8=hH&MlD zjMQt_EMrum|F*Vfjw)B0TGgsprcvTx!f-BFCxipNw3)zk_m>R z<=*chnLE9ZSBAsE!y}iK$Ce9^&MjY5&gU2FjpyT$E>f7D(eKxXuG!dU^P_Yr}re%s@kE%nxnNcU=Y{dZaJWV-3wZ- z*7VD~tQ)6xC(?%wC7(YZEUd4`)$n*>xwta7pcGjx`k~6og~H-Fh1B-c2y1qv$n414 z7ds2JFXq>3U(D&ZFP@gPBgeFzQ@pJV2RuuxEuR`@hv6Re9dbN9l@_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jA#Qs0_|J}R&MuN@dHthfZJT^Q2AJbcg Af&c&j literal 0 HcmV?d00001 diff --git a/reference/golden/metal/edges.json b/reference/golden/metal/edges.json new file mode 100644 index 00000000..e50eb624 --- /dev/null +++ b/reference/golden/metal/edges.json @@ -0,0 +1,59 @@ +[ + { + "col": 11, + "kind": "calls", + "line": 23, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "function:06d476406c9dac14172f0784bdcf3614", + "target": "function:0dd9c7c67cf2c6ae7a23bbbd5b2e5078" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:shader.metal", + "target": "function:06d476406c9dac14172f0784bdcf3614" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:shader.metal", + "target": "function:0dd9c7c67cf2c6ae7a23bbbd5b2e5078" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:shader.metal", + "target": "struct:71307e3c8493876bbef9b6575c1dabc4" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:shader.metal", + "target": "struct:ce73931d0e937bddde9dd6094c56cfad" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:shader.metal", + "target": "struct:ea772be38f713c9777b2e8c23ddf6638" + } +] diff --git a/reference/golden/metal/files.json b/reference/golden/metal/files.json new file mode 100644 index 00000000..84c7f7c8 --- /dev/null +++ b/reference/golden/metal/files.json @@ -0,0 +1,10 @@ +[ + { + "content_hash": "42a8ea57f43a0da7ea71ed53775560358fbfe499ed6414bb0be9a2cb43eeda30", + "errors": null, + "language": "cpp", + "node_count": 6, + "path": "shader.metal", + "size": 340 + } +] diff --git a/reference/golden/metal/nodes.json b/reference/golden/metal/nodes.json new file mode 100644 index 00000000..b1eec34a --- /dev/null +++ b/reference/golden/metal/nodes.json @@ -0,0 +1,134 @@ +[ + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 25, + "file_path": "shader.metal", + "id": "file:shader.metal", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "cpp", + "name": "shader.metal", + "qualified_name": "shader.metal", + "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": 24, + "file_path": "shader.metal", + "id": "function:06d476406c9dac14172f0784bdcf3614", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "vertex_main", + "qualified_name": "vertex_main", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 22, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 20, + "file_path": "shader.metal", + "id": "function:0dd9c7c67cf2c6ae7a23bbbd5b2e5078", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "cpp", + "name": "tint", + "qualified_name": "tint", + "return_type": "float4", + "signature": null, + "start_column": 0, + "start_line": 18, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 11, + "file_path": "shader.metal", + "id": "struct:71307e3c8493876bbef9b6575c1dabc4", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "float2", + "qualified_name": "float2", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 8, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 6, + "file_path": "shader.metal", + "id": "struct:ce73931d0e937bddde9dd6094c56cfad", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "float4", + "qualified_name": "float4", + "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": 16, + "file_path": "shader.metal", + "id": "struct:ea772be38f713c9777b2e8c23ddf6638", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "cpp", + "name": "VertexIn", + "qualified_name": "VertexIn", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 13, + "type_parameters": null, + "visibility": null + } +] diff --git a/reference/golden/metal/refs.json b/reference/golden/metal/refs.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/reference/golden/metal/refs.json @@ -0,0 +1 @@ +[] diff --git a/reference/golden/metal/schema.sql b/reference/golden/metal/schema.sql new file mode 100644 index 00000000..d36218fe --- /dev/null +++ b/reference/golden/metal/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);