• Keine Ergebnisse gefunden

Augmented Configuration Trace Semantics

Augmented configurations are pairs of form ha | si where a ∈ PP + AS and s∈State. Ife ∈AS, the configurationhe |siencodes the situation where state shas been obtained by performing atomic stepe. Forp ∈PP, the configuration hp |iimeans that computation starts atpwith initial statei. To achieve uniformity, the left components of augmented configurations which belong to PP may be called entrance steps.

Denote the set of all augmented configurations byAConf, soAConf = (PP + AS )×State and takingC = AConf in Definition 4.1.1 satisfies its conditions.

Denote also conf∈AConf →Conf(with99K, we denote partial functions).

In the rest of this chapter, we deal with transfinite semantics of formTψ for oper-atorsψ ∈STListAConf → 1 +AConf. Not everyψgives rise to a reasonable semanticsTψbecause different augmented configurations in one list contain over-lapping information which can be contradictory. To be ready for defining sound-ness of a given operator ψ, we at first have to be able to make clear for every looping computation which program points the loop causing this computation ac-tually consists of. The following definition states it.

Definition 4.3.1. Letl∈TListAConf\{nil}. We call a program pointplooping inliff, for every ordinalo <|l|, there exists an ordinal̺,o < ̺ <|l|, such that pp(l(̺)) =p. The set of all program points looping inlis denoted byloopl.

Clearly a computationl contains looping program points only if|l|is a limit or-dinal. Note that not necessarily all program points of an infinitely running while-loop are while-looping in this infinite computation (there can be branches of conditionals in the body of the loop being used a finite number of times only). However, the head point of an infinitely running while-loop (meaning the body being executed infinitely many times) definitely is looping.

The writing(0 7→c)denotes the transfinite list of length 1whose single element isc.

Definition 4.3.2. Letψ∈STListAConf →1 +AConf.

(i) Call the operatorψsound iff, for everyc ∈AConf, both following condi-tions hold:

1. if ψ(0 7→ c) 6= ⊥ then arc(ψ(0 7→ c)) ∈/ AS and s(arc(ψ(0 7→ c))) = pp(c)6=f, otherwisepp(c) =f;

2. for everyc˜∈AConf,conf ˜c= confcimpliesψ(07→c) =˜ ψ(07→c).

(ii) Call the operator ψ transfinitely sound iff it is sound and, for every c ∈ AConf and selfish ordinalγsatisfying both1< γ6|iterψ c|andγ <∝, if we denotel= takeγ(iterψ c)then both following conditions hold:

1. ψ(l)6=⊥,arc(ψ(l))∈ASands(arc(ψ(l)))∈loopl;

2. for everyl˜∈STListAConf,map conf ˜l= map conflimpliesψ(˜l) =ψ(l).

(iii) For everyc∈AConf, definenextψc=ψ(07→c).

Soundness ofψguarantees that the program point of any component of a list rep-resenting a computation according toψcoincides with the source of the atomic step of the next component (provided it exists). Soundness also states thatf cor-responds to the finished computation. Transfinite soundness states that every end-less initial part of any computation can be continued with a transfinite step and the source of this step is looping in the computation observed. These and some other facts are more precisely stated and proven in Lemma 4.3.3 below.

It is also required that ordinary steps use ordinary arcs while transfinite steps use transfinite arcs. This is a matter of simplicity. In the case of constructs like loop Sdiscussed in Sect. 4.1, it is obvious that escaping the loop must involve a new arc, but it is semantically neat to demand that actually all infinite loops use some special kind of arcs for transfinite escapement even if there exists an ordi-nary arc between the same vertices. Hence an ordiordi-nary arc starting in a program point of predicate test is still used only if the predicate evaluated to the truth value corresponding to this arc. For while-loops, it means that the ordinary arc from the beginning point to the point immediately after the loop is dubbed with a transfinite arc between the same program points.

The second conditions of soundness and transfinite soundness together demand that the additional information in configurations in comparison to Sect. 4.1 have no influence on the computation process. The meaning of functionnextψ is the same as in Sect. 4.1. It is indexed withψto emphasize the dependence onψ.

Byp → q, we denote that q is an immediate successor ofp, i.e. there is an arc fromptoq, inTCFG.

