Definitioncore
Collecting semantics
Also called static semantics of reachable states.
The semantics that maps each program point to the set of all states that reach it, the most precise property an analysis can compute.
The collecting semantics of a program maps each program point to the set of all states that some run of the program has at that point. It is the least fixed point of a set of equations over sets of states, so it is the strongest property of each point that holds in every run. Every analysis in abstract interpretation is proved sound against it, and no algorithm computes it in general.
Definition
The programs are in the toy IR: three-address code in basic blocks, with unbounded integers. This page uses the Cousot convention for the order: sets of states are ordered by inclusion , the join is union, and the bottom element means that no state reaches the point. Lower is more precise. The dataflow pages, such as maximal fixed-point solution, use the dual meet order of Kildall; turning the order upside down maps one convention onto the other.
States. Let be the set of names of the program. An environment is a partial map . A state at the start of block is the pair . Let be the set of all environments.
Edge transformers. For each CFG edge , let be the set of environments such that some , run through the instructions of , gives , and the terminator of then goes to . A run that traps or returns in adds nothing. Since is defined one element at a time, it preserves all unions:
The equations. Let be the set of initial environments: each one binds the parameters to integers, or to the integers that a precondition allows. The lattice is with the pointwise order. It is a complete lattice. The function is
where is at the entry block and elsewhere. is monotone. The collecting semantics is
It exists by the Knaster-Tarski theorem, and it is the intersection of all with .
The reachable states. Let be the set of environments such that some run from an initial environment arrives at the start of block with environment . Then .
Proof. is a fixed point of : a state at the start of is reached either at the start of the run (, ) or by one block step from a state that is reached at a predecessor, and each such step gives a state in . So . For the other inclusion, take any with . By induction on the number of block steps of a run, the state after steps is in : for it is in , and one more step applies a of an edge, which stays inside . So for every such , and .
Iteration. Since each preserves unions, preserves the unions of increasing chains, so the Kleene fixed-point theorem gives . By induction on , is the set of states that runs of fewer than block steps reach at . The union may need infinitely many steps.
Paths. Unfold the union over the steps of a run. For a path with and , let be the composition of the edge transformers along . Then
This is the join over all paths, in the Cousot order, of the concrete transfer functions. Every path counts, also a path that no run follows, because is empty for such a path. The equation solution and the path solution agree because each distributes over union; this is the case of equality in the MOP and MFP coincidence theorem, read in the dual order.
Soundness of an analysis. An analysis gives, for each block , an abstract value with a meaning (see abstract domain). It is sound when
Not computable. A toy IR program with unbounded integers can simulate a register machine. So the question "is ?" for the block that holds ret is the halting problem, and it is undecidable. By Rice's theorem, every nontrivial question about is undecidable. An analysis therefore computes an over-approximation in an abstract domain.
Examples and non-examples
A loop with a parameter. The parameter is n.
entry:
i = 0
jump head
head:
t = i < n
br t body exit
body:
i = i + 1
jump head
exit:
ret i
The edges are entry head, head body, head exit and body head. With , round-robin iteration in the order entry, head, body, exit gives these values of i at the start of each block. Each value computed this way stays inside , since is monotone and each step applies one component of to values inside , and each round is at least the Kleene iterate of the same number, so it ends at .
| round | head | body | exit |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | no change |
The plain Kleene iterates reach the same result and are stable from , because they move one block per step.
With equal to all values of n, the result is an infinite set at each block. Write the states as pairs :
Here grows at each step, and only the infinite union reaches the fixed point. An analysis in the interval domain finds at head; one in the polyhedra domain also finds when holds on entry.
An unreachable block. Change the terminator of head to jump head. Then no edge leads to exit, and , the bottom element. In the Cousot order means "no state", not "no information".
Non-example: one value set per name. Two runs reach a point with and . The collecting semantics is the set , so it proves . The map that keeps one set of values per name, and , also allows . That map is an abstraction of the collecting semantics (the cartesian abstraction), not the collecting semantics itself.
Non-example: one run. The outcome of one run, run(prog, args), is a concrete execution. The collecting semantics collects the states of all runs from all initial states in .
Non-example: the trace semantics. The set of all finite runs, each one a sequence of states, is more precise than the collecting semantics. It can say "at head, i grows by one between two visits", and the set of reachable states cannot. The collecting semantics is the abstraction of the trace semantics that keeps, for each point, the set of last states of the traces that end there.
Related definitions
- Abstract domain: a set of descriptions of sets of states, with a concretization , used to approximate .
- Galois connection: the pair that gives the best description of a set of states.
- Abstract interpretation: the general technique that computes a sound approximation of ; this page gives its concrete side.
- Inductive invariant: a family with . Each one contains , and is itself inductive, so it is the strongest inductive invariant.
- Meet-over-all-paths solution: the path formula above, in the dataflow convention and over an abstract lattice.
- Fixed point, Knaster-Tarski theorem and Kleene fixed-point theorem: the existence of and its computation as a limit.
- Variants. The relational collecting semantics collects pairs (initial environment, current environment); procedure summaries use it. The backward collecting semantics collects the states from which an error state can be reached, with in place of .
References
- 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 static semantics of a program as the least fixed point of a system of equations over sets of environments, one per program point, and the correctness of abstract interpretations with respect to it
- Patrick Cousot and Radhia Cousot, Static determination of dynamic properties of programs, Proceedings of the Second International Symposium on Programming, B. Robinet (ed.), Dunod, Paris, 1976, pages 106 to 130, the semantic equations of a flowchart program and the correctness of the interval analysis with respect to them
- Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Chapter 4 (Abstract Interpretation), the correctness relations and the collecting semantics against which the analyses are proved correct
- Xavier Rival and Kwangkeun Yi, Introduction to Static Analysis, An Abstract Interpretation Perspective, MIT Press, 2020, Chapter 3 and Chapter 4 (the concrete semantics as a least fixed point over sets of states, the reachable states of a transition system)
- Patrick Cousot, Principles of Abstract Interpretation, MIT Press, 2021, the chapters on the structural fixpoint semantics and on the reachability semantics
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag AR4EWF Edit this page History Report an error Markdown