tihomir gvero, ruzica piskac, viktor kuncak

40
Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Upload: others

Post on 15-Oct-2021

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Page 2: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

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

Page 3: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

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?

Page 4: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

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

Page 5: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

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

iSynth - a tool that suggests multiple meaningfulexpressions at a given program point

Page 6: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Implemented for Scala language Input: Partial Scala program – visible declarations Program point – desired type

Output: Code snippets – expression with desired type

Runs synthesis algorithm based on resolution to find candidate snippets

Handles simple and generic (parametric) types

Type Information

Page 7: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def fopen(name:String):File = { ... }def fread(f:File, p:Int):Data = { ... }var currentPos : Int = 0var fname : String= null...def getData():Data = ?

Page 8: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def fopen(name:String):File = { ... }def fread(f:File, p:Int):Data = { ... }var currentPos : Int = 0var fname : String= null...def getData():Data = ?

DEMO

Page 9: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def map[A,B](f: A=>B, l:List[A]):List[B] = { ... }def stringConcat(lst : List[String]) :String = { ... }...def printInts(intList: List[Int], fun:Int=>String):String = ?

Page 10: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def map[A,B](f: A=>B, l:List[A]):List[B] = { ... }def stringConcat(lst : List[String]) :String = { ... }...def printInts(intList: List[Int], fun:Int=>String):String = ?

DEMO

Page 11: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

object Calendar {private val events:List[Event] = { … }

def reserve(user:User, date:Date):Event = { ... }def getEvent(user:User, date:Date):Event = { ... }def remove(user:User, date:Date):Event = ?

}

Page 12: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

object Calendar {private val events:List[Event] = { … }

def reserve(user:User, date:Date):Event = { ... }def getEvent(user:User, date:Date):Event = { ... }def remove(user:User, date:Date):Event = ?

}

DEMO

Page 13: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Program point

Max steps

…………………………………………………………………………………………………………………………………………………………………………………………………………………………………

Page 14: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Program point

Max steps

Find all visible symbols

…………………………………………………………………………………………………………………………………………………………………………………………………………………………………

Page 15: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Program point

Max steps

Create clauses:- encode in FOL - assign weights

Find all visible symbols

…………………………………………………………………………………………………………………………………………………………………………………………………………………………………

Page 16: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Program point

Max steps

Create clauses:- encode in FOL - assign weights

Find all visible symbols

Resolution algorithm with weights

…………………………………………………………………………………………………………………………………………………………………………………………………………………………………

Page 17: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Program point

Max steps

Create clauses:- encode in FOL - assign weights

Find all visible symbols

Resolution algorithm with weights

…………………………………………………………………………………………………………………………………………………………………………………………………………………………………

Code snippets

Page 18: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m1():Int

Page 19: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m1():Int

hasType(m1, Int)

Page 20: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m1():Int

hasType(m1, Int)

Predicate

Page 21: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m1():Int

hasType(m1, Int)

def m2(a1:Int):Boolean

Predicate

Page 22: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m1():Int

hasType(m1, Int)

def m2(a1:Int):Boolean

hasType(m2, Arrow(Int, Boolean)))

Predicate

Page 23: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m1():Int

hasType(m1, Int)

def m2(a1:Int):Boolean

hasType(m2, Arrow(Int, Boolean)))

Predicate

Function Symbol

Page 24: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m3(a1: Int, a2:Boolean):String

Page 25: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m3(a1: Int, a2:Boolean):String

hasType(m3, Arrow(Int, Arrow(Boolean, String)))

Page 26: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m3(a1: Int, a2:Boolean):String

hasType(m3, Arrow(Int, Arrow(Boolean, String)))

def m4(fun:Int=> Boolean):String

Page 27: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m3(a1: Int, a2:Boolean):String

hasType(m3, Arrow(Int, Arrow(Boolean, String)))

def m4(fun:Int=>Boolean):String

hasType(m4, Arrow(Arrow(Int,Boolean),String))

Page 28: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m5[A](lst :A) :String

Page 29: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m5[A](lst :A) :String

hasType(m5, Arrow(A, String))

Page 30: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m5[A](lst :A) :String

hasType(m5, Arrow(A, String))

Univ. quan.Variable

Page 31: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m5[A](lst :A) :String

hasType(m5, Arrow(A, String))

def m6():String = ?

Univ. quan.Variable

Page 32: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m5[A](lst :A) :String

hasType(m5, Arrow(A, String))

def m6():String = ?

query(String)

Univ. quan.Variable

Page 33: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

def m5[A](lst :A) :String

hasType(m5, Arrow(A, String))

def m6():String = ?

query(String)

Univ. quan.Variable

Predicate

Page 34: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Forward Reasoning:

hasType(f, Arrow(T1, T2)) hasType(a, T1)hasType(f(a), T2)

Example:

def f(arg:T1):T2 var a:T1f(a): T2

Page 35: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Backward Reasoning:

hasType(f, Arrow(T1, T2)) query(T2)query(T1)

Example:

def f(arg:T1):T2 var a:T2 = ?arg: T1 = ?

Page 36: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Deriving empty clause:

hasType(x, T1) query(T1)

Example:

def f():T1 var a:T1 = ?f()

Page 37: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Symbol weights

User preferred

Local symbols

Method and field symbolsAPI symbols

Term weights Knuth-Bendix ordering Recalculate weight of terms with user preferred symbols

Clause weights Sum of all terms’ weight in clause

Arrow

Low High

Page 38: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Program # Loaded Declarations

# Methods in Synthesized Snippets

Time [s]

FileReader 5 4 0.001Map 3 3 < 0.001

FileManager 7 3 0.001Calendar 29 3 0.001FileWriter 442 6 0.72

SwingBorder 161 2 0.02TcpService 112 3 0.62

Page 39: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

iSynth - 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

Page 40: Tihomir Gvero, Ruzica Piskac, Viktor Kuncak

Thank you