TL;DR
Finding bugs in compilers requires generating weird, creative programs that still obey strict language rules—a task where hand-coded generators take years to build and standard AI models waste vast effort just learning where the semicolons go. SYNSEMA splits the job: it uses readily available language grammars to guarantee valid syntax by construction, freeing a small, randomly initialized reinforcement learning (RL) agent to focus entirely on learning semantics from compiler feedback. The result is a lightweight fuzzer that learns from scratch to write valid Rust and Java code—uncovering weird, unvisited corners of production compilers that even giant, pretrained LLMs miss.
What Problem Does This Paper Address?
To stress-test a compiler (like rustc or javac), you need to feed it diverse, valid programs. If your test program has a syntax typo, the compiler’s front-end parser immediately rejects it, leaving the complex optimization and code-generation machinery untouched. Even if the syntax is right, the program must still obey semantic rules—like type checking, variable scoping, and Rust’s notorious ownership constraints.
Historically, engineers had two painful choices:
- Hand-craft a generator: Spend months encoding an 800-page language specification into custom generation logic.
- Train a language model: Have a neural network predict tokens from scratch, forcing it to simultaneously figure out syntax and semantics in an astronomical search space—leading to >99.9% of early training attempts being rejected for trivial syntax errors.
The authors ask: What if we stop making the AI learn syntax, since we already have formal grammars for that?
Methods
SYNSEMA reformulates program generation as a syntax-guided reinforcement learning task, built on an asynchronous Deep Q-Learning setup (Ape-X) using a randomly initialized 124M-parameter GPT-2 architecture.
Here is what is standard vs. what is new:
- Constrained Action Spaces (Systematic Exploration): Using standard Context-Free Grammars (CFGs), SYNSEMA masks out invalid moves so the agent cannot make a syntax error. The authors implement and compare three classic parsing algorithms as RL action spaces: LL (top-down) and LR (bottom-up), where actions are grammar rules/operations, and Earley (chart-based), where actions are valid next code tokens.
- Fine-Grained Semantic Rewards (Novel): Compilers don't just say "pass/fail"; they point to exact line and column spans where errors occur. When compilation fails, SYNSEMA maps those error spans back to the exact RL actions that generated the offending code and penalizes them directly (-1 split across offending steps).
- Novelty Bonus: If a program compiles, the final action gets a positive reward (up to 10, decaying linearly with repetition) based on whether it triggered new execution paths (edge coverage) inside the compiler itself.
Datasets
Because SYNSEMA learns directly from interacting with rustc and Java 21 (javac) from scratch, no training datasets are used. It relies only on existing ANTLR/standard CFGs and a predefined subword vocabulary for identifiers and literals.
For post-hoc analysis of how unusual the generated programs were, the authors compared SYNSEMA's outputs against the Rust compiler regression test suite and programs generated by pretrained LLMs (DeepSeek-V4-Pro and Gemma-3-4B-IT).
Key Insights and Ideas
- Ignorance is a Fuzzing Superpower: When compared against Fuzz4All powered by DeepSeek-V4-Pro (given an equivalent ~$100 compute budget), DeepSeek achieved higher overall compiler code coverage, yet found only 1 crash compared to SYNSEMA's 12 Rust bugs. Scoring the programs with an independent base model (Qwen3-8B) revealed why: pretrained LLMs stay on the beaten path of "human-like" code. Starting from random weights with zero human priors lets SYNSEMA stumble into bizarre combinations (like putting a diverging
loop {}inside an unsized sliceconstparameter) that compiler devs never anticipated. - Blame the Culprit, Not the Messenger: Ablating the reward mechanism showed that mapping compiler error spans directly back to the exact actions that caused them increased valid-program compiler coverage by 25.2% compared to simply penalizing the final step of the episode.
- Parser Choice Shapes Learning: Chart-based (Earley) token masking gave the best overall bug-finding and coverage, while bottom-up (LR) parsing achieved the highest compilation success rate in Rust (14.16%) despite needing ~3x more steps per token to build parse trees.
Key Results
Evaluated over five-day runs on Rust and Java 21 against an unconstrained token-by-token RL baseline:
- Compilation Success: SYNSEMA achieved an average 7.29% semantic validity rate across languages/parsers (peaking at 14.16% for Rust Bottom-Up), crushing the unconstrained baseline's 0.03% average.
- Compiler Exploration: Syntax-guided agents triggered 2.6× higher source coverage on average than the baseline (up to 4.05× with the Chart parser on Rust).
- Real-World Impact: SYNSEMA uncovered 14 distinct crashes and hangs (12 in
rustc, 2 injavac), including 5 previously unknown bugs in production compilers. The unconstrained baseline found zero.
Limitations and Future Work
- Small Scale & Vocabulary: The prototype caps episodes at 128 actions (auto-completing unfinished prefixes with the shortest valid suffix), omits code comments, and restricts variable names/literals to a fixed vocabulary.
- No Pretraining for Operations: While token-based chart parsing could theoretically wrap a pretrained LLM, operation-based agents (LL and LR) speak in grammar transitions, for which no pretrained models exist.
- The Oracle Catch-22: Because the compiler under test is also the teacher, SYNSEMA can find compiler crashes, but it cannot tell if a compiler silently miscompiles invalid code without crashing. Future work could incorporate differential testing (comparing multiple compilers against each other) or runtime execution rewards.
Summary updated