Direct Manipulation For Imperative Programs Hu 1 , Roopsha Samanta 2 - - PowerPoint PPT Presentation

direct manipulation for imperative programs
SMART_READER_LITE
LIVE PREVIEW

Direct Manipulation For Imperative Programs Hu 1 , Roopsha Samanta 2 - - PowerPoint PPT Presentation

Direct Manipulation For Imperative Programs Hu 1 , Roopsha Samanta 2 , Rishabh Singh 3 , Loris DAntoni 1 Qin Qinhepin ing Hu 1 Universitve of Wisconsin-Madison 2 Purdue University 3 Google 5 Variable values Call stack code 6 Python


slide-1
SLIDE 1

Direct Manipulation For Imperative Programs

Qin Qinhepin ing Hu Hu1 , Roopsha Samanta2 , Rishabh Singh3 , Loris D’Antoni1

1 Universitve of Wisconsin-Madison

2 Purdue University 3 Google

slide-2
SLIDE 2
slide-3
SLIDE 3

5

code Call stack Variable values

slide-4
SLIDE 4

Python tutor [Guo SIGCSE 2013]

6

slide-5
SLIDE 5

7

Given an unsorted array of length N and we have to find largest gap between any two elements of array

slide-6
SLIDE 6

8

slide-7
SLIDE 7

9

slide-8
SLIDE 8

10

slide-9
SLIDE 9

11

slide-10
SLIDE 10

12

int i = 0;

slide-11
SLIDE 11

Direct State Manipulation

slide-12
SLIDE 12

Problem definition

loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Manipulated location Trace on input = {9,5,6,10}

Input Buggy program

loc 1 … 3 i

? max

9

New trace on input = {9,5,6,10}

Don’t care about non-manipulated variables public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i]; } } return max; } 𝑄′

Goal Repaired program

9

Direct manipulation

1 2 3 4 5 6 7 8 9 Manipulated location Manipulated value 𝑄′ is correct on the given manipulation

slide-13
SLIDE 13

Problem definition

15

𝑄 𝑄′ Search Space Correct programs w.r.t. manipulation

slide-14
SLIDE 14

To solve this problem we need concrete ways to

  • Describe the search space
  • Specify the correctness
  • Search for a solution

16

slide-15
SLIDE 15

To solve this problem we need concrete ways to

  • Describe the search space: program sketching
  • Specify the correctness
  • Search for a solution

17

slide-16
SLIDE 16

How to describe the search space

public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i]; } } return max; } public static int getMax(int[] input){ int max = 0 + ??; for(int i = 1 + ??;i < input.length;i++){ if(input[i] > max + ??){ max = input[i] + ??; } } return max + ??; }

slide-17
SLIDE 17

void P(int in){ int c = ??; assert in + in == c * in; } void P(int in){ int c = 2; assert in + in == c * in; }

Program Sketching [Solar-Lezama et al 06]

slide-18
SLIDE 18

To solve this problem we need concrete ways to

  • Describe the search space: program sketching
  • Specify the correctness: guessing the return points
  • Search for a solution

20

slide-19
SLIDE 19

To solve this problem we need concrete ways to

  • Describe the search space: program sketching
  • Specify the correctness
  • Search for a solution

21

slide-20
SLIDE 20

Challenge 1: how to specify the manipulation

int pc = -1; int[] trace_line; public static int getMax(int[] input){ record(2); int max = 0 + ??; record(3); for(int i = 1 + ??;i < input.length;i++){ record(4); if(input[i] > max + ??){ record(5); max = input[i] + ??;} record(3); } record(3); return max + ??; } assert ∃pc.trace_line[pc]==3; void record(int line){ pc++; trace_line[pc] = line; } loc … 3 i … 1 max … 5 Manipulated location Manipulation 9

slide-21
SLIDE 21

Challenge 1: how to specify the manipulation

