codehint dynamic and interactive synthesis of code
play

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:


  1. CodeHint: Dynamic and Interactive Synthesis of Code Snippets Joel Galenson, Ras Bodik, Koushik Sen UC Berkeley 1 / 21

  2. Motivation Specification Test cases Desired type 2 / 21 Pictures by Mangpo Phitchaya Phothilimthana

  3. CodeHint: Autocomplete for the modern age ● Autocomplete is useful but very limited. ● Our improvements: – Being dynamic – General specifications – Synthesis 3 / 21

  4. Overview Source code Combine Test case Candidates Find locals Evaluate Candidates Specification CodeHint Refine 4 / 21

  5. Example: The problem 5 / 21

  6. Example: First step “Find a JMenuBar” 6 / 21

  7. Demo 7 / 21

  8. 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. Iteration 1 Iteration 2 Iteration 3 + x average x y ... max + max y x y x y x y ... ... ... 8 / 21

  9. First iteration ● Find local variables. ... x y tree this null 9 / 21

  10. Second iteration ● Get each expression's type and combine it with others in type-correct ways. + < ... x x y x y getPathForLocation getPathForLocation getTopLevelAncestor ... tree (JTree) x y (JTree) y x tree tree tree getWindowAncestor ... SwingUtilities tree 10 / 21

  11. Side effects ● Handle in-memory and external effects. In-memory: add Breakpoints tree makeTree() ... tree.children changed from to renderer renderer makeTree() renderer makeTree() children ... tree External: delete file SecurityManager 11 / 21

  12. Equivalence classes ● Group equivalent code to avoid unneeded work. getTopLevelAncestor getRoot tree SwingUtilities tree getName getName getTopLevelAncestor getRoot Next iteration: tree SwingUtilities tree getJMenuBar getJMenuBar getJMenuBar End of search: getTopLevelAncestor getTopLevelAncestor getRoot 12 / 21 tree tree SwingUtilities tree

  13. Probabilistic model ● Mined 10MLOC to build model of likely code. Probability of accessing method/field m on type T: Probability of using constant c as argument i to method m: ● Use to avoid unlikely expressions. getNextMatch getComponent tree ... tree KeyEvent.VK_ENTER 13 / 21

  14. Third iteration and result getJMenuBar + 1 getRowForLocation (JFrame) ... Third iteration: getTopLevelAncestor (JTree) x y tree tree getJMenuBar getJMenuBar Result: (JFrame) (JFrame) getTopLevelAncestor getRoot tree SwingUtilities tree 14 / 21

  15. Refinement ● Users can give another demonstration in a different state to refine the results. getJMenuBar getJMenuBar (JFrame) (JFrame) ... getTopLevelAncestor getWindowAncestor SwingUtilities tree tree 15 / 21

  16. Synthesis from specifications Context- independent API Program exploration synthesis Static type Correctness condition rv instanceof JMenuBar isSorted(array) Context- dependence x.toString().contains(“Eve”) Programming by demonstration Context- Value demonstrations dependent x == 42 Weak Strength Strong 16 / 21

  17. Empirical results Our algorithms work well in practice. 17 / 21 In real-world code, ~95% of expressions need ≤3 iterations and ~99% need ≤4.

  18. 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. Higher is better Lower is better 18 / 21

  19. Future work ● Improving the probabilistic model ● CodeHint for JavaScript – https://github.com/jgalenson/codehint.js – ● Integrating symbolic techniques 19 / 21

  20. Probabilistic search getJMenuBar Model getWindowAncestor (JFrame) SwingUtilities tree getWindowAncestor ; SwingUtilities tree foo bar ... 20 / 21 Candidates

  21. Summary ● Dynamic and interactive synthesis ● Autocomplete for the modern age ● User studies showed productivity improvements Thanks! https://jgalenson.github.io/codehint/ 21 / 21

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend