On Interactive Synthesis of Code Snippets Tihomir Gvero























 : String Encoding in FOL def m 5[A](lst : A) : String](https://slidetodoc.com/presentation_image/14d24a9e80ea8aa1fd8ad0a486953375/image-24.jpg)
 : String has. Type(m 5, Arrow(A, Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A,](https://slidetodoc.com/presentation_image/14d24a9e80ea8aa1fd8ad0a486953375/image-25.jpg)
 : String has. Type(m 5, Arrow(A, Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A,](https://slidetodoc.com/presentation_image/14d24a9e80ea8aa1fd8ad0a486953375/image-26.jpg)
 : String has. Type(m 5, Arrow(A, Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A,](https://slidetodoc.com/presentation_image/14d24a9e80ea8aa1fd8ad0a486953375/image-27.jpg)
 : String has. Type(m 5, Arrow(A, Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A,](https://slidetodoc.com/presentation_image/14d24a9e80ea8aa1fd8ad0a486953375/image-28.jpg)
 : String has. Type(m 5, Arrow(A, Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A,](https://slidetodoc.com/presentation_image/14d24a9e80ea8aa1fd8ad0a486953375/image-29.jpg)




![Evaluation Program # Loaded Declarations # Methods in Synthesized Snippets Time [s] File. Reader Evaluation Program # Loaded Declarations # Methods in Synthesized Snippets Time [s] File. Reader](https://slidetodoc.com/presentation_image/14d24a9e80ea8aa1fd8ad0a486953375/image-34.jpg)



- Slides: 37
On Interactive Synthesis of Code Snippets Tihomir Gvero, Ruzica Piskac, Viktor Kuncak
Introduction Search for method composition in large and complex libraries Substantial effort Obstructing Auto Complete in IDE Predicting a symbol that the user wants to type No need to read source code and doc. Code Synthesis – Synthesizes code from specification
Introduction Search for method composition in large and complex libraries Substantial effort Obstructing Auto Complete in IDE Predicting a symbol that the user wants to type No need to read source code and doc. Code Synthesis – Synthesizes code from specification Can we combine Auto Complete with Code Synthesis?
Introduction Search for method composition in large and complex libraries Substantial effort Obstructing Auto Complete in IDE Predicting a symbol that the user wants to type No need to read source code and doc. Code Synthesis – Synthesizes code from specification Can we combine Auto Complete with Code Synthesis? YES
Introduction Search for method composition in large and complex libraries Substantial effort Obstructing Auto Complete in IDE Predicting a symbol that the user wants to type No need to read source code and doc. Code Synthesis – Synthesizes code from specification In. Synth - a tool that suggests multiple meaningful expressions at a given program point
In. Synth Implemented for Scala language Input: Partial Scala program – visible declarations Program point – desired type Output: Type Information Code snippets – expression with desired type Runs synthesis algorithm based on resolution to find candidate snippets Handles simple and generic (parametric) types
Example def fopen(name: String): File = {. . . } def fread(f: File, p: Int): Data = {. . . } var current. Pos : Int = 0 var fname : String= null. . . def get. Data(): Data = ?
Example def fopen(name: String): File = {. . . } def fread(f: File, p: Int): Data = {. . . } var current. Pos : Int = 0 var fname : String= null. . . def get. Data(): Data = ? DEMO
………………………… ………………………… …………… Program point Max steps Find all visible symbols
………………………… ………………………… …………… Program point Max steps Find all visible symbols Create clauses: - encode in FOL - assign weights
………………………… ………………………… …………… Find all visible symbols Create clauses: - encode in FOL - assign weights Program point Resolution algorithm with weights Max steps
………………………… ………………………… …………… Find all visible symbols Create clauses: - encode in FOL - assign weights Program point Resolution algorithm with weights Max steps Code snippets
Encoding in FOL def m 1(): Int
Encoding in FOL def m 1(): Int has. Type(m 1, Int)
Encoding in FOL def m 1(): Int Predicate has. Type(m 1, Int)
Encoding in FOL def m 1(): Int Predicate has. Type(m 1, Int) def m 2(a 1: Int): Boolean
Encoding in FOL def m 1(): Int Predicate has. Type(m 1, Int) def m 2(a 1: Int): Boolean has. Type(m 2, Arrow(Int, Boolean)))
Encoding in FOL def m 1(): Int Predicate has. Type(m 1, Int) def m 2(a 1: Int): Boolean Function Symbol has. Type(m 2, Arrow(Int, Boolean)))
Encoding in FOL def m 3(a 1: Int, a 2: Boolean): String
Encoding in FOL def m 3(a 1: Int, a 2: Boolean): String has. Type(m 3, Arrow(Int, Arrow(Boolean, String)))
Encoding in FOL def m 3(a 1: Int, a 2: Boolean): String has. Type(m 3, Arrow(Int, Arrow(Boolean, String))) def m 4(fun: Int=>Boolean): String
Encoding in FOL def m 3(a 1: Int, a 2: Boolean): String has. Type(m 3, Arrow(Int, Arrow(Boolean, String))) def m 4(fun: Int=>Boolean): String has. Type(m 4, Arrow(Int, Boolean), String))
Encoding in FOL def m 5[A](lst : A) : String
Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A, String))
Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A, String)) Univ. quan. Variable
Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A, String)) def m 6(): String = ? Univ. quan. Variable
Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A, String)) def m 6(): String = ? query(String) Univ. quan. Variable
Encoding in FOL def m 5[A](lst : A) : String has. Type(m 5, Arrow(A, String)) def m 6(): String = ? Predicate query(String) Univ. quan. Variable
Rules Forward Reasoning: has. Type(f, Arrow(T 1, T 2)) has. Type(a, T 1) has. Type(f(a), T 2) Example: def f(arg: T 1): T 2 f(a): T 2 var a: T 1
Rules Backward Reasoning: has. Type(f, Arrow(T 1, T 2)) query(T 2) query(T 1) Example: def f(arg: T 1): T 2 var a: T 2 = ? arg: T 1 = ?
Rules Deriving empty clause: has. Type(x, T 1) query(T 1) Example: def f(): T 1 f() var a: T 1 = ?
Weights Symbol weights Low High User preferred Arrow Method and field symbols Local symbols Term weights API symbols Knuth-Bendix ordering Recalculate weight of terms with user preferred symbols Clause weights Sum of all terms’ weight in clause
Evaluation Program # Loaded Declarations # Methods in Synthesized Snippets Time [s] File. Reader 6 4 < 0. 001 Map 4 4 < 0. 001 File. Manager 3 3 < 0. 001 Calendar 7 3 < 0. 001 File. Writer 320 6 0. 093 Swing. Border 161 2 0. 016 Tcp. Service 89 2 < 0. 001
Evaluation Rank Examples Percentage 1 38 46% 2 21 25% 3 10 12% 4 2 2% 5 1 1% 72 87% Same Behavior 6 7% Diff. Behavior 5 6% Missed 11 13% Total 83 100% Match
Conclusion In. Synth - the first interactively deployed synthesis tool: Parameterized types Weights indicating preferences Based on a variation of an ordered resolution calculus We have found to be fast enough and helpful in synthesizing meaningful code fragments Future work: Weights mining
Thank you