int pc = -1; int[] trace_line; public static int getMax(int[] input){ record(2); int max = 0 + ??; record(3); for(int i = 1 + ??;i < input.length;i++){ record(4); if(input[i] > max + ??){ record(5); max = input[i] + ??;} record(3); } record(3); return max + ??; } assert ∃pc.trace_line[pc]==3; void record(int line){ pc++; trace_line[pc] = line; } loc … 3 i … 1 max … 5 Manipulated location Manipulation 9

slide-22
SLIDE 22

Challenge 1: how to specify the manipulation

int pc = -1; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2); int max = 0 + ??; record(3); for(int i = 1 + ??;i < input.length;i++){ record(4); if(input[i] > max + ??){ record(5); max = input[i] + ??;} record(3); } record(3); return max + ??; } assert ∃pc.trace_line[pc]==3; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line){ pc++; trace_line[pc] = line; }

slide-23
SLIDE 23

Challenge 1: how to specify the manipulation

int pc = -1; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); } record(3,max); return max + ??; } assert ∃pc.trace_line[pc]==3; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line){ pc++; trace_line[pc] = line; }

slide-24
SLIDE 24

Challenge 1: how to specify the manipulation

int pc = -1; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); } record(3,max); return max + ??; } assert ∃pc.trace_line[pc]==3; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; }

slide-25
SLIDE 25

Challenge 1: how to specify the manipulation

int pc = -1; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); } record(3,max); return max + ??; } assert ∃pc.trace_line[pc]==3 && trace_max[pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; }

slide-26
SLIDE 26

Challenge 2: at which iteration we should return

int pc = -1; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); } record(3,max); return max + ??; } assert ∃pc.trace_line[pc]==3 && trace_max[pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; } We want to find the repair instead of checking existence

slide-27
SLIDE 27

Challenge 2: at which iteration we should return

int pc = -1; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); } record(3,max); return max + ??; } assert ∃pc.trace_line[pc]==3 && trace_max[pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; } There can be multiple possible return points

slide-28
SLIDE 28

Challenge 2: at which iteration we should return

int pc = -1, final_pc = ??; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); } record(3,max); return max + ??; } assert ∃pc.trace_line[pc]==3 && trace_max[pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; } Idea: guess the final program counter

slide-29
SLIDE 29

Challenge 2: at which iteration we should return

int pc = -1, final_pc = ??; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); } record(3,max); return max + ??; } assert ∃pc.trace_line[pc]==3 && trace_max[pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; }

slide-30
SLIDE 30

Challenge 2: at which iteration we should return

int pc = -1, final_pc = ??; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); if(pc == final_pc) return; } record(3,max); return max + ??; } assert ∃pc.trace_line[pc]==3 && trace_max[pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; }

slide-31
SLIDE 31

Challenge 2: at which iteration we should return

int pc = -1, final_pc = ??; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); if(pc == final_pc) return; } record(3,max); if(pc == final_pc) return; return max + ??; } assert ∃pc.trace_line[pc]==3 && trace_max[pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; }

slide-32
SLIDE 32

Challenge 2: at which iteration we should return

int pc = -1, final_pc = ??; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); if(pc == final_pc) return; } record(3,max); if(pc == final_pc) return; return max + ??; } assert ∃ pc.trace_line[final_pc]==3 && trace_max[final_pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; }

slide-33
SLIDE 33

Challenge 2: at which iteration we should return

int pc = -1, final_pc = ??; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); if(pc == final_pc) return; } record(3,max); if(pc == final_pc) return; return max + ??; } assert ∃ pc.trace_line[final_pc]==3 && trace_max[final_pc]==9; loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 void record(int line, int max){ pc++; trace_line[pc] = line; trace_max[pc] = max; }

slide-34
SLIDE 34

To solve this problem we need concrete ways to

  • Describe the search space: program sketching
  • Specify the correctness: guessing the return points
  • Search for a solution:

36

slide-35
SLIDE 35

To solve this problem we need concrete ways to

  • Describe the search space: program sketching
  • Specify the correctness: guessing the return points
  • Search for a solution: Sketch solver

37

slide-36
SLIDE 36

