A Logic Your Typechecker Can Count On: Unordered Tree Types in - - PowerPoint PPT Presentation

a logic your typechecker can count on unordered tree
SMART_READER_LITE
LIVE PREVIEW

A Logic Your Typechecker Can Count On: Unordered Tree Types in - - PowerPoint PPT Presentation

A Logic Your Typechecker Can Count On: Unordered Tree Types in Practice Nate Foster (Penn) Benjamin C. Pierce (Penn) Alan Schmitt (INRIA Rh one-Alpes) X . {}| ( hd [ T ]+ tl [ X ] ) PLAN-X 07 ( x 0 , .., x 4 ) , 2 hd [ T ] ,


slide-1
SLIDE 1

A Logic Your Typechecker Can Count On: Unordered Tree Types in Practice

Nate Foster (Penn) Benjamin C. Pierce (Penn) Alan Schmitt (INRIA Rhˆ

  • ne-Alpes)

PLAN-X ’07

µX. {}|(hd[T]+tl[X])

  • φ(x0, .., x4),

2 4 hd[T] , hd[¬T] , tl[X] , tl[¬X] , {hd, tl}[True] 3 5

slide-2
SLIDE 2

µX. {}|(hd[T]+tl[X])

  • φ(x0, .., x4),

  hd[T] , hd[¬T] , tl[X] , tl[¬X] , {hd, tl}[True]  

slide-3
SLIDE 3

Types in

Sync A B A’ B’ O T

Harmony

A generic synchronization framework

◮ Architecture takes two replicas + original ⇒ updated

replicas.

◮ Data model is “deterministic” trees: unordered,

edge-labeled trees.

slide-4
SLIDE 4

Types in

Sync A B A’ B’ O T

Harmony: Typed Synchronization [DBPL ’05]

Behavior of synchronizer guided by type.

◮ If inputs well-typed, so are outputs. ◮ Required operations: membership of trees in type [also

sets of names].

slide-5
SLIDE 5

Types in

Sync A B A’ B’ O T

Harmony: Lenses [POPL ’05]

Pre-/post-process replicas using bi-directional programs.

◮ Facilitates heterogeneous synchronization. ◮ Types in conditionals, run-time asserts, static checkers. ◮ Required operations: membership, inclusion, equivalence,

emptiness, [projection, injection, etc.].

slide-6
SLIDE 6

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

slide-7
SLIDE 7

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Semantics

Singleton denoting the unique tree with no children: ∈ {}

slide-8
SLIDE 8

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Semantics

Atoms: trees with single child n and subtree in T: If t ∈ T, then

n

t ∈ n[T]

slide-9
SLIDE 9

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Semantics

Commutative concatenation operator: If t ∈ T and t’ ∈ T ′, then t t’ ∈ T+T ′

slide-10
SLIDE 10

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Semantics

Boolean operations and recursion: X1 = T1 . . . Xn = Tn

slide-11
SLIDE 11

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Semantics

If m ∈ {n1, .., nk} and t ∈ T, then

m

t ∈!\{n1, .., nk}[T]

slide-12
SLIDE 12

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Semantics

If m1, .., mk ∈ {n1, .., nk} and t1 .. tk ∈ T, then

m1 mk

.. .. t1 tk ∈ *\{n1, .., nk}[T]

slide-13
SLIDE 13

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Example: hd[True]+tl[True]

hd tl

slide-14
SLIDE 14

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Example: {}|(hd[True]+tl[True])

  • r

hd tl

slide-15
SLIDE 15

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Example: X = {}|(hd[True]+tl[X])

  • r

hd tl hd tl hd tl

slide-16
SLIDE 16

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Example: ![True]+![True]

slide-17
SLIDE 17

Deterministic Tree Types

Syntax

T::= {} | n[T] | T+T | T|T | ~T | X | !\{n1, .., nk}[T] | *\{n1, .., nk}[T]

Example: ~(![True]+![True])

  • r
  • r
  • r ...

Can eliminate negations, and use direct algorithms, but types get large...

slide-18
SLIDE 18

Sheaves Formulas

Formulas

S = φ(x0, .., xk), [r0[S0] , .., rk[Sk]] where φ is a Presburger formula and ri a set of names. [Dal Zilio, Lugiez, Meyssonnier, POPL ’04]

slide-19
SLIDE 19

Sheaves Formulas