Lemma 4.3.3. Letψ∈STListAConf →1 +AConf.

(i) Letl= iterψ cfor somec∈AConf. Take an ordinalo6|l|and leto=α+ γbe the principal representation. Thenloop (takeo l) = loop (takeγ(dropα l)).

(ii) Let l = iterψ c for some c ∈ AConf. For every o < |l|, l(o + 1) = nextψ(l(o)).

(iii) Assumeψbeing sound. For everyc∈AConf,nextψc=⊥iffppc=f. (iv) Assumeψbeing sound. Letc∈AConf be arbitrary. Ifpp(nextψc) =qand ppc=pthenarc(nextψc)goes fromptoqinTCFG. Moreover, ifp∈V(cfgS) for some programSthenqandarc(nextψc)belong tocfgS.

(v) Assume ψ being sound. Let l = iterψ c for some c ∈ AConf. For every ordinal o with o+ 1 < |l|, arc(l(o+ 1))goes from pp(l(o)) topp(l(o+ 1)) in TCFG.

(vi) Assumeψbeing transfinitely sound. Letl = iterψ cfor somec ∈ AConf whereby|l|<∝. Then|l|=o+ 1andpp(l(o)) =f for some ordinalo.

(vii) Assume ψbeing transfinitely sound. Letl = iterψ cfor somec ∈ AConf whereby|l|<∝. Letλ6 |l|be a limit ordinal. Thenλ <|l|,arc(l(λ)) ∈ AS

ands(arc(l(λ)))∈loop (takeλ l). Proof.

(i) Assume p ∈ loop (takeo l). Take arbitrary π < |takeγ(dropα l)| = γ.

Thenα+π < α+γ =oand there exists a̺satisfyingα+π < ̺ < osuch that (takeo l)(̺) =p. Thenπ < ̺−α < γand

(takeγ(dropα l))(̺−α) = (dropα l)(̺−α) =l(̺) = (takeo l)(̺) =p . Assume now p ∈ loop (takeγ(dropα l)). Take arbitrary π < |takeo l| = o.

Defineπ˜ =π−αifπ >αandπ˜ = 0otherwise. Thenπ < γ˜ and there exists a̺ satisfyingπ < ̺ < γ˜ such that(takeγ(dropα l))(̺) =p. Thenα < α+̺ < o and

(takeo l)(α+̺) = (dropα(takeo l))(̺) = (takeγ(dropα l))(̺) =p . (ii) By iterativity and Definitions 4.1.1 and 4.3.2(iii),

l(o+ 1) = id(ψ(take 1(dropo l))) =ψ(take 1(dropo l))

= ψ(07→(dropo l)(0)) =ψ(07→l(o)) = nextψ(l(o)) . (iii) Straightforward by Definitions 4.3.2(i) and 4.3.2(iii).

(iv) Denote e = arc(nextψc) = arc(ψ(0 7→ c)). Asψ(0 7→ c) = nextψc 6=

⊥, soundness gives s(e) = ppc = p and e ∈/ AS. We also have t(e) =

t(arc(nextψc)) = pp(nextψc) = q. Therefore p → q, implying together with p∈V(cfgS)thatqandarc(nextψc)both are incfgS.

(v) Straightforward by parts (ii) and (iv).

(vi) Let|l|=α+γ be the principal representation. Ifγ > 1then, by iterativity and transfinite soundness used together with Corollary 3.4.8, we obtain

l(|l|) =ψ(takeγ(dropα l))6=⊥

which contradicts the concept of length. Henceγ = 1and, takingo=α, we obtain the desired form. Using part (ii), we get

⊥=l(|l|) =l(o+ 1) = nextψ(l(o)) , hence, by part (iii),pp(l(o)) =f.

(vii) By (vi), |l| is a successor ordinal, so λ = |l|cannot be the case. Letλ = α+γ be the principal representation; then γ > 1. By transfinite soundness and Corollary 3.4.8,e = arc(l(λ)) = arc(ψ(takeγ(dropα l))) ∈ AS and s(e) is looping intakeγ(dropα l), hence, by (i), also intakeλ l. ⊓⊔ Traditionally, any computation with a program redounds as a walk in its control flow graph. Lemma 4.3.4 states that, in the case of transfinite semantics based on a transfinitely sound operator, a similar property holds also for transfinite control flow graphs: any transfinite computation according to a finite programS can be traced by a walk intcfgS.

