Rust: no CALLS edge for any call inside a user `macro_rules!` macro (macro_invocation has no `arguments` field)
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 45/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- rust
- Domínio
- backend-api-design, devtools
Direção de pesquisa
Start with internal/cbm/lsp/rust_lsp.c, especially rust_expand_user_macro, rust_walk_macro_tokens, and rust_inject_syn_call, then trace how call sites reach src/pipeline/pass_parallel.c:3170. Reproduce with the macro-probe example in the issue and inspect the indexed CALLS edges. Done means calls in macro arguments produce edges with source lines, with a regression test covering the behavior; the issue shows that fixing the token-tree lookup alone does not achieve this.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Version: codebase-memory-mcp v0.12.1 (pkg/go/v0.12.1, a7158ac2). The same two lookups are on
main at 612eee25 (internal/cbm/lsp/rust_lsp.c:3562 and :4861).
What I did
I indexed jdx/mise v2026.11.2 and looked at install_missing_runtimes in src/cli/install.rs.
Its body wraps a call in mise's own timing macro:
measure!("install_all_versions", { ts.install_all_versions_with_progress(…) })
measure! is #[macro_export] macro_rules! measure { ($fmt:expr, $block:block) => {{ … $block … }} }
in src/timings.rs:93.
What happened
The function has CALLS edges for line 717 and then line 730, and none for lines 718-729, the whole
measure! body.
Minimal repro
Cargo.toml:
[package]
name = "macro-probe"
version = "0.1.0"
edition = "2021"
src/timings.rs:
#[macro_export]
macro_rules! measure_x {
($fmt:expr, $block:block) => {{ $block }};
}
src/main.rs:
#[macro_use]
mod timings;
macro_rules! measure_l {
($fmt:expr, $block:block) => {{ $block }};
}
macro_rules! body_l {
() => {{ Ts.via_body() }};
}
fn free_body() -> u32 { 5 }
fn free_print() -> u32 { 7 }
fn free_arg() -> u32 { 6 }
macro_rules! body_f {
() => {{ free_body() }};
}
struct Ts;
impl Ts {
fn via_local(&self) -> u32 { 1 }
fn via_cross(&self) -> u32 { 2 }
fn via_plain(&self) -> u32 { 3 }
fn via_body(&self) -> u32 { 4 }
}
fn run() -> u32 {
let ts = Ts;
let a = measure_l!("l", { ts.via_local() });
let b = measure_x!("x", { ts.via_cross() });
let c = ts.via_plain();
let d = body_l!();
let e = body_f!();
let f = measure_l!("f", { free_arg() });
println!("{}", free_print());
a + b + c + d + e + f
}
fn main() { run(); }
It builds and prints 7. Make the folder a git repo with one commit, then:
codebase-memory-mcp cli index_repository '{"repo_path":"<abs>/macro-probe","name":"macro-probe","mode":"full"}'
codebase-memory-mcp cli query_graph '{"project":"macro-probe","query":"MATCH (a:Function {name:\"run\"})-[r:CALLS]->(b) RETURN b.name, r.line, r.strategy"}'
via_plain "32" lsp_method_dispatch
free_print - lsp_direct
run makes seven calls; only the first two get an edge:
| call | edge? |
|---|---|
ts.via_plain() |
yes |
free_print() inside println! |
yes (the edge has no line number) |
ts.via_local() passed as $block to the same-file measure_l! |
no |
free_arg() passed as $block to the same-file measure_l! |
no |
ts.via_cross() passed to the #[macro_export] measure_x! from timings.rs |
no |
Ts.via_body() written in the same-file body_l!'s own transcriber |
no |
free_body() written in the same-file body_f!'s own transcriber |
no |
Why
The pipeline only makes an edge for a syntactic call site (src/pipeline/pass_parallel.c:3170,
src/pipeline/pass_calls.c:1374). The LSP's resolved_calls are looked up for those sites. Inside
a macro, the tree-sitter-rust grammar gives the arguments as a token_tree with no
call_expression in it, so the generic extractor finds no site. The LSP adds synthetic sites
(rust_inject_syn_call, internal/cbm/lsp/rust_lsp.c:4045-4060) only for the built-in expression
macros (:3755-3772). Nothing covers user macros:
rust_expand_user_macro(rust_lsp.c:3526-3652) reads a field that doesn't exist. It takes the
invocation's arguments withts_node_child_by_field_name(invocation, "arguments", 9)(:3546).
In the vendored grammar,macro_invocationhas only amacrofield; itstoken_treechild has
no field name. (I checked this by loadinginternal/cbm/vendored/grammars/rustinto py-tree-sitter:
the children areidentifier(fieldmacro),!andtoken_tree(no field), and
child_by_field_name("arguments")returns nothing.) Soinv_argsis always NULL, no pattern
matches, and the first rule is used without substitution (:3571-3572):$blockis never
replaced by the caller's code.rust_walk_macro_tokensnever runs. Themacro_invocationhandler's fallback for every
other macro does the same lookup (:4816-4818), so it always gets a null node.- Expanded source gets no site anyway. The expansion is walked with
emit_site_start_byte=
emit_site_end_byte= 0 (:3635), and the comment at:2918-2920says "Generated macro_rules!
source has no faithful mapped site and stays semantic only." That matches the probe: even calls
written in the transcriber itself, which need no substitution, get no edge. - Rules are per file.
rust_collect_macro_rules(:3015-3050, called once at:5304) collects
definitions from the current file only, so a#[macro_export]macro used from another file, as
measure!is, is never expanded.
Proposal
- Find the argument
token_treeas the invocation's first namedtoken_treechild instead of by
field name, in both places (:3546and:4816). - Map calls in a substituted
$block/$exprfragment back to their bytes in the invocation, the
way the built-in expression macros are mapped (rust_map_source_range), and inject a site for
each resolved call. - Optionally, collect
#[macro_export]rules across the crate. - Add a test that indexes a call passed to a
macro_rules!macro and expects a CALLS edge with its
line.
Fixing the field lookup alone brings back no edge
I rebuilt v0.12.1 with both lookups replaced by "first named token_tree child" and indexed the
probe above again (a direct cbm_pipeline_run driver, like tests/test_integration.c). The CALLS edges
are the same as before: only ts.via_plain() and the call inside println!. With stderr prints
added, the expansion does now run with bound arguments, for example measure_l!("l", { ts.via_local() })
matches and expands to fn __cbm_macro_expand() { { { ts.via_local() } }; }. Each of the four
same-file expansions pushes one resolved call with the right caller (...main.run). They are
dropped later:
- The call-edge pass (
src/pipeline/pass_parallel.c:3170) loops over the extractor'sCBMCall
sites and only attaches a resolved call to one of them. The extractor sees atoken_tree, not a
call, so there is no carrier. - A resolved call can create its own carrier only through
rust_inject_syn_call, which pushes a
CBMCall(rust_lsp.c:4060).rust_emit_resolved_call_reasoncalls it only when
emit_site_end_byte > emit_site_start_byte(rust_lsp.c:4111-4113), and the expansion sets both
to 0. The comment atpass_parallel.c:4026-4032says this is on purpose: "Zero-span generated
semantics are excluded: without source provenance they cannot safely join a graph carrier." rust_walk_macro_tokensnow gets thetoken_tree, but it only looks forcall_expression,
macro_invocationandfield_expressionnodes (:2831-2846), which a token tree never has. It
pushed 0 resolved calls on every invocation.- The cross-file
measure_x!was never expanded (point 4).
So the field fix is needed but not enough: the second proposal item, a real site for each call in
a substituted fragment, is what would bring the edges back.
- Linguagem predominante
- C
- Estrelas
- 45.8k
- Forks
- 3.8k
- Merge médio
- 2d 18h
- PRs com merge (30d)
- 108
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de DeusData/codebase-memory-mcp
-
bug ux/behavior
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
DeusData/codebase-memory-mcp#3191 ·
Mantenedores costumam responder em até 1 dia
-
documentation enhancement parsing/quality ux/behavior
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 82/100
DeusData/codebase-memory-mcp#3131 · 1 comentário · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
hook-augment: the five-row cap keeps the first five search_graph rows, so variables and modules displace function definitions (v0.12.1)Talvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertabug editor/integration parsing/quality ux/behavior
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
DeusData/codebase-memory-mcp#3062 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
Generated client files (AGENTS.md block, SKILL.md) teach a call syntax no harness can executeAbertabug documentation editor/integration parsing/quality
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
DeusData/codebase-memory-mcp#3050 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
editor/integration parsing/quality
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
DeusData/codebase-memory-mcp#2286 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de DeusData/codebase-memory-mcp
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
NVIDIA/open-gpu-kernel-modules#1635 ·
Mantenedores costumam responder em até 1 dia
-
iOS: the "Edit controls" button never hides, even with a controller connected, and covers the gameAbertagame: 010065A014024000 ios
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
seedds/nxnative#3714 · 1 comentário ·
Mantenedores costumam responder em até 2 dias