Algorithm Search⌘K

Definitioncore

Abstract domain

Also called abstract lattice.

A lattice of abstract properties with a concretization map and sound abstract versions of the program operations, join and widening.

An abstract domain is a set of machine-readable descriptions of sets of program states, together with the operations that an analyzer needs on them: an order, a join, sound versions of the program instructions, and a widening. Each description aa has a meaning γ(a)\gamma(a), the set of states it allows. The domain fixes what an analysis can say. The interval domain can say 0≤i≤100 \le i \le 10 and cannot say i≤ni \le n; the polyhedra domain can say both, at a higher cost.

Definition

The concrete side is the collecting semantics: for each program point, a set of environments, ordered by inclusion. This page uses the Cousot order: lower is more precise, and ⊥\bot describes the empty set of states. The dataflow pages, such as monotone dataflow framework, use the dual order of Kildall, where the meet combines paths and the top element means "unreachable".

An abstract domain for the set Env\mathit{Env} of environments is a tuple (A,⊑,⊥,⊤,⊔,γ,assign♯,guard♯,∇)(A, \sqsubseteq, \bot, \top, \sqcup, \gamma, \mathit{assign}^\sharp, \mathit{guard}^\sharp, \nabla) with these parts and conditions.

  1. Elements and order. AA is a set with a preorder ⊑\sqsubseteq, and a program can decide a⊑ba \sqsubseteq b. Often (A,⊑)(A, \sqsubseteq) is a lattice, but it need not be complete, and two representations of the same set may be equivalent without being equal.
  2. Concretization. γ:A→P(Env)\gamma : A \to \mathcal{P}(\mathit{Env}) is monotone: a⊑ba \sqsubseteq b implies γ(a)⊆γ(b)\gamma(a) \subseteq \gamma(b).
  3. Extremes. γ(⊥)=∅\gamma(\bot) = \emptyset and γ(⊤)=Env\gamma(\top) = \mathit{Env}.
  4. Join. a⊔ba \sqcup b is an upper bound of aa and bb that a program can compute. It is sound: γ(a)∪γ(b)⊆γ(a⊔b)\gamma(a) \cup \gamma(b) \subseteq \gamma(a \sqcup b). It need not be the least upper bound, and γ(a⊔b)\gamma(a \sqcup b) is often larger than the union.
  5. Transfer functions. For each instruction x=ex = e there is assign♯(x,e):A→A\mathit{assign}^\sharp(x, e) : A \to A, and for each branch condition cc there is guard♯(c):A→A\mathit{guard}^\sharp(c) : A \to A. Each one is sound: for every aa,
postx=e(γ(a))⊆γ(assign♯(x,e)(a)),{ρ∈γ(a):c holds in ρ}⊆γ(guard♯(c)(a)).\mathit{post}_{x = e}\bigl(\gamma(a)\bigr) \subseteq \gamma\bigl(\mathit{assign}^\sharp(x, e)(a)\bigr), \qquad \{ \rho \in \gamma(a) : c \text{ holds in } \rho \} \subseteq \gamma\bigl(\mathit{guard}^\sharp(c)(a)\bigr).
  1. Widening. If AA has an infinite strictly ascending chain, a widening operator ∇\nabla is part of the domain. Without it the iteration may not stop.

These parts are optional: a meet ⊓\sqcap with γ(a)∩γ(b)⊆γ(a⊓b)\gamma(a) \cap \gamma(b) \subseteq \gamma(a \sqcap b), a narrowing operator, and an abstraction α:P(Env)→A\alpha : \mathcal{P}(\mathit{Env}) \to A that gives the best description of each set. When α\alpha exists and α(S)⊑a  ⟺  S⊆γ(a)\alpha(S) \sqsubseteq a \iff S \subseteq \gamma(a), the pair is a Galois connection. The definition does not require it: the polyhedra domain has no best description of a disk.

From local conditions to a sound result. For an edge ℓ→ℓ′\ell \to \ell', let postℓ→ℓ′♯\mathit{post}^\sharp_{\ell \to \ell'} be the composition of the transfer functions of the instructions of ℓ\ell, followed by guard♯\mathit{guard}^\sharp of the branch condition that selects ℓ′\ell' (or of its negation). Let init♯\mathit{init}^\sharp satisfy Init⊆γ(init♯)\mathit{Init} \subseteq \gamma(\mathit{init}^\sharp). Define F♯F^\sharp on maps ALabelsA^{\mathit{Labels}} in the same shape as the concrete FF:

