Programs Synthesis from Polymorphic Refinement Types Nadia - - PowerPoint PPT Presentation

programs synthesis from
SMART_READER_LITE
LIVE PREVIEW

Programs Synthesis from Polymorphic Refinement Types Nadia - - PowerPoint PPT Presentation

Programs Synthesis from Polymorphic Refinement Types Nadia Polikarpova Ivan Kuraj Armando Solar-Lezama Program synthesis Make a list with n copies of x declarative specification Synthesizer ? 2 50 replicate n x = if if n 0


slide-1
SLIDE 1

Programs Synthesis from Polymorphic Refinement Types

Nadia Polikarpova Ivan Kuraj Armando Solar-Lezama

slide-2
SLIDE 2

Program synthesis

2

“Make a list with n copies of x” replicate n x = if if n ≤ 0 th then Nil els lse Cons x (replicate (dec n) x)

declarative specification executable program

250 ⊨ ?

Synthesizer

slide-3
SLIDE 3

Modular verification for synthesis

3

slide-4
SLIDE 4

Specifications for synthesis

4

?

replicate n x = if if n ≤ 0 th then Nil els lse Cons x (replicate (dec n) x) Synthesizer

  • 1. supports automatic, modular

verification

  • 2. abstract and concise
  • 3. sufficiently expressive

refinement types

slide-5
SLIDE 5

Demo: replicate

  • - Specification:

replicate :: n: Nat → x: α → {ν: List α | len ν = n} replicate = ??

  • - Components:

zero :: {ν: Int | ν = 0} inc :: x: Int → {ν: Int | ν = x + 1} dec :: x: Int → {ν: Int | ν = x - 1} leq :: x: Int → y: Int → {Bool | ν = (x ≤ y) } neq :: x: Int → y: Int → {Bool | ν = (x ≠ y) }

5

slide-6
SLIDE 6

Synthesis from refinement types

6

Γ ⊢ ?? :: T

slide-7
SLIDE 7

Synthesis from refinement types

7

Γ ⊢ ?? :: T

x1 :: T1; ... φ1; ...

slide-8
SLIDE 8

Synthesis from refinement types

8

Γ ⊢ ?? :: T

  • I. top-down enumerative search

x1 :: T1; ... φ1; ...

slide-9
SLIDE 9

Synthesis from refinement types

9

Γ ⊢ ?? :: T

?? :: U ?? :: V

  • I. top-down enumerative search

x1 :: T1; ... φ1; ... :: T

slide-10
SLIDE 10

Synthesis from refinement types

10

Γ ⊢ ?? :: T

?? :: U ?? :: V

  • I. top-down enumerative search

x1 :: T1; ... φ1; ... :: T

slide-11
SLIDE 11

Synthesis from refinement types

11

Γ ⊢ ?? :: T

?? :: _ ?? :: _

  • I. top-down enumerative search

x1 :: T1; ... φ1; ... :: T’

slide-12
SLIDE 12

Synthesis from refinement types

12

Γ ⊢ ?? :: T

?? :: _ ?? :: _

  • I. top-down enumerative search

x1 :: T1; ... φ1; ... :: T’

slide-13
SLIDE 13

Synthesis from refinement types

13

Γ ⊢ ?? :: T

?? :: _

  • I. top-down enumerative search
  • II. round-trip type checking

x1 :: T1; ... φ1; ... ?? :: U

slide-14
SLIDE 14

Synthesis from refinement types

14

Γ ⊢ ?? :: T

?? :: _

  • I. top-down enumerative search
  • II. round-trip type checking

x1 :: T1; ... φ1; ... ?? :: U

slide-15
SLIDE 15

Synthesis from refinement types

15

Γ ⊢ ?? :: T

?? :: _ ?? :: _

  • I. top-down enumerative search
  • II. round-trip type checking

x1 :: T1; ... φ1; ... ?? :: U ?? :: V

slide-16
SLIDE 16

Synthesis from refinement types

16

Γ ⊢ ?? :: T

