Skip to content

Latest commit

 

History

History
272 lines (214 loc) · 13 KB

call-resolution.md

File metadata and controls

272 lines (214 loc) · 13 KB

Call resolution

Trailmark resolves calls by name and scope, not by type checking. Calls it cannot resolve are kept as edges to proxy.unresolved: nodes (see Proxy nodes). This page covers how to measure those gaps and what they mean for reachability results.

The report

trailmark analyze --language rust --resolution path/to/project

For this file:

struct Engine;
impl Engine {
    fn execute(&self) {}
}

fn make() -> Result<Engine, ()> { Ok(Engine) }

fn handle(engine: &Engine, value: Option<u8>) {
    value.unwrap();
    value.unwrap();
    engine.execute();
    helper();
}

fn helper() {}

the report is:

{
  "call_sites": 5,
  "resolved_call_sites": 1,
  "unresolved_call_sites": 4,
  "unresolved_targets": 3,
  "affected_callers": 2,
  "unresolved_by_callee": [
    {"callee": "unwrap", "call_sites": 2, "targets": 1},
    {"callee": "Ok", "call_sites": 1, "targets": 1},
    {"callee": "execute", "call_sites": 1, "targets": 1}
  ]
}
Field Meaning
call_sites Every calls edge: extracted call expressions, plus any calls links from .trailmark/links.toml and imported binary calls. Repeated calls count separately.
resolved_call_sites Calls whose target is not an unresolved proxy: a declaration (here, helper()), or an external proxy from a declared link or binary import
unresolved_call_sites Calls that point to a proxy.unresolved: node
unresolved_targets Distinct unresolved proxy nodes
affected_callers Functions with at least one unresolved call
unresolved_by_callee Unresolved calls grouped by the final name in the call expression, sorted by call-site count (descending), then name

engine.execute() is unresolved even though engine is declared &Engine, because Trailmark does not use parameter annotations to infer receiver types. The unwrap group is a syntactic label: it does not identify which unwrap implementation is called. Calls to proxies that were explicitly declared external in .trailmark/links.toml are not counted as unresolved.

Inspecting call sites

engine = QueryEngine.from_directory("./project", language="rust")
engine.call_resolution()            # the report above
engine.unresolved_calls()           # every unresolved call site
engine.unresolved_calls("handle")   # only calls made directly by handle

Each row has the caller (source), the proxy ID (target), the raw call text (raw_target), the final name (callee), the edge confidence, and the call site's location (or None if unavailable). A proxy node's own location is only its first occurrence; use each row's location when a call repeats. A name that matches no function returns [].

Solidity receiver calls inside comparisons retain the callee text and each call's own span, excluding preceding comparison operands. Repeated calls to the same unresolved receiver member share a proxy while retaining separate call-site rows.

The report and unresolved_calls() work for every supported language.

What unresolved calls mean for results

A proxy marks where Trailmark stopped following a path. Reachability queries, entrypoint paths, and preanalysis cannot continue past it to the real implementation, so effects of that implementation are missing from their results. In the README example, handle_request does not appear in ancestors_of("Auth._check_sig") for this reason.

To close a gap you have reviewed:

Hiding common proxy names, such as unwrap, does not restore the missing paths.

What the report does not measure

The report counts the calls Trailmark extracted, not overall program coverage. Code inside macros that are not expanded and implicit calls such as destructors produce no call sites, so they are outside its counts. Zero unresolved calls is not proof that the graph contains every executable path. A large number of proxies does not mean calls were dropped; each one is a call that was kept but not resolved.

C++ out-of-line methods

Simple qualified definitions such as Stream::flush and Stream::~Stream attach to an identifiable class or struct. A same-file declaration takes precedence; a cross-file owner must be unique. Namespace-qualified free functions, template-qualified owners, and ambiguous class owners are not reclassified. Existing definition IDs are preserved, while method names and containment reflect the class owner.

Bare calls within those methods can navigate to a unique method in that class. Overloads and shadowing local values remain uncertain; header prototypes do not compete with extracted method definitions.

Dart explicit receivers

An explicit this.method(...) call can navigate to a unique method in its nearest lexical class with inferred confidence. A local value with the same method name does not shadow explicit this. Missing and inherited methods, chained receivers, and other value receivers remain unresolved. Calls through super.method(...) retain their source sites without guessing inheritance.

Dart declared factory results

A direct final value = factory(...) initializer can provide a receiver type for subsequent value.method(...) calls in the same straight-line block. The factory must already resolve to an ordinary function or method in the same file and declare a simple class return type. A unique method in that class becomes an inferred target. Mutable locals, captured or nested uses, callable getters, generic parameters, type aliases, and nullable or compound return types do not receive this inference.

Cross-file class lookup accepts directly imported, inspected relative .dart files. Prefixed, filtered, conditional, package, missing, and re-exported type scopes remain conservative. This pass does not propagate arbitrary expression types or infer a factory's return type from its implementation.

C# qualified static calls

An explicit Type.Method(...) call can navigate to a unique declared static method in its namespace or enclosing type scope. Matching partial class declarations are considered together across inspected files. Targets use inferred confidence; overloads, generic type owners, aliases, value receivers, and incomplete inherited scopes remain uncertain. global:: qualification starts at the global namespace.