Find solution with Sketch solver

int pc = -1, final_pc = ??; int[] trace_line, trace_max; public static int getMax(int[] input){ record(2,max); int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); if(input[i] > max + ??){ record(5,max); max = input[i] + ??;} record(3,max); If(pc == final_pc) return; } record(3,max); if(pc == final_pc) return; return max + ??; } assert trace_line[pc]==3 && trace_max[pc]==9; Sketch solver public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; }

slide-37
SLIDE 37

Finding a correct solution is not enough

39

𝑄 𝑄′ Search Space Correct programs

slide-38
SLIDE 38

When can we say a solution is better than another?

40

𝑄 𝑄′ Search Space Correct programs 𝑄′′

slide-39
SLIDE 39

Idea 1: edit as less as possible

41

public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i] + 4;} } return max; } public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } input = {9,5,6,10} Change from 1 to 0: cost 1 Change from 0 to 4 : cost 4 loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 Syntactic distance: syntactic similarity between programs 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8

slide-40
SLIDE 40

Idea2: preserve the trace as much as possible

42

public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } input = {9,5,6,10} loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 1 2 3 4 5 6 7 8

slide-41
SLIDE 41

Idea2: preserve the trace as much as possible

43

public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i] - 1;} } return max; } public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } input = {9,5,6,10} Change from 1 to 0 Change from 0 to -1 loc … 3 i … 1 max … 5 Manipulated location Manipulation 9 Both edits are small 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8

slide-42
SLIDE 42

Idea2: preserve the trace as much as possible

44

input = {9,5,6,10} loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Original trace public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } loc 1 2 3 4 5 3 i

  • max
  • 9

New trace public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i] - 1;} } return max; } 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8

slide-43
SLIDE 43

Idea2: preserve the trace as much as possible

45

input = {9,5,6,10} public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } loc 1 2 3 4 5 3 i

  • max
  • 9

New trace public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i] - 1;} } return max; } 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Original trace

slide-44
SLIDE 44

1 2 3 4 5 6 7 8

Idea2: preserve the trace as much as possible

46

input = {9,5,6,10} public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } loc 1 2 3 4 5 3 i

  • max
  • 9

New trace public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i] - 1;} } return max; } loc 1 2 3 4 5 3 4 5 3 4 5 3 i

  • 1

1 1 2 2 2 3 3 3 max

  • 4

4 4 5 5 5 9 New trace Semantic distance: similarity between traces 1 2 3 4 5 6 7 8 loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Original trace

slide-45
SLIDE 45

Program repair with Quantitative Objective [D’

Antoniet al. CAV16]

In program repair via test cases, finding solution with sma mall llest

  • Syn

yntactic ic di distances:

  • syntactic similarity between two programs
  • Sem

Semantic ic di distances:

  • similarity between trace of the original program and trace of repaired program on the given input

47

slide-46
SLIDE 46

Revised problem definition with distance

48

𝑄′ Search Space Correct programs 𝑄

slide-47
SLIDE 47

Revised problem definition with distance

49

Search Space Correct programs 𝑄 𝑄′ Smallest distance

slide-48
SLIDE 48

Encode distance in Sketching

  • Syntactic distance example: sum of values of all holes

50

public static int getMax(int[] input){ int max = 0 + ??; for(int i = 1 + ??;i < input.length;i++){ if(input[i] > max + ??){ max = input[i] + ??;} } return max + ??; } assert trace_line[pc]==3 && trace_max[pc]==9; SynDistance = ∑??

slide-49
SLIDE 49

Encode distance in Sketching

  • Syntactic distance example: sum of values of all holes

51

int SyntacticDistance(){ int dist = 0; for(int = 0; i < input_holes; i++){ dist += ??_i } return dist; } public static int getMax(int[] input){ int max = 0 + ??; for(int i = 1 + ??;i < input.length;i++){ if(input[i] > max + ??){ max = input[i] + ??;} } return max + ??; } assert trace_line[pc]==3 && trace_max[pc]==9;

slide-50
SLIDE 50

Encode distance in Sketching

  • Syntactic distance example: sum of values of all holes
  • Semantic distance example: Hamming distance between traces

52

int SemanticDistance(int[] oriTrace, int[] trace){ int dist = 0; for(int = 0; i < oriTrace.length; i++){ dist += oriTrace[i] != trace[i]; } return dist; } loc 1 2 3 4 5 3 i

  • max
  • 9

New trace loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Original trace

slide-51
SLIDE 51

Quantitative objective in Sketch

53

assert trace_line[pc]==3 && trace_max[pc]==9; minimize SyntacticDistance() + SemanticDistance(oriTrace,trace); loc … 3 i … 1 ma max … 5 Manipulated location Manipulation 9

slide-52
SLIDE 52

Overview of JDial

54

slide-53
SLIDE 53

The tool JDial

55

Test cases Trace + Manipulation JDial Backend input: 9

  • ->

Specification TraceDistance(t1, t2){ // computes semantic // distance between // traces t1 and t2 return Hamming(t1, t2) } SyntacticDistance( ){ // computes syntactic // distance from original // program based on holes if (??1 != 1) dist += ??1; … } input 2 4 ...

  • utput

12 42 ... Sketch Buggy Program Aggregate(d1, d2){ // combines the // two distances return d1+ d2; } Fixed Program

line 16 x: 0 -> 3 y: 2 -> ?

// Instrumentation variables counter, line[], valx[], valy[], ret_val // Instrumented program SkProg(input) { // Adds holes to encode repair // space and to compute traces ... counter++; y = ??1 x + ??2 y + ??3; line[counter] = 20; valx[counter] = x; … } // Functional assertions + distance computations // Direct manipulation SkProg(9); assert(valx[16]=3); semDist += TraceDistance(..., ...) // Test Cases assert(SkProg(2)=12); semDist += TraceDistance(..., ...) assert(SkProg(4)=42); semDist += TraceDistance(..., ...) ... synDist = SyntacticDistance() minimize(Aggregate(synDist, semDist)); 1. Prog(input) { … … 16. x = 5y+2; … 20. y = y+2 … } 1. Prog(input) { … … 16. x = 5y+2; … 20. y = x-1; … } GetRepairSpace(){ // returns a sketched version // of Prog that encodes // the repair space e.g., replace constants with ?? }

slide-54
SLIDE 54

The tool JDial

56

Test cases Trace + Manipulation JDial Backend input: 9

  • ->

Specification TraceDistance(t1, t2){ // computes semantic // distance between // traces t1 and t2 return Hamming(t1, t2) } SyntacticDistance( ){ // computes syntactic // distance from original // program based on holes if (??1 != 1) dist += ??1; … } input 2 4 ...

  • utput

12 42 ... Sketch Buggy Program Aggregate(d1, d2){ // combines the // two distances return d1+ d2; } Fixed Program

line 16 x: 0 -> 3 y: 2 -> ?

// Instrumentation variables counter, line[], valx[], valy[], ret_val // Instrumented program SkProg(input) { // Adds holes to encode repair // space and to compute traces ... counter++; y = ??1 x + ??2 y + ??3; line[counter] = 20; valx[counter] = x; … } // Functional assertions + distance computations // Direct manipulation SkProg(9); assert(valx[16]=3); semDist += TraceDistance(..., ...) // Test Cases assert(SkProg(2)=12); semDist += TraceDistance(..., ...) assert(SkProg(4)=42); semDist += TraceDistance(..., ...) ... synDist = SyntacticDistance() minimize(Aggregate(synDist, semDist)); 1. Prog(input) { … … 16. x = 5y+2; … 20. y = y+2 … } 1. Prog(input) { … … 16. x = 5y+2; … 20. y = x-1; … } GetRepairSpace(){ // returns a sketched version // of Prog that encodes // the repair space e.g., replace constants with ?? }

Replace expression to linear combination of variables L1 distance

  • n changed

constants Hamming distance

slide-55
SLIDE 55

The tool JDial

57

Test cases Trace + Manipulation JDial Backend input: 9

  • ->

Specification TraceDistance(t1, t2){ // computes semantic // distance between // traces t1 and t2 return Hamming(t1, t2) } SyntacticDistance( ){ // computes syntactic // distance from original // program based on holes if (??1 != 1) dist += ??1; … } input 2 4 ...

  • utput

12 42 ... Sketch Buggy Program Aggregate(d1, d2){ // combines the // two distances return d1+ d2; } Fixed Program

line 16 x: 0 -> 3 y: 2 -> ?

// Instrumentation variables counter, line[], valx[], valy[], ret_val // Instrumented program SkProg(input) { // Adds holes to encode repair // space and to compute traces ... counter++; y = ??1 x + ??2 y + ??3; line[counter] = 20; valx[counter] = x; … } // Functional assertions + distance computations // Direct manipulation SkProg(9); assert(valx[16]=3); semDist += TraceDistance(..., ...) // Test Cases assert(SkProg(2)=12); semDist += TraceDistance(..., ...) assert(SkProg(4)=42); semDist += TraceDistance(..., ...) ... synDist = SyntacticDistance() minimize(Aggregate(synDist, semDist)); 1. Prog(input) { … … 16. x = 5y+2; … 20. y = y+2 … } 1. Prog(input) { … … 16. x = 5y+2; … 20. y = x-1; … } GetRepairSpace(){ // returns a sketched version // of Prog that encodes // the repair space e.g., replace constants with ?? }

slide-56
SLIDE 56

The tool JDial

58

Test cases Trace + Manipulation JDial Backend input: 9

  • ->

Specification TraceDistance(t1, t2){ // computes semantic // distance between // traces t1 and t2 return Hamming(t1, t2) } SyntacticDistance( ){ // computes syntactic // distance from original // program based on holes if (??1 != 1) dist += ??1; … } input 2 4 ...

  • utput

12 42 ... Sketch Buggy Program Aggregate(d1, d2){ // combines the // two distances return d1+ d2; } Fixed Program

line 16 x: 0 -> 3 y: 2 -> ?

// Instrumentation variables counter, line[], valx[], valy[], ret_val // Instrumented program SkProg(input) { // Adds holes to encode repair // space and to compute traces ... counter++; y = ??1 x + ??2 y + ??3; line[counter] = 20; valx[counter] = x; … } // Functional assertions + distance computations // Direct manipulation SkProg(9); assert(valx[16]=3); semDist += TraceDistance(..., ...) // Test Cases assert(SkProg(2)=12); semDist += TraceDistance(..., ...) assert(SkProg(4)=42); semDist += TraceDistance(..., ...) ... synDist = SyntacticDistance() minimize(Aggregate(synDist, semDist)); 1. Prog(input) { … … 16. x = 5y+2; … 20. y = y+2 … } 1. Prog(input) { … … 16. x = 5y+2; … 20. y = x-1; … } GetRepairSpace(){ // returns a sketched version // of Prog that encodes // the repair space e.g., replace constants with ?? }

slide-57
SLIDE 57

The tool JDial

59

Test cases Trace + Manipulation JDial Backend input: 9

  • ->

Specification TraceDistance(t1, t2){ // computes semantic // distance between // traces t1 and t2 return Hamming(t1, t2) } SyntacticDistance( ){ // computes syntactic // distance from original // program based on holes if (??1 != 1) dist += ??1; … } input 2 4 ...

  • utput

12 42 ... Sketch Buggy Program Aggregate(d1, d2){ // combines the // two distances return d1+ d2; } Fixed Program

line 16 x: 0 -> 3 y: 2 -> ?

// Instrumentation variables counter, line[], valx[], valy[], ret_val // Instrumented program SkProg(input) { // Adds holes to encode repair // space and to compute traces ... counter++; y = ??1 x + ??2 y + ??3; line[counter] = 20; valx[counter] = x; … } // Functional assertions + distance computations // Direct manipulation SkProg(9); assert(valx[16]=3); semDist += TraceDistance(..., ...) // Test Cases assert(SkProg(2)=12); semDist += TraceDistance(..., ...) assert(SkProg(4)=42); semDist += TraceDistance(..., ...) ... synDist = SyntacticDistance() minimize(Aggregate(synDist, semDist)); 1. Prog(input) { … … 16. x = 5y+2; … 20. y = y+2 … } 1. Prog(input) { … … 16. x = 5y+2; … 20. y = x-1; … } GetRepairSpace(){ // returns a sketched version // of Prog that encodes // the repair space e.g., replace constants with ?? }

slide-58
SLIDE 58

The tool JDial

60

Test cases Trace + Manipulation JDial Backend input: 9

  • ->

Specification TraceDistance(t1, t2){ // computes semantic // distance between // traces t1 and t2 return Hamming(t1, t2) } SyntacticDistance( ){ // computes syntactic // distance from original // program based on holes if (??1 != 1) dist += ??1; … } input 2 4 ...

  • utput

12 42 ... Sketch Buggy Program Aggregate(d1, d2){ // combines the // two distances return d1+ d2; } Fixed Program

line 16 x: 0 -> 3 y: 2 -> ?

// Instrumentation variables counter, line[], valx[], valy[], ret_val // Instrumented program SkProg(input) { // Adds holes to encode repair // space and to compute traces ... counter++; y = ??1 x + ??2 y + ??3; line[counter] = 20; valx[counter] = x; … } // Functional assertions + distance computations // Direct manipulation SkProg(9); assert(valx[16]=3); semDist += TraceDistance(..., ...) // Test Cases assert(SkProg(2)=12); semDist += TraceDistance(..., ...) assert(SkProg(4)=42); semDist += TraceDistance(..., ...) ... synDist = SyntacticDistance() minimize(Aggregate(synDist, semDist)); 1. Prog(input) { … … 16. x = 5y+2; … 20. y = y+2 … } 1. Prog(input) { … … 16. x = 5y+2; … 20. y = x-1; … } GetRepairSpace(){ // returns a sketched version // of Prog that encodes // the repair space e.g., replace constants with ?? }

slide-59
SLIDE 59

The tool JDial

61

Test cases Trace + Manipulation JDial Backend input: 9

  • ->

Specification TraceDistance(t1, t2){ // computes semantic // distance between // traces t1 and t2 return Hamming(t1, t2) } SyntacticDistance( ){ // computes syntactic // distance from original // program based on holes if (??1 != 1) dist += ??1; … } input 2 4 ...

  • utput

12 42 ... Sketch Buggy Program Aggregate(d1, d2){ // combines the // two distances return d1+ d2; } Fixed Program

line 16 x: 0 -> 3 y: 2 -> ?

// Instrumentation variables counter, line[], valx[], valy[], ret_val // Instrumented program SkProg(input) { // Adds holes to encode repair // space and to compute traces ... counter++; y = ??1 x + ??2 y + ??3; line[counter] = 20; valx[counter] = x; … } // Functional assertions + distance computations // Direct manipulation SkProg(9); assert(valx[16]=3); semDist += TraceDistance(..., ...) // Test Cases assert(SkProg(2)=12); semDist += TraceDistance(..., ...) assert(SkProg(4)=42); semDist += TraceDistance(..., ...) ... synDist = SyntacticDistance() minimize(Aggregate(synDist, semDist)); 1. Prog(input) { … … 16. x = 5y+2; … 20. y = y+2 … } 1. Prog(input) { … … 16. x = 5y+2; … 20. y = x-1; … } GetRepairSpace(){ // returns a sketched version // of Prog that encodes // the repair space e.g., replace constants with ?? }

Replace expression to linear combination of variables Sum of values of all holes Hamming distance + difference of length max = input[i] + ??*max + ?? * i+ ??

slide-60
SLIDE 60

Evaluation

62

slide-61
SLIDE 61

Benchmarks

63

12 5

slide-62
SLIDE 62

Benchmarks

64

12 5 Avg LOC: 6.9

slide-63
SLIDE 63

Benchmarks

65

12 5 Avg Vars: 4.1

slide-64
SLIDE 64

Benchmarks

66

12 5 Avg |Trace|: 17.4

slide-65
SLIDE 65

Benchmarks

67

public static int largestGap(int[] input){ int max = 0; int min = 100; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i]; } if(input[i] < min){ min = input[i]; } } return max-min; } Incorrect initialization

slide-66
SLIDE 66

Benchmarks

68

public static int largestGap(int[] input){ int max = 0; int min = 100; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i]; } if(input[i] < min){ min = input[i]; } } return max-min; } Incorrect loop condition

slide-67
SLIDE 67

Benchmarks

69

public static int max3(int x, int y, int z){ if(x > y){ y = x; } if(y > z){ z = x; } return z; } Incorrect assignment

slide-68
SLIDE 68

Question 1: Can JDial produce better repairs than Qlose*?

* D’Antoni et al, Qlose: program repair with quantitative objectives [CAV16]

70

JDial Qlose Program repair via test cases

slide-69
SLIDE 69

Question 1: Can JDial produce better repairs than Qlose*?

* D’Antoni et al, Qlose: program repair with quantitative objectives [CAV16]

71

𝑄 Random input

JDial Qlose

Manipulation Test case Random input 𝑄

We provide the manipulation by pretending to be users

slide-70
SLIDE 70

Question 1: Can JDial produce better repairs than Qlose*?

72

5 different random inputs

slide-71
SLIDE 71

JDial vs one test case

74

On how many random inputs each tool can solve the benchmark

slide-72
SLIDE 72

Avoid overfitting for single test case

75

Test cases: {9,5,6} -> 9 public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max + 4; } 1 2 3 4 5 6 7 public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } 1 2 3 4 5 6 7 loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Manipulated location Trace on input = {9,5,6} 9 Repair via manipulation Repair via test case

slide-73
SLIDE 73

Avoid overfitting for single test case

76

Test cases: {9,5,6} -> 9 loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Manipulated location Trace on input = {9,5,6} 9 public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max + 4; } 1 2 3 4 5 6 7 public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } 1 2 3 4 5 6 7 Repair via manipulation Repair via test case

Program repair via test cases prefer to modify return statement Keep all traces unchanged before return

slide-74
SLIDE 74

Provide one more test case

77

𝑄 Random input 1

JDial Qlose

Manipulation Test case Random input 1 𝑄 Test case Random input 2 Test case Random input 2

slide-75
SLIDE 75

JDial + one test case vs two test cases

78

slide-76
SLIDE 76

Question 2: How sensitive is JDial with respect to the trace location at which the state manipulation is performed?

79

𝑄 Random input

JDial

Manipulation

What if manipulation is not the “best” one

slide-77
SLIDE 77

Question 2: How sensitive is JDial with respect to the trace location at which the state manipulation is performed?

80

loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Manipulated location Trace on input = {9,5,6,10} 9 public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i]; } } return max; } 1 2 3 4 5 6 7 8 9