Formulas

S = φ(x0, .., xk), [r0[S0] , .., rk[Sk]] where φ is a Presburger formula and ri a set of names. φ(x0, x1), [b[True], {a, c}[True]]

a b c

slide-20
SLIDE 20

Sheaves Formulas

Formulas

S = φ(x0, .., xk), [r0[S0] , .., rk[Sk]] where φ is a Presburger formula and ri a set of names. φ(x0, x1), [b[True], {a, c}[True]] 1

a b c

slide-21
SLIDE 21

Sheaves Formulas

Formulas

S = φ(x0, .., xk), [r0[S0] , .., rk[Sk]] where φ is a Presburger formula and ri a set of names. φ(x0, x1), [b[True], {a, c}[True]] 1 1

a b c

slide-22
SLIDE 22

Sheaves Formulas

Formulas

S = φ(x0, .., xk), [r0[S0] , .., rk[Sk]] where φ is a Presburger formula and ri a set of names. φ(x0, x1), [b[True], {a, c}[True]] 1 2

a b c

slide-23
SLIDE 23

Sheaves Formulas

Formulas

S = φ(x0, .., xk), [r0[S0] , .., rk[Sk]] where φ is a Presburger formula and ri a set of names. φ(x0, x1), [b[True], {a, c}[True]] 1 2

?

| = φ(1, 2)

slide-24
SLIDE 24

Sheaves Formulas

Formulas

S = φ(x0, .., xk), [r0[S0] , .., rk[Sk]] where φ is a Presburger formula and ri a set of names. φ(x0, x1, x2),

  • b[True], {a, c}[True], {a, b, c}[True]
  • For coherence: ri[Si] must partition set of atoms.

Note: does not ensure determinism.

slide-25
SLIDE 25

Examples as Sheaves Formulas

X = ({}|hd[True]+tl[X])

X = (x0 =x1 =x2 =x3 =0) ∨ (x0 =x1 =1 ∧ x2 =x3 =0),

  • hd[True] , tl[X] , tl[¬X] , {hd, tl}[True]
slide-26
SLIDE 26

Examples as Sheaves Formulas

X = ({}|hd[True]+tl[X])

X = (x0 =x1 =x2 =x3 =0) ∨ (x0 =x1 =1 ∧ x2 =x3 =0),

  • hd[True] , tl[X] , tl[¬X] , {hd, tl}[True]
  • ~(![True]+![True])

x0 = 2,

  • {}[True]
slide-27
SLIDE 27

Challenges and Strategies

Blowup in naive compilation from types to formulas.

◮ Syntactic optimizations avoid blowup in common cases.

Backtracking in top-down, non-deterministic traversal.

◮ Incremental algorithm avoids useless paths.

Presburger arithmetic requires double-exponential time.

◮ Compile Presburger formulas to MONA representation. ◮ Hash-consing allocation + aggressive memoization.

slide-28
SLIDE 28

Challenges and Strategies

Blowup in naive compilation from types to formulas.

◮ Syntactic optimizations avoid blowup in common cases.

Backtracking in top-down, non-deterministic traversal.

◮ Incremental algorithm avoids useless paths.

Presburger arithmetic requires double-exponential time.

◮ Compile Presburger formulas to MONA representation. ◮ Hash-consing allocation + aggressive memoization.

Contributions

◮ Strategies and algorithms; ◮ Implementation in Harmony; ◮ Experimental results.

slide-29
SLIDE 29

Incremental Algorithm

φ(x0, .., xk), [r0[S0] , ..rk[Sk]] ..

n1 n2 nk−1 nk

.. ..

slide-30
SLIDE 30

Incremental Algorithm

φ(x0, .., xk), [r0[S0] , ..rk[Sk]] (φ)

n1 n2 nk−1 nk

.. ..

slide-31
SLIDE 31

Incremental Algorithm

φ(x0, .., xk), [r0[S0] , ..rk[Sk]] (φ ∧ ψdom)

n1 n2 nk−1 nk

.. ..

slide-32
SLIDE 32

Incremental Algorithm

φ(x0, .., xk), [r0[S0] , ..rk[Sk]] (φ ∧ ψdom ∧ ψ1)

n1 n2 nk−1 nk

.. ..

slide-33
SLIDE 33

Incremental Algorithm