Lemma 4.3.4. Letψ∈STListAConf →1 +AConf be transfinitely sound and letS ∈Progbe finite. Letl=Tψ(S)(i)for ani∈State and leto,π be ordinals, o6π <|l|. Denotep = pp(l(o))andq = pp(l(π)). Thenpandqare vertices in tcfgS; furthermore, there exists a walkw = (v0,e1,v1, . . . ,en,vn) fromptoq intcfgSsuch that the following holds:

1. there exist ordinals̺1, . . . , ̺n such thato < ̺1 < . . . < ̺nand, for everyi= 1, . . . , n,arc(l(̺i)) =eiandpp(l(̺i)) =vi;

2. for every ordinal ̺witho < ̺6π, there exists ani = 1, . . . , nsuch that arc(l(̺)) =ei.

Proof. Argue by transfinite induction on(o, π)ordered lexicographically.

Ifo=π = 0thenp =q =iS and the desired result follows trivially (one can take the empty walk fromiSto itself).

If0< o=π then applying the induction hypothesis foro← 0,π ←ogives that pis a vertex intcfgS. Thus the empty walk fromptopworks.

Let finally be06o < π. Letπ−o=α+γbe the principal representation ofπ−o and letπ=β+γ be the principal representation ofπ. By iterativity,l(π) =ψ(m) wherem= takeγ(dropβ l).

Ifγ = 1then, by the induction hypothesis, find a walkvfrompp(l(o))topp(l(o+ α))intcfgSwhich meets the two properties. By soundness,

s(arc(l(π))) =s(arc(ψ(m))) = pp(headm) = pp(head(dropβ l)) = pp(l(β)) . By Lemma 3.4.5(ii),β=o+α. Thus the desired walk can be obtained by append-ingarc(l(π))andpp(l(π))to the end ofv.

Consider the caseγ > 1now. LetM be the set of all arcs used by computation drop(o+ 1)(takeπ l). The induction hypothesis implies that every arc inM is in tcfgS. By assumptions,M is finite. For everye ∈M, letξe be the least ordinal such thatarc((drop(o+ 1)(takeπ l))(ξe)) =e. By transfinite soundness,

s(arc(l(π))) =s(arc(ψ(m)))∈loopm .

Find̺ > β,̺ > maxe∈M(o+ 1 +ξe) such that s(arc(l(π))) = pp(m(̺−β)).

As o 6 ̺ < π, the induction hypothesis implies that there is a walk v from pp(l(o))topp(l(̺))meeting the two properties. The desired walk can be obtained by appendingarc(l(π))andpp(l(π))to the end ofv. ⊓⊔ Lemma 4.3.4 implies that all executions of any fixed finite program in a trans-finitely sound semantics use only trans-finitely many program points and atomic steps altogether. The Lemma 4.3.5 states that, under similar assumptions, every endless computation has a non-empty final part during which it visits looping program points only.

Lemma 4.3.5. Letψ∈STListAConf →1 +AConf be transfinitely sound and let S ∈ Prog be finite. Let l = Tψ(S)(i) for an i ∈ State. For every ordinal o satisfying 0 < o 6 |l|, there exists an ordinal π < o such that pp(l(̺)) ∈ loop(takeo l)for every̺satisfyingπ < ̺ < o.

Proof. LetP be the set of all program pointspbeing reachable fromiSinTCFG and satisfyingp∈/ loop(takeo l). For everyp ∈P, chooseξp < oin such a way that pp(l(̺)) = p for no̺ satisfying ξp < ̺ < o. This definition is sound for everypaspis not looping intakeo land0< o.

AsP ⊆V(tcfgS), it is finite and we can findπ = maxp∈Pξp< o. Choose any̺ such thatπ < ̺ < o. By construction,pp(l(̺)) ∈/ P. By Lemma 4.3.4,pp(l(̺)) is reachable frompp(l(0)) =iSinTCFG. Thuspp(l(̺))∈loop(takeo l). ⊓⊔ We introduce some more restrictions to be imposed on semantics w.r.t. which we are going to work. Like soundness and transfinite soundness, they are formulated as properties of semantics.