?? :: _ ?? :: _

  • I. top-down enumerative search
  • II. round-trip type checking

x1 :: T1; ... φ1; ... :: T’ ?? :: U ?? :: V

slide-17
SLIDE 17

Synthesis from refinement types

17

Γ ⊢ ?? :: T

  • I. top-down enumerative search
  • II. round-trip type checking

x1 :: T1; ... φ1; ... if f then else

?? :: Bool

slide-18
SLIDE 18

Synthesis from refinement types

18

Γ ⊢ ?? :: T

  • I. top-down enumerative search
  • II. round-trip type checking

x1 :: T1; ... φ1; ... if f then else

P⊢?? :: T

  • III. condition abduction
slide-19
SLIDE 19

Synthesis from refinement types

19

Γ ⊢ ?? :: T

  • I. top-down enumerative search
  • II. round-trip type checking

x1 :: T1; ... φ1; ... if f then else

?? :: Bool P⊢?? :: T

  • III. condition abduction

??::{Bool|ν=P}

¬P⊢??::T

slide-20
SLIDE 20

Round-trip type checking

20

⊢ ?? :: {List Neg | len ν ≥ 5}

Γ

slide-21
SLIDE 21

Round-trip type checking

21

Nil ; 0 ; 5 ; -5 zeros replicate ; Cons ⊢ ?? :: {List Neg | len ν ≥ 5}

slide-22
SLIDE 22

Round-trip type checking

22

Nil ; 0 ; 5 ; -5 zeros replicate ; Cons ⊢ ?? :: {List Neg | len ν ≥ 5}

Nil :: {List Neg|len ν = 0}

Nil :: {List a | len ν = 0}

slide-23
SLIDE 23

Round-trip type checking

23

Nil ; 0 ; 5 ; -5 zeros replicate ; Cons ⊢ ?? :: {List Neg | len ν ≥ 5}

?? :: _ → {List Neg | len ν ≥ 5}

slide-24
SLIDE 24

Round-trip type checking

24

Nil ; 0 ; 5 ; -5 zeros replicate ; Cons ⊢ ?? :: {List Neg | len ν ≥ 5} zeros :: n:Nat → {List Zero | len ν = n}

zeros :: n:Nat → {List Zero | len ν = n} ?? :: _ → {List Neg | len ν ≥ 5}

slide-25
SLIDE 25

Nil ; 0 ; 5 ; -5 zeros replicate Cons

Round-trip type checking

25

⊢ ?? :: {List Neg | len ν ≥ 5} ?? :: _ → _ → {List Neg|len ν ≥ 5}

slide-26
SLIDE 26

Nil ; 0 ; 5 ; -5 zeros replicate Cons

Round-trip type checking

26

⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: Neg → {List Neg | len ν = n} ?? :: Nat ?? :: Neg

replicate :: n: Nat → x: a → {List a | len ν = n}

?? :: _ → _ → {List Neg|len ν ≥ 5}

slide-27
SLIDE 27

Nil ; 0 ; 5 ; -5 zeros replicate Cons

Round-trip type checking

27

⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: Neg → {List Neg | len ν = n} ?? :: Nat 0 :: { ν = 0 }

replicate :: n: Nat → x: a → {List a | len ν = n}

?? :: _ → _ → {List Neg|len ν ≥ 5}

slide-28
SLIDE 28

Nil ; 0 ; 5 ; -5 zeros replicate Cons

Round-trip type checking

28

⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: Neg → {List Neg | len ν = n} ?? :: Nat ?? :: Neg 0 :: { ν = 0 } :: {List Neg | len ν = 0}

replicate :: n: Nat → x: a → {List a | len ν = n}

?? :: _ → _ → {List Neg|len ν ≥ 5}

slide-29
SLIDE 29

Nil ; 0 ; 5 ; -5 zeros replicate Cons

Round-trip type checking

29

⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: Neg → {List Neg | len ν = n} ?? :: Nat ?? :: Neg 0 :: { ν = 0 } 5 :: { ν = 5 } :: {List Neg | len ν = 0} :: {List Neg | len ν = 5}

