memo tables
play

Memo Tables Jean-Christophe Filli atre CNRS joint work with Fran c - PowerPoint PPT Presentation

Memo Tables Jean-Christophe Filli atre CNRS joint work with Fran c ois Bobot and Andrei Paskevich ProVal team, Orsay, France IFIP WG 2.8 Functional Programming March 2011 Context: Deductive Program Verification proof annotated provers


  1. Memo Tables Jean-Christophe Filliˆ atre CNRS joint work with Fran c ois Bobot and Andrei Paskevich ProVal team, Orsay, France IFIP WG 2.8 Functional Programming March 2011

  2. Context: Deductive Program Verification proof annotated provers WP transf. program tasks

  3. Context: Deductive Program Verification proof annotated provers WP transf. program tasks ◮ C / Java programs ◮ ML programs ◮ pre/post- conditions ◮ invariants

  4. Context: Deductive Program Verification proof annotated provers WP transf. program tasks ◮ C / Java ◮ polymorphic programs first-order logic ◮ ML programs ◮ algebraic data types ◮ pre/post- ◮ inductive conditions predicates ◮ invariants

  5. Context: Deductive Program Verification proof annotated provers WP transf. program tasks ◮ untyped, many-sorted, ◮ C / Java ◮ polymorphic etc. programs first-order logic ◮ few or no ◮ ML programs ◮ algebraic data algebraic data types types ◮ pre/post- ◮ inductive ◮ some built-in conditions predicates theories ◮ invariants (arithmetic, arrays, etc.)

  6. Context: Deductive Program Verification Why3: new implementation started one year ago key notion: transformation proof prover task

  7. Context: Deductive Program Verification Why3: new implementation started one year ago key notion: transformation proof prover task

  8. Context: Deductive Program Verification Why3: new implementation started one year ago key notion: transformation T 1 proof prover task example ◮ T 1 = inlining of simple definitions

  9. Context: Deductive Program Verification Why3: new implementation started one year ago key notion: transformation T 1 T 2 proof prover task example ◮ T 1 = inlining of simple definitions ◮ T 2 = elimination of algebraic types

  10. Context: Deductive Program Verification Why3: new implementation started one year ago key notion: transformation T 1 T 2 T 3 proof prover task example ◮ T 1 = inlining of simple definitions ◮ T 2 = elimination of algebraic types ◮ T 3 = encoding of polymorphism

  11. Efficiency Concerns to save space, we do ◮ hash-consing of terms, formulas and task prefixes to save time, we do ◮ memoization of transformation functions

  12. Memo Tables there are millions of task elements, thousands of transformations some are long-lived, others short-lived we need efficient memo tables to avoid memory leaks

  13. The Problem

  14. Terminology ◮ a value can point to another value V 1 V 2 ◮ a value is reachable from another value ✳✳✳ V 1 V 2 V n ◮ a set of values called roots any value not reachable from a root can be reclaimed

  15. The Problem some values are called keys, some values are called tables to a key K and a table T we can assign an arbitrary value V , written T : K �→ V given an existing binding T : K �→ V , we can remove it, undoing the corresponding assignment

  16. The Problem: Requirements given a binding T : K �→ V as long as K and T are both reachable, then V is reachable too (and can be obtained from K and T)

  17. The Problem: Requirements if K is reachable, then it is still reachable when all bindings T : K �→ V are removed if T is reachable, then it is still reachable when all bindings T : K �→ V are removed if V is reachable, then it is still reachable when all bindings T : K �→ V with K or T unreachable are removed

  18. Some (Partial) Solutions

  19. Naive Solution T is a traditional dictionary data structure (hash table, balanced tree, etc.) T V 1 K 1 �→ �→ K 2 V 2 . . .

  20. Naive Solution T is a traditional dictionary data structure (hash table, balanced tree, etc.) T V 1 K 1 �→ �→ K 2 V 2 . . . obvious drawback T reachable ⇒ all keys and values bound in T are also reachable conclusion T should not hold pointers to keys

  21. New Tool: Weak Pointers a value can weakly point to another value, depicted V 1 V 2 a value not yet reclaimed can be accessed via a weak pointer

  22. New Tool: Finalizers one or several finalizers can be attached to a value s♦♠❡ ❝♦❞❡ ❱ a finalizer is a closure which is executed whenever the corresponding value is going to be reclaimed

  23. A Better Solution? K is not used directly as index in T but a unique tag i is used instead r❡♠♦✈❡ i T K V i �→ . . .

  24. A Better Solution? K is not used directly as index in T r❡♠♦✈❡ K T K V �→ . . .

  25. A Better Solution? it seems to be a good solution... but a key can be reachable from a value ( e.g. V = K ) r❡♠♦✈❡ K T K V �→ . . . preventing K from being reclaimed

  26. A Better Solution? it seems to be a good solution... but a key can be reachable from a value ( e.g. V = K ) r❡♠♦✈❡ K T K V �→ . . . preventing K from being reclaimed conclusion T should not hold pointers to values either

  27. A Better Solution! we cannot stock bindings inside tables ⇒ let us keep them in keys instead r❡♠♦✈❡ a K T a V a �→ . . .

  28. A Better Solution! improvement: only one finalizer instead of one per key ❝❧❡❛♥ T a T a K V a �→ . . .

  29. A Better Solution! K reachable from V is not a problem anymore ❝❧❡❛♥ T a T a K V a �→ . . .

  30. A Better Solution! K reachable from V is not a problem anymore ❝❧❡❛♥ T a T a K V a �→ . . . (note: you can implement a similar solution in Haskell using System.Mem.Weak )

  31. Symmetry of course, the roles of K and T being symmetric, if T is reachable from V the “cycle issue” is still there example: we want to memoize the K combinator K ( X , Y ) = X we first memoize the partial application to X , the result being another memoization table T b T a X Y a �→ b �→ . . . . . .

  32. Symmetry the approach is viable if we can guarantee that the first argument always lives longer than the second one fortunately, this is indeed the case in our framework

  33. Implementation implemented as an Ocaml library type tag type α tagged = private { node : α ; tag : tag; } val create : α → α tagged val memoize : ( α tagged → α ) → ( α tagged → α )

  34. Implementation implemented as an Ocaml library type tag val create : unit → tag module Memo (Key : sig type t val tag : t → tag end) : sig val memoize : (Key.t → α ) → (Key.t → α ) end

  35. Benchmarks 1,448 proof tasks translated to SMT-lib format and printed in files

  36. Discussion we can rephrase the problem in terms of a single, immortal table with several keys T . . . K V · · · · · · . . . where V is removed as soon as K or T is reclaimed can we propose a new notion of weak pointer for that purpose?

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