φ(x0, .., xk), [r0[S0] , ..rk[Sk]] (φ ∧ ψdom ∧ ψ1 ∧ ψ2)

n1 n2 nk−1 nk

.. ..

slide-34
SLIDE 34

Incremental Algorithm

φ(x0, .., xk), [r0[S0] , ..rk[Sk]] (φ ∧ ψdom ∧ ψ1 ∧ .. ∧ ψk−1)

n1 n2 nk−1 nk

.. ..

slide-35
SLIDE 35

Incremental Algorithm

φ(x0, .., xk), [r0[S0] , ..rk[Sk]] (φ ∧ ψdom ∧ ψ1 ∧ .. ∧ ψk)

n1 n2 nk−1 nk

.. ..

slide-36
SLIDE 36

Hash-Consing and Memoization

Thousands of formulas and trees, but many repeats. Suggests hash-consed allocation:

◮ Sheaves formulas; ◮ Presburger formulas; ◮ Trees.

Memoization of intermediate results:

◮ MONA representations of Presburger formulas; ◮ Satisfiability of Presburger formulas; ◮ Membership results; ◮ Partially-evaluated member functions.

slide-37
SLIDE 37

Experiments

Programs:

◮ Structured text parser; ◮ Address book validator; ◮ iCalendar lens.

Experimental setup: structures populated with snippets of Joyce’s Ulysses; 1.4GHz Intel Pentium III, 2GB RAM, SuSE Linux OS kernel 2.6.16; execution times collected from POSIX functions.

slide-38
SLIDE 38

Experiments: Address Book Validator

Time(seconds) 50 100 150 Input Size (# lines) 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 base base-memo

States Formulas Sat Trees 312 107711 99.8% 25744 99.9% 107711 42.1%

slide-39
SLIDE 39

Experiments: Address Book Validator

Time(seconds) 50 100 150 Input Size (# lines) 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 base base-memo incr-all-off incr

States Formulas Sat Trees 312 107711 99.8% 25744 99.9% 107711 42.1%

slide-40
SLIDE 40

Experiments: Address Book Validator

Time(seconds) 50 100 150 Input Size (# lines) 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 base base-memo incr-all-off incr-phi-off incr-member-off incr

States Formulas Sat Trees 312 107711 99.8% 25744 99.9% 107711 42.1%

slide-41
SLIDE 41

Experiments: Structured Text Parser

Time(seconds) 50 100 150 200 Input Size (# lines) 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 base base-memo incr-all-off incr-phi-off incr-member-off incr

States Formulas Sat Trees 105 12580 99.1% 222 92.8% 3507706 81.4%

slide-42
SLIDE 42

Experiments: iCalendar Lens

Time(seconds) 50 100 150 200 250 Input Size (# lines) 100 200 300 400 500 600 700 800 900 1000 base base-memo incr-all-off incr-phi-off incr-member-off incr

States Formulas Sat Trees 361 116939 97.4% 17600 87.8% 407652 76.5%

slide-43
SLIDE 43

Related Work

Types and Automata:

◮ TQL [Cardelli and Ghelli, ESOP ’01] ◮ “A Logic You Can Count On”

[Dal Zilio, Lugiez, Meyssonnier, POPL ’04]

◮ “Counting In Trees For Free”

[Seidl, Schwentick, Muscholl, Habermehl, ICALP ’04]

◮ Survey and Foundations:

[Boneva and Talbot, RTA ’05, LICS ’05] Implementations:

◮ “Static Checkers for Tree Structrures and Heaps”

[Hague ’04]

◮ “Boolean Operations and Inclusion Test for Attribute

Element Constraints” [Hosoya and Murata, ICALP ’03]

slide-44
SLIDE 44

Conclusions and Future Work

Summary

◮ Strategies and algorithms; ◮ Implemented in Harmony; ◮ Reasonable performance.

Tune algorithm, hash-consing, memoization parameters. Determinize sheaves formulas. Implement Presburger arithmetic directly, optimized for adding constraints incrementally; also restricted fragments. Extend to new structures and types: multitrees, ordered trees, also horizontal recursion, adjoint operators, etc.

slide-45
SLIDE 45

Acknowledgements

Haruo Hosoya, Christian Kirkegaard, St´ ephane Lescuyer, Thang Nguyen, Val Tannen, Penn PLClub and DB Group.

http://www.seas.upenn.edu/∼harmony/