replicate :: n: Nat → x: a → {List a | len ν = n}

?? :: _ → _ → {List Neg|len ν ≥ 5}

slide-30
SLIDE 30

0 :: { ν = 0 } 5 :: { ν = 5 }

Nil ; 0 ; 5 ; -5 zeros replicate Cons

Round-trip type checking

30

⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: Neg → {List Neg | len ν = n} ?? :: Nat ?? :: Neg 0 :: { ν = 0 } 5 :: { ν = 5 } :: {List Neg | len ν = 0} :: {List Neg | len ν = 5}

  • 5 :: { ν = -5 }

replicate :: n: Nat → x: a → {List a | len ν = n}

?? :: _ → _ → {List Neg|len ν ≥ 5}

slide-31
SLIDE 31

Condition abduction

31

Nil ; 0 ; -5 ; n :: Nat (≤) ; (≠) ⊢ ?? :: {List Neg | len ν = n} P

slide-32
SLIDE 32

Condition abduction

32

Nil ; 0 ; -5 ; n :: Nat (≤) ; (≠) ⊢ ?? :: {List Neg | len ν = n} Nil :: {List Neg |len ν = 0} P n ≤ 0

slide-33
SLIDE 33

Condition abduction

33

Nil ; 0 ; -5 ; n :: Nat (≤) ; (≠) ⊢ ?? :: {List Neg | len ν = n} Nil :: {List Neg |len ν = 0} P n ≤ 0 if if n ≤ 0 th then Nil els lse Γ;¬(n ≤ 0) ⊢ ?? :: {List Neg | len ν = n}

slide-34
SLIDE 34

Liquid abduction

34

n ≥ 0 ∧ len ν = 0 ∧ P ⇒ len ν = n Nil :: {List a | len ν = 0} n :: Nat

slide-35
SLIDE 35

Liquid abduction

35

n ≥ 0 ∧ len ν = 0 ∧ P ⇒ len ν = n ★ ≤ ★ ★ ≠ ★ ∧ ¬(len ν = n)

slide-36
SLIDE 36

Liquid abduction

36

n ≥ 0 ∧ len ν = 0 ∧ P ⇒ len ν = n ★ ≤ ★ ★ ≠ ★ n ≤ 0 n ≤ -5

  • 5 ≤ n

n ≠ 0 n ≠ -5

slide-37
SLIDE 37

Liquid abduction

37

n ≥ 0 ∧ len ν = 0 ∧ P ⇒ len ν = n ★ ≤ ★ ★ ≠ ★ n ≤ 0 n ≤ -5

  • 5 ≤ n

n ≠ 0 n ≠ -5 ∧ ¬(len ν = n) UNSAT core [

]

slide-38
SLIDE 38

Liquid abduction

38

n ≥ 0 ∧ len ν = 0 ∧ P ⇒ len ν = n ★ ≤ ★ ★ ≠ ★ n ≤ 0 n ≤ -5

  • 5 ≤ n

n ≠ 0 n ≠ -5 ∧ ¬(len ν = n) UNSAT core [

]

slide-39
SLIDE 39

Evaluation

39

take, drop, delete, zip with, reverse, de- duplicate, fold, length/append with fold, ...

Lists

insertion s., selection s., merge s., quick s.

Sorting

member, insert, delete

Binary Search Trees

RBT & AVL insertion, AVL deletion

Balanced trees

AST desugaring, address book

Custom datatypes

20 s

6 s

64 benchmarks

33 31

> > 120 s No roundtrip type checking

37 27

Naive liquid abduction

slide-40
SLIDE 40

Synthesis of recursive programs

40

easy to verify hard to verify strong guarantees weak guarantees

pre-/post- conditions input-output examples

[Escher: CAV’13] [Myth: PLDI’15] [λ2: PLDI’15] [Leon: OOPSLA’13]

refinement types

[Myth+, POPL’16]

slide-41
SLIDE 41

41

http://tiny.cc/synquid