Download presentation
Presentation is loading. Please wait.
Published byAlison Bridges Modified over 8 years ago
1
Programming by Sketching Ras Bodik
2
2 The Problem Problem: k-line algorithm translates to 10-100k lines of code. 30-year-old idea: Can we synthesize the code? No. Search space too large. Our observation: Some code fragments are harder than others. Our idea: Can we synthesize just the hard fragments?
3
3 int[] mergeSort (int[] input, int n) { if ( n == 1 ) return input; return merge(mergeSort (input[0:n/2]), mergeSort (input[n/2:n-1]), n ); } int[] merge (int[] a, int b[], int n) { int j=0; int k=0; for (int i = 0; i < n; i++) if ( a[j] < b[k] ) { result[i] = a[j++]; } else { result[i] = b[k++]; } return result; } Merge Sort looks simple to code, but there is a bug
4
4 Correct Merge Sort int[] mergeSort (int[] input, int n) { if ( n == 1 ) return input; return merge(mergeSort (input[0:n/2]), mergeSort (input[n/2:n-1]), n); } int[] merge (int[] a, int b[], int n) { int j=0; int k=0; for (int i = 0; i < n; i++) if ( j<n/2 && ( !(k<n-n/2) || a[j] < b[k]) ) { result[i] = a[j++]; } else { result[i] = b[k++]; } return result; }
5
5 The sketching experience sketch implementation Movie Script: “Big hairy monster listens patiently to his green friend.” specification + sketch of Merge Sort sketch of Merge Sort completed Merge Sort completed Merge Sort Bubble Sort +
6
6 Sketched Merge Sort int[] mergeSort (int[] input, int n) { if ( n == 1 ) return input; return merge(mergeSort (input[0:n/2]), mergeSort (input[n/2:n-1]), n); } int[] merge (int[] a, int b[], int n) { int j=0; int k=0; for (int i = 0; i < n; i++) if ( j<n/2 && ( !(k<n-n/2) || a[j] < b[k]) ) { result[i] = a[j++]; } else { result[i] = b[k++]; } return result; } hole
7
7 Benefits and Plans Division of labor –programmer writes the strategy/algorithm –synthesizer writes low-level details Immediate plans: –parallel programming! –especially gaming kernels on parallel processors, such as PS3
8
8 Prospector: another sketching project Sketching is promising for performance code: Abstraction gap between spec and implementation. But what about API client code? Even short code is surprisingly hard-to-write. But such code has no concise specification! public void parseJavaFile (IFile file) { ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file); ASTNode node = AST.parseCompilationUnit(cu, false); } public void parseJavaFile (IFile file) { ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file); ASTNode node = AST.parseCompilationUnit(cu, false); }
9
9 Prospector: a very different synthesizer sketch multiple implementations, user chooses one specification hard to write, hence omitted + but the same “sketching formula”
10
10 Sketching in API client code How do we present jungloid synthesis to programmers? hole objects we have object we want
11
11 You are invited to the PS Lunch Live demos by people who did the work... and many other presentations 380 Soda, noon-2pm
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.