slide-78
SLIDE 78

Question 2: How sensitive is JDialwith respect to the trace location at which the state manipulation is performed?

81

loc 1 2 3 4 i

  • 1

max

  • Trace on input = {9,5,6,10}

public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i]; } } return max; } 1 2 3 4 5 6 7 8 9 Manipulated location

slide-79
SLIDE 79

Question 2: How sensitive is JDialwith respect to the trace location at which the state manipulation is performed?

82

loc 1 2 3 4 5 3 4 5 3 i

  • 1

1 1 2 2 2 max

  • 5

5 5 6 Trace on input = {9,5,6,10} public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i]; } } return max; } 1 2 3 4 5 6 7 8 9 Manipulated location 9

We will lose the good repair with this manipulation

slide-80
SLIDE 80

Question 2: How sensitive is JDialwith respect to the trace location at which the state manipulation is performed?

83

On how muchp ercentage

  • f random inputs we lose

the desired repair due to the late manipulation

Number of steps after the chosen manipulation

slide-81
SLIDE 81

Question 2: How sensitive is JDialwith respect to the trace location at which the state manipulation is performed?

84

Number of steps after the chosen manipulation

Lose about 75% if we manipulate one step after the chosen manipulation

slide-82
SLIDE 82

Question 2: How sensitive is JDialwith respect to the trace location at which the state manipulation is performed?