F♯(X)(ℓ)=[ℓ=entry] init♯ ⊔⨆ℓ′→ℓpostℓ′→ℓ♯(X(ℓ′)).F^\sharp(X)(\ell) = [\ell = \mathit{entry}]\,\mathit{init}^\sharp \ \sqcup \bigsqcup_{\ell' \to \ell} \mathit{post}^\sharp_{\ell' \to \ell}\bigl(X(\ell')\bigr).

Claim. For every XX, F(γ∘X)⊆γ∘F♯(X)F(\gamma \circ X) \subseteq \gamma \circ F^\sharp(X) pointwise.

Proof. First, a composition of sound steps is sound. If posts1(γ(a))⊆γ(s1♯(a))\mathit{post}_{s_1}(\gamma(a)) \subseteq \gamma(s_1^\sharp(a)) and the same holds for s2s_2, then, since the concrete posts2\mathit{post}_{s_2} is monotone,

posts2(posts1(γ(a)))⊆posts2(γ(s1♯(a)))⊆γ(s2♯(s1♯(a))).\mathit{post}_{s_2}\bigl(\mathit{post}_{s_1}(\gamma(a))\bigr) \subseteq \mathit{post}_{s_2}\bigl(\gamma(s_1^\sharp(a))\bigr) \subseteq \gamma\bigl(s_2^\sharp(s_1^\sharp(a))\bigr).

By induction on the length of the block, postℓ′→ℓ(γ(X(ℓ′)))⊆γ(postℓ′→ℓ♯(X(ℓ′)))\mathit{post}_{\ell' \to \ell}(\gamma(X(\ell'))) \subseteq \gamma(\mathit{post}^\sharp_{\ell' \to \ell}(X(\ell'))). Second, a join of sound terms is sound. If Si⊆γ(bi)S_i \subseteq \gamma(b_i) for each ii, then ⋃iSi⊆⋃iγ(bi)⊆γ(⨆ibi)\bigcup_i S_i \subseteq \bigcup_i \gamma(b_i) \subseteq \gamma(\bigsqcup_i b_i), by condition 4 and induction on the number of terms. The entry term is covered by Init⊆γ(init♯)\mathit{Init} \subseteq \gamma(\mathit{init}^\sharp). Put the two parts together at each ℓ\ell. □\square

Consequence. If F♯(X)⊑XF^\sharp(X) \sqsubseteq X pointwise, then F(γ∘X)⊆γ∘F♯(X)⊆γ∘XF(\gamma \circ X) \subseteq \gamma \circ F^\sharp(X) \subseteq \gamma \circ X, by the claim and condition 2. So γ∘X\gamma \circ X is an element SS with F(S)⊆SF(S) \subseteq S, and the least fixed point is below it: Coll⊆γ∘X\mathit{Coll} \subseteq \gamma \circ X. The abstract interpretation page gives this last step as its soundness theorem; Knaster-Tarski calls such an SS a pre-fixed point, and Cousot calls the abstract XX with F♯(X)⊑XF^\sharp(X) \sqsubseteq X a post-fixed point. Two points matter in practice. The proof does not use the monotonicity of F♯F^\sharp, so a non-monotone transfer function or a widening does not break soundness. And a map XX with F♯(X)⊑XF^\sharp(X) \sqsubseteq X is a certificate: to check it, a program evaluates F♯F^\sharp once and tests ⊑\sqsubseteq at each point.

Non-relational and relational domains. A non-relational domain keeps one value description per name. It is built from a value domain (B,⊑B,γB)(B, \sqsubseteq_B, \gamma_B) that describes sets of integers: A=(V→B)∪{⊥}A = (V \to B) \cup \{\bot\}, with the pointwise order and

γ(m)={ρ:ρ(x)∈γB(m(x)) for each x∈V}.\gamma(m) = \{ \rho : \rho(x) \in \gamma_B(m(x)) \text{ for each } x \in V \}.

A map in which one name has the empty description describes no state, so it is identified with ⊥\bot. A relational domain describes sets of tuples directly, and it can keep a relation between names, such as x≤yx \le y or x+y=10x + y = 10.

Examples and non-examples

Parity. The value domain has four elements, ⊥⊑even,odd⊑⊤\bot \sqsubseteq \mathit{even}, \mathit{odd} \sqsubseteq \top, with γB(even)\gamma_B(\mathit{even}) the even integers and γB(odd)\gamma_B(\mathit{odd}) the odd ones. Its sum gives even\mathit{even} when both arguments are equal and not ⊤\top, and odd\mathit{odd} when they differ; its product gives even\mathit{even} when one argument is even\mathit{even} and odd\mathit{odd} when both are odd\mathit{odd}. Both are the best transformers: a check over all argument pairs gives exactly these results. Analyze this program with the parameter n:

