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

memo tables
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Memo Tables

Jean-Christophe Filliˆ atre CNRS joint work with Francois Bobot and Andrei Paskevich ProVal team, Orsay, France IFIP WG 2.8 Functional Programming March 2011

slide-2
SLIDE 2

Context: Deductive Program Verification

annotated program WP proof tasks transf. provers

slide-3
SLIDE 3

Context: Deductive Program Verification

annotated program WP proof tasks transf. provers

◮ C / Java

programs

◮ ML programs ◮ pre/post-

conditions

◮ invariants

slide-4
SLIDE 4

Context: Deductive Program Verification

annotated program WP proof tasks transf. provers

◮ C / Java

programs

◮ ML programs ◮ pre/post-

conditions

◮ invariants ◮ polymorphic

first-order logic

◮ algebraic data

types

◮ inductive

predicates

slide-5
SLIDE 5

Context: Deductive Program Verification

annotated program WP proof tasks transf. provers

◮ C / Java

programs

◮ ML programs ◮ pre/post-

conditions

◮ invariants ◮ polymorphic

first-order logic

◮ algebraic data

types

◮ inductive

predicates

◮ untyped,

many-sorted, etc.

◮ few or no

algebraic data types

◮ some built-in

theories (arithmetic, arrays, etc.)

slide-6
SLIDE 6

Context: Deductive Program Verification

Why3: new implementation started one year ago key notion: transformation proof task prover

slide-7
SLIDE 7

Context: Deductive Program Verification

Why3: new implementation started one year ago key notion: transformation proof task prover

slide-8
SLIDE 8

Context: Deductive Program Verification

Why3: new implementation started one year ago key notion: transformation proof task prover T1 example

◮ T1 = inlining of simple definitions

slide-9
SLIDE 9

Context: Deductive Program Verification

Why3: new implementation started one year ago key notion: transformation proof task prover T1 T2 example

◮ T1 = inlining of simple definitions ◮ T2 = elimination of algebraic types

slide-10
SLIDE 10

Context: Deductive Program Verification

Why3: new implementation started one year ago key notion: transformation proof task prover T1 T2 T3 example

◮ T1 = inlining of simple definitions ◮ T2 = elimination of algebraic types ◮ T3 = encoding of polymorphism

slide-11
SLIDE 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

slide-12
SLIDE 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

slide-13
SLIDE 13

The Problem

slide-14
SLIDE 14

Terminology

◮ a value can point to another value

V1 V2

◮ a value is reachable from another value

V1 V2 ✳✳✳ Vn

◮ a set of values called roots

any value not reachable from a root can be reclaimed

slide-15
SLIDE 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

slide-16
SLIDE 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)

slide-17
SLIDE 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

slide-18
SLIDE 18

Some (Partial) Solutions

slide-19
SLIDE 19

Naive Solution

T is a traditional dictionary data structure (hash table, balanced tree, etc.)

K1 K2 T → → . . . V1 V2

slide-20
SLIDE 20

Naive Solution

T is a traditional dictionary data structure (hash table, balanced tree, etc.)

K1 K2 T → → . . . V1 V2

  • bvious drawback

T reachable ⇒ all keys and values bound in T are also reachable conclusion T should not hold pointers to keys

slide-21
SLIDE 21

New Tool: Weak Pointers

a value can weakly point to another value, depicted

V1 V2

a value not yet reclaimed can be accessed via a weak pointer

slide-22
SLIDE 22

New Tool: Finalizers

  • ne 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

slide-23
SLIDE 23

A Better Solution?

K is not used directly as index in T but a unique tag i is used instead

r❡♠♦✈❡ i K T → . . . V i

slide-24
SLIDE 24

A Better Solution?

K is not used directly as index in T

r❡♠♦✈❡ K K T → . . . V

slide-25
SLIDE 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 K T → . . . V

preventing K from being reclaimed

slide-26
SLIDE 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 K T → . . . V

preventing K from being reclaimed conclusion T should not hold pointers to values either

slide-27
SLIDE 27

A Better Solution!

we cannot stock bindings inside tables ⇒ let us keep them in keys instead

r❡♠♦✈❡ a Ta K a → . . . V

slide-28
SLIDE 28

A Better Solution!

improvement: only one finalizer instead of one per key

❝❧❡❛♥ Ta Ta K a → . . . V

slide-29
SLIDE 29

A Better Solution!

K reachable from V is not a problem anymore

❝❧❡❛♥ Ta Ta K a → . . . V

slide-30
SLIDE 30

A Better Solution!

K reachable from V is not a problem anymore

❝❧❡❛♥ Ta Ta K a → . . . V

(note: you can implement a similar solution in Haskell using System.Mem.Weak)

slide-31
SLIDE 31

Symmetry

  • f 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

Ta X a → . . . Tb Y b → . . .

slide-32
SLIDE 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

slide-33
SLIDE 33

Implementation

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

slide-34
SLIDE 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

slide-35
SLIDE 35

Benchmarks

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

slide-36
SLIDE 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?