CodeHint: Dynamic and Interactive Synthesis of Code Snippets Joel - - PowerPoint PPT Presentation

codehint dynamic and interactive synthesis of code
SMART_READER_LITE
LIVE PREVIEW

CodeHint: Dynamic and Interactive Synthesis of Code Snippets Joel - - PowerPoint PPT Presentation

CodeHint: Dynamic and Interactive Synthesis of Code Snippets Joel Galenson, Ras Bodik, Koushik Sen UC Berkeley 1 / 21 Motivation Specification Test cases Desired type 2 / 21 Pictures by Mangpo Phitchaya Phothilimthana CodeHint:


slide-1
SLIDE 1

1 / 21

CodeHint: Dynamic and Interactive Synthesis of Code Snippets

Joel Galenson, Ras Bodik, Koushik Sen UC Berkeley

slide-2
SLIDE 2

2 / 21

Motivation

Pictures by Mangpo Phitchaya Phothilimthana

Test cases Desired type Specification

slide-3
SLIDE 3

3 / 21

CodeHint: Autocomplete for the modern age

  • Autocomplete is useful but very limited.
  • Our improvements:

– Being dynamic – General specifications – Synthesis

slide-4
SLIDE 4

4 / 21

Overview

CodeHint Source code Test case Specification Candidates Find locals Evaluate Candidates Combine Refine

slide-5
SLIDE 5

5 / 21

Example: The problem

slide-6
SLIDE 6

6 / 21

Example: First step

“Find a JMenuBar”

slide-7
SLIDE 7

7 / 21

Demo

slide-8
SLIDE 8

8 / 21

Basic algorithm

  • Find local variables, do BFS over Java

statements, show user those that pass spec.

– Actually evaluate these statements, including file

I/O, reflection, etc.

x y Iteration 1 x + y x max y Iteration 2 Iteration 3 x max y average x + y ... ... ... ...

slide-9
SLIDE 9

9 / 21

First iteration

  • Find local variables.

x y tree null this ...

slide-10
SLIDE 10

10 / 21

Second iteration

  • Get each expression's type and combine it with
  • thers in type-correct ways.

x x + y x < y ... tree (JTree) getPathForLocation x tree y (JTree) getPathForLocation y tree x tree getTopLevelAncestor ... tree getWindowAncestor SwingUtilities ...

slide-11
SLIDE 11

11 / 21

Side effects

  • Handle in-memory and external effects.

makeTree() add tree children ...

renderer makeTree()

... tree tree.children changed from to

renderer renderer makeTree()

file delete SecurityManager Breakpoints In-memory: External:

slide-12
SLIDE 12

12 / 21

tree getTopLevelAncestor getJMenuBar

Equivalence classes

  • Group equivalent code to avoid unneeded work.

tree getRoot SwingUtilities tree getTopLevelAncestor tree getTopLevelAncestor getName tree getRoot SwingUtilities getName tree getRoot SwingUtilities getJMenuBar tree getTopLevelAncestor getJMenuBar Next iteration: End of search:

slide-13
SLIDE 13

13 / 21

Probabilistic model

  • Mined 10MLOC to build model of likely code.
  • Use to avoid unlikely expressions.

Probability of accessing method/field m on type T: Probability of using constant c as argument i to method m: tree getNextMatch ... KeyEvent.VK_ENTER getComponent tree

slide-14
SLIDE 14

14 / 21

Third iteration and result

tree getTopLevelAncestor (JFrame) getJMenuBar (JTree) getRowForLocation x tree y + 1 ... Third iteration: Result: (JFrame) getJMenuBar tree getRoot SwingUtilities tree getTopLevelAncestor (JFrame) getJMenuBar

slide-15
SLIDE 15

15 / 21

Refinement

  • Users can give another demonstration in a

different state to refine the results.

(JFrame) getJMenuBar tree getWindowAncestor SwingUtilities tree getTopLevelAncestor (JFrame) getJMenuBar ...

slide-16
SLIDE 16

16 / 21

Synthesis from specifications

Strength

Weak Strong

Context- dependence

Context- independent Context- dependent API exploration Program synthesis Programming by demonstration Static type rv instanceof JMenuBar Correctness condition isSorted(array) Value demonstrations x == 42 x.toString().contains(“Eve”)

slide-17
SLIDE 17

17 / 21

Empirical results

In real-world code, ~95% of expressions need ≤3 iterations and ~99% need ≤4.

Our algorithms work well in practice.

slide-18
SLIDE 18

18 / 21

User studies

  • Completed two user studies with 28 subjects.
  • Found statistically-significant productivity

improvements.

– Fewer bugs and more tasks completed in less time.

CodeHint makes programmers more productive.

Lower is better Higher is better

slide-19
SLIDE 19

19 / 21

Future work

  • Improving the probabilistic model
  • CodeHint for JavaScript

– https://github.com/jgalenson/codehint.js –

  • Integrating symbolic techniques
slide-20
SLIDE 20

20 / 21

Probabilistic search

foo ; bar tree getWindowAncestor SwingUtilities ... Model Candidates tree getWindowAncestor SwingUtilities (JFrame) getJMenuBar

slide-21
SLIDE 21

21 / 21

Summary

  • Dynamic and interactive synthesis
  • Autocomplete for the modern age
  • User studies showed productivity improvements

Thanks! https://jgalenson.github.io/codehint/