Introduction
Compilers are the foundational infrastructure of software development, yet verifying their correctness remains a significant challenge. The primary obstacle is the "oracle problem": determining whether the output of a compiled program matches its intended semantics. Traditionally, compiler testing falls into two extremes. On one hand, techniques like Equivalence Modulo Inputs (EMI) use weak oracles by modifying dead code, which is easy to automate but limited in scope. On the other hand, formal methods provide rigorous proofs but require immense manual effort and specialized expertise, making them difficult to scale for modern, rapidly evolving languages.
To bridge this gap, researchers have introduced PTE (Precondition, Transformation, Expectation), a practical and incremental framework that defines semantic "axioms" within the target language itself. By leveraging the language's own meta-programming capabilities, PTE allows compiler engineers to systematically test language semantics without the overhead of full formal verification.
The PTE Framework
The core of the approach is the PTE Rule, a triple designed to verify specific semantic properties:
- Precondition: A check to determine if a code snippet contains specific features (e.g., "Does this program contain an interface with an abstract property?").
- Transformation: A programmatic modification of the code (e.g., "Parse the AST and regenerate tokens").
- Expectation: The required outcome, which could be behavioral equivalence or the triggering of a specific compiler error.
This framework is designed for iterative refinement. If a rule produces false positives—often due to complex features like polymorphism—developers can easily tighten the precondition or adjust the expectation. Because rules are implemented using the target language's own tools (such as Cangjie macros or Java's JDT), the system remains accessible to compiler engineers and resilient to syntax changes.
Evaluation and Real-World Impact
The authors evaluated PTE on two distinct targets: Cangjie, a new language under active development, and Java 20, a mature ecosystem. For Cangjie, a seed suite of 5,641 programs was used to compare PTE against existing fuzzers like CJSmith and MetaFuzz. For Java, the testing focused on newly introduced features such as pattern matching in switch statements.
Key Results
- Bug Discovery: PTE identified 34 confirmed bugs in Cangjie and 8 confirmed bugs in Java.
- Performance: In head-to-head comparisons on Cangjie, PTE found 34 bugs, while the next best tool, MetaFuzz, found only 3.
- Efficiency: The automated testing process is highly efficient; a suite of 40 rules was applied to over 5,000 test cases in under 60 hours on standard hardware.
- Design Insights: Beyond implementation errors, PTE uncovered 9 language design issues where specifications were ambiguous or confusing.
The Power of Generalization
One of the most effective strategies identified was generalizing specific bug reports into broad semantic rules. For instance, a bug involving the toTokens() function was transformed into an "inverse rule": parsing tokens and regenerating them should always yield an equivalent program. This single generalized rule led to the discovery of eight additional unique bugs.
Conclusion and Future Work
PTE demonstrates that axiomatic semantics can be applied practically to modern compiler testing. While it currently requires manual rule creation, its ability to find deep semantic bugs and design flaws with relatively low overhead is a significant advancement. Future work will focus on automating the generation of test cases that satisfy complex preconditions and developing formal metrics for "semantic coverage" to better understand the depth of the testing process. The Cangjie compiler team has already integrated PTE into their official testing workflow, proving its utility in industrial-scale software development.
Summary updated