Graph-based, Self-Supervised Program Repair from Diagnostic Feedback - - PowerPoint PPT Presentation

graph based self supervised program repair from
SMART_READER_LITE
LIVE PREVIEW

Graph-based, Self-Supervised Program Repair from Diagnostic Feedback - - PowerPoint PPT Presentation

Graph-based, Self-Supervised Program Repair from Diagnostic Feedback ICML 2020 Michihiro Yasunaga, Percy Liang Stanford University Why program repair? Programmers spend 75% of time fixing source code errors Automatic program repair can


slide-1
SLIDE 1

Graph-based, Self-Supervised Program Repair from Diagnostic Feedback

ICML 2020

Michihiro Yasunaga, Percy Liang Stanford University

slide-2
SLIDE 2

Why program repair?

Programmers spend 75% of time fixing source code errors Automatic program repair can dramatically enhance programming productivity

2

Dream Reality

slide-3
SLIDE 3

Theme: Learning from Feedback

Humans learn from feedback Write code → compile/execute → repair code based on feedback

3

slide-4
SLIDE 4

Theme: Learning from Feedback

Humans learn from feedback Write code → compile/execute → repair code based on feedback

4

slide-5
SLIDE 5

Theme: Learning from Feedback

Humans learn from feedback Write code → compile/execute → repair code based on feedback General framework with many other applications

  • Edit essays based on written feedback
  • Learn from user inputs in interactive dialogue

5

Repair programs based on errors Edit essays based on feedback

slide-6
SLIDE 6

Example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

6

Broken program

slide-7
SLIDE 7

Example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

7

Broken program

Should be

`string`

slide-8
SLIDE 8

Example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

8

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

Evaluator (compiler) Feedback

slide-9
SLIDE 9

Example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

9

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

Evaluator (compiler) Feedback

slide-10
SLIDE 10

Example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

10

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

Evaluator (compiler) Feedback

slide-11
SLIDE 11

Example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

11

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

Evaluator (compiler) Feedback

slide-12
SLIDE 12

Example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

12

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

Evaluator (compiler) Feedback

slide-13
SLIDE 13

Example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

13

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

Evaluator (compiler) Feedback

  • 1. Error localized line 5
  • 2. Repair

char tmp, a, b; → string tmp, a, b;

Repair!

slide-14
SLIDE 14

Goal: learn to repair programs from error messages

14

slide-15
SLIDE 15

Goal: learn to repair programs from error messages

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

15

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

Diagnostic Feedback

slide-16
SLIDE 16

Goal: learn to repair programs from error messages

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

16

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

  • 1. Error localized line 5

Dr Repair (our system)

Diagnostic Feedback

slide-17
SLIDE 17

Goal: learn to repair programs from error messages

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

17

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

  • 1. Error localized line 5
  • 2. Repair

char tmp, a, b; → string tmp, a, b;

Dr Repair (our system)

Diagnostic Feedback

slide-18
SLIDE 18

Challenges

1. Modeling

○ How to connect two modalities: program and feedback? ○ How to model the reasoning of repair (e.g. tracking symbols)?

18

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () 10 tmp.push_back(a [i]); 11 string tmp1 = tmp; ...

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

?

slide-19
SLIDE 19

Challenges

1. Modeling

○ How to connect two modalities: program and feedback? ○ How to model the reasoning of repair (e.g. tracking symbols)?

2. Data

○ Existing works rely on labeled datasets of <broken code, fixed code> ○ Relatively small (10–100K data points). How to scale up?

19

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () 10 tmp.push_back(a [i]); 11 string tmp1 = tmp; ...

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

?

slide-20
SLIDE 20

Our contributions

1. Program-feedback graph ○ Connect symbols across program & feedback ○ Performs reasoning via graph-attention

20

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp; ...

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char char size size

b b

slide-21
SLIDE 21

Our contributions

  • 2. Self-supervised learning

○ Collect unlabeled programs ○ Corrupt and get diagnostic feedback (e.g. run compiler) ⇒ Extra training data: <broken code, feedback, fixed code>

21

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[i]; 11 cout << i; }

Corrupted

5 int i, n; 6 char A; 7 cin >> n . 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[j]; 11 cout << i; }

Error!

line 7: expected ‘;’

compiler corrupt

slide-22
SLIDE 22

Our results

Improved performance on two applications

  • DeepFix: correct intro programming assignments in C
  • SPoC: correct output of C++ program synthesis

22

SPoC TestP DeepFix Test

slide-23
SLIDE 23

Outline

  • Innovations
  • 1. Reasoning via program-feedback graph
  • 2. Self-supervised learning
  • Evaluations
  • 1. DeepFix
  • 2. SPoC
  • Analysis & Examples
  • Takeaways

23

slide-24
SLIDE 24
  • 1. Reasoning via program-feedback graph

