TL;DR
This paper introduces a novel approach to automatically learn static analysis rules from data, addressing the challenge of building precise and scalable program analyzers. By combining a synthesizer with a counter-example guided learning loop, the method generates new programs to refine the analysis, leading to more robust and generalizable results than traditional manual methods.
What Problem Does This Paper Address?
Modern static analyzers are crucial tools for program verification, optimization, and bug finding. However, building analyzers that are both scalable and precise, especially for complex languages like JavaScript with extensive libraries, is a significant challenge. Manually crafting the inference rules that govern these analyzers is difficult because the effects of these rules can be non-trivial, and the sheer number of cases to handle grows with language and library complexity. Existing machine learning techniques often produce opaque models, making it hard to interpret or verify the learned rules. This paper aims to automate the creation of key parts of static analyzers by learning inference rules directly from a dataset of programs.
Methods
The core of the approach is a counter-example guided learning loop. It consists of three main components:
- Language (L): A domain-specific language (DSL) designed to express analysis rules. This DSL is loop-free and uses conditional
if-then-elsestatements, allowing for the representation of complex analysis logic. - Synthesizer: This component learns a candidate analyzer (a set of rules in L) from a given dataset of programs and their desired analysis outputs. It frames the learning problem as building a decision tree, adapting the ID3 algorithm.
- Oracle: This component tests the candidate analyzer. If it finds a counter-example (a program where the analyzer produces an incorrect result), it feeds this back to the synthesizer. The oracle uses program modifications (semantic-preserving or not) to generate these counter-examples efficiently.
The learning process is iterative: the synthesizer generates an analyzer, the oracle tests it and finds a counter-example if one exists, and the synthesizer uses this counter-example to refine the analyzer. This loop continues until no counter-examples are found, ensuring the learned analyzer is sound and precise on the training data and generalizes well.
Datasets
The paper uses the official ECMAScript (ECMA-262) conformance suite as its primary dataset. This suite contains over 20,000 test cases. For their experiments, they used a subset of 15,675 tests that the NodeJS interpreter could execute without syntax errors as the training dataset.
Key Insights and Ideas
- Counter-example Guided Learning for Static Analysis: The paper's main innovation is applying a counter-example guided learning loop, traditionally used in program synthesis, to the problem of learning static analyzers. This approach effectively combats overfitting by actively seeking out weaknesses in the learned analyzer.
- Domain-Specific Language for Rules: Designing a DSL that captures the structure of analysis rules (e.g., decision trees over AST traversals) is crucial for enabling effective learning. This allows the synthesizer to generate meaningful analysis logic rather than just opaque models.
- Balancing Precision and Soundness: The approach aims to learn analyzers that are both sound (correct) and precise (avoiding false positives). The cost function and the counter-example generation process are designed to achieve this balance.
- Learned Rules Outperform Manual Ones: The experiments show that the automatically learned rules for points-to and allocation site analysis are not only practical but also discover rules that are missed by state-of-the-art, manually tuned analyzers. This highlights the potential of data-driven approaches for complex static analysis tasks.
Key Results
The paper demonstrates the effectiveness of their approach on two challenging JavaScript analysis problems: points-to analysis and allocation site analysis.
- Points-to Analysis: The learned rules for JavaScript APIs (e.g.,
Function.prototype.call,Array.prototype.map) were able to capture complex behaviors related to thethiskeyword and object binding, which are often handled incompletely or incorrectly by existing analyzers. The learned analyzers were significantly more precise than trivial ones. - Allocation Site Analysis: The system learned rules that accurately identify object allocation sites, including tricky cases involving JavaScript's built-in constructors and expressions. The learned analysis was able to identify twice as many allocation sites as a simple, incorrect analysis.
- Efficiency: The counter-example guided search was orders of magnitude more efficient at finding counter-examples than a random search. The learning process, including counter-example generation, was completed within minutes to hours for various APIs.
Limitations and Future Work
- Limitations:
- The approach relies on having a dataset of programs with desired analysis outputs. Obtaining this data can still be a challenge, although the paper suggests methods for automation.
- The current implementation has some restrictions, such as filtering out programs using
eval, dynamic function binding (Function.prototype.bind), and theFunctionobject constructor, as these require more complex analysis techniques. Accesses to theargumentsobject were also filtered for allocation site analysis due to instrumentation limitations. - While the learned analyzers are correct on the training data and generalize well, formal verification of the learned analyzer against all possible programs is not guaranteed and is considered a separate, orthogonal problem.
- Future Work:
- Learning to model the interfaces of large libraries with respect to a given analysis.
- Learning rules for other types of analyzers, such as type analysis.
- Learning analyses that are semantically similar to manually written ones.
- Exploring more expressive DSLs and more sophisticated synthesis and search strategies to handle even more complex analysis problems.
Summary updated