85

Converge to repair with

  • ne teste case

Number of steps after the chosen manipulation

slide-83
SLIDE 83

Question 2: How sensitive is JDialwith respect to the trace location at which the state manipulation is performed?

86

Converge to repair with two teste cases

slide-84
SLIDE 84

Comparison to program repair via test cases

87

slide-85
SLIDE 85

Avoid overfitting for single test case

88

Test cases: {9,5,6} -> 9 public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max + 4; } 1 2 3 4 5 6 7 public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } 1 2 3 4 5 6 7 loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Manipulated location Trace on input = {9,5,6} 9 Repair via manipulation Repair via test case

slide-86
SLIDE 86

Avoid overfitting for single test case

89

Test cases: {9,5,6} -> 9 loc 1 2 3 4 5 3 i

  • 1

1 1 max

  • 5

Manipulated location Trace on input = {9,5,6} 9 public static int getMax(int[] input){ int max = 0; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max + 4; } 1 2 3 4 5 6 7 public static int getMax(int[] input){ int max = 0; for(int i = 0;i < input.length;i++){ if(input[i] > max){ max = input[i];} } return max; } 1 2 3 4 5 6 7 Repair via manipulation Repair via test case

Program repair via test cases prefer to modify return statement Keep all traces unchanged before return

slide-87
SLIDE 87

Hard to write test cases for partial implementations

90

public static int largestGap(int[] input){ int max = 0; int min = 100; for(int i = 1;i < input.length;i++){ if(input[i] > max){ max = input[i]; } //TODO: implement min } int result = max-min; return result; } Test cases: {9,5,6,10} -> ?

slide-88
SLIDE 88

Conclusion

91

slide-89
SLIDE 89

New specification mechanism that can yield better repair than test cases JDia JDial: l: a tool for repairing programs via direct state manipulation Can we make the approach less sensitive to manipulated location? Can JDial scale better?

Test cases Trace + Manipulation JDial Backend input: 9

  • ->

Specification TraceDistance(t1, t2){ // computes semantic // distance between // traces t1 and t2 return Hamming(t1, t2) } SyntacticDistance( ){ // computes syntactic // distance from original // program based on holes if (??1 != 1) dist += ??1; … } input 2 4 ...

  • utput

12 42 ... Sketch Buggy Program Aggregate(d1, d2){ // combines the // two distances return d1+ d2; } Fixed Program

line 16 x: 0 -> 3 y: 2 -> ?

// Instrumentation variables counter, line[], valx[], valy[], ret_val // Instrumented program SkProg(input) { // Adds holes to encode repair // space and to compute traces ... counter++; y = ??1 x + ??2 y + ??3; line[counter] = 20; valx[counter] = x; … } // Functional assertions + distance computations // Direct manipulation SkProg(9); assert(valx[16]=3); semDist += TraceDistance(..., ...) // Test Cases assert(SkProg(2)=12); semDist += TraceDistance(..., ...) assert(SkProg(4)=42); semDist += TraceDistance(..., ...) ... synDist = SyntacticDistance() minimize(Aggregate(synDist, semDist)); 1. Prog(input) { … … 16. x = 5y+2; … 20. y = y+2 … } 1. Prog(input) { … … 16. x = 5y+2; … 20. y = x-1; … } GetRepairSpace(){ // returns a sketched version // of Prog that encodes // the repair space e.g., replace constants with ?? }

slide-90
SLIDE 90

93