Irrespective of the possible universal rules for choosing limit points, we can notice a natural property desired in probably all situations. Namely, the limit point must

be outside the loop causing non-termination as the idea behind transfinite seman-tics is to be able to overcome non-terminating parts of programs. This observation leads to the kind of transfinite semantics we call escaping.

Definition 4.3.6. Call a transfinitely sound operatorψ∈ STListAConf →1 + AConf escaping iff, for every c ∈ AConf and selfish γ satisfying 1 < γ <

|iterψ c|, if we denotel= takeγ(iterψ c)thenpp(ψ(l))∈/loopl.

After any infinite computation according to a finite program in an escaping seman-tics, control reaches a program point which it has not visited during an infinite final part of this computation. The transfinite semantics for while-loops considered in Sect. 4.1 is obviously escaping by the definition oflimp for program point lists p.

Next we are going to prove thatωωis an upper bound of the lengths of transfinite computation in escaping semantics, irrespective of the language. This is achieved by Theorem 4.3.8. Almost the same result (ωω+1) was obtained by Giacobazzi and Mastroeni [5] for IMPprograms.

Denote the set of all program points visited by computationcbyoccurc.

Lemma 4.3.7. Letψ : STListAConf → 1 +AConf be an escaping operator.

For every natural numberkand arbitraryc∈Conf,

|iterψ c|>ωk ⇒ |loop

takeωk(iterψ c)

|>k ,

|iterψ c|>ωk ⇒ |occur

take(ωk+ 1)(iterψ c)

|> k . Proof. Prove by induction onk. The casek= 0is trivial.

Suppose that the claim holds forkand assume

|iterψ c|>ωk+1k·ω=ωkk+. . .

| {z }

ω

.

Thus the listtakeωk+1(iterψ c)divides intoωsubparts, each of lengthωk. Each subpart is of formtakeωk(drop(ωk·n)(iterψ c))for a natural numbern.

Apply Corollary 3.4.7 withh= iterψ,λ=ωk,µ=ωk+1(note that being selfish is equivalent to being a power ofω), andπ =ωk+1. We obtain

takeωk+1(drop(ωk·n)(iterψ c)) = takeωk+1(iterψ d) (4.2) whered = (iterψ ; takeωk ; ψ)n(c). Both sides of (4.2) are different from ⊥ since our assumption|iterψ c|>ωk+1implies|drop(ωk·n)(iterψ c)|>ωk+1. This allows to conclude|iterψ d|>ωk+1kand

takeo(drop(ωk·n)(iterψ c)) = takeo(iterψ d)

for allo6ωk+1. Now the induction hypothesis gives

|occur take(ωk+ 1)(drop(ωk·n)(iterψ c))

|

=|occur take(ωk+ 1)(iterψ d)

| > k . (4.3) Letm= |loop takeωk+1(iterψ c)

|. It is possible to findnsuch that the com-putationdrop(ωk·n)(takeωk+1(iterψ c))visits thesemlooping program points only. Thereforem>k+1since, by (4.3), the firstωk+1steps of this computation visit more thankprogram points.

Finally, if|iterψ c|>ωk+1thenωk+1 <∝. The representationωk+1= 0 +ωk+1 is principal, hence, by iterativity and escapement,

pp((iterψ c)(ωk+1)) = pp(ψ(takeωk+1(drop 0(iterψ c))))

= pp(ψ(takeωk+1(iterψ c))) /

∈ loop

takeωk+1(iterψ c) . Therefore|occur take(ωk+1+ 1)(iterψ c)

|> k+ 1. ⊓⊔

Theorem 4.3.8. Let ψ ∈ STListAConf → 1 +AConf be an escaping oper-ator and letS be a finite program. For everyi ∈ State, we have|Tψ(S)(i)| 6 ω|V(cfgS)|ω.

Proof. By conditions,l = Tψ(S)(s) = iterψhiS | si for some state s. Suppose

