gradual programming: bridging the semantic gap bor-yuh evan chang bor-yuh evan chang amer diwan...

8
Gradual Programming: Gradual Programming: Bridging the Semantic Bridging the Semantic Gap Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT 2009

Upload: tyrone-evans

Post on 18-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT

Gradual Programming: Gradual Programming: Bridging the Semantic GapBridging the Semantic Gap

Bor-Yuh Evan ChangBor-Yuh Evan Chang Amer Diwan Jeremy G. Siek

University of Colorado, Boulder

PLDI FIT 2009

Page 2: Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT

2

Have you noticed a time where your Have you noticed a time where your program is not optimized where you program is not optimized where you expect?expect?

Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming

“I need a map data structure”

“I need a map data structure”

Load class fileRun class initializationCreate hashtable

Load class fileRun class initializationCreate hashtable

ProblemProblem: Tools (IDEs, checkers, optimizers) have no knowledge of what the programmer cares about

ProblemProblem: Tools (IDEs, checkers, optimizers) have no knowledge of what the programmer cares about

… hampering programmer productivity, software reliability, and execution efficiency

… hampering programmer productivity, software reliability, and execution efficiency

semantic gap

ObservationObservation: A disconnect between programmer intent and program meaning

Page 3: Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT

3

Example: Iteration OrderExample: Iteration Order

class OpenArray extends Object {private Double data[]; public boolean contains(Object

lookFor) {for (i = 0; i < data.length; i++) {

if (data[i].equals(lookFor)) return true;

}return false;

}}

Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming

Compiler cannot choose a different iteration order (e.g., parallelparallel)

Compiler cannot choose a different iteration order (e.g., parallelparallel)

class OpenArray extends Object {private Double data[]; public boolean contains(Object

lookFor) {for (i = 0; i < data.length; i++) {

if (data[i].equals(lookFor)) return true;

}return false;

}}

Must specify an iteration Must specify an iteration orderorder even when it should not matter

Must specify an iteration Must specify an iteration orderorder even when it should not matter

Page 4: Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT

4

Wild and Crazy Idea: Use Non-Wild and Crazy Idea: Use Non-DeterminismDeterminism

• Programmer starts with a potentially non-deterministic program

• Analysis identifies instances of “under-determinedness”

• Programmer eliminates “under-determinedness”

Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming

class OpenArray extends Object {private Double data[]; public boolean contains(Object lookFor)

{for (i = 0; i < data.length; i++) {

if (data[i].equals(lookFor)) return true;

}return false;

}}

class OpenArray extends Object {private Double data[]; public boolean contains(Object lookFor)

{for (i = 0; i < data.length; i++) {

if (data[i].equals(lookFor)) return true;

}return false;

}}

class OpenArray extends Object {private Double data[]; public boolean contains(Object lookFor)

{ i 0 .. data.length-1 {

if (data[i].equals(lookFor)) return true;

}return false;

}}

class OpenArray extends Object {private Double data[]; public boolean contains(Object lookFor)

{ i 0 .. data.length-1 {

if (data[i].equals(lookFor)) return true;

}return false;

}}

“over-determined”

“under-determined”

just right

starting point

QuestionQuestion: What does this mean? Is it “under-determined”?ResponseResponse: Depends, is the iteration order important?

QuestionQuestion: What does this mean? Is it “under-determined”?ResponseResponse: Depends, is the iteration order important?

Page 5: Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT

5

Let’s try a few program variantsLet’s try a few program variants

Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming

public boolean contains(Object lookFor) {

for (i = data.length-1; i >= 0; i--) {if (data[i].equals(lookFor))

return true; }return false;

}

public boolean contains(Object lookFor) {

for (i = data.length-1; i >= 0; i--) {if (data[i].equals(lookFor))

return true; }return false;

}

public boolean contains(Object lookFor) {

for (i = 0; i < data.length; i++) {if (data[i].equals(lookFor))

return true; }return false;

}

public boolean contains(Object lookFor) {

for (i = 0; i < data.length; i++) {if (data[i].equals(lookFor))

return true; }return false;

}

public boolean contains(Object lookFor) {

parallel_for (0, data.length-1) i => {if (data[i].equals(lookFor))

return true; }return false;

}

public boolean contains(Object lookFor) {

parallel_for (0, data.length-1) i => {if (data[i].equals(lookFor))

return true; }return false;

}

Do they compute the same result?Do they compute the same result?

ApproachApproach: Try to verify equivalence of program variants up to a specification

ApproachApproach: Try to verify equivalence of program variants up to a specificationYes Pick any oneNo Ask user

Yes Pick any oneNo Ask user

What about here?What about here?

Page 6: Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT

6

Surprisingly, analysis says no. Surprisingly, analysis says no. Why? Why?

Exceptions!

Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming

Need user interaction to refine specification that captures programmer intent

Need user interaction to refine specification that captures programmer intent

nulla.data =

a.contains( )left-to-right iteration

returns true

right-to-left iterationthrows

NullPointerException

Page 7: Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT

7

Scary Proposal?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

Page 8: Gradual Programming: Bridging the Semantic Gap Bor-Yuh Evan Chang Bor-Yuh Evan Chang Amer Diwan Jeremy G. Siek University of Colorado, Boulder PLDI FIT

8

Bridging the Semantic GapBridging the Semantic Gap

Bor-Yuh Evan Chang, Amer Diwan, and Jeremy G. Siek - Gradual Programming

“I need a map data structure”

“I need a map data structure”

“Looks like iterator order matters for your program”

“Looks like iterator order matters for your program”

“Yes, I need iteration in sorted order”

“Yes, I need iteration in sorted order”

“Let’s use a balanced binary tree (TreeMap)”

“Let’s use a balanced binary tree (TreeMap)”