entry:
  x = 1
  jump head
head:
  t = x < n
  br t body exit
body:
  x = x + 2
  jump head
exit:
  y = x * x
  ret y

At head the first pass gives x↦oddx \mapsto \mathit{odd} from the entry edge, and the body edge gives odd+even=odd\mathit{odd} + \mathit{even} = \mathit{odd}, so the second pass changes nothing. The domain has finite height, so no widening is needed. At exit y=odd⋅odd=oddy = \mathit{odd} \cdot \mathit{odd} = \mathit{odd}: the program always returns an odd number. The guard x < n gives no parity information, so its transfer function is the identity.

A table of common domains. All of these are domains in the sense above. The height is that of the value lattice of one name, and vv is the number of names.

domain kind height example fact cost of one operation
sign non-relational 2 x>0x > 0 O(v)O(v)
parity non-relational 2 xx odd O(v)O(v)
constants (constant propagation) non-relational 2 x=7x = 7 O(v)O(v)
intervals non-relational infinite 0≤x≤100 \le x \le 10 O(v)O(v)
octagons relational, weakly infinite x−y≤3x - y \le 3, x+y≤10x + y \le 10 O(v3)O(v^3) for closure
convex polyhedra relational infinite y=2xy = 2x, x+y+z≤9x + y + z \le 9 exponential in vv in the worst case

The constant lattice has height 2 but infinite width, so its iteration still stops. The interval, octagon and polyhedra domains need a widening.

Non-relational loses relations. Two runs reach a point with (x,y)=(1,2)(x, y) = (1, 2) and (2,1)(2, 1). Intervals give x∈[1,2]x \in [1, 2] and y∈[1,2]y \in [1, 2], which also allows (1,1)(1, 1), so they cannot prove x+y=3x + y = 3. Octagons keep x+y=3x + y = 3 exactly.

Non-example: an unsound transfer function. Take the sign domain and define pos−pos=pos\mathit{pos} - \mathit{pos} = \mathit{pos}. Then γ(pos)\gamma(\mathit{pos}) contains 1 and 2, and 1−2=−11 - 2 = -1 is not in γ(pos)\gamma(\mathit{pos}). Condition 5 fails, and an analysis with this rule can prove that y = x - z is positive when it is not. The sound rule gives ⊤\top.

Non-example: an order that does not follow the meaning. Order intervals by their width: [0,0]⊑[5,6][0, 0] \sqsubseteq [5, 6] because 0≤10 \le 1. Then γ([0,0])={0}\gamma([0, 0]) = \{0\} is not inside γ([5,6])={5,6}\gamma([5, 6]) = \{5, 6\}, so γ\gamma is not monotone and condition 2 fails. A test F♯(X)⊑XF^\sharp(X) \sqsubseteq X in this order proves nothing about the program.

Non-example: a join that is too small. Use the intersection of intervals as the join. Then [0,1]⊔[5,6]=⊥[0, 1] \sqcup [5, 6] = \bot, and the point after an if with these two branches would look unreachable. Condition 4 fails. Any computable upper bound is acceptable, but a lower bound is not.

References

  1. Patrick Cousot and Radhia Cousot, Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints, POPL 1977, pages 238 to 252, the definition of an abstract interpretation as a lattice of abstract contexts with abstract operations, its consistency with the static semantics, and the widening for lattices with infinite ascending chains
  2. Patrick Cousot and Radhia Cousot, Abstract interpretation frameworks, Journal of Logic and Computation 2(4), 1992, pages 511 to 547, the frameworks that use a concretization function only, with no best abstraction, and their comparison with the Galois connection framework
  3. Patrick Cousot and Radhia Cousot, Systematic design of program analysis frameworks, POPL 1979, pages 269 to 282, the design of abstract domains and of their combinations from the concrete semantics
  4. Xavier Rival and Kwangkeun Yi, Introduction to Static Analysis, An Abstract Interpretation Perspective, MIT Press, 2020, Chapter 3 (abstract domains for sets of states, the non-relational and relational domains, and the soundness of the abstract operations)
  5. Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Chapter 4 (Abstract Interpretation), the property spaces and the correctness relations

Where this leads

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/KJGF11/text.yaml