Namespace imports do not justify guessing an outer type. Nearer namespace/type names stop fallback, and local, parameter, pattern, catch, loop, lambda, and partial-class value bindings block type interpretation. Calls are reconsidered after directory merging so later declarations can retract a per-file candidate.

Rust limits

Rust code commonly produces many proxies. Common patterns:

Pattern Behavior
Standard methods: .unwrap(), .expect(), .clone(), .len() Calls are kept; receiver types and dependency implementations are not inferred
Iterator chains: .iter().map(...).collect() Each call is kept; intermediate result types are not propagated
Trait conversions: .into(), .try_into(), TokenId::try_from() Trait implementations and generated methods may stay unresolved
External crates: UdpSocket::bind(), prost_build::Config::new() Dependency source is not loaded
Generated builders: Action::builder().timestamp(...) Calls are kept; the macro that generates the builder is not expanded
Local value receivers: engine.execute(), self.side.converse() Receiver types are not inferred, even from explicit parameter annotations
Enum constructors: ActionKind::Deposit(1), Ok(...), Err(...) Parenthesized constructors are calls and can stay proxies; a bare variant value is not a call

Declared return types are recorded but do not resolve later calls on the returned value. Given make() -> Result<Engine, ()>, the chain make().unwrap().execute() records three calls, to make, unwrap, and execute, but does not link execute to Engine.execute.

See Rust and Verus for the scoping rules that do resolve.

Julia

The .jl frontend extracts modules, structs, abstract and primitive types, long and short function definitions, typed/default/variadic parameters, explicit return types, branches, and using/import dependencies. A synthetic file:<script> function owns top-level calls; module bodies have their own script node. Anonymous functions and do blocks own their calls and branches.

Multiple dispatch is not inferred. Every same-name method survives with an @line_column ID suffix, and calls to that name stay uncertain. A unique, unshadowed lexical function can resolve as inferred; script calls must follow its declaration. Conditional definitions and parameter/local/loop bindings block inference. Nested modules do not inherit enclosing module bindings. Qualified, broadcast, constructor, callable-object, imported/aliased, and cross-file calls remain uncertain proxies. These are syntax-based candidates, not Julia compiler resolution or a guarantee about runtime dispatch.

Literal include("helpers.jl") paths become dependencies. Interpolated or computed paths do not. include, include_string, eval, and explicit global mutation disable local inference throughout the file. No Julia code is executed. The parser traverses @inline and @noinline wrappers. Other macro calls warn that expansion was skipped and disable local inference; their bodies and macro definitions are not expanded. Generated methods, implicit constructors, compiler entrypoints, and operator desugaring are not invented. A missing edge is not proof of dead code. main follows the generic entrypoint rule; script execution needs an entrypoint override. Syntax errors warn that the graph may be incomplete.

Dart constructors

Dart constructor calls resolve to a unique constructor declaration in the same file when the class name is unshadowed. This includes named constructors such as Context._internal() and calls made inside factory constructors. The calls edge targets the constructor method, preserving its source site for caller and callee queries. Constructor binding has inferred confidence. Imported class aliases and inferred receiver types do not participate in constructor type lookup.

Swift self and cleanup

An explicit self.method() call resolves to a unique method on its nearest lexical type, including merged extensions. Capture rebinding, syntax recovery, and lexical binding barriers block this inference. Overloads and other value receivers remain unresolved; Trailmark does not perform Swift type checking or infer inherited implementations. These local method bindings have inferred confidence.

A Swift defer body belongs to its enclosing function or method. Its calls and branches retain that owner; defer does not create a function call or a closure node. Actual closures nested inside cleanup code keep their own nodes and calls.

C# construction

Explicit C# new Type(...) expressions retain constructor call sites, including construction inside a throw expression. A unique declared instance constructor in the same file can resolve with inferred confidence. Static constructors are excluded. Missing, implicit, generic and overloaded constructors remain uncertain proxies; Trailmark does not select overloads by argument types. Import aliases and generic type parameters block constructor type lookup. Potentially competing namespace imports block binding to outer namesakes. A global:: type qualification retains its absolute meaning.

C# optional-default overloads

C# bare calls have one bounded overload tie-breaker: when all declared candidates have identical provided parameter types, a unique declaration with every parameter supplied wins over declarations that need optional defaults. This inferred binding requires ordinary positional arguments, one nongeneric class/struct declaration context, and no uninspected base-class family. Named arguments, generic methods, params, reference parameters, virtual methods, differing provided types, and families spread across declaration contexts remain uncertain. Directory merging rechecks the family and can retract an earlier per-file selection.

C++ cast receivers

C++ retains declared-member navigation for static_cast<EnclosingClass&>(value).method() inside that class's member functions, including identifiable out-of-line definitions. The injected class name and a unique declared method must remain unshadowed; prototypes count toward overload ambiguity. Local type aliases, generic classes, member using-declarations, and incomplete or duplicate method families keep their proxies. A plain nonvirtual method in a class without bases receives inferred confidence. An explicit virtual method or any source base clause makes the concrete declared target uncertain and adds cpp_cast_dispatch_uncertain=True, even when the base is unavailable. This is source navigation to the declared member; it does not claim an exhaustive set of runtime dispatch targets.