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 executable th then Nil program els lse Cons x (replicate (dec n) x) 2
Modular verification for synthesis 3
Specifications for synthesis 1. supports automatic, modular refinement ? verification types 2. abstract and concise 3. sufficiently expressive Synthesizer replicate n x = if n ≤ 0 if th then Nil els lse Cons x (replicate (dec n) x) 4
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
Synthesis from refinement types Γ ⊢ ?? :: T 6
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... 7
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... I. top-down enumerative search 8
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... ?? :: U ?? :: V :: T I. top-down enumerative search 9
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... ?? :: U ?? :: V :: T I. top-down enumerative search 10
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... ?? :: _ ?? :: _ :: T’ I. top-down enumerative search 11
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... ?? :: _ ?? :: _ :: T’ I. top-down enumerative search 12
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... ?? :: _ ?? :: U I. top-down enumerative search II. round-trip type checking 13
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... ?? :: _ ?? :: U I. top-down enumerative search II. round-trip type checking 14
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... ?? :: _ ?? :: _ ?? :: U ?? :: V I. top-down enumerative search II. round-trip type checking 15
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... ?? :: _ ?? :: _ :: T’ ?? :: U ?? :: V I. top-down enumerative search II. round-trip type checking 16
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... if f then else ?? :: Bool I. top-down enumerative search II. round-trip type checking 17
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... if f then else P ⊢ ?? :: T I. top-down enumerative search II. round-trip type checking III. condition abduction 18
Synthesis from refinement types x 1 :: T 1 ; ... Γ ⊢ ?? :: T φ 1 ; ... if f then else ¬P ⊢ ??::T P ⊢ ?? :: T ?? :: Bool ??::{Bool| ν =P} I. top-down enumerative search II. round-trip type checking III. condition abduction 19
Round-trip type checking Γ ⊢ ?? :: {List Neg | len ν ≥ 5} 20
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros replicate ; Cons ⊢ ?? :: {List Neg | len ν ≥ 5} 21
Round-trip type checking Nil :: {List a | len ν = 0} Nil ; 0 ; 5 ; -5 zeros replicate ; Cons ⊢ ?? :: {List Neg | len ν ≥ 5} Nil :: {List Neg|len ν = 0} 22
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros replicate ; Cons ⊢ ?? :: {List Neg | len ν ≥ 5} ?? :: _ → {List Neg | len ν ≥ 5} 23
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros zeros :: n:Nat → {List Zero | len ν = n} replicate ; Cons ⊢ ?? :: {List Neg | len ν ≥ 5} ?? :: _ → {List Neg | len ν ≥ 5} zeros :: n:Nat → {List Zero | len ν = n} 24
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros ⊢ ?? :: {List Neg | len ν ≥ 5} replicate Cons ?? :: _ → _ → {List Neg|len ν ≥ 5} 25
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros ⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: a → {List a | len ν = n} replicate Cons ?? :: _ → _ → ?? :: Nat ?? :: Neg {List Neg|len ν ≥ 5} replicate :: n: Nat → x: Neg → {List Neg | len ν = n} 26
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros ⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: a → {List a | len ν = n} replicate Cons ?? :: _ → _ → ?? :: Nat {List Neg|len ν ≥ 5} 0 :: { ν = 0 } replicate :: n: Nat → x: Neg → {List Neg | len ν = n} 27
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros ⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: a → {List a | len ν = n} replicate Cons ?? :: _ → _ → ?? :: Nat ?? :: Neg :: {List Neg | len ν = 0} {List Neg|len ν ≥ 5} 0 :: { ν = 0 } replicate :: n: Nat → x: Neg → {List Neg | len ν = n} 28
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros ⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: a → {List a | len ν = n} replicate Cons ?? :: _ → _ → ?? :: Nat ?? :: Neg :: {List Neg | len ν = 0} :: {List Neg | len ν = 5} {List Neg|len ν ≥ 5} 0 :: { ν = 0 } 5 :: { ν = 5 } replicate :: n: Nat → x: Neg → {List Neg | len ν = n} 29
Round-trip type checking Nil ; 0 ; 5 ; -5 zeros ⊢ ?? :: {List Neg | len ν ≥ 5} replicate :: n: Nat → x: a → {List a | len ν = n} replicate Cons ?? :: _ → _ → ?? :: Nat ?? :: Neg :: {List Neg | len ν = 0} :: {List Neg | len ν = 5} {List Neg|len ν ≥ 5} 5 :: { ν = 5 } 0 :: { ν = 0 } -5 :: { ν = -5 } 5 :: { ν = 5 } 0 :: { ν = 0 } replicate :: n: Nat → x: Neg → {List Neg | len ν = n} 30
Condition abduction Nil ; 0 ; -5 ; n :: Nat ( ≤ ) ; (≠) ⊢ ?? :: {List Neg | len ν = n} P 31
Condition abduction Nil ; 0 ; -5 ; n :: Nat ( ≤ ) ; (≠) ⊢ ?? :: {List Neg | len ν = n} n ≤ 0 P Nil :: {List Neg |len ν = 0} 32
Condition abduction Nil ; 0 ; -5 ; n :: Nat ( ≤ ) ; (≠) ⊢ ?? :: {List Neg | len ν = n} n ≤ 0 P Nil :: {List Neg |len ν = 0} if if n ≤ 0 th then Nil els lse Γ;¬(n ≤ 0) ⊢ ?? :: {List Neg | len ν = n} 33
Liquid abduction n ≥ 0 ∧ len ν = 0 ∧ ⇒ len ν = n P n :: Nat Nil :: {List a | len ν = 0} 34
Liquid abduction n ≥ 0 ∧ len ν = 0 ∧ ∧ ¬( len ν = n) ⇒ len ν = n P ★ ≤ ★ ★ ≠ ★ 35
Liquid abduction n ≥ 0 ∧ len ν = 0 ∧ ⇒ len ν = n P ★ ≤ ★ n ≤ 0 ★ ≠ ★ n ≤ -5 -5 ≤ n n ≠ 0 n ≠ -5 36
Liquid abduction core [ ] UNSAT n ≥ 0 ∧ len ν = 0 ∧ ∧ ¬( len ν = n) ⇒ len ν = n P ★ ≤ ★ n ≤ 0 ★ ≠ ★ n ≤ -5 -5 ≤ n n ≠ 0 n ≠ -5 37
Liquid abduction core [ ] UNSAT n ≥ 0 ∧ len ν = 0 ∧ ∧ ¬( len ν = n) ⇒ len ν = n P ★ ≤ ★ n ≤ 0 ★ ≠ ★ n ≤ -5 -5 ≤ n n ≠ 0 n ≠ -5 38
Evaluation Lists take, drop, delete, zip with, reverse, de- duplicate, fold, length/append with fold, ... No roundtrip type checking 27 Sorting 31 Naive liquid abduction 64 benchmarks insertion s., selection s., merge s., quick s. 6 s Binary Search Trees member, insert, delete Custom datatypes 37 AST desugaring, address book 33 Balanced trees RBT & AVL insertion, AVL deletion 20 s > > 120 s 39
Synthesis of recursive programs strong guarantees pre-/post- refinement conditions types [ Leon: OOPSLA’13] [ Myth+ , POPL’16] [ Escher : CAV’13] input-output weak [ Myth : PLDI’15] examples [ λ 2 : PLDI’15] guarantees easy to verify hard to verify 40
http://tiny.cc/synquid 41
Recommend
More recommend