Skip to content

ast-bro v4.10.0

Latest

Choose a tag to compare

@github-actions github-actions released this 03 Dec 03:04

1. High-Level Summary (TL;DR)

  • Impact: High. 57 PRs since 4.9.0, closing 54 issues and fixing 6 more in part. Most are call-graph answers that were wrong without saying so:

    • a C++ static helper took calls from other files;
    • a Go bare call bound to another package's function, and a Python open() to the project's open;
    • a production call bound to a test helper;
    • a name two functions share was answered as one;
    • a linked worktree counted every call twice.

    The C++ and Kotlin outlines gain most of what they were missing, and search stops printing megabyte chunks. The one new flag is context --kind. JSON changes are additive only.

  • Key Changes:

    • 🎯 Call resolution follows each language's scoping:
      • C++ internal linkage (#172);
      • Go package scope (#171);
      • Python import roots (#173), relative bindings (#150) and builtins (part of #166);
      • no method for a call without a receiver in Python, TS/JS and Rust (part of #167 and #109);
      • test helpers kept out of production (#177).
    • 🧭 A name several definitions share is answered per definition (#192): callers/callees print one section each, and context --kind callable|type picks between a function and a type with one qualified name.
    • 🧱 C++ and Kotlin outlines:
      • bases (#178), preprocessor conditionals (#182, #76), member shapes (part of #184) and export macros (#184);
      • Kotlin properties, constructor vals, enum entries and type aliases (#66).
    • 🔗 More calls reach the graph:
      • calls inside closures (#179, #130) and in Rust standard macros' arguments (#180);
      • Ruby lambdas, .() and attribute writes (#87–#89), and class << self (#85);
      • C# ?. calls (#185).
    • 📦 Deps:
      • tsconfig paths matched as tsc matches them (#141);
      • ./x.js resolves to x.ts (#134);
      • an assigned require is an import (#153);
      • Go raw-string imports resolve (#207).
    • 🔎 Search:
      • bounded excerpts instead of whole chunks (part of #195);
      • oversized files named (#112);
      • one build for concurrent first searches (#200);
      • torn or corrupted indexes rebuilt (#119, #202).
    • ⚡ Quadratic cases made linear: comment runs above a declaration (part of #196), and same-file call lookup (#197).
    • 🛡️ Robustness:
      • non-UTF-8 sources are read (#188);
      • a closed pipe exits 0, not 101 (#114);
      • an unwritable cache is reported once (#201);
      • a linked worktree is not walked twice (#187).

2. Visual Overview (Code & Logic Map)

Where a call f() without a receiver looks for its target in 4.10.0.

graph TD
    c["a call f() with no receiver"] --> l{"caller's language"}
    l -- "Go" --> g["own package (its directory), then dot-imports;<br/>functions only, never a method;<br/>none: unresolved (a builtin, or outside code)"]
    l -- "Python" --> p{"bound by an import,<br/>or defined in the file?"}
    p -- "yes" --> pa["pass A: Exact"]
    p -- "no, and f is a builtin's name<br/>with no star import" --> pb["the builtin: unresolved"]
    p -- "no" --> B
    l -- "TS/JS, Rust" --> m["methods dropped from the candidates"] --> B
    l -- "C++" --> k["another file's static or<br/>unnamed-namespace function dropped<br/>(headers excepted)"] --> B
    l -- "other" --> B
    B["pass B: candidates the language family can reach,<br/>test-only ones dropped for a production caller"] --> one{"one left?"}
    one -- "yes" --> e["Exact"]
    one -- "several" --> C["pass C: the caller's import closure"]
    one -- "none" --> u["unresolved"]

3. Detailed Change Analysis

Every before/after output, count and timing below was measured on the release binaries: 4.9.0 as published, and 4.10.0 as built by CI for this release, on macOS arm64. Each case ran in a fresh directory per binary.

🎯 Call resolution

C++ internal linkage (#172)

In a translation unit (.cpp, .cc, .cxx, .c++, .cu), a static free function, and anything in an unnamed namespace, takes calls from its own file only.

  • Prototypes: a definition after a static prototype of the same function inherits its linkage. "Same" means the same full name (a reopened namespace or N::f counts, templates too) and the same parameter types (const int x, int* for int[] and f() for f(void) all match).
  • Headers: they are untouched, since every file that includes one gets its own copy.
  • map --no-private and digest leave these functions out.
$ ast-bro callees use_b .        # 4.9.0
b.cpp:3     a.cpp::log_it  (Exact)
b.cpp:3     a.cpp::?::hidden  (Exact)
$ ast-bro callees use_b .        # 4.10.0
b.cpp:3     [unresolved] hidden  (Ambiguous)
b.cpp:3     [unresolved] log_it  (Ambiguous)

callers log_it goes from 2 callers, use_a and b.cpp's use_b, to use_a alone.

Go package scope (#171)

A Go call without a receiver looks in its own package, then in dot-imported ones. It never looks in another imported package, and never at a method. A builtin like min no longer binds to a project min.

Call in app/a.go 4.9.0 4.10.0
Helper() (also in app/b.go and in util) util/util.go::util::Helper (Inferred) app/b.go::app::Helper (Exact)
util.Helper() util/util.go::util::Helper (Inferred) unchanged
min(1, 2), the builtin util/util.go::util::min (Exact) [unresolved] min

Python (#173, #150, #166)

Case 4.9.0 4.10.0
import time beside a project pkg/time.py (deps) pkg/time.py (import) [external] time
from .globals import helper as h, then h() [unresolved] h (Ambiguous) pkg/globals.py::helper (Exact)
from pkg import helper with helper in pkg/__init__.py and a pkg/helper.py pkg/helper.py::helper (Exact) pkg/__init__.py::helper (Exact)
open("app.toml") beside a project open in another module helpers.py::open (Exact) [unresolved] open (Ambiguous)
  • Import roots: an absolute import matches only from an import root, and packages in a src/ layout are found by their __init__.
  • Builtins: a builtin's name with no import binding, no definition in the file and no star import is the builtin.

No method for a call without a receiver (part of #167 and #109)

In Python, TS/TSX/JS and Rust a method is called through self, this or Self::, so a bare call never binds to one. That includes the method itself: in impl W { fn flush(&self) { flush() } }, the call went from src/lib.rs::W::flush (Exact), a call to itself, to the free function src/lib.rs::flush (Exact).

Test helpers (#177)

A production call no longer binds by name to a function defined only in test code. Tests still reach their helpers.

$ ast-bro callees signup .       # 4.9.0
src/signup.php:2     tests/helpers.php::make_user  (Exact)
$ ast-bro callees signup .       # 4.10.0
src/signup.php:2     [unresolved] make_user  (Ambiguous)

Rust unit tests are test code (#186)

  • What counts: #[test], #[cfg(test)] modules and the files only they load.
  • Where it applies: --tests and --exclude-tests, impact --mode tests and review.
  • C and C++: _unittest suffixes, unittests/ directories and FooTest.cpp count as test files too.
src/lib.rs: run() and two #[test]s call compute 4.9.0 4.10.0
callers compute --tests 0 2
callers compute --exclude-tests 3 1 (run)

Smaller resolution fixes

  • Families: a type meets its bases, implementors and constructions within its own language family. A TS class no longer has a Python Base as its ancestor (#176).
  • Rust:
    • a generic impl<T> Foo<T> joins struct Foo (#98);
    • a grouped use a::b::{x} binds only x (#136).
  • Generic bases: a base written through a generic outer type (Outer<String>.Inner, or Scala's Outer[Int]#Inner) is matched as the inner type (#212).
  • Updates:
    • an incremental update re-resolves a call whose target gains a homonym, as a cold build would (#239);
    • callees come in source order, and --rebuild and an update agree on it (#90).

🧭 One name, several definitions (#192, #97, #252, #100)

$ ast-bro callers parse . --depth 2     # 4.9.0: one list
# 4 caller(s) for 'parse':
src/lib.rs:3     depth=1 src/lib.rs::load_json  (Inferred)
src/lib.rs:5     depth=2 src/lib.rs::app  (Exact)
src/lib.rs:4     depth=1 src/lib.rs::load_toml  (Inferred)
src/lib.rs:5     depth=2 src/lib.rs::app  (Exact)
$ ast-bro callers parse . --depth 2     # 4.10.0: one section per definition
# 4 caller(s) for 'parse' across 2 definitions:
## 2 caller(s) of src/json.rs::parse:
src/lib.rs:3     depth=1 src/lib.rs::load_json  (Inferred)
src/lib.rs:5     depth=2 src/lib.rs::app  (Exact)

## 2 caller(s) of src/toml.rs::parse:
src/lib.rs:4     depth=1 src/lib.rs::load_toml  (Inferred)
src/lib.rs:5     depth=2 src/lib.rs::app  (Exact)
  • Each definition gets its own count and its own share of --limit.
  • context --kind callable|type (MCP argument kind) picks between a function and a type that share one qualified name, such as Kotlin fun Job() beside interface Job. The note says which to pass.
  • Constructed classes:
    • callers Foo on a class built once goes from # 2 caller(s) (the construction counted again as a call) to # 1 caller(s);
    • impact Foo goes from a function report with the note 'Foo' matched 2 symbols to one class report and no note.
  • MCP: callers and callees answer type targets as the CLI does, and reject a name nothing declares. MCP context puts the ambiguity note in the response itself.
  • --limit order: production callers come before test callers when the list is cut (part of #191).

🧱 C++ and Kotlin outlines (#178, #182, #76, #184, #66)

  • Preprocessor conditionals: declarations inside #if, #ifdef and include guards are read in C++ and C#, except a switched-off #if 0.
  • Member shapes:
    • methods returning * or &, conversion operators, member templates and nested types;
    • int a, b;, function-pointer fields, union, typedef struct {…} P; and extern "C";
    • definitions keep their parameters: int add(int a, char b) was shown as int add().
  • Export macros: class MYLIB_API Foo is a class again.
  • Bases: C++ and Kotlin types record their bases, so implements, callers <Type> and context <Type> see their hierarchy.
  • Kotlin: properties, constructor val/vars, enum entries and type aliases are outlined.
Corpus 4.9.0 4.10.0
aws-lc, all 369 C++ files: declarations 7,578 10,008
aws-lc: classes and structs with bases recorded 0 of 435 352 of 620
leveldb's 15 public headers, renamed .hpp*: classes and structs, members 0, 0 56, 252

* .h files are not parsed as C++ (#235), so the headers were renamed to measure them.

🔗 More calls reach the graph (#179, #130, #180, #87–#89, #85, #185)

  • Closures and lambdas: a call inside one belongs to the function around it, in Rust, Java, Kotlin, Scala, C#, C++ and Go.
  • Rust standard macros: calls in the arguments of the format!, print!, write!, panic! and assert! families, plus vec! and dbg!, reach the graph. On ast-bro's own source, callers cache_is_valid goes from 2 callers to 12.
  • Ruby:
    • calls in -> { } count for the method around them;
    • Job.(1) calls call;
    • Conf.level = 3 calls the setter level=;
    • class << self methods are outlined and in the graph.
  • C#: s?.Compute() resolves to Compute, and : Base(arg) is the base Base.

📦 Deps (#141, #134, #153, #207)

Case 4.9.0 4.10.0
ky: direct importers of source/index.ts (they write ./index.js) 0 36
const { parse: p } = require('./lib/utils') (deps) (no imports) lib/utils.js (import)
… and the call p('x') [unresolved] p (Ambiguous) lib/utils.js::parse (Exact)
import m `example.com/shop/model` (deps) [external] `example.com/shop/model` model/m.go (import) [as m]
  • tsconfig paths: keys match as tsc matches them. Later targets are tried, the "*" key works, exact keys stay exact, a suffix after * counts, and the longest prefix wins.
  • nodenext: a TS import of ./x.js, .jsx, .mjs or .cjs resolves to the TypeScript source, as tsc does.

🔎 Search (#195, #112, #200, #119, #202, #118)

  • Bounded excerpts: a hit prints the chunk whole only up to 4 KB with no line over 300 characters. A larger chunk prints an excerpt around the query term and a line saying where the rest is. --json still carries the whole chunk.

    Case 4.9.0 4.10.0
    search "filter map call" -k 5 beside a 1.4 MB minified bundle, stdout 1,414,221 bytes 721 bytes
  • Oversized files: files left out for being over 2 MB are named at build, under index --stats, and in a note on every search.

  • Concurrent first searches: they build the index once; the others wait and load it.

  • Damaged indexes: an index write that stopped partway, or a cache whose bytes changed, is rebuilt rather than served. graph.bin and the index files now end in a checksum.

  • find-related: it leaves out the source's own code, and after an edit reads the new text.

⚡ Performance (#196, #197)

Case 4.9.0 4.10.0
map, TypeScript file with 26,000 comment lines above one function (1.2 MB) 10.58 s 0.04 s
map, Rust file with 300 functions under 1,000 doc lines each (13 MB) 56.12 s 1.62 s
cold callers, Go file with 53,000 methods that each call the file's helper 4.70 s 1.26 s

Python's share of #196 is in tree-sitter-python's scanner and stays open.

🛡️ Robustness and output

Case 4.9.0 4.10.0
ast-bro map src | head -1, exit code 101 (panic) 0
callers foo with two linked worktrees of the repository inside it 3 callers 1 caller
  • Text encodings (#188): a source file that isn't UTF-8 is read: UTF-16 with a BOM is transcoded, anything else decoded lossily. It used to be dropped silently.
  • Unwritable cache (#201): one stderr note says every command rebuilds the graph, instead of silence.
  • CRLF (#189): a CRLF conversion is formatting only in diff, and docs carry no \r.
  • show (#193, #55, #146): every name asked for keeps a match under --limit. Markdown headings holding / or a dot are found by their name.
  • digest (#78): Markdown headings past level 3 are flattened, not dropped.
  • Go types (#206): a type's range stops at the type, not at its last method.
  • implements --direct (#80): the header no longer says (incl. transitive).
  • Hook (#194): a failed Read's map fits Claude Code's 10,000-character cap on added context, so the model gets the map rather than a path and a preview.

4. Impact & Risk Assessment

  • ✅ No breaking changes to flags or schemas.

    • One flag is added, context --kind, with the MCP argument kind. No default changed.
    • JSON changes are additive, and every schema version is kept. In the 23 --json answers of 4.9.0 and 4.10.0 on this repository, no key was removed. The keys added are:
      • callers/callees: definitions and matches[].definition;
      • show: per_symbol;
      • context: candidates, candidates_total and candidates_truncated;
      • search and find-related: oversized.
    • The agent prompt (ast-bro prompt) gains two sentences, one on per-definition caps and one on --kind.
  • ⚠️ Behavioural changes worth knowing about:

    • Rows and counts:
      • a callers/callees answer for a shared name groups its rows by definition, in text and in JSON;
      • callers <Class> counts a construction once;
      • under --limit, production callers come first.
    • MCP: callers and callees return isError for a name nothing declares, where they returned an empty answer. MCP text is never coloured.
    • Outline:
      • map --no-private and digest drop static and unnamed-namespace functions in C++ source files;
      • Rust methods of a generic impl move under their type, so their qualified names change.
    • Resolution:
      • some calls that 4.9.0 bound Exact by a lone name match are now unresolved, by each language's scoping rules (Go, Python builtins, C++ static, test helpers);
      • Python 2-style implicit relative imports (import utils for a sibling) stop resolving;
      • a TS import of ./x.js beside both x.ts and x.js goes to x.ts.
    • Search text output shows excerpts for large chunks.
    • The first command after upgrading rebuilds the graph cache (schema v15) and the search index, as every release does.
  • 📌 Known gaps:

    • C++: prototypes at file scope are not outlined (#217), and .h headers are not parsed (#235).
    • C++ internal linkage: a static prototype in a header with its definition in the .cpp isn't seen, and a typedef that respells a parameter type misses its prototype.
    • Methods for bare calls: Java, C#, Kotlin, Scala, C++, Ruby and PHP still bind a call without a receiver to a method (#109, #167, #168).
    • Python: a parameter's callback() and locals still bind by name (#166).
    • Go: a method declared in another file from its type loses the type (#183).
    • Search: telling a generated file from its content (#195), and Markdown chunking (#59).
    • MCP: hints say raise --limit where the parameter is limit (#191, #58).