Decidability
Christian Gram Kalhauge
What makes program analysis hard?
In what circumstances would you want a May vs a Must analysis?
What does it mean that an analysis is sound?
It all started with math.
A program is an object , from a language , with a step function from machine state to machine state:
Initial state .
Trace, the sequence of states visited by a step function.
Running the program to completion.
Using automatic techniques to figure out facts about a computer program.
What is a turing complete language?
A language in which you can compute anything a (Turing) machine can compute.
Almost all real
programming languages are Turing complete
It can...
fire the missiles,
not fire the missiles,
never terminate,
kill grandma, and worst of all
throw a null pointer exception!
Given any program from the language , decide if it is going to terminate (halt) when executed on a state .
E.g ., does there exist a sequence, which eventually stabilizes: , , , ,
Do these programs halt?
def forever():
while True:
print("Running!")def never():
while False:
print("Running!")A harder one
def does_halt(p : Program) -> bool:
# A program returns true if p haltsdef main():
while does_halt(main):
print("Running")Wait! That's illegal!
def main():
something_that_might_go_forever()
fire_the_nukes()Rice's Theorem
This means... that there is no best solution.
Welcome to Art School.
(Glitters) Provable:
(Gold) Truth:
In a sound system, we can only prove true things. Or, if we can prove given (), then is true given ().
In a complete system, we can prove all true things. Or if is true given () then is provable given ().
An individual proposition is either a true positive, true negative, false positive, or false negative, following the table below:
| TP | FP | |
| FN | TN |
Program based questions, soundness and completeness. The solid blob is the set of good
programs. The dashed line is the set of programs accepted by the analysis.
Trace based questions, soundness and completeness.
May Analaysis Overapproximate all traces (No False Positives).
Must Analysis Underapproximate all traces (No False Negatives).
[...], virtually all published wholeprogram analyses are unsound and omit conservative handling of common language features when applied to real programming languages.
β In Defense of Soundiness: A Manifesto
Confidence not Absolutes
Write an analysis that given the name of a JVM method, predict the possible behaviors.
Evaluate it on the JPAMB suite.
Upload your results to AutoLab (link next week).
@Case("(false) -> assertion error")
@Case("(true) -> ok")
public static void assertBoolean(boolean shouldFail) {
assert shouldFail;
}assertion error;100% # I'm totally sure this happens
ok;100%
<the-others>;0% # I'm totally sure this never happens. assertion error;yes # I think this happens
ok;maybe # This might happen, I don't know
<the-others>;no # I think this does not happenWhat makes program analysis hard?
In what circumstances would you want a May vs a Must analysis?
What does it mean that an analysis is sound?