a logic your typechecker can count on unordered tree
play

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 ] ,


  1. 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 ] , hd [ ¬ T ] , 3 tl [ X ] , tl [ ¬ X ] , 4 5 { hd , tl } [True]

  2. µ X . {}| ( hd [ T ]+ tl [ X ] ) � φ ( x 0 , .., x 4 ) ,  hd [ T ] , hd [ ¬ T ] ,  tl [ X ] , tl [ ¬ X ] ,   { hd , tl } [True]

  3. Types in O A B Sync A’ B’ T Harmony A generic synchronization framework ◮ Architecture takes two replicas + original ⇒ updated replicas. ◮ Data model is “deterministic” trees: unordered, edge-labeled trees.

  4. Types in O A B Sync A’ B’ 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].

  5. Types in O A B Sync A’ B’ 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.].

  6. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ]

  7. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Semantics Singleton denoting the unique tree with no children: ∈ {}

  8. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Semantics Atoms: trees with single child n and subtree in T : n If ∈ T , then ∈ n [ T ] t t

  9. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Semantics Commutative concatenation operator: If ∈ T and ∈ T ′ , then ∈ T + T ′ t t’ t t’

  10. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Semantics Boolean operations and recursion: = X 1 T 1 . . . X n = T n

  11. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Semantics If m �∈ { n 1 , .., n k } and m ∈ T , then ∈ ! \{ n 1 , .., n k } [ T ] t t

  12. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Semantics If m 1 , .., m k �∈ { n 1 , .., n k } and m 1 m k .. .. ∈ T , then ∈ * \{ n 1 , .., n k } [ T ] .. t 1 t k t 1 t k

  13. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Example: hd [ True ]+ tl [ True ] hd tl

  14. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Example: {}| ( hd [ True ]+ tl [ True ] ) hd tl or

  15. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Example: X = {}| ( hd [ True ]+ tl [ X ] ) hd tl hd or tl hd tl

  16. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Example: ! [ True ]+ ! [ True ]

  17. Deterministic Tree Types Syntax T ::= {} | n [ T ] | T + T | T | T | ~ T | X | ! \{ n 1 , .., n k } [ T ] | * \{ n 1 , .., n k } [ T ] Example: ~ (! [ True ]+ ! [ True ] ) or or or ... Can eliminate negations, and use direct algorithms, but types get large...

  18. Sheaves Formulas Formulas S = φ ( x 0 , .., x k ) , where φ is a Presburger formula [ r 0 [ S 0 ] , .., r k [ S k ]] and r i a set of names. [Dal Zilio, Lugiez, Meyssonnier, POPL ’04]

  19. Sheaves Formulas Formulas S = φ ( x 0 , .., x k ) , where φ is a Presburger formula [ r 0 [ S 0 ] , .., r k [ S k ]] and r i a set of names. φ ( x 0 , x 1 ) , 0 0 [ b [True] , { a , c } [True]] a c b

  20. Sheaves Formulas Formulas S = φ ( x 0 , .., x k ) , where φ is a Presburger formula [ r 0 [ S 0 ] , .., r k [ S k ]] and r i a set of names. φ ( x 0 , x 1 ) , 0 1 [ b [True] , { a , c } [True]] a c b

  21. Sheaves Formulas Formulas S = φ ( x 0 , .., x k ) , where φ is a Presburger formula [ r 0 [ S 0 ] , .., r k [ S k ]] and r i a set of names. φ ( x 0 , x 1 ) , 1 1 [ b [True] , { a , c } [True]] a c b

  22. Sheaves Formulas Formulas S = φ ( x 0 , .., x k ) , where φ is a Presburger formula [ r 0 [ S 0 ] , .., r k [ S k ]] and r i a set of names. φ ( x 0 , x 1 ) , 1 2 [ b [True] , { a , c } [True]] a c b

  23. Sheaves Formulas Formulas S = φ ( x 0 , .., x k ) , where φ is a Presburger formula [ r 0 [ S 0 ] , .., r k [ S k ]] and r i a set of names. φ ( x 0 , x 1 ) , 1 2 [ b [True] , { a , c } [True]] ? | = φ (1 , 2)

  24. Sheaves Formulas Formulas S = φ ( x 0 , .., x k ) , where φ is a Presburger formula [ r 0 [ S 0 ] , .., r k [ S k ]] and r i a set of names. φ ( x 0 , x 1 , x 2 ) , � � b [True] , { a , c } [True] , { a , b , c } [True] For coherence: r i [ S i ] must partition set of atoms. Note: does not ensure determinism.

  25. Examples as Sheaves Formulas X = ( {}|hd[ True ]+tl[ X ] ) ( x 0 = x 1 = x 2 = x 3 =0) ∨ ( x 0 = x 1 =1 ∧ x 2 = x 3 =0) , X = � � hd [True] , tl [ X ] , tl [ ¬ X ] , { hd , tl } [True]

  26. Examples as Sheaves Formulas X = ( {}|hd[ True ]+tl[ X ] ) ( x 0 = x 1 = x 2 = x 3 =0) ∨ ( x 0 = x 1 =1 ∧ x 2 = x 3 =0) , X = � � hd [True] , tl [ X ] , tl [ ¬ X ] , { hd , tl } [True] ~ (! [ True ]+ ! [ True ] ) x 0 � = 2 , � � {} [True]

  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.

  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.

  29. Incremental Algorithm φ ( x 0 , .., x k ) , .. 0 0 0 [ r 0 [ S 0 ] , .. r k [ S k ]] .. n 1 n 2 n k − 1 n k ..

  30. Incremental Algorithm φ ( x 0 , .., x k ) , ( φ ) [ r 0 [ S 0 ] , .. r k [ S k ]] .. n 1 n 2 n k − 1 n k ..

  31. Incremental Algorithm φ ( x 0 , .., x k ) , ( φ ∧ ψ dom ) [ r 0 [ S 0 ] , .. r k [ S k ]] .. n 1 n 2 n k − 1 n k ..

  32. Incremental Algorithm φ ( x 0 , .., x k ) , ( φ ∧ ψ dom ∧ ψ 1 ) [ r 0 [ S 0 ] , .. r k [ S k ]] .. n 1 n 2 n k − 1 n k ..

  33. Incremental Algorithm φ ( x 0 , .., x k ) , ( φ ∧ ψ dom ∧ ψ 1 ∧ ψ 2 ) [ r 0 [ S 0 ] , .. r k [ S k ]] .. n 1 n 2 n k − 1 n k ..

  34. Incremental Algorithm φ ( x 0 , .., x k ) , ( φ ∧ ψ dom ∧ ψ 1 ∧ .. ∧ ψ k − 1 ) [ r 0 [ S 0 ] , .. r k [ S k ]] .. n 1 n 2 n k − 1 n k ..

  35. Incremental Algorithm φ ( x 0 , .., x k ) , ( φ ∧ ψ dom ∧ ψ 1 ∧ .. ∧ ψ k ) [ r 0 [ S 0 ] , .. r k [ S k ]] .. n 1 n 2 n k − 1 n k ..

  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.

  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.

  38. Experiments: Address Book Validator base base-memo 150 100 Time(seconds) 50 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Input Size (# lines) States Formulas Sat Trees 312 107711 99.8% 25744 99.9% 107711 42.1%

  39. Experiments: Address Book Validator base base-memo incr-all-off 150 incr 100 Time(seconds) 50 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Input Size (# lines) States Formulas Sat Trees 312 107711 99.8% 25744 99.9% 107711 42.1%

  40. Experiments: Address Book Validator base base-memo incr-all-off 150 incr-phi-off incr-member-off incr 100 Time(seconds) 50 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 Input Size (# lines) States Formulas Sat Trees 312 107711 99.8% 25744 99.9% 107711 42.1%

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend