CSE507
Emina Torlak
emina@cs.washington.educourses.cs.washington.edu/courses/cse507/14au/
Computer-Aided Reasoning for Software
Solver-Aided Languages
CSE507 Computer-Aided Reasoning for Software Solver-Aided Languages - - PowerPoint PPT Presentation
CSE507 Computer-Aided Reasoning for Software Solver-Aided Languages courses.cs.washington.edu/courses/cse507/14au/ Emina Torlak emina@cs.washington.edu Today 2 Today Last lecture Program synthesis 2 Today Last lecture Program
Emina Torlak
emina@cs.washington.educourses.cs.washington.edu/courses/cse507/14au/
Computer-Aided Reasoning for Software
Solver-Aided Languages
Today
2Today
2Last lecture
Today
2Last lecture
Today
Today
2Last lecture
Today
Reminders
a little programming for everyone
A little programming for everyone
4 We all want to build programs …A little programming for everyone
4 We all want to build programs … social scientistA little programming for everyone
4 We all want to build programs … biologist social scientistA little programming for everyone
4 We all want to build programs … hardware designer biologist social scientistA little programming for everyone
4 code time effort We all want to build programs … hardware designer biologist social scientistA little programming for everyone
5 less code less time less effort solver-aided languages We all want to build programs …A little history
6 better programsA little history
6 better programs 1960 1970 1980 1990 2000A little history
6 better programs 1960 1970 1980 1990 2000 ASTRÉE [AbsInt] SLAM [MSR] 6TH SENSE [IBM]A little history
6 better programs 1960 1970 1980 1990 2000A little history
6 better programs 1960 1970 1980 1990 2000A little history
6 better programs more easily 1960 1970 1980 1990 2000 2010solver-aided tools, languages and beyond
solver-aided tools, languages and beyond solver-aided tools
solver-aided tools, languages and beyond solver-aided tools, languages
solver-aided tools, languages and beyond solver-aided tools, languages and beyond
solver-aided tools
Programming …
9 specificationProgramming …
9 specification test case assert safe(P(2))Programming with a solver-aided tool
10?
SAT/SMT solver translate(…) P(x) { … … } assert safe(P(x))Solver-aided tools: verification
11 Find an inputSolver-aided tools: verification
11 Find an inputSolver-aided tools: debugging
12 Localize bad parts of the program. x = 42 ⋀ safe(P(x)) P(x) { v = x + 2 … } assert safe(P(x)) 42 BugAssist [Jose & Majumdar, PLDI’11] Angelina [Chandra et al., ICSE’11]Solver-aided tools: debugging
12 min core Localize bad parts of the program. x = 42 ⋀ safe(P(x)) P(x) { v = x + 2 … } assert safe(P(x)) x + 2 42 expressions BugAssist [Jose & Majumdar, PLDI’11] Angelina [Chandra et al., ICSE’11]Solver-aided tools: angelic execution
13 Find values that repair the failing execution.∃v . safe(P(42, v))
SAT/SMT solver P(x) { v = choose() … } assert safe(P(x)) 42 Kaplan [Koksal et al, POPL’12] PBnJ [Samimi et al., ECOOP’10] Squander [Milicevic et al., ICSE’11]Solver-aided tools: angelic execution
13 Find values that repair the failing execution.∃v . safe(P(42, v))
model values SAT/SMT solver P(x) { v = choose() … } assert safe(P(x)) 42 40 Kaplan [Koksal et al, POPL’12] PBnJ [Samimi et al., ECOOP’10] Squander [Milicevic et al., ICSE’11]Solver-aided tools: synthesis
14 Synthesize code that repairs the program.∃e . ∀x . safe(Pe(x))
SAT/SMT solver Sketch [Solar-Lezama et al., ASPLOS’06] Comfusy [Kuncak et al., CAV’10]Solver-aided tools: synthesis
14 Synthesize code that repairs the program.∃e . ∀x . safe(Pe(x))
SAT/SMT solver x − 2 model expressions Sketch [Solar-Lezama et al., ASPLOS’06] Comfusy [Kuncak et al., CAV’10]more solver-aided tools …
more solver-aided tools …
Building solver-aided tools: state-of-the-art
16 tools expert execute synthBuilding solver-aided tools: state-of-the-art
16 learn the problem domain I need a tool to create models of biological cells … tools expert domain expert execute synthBuilding solver-aided tools: state-of-the-art
16 learn the problem domain design a domain language I need a tool to create models of biological cells … Abstractions for cells, components, interactions, … tools expert domain expert execute synthBuilding solver-aided tools: state-of-the-art
16 learn the problem domain design a domain language monthsCan we do better?
17 design a domain language weeks domain expert verify debug execute synth implement an interpreter for the language, get a symbolic compiler for freeCan we do better?
17 design a domain language weeks domain expert a solver-aided host language a solver-aided domain-specific language (SDSL) verify debug execute synth implement an interpreter for the language, get a symbolic compiler for freesolver-aided languages
Layers of languages
19 host language A formal language that is specialized to a particular application domain and often limited in capability. A high-level language for implementing DSLs, usually with meta-programming features. interpreter libraryLayers of languages
19 host language interpreter libraryLayers of languages
19 host language C = A * B C / Java Eigen / Matlab [associativity] C = A * B for (i = 0; i < n; i++) for (j = 0; j < m; j++) for (k = 0; k < p; k++) C[i][k] += A[i][j] * B[j][k] interpreter libraryLayers of solver-aided languages
20 solver-aided host language symbolic virtual machine interpreter libraryLayers of solver-aided languages
20 solver-aided host language symbolic virtual machineROSETTE
[Torlak & Bodik, Onward’13, PLDI’14] interpreter libraryLayers of solver-aided languages
20 solver-aided host language symbolic virtual machineROSETTE
[Torlak & Bodik, Onward’13, PLDI’14] interpreter librarySDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert)SDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert) GreenArrays GA144x + z
SDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert) GreenArrays GA144x + z x + z x + z
SDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert)SDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert)SDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert)SDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert)SDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert)SDSLs developed with ROSETTE
21 (first-year grad) (expert) (undergrad) (expert)Modern descendent of Scheme with macro-based metaprogramming.
Anatomy of a solver-aided host language
22Racket
ROSETTE
Anatomy of a solver-aided host language
22 (define-symbolic id type) (assert expr) (verify expr) (debug [expr] expr) (solve expr) (synthesize [expr] expr)A tiny example SDSL
23 def bvmax(r0, r1) : r2 = bvge(r0, r1) r3 = bvneg(r2) r4 = bvxor(r0, r2) r5 = bvand(r3, r4) r6 = bvxor(r1, r5) return r6 BV: A tiny assembly-like language for writing fast, low- level library functions. debug synthA tiny example SDSL
23 def bvmax(r0, r1) : r2 = bvge(r0, r1) r3 = bvneg(r2) r4 = bvxor(r0, r2) r5 = bvand(r3, r4) r6 = bvxor(r1, r5) return r6 BV: A tiny assembly-like language for writing fast, low- level library functions. test verify debug synthA tiny example SDSL
23 def bvmax(r0, r1) : r2 = bvge(r0, r1) r3 = bvneg(r2) r4 = bvxor(r0, r2) r5 = bvand(r3, r4) r6 = bvxor(r1, r5) return r6 BV: A tiny assembly-like language for writing fast, low- level library functions. test verify debug synth 1. interpreter [10 LOC] 2. verifier [free] 3. debugger [free] 4. synthesizer [free]A tiny example SDSL:
24ROSETTE
A tiny example SDSL:
24 (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) parseROSETTE
A tiny example SDSL:
24 (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) parseROSETTE
(out opcode in ...) (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5)))A tiny example SDSL:
25ROSETTE
interpret (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) `(-2 -1)A tiny example SDSL:
25ROSETTE
interpret (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) 0 -2 1 -1 2 3 4 -2 5 6 -1A tiny example SDSL:
25ROSETTE
interpret (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) 0 -2 1 -1 2 3 4 -2 5 6 -1 (2 bvge 0 1)A tiny example SDSL:
25ROSETTE
interpret (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) 0 -2 1 -1 2 3 4 -2 5 6 -1 (2 bvge 0 1)A tiny example SDSL:
25ROSETTE
interpret (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) 0 -2 1 -1 2 3 4 -2 5 6 -1 (2 bvge 0 1)A tiny example SDSL:
25ROSETTE
interpret (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) 0 -2 1 -1 2 3 4 -2 5 6 -1 (2 bvge 0 1)A tiny example SDSL:
25ROSETTE
interpret (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) 0 -2 1 -1 2 3 4 -2 5 6 -1 (2 bvge 0 1) (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5)))A tiny example SDSL:
25ROSETTE
interpret (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5))) 0 -2 1 -1 2 3 4 -2 5 6 -1 (2 bvge 0 1) (define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5)))A tiny example SDSL:
26ROSETTE
(define bvmax `((2 bvge 0 1) (3 bvneg 2) (4 bvxor 0 2) (5 bvand 3 4) (6 bvxor 1 5)))A tiny example SDSL:
27ROSETTE
queryA tiny example SDSL:
27ROSETTE
Creates two fresh symbolic constants of type number and binds them to variables n0 and n1. queryA tiny example SDSL:
27ROSETTE
Symbolic values can be used just like concrete values of the same type. queryA tiny example SDSL:
27ROSETTE
(verify expr) searches for a concrete interpretation of symbolic constants that causes expr to fail. queryA tiny example SDSL:
27ROSETTE
queryA tiny example SDSL:
28ROSETTE
queryA tiny example SDSL:
28ROSETTE
query def bvmax(r0, r1) : r2 = bvge(r0, r1) r3 = bvneg(r2) r4 = bvxor(r0, r2) r5 = bvand(r3, r4) r6 = bvxor(r1, r5) return r6A tiny example SDSL:
29ROSETTE
queryA tiny example SDSL:
29ROSETTE
querysymbolic virtual machine (SVM)
ROSETTE How it all works: a big picture view
31symbolic virtual machine
SDSL programquery
solver
[Torlak & Bodik, Onward’13] [Torlak & Bodik, PLDI’14]ROSETTE How it all works: a big picture view
31symbolic virtual machine
SDSL programresult
solver
[Torlak & Bodik, Onward’13] [Torlak & Bodik, PLDI’14]ROSETTE How it all works: a big picture view
31symbolic virtual machine
SDSL programresult
solver
Translation to constraints by example
32 solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs) reverse and filter, keepingTranslation to constraints by example
32 solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs) vs psTranslation to constraints by example
32 solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs) vs ps constraintsTranslation to constraints by example
32 solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs) vs ps constraintsDesign space of precise symbolic encodings
33 symbolic execution bounded model checking solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs){ }
a > 0 b ≤ 0 falseDesign space of precise symbolic encodings
33 a > 0 b ≤ 0 ps ↦ (a) ps ↦ (a) vs ↦ (a, b) ps ↦ ( ) symbolic execution bounded model checking solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs){ }
a > 0 b ≤ 0 false∨ ∨ ∨ Design space of precise symbolic encodings
33 a > 0 b ≤ 0 ps ↦ (a) ps ↦ (a) vs ↦ (a, b) ps ↦ ( ) b > 0 b > 0 ps ↦ (b) ps ↦ (b, a){ }
a ≤ 0 b > 0 false{ }
a > 0 b > 0 true a ≤ 0 b ≤ 0 ps ↦ ( ) ps ↦ ( ){ }
a ≤ 0 b ≤ 0 false symbolic execution bounded model checking solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs){ }
a > 0 b ≤ 0 false∨ ∨ ∨ Design space of precise symbolic encodings
33 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ps0 a > 0 a ≤ 0 ps0 = ite(a > 0, (a), ( )) ps1 = insert(b, ps0) ps2 = ite(b > 0, ps0, ps1) assert len(ps2) = 2 a > 0 b ≤ 0 ps ↦ (a) ps ↦ (a) vs ↦ (a, b) ps ↦ ( ) b > 0 b > 0 ps ↦ (b) ps ↦ (b, a){ }
a ≤ 0 b > 0 false{ }
a > 0 b > 0 true a ≤ 0 b ≤ 0 ps ↦ ( ) ps ↦ ( ){ }
a ≤ 0 b ≤ 0 false symbolic execution bounded model checking ps ↦ ( ) solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs){ }
a > 0 b ≤ 0 false∨ ∨ ∨ Design space of precise symbolic encodings
33 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ps0 a > 0 a ≤ 0 ps0 = ite(a > 0, (a), ( )) ps1 = insert(b, ps0) ps2 = ite(b > 0, ps0, ps1) assert len(ps2) = 2 a > 0 b ≤ 0 ps ↦ (a) ps ↦ (a) vs ↦ (a, b) ps ↦ ( ) b > 0 b > 0 ps ↦ (b) ps ↦ (b, a){ }
a ≤ 0 b > 0 false{ }
a > 0 b > 0 true a ≤ 0 b ≤ 0 ps ↦ ( ) ps ↦ ( ){ }
a ≤ 0 b ≤ 0 false symbolic execution bounded model checking ps ↦ ( ) ps ↦ ps1 b > 0 solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs){ }
a > 0 b ≤ 0 false∨ ∨ ∨ Design space of precise symbolic encodings
33 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ps0 a > 0 a ≤ 0 ps0 = ite(a > 0, (a), ( )) ps1 = insert(b, ps0) ps2 = ite(b > 0, ps0, ps1) assert len(ps2) = 2 a > 0 b ≤ 0 ps ↦ (a) ps ↦ (a) vs ↦ (a, b) ps ↦ ( ) b > 0 b > 0 ps ↦ (b) ps ↦ (b, a){ }
a ≤ 0 b > 0 false{ }
a > 0 b > 0 true a ≤ 0 b ≤ 0 ps ↦ ( ) ps ↦ ( ){ }
a ≤ 0 b ≤ 0 false symbolic execution bounded model checking ps ↦ ( ) ps ↦ ps1 ps ↦ ps2 b > 0 b ≤ 0 ps ↦ ps0 solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs)A new design: type-driven state merging
34{ }
a > 0 b > 0 true solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs)Merge values of
A new design: type-driven state merging
34{ }
a > 0 b > 0 true solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs)Merge values of
A new design: type-driven state merging
34{ }
a > 0 b > 0 true solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs) ⁊g g cMerge values of
A new design: type-driven state merging
34{ }
a > 0 b > 0 true solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs) ⁊g g c (e, f)Merge values of
A new design: type-driven state merging
34{ }
a > 0 b > 0 true solve: ps = () for v in vs: if v > 0: ps = insert(v, ps) assert len(ps) == len(vs) ⁊g g c (e, f) { ¬g ⊦ a, g ⊦ () } ()A new design: type-driven state merging
35 symbolic virtual machineA new design: type-driven state merging
35 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ( ) symbolic virtual machineSymbolic union: a set
disjoint guards.
g0 = a > 0 g1 = b > 0 g2 = g0 ∧ g1 g3 = ¬(g0 ⇔ g1) g4 = ¬g0 ∧ ¬g1 c = ite(g1, b, a) assert g2 a > 0 a ≤ 0 g0 ¬ g0A new design: type-driven state merging
35 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ( ) symbolic virtual machine ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) }Execute insert concretely on all lists in the union.
g0 = a > 0 g1 = b > 0 g2 = g0 ∧ g1 g3 = ¬(g0 ⇔ g1) g4 = ¬g0 ∧ ¬g1 c = ite(g1, b, a) assert g2 a > 0 a ≤ 0 g1 g0 ¬ g0A new design: type-driven state merging
35 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ( ) symbolic virtual machine ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) } ps ↦ { g0 ⊦ (b, a), ¬g0 ⊦ (b) }A new design: type-driven state merging
35 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ( ) symbolic virtual machine ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) } ps ↦ { g0 ⊦ (b, a), ¬g0 ⊦ (b) } ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) }A new design: type-driven state merging
35 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ( ) symbolic virtual machine ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) } ps ↦ { g0 ⊦ (b, a), ¬g0 ⊦ (b) } ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) } ps ↦ { g2 ⊦ (b, a), g3 ⊦ (c), g4 ⊦ ( ) }Evaluate len concretely
assertion true only on the list guarded by g2.
g0 = a > 0 g1 = b > 0 g2 = g0 ∧ g1 g3 = ¬(g0 ⇔ g1) g4 = ¬g0 ∧ ¬g1 c = ite(g1, b, a) assert g2 a > 0 a ≤ 0 ¬ g1 g1 g0 ¬ g0A new design: type-driven state merging
35 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ( ) symbolic virtual machine ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) } ps ↦ { g0 ⊦ (b, a), ¬g0 ⊦ (b) } ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) } ps ↦ { g2 ⊦ (b, a), g3 ⊦ (c), g4 ⊦ ( ) }A new design: type-driven state merging
35 vs ↦ (a, b) ps ↦ ( ) ps ↦ (a) ps ↦ ( ) symbolic virtual machine ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) } ps ↦ { g0 ⊦ (b, a), ¬g0 ⊦ (b) } ps ↦ { g0 ⊦ (a), ¬g0 ⊦ ( ) } ps ↦ { g2 ⊦ (b, a), g3 ⊦ (c), g4 ⊦ ( ) }concrete evaluation polynomial encoding
Effectiveness of type-driven state merging
36 Merging performance for verification and synthesis queries in SynthCL, WebSynth and IFC programs 10000 20000 30000 40000 number of control flow joins 4500 9000 13500 18000 R² = 0.9884 R² = 0.95 number of unions size of all unionsEffectiveness of type-driven state merging
37 SVM and solving time for verification and synthesis queries in SynthCL, WebSynth and IFC programs running time (sec) 75 150 225 300 FWT3 B1 B2 J2 B3 MM1 J1 FWT1 B4 SF3 CR1 CR2 CR3 FWT4 CR4 MM2 SF1 FWT2 iTunes IMDb MM3 AlAn SF4 SF2 SVM Z3advanced programming for everyone
Where next?
39 less code less time less effort web scraping scripts secure stack machines spatial programs data-parallel programsWhere next?
39 less code less time less effort new kinds of programs harder programsKeeping the programmer in the loop
40 SAT/SMT solver SVM SDSL program?
verify debug execute synthKeeping the programmer in the loop
40 SAT/SMT solver SVM SDSL program?
verify debug execute synthKeeping the programmer in the loop
40 SAT/SMT solver SVM SDSL program?
verify debug execute synth domain properties, invariants, insightKeeping the programmer in the loop
40 SAT/SMT solver SVM SDSL program?
verify debug execute synth domain properties, invariants, insight? ?
Keeping the programmer in the loop
40 SAT/SMT solver SVM SDSL program?
verify debug execute synth domain properties, invariants, insightsymbolic profiling
? ?
Keeping the system in the loop
41 SAT/SMT solver SVM?
verify debug execute synth domain properties, invariants, insight SDSL programsymbolic design patterns Keeping the system in the loop
41 SAT/SMT solver SVM?
verify debug execute synth domain properties, invariants, insight SDSL programDomain-specific solvers
42?
verify debug execute synth Sometimes you need a special-purpose solver … SDSL programDomain-specific solvers for everyone
43?
verify debug execute synthsynthesis of domain- specific solvers
So long, and thanks for all the fish!