|l| > ω|V(cfgS)|. Then Lemma 4.3.7 implies that l visits more program points than there is incfgSwhich is impossible. Hence the first inequality follows. By finiteness,|V(cfgS)|<ω, implying the second inequality. ⊓⊔ For everyn∈N, the length of the transfinite computation of the program

while true do . . . while true do

| {z }

n

isωn. The least common upper bound of the numbersωnisωω. Hence Theorem 4.3.8 achieves the best conservative estimation common to all programs (provided our language is powerful enough to enable arbitrary finite depth of nested loops).

The following definitions refer to control dependence. This notion is well-known;

however, it is also explained in Sect. 2.3 for abstract flow graphs; it is called simply dependence there.

Informally, a program pointq is control dependent onpif there is a computation starting atpand finishing atf which avoidsqbut, after some possible atomic com-putation step, it reaches a program point where it is already impossible to avoid

q later. (Note that, in the case of transfinite semantics, finishing computation is not the same as terminating computation since also non-terminating computations can finish.)

For everyP ⊆PP, we denote byatP the predicate being true on configurations cwithppc∈P. For everyX ∈Var andc∈AConf, the value ofXat statestc is denoted byvalX c.

Definition 4.3.9. Letψ∈STListAConf →1 +AConf.

(i) Call the operator ψ regular iffψ is transfinitely sound and, for every c ∈ AConf and selfish γ satisfying 1 < γ < |iterψ c|, ifl = takeγ(iterψ c) then there is exactly one program point p ∈ loopl with transfinite arc from p to pp(ψ(l))andpp(ψ(l))postdominates all program points inloopl.

(ii) Call the operatorψintuitive iff both following conditions hold:

1. for everyc, d ∈ AConf, selfish ordinals γ, δ satisfying 1 < γ < |iterψ c|, 1 < δ < |iterψ d| and X ∈ Var, if we denote l = takeγ(iterψ c), k = takeδ(iterψ d)then

map(valX)(filter(at{s(arc(ψ(l)))})l)

= map(valX)(filter(at{s(arc(ψ(k)))})k) impliesvalX(ψ(l)) = valX(ψ(k));

2. for everyc∈AConf, selfish ordinalγsatisfying1< γ <|iterψ c|,X ∈Var and v ∈ Val, if we denotel = takeγ(iterψ c)then if there exists an o < |l|

such thatvalX(l(π)) =vfor everyπ > o,π <|l|, thenvalX(ψ(l)) =v.

By construction of the transfinite semantics of while-loops in Sect. 4.1, that se-mantics is regular. Note that every regular operator is escaping since all postdom-inators of a vertex differ from it (Theorem 2.2.4).

The notion of intuitivity (Definition 4.3.9(ii)) formalizes two natural desires about limits of endless sequences of states. The first is that the limit value of every variable depends only on the values this variable possesses at program point where the transfinite arc escapes the loop. This is what Example 4.1.2 suggested and what we demanded in our semantics for while-loops in Sect. 4.1. The second is that if the sequence of values of a variable stabilizes then the limit equals to this stable value — again a condition demanded for while-loops. In other words, it states that, if the value of a variable is changed, this must be caused by a finite atomic step.

This way, all the properties of operatorsψdefined in this section have been cho-sen having in mind the transfinite semantics for while-loops constructed in Sect.

4.1. The facts proven about semantics possessing these properties apply to other semantics inasmuch as they behave similarly.

Lemma 4.3.10. Letψ: STListAConf →1 +AConf be an operator.

(i) Letψbe regular and l = iterψ c for ac ∈ AConf. For every limit ordi-nalλ < |l|, there is exactly one program point p ∈ loop(takeλ l) with transfi-nite arc fromp topp(l(λ))and pp(l(λ))postdominates every program point in loop(takeλ l).

(ii) Letψbe intuitive andl= iterψ cfor ac∈AConf. For every limit ordinal λ <|l|andX∈Var, ifmap(valX)(takeλ l)stabilizes tovthenvalX(l(λ)) = v.

(iii) Letψbe an intuitive limit operator andl = iterψ c,k= iterψ dforc, d∈ AConf. For everyX ∈ Var, limit ordinals λ < |l|,κ < |k|, and ordinals α,β such thatλ−αandκ−β both are selfish limit ordinals, if

