a general framework for variable aliasing towards optimal
play

A general framework for variable aliasing: Towards optimal operators - PDF document

A general framework for variable aliasing: Towards optimal operators for sharing properties LOPSTR 2002 Gianluca Amato (Universit di Chieti) Francesca Scozzari (Universit di Pisa) LOPSTR 2002 1 Overview We are interested in sharing


  1. A general framework for variable aliasing: Towards optimal operators for sharing properties LOPSTR 2002 Gianluca Amato (Università di Chieti) Francesca Scozzari (Università di Pisa) LOPSTR 2002 1

  2. Overview • We are interested in sharing analysis of logic pro- grams by abstract interpretation • We look for an optimal operator for comput- ing the mgu in abstract domains which combine sharing and linearity properties. • We propose a new domain equipped with an op- timal operator for unification. • By abstraction we obtain the optimal operators for King’s domain ShLin 2 and Sharing × Lin . LOPSTR 2002 2

  3. The framework The concrete domain: Psub = { [Σ , U ] | Σ ⊆ ISubst ∼ U , U ∈ ℘ f ( V ) }∪{⊥ , ⊤} A concrete object: � � � � � � � � x/f ( k ) x/f ( v ) , { x, y, w, z } , y/g ( k ) w/y � � � � � � � � x/f ( u ) x/f ( k ) , , { x, y, w, z } y/g ( u ) w/y • The semantics has 3 operators for: - (forward and backward) unification - - projection - - union - • an operator for (forward) unification unif : unif Ps ([Σ , U ] , δ, V ) = [ { mgu( θ, δ ) | θ ∈ Σ , } , U ∪ V ] LOPSTR 2002 3

  4. � � � An example A goal p ( x ) , a clause p ( u ) ← B ✤ ✜ ✤ ✜ call substitution entry substitution { x/u } [ {{ x/f ( k ) }} , { x } ] [ { x/f ( k ) , u/f ( k ) }} , { u } ] ✣ ✢ ✣ ✢ ✤ ✜ ✤ ✜ answer substitution exit substitution [ A ′ , { x } ] [ A, { u } ] { x/u } ✣ ✢ ✣ ✢ unif Ps ([ {{ x/f ( k ) }} , { x } ] , { x/u } , { u } )) = [ { x/f ( k ) , u/f ( k ) }} , { x, u } ] LOPSTR 2002 4

  5. The abstract domain Sharing Sharing = { [ A, U ] | A ⊆ ℘ ( U ) , ( A � = ∅ ⇒ ∅ ∈ A ) , U ∈ ℘ f ( V ) }∪{⊤ , ⊥} � � x/f ( a, b ) ⇒ α [ {{ x, y, z } , { x, y } , ∅} , { x, y, z } ] y/g ( a, b, b, b ) z/f ( a, a ) [ { xyz , xy } , { x, y, z } ] A more precise domain... ShLin 2 = � [ S, U ] | S ∈ ℘ ↓ ( Sg 2 ( U )) , U ∈ ℘ f ( V ) , S � = ∅ ⇒ ∅ ∈ S � ∪{⊤ , ⊥} � � x/f ( a, b ) ⇒ α [ { xyz ∞ , xy ∞ } , { x, y, z } ] y/g ( a, b, b, b ) z/f ( a, a ) What about unification? We look for an operator: unif X ([ S, U ] , δ, V ) which is: • correct: unif X ([ S, U ] , δ, V ) approximates unif Ps ([Σ , U ] , δ, V ) • optimal: unif X ([ S, U ] , δ, V ) is the best approximation of unif Ps ([Σ , U ] , δ, V )) LOPSTR 2002 5

  6. A more concrete domain In order to study the unification operator we move to a more concrete domain: From sets to multisets . ShLin ω = { [ S, U ] | U ∈ ℘ f ( V ) , S ⊆ ℘ m ( U ) , S � = ∅ ⇒ ∅ ∈ S }∪{⊥ ω , ⊤ ω } � x/f ( a, b ) � ⇒ [ { xyz 2 , xy 3 } , { x, y, z } ] y/g ( a, b, b, b ) z/f ( a, a ) Towards an operator of unification for ShLin ω . multiplicity of an ω -sharing group B in a term t : � χ ( B, t ) = B ( v ) · occ ( v, t ) v ∈ � B � χ ( x 3 yz 4 , t ( x, y, f ( x, y, z ))) = 3 · 2 + 1 · 2 + 4 · 1 = 12 . If B represents the variable v in some substitution θ then χ ( B, t ) is the number of occurrences of v in tθ . LOPSTR 2002 6

  7. � � � The sharing graph A sharing graph � N, l, E � is a directed multigraph whose nodes are labeled with sharing groups. • N is the finite set of nodes • l is the labeling function from N to sharing groups • E is the multiset of edges. ✎ ☞ ✎ ☞ 0 3 xyz ux 2 ✍ ✌ ✍ ✌ 2 1 A sharing graph is balanced for the equation t 1 = t 2 if: 1. it is connected; 2. for each node s ∈ N , the out-degree of s is equal to χ ( l ( s ) , t 1 ) and the in-degree of s is equal to χ ( l ( s ) , t 2 ) . The above graph is balanced for x = r ( y, y, z ) . χ ( ux 2 , x ) = 2 χ ( ux 2 , r ( y, y, z )) = 0 χ ( xyz, x ) = 1 χ ( xyz, r ( y, y, z )) = 3 The resultant ω -sharing group of G is the multiset union of the labels. In the above example: res ( G ) = ux 3 yz . LOPSTR 2002 7

  8. � � � � From balanced sharing graphs to mgu A sharing graph represents a possible way to merge together several sharing groups by unifying them with a given binding. mgu( S, t 1 = t 2 ) = { res ( G ) | G is a balanced sharing graph for t 1 = t 2 with l ( N ) ⊆ S } Let S = { ux 2 , xy, vz, wz, xyz } . The following is a balanced sharing graph for t ( x ) = r ( y, z ) and S : ✎ ☞ ✎ ☞ ✎ ☞ 0 1 1 xy vz ux 2 ✍ ✌ ✍ ✌ ✍ ✌ 2 1 0 ✎ ☞ ✎ ☞ 1 1 xy wz ✍ ✌ ✍ ✌ 1 0 Therefore uvwx 4 y 2 z 2 ∈ mgu( S, t ( x ) = r ( y, z )) . We define mgu( S, θ ) by induction: mgu( S, ǫ ) = ǫ mgu( S, { x/t } ⊎ θ ) = mgu(mgu( S, x = t ) , θ ) unif ω ([ S, U 1 ] , δ, U 2 ) = [mgu( S ∪{{ { v } } | v ∈ U 2 \ U 1 } , δ ) , U 1 ∪ U 2 ] unif ω is optimal (and correct) w.r.t. unif Ps . LOPSTR 2002 8

  9. A Characterization for Resultant Sharing Groups Let S be a set of ω -sharing groups and t 1 , t 2 be terms. Then B ∈ mgu( S, t 1 = t 2 ) iff B = ⋒ i ∈ I B i where I is a finite set and { { B i } } i ∈ I ∈ ℘ m ( S ) such that: � i ∈ I χ ( B i , t 1 ) = � i ∈ I χ ( B i , t 2 ) ≥ | I | − 1 Example. Consider S = { xa, xb, z 2 , zc } and the equation x = z . { xa, xb, z 2 } For A = { } , we have: χ ( A, x ) = 2 = χ ( A, z ) ≥ | A | − 1 Thus x 2 z 2 ab ∈ mgu( S, x = z ) . For B = { { xa, xb, zc, zc } } , we have: χ ( B, x ) = 2 = χ ( B, z ) � | B | − 1 = 3 Actually, z 2 c 2 x 2 ab / ∈ mgu( S, x = z ) . LOPSTR 2002 9

  10. From ShLin ω to ShLin 2 The abstraction function from ShLin ω to ShLin 2 is immediate: { xy 3 , xy 4 , xyz, xa, xa 2 } ⇒ α { xy ∞ , xyz, xa ∞ } Given A, B ∈ ShLin 2 we define: A � B = λv ∈ V .A ( v ) ⊕ B ( v ) ⊕ 0 ∞ 1 ∞ 0 0 1 where ⊕ is defined as 1 1 ∞ ∞ ∞ ∞ ∞ ∞ � { xy ∞ , xyz, xa ∞ } = x ∞ y ∞ za ∞ The multiplicity of a 2 -sharing group is the set of mul- tiplicity of its concretization: χ ( A, t ) = { χ ( S, t ) | α ( S ) ≤ A } mgu( S, x = t ) = � � Y | Y ⊆ m S, ∃ n ∈ χ ( Y, x ) ∩ χ ( Y, t ) . n ≥ | Y |− 1 � LOPSTR 2002 10

  11. A different characterization of mgu mgu( S, x = t ) = C 0 ∪ ↓ ( { � X 2 | X ⊆ S 1 ∪ S 2 , X ∩ S nl 1 � = ∅ , X ∩ S nl 2 � = ∅}∪ { � X 2 | X ⊆ S 1 2 , X ∩ S nl 1 � = ∅}∪ 1 � = ∅ ∨ o ∈ P ∞ { o � ( � X 2 ) | o ∈ P 1 , X ⊆ S 1 2 , X ∩ S nl 1 , X ∩ P 2 � = ∅}∪ { � X 2 | X ⊆ S 1 1 , X ∩ S nl 2 � = ∅}∪ { o � ( � X 2 ) | o ∈ P 2 , X ⊆ S 1 1 , X ∩ S nl 2 � = ∅ ∨ o ∈ P ∞ 2 , X ∩ P 1 � = ∅}∪ { � X 2 | X ⊆ C 1 } ∪ { o � Y � ( � X 2 ) | o ∈ P 2 , X ⊆ C 1 , Y ⊆ m P 1 1 , | Y | = χ M ( o, t ) ∈ N + } ) LOPSTR 2002 11

  12. Conclusions • We propose a new domain ShLin ω as a general framework for investigating sharing and linearity properties. • We introduce the notion of (balanced) sharing graph and provide optimal abstract operators for ShLin ω . • We obtain the optimal operators for forward and backward unification in King’s domain ShLin 2 and in Sharing × Lin . LOPSTR 2002 11

Recommend


More recommend