Direct Manipulation For Imperative Programs Hu 1 , Roopsha Samanta 2 , Rishabh Singh 3 , Loris DβAntoni 1 Qin Qinhepin ing Hu 1 Universitve of Wisconsin-Madison 2 Purdue University 3 Google
5 Variable values Call stack code
6 Python tutor [Guo SIGCSE 2013]
7 Given an unsorted array of length N and we have to find largest gap between any two elements of array
8
9
10
11
12 int i = 0 ;
Direct State Manipulation
Problem definition Direct manipulation Buggy program Manipulated location Input public static int getMax(int[] input){ 1 int max = 0; 2 Trace on input = {9,5,6,10} 3 for(int i = 1;i < input.length;i++){ 4 if(input[i] > max){ loc 1 2 3 4 5 3 max = input[i]; 5 i - - - 1 1 1 } 6 } 7 9 max - - 0 0 0 5 8 return max; 9 } New trace on input = {9,5,6,10} Repaired program Goal Manipulated location loc 1 β¦ 3 π β² is correct on the given manipulation π β² i - β¦ ? Donβt care about non -manipulated variables Manipulated value max - β¦ 9
15 Problem definition π β² π Correct programs w.r.t. manipulation Search Space
16 To solve this problem we need concrete ways to β’ Describe the search space β’ Specify the correctness β’ Search for a solution
17 To solve this problem we need concrete ways to β’ Describe the search space: program sketching β’ Specify the correctness β’ Search for a solution
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 + ??; }
Program Sketching [Solar-Lezama et al 06] void P(int in){ void P(int in){ int c = ?? ; int c = 2 ; assert in + in == c * in; assert in + in == c * in; } }
20 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
21 To solve this problem we need concrete ways to β’ Describe the search space: program sketching β’ Specify the correctness β’ Search for a solution
Challenge 1: how to specify the manipulation Manipulation int pc = -1; loc β¦ 3 int[] trace_line; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2); max β¦ 5 9 int max = 0 + ??; record(3); for(int i = 1 + ??;i < input.length;i++){ record(4); void record(int line){ if(input[i] > max + ??){ pc++; record(5); trace_line[pc] = line; max = input[i] + ??;} record(3); } } record(3); return max + ??; } assert β pc.trace_line[pc]==3;
Challenge 1: how to specify the manipulation Manipulation int pc = -1; loc β¦ 3 int[] trace_line; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2); max β¦ 5 9 int max = 0 + ??; record(3); for(int i = 1 + ??;i < input.length;i++){ record(4); void record(int line){ if(input[i] > max + ??){ pc++; record(5); trace_line[pc] = line; max = input[i] + ??;} record(3); } } record(3); return max + ??; } assert β pc.trace_line[pc]==3;
Challenge 1: how to specify the manipulation Manipulation int pc = -1; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2); max β¦ 5 9 int max = 0 + ??; record(3); for(int i = 1 + ??;i < input.length;i++){ record(4); void record(int line){ if(input[i] > max + ??){ pc++; record(5); trace_line[pc] = line; max = input[i] + ??;} record(3); } } record(3); return max + ??; } assert β pc.trace_line[pc]==3;
Challenge 1: how to specify the manipulation Manipulation int pc = -1; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line){ if(input[i] > max + ??){ pc++; record(5,max); trace_line[pc] = line; max = input[i] + ??;} record(3,max); } } record(3,max); return max + ??; } assert β pc.trace_line[pc]==3;
Challenge 1: how to specify the manipulation Manipulation int pc = -1; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line, int max){ if(input[i] > max + ??){ pc++; record(5,max); trace_line[pc] = line; max = input[i] + ??;} trace_max[pc] = max; record(3,max); } } record(3,max); return max + ??; } assert β pc.trace_line[pc]==3;
Challenge 1: how to specify the manipulation Manipulation int pc = -1; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line, int max){ if(input[i] > max + ??){ pc++; record(5,max); trace_line[pc] = line; max = input[i] + ??;} trace_max[pc] = max; record(3,max); } } record(3,max); return max + ??; } assert β pc.trace_line[pc]==3 && trace_max[pc]==9;
Challenge 2: at which iteration we should return Manipulation int pc = -1; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line, int max){ if(input[i] > max + ??){ pc++; record(5,max); trace_line[pc] = line; max = input[i] + ??;} trace_max[pc] = max; record(3,max); } We want to find the repair instead of checking existence } record(3,max); return max + ??; } assert β pc.trace_line[pc]==3 && trace_max[pc]==9;
Challenge 2: at which iteration we should return Manipulation int pc = -1; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line, int max){ if(input[i] > max + ??){ pc++; record(5,max); There can be multiple possible return points trace_line[pc] = line; max = input[i] + ??;} trace_max[pc] = max; record(3,max); } } record(3,max); return max + ??; } assert β pc.trace_line[pc]==3 && trace_max[pc]==9;
Challenge 2: at which iteration we should return Manipulation Idea: guess the final program counter int pc = -1, final_pc = ??; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line, int max){ if(input[i] > max + ??){ pc++; record(5,max); trace_line[pc] = line; max = input[i] + ??;} trace_max[pc] = max; record(3,max); } } record(3,max); return max + ??; } assert β pc.trace_line[pc]==3 && trace_max[pc]==9;
Challenge 2: at which iteration we should return Manipulation int pc = -1, final_pc = ??; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line, int max){ if(input[i] > max + ??){ pc++; record(5,max); trace_line[pc] = line; max = input[i] + ??;} trace_max[pc] = max; record(3,max); } } record(3,max); return max + ??; } assert β pc.trace_line[pc]==3 && trace_max[pc]==9;
Challenge 2: at which iteration we should return Manipulation int pc = -1, final_pc = ??; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line, int max){ if(input[i] > max + ??){ pc++; record(5,max); trace_line[pc] = line; max = input[i] + ??;} trace_max[pc] = max; record(3,max); if(pc == final_pc) return; } } record(3,max); return max + ??; } assert β pc.trace_line[pc]==3 && trace_max[pc]==9;
Challenge 2: at which iteration we should return Manipulation int pc = -1, final_pc = ??; loc β¦ 3 int[] trace_line, trace_max; Manipulated location public static int getMax(int[] input){ i β¦ 1 record(2,max); max β¦ 5 9 int max = 0 + ??; record(3,max); if(pc == final_pc) return; for(int i = 1 + ??;i < input.length;i++){ record(4,max); void record(int line, int max){ if(input[i] > max + ??){ pc++; record(5,max); trace_line[pc] = line; max = input[i] + ??;} trace_max[pc] = max; 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;
Recommend
More recommend