24

slide-25
SLIDE 25
  • 1. Reasoning via program-feedback graph

Challenges

  • How to connect two modalities: program and feedback?
  • How to model the reasoning of repair (e.g. tracking symbols)?

25

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

?

slide-26
SLIDE 26
  • 1. Reasoning via program-feedback graph

Our solution: program-feedback graph

26

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char char size size

b b

slide-27
SLIDE 27
  • 1. Reasoning via program-feedback graph

Our solution: program-feedback graph

  • Join program & feedback through symbols relevant to program repair

→ shared/abstracted semantic space

27

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char char size size

b b

slide-28
SLIDE 28
  • 1. Reasoning via program-feedback graph

Our solution: program-feedback graph

  • Join program & feedback through symbols relevant to program repair

→ shared/abstracted semantic space

  • Reason over this space using graph attention

28

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char char size size

b b

slide-29
SLIDE 29
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

29

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

slide-30
SLIDE 30
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

30

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

<data type>

slide-31
SLIDE 31
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

31

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

<identifier> <data type>

slide-32
SLIDE 32
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

32

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

<identifier> <data type>

slide-33
SLIDE 33
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

33

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

<identifier> <data type>

slide-34
SLIDE 34
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

34

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

<identifier> <data type> <operator>

slide-35
SLIDE 35
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

35

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

<diagnostic argument> <identifier> <data type> <operator>

slide-36
SLIDE 36
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

36

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

<diagnostic argument> <identifier> <data type> <operator>

slide-37
SLIDE 37
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types

37

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘char ’

<diagnostic argument> <identifier> <data type> <operator>

slide-38
SLIDE 38
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types
  • Nodes: diagnostic arguments

38

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ ‘a’ char size

slide-39
SLIDE 39
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types
  • Nodes: diagnostic arguments, their occurences

39

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char size

slide-40
SLIDE 40
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types
  • Nodes: diagnostic arguments, their occurences

40

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char char size

slide-41
SLIDE 41
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types
  • Nodes: diagnostic arguments, their occurences

41

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char char size size

slide-42
SLIDE 42
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types
  • Nodes: diagnostic arguments, their occurences, and all identifiers

42

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char char size size

b b

slide-43
SLIDE 43
  • 1. Reasoning via program-feedback graph

How to construct graph?

  • Recognize token types
  • Nodes: diagnostic arguments, their occurences, and all identifiers
  • Edges: connect identical tokens to capture semantic correspondence

43

Source code

4 int main() { 5 char tmp, a, b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size () ... 10 tmp.push_back(a [i]); 11 string tmp1 = tmp;

Compiler message

request for member ‘size ’ in ‘a’, which is of non-class type ‘Char ’ a ‘a’ a a a char char size size

b b

slide-44
SLIDE 44

44

  • 1. Reasoning via program-feedback graph

Model

  • Initial encoding
  • Graph attention
  • Recontextualization
  • Decoding
slide-45
SLIDE 45

45

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Initial encoding)

slide-46
SLIDE 46

46

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Initial encoding)

x13 x12 x11 Line 1

slide-47
SLIDE 47

47

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Initial encoding)

x13 x12 x11 x13 x12 x11 Line 2 Line 1

slide-48
SLIDE 48

48

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Initial encoding)

x13 x12 x11 x13 x12 x11 x13 x12 x11 Line 3 Source code Line 2 Line 1

slide-49
SLIDE 49

49

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Initial encoding)

x13 x12 x11 x13 x12 x11 x13 x12 x11 m3 m2 m1 ierr Line 3 Source code

Line idx Msg content Feedback (compiler message)

Line 2 Line 1

slide-50
SLIDE 50

50

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Initial encoding)

LSTM code(1) LSTM code(1) LSTM code(1) LSTM msg(1) x13 x12 x11 x13 x12 x11 x13 x12 x11 m3 m2 m1 ierr Line 3 Source code

Line idx Msg content Feedback (compiler message)

Line 2 Line 1

Position embedding

slide-51
SLIDE 51

51

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Graph attention)

LSTM code(1) LSTM code(1) LSTM code(1) LSTM msg(1)

Graph Attention

x13 x12 x11 x13 x12 x11 x13 x12 x11 m3 m2 m1 ierr Line 3 Source code

Line idx Msg content Feedback (compiler message)

Line 2 Line 1

Position embedding

slide-52
SLIDE 52

52

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Graph attention)

  • Message passing across tokens with long-range dependencies

Line 1 Line 2 Line 3 Compiler message hx11 hx12 hx13 ... hm 1 hm 2 hm 3 .. hx21 hx22 hx23 ... hx31 hx32 hx33 ... hm1 ’

Aggregate

Program-Feedback Graph

Multi-Head Attention

slide-53
SLIDE 53

53

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Graph attention)

