Predicate Subtypes in VerCors
This paper presents a prototype implementation in the VerCors program verifier that adds support for predicate subtypes to specify variable range constraints, featuring automatic specification generation, the ability to combine multiple subtypes, and a strict mode for enhanced overflow checking.
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 are building a house of cards. In the world of computer programming, the "cards" are variables (like numbers or lists), and the "house" is the software. Usually, when you declare a variable, you just say, "This is a number." But in reality, not just any number will do. Maybe you need a number that is never zero (so you don't divide by it), or a number that fits inside a tiny box (so it doesn't break the system).
This paper introduces a new feature for a tool called VerCors, which is like a super-smart inspector that checks if your house of cards will stand up before you even build it. The new feature is called Predicate Subtypes.
Here is the breakdown of how this works, using some everyday analogies:
1. The Problem: The "Any Number" Mistake
Imagine you tell a construction worker, "Bring me a brick." They might bring you a giant boulder, a tiny pebble, or a real brick. If your wall needs a specific size, the boulder will crash the whole thing.
In programming, if you tell the computer, "This variable is an integer," the computer assumes it can be any integer, from negative infinity to positive infinity. But in the real world (and in specific programs), we often need to say, "This integer must be between 0 and 100," or "This integer must never be zero."
Without this feature, the computer might miss a mistake where a number gets too big (an overflow) or becomes zero when it shouldn't, causing the program to crash later.
2. The Solution: The "Special Label" (Predicate Subtypes)
The authors added a way to put a special label on your variables. Instead of just saying "This is a number," you can say:
- "This is a Non-Zero Number."
- "This is a Short Number (between -128 and 127)."
- "This is a Valid Index (a number that fits inside this specific list)."
In the paper, they call these Predicate Subtypes. Think of it like a VIP pass. If a variable has the "Non-Zero" VIP pass, the computer knows it is strictly forbidden to be zero.
3. How the Inspector Works (Automatic Checks)
The coolest part of this paper is that the VerCors tool does the heavy lifting automatically. You don't have to write a hundred different checks to make sure your numbers are safe.
- The Magic Translator: When you write
int xwith a "Non-Zero" label, VerCors acts like a translator. It secretly rewrites your code behind the scenes to add safety checks. - The Guard at the Door: Every time you try to put a new value into that variable, VerCors puts a guard at the door. The guard checks: "Does this new value satisfy the label?"
- If you try to put
0into a "Non-Zero" variable, the guard stops you and says, "Error! This doesn't fit the label." - If you try to put
5, the guard says, "All clear!"
- If you try to put
4. The "Strict Mode": Checking the Journey, Not Just the Destination
This is the most clever part of the paper. Sometimes, the final result is fine, but the journey to get there was dangerous.
The Analogy: Imagine you are driving a car that can only carry 100 pounds of cargo.
- Normal Mode: You load 50 pounds, drive over a bridge that collapses under 200 pounds, and then drop off 50 pounds. The final weight is 50 (safe), but you crashed the bridge on the way!
- Strict Mode: The car has a "Strict" label. This means every single step of the journey must stay under 100 pounds. Even if you are just doing a quick math calculation in the middle of the road, the computer checks if that temporary number is safe.
The paper introduces a "Strict Arithmetic" mode. If you turn this on, VerCors checks every tiny math operation (like x - 2) to make sure it doesn't temporarily explode the size limit, even if the final answer is safe. This is crucial for preventing "overflows" (when a number gets too big for the computer to handle).
5. Mixing and Matching Labels
Just like you can wear a hat and a scarf at the same time, you can combine these labels.
- You can say a variable must be Non-Zero AND Positive.
- You can say it must be Either a Short Number OR a Long Number.
- You can even say "If it's not Null, then it must be Length 3."
The tool handles all these complex combinations automatically, turning them into simple safety checks that the computer can understand.
Why Does This Matter?
In the past, programmers had to manually write safety checks everywhere, which is tedious and easy to mess up. Or, they had to use very rigid systems that couldn't handle complex rules.
This paper shows that VerCors can now:
- Understand complex rules about your data (like "this list must have exactly 3 items").
- Automatically check that those rules are never broken, even in the middle of a calculation.
- Catch dangerous overflows before the program ever runs, saving time and preventing crashes.
Summary
Think of Predicate Subtypes as giving your computer a pair of smart glasses. Instead of just seeing "a number," the computer sees "a number that must be between 0 and 100." The VerCors tool then acts as a strict bouncer, checking every single time a number tries to enter a room (or a variable) to make sure it's wearing the right ID badge. If it's not, the bouncer stops the program before it can cause a disaster.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.