Skip to content
STIRUP

TECHNOLOGY INTELLIGENCE

Understand what's next.

AxiomCode's Formal Methods Improve Code Graph Accuracy

AxiomCode constructs code graphs using formal methods based on type inference, achieving higher accuracy in linking function calls compared to traditional tools like GitNexus and CodeGraph.

Share
AI-generated conceptual illustration accompanying: AxiomCode's Formal Methods Improve Code Graph Accuracy
AI-generated editorial illustration of the article topic; not a photograph, product screenshot or measured result.

Formal Methods in Code Graph Construction

Formal methods play a crucial role in the construction of AxiomCode's knowledge graph. Unlike traditional approaches that rely on syntactic patterns to infer function calls, AxiomCode uses logical rules derived from the receiver's declared and inferred type, similar to how a compiler operates. This method ensures that the graph accurately represents the relationships between functions, specifying exactly who calls each function and what each function calls. By grounding the graph in deterministic, language-aware rules, AxiomCode reduces ambiguity and potential errors that arise from guesswork in other graph-building tools. This approach is particularly advantageous in complex codebases where syntactic cues may be misleading or insufficient. As noted in the research, this formal method-based construction provides a more reliable foundation for tools that depend on accurate code analysis, such as refactoring assistants and automated testing frameworks.

Performance Metrics and Comparisons

In performance comparisons, AxiomCode's Graph demonstrates significant improvements over existing tools. When evaluated against the compiler's own answer for Java bytecode and TypeScript type checking across five open-source projects, AxiomCode achieved 96.5% accuracy for Java and 88.8% for TypeScript in linking calls to their exact targets, outperforming alternatives like GitNexus and CodeGraph. It also achieved an F1 score of 0.976 for Java and 0.896 for TypeScript in identifying file-level call relationships, surpassing the best CST-based approach (0.876 and 0.708).On 748 held-out bugs from Defects4J, AxiomCode selected tests that included every bug-revealing test for 94.9% of bugs, compared to 61.5% for the best CST-based graph builder. It also achieved an F1 score of 72.4 against Defects4J's own test selection. In a large JVM project with 181,355 methods, AxiomCode reported direct callers with a precision of 0.980, compared to 0.397 for CST-based name matching, at the same recall level.

Command-Line Interface and Usage

The AxiomCode Graph provides a command-line interface (CLI) for developers to explore and analyze code dependencies with precision. To install, users run npm i -g @axiomcode/code-graph (Hacker News Show). Once installed, the axiomcode command offers several subcommands. For example, axiomcode path main Ledger.put and axiomcode path main SqlStore.put (Hacker News Show) trace the call paths from a function to its dependencies, listing each function in the chain along with the relevant line of code. The axiomcode impact command identifies who calls a function, what changes to it affect, and which tests exercise it (Hacker News Show). The axiomcode tests command lists tests affected by uncommitted edits, including the last run command. Lastly, axiomcode link allows users to manually resolve unresolved calls, recording them in axiomcode-links.tsv for future reference (Hacker News Show). These tools help reduce rework by providing clear, formal insights into code structure and dependencies.

Graph Structure and Output

The AxiomCode Graph is structured as a single SQLite database file, .axiomcode/out/graph.sqlite, containing a consistent schema across all languages and their documentation. This schema includes components such as schema_guide, schema_queries, and schema_vocab, ensuring uniformity in how data is stored and accessed. Each edge in the graph is assigned a tier, which determines the level of certainty associated with the connection. Tiers include known_edge for exact resolutions, multi_inferred for multiple possible targets, boundary_lib for library references, and ambiguous_unknown for unresolved cases. The full schema is documented in graph/bundle/SCHEMA.md. To use the graph, users can execute commands such as bin/axiomcode ./out to generate the graph from a source tree. Testing is supported through various regression suites, including comparisons against ground truth from javac, javap, the TypeScript compiler, and CPython bytecode.

Testing and Validation

In testing and validation, AxiomCode Graph demonstrates significant improvements over existing methods. On 748 held-out bugs from Defects4J, AxiomCode selects tests that include every bug-revealing test for 94.9% of bugs, compared to 61.5% for the best CST-based graph builder (Hacker News Show). This performance is reflected in an F1 score of 72.4, matching the selection quality of Defects4J's own test suite. In another evaluation on five real commits from a large JVM project, AxiomCode reports direct callers with a precision of 0.980, significantly higher than 0.397 for CST-based name matching, while maintaining the same recall (Hacker News Show). The tool also provides a command-line interface for testing, with options to run regression suites and compare results against ground truth from javac, javap, TypeScript compiler, CPython, and parser-specific tests (Hacker News Show).

Sources and reporting notes

Based on published source material. No independent hands-on testing is claimed.

Read more