LSTM code(1) LSTM code(1) LSTM code(1) LSTM msg(1)

Graph Attention

x13 x12 x11 x13 x12 x11 x13 x12 x11 m3 m2 m1 ierr Line 3 Source code

Line idx Msg content Feedback (compiler message)

Line 2 Line 1

Position embedding

slide-54
SLIDE 54

54

Graph Attention

Line 3

Line idx Msg content

Line 2 Line 1

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Recontextualization)

slide-55
SLIDE 55

55

LSTM code(2) LSTM code(2) LSTM code(2) LSTM msg(2)

Graph Attention

Line 3

Line idx Msg content

Line 2 Line 1

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Recontextualization)

slide-56
SLIDE 56

56

LSTM code(2) LSTM code(2) LSTM code(2) LSTM msg(2)

Graph Attention

LSTM code(3) Line 3

Line idx Msg content

Line 2 Line 1

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Recontextualization)

slide-57
SLIDE 57

57

LSTM code(2) LSTM code(2) LSTM code(2) LSTM msg(2)

Graph Attention

MLP

+ softmax

Localize = 2

LSTM code(3) Line 3

Line idx Msg content

Line 2 Line 1

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Decoding)

slide-58
SLIDE 58

58

LSTM code(2) LSTM code(2) LSTM code(2) LSTM msg(2)

Graph Attention

Pointer-Generator Decoder

MLP

+ softmax

Repair = "string tmp,a,b;" Localize = 2

LSTM code(3) Line 3

Line idx Msg content

Line 2 Line 1

Source code

1 int main() { 2 char tmp, a, b; 3 map<string,int> mp; ...

Compiler message

9: request for member ‘size ’ …

  • 1. Reasoning via program-feedback graph

Model (Decoding)

slide-59
SLIDE 59
  • 1. Reasoning via program-feedback graph

Model overview

59

slide-60
SLIDE 60
  • 2. Self-supervised learning

60

slide-61
SLIDE 61
  • 2. Self-supervised learning

Why?

  • Labeled datasets of program repair are small (10-100K examples)
  • Vast amount of unlabeled programs available online
  • Can we leverage them to improve learning?

61

>> 1M submissions > 30M repos

slide-62
SLIDE 62
  • 2. Self-supervised learning

Our idea (outline)

Step 1. Collect unlabeled, working programs y Step 2. Design (randomized) program corruption procedure P Step 3. Corrupt and get diagnostic feedback (e.g. run compiler) ⇒ Extra training data: <broken code x, feedback f, fixed code y> Step 4. Use them for pre-training

62

slide-63
SLIDE 63
  • 2. Self-supervised learning
  • 1. Collect unlabeled programs
  • Our target tasks (DeepFix & SPoC) are in C/C++
  • Collect 300K working C++ programs from codeforces.com

63

slide-64
SLIDE 64
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors (know your enemy)

64

Error type Common compiler messages Statistics Expected ...

  • operator/punctuator
  • primary expression

expected @@@ (e.g. expected ‘;’ before...) missing @@@ (e.g. missing ")

Identifier type

redeclaration/conflicting declaration invalid conversion from <type> to <type>

Identifier undeclared

@@@ was not declared

Others

‘else’ without a previous ‘if’ no matching function for call to... [Gupta et al. 17] [Mesbah et al. 19] [Kulal et al. 19]

slide-65
SLIDE 65
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors (know your enemy)

65

Error type Common compiler messages Statistics

Experienced

Expected ...

  • operator/punctuator
  • primary expression

expected @@@ (e.g. expected ‘;’ before...) missing @@@ (e.g. missing ")

9%

Identifier type

redeclaration/conflicting declaration invalid conversion from <type> to <type>

9%

Identifier undeclared

@@@ was not declared

62%

Others

‘else’ without a previous ‘if’ no matching function for call to...

20%

[Gupta et al. 17] [Mesbah et al. 19] [Kulal et al. 19]

slide-66
SLIDE 66
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors (know your enemy)

66

Error type Common compiler messages Statistics

Experienced Beginner

Expected ...

  • operator/punctuator
  • primary expression

expected @@@ (e.g. expected ‘;’ before...) missing @@@ (e.g. missing ")

9% 48%

  • 37%
  • 11

Identifier type

redeclaration/conflicting declaration invalid conversion from <type> to <type>

9% 5%

Identifier undeclared

@@@ was not declared

62% 33%

Others

‘else’ without a previous ‘if’ no matching function for call to...

20% 14%

[Gupta et al. 17] [Mesbah et al. 19] [Kulal et al. 19]

slide-67
SLIDE 67
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors (know your enemy)

67

Error type Common compiler messages Statistics

Experienced Beginner SPoC

Expected ...

  • operator/punctuator
  • primary expression

expected @@@ (e.g. expected ‘;’ before...) missing @@@ (e.g. missing ")

9% 48%

  • 37%
  • 11

35%

  • 29%
  • 6%

Identifier type

redeclaration/conflicting declaration invalid conversion from <type> to <type>

9% 5% 18%

Identifier undeclared

@@@ was not declared

62% 33% 31%

Others

‘else’ without a previous ‘if’ no matching function for call to...

20% 14% 16%

[Gupta et al. 17] [Mesbah et al. 19] [Kulal et al. 19]

slide-68
SLIDE 68
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors (know your enemy)

68

Error type Common compiler messages Statistics

Experienced Beginner SPoC

Avg.

Expected ...

  • operator/punctuator
  • primary expression

expected @@@ (e.g. expected ‘;’ before...) missing @@@ (e.g. missing ")

9% 48%

  • 37%
  • 11

35%

  • 29%
  • 6%

30%

  • 23%
  • 7%

Identifier type

redeclaration/conflicting declaration invalid conversion from <type> to <type>

9% 5% 18%

11%

Identifier undeclared

@@@ was not declared

62% 33% 31%

42%

Others

‘else’ without a previous ‘if’ no matching function for call to...

20% 14% 16%

17%

[Gupta et al. 17] [Mesbah et al. 19] [Kulal et al. 19]

slide-69
SLIDE 69
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors (know your enemy)

69

Error type Common compiler messages Statistics

Experienced Beginner SPoC

Avg.

Expected ...

  • operator/punctuator
  • primary expression

expected @@@ (e.g. expected ‘;’ before...) missing @@@ (e.g. missing ")

9% 48%

  • 37%
  • 11

35%

  • 29%
  • 6%

30%

  • 23%
  • 7%

Identifier type

redeclaration/conflicting declaration invalid conversion from <type> to <type>

9% 5% 18%

11%

Identifier undeclared

@@@ was not declared

62% 33% 31%

42%

Others

‘else’ without a previous ‘if’ no matching function for call to...

20% 14% 16%

17%

[Gupta et al. 17] [Mesbah et al. 19] [Kulal et al. 19]

slide-70
SLIDE 70
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors
  • Design perturbation modules M to cause those errors

70

slide-71
SLIDE 71
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors
  • Design perturbation modules M to cause those errors

71

Perturbation module Example

Syntax (delete/insert/replace operators .;(){}'"+, etc.)

return 0; } → return 0; } }

slide-72
SLIDE 72
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors
  • Design perturbation modules M to cause those errors

72

Perturbation module Example

Syntax (delete/insert/replace operators .;(){}'"+, etc.)

return 0; } → return 0; } }

ID-type (delete/insert/replace type)

string tmp; → char tmp;

slide-73
SLIDE 73
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors
  • Design perturbation modules M to cause those errors

73

Perturbation module Example

Syntax (delete/insert/replace operators .;(){}'"+, etc.)

return 0; } → return 0; } }

ID-type (delete/insert/replace type)

string tmp; → char tmp;

ID-typo (delete/insert/replace IDentifier)

int a, b=0, m; → int a, m;

slide-74
SLIDE 74
  • 2. Self-supervised learning
  • 2. How to design corruption procedure P ?
  • Look at common errors
  • Design perturbation modules M to cause those errors

74

Perturbation module Example

Syntax (delete/insert/replace operators .;(){}'"+, etc.)

return 0; } → return 0; } }

ID-type (delete/insert/replace type)

string tmp; → char tmp;

ID-typo (delete/insert/replace IDentifier)

int a, b=0, m; → int a, m;

Keyword (delete/insert/replace keyword/call)

if (n >= 0) → while (n >= 0)

slide-75
SLIDE 75
  • 2. Self-supervised learning
  • 2. Our corruption procedure P
  • Look at common errors
  • Design perturbation modules M to cause those errors
  • P : Sample 1-5 modules from M, and apply to program sequentially

75

slide-76
SLIDE 76
  • 2. Self-supervised learning
  • 2. Our corruption procedure P
  • Look at common errors
  • Design perturbation modules M to cause those errors
  • P : Sample 1-5 modules from M, and apply to program sequentially

e.g. ID-type , ID-typo , Syntax .

76

slide-77
SLIDE 77
  • 2. Self-supervised learning
  • 2. Our corruption procedure P
  • Look at common errors
  • Design perturbation modules M to cause those errors
  • P : Sample 1-5 modules from M, and apply to program sequentially

e.g. ID-type , ID-typo , Syntax .

77

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[i]; 11 cout << i; }

slide-78
SLIDE 78
  • 2. Self-supervised learning
  • 2. Our corruption procedure P
  • Look at common errors
  • Design perturbation modules M to cause those errors
  • P : Sample 1-5 modules from M, and apply to program sequentially

e.g. ID-type , ID-typo , Syntax .

78

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[i]; 11 cout << i; }

Perturbed 1

5 int i, n; 6 char A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[i]; 11 cout << i; }

slide-79
SLIDE 79
  • 2. Self-supervised learning
  • 2. Our corruption procedure P
  • Look at common errors
  • Design perturbation modules M to cause those errors
  • P : Sample 1-5 modules from M, and apply to program sequentially

e.g. ID-type , ID-typo , Syntax .

79

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[i]; 11 cout << i; }

Perturbed 1

5 int i, n; 6 char A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[i]; 11 cout << i; }

Perturbed 2

5 int i, n; 6 char A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[j]; 11 cout << i; }

slide-80
SLIDE 80
  • 2. Self-supervised learning
  • 2. Our corruption procedure P
  • Look at common errors
  • Design perturbation modules M to cause those errors
  • P : Sample 1-5 modules from M, and apply to program sequentially

e.g. ID-type , ID-typo , Syntax .

80

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[i]; 11 cout << i; }

Perturbed 1

5 int i, n; 6 char A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[i]; 11 cout << i; }

Perturbed 2

5 int i, n; 6 char A; 7 cin >> n; 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[j]; 11 cout << i; }

Perturbed 3

5 int i, n; 6 char A; 7 cin >> n . 8 A.resize(n); 9 for (i = 0; i < n; i++){ 10 cin >> A[j]; 11 cout << i; }

slide-81
SLIDE 81
  • 2. Self-supervised learning
  • 3. Prepare pre-training data
  • 300K working programs from codeforces.com

81

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[i]; 11 cout << i; }

slide-82
SLIDE 82
  • 2. Self-supervised learning
  • 3. Prepare pre-training data
  • 300K working programs from codeforces.com
  • For each program, create corrupted versions by applying P

82

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[i]; 11 cout << i; }

Corrupted

5 int i, n; 6 char A; 7 cin >> n . 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[j]; 11 cout << i; }

P

slide-83
SLIDE 83
  • 2. Self-supervised learning
  • 3. Prepare pre-training data
  • 300K working programs from codeforces.com
  • For each program, create corrupted versions by applying P

83

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[i]; 11 cout << i; }

Corrupted

5 int i, n; 6 char A; 7 cin >> n . 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[j]; 11 cout << i; }

Error!

line 7: expected ‘;’

compiler

P

slide-84
SLIDE 84
  • 2. Self-supervised learning
  • 3. Prepare pre-training data
  • 300K working programs from codeforces.com
  • For each program, create corrupted versions by applying P

⇒ New program repair examples: <broken code, feedback, fixed code>

84

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[i]; 11 cout << i; }

Corrupted

5 int i, n; 6 char A; 7 cin >> n . 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[j]; 11 cout << i; }

Error!

line 7: expected ‘;’

compiler

P

slide-85
SLIDE 85
  • 2. Self-supervised learning
  • 3. Prepare pre-training data
  • 300K working programs from codeforces.com
  • For each program, create corrupted versions by applying P

⇒ New program repair examples: <broken code, feedback, fixed code>

85

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[i]; 11 cout << i; }

Corrupted

5 int i, n; 6 char A; 7 cin >> n . 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[j]; 11 cout << i; }

Error!

line 7: expected ‘;’

compiler

P

slide-86
SLIDE 86
  • 2. Self-supervised learning
  • 3. Prepare pre-training data
  • 300K working programs from codeforces.com
  • For each program, create corrupted versions by applying P

⇒ New program repair examples: <broken code, feedback, fixed code>

86

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[i]; 11 cout << i; }

Corrupted

5 int i, n; 6 char A; 7 cin >> n . 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[j]; 11 cout << i; }

Error!

line 7: expected ‘;’

compiler

P

slide-87
SLIDE 87
  • 2. Self-supervised learning
  • 3. Prepare pre-training data
  • 300K working programs from codeforces.com
  • For each program, create corrupted versions by applying P

⇒ New program repair examples: <broken code, feedback, fixed code>

87

Working code

5 int i, n; 6 string A; 7 cin >> n; 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[i]; 11 cout << i; }

Corrupted

5 int i, n; 6 char A; 7 cin >> n . 8 A.resize(n); 9 for (i=0;i<n;i++){ 10 cin >> A[j]; 11 cout << i; }

Error!

line 7: expected ‘;’

compiler

P

slide-88
SLIDE 88
  • 2. Self-supervised learning

What’s interesting?

  • Typically, pre-training task ≠ target task (e.g. masked LM v.s. QA)
  • Here, targeted pre-training (pre-training task = target task = program repair)

○ More direct pre-training structure ○ Data distributions can be different between pre-training & target

88

slide-89
SLIDE 89

Evaluation 1: DeepFix

89

slide-90
SLIDE 90

Evaluation 1: DeepFix

Task

  • Repair C programs
  • May have multiple error lines
  • Apply repair model iteratively (up to 5 times)

90

[Gupta et al., 17]

slide-91
SLIDE 91

Evaluation 1: DeepFix

Our model outputs

Input code

4 int main() { 5 int n; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

91

slide-92
SLIDE 92

Evaluation 1: DeepFix

Our model outputs

Input code

4 int main() { 5 int n; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

Error message

line 9: ‘i’ undeclared

92

slide-93
SLIDE 93

Evaluation 1: DeepFix

Our model outputs

Input code

4 int main() { 5 int n; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

Error message

line 9: ‘i’ undeclared

Attempt 1

4 int main() { 5 int n, i; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

93

DrRepair

slide-94
SLIDE 94

Evaluation 1: DeepFix

Our model outputs

Input code

4 int main() { 5 int n; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

Error message

line 9: ‘i’ undeclared

Attempt 1

4 int main() { 5 int n, i; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

Error message

line 12: expected ‘;’ before ‘}’

94

DrRepair

slide-95
SLIDE 95

Evaluation 1: DeepFix

Our model outputs

Input code

4 int main() { 5 int n; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

Error message

line 9: ‘i’ undeclared

Attempt 1

4 int main() { 5 int n, i; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

Error message

line 12: expected ‘;’ before ‘}’

Attempt 2

4 int main() { 5 int n; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 ; }

95

DrRepair DrRepair

slide-96
SLIDE 96

Evaluation 1: DeepFix

Our model outputs

Input code

4 int main() { 5 int n; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

Error message

line 9: ‘i’ undeclared

Attempt 1

4 int main() { 5 int n, i; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 }

Error message

line 12: expected ‘;’ before ‘}’

Attempt 2

4 int main() { 5 int n; 6 int * m[2]; 7 m[0] = malloc(n*sizeof(int)); 8 m[1] = malloc(n*sizeof(int)); 9 for (i = 0; i < n; i++) { 10 m[0][i] = -1; 11 m[1][i] = -1; } 12 return 0 ; }

Compiled!!

96

DrRepair DrRepair

slide-97
SLIDE 97

Evaluation 1: DeepFix

Results

97

Test (full repair accuracy)

Prior works do not use compiler messages

slide-98
SLIDE 98

Evaluation 1: DeepFix

Results

98

Test (full repair accuracy)

Prior works do not use compiler messages

slide-99
SLIDE 99

Evaluation 1: DeepFix

Results

99

Test (full repair accuracy)

Prior works do not use compiler messages Use of compiler messages is important

slide-100
SLIDE 100

Evaluation 1: DeepFix

Results

100

Test (full repair accuracy)

Prior works do not use compiler messages Use of compiler messages is important

slide-101
SLIDE 101

Evaluation 1: DeepFix

Results

101

Test (full repair accuracy)

Prior works do not use compiler messages Use of compiler messages is important Graph & pre-train are both useful

slide-102
SLIDE 102

Evaluation 2: SPoC

102

slide-103
SLIDE 103

Evaluation 2: SPoC

Task

  • Translate pseudocode into C++ code (program synthesis)
  • Line-level alignment

103

[Kulal et al., 19]

slide-104
SLIDE 104

Evaluation 2: SPoC

Prior work (Kulal+19)

  • Stitch line-level translations & search

104

Pseudocode

declare i for i from 0 to n print i

Code candidates

slide-105
SLIDE 105

Evaluation 2: SPoC

Prior work (Kulal+19)

  • Stitch line-level translations & search

105

Pseudocode

declare i for i from 0 to n print i

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

translate

slide-106
SLIDE 106

Evaluation 2: SPoC

Prior work (Kulal+19)

  • Stitch line-level translations & search

106

Pseudocode

declare i for i from 0 to n print i

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

translate

slide-107
SLIDE 107

Evaluation 2: SPoC

Prior work (Kulal+19)

  • Stitch line-level translations & search

107

Pseudocode

declare i for i from 0 to n print i

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

cout << i << "\n"; cout << i; putc(i);

[p=0.4] [p=0.3] [p=0.1]

translate

slide-108
SLIDE 108

Evaluation 2: SPoC

Prior work (Kulal+19)

  • Stitch line-level translations & search

108

Pseudocode

declare i for i from 0 to n print i

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

cout << i << "\n"; cout << i; putc(i);

[p=0.4] [p=0.3] [p=0.1]

translate

slide-109
SLIDE 109

Evaluation 2: SPoC

Prior work (Kulal+19)

  • Stitch line-level translations & search

109

Pseudocode

declare i for i from 0 to n print i

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

cout << i << "\n"; cout << i; putc(i);

[p=0.4] [p=0.3] [p=0.1]

translate Best first search

slide-110
SLIDE 110

Evaluation 2: SPoC

Prior work (Kulal+19)

  • Stitch line-level translations & search

110

Pseudocode

declare i for i from 0 to n print i

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

cout << i << "\n"; cout << i; putc(i);

[p=0.4] [p=0.3] [p=0.1]

translate Best first search

slide-111
SLIDE 111

Evaluation 2: SPoC

Prior work (Kulal+19)

  • Stitch line-level translations & search

111

Pseudocode

declare i for i from 0 to n print i

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

cout << i << "\n"; cout << i; putc(i);

[p=0.4] [p=0.3] [p=0.1]

translate Best first search ...

slide-112
SLIDE 112

Evaluation 2: SPoC

Problem

  • Line-level translation misses global context

112

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

cout << i << "\n"; cout << i; putc(i);

[p=0.4] [p=0.3] [p=0.1]

slide-113
SLIDE 113

Evaluation 2: SPoC

Problem

  • Line-level translation misses global context

113

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

cout << i << "\n"; cout << i; putc(i);

[p=0.4] [p=0.3] [p=0.1]

Does not compile!

(redeclaration of ‘i’)

slide-114
SLIDE 114

Evaluation 2: SPoC

Problem

  • Line-level translation misses global context

Our solution

  • Apply repair model if current candidate program does not compile

114

Code candidates

int i; char i; i=0;

[p=0.7] [p=0.2] [p=0.1]

for(int i=0;i<n;i++) for(i=0;i<n;i++) while (1)

[p=0.3] [p=0.2] [p=0.1]

cout << i << "\n"; cout << i; putc(i);

[p=0.4] [p=0.3] [p=0.1]

Does not compile!

(redeclaration of ‘i’)

slide-115
SLIDE 115

Evaluation 2: SPoC

Results

115

TestP (synthesis success rate)

BFS + error localization

slide-116
SLIDE 116

Evaluation 2: SPoC

Results

116

TestP (synthesis success rate)

BFS + error localization BFS + repair

slide-117
SLIDE 117

Evaluation 2: SPoC

Results

117

TestP (synthesis success rate) Dev (repair accuracy) - ablation

BFS + error localization BFS + repair

slide-118
SLIDE 118

Evaluation 2: SPoC

Results

118

TestP (synthesis success rate) Dev (repair accuracy) - ablation

BFS + error localization BFS + repair

slide-119
SLIDE 119

Evaluation 2: SPoC

Results

119

TestP (synthesis success rate) Dev (repair accuracy) - ablation

BFS + error localization BFS + repair

slide-120
SLIDE 120

Evaluation 2: SPoC

Results

120

TestP (synthesis success rate) Dev (repair accuracy) - ablation

BFS + error localization BFS + repair

slide-121
SLIDE 121

Evaluation 2: SPoC

Results

121

TestP (synthesis success rate) Dev (repair accuracy) - ablation

BFS + error localization BFS + repair

slide-122
SLIDE 122

Analysis 1: When is graph useful?

122

Compiler message type Frequency in train set

(SPoC)

Repair acc. (SPoC dev) base + graph + graph + pretrain

‘@@@’ was not declared … 35.2 % 50.2 58.9 65.0 redeclaration of ‘@@@’ 8.9 % 40.7 43.0 49.1 expected ‘@@@’ before ‘@@@’ 3.2 % 67.6 70.7 86.1 expected primary-expression before … 3.0 % 47.4 47.4 49.1 request for member ‘@@@’ in ‘@@@’, … 2.9 % 37.9 56.9 48.4 expected initializer before ‘@@@’ 2.1 % 48.8 50.1 93.0 ‘@@@’ without a previous ‘@@@’ 1.3 % 37.0 38.7 44.4

slide-123
SLIDE 123

Analysis 1: When is graph useful?

123

Compiler message type Frequency in train set

(SPoC)

Repair acc. (SPoC dev) base + graph + graph + pretrain

‘@@@’ was not declared … 35.2 % 50.2 58.9 65.0 redeclaration of ‘@@@’ 8.9 % 40.7 43.0 49.1 expected ‘@@@’ before ‘@@@’ 3.2 % 67.6 70.7 86.1 expected primary-expression before … 3.0 % 47.4 47.4 49.1 request for member ‘@@@’ in ‘@@@’, … 2.9 % 37.9 56.9 48.4 expected initializer before ‘@@@’ 2.1 % 48.8 50.1 93.0 ‘@@@’ without a previous ‘@@@’ 1.3 % 37.0 38.7 44.4

slide-124
SLIDE 124

Analysis 1: When is graph useful?

124

Need reasoning

  • ver multiple

lines of code

Compiler message type Frequency in train set

(SPoC)

Repair acc. (SPoC dev) base + graph + graph + pretrain

‘@@@’ was not declared … 35.2 % 50.2 58.9 65.0 redeclaration of ‘@@@’ 8.9 % 40.7 43.0 49.1 expected ‘@@@’ before ‘@@@’ 3.2 % 67.6 70.7 86.1 expected primary-expression before … 3.0 % 47.4 47.4 49.1 request for member ‘@@@’ in ‘@@@’, … 2.9 % 37.9 56.9 48.4 expected initializer before ‘@@@’ 2.1 % 48.8 50.1 93.0 ‘@@@’ without a previous ‘@@@’ 1.3 % 37.0 38.7 44.4

slide-125
SLIDE 125

Recall this example

1 #include <bits/stdc++.h> 2 #include <string> 3 using namespace std; 4 int main() { 5 char tmp, a , b; 6 map<string,int> mp; 7 cin >> a >> b; 8 int i, j; 9 for (i = 0; i < a .size(); i++){ 10 tmp.push_back( a [i]); 11 string tmp1 = tmp; 12 for (j = 0; j < b.size(); j++){ 13 tmp1.push_back(b[j]); 14 mp[tmp1] = 1; 15 } 16 } ...

125

Broken program

line 9:error: request for member ‘size’ in ‘a’, which is of non-class type ‘char’

Feedback

  • 1. Error localized line 5
  • 2. Repair

char tmp, a, b; → string tmp, a, b;

Repair

Multi-hop!

slide-126
SLIDE 126

Analysis 1: When is graph useful?

126

Need reasoning

  • ver multiple

lines of code Graph captures long-range connections of tokens

Compiler message type Frequency in train set

(SPoC)

Repair acc. (SPoC dev) base + graph + graph + pretrain

‘@@@’ was not declared … 35.2 % 50.2 58.9 65.0 redeclaration of ‘@@@’ 8.9 % 40.7 43.0 49.1 expected ‘@@@’ before ‘@@@’ 3.2 % 67.6 70.7 86.1 expected primary-expression before … 3.0 % 47.4 47.4 49.1 request for member ‘@@@’ in ‘@@@’, … 2.9 % 37.9 56.9 48.4 expected initializer before ‘@@@’ 2.1 % 48.8 50.1 93.0 ‘@@@’ without a previous ‘@@@’ 1.3 % 37.0 38.7 44.4

slide-127
SLIDE 127

Analysis 2: When is pre-training useful?

127

Compiler message type Frequency in train set

(SPoC)

Repair acc. (SPoC dev) base + graph + graph + pretrain

‘@@@’ was not declared … 35.2 % 50.2 58.9 65.0 redeclaration of ‘@@@’ 8.9 % 40.7 43.0 49.1 expected ‘@@@’ before ‘@@@’ 3.2 % 67.6 70.7 86.1 expected primary-expression before … 3.0 % 47.4 47.4 49.1 request for member ‘@@@’ in ‘@@@’, … 2.9 % 37.9 56.9 48.4 expected initializer before ‘@@@’ 2.1 % 48.8 50.1 93.0 ‘@@@’ without a previous ‘@@@’ 1.3 % 37.0 38.7 44.4

slide-128
SLIDE 128

Analysis 2: When is pre-training useful?

128

Compiler message type Frequency in train set

(SPoC)

Repair acc. (SPoC dev) base + graph + graph + pretrain

‘@@@’ was not declared … 35.2 % 50.2 58.9 65.0 redeclaration of ‘@@@’ 8.9 % 40.7 43.0 49.1 expected ‘@@@’ before ‘@@@’ 3.2 % 67.6 70.7 86.1 expected primary-expression before … 3.0 % 47.4 47.4 49.1 request for member ‘@@@’ in ‘@@@’, … 2.9 % 37.9 56.9 48.4 expected initializer before ‘@@@’ 2.1 % 48.8 50.1 93.0 ‘@@@’ without a previous ‘@@@’ 1.3 % 37.0 38.7 44.4

Rare in train set Extra examples in pre-training are helpful

slide-129
SLIDE 129

Takeaways

New insights

  • Use of error messages is crucial to learn program repair
  • Program-feedback graph helps complex reasoning
  • Unlabeled programs can be used for targeted pre-training

General framework

  • Learning to reason with feedback - many applications, e.g.

○ Edit essays based on written feedback ○ Learn from user inputs in interactive dialogue

  • We show that graph-based reasoning can be a good solution

129

slide-130
SLIDE 130

Thanks!

Michihiro Yasunaga Percy Liang Thanks!

130

Thank you to John Hewitt, Mina Lee, Sumith Kulal, Pang Wei Koh, Robin Jia, Ananya Kumar, Ruiqi Zhong, and anonymous reviewers. Funded in part by NSF CAREER Award, PECASE Award, and Amazon Research Award.

Code/Data: https://cs.stanford.edu/~myasu/