Bridging the Semantic Gap in Gradual Programming
80 likes | 194 Vues
Explore the disconnect between programmer intent and program meaning, hindering productivity and efficiency. Learn how gradual programming tackles this issue with examples and wild ideas.
Bridging the Semantic Gap in Gradual Programming
E N D
Presentation Transcript
Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan ChangAmerDiwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT 2009
Have you noticed a time where your program is not optimized where you expect? Observation: A disconnect between programmer intent and program meaning “I need a map data structure” Load class file Run class initialization Create hashtable semantic gap Problem: Tools (IDEs, checkers, optimizers) have no knowledge of what the programmer cares about … hampering programmer productivity, software reliability, and execution efficiency Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming
Example: Iteration Order classOpenArrayextends Object { private Double data[]; public booleancontains(ObjectlookFor) { for (i = 0; i < data.length; i++) { if (data[i].equals(lookFor)) return true; } return false; } } Must specify an iteration order even when it should not matter classOpenArrayextends Object { private Double data[]; public booleancontains(ObjectlookFor) { for (i = 0; i<data.length; i++) { if (data[i].equals(lookFor)) return true; } return false; } } Compiler cannot choose a different iteration order (e.g., parallel) Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming
Wild and Crazy Idea: Use Non-Determinism • Programmer starts with a potentially non-deterministic program • Analysis identifies instances of “under-determinedness” • Programmer eliminates “under-determinedness” “over-determined” just right Question: What does this mean? Is it “under-determined”? Response: Depends, is the iteration order important? classOpenArrayextends Object { private Double data[]; public booleancontains(ObjectlookFor) { • for (i = 0; i < data.length; i++) { • if (data[i].equals(lookFor)) return true; • } return false; } } classOpenArrayextends Object { private Double data[]; public booleancontains(ObjectlookFor) { • i 0 .. data.length-1 { • if (data[i].equals(lookFor)) return true; • } return false; } } starting point “under-determined” Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming
Let’s try a few program variants • public booleancontains(ObjectlookFor) { • for (i = 0; i < data.length; i++) { • if(data[i].equals(lookFor)) return true; } • return false; • } Do they compute the same result? Approach: Try to verify equivalence of program variants up to a specification • public booleancontains(ObjectlookFor) { • for (i = data.length-1; i >= 0; i--) { • if(data[i].equals(lookFor)) return true; } • return false; • } Yes Pick any one No Ask user • public booleancontains(ObjectlookFor) { • parallel_for (0, data.length-1) i => { • if(data[i].equals(lookFor)) return true; } • return false; • } What about here? Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming
Surprisingly, analysis says no. Why? Exceptions! Need user interaction to refine specification that captures programmer intent a.data= null a.contains( ) left-to-right iteration returns true right-to-left iteration throws NullPointerException Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming
Scary Proposal? • “Fix semantics per program”: Abstract constructs with many possible concrete implementations • Apply program analysis to find inconsistent implementations • Interact with the user to refine the specification • Language designer role can enumerate the possible implementations Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming
Bridging the Semantic Gap “I need a map data structure” “Looks like iterator order matters for your program” “Yes, I need iteration in sorted order” “Let’s use a balanced binary tree (TreeMap)” Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming