Rust: no CALLS edge for any call inside a user `macro_rules!` macro (macro_invocation has no `arguments` field)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 45/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- rust
- Domaine
- backend-api-design, devtools
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- C
- Étoiles
- 45.8k
- Forks
- 3.8k
- Merge moyen
- 2 j 18 h
- PR mergées (30 j)
- 108
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de DeusData/codebase-memory-mcp
-
bug ux/behavior
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
DeusData/codebase-memory-mcp#3191 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation enhancement parsing/quality ux/behavior
Difficulté 1/5 1-3 heures Accessibilité débutants 82/100
DeusData/codebase-memory-mcp#3131 · 1 commentaire · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
hook-augment: the five-row cap keeps the first five search_graph rows, so variables and modules displace function definitions (v0.12.1)Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouvertebug editor/integration parsing/quality ux/behavior
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
DeusData/codebase-memory-mcp#3062 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Generated client files (AGENTS.md block, SKILL.md) teach a call syntax no harness can executeOuvertebug documentation editor/integration parsing/quality
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
DeusData/codebase-memory-mcp#3050 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
editor/integration parsing/quality
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
DeusData/codebase-memory-mcp#2286 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de DeusData/codebase-memory-mcp
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
NVIDIA/open-gpu-kernel-modules#1635 ·
Les mainteneurs répondent en général sous 1 jour
-
iOS: the "Edit controls" button never hides, even with a controller connected, and covers the gameOuvertegame: 010065A014024000 ios
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
seedds/nxnative#3714 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours