Algorithm Search⌘K

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 k≥1k \ge 1, 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 kk, 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 k≥0k \ge 0. The k-CFA of a closed labeled term ee is the least analysis (C^,r^)(\hat C, \hat r) of the k-CFA page, where C^(ℓ,δ)\hat C(\ell, \delta) is the set of abstract closures at label ℓ\ell in contour δ\delta, a sequence of at most kk call sites. The control flow problem for k-CFA is: given ee, a function λx.t\lambda x.t of ee and a label ℓ\ell of ee, decide whether some closure of λx.t\lambda x.t is in C^(ℓ,δ)\hat C(\ell, \delta) for some contour δ\delta. Write nn for the size of ee.

Theorem (Van Horn and Mairson 2008). For every fixed k≥1k \ge 1:

  1. Membership. The control flow problem for k-CFA can be decided in time 2O(nlog⁡n)2^{O(n \log n)}, so it is in EXPTIME.
  2. Hardness. For every deterministic Turing machine MM that halts within 2p(∣x∣)2^{p(|x|)} steps on every input xx, for a polynomial pp, there is a function computable in logarithmic space that maps xx to a closed term exe_x, a function λ\lambda of exe_x and a label ℓ\ell of exe_x, such that MM accepts xx exactly when λ\lambda flows to ℓ\ell in the k-CFA of exe_x.

So the control flow problem for k-CFA is EXPTIME-complete under logarithmic space reductions.

Corollary. For every fixed k≥1k \ge 1, 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 nn be the number of nodes of ee. A contour is a sequence of at most kk labels, so there are N≤(n+1)kN \le (n + 1)^k contours. An abstract closure is a function of ee with an environment that maps its at most nn free variables to contours, so there are at most Q=nNnQ = n N^n closures. The cache has at most nNn N entries and the binding table at most nNn N more, and each holds a subset of the QQ closures. The k-CFA algorithm only adds closures to these sets and stops when a full pass adds nothing. So it makes at most 2nNQ+12 n N Q + 1 passes, and each pass costs a polynomial in nn, NN and QQ (the proof file of the k-CFA page gives the details). With N≤(n+1)kN \le (n+1)^k and kk fixed, Q=2O(nlog⁡n)Q = 2^{O(n \log n)}, so the whole run takes 2O(nlog⁡n)2^{O(n \log n)} steps. The answer is read from the final cache. This is Lemma 10 of Van Horn's thesis. □\square

Hardness (sketch). This follows Van Horn's thesis, Section 5.5, Lemma 11 and Theorem 10, and Van Horn and Mairson (2008). Take MM, pp and an input xx of length mm, and let N=O(p(m))N = O(p(m)).

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 ziz_i 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 2N2^N 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 2N2^N closures, one for each bit vector of length NN. 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 ⟨T,S,H,C,b⟩\langle T, S, H, C, b \rangle of bit blocks: at time TT the machine is in state SS with its head on cell HH, and cell CC holds symbol bb. One configuration of MM is the set of such tuples for all cells CC. The blocks have O(p(m))O(p(m)) bits, so they count up to 2p(m)2^{p(m)} steps and cells.

Step 4: a transition by a cross product. The step function is a term $\Phi = $ fun p -> ... that uses pp twice and is otherwise linear. In a real run, both uses of pp see the same tuple. In the analysis, pp 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 TT and the first has H=CH = C, it writes the new tuple for cell HH at time T+1T + 1 with the new state, head and symbol. If the first has time T+1T + 1 and the second has time TT with H′≠C′H' \ne C', it copies cell C′C' to time T+1T + 1 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 Φ\Phi 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 MM on xx, or the null tuple, by induction on TT. Every true fact flows, by induction on TT and the two rules. A final linear term checks whether some tuple has the accepting state and, if so, sends a chosen function λ\lambda to a chosen label ℓ\ell. So λ\lambda flows to ℓ\ell exactly when MM accepts xx.

Step 6: size and larger kk. The term exe_x has size polynomial in mm, and its parts are written out by a log-space transducer. For k>1k > 1, each place where the proof needs one shared contour gets k−1k - 1 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 Φ\Phi and the iterator, is in the thesis and the 2008 paper. □\square

Corollary. By the time hierarchy theorem, some language in EXPTIME is not in P. If the control flow problem for some k≥1k \ge 1 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. ■\blacksquare

Consequences

  • The k-CFA hierarchy has two levels of cost. 0-CFA is complete for PTIME, and every fixed k≥1k \ge 1 gives an EXPTIME-complete problem. Larger fixed kk does not raise the class, because the bound of part 1 holds for every fixed kk.
  • 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 nN≤n(n+1)kn N \le n (n+1)^k 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 kk. 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 k=0k = 0 to k=1k = 1 is real: 0-CFA is in polynomial time. The bound uses fixed kk. If the contour length grows with the program, the count of environments (nk)n(n^{k})^{n} 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 kk, k-CFA with small kk 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 k≥1k \ge 1. 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

  1. 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
  2. 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)
  3. 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
  4. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/QS1ZW0/text.yaml