Generating Complex Code Analyzers from Natural Language Questions
This paper introduces Merlin, a system that combines large language models with the CodeQL program analysis framework using a novel RAG-based iterative generation and self-testing approach to effectively answer complex natural language questions about large codebases, significantly improving developer task accuracy and efficiency.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you have a massive library containing millions of books (the codebase) written in a very specific, technical language. You are a librarian (the developer) who needs to find a very specific pattern: "Find every book where a character introduces themselves before they are fully born."
Doing this by hand is impossible. Using a simple search bar to look for the word "born" (like grep) is useless because it misses the meaning of the sentence. Asking a super-smart AI assistant (a Large Language Model or LLM) to read the whole library and tell you the answer often fails because the library is too big for the AI to hold in its memory at once, or the AI just guesses wrong.
Enter Merlin.
Merlin is a new system that acts like a super-powered translator and detective. It sits between you (who speaks natural English) and a very strict, powerful database engine called CodeQL (which understands the technical structure of code perfectly).
Here is how Merlin works, using simple analogies:
1. The Translator (Natural Language to CodeQL)
You ask Merlin a question in plain English: "Show me all places where a constructor calls a method that can be changed later."
Merlin doesn't just guess the answer. Instead, it translates your question into a precise query for the CodeQL database. Think of CodeQL as a giant, structured spreadsheet of your entire code. Merlin writes a specific SQL-like command to ask that spreadsheet for the exact data you need.
2. The "Self-Test" (The Litmus Test)
Here is the tricky part: Even if Merlin writes a query that looks grammatically correct, it might still be logically wrong. It might ask for "apples" when you meant "fruit," or it might be too picky and find nothing.
To fix this, Merlin has a self-test feature. Before it searches your massive library, it asks the AI to create a tiny, fake example (a "mock" scenario) to see if the query works.
- The Analogy: Imagine you are testing a metal detector. Before you walk through a whole city, you walk through a small garden with a few buried coins. If the metal detector beeps for the coins, you know it's working. If it stays silent, you know the detector is broken, and you fix it before you waste time searching the city.
- The Result: If the query fails this small test, Merlin knows it's broken and tries again.
3. The "Assistive Query" (The Detective's Flashlight)
Sometimes, the query is syntactically perfect but still finds nothing because the AI misunderstood a subtle detail.
Merlin uses a technique called Assistive Queries.
- The Analogy: Imagine you are looking for a specific type of bird in a forest, but your binoculars are foggy. Instead of just staring harder, you ask a helper to shout out everything they see in the trees right now ("I see a red bird, a blue bird, a squirrel...").
- How it helps: By seeing this list of "witnesses," the AI realizes, "Oh! I was looking for red birds, but the forest is full of blue ones. I need to change my search." This helps the AI debug its own logic and find the right answer.
4. The Results: Why It Matters
The researchers tested Merlin against other tools and human developers.
- Finding the Needle: Merlin found almost all the bugs that existing professional tools found, but it also found many more that the other tools missed.
- Human Speed: In a study where real programmers had to find and fix bugs:
- Those using Merlin were 3.8 times more accurate than those without it.
- They finished the tasks 31% faster.
- The "Why": Without Merlin, programmers often got stuck doing tedious, manual searching or relied on AI that gave them wrong answers. Merlin gave them a clear, auditable list of locations and the exact logic used to find them, so they could trust the results.
Summary
Merlin is like having a translator who speaks both "Human English" and "Machine Logic," a quality control inspector who tests the instructions before sending them out, and a detective who uses flashlights to figure out why a search failed. It allows developers to ask complex questions about huge codebases and get reliable, precise answers without needing to be experts in the technical query language themselves.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.