Theoremresearch
EXPTIME-completeness of k-CFA
Also called Van Horn-Mairson theorem.
For every fixed k at least 1, deciding whether a function flows to a program point under k-CFA is complete for exponential time.
For each fixed , the control flow problem of k-CFA is complete for EXPTIME. The problem asks whether, in the k-CFA result of a program, a given function flows to a given program point. Van Horn and Mairson proved this in 2008. It ended a long belief that k-CFA was polynomial for fixed , and it shows a jump: 0-CFA is complete for polynomial time, while 1-CFA is already as hard as any problem that a Turing machine solves in exponential time. The cause is the environments of closures, which can take exponentially many abstract values. When environments are flat, as for objects that copy their fields when they are created, the same analysis is polynomial.
Statement
Fix . The k-CFA of a closed labeled term is the least analysis of the k-CFA page, where is the set of abstract closures at label in contour , a sequence of at most call sites. The control flow problem for k-CFA is: given , a function of and a label of , decide whether some closure of is in for some contour . Write for the size of .
Theorem (Van Horn and Mairson 2008). For every fixed :
- Membership. The control flow problem for k-CFA can be decided in time , so it is in EXPTIME.
- Hardness. For every deterministic Turing machine that halts within steps on every input , for a polynomial , there is a function computable in logarithmic space that maps to a closed term , a function of and a label of , such that accepts exactly when flows to in the k-CFA of .
So the control flow problem for k-CFA is EXPTIME-complete under logarithmic space reductions.
Corollary. For every fixed , no algorithm decides the k-CFA control flow problem in polynomial time.
In plain words
k-CFA looks at a program and works out which functions can show up where. For k equal to zero this takes polynomial time. For any larger fixed k, it can take exponential time, and the theorem says that this is not the fault of a poor algorithm. The analysis itself is powerful enough to run any program that needs exponential time. The trick uses the fact that the analysis is not exact. A function value remembers a context for each of its variables, and the analysis mixes these contexts freely. So one small function can stand for exponentially many different values at once, and two uses of the same variable can pick values independently. A clever program uses this to store a huge machine tape and to step the machine forward. The answer to one flow question then tells whether the machine accepts.
Proof
Membership (full proof). Let be the number of nodes of . A contour is a sequence of at most labels, so there are contours. An abstract closure is a function of with an environment that maps its at most free variables to contours, so there are at most closures. The cache has at most entries and the binding table at most more, and each holds a subset of the closures. The k-CFA algorithm only adds closures to these sets and stops when a full pass adds nothing. So it makes at most passes, and each pass costs a polynomial in , and (the proof file of the k-CFA page gives the details). With and fixed, , so the whole run takes steps. The answer is read from the final cache. This is Lemma 10 of Van Horn's thesis.
Hardness (sketch). This follows Van Horn's thesis, Section 5.5, Lemma 11 and Theorem 10, and Van Horn and Mairson (2008). Take , and an input of length , and let .
Step 1: Boolean logic by linear terms. True and False are closed functions, and every gate of a Boolean circuit is a term that uses each variable exactly once. For such linear terms the analysis is exact: each function is applied to at most one argument, so the abstract flow equals the real flow. This is the construction behind the PTIME-hardness of 0-CFA, by reduction from the circuit value problem (Van Horn and Mairson 2007).
Step 2: exponentially many closures at one place. Consider
(fun f1 -> f1 0; f1 1) (fun z1 ->
(fun f2 -> f2 0; f2 1) (fun z2 ->
...
(fun fN -> fN 0; fN 1) (fun zN ->
(fun x -> x) (fun w -> w z1 z2 ... zN))))
Each is bound to 0 at one call site and to 1 at another, so in 1-CFA it has two contours. The tuple fun w -> w z1 ... zN is created in all combinations of these contours. The identity function applied at one fixed call site puts all of them in the same cache entry, under the same contour. So one entry holds closures, one for each bit vector of length . A closure has polynomial size, but the set of closures in one entry can be exponential.
Step 3: a machine configuration as a set of closures. A closure codes a tuple of bit blocks: at time the machine is in state with its head on cell , and cell holds symbol . One configuration of is the set of such tuples for all cells . The blocks have bits, so they count up to steps and cells.
Step 4: a transition by a cross product. The step function is a term $\Phi = $ fun p -> ... that uses twice and is otherwise linear. In a real run, both uses of see the same tuple. In the analysis, ranges over all tuples in its cache entry, and the two uses are analysed independently, so the body sees every pair of tuples. On each pair, a linear Boolean circuit computes the next tuple. If both tuples have the same time and the first has , it writes the new tuple for cell at time with the new state, head and symbol. If the first has time and the second has time with , it copies cell to time with the new state and head. On all other pairs it returns a fixed null tuple.
Step 5: iteration and the answer. The term applies again and again to its own output, starting from the initial configuration, with enough iterations for the analysis to reach a fixed point. Every tuple that flows is then a true fact about the run of on , or the null tuple, by induction on . Every true fact flows, by induction on and the two rules. A final linear term checks whether some tuple has the accepting state and, if so, sends a chosen function to a chosen label . So flows to exactly when accepts .
Step 6: size and larger . The term has size polynomial in , and its parts are written out by a log-space transducer. For , each place where the proof needs one shared contour gets more applications of identity functions. These extra call sites fill the longer contours, so k-CFA of the padded term behaves as 1-CFA of the original.
The full construction, with the circuits for and the iterator, is in the thesis and the 2008 paper.
Corollary. By the time hierarchy theorem, some language in EXPTIME is not in P. If the control flow problem for some were in P, then every EXPTIME language would be in P, through the log-space reduction of part 2. So it is not in P.
Consequences
- The k-CFA hierarchy has two levels of cost. 0-CFA is complete for PTIME, and every fixed gives an EXPTIME-complete problem. Larger fixed does not raise the class, because the bound of part 1 holds for every fixed .
- Flat environments are polynomial. Call an analysis flat if every abstract closure has one contour for all its free variables. Then there are at most abstract closures, the sets in the cache have polynomial size, and the same round-robin solver runs in polynomial time. In Java and similar languages, an object copies the values it needs into its fields when it is created, in the context of the creation. So k-call-site and object-sensitive points-to analyses of such languages are flat, and polynomial for fixed . Might, Smaragdakis and Van Horn (2010) used this to explain the "k-CFA paradox", the gap between slow functional k-CFA and fast object-oriented k-CFA, and to design m-CFA, a flat and polynomial analysis for functional programs.
- Approximation is the source of the hardness. When the contours are never cut, k-CFA computes the exact run, and Van Horn shows that this exact problem is only PTIME-complete (Proposition 1 of the thesis). The power to reach EXPTIME comes from mixing the contours of different variables.
- NP-hardness has a short proof. With Step 2 and one Boolean formula applied to the tuple, True flows out exactly when the formula is satisfiable, so 1-CFA is NP-hard (Theorems 8 and 9 of the thesis). The theorem above makes this tight.
Tightness
The upper bound of part 1 cannot be lowered to polynomial time, by the corollary. The jump from to is real: 0-CFA is in polynomial time. The bound uses fixed . If the contour length grows with the program, the count of environments grows too, and Van Horn notes that with exponential contour length the problem becomes doubly exponential. The hardness uses a nonlinear variable and closures with many free variables. Without free variables in closures, or with flat environments, the problem is polynomial.
History
Shivers defined the k-CFA hierarchy in 1988 and 1991. Since the number of contours is polynomial for fixed , k-CFA with small was often taken to be polynomial. Van Horn and Mairson showed in 2007 that 0-CFA is PTIME-complete, and in 2008 that k-CFA is EXPTIME-complete for every . Van Horn's 2009 thesis collects these results. In 2010, Might, Smaragdakis and Van Horn explained why k-CFA style analyses of Java are polynomial, and introduced m-CFA.
References
- David Van Horn and Harry G. Mairson, Deciding kCFA is complete for EXPTIME, Proceedings of ICFP 2008, 275 to 282, the main theorem, the EXPTIME-completeness of the control flow problem of k-CFA for every k greater than 0
- David Van Horn, The Complexity of Flow Analysis in Higher-Order Languages, PhD thesis, Brandeis University, 2009, arXiv:1311.4733, chapter 5, Lemma 10 (membership), Theorems 8 and 9 (NP-hardness), Lemma 11 and Theorem 10 (EXPTIME-hardness), Proposition 1 (exact k-CFA is PTIME-complete); chapter 3, Theorem 3 (0-CFA is PTIME-complete)
- David Van Horn and Harry G. Mairson, Relating complexity and precision in control flow analysis, Proceedings of ICFP 2007, 85 to 96, the PTIME-completeness of 0-CFA, by analysis of linear terms that code Boolean circuits
- Matthew Might, Yannis Smaragdakis and David Van Horn, Resolving and exploiting the k-CFA paradox, Proceedings of PLDI 2010, 305 to 315, why k-CFA of object-oriented programs is polynomial, and the polynomial m-CFA hierarchy for functional programs
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag QS1ZW0 Edit this page History Report an error Markdown