direct manipulation for imperative programs
play

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


  1. 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

  2. 5 Variable values Call stack code

  3. 6 Python tutor [Guo SIGCSE 2013]

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

  5. 8

  6. 9

  7. 10

  8. 11

  9. 12 int i = 0 ;

  10. Direct State Manipulation

  11. 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

  12. 15 Problem definition 𝑄 β€² 𝑄 Correct programs w.r.t. manipulation Search Space

  13. 16 To solve this problem we need concrete ways to β€’ Describe the search space β€’ Specify the correctness β€’ Search for a solution

  14. 17 To solve this problem we need concrete ways to β€’ Describe the search space: program sketching β€’ Specify the correctness β€’ Search for a solution

  15. 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 + ??; }

  16. 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; } }

  17. 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

  18. 21 To solve this problem we need concrete ways to β€’ Describe the search space: program sketching β€’ Specify the correctness β€’ Search for a solution

  19. 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;

  20. 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;

  21. 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;

  22. 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;

  23. 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;

  24. 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;

  25. 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;

  26. 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;

  27. 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;

  28. 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;

  29. 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;

  30. 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