map(valX)(filter(at{s(arc(l(λ)))})(dropα(takeλ l)))

= map(valX)(filter(at{s(arc(k(κ)))})(dropβ(takeκ k))) thenvalX(l(λ)) = valX(k(κ)).

Proof.

(i) Straightforward by regularity and Corollary 3.4.8.

(ii) Straightforward by intuitivity and Corollary 3.4.8.

(iii) Denoteγ =λ−α,δ =κ−βandl˜= dropα(takeλ l) = takeγ(dropα l), k˜ = dropβ(takeκ l) = takeδ(dropβ k). By Corollary 3.4.8,dropα l= iterψ x anddropβ k = iterψ y for somex, y ∈ AConf, thereforel˜= takeγ(iterψ x) andk˜ = takeδ(iterψ y). Thus

l(λ) = (dropα l)(γ) = (iterψ x)(γ) =ψ(takeγ(iterψ x)) =ψ(˜l) , k(κ) = (dropβ k)(δ) = (iterψ y)(δ) =ψ(takeδ(iterψ y)) =ψ( ˜k) . Hence, by intuitivity,valX(ψ(˜l)) = valX(ψ( ˜k)), implying the desired claim. ⊓⊔ Byp < q, we denote thatq postdominatesp inTCFG. By Theorem 2.2.4,<is a strict order on program points. The corresponding non-strict order is denoted by 6.

Lemma 4.3.11. Letψ∈STListAConf →1+AConf be transfinitely sound and letS ∈Prog be finite. Letl =Tψ(S)(i)for ani∈State and letpp(l(o)) = p ∈ PPfor an ordinalo. Letq,rbe postdominators ofpboth visited bym= dropo l.

Ifq<rthen the first visit ofqbymoccurs before the first visit ofr.

Proof. Let̺be the least ordinal for whichpp(m(̺)) = r; then r= pp((dropo l)(̺)) = pp(l(o+̺)) .

By Lemma 4.3.4, there exists a walk w from p to r in TCFG using only the arcs occurring in the list drop(o+ 1)(take(o+̺+ 1)l). As q < r and both q andrpostdominatep, walkwpasses throughq(Theorem 2.2.9). Thus we find an ordinalπsuch thatπ+1<|drop(o+ 1)(take(o+̺+ 1)l)|= (o+̺+1)−(o+1) =

̺+ 1−1 =̺−1 + 1and

q = pp((drop(o+ 1)(take(o+̺+ 1)l))(π))

= pp((take(o+̺+ 1)l)(o+ 1 +π))

= pp(l(o+ 1 +π))

= pp((dropo l)(1 +π))

= pp(m(1 +π)) .

Hencemvisitsqbeforerasπ+ 1< ̺−1 + 1givesπ < ̺−1and1 +π < ̺. ⊓⊔ Lemma 4.3.12. Letψ ∈ STListAConf → 1 +AConf be regular and letS ∈ Prog be regular. Letl = Tψ(S)(i) for an i ∈ State. Take π < |l|and assume arc(l(π))going fromp toq. Then every program point inloop (takeπ l)is tran-sitively control dependent onp.

Proof. Ifπ is a successor ordinal, the result holds vacuously asloop (takeπ l) =

∅. Assume therefore π being a limit ordinal. Then, by transfinite soundness, arc(l(π))∈ASandp ∈loop (takeπ l).

By Lemma 4.3.5, there exists ano < πsuch thatpp(l(o)) = p andpp(l(̺)) ∈ loop (takeπ l)for every̺satisfyingo6̺ < π. By Lemma 4.3.4, find a walkw fromptoqcontaining precisely the arcs used bydrop(o+ 1)(take(π+ 1)l).

As S is regular, q immediately postdominates p. As ψ is regular, q postdom-inates all program points in loop (takeπ l), i.e. the program points visited by dropo(takeπ l). Thus q does not occur inw except at the end. Sow is a walk from pointp to its immediate postdominator whereby no intermediate program points postdominatep. Thus all intermediate program points are transitively con-trol dependent onp (Theorem 2.3.5). By construction, wpasses through all pro-gram points inloop (takeπ l). Hence the claim follows. ⊓⊔