to type or not to type quantifying detectable bugs in
play

To Type or Not to Type: Quantifying Detectable Bugs in JavaScript - PowerPoint PPT Presentation

To Type or Not to Type: Quantifying Detectable Bugs in JavaScript Zheng Gao , Christian Bird , Earl Barr University College London, Microsoft Research Static Typing vs. Dynamic Typing Static Typing vs. Dynamic Typing


  1. To Type or Not to Type: Quantifying Detectable Bugs in JavaScript Zheng Gao ✢ , Christian Bird ✵ , Earl Barr ✢ ✢ University College London, ✵ Microsoft Research

  2. Static Typing vs. Dynamic Typing

  3. Static Typing vs. Dynamic Typing ��3����3���� ��������3��� ��,91������ �1�����1���� ��5�������3���� ���9��3�����3� ���1����������3� ���1����������3� ����5��������3�

  4. Static Typing vs. Dynamic Typing ���1����������3�

  5. Engine of the Web is dynamically typed; { has a large set of long-running projects.

  6. Engine of the Web is dynamically typed; { has a large set of long-running projects. ������ ����������5����5����3�����9�

  7. Static Typing for JavaScript

  8. Static Typing for JavaScript

  9. � � � � � � � � � � � � � � � � � � � � � � � � Had Static Typing been Used … …

  10. � � � � � � � � � � � � � � � � � � � � � � � � Had Static Typing been Used … � � � …

  11. � � � � � � � � � � � � � � � � � � � � � � � � Had Static Typing been Used … � � � …

  12. � � � � � � � � � � � � � � � � � � � � � � � � Had Static Typing been Used … � � …

  13. Central Finding

  14. Central Finding 15%

  15. Central Finding 15%

  16. Bug Life Cycle

  17. Bug Life Cycle edit-time bugs

  18. Bug Life Cycle saved edit-time bugs bugs

  19. Bug Life Cycle team saved edit-time bugs bugs bugs

  20. Bug Life Cycle field team saved edit-time bugs bugs bugs bugs

  21. Bug Life Cycle field team bugs bugs

  22. Bug Life Cycle field team public bugs bugs bugs

  23. Type System Detectable Definition ( ts- detectable): Given a static type system ts , a bug is ts -detectable when 1. adding or changing type annotations causes the program containing the bug to fail to type check on a line a fix changes.

  24. Problem When the type of b is nullable number , annotating var a = b + 1; to var a:boolean = b + 1; “trivially” triggers a type error.

  25. Consistency Definition (Consistency): The added or changed type annotations are consistent with a fixed version of the program containing the bug f , if they carried to f type check, and the type of every annotated term is a supertype of that term’s type when an oracle precisely annotates it in f .

  26. Type System Detectable Definition ( ts- detectable): Given a static type system ts , a bug is ts -detectable when 1. adding or changing type annotations causes the program containing the bug to fail to type check on a line a fix changes; 2. the new annotations are consistent with a fixed version of the program containing the bug.

  27. Example of Detection Error-free in JavaScript, TypeScript throws the and unexpectedly displays following error: an string, 30

  28. Research Question What percentage of public bugs are detectable under Flow or TypeScript?

  29. Experiment Overview patch

  30. Corpus Collection patch

  31. Corpus Collection ‣ What is the sample size? ‣ How to identify public bugs? patch

  32. Corpus Collection ‣ What is the sample size? ‣ How to identify public bugs?

  33. Sample Size Calculation 3,910,969 closed bug 384 bugs reports s: sample size X 2 : a constant for the confidence level of 95% N: population size, 3910969 P: population proportion, 0.5 d: degree of accuracy, 0.05

  34. Corpus Collection ‣ What is the sample size? ‣ How to identify public bugs?

  35. Bug Identification Bug Identification

  36. Bug Identification Bug Fix Identification Identification

  37. Bug Identification Parents are buggy Bug Fix Identification Identification

  38. Fix Identification

  39. Fix Identification These candidates may include commits that add features or refactor.

  40. Subjects general bugs public bugs ts-detectable bugs

  41. Subjects general bugs public bugs ts-detectable bugs

  42. Subjects general bugs public bugs fixed ts-detectable public bugs bugs

  43. Subjects general bugs public bugs fixed ts-detectable public bugs bugs

  44. Size Statistics of the Corpus The sizes are in lines of code.

  45. � � � � � ��� � � � � Methodology Project Version History Researcher

  46. � � � � � ��� � � � � Methodology buggy fixed version version Project Version History Researcher

  47. � � � � � ��� � � � � Methodology buggy fixed version version Project Version History travel back in time

  48. � � � � � ��� � � � � Methodology Project Version History Check out p i-1

  49. � � � � � ��� � � � � Methodology Project Version History Gradually annotate p i-1

  50. � � � � ��� ��� � � � � � Methodology a is the annotation function Project Version History Type check a(p i-1 )

  51. Annotation patch

  52. Annotation Y gradually possibly N type check detected? add detectable? annotation N Y patch explain justify annotations undetectable

  53. Annotation Y gradually possibly N type check detected? add detectable? annotation We do not fully annotate N Y the program; we rely on patch gradual typing to locally, explain justify minimally annotate the annotations undetectable patched region.

  54. Annotation Sources project bug fixes bug reports documentation

  55. Expert Source

  56. Problem var t = {x:0, z:1}; t.x = t.y; // the error is y does not exist on t t.x = t.z;

  57. Problem What is the type of variable t? var t = {x:0, z:1}; t.x = t.y; // the error is y does not exist on t t.x = t.z;

  58. Problem What is the type of variable t? Seems to be {x: number, z: number}? var t = {x:0, z:1}; t.x = t.y; // the error is y does not exist on t t.x = t.z;

  59. Problem What is the type of variable t? Seems to be {x: number, z: number}? var t = {x:0, z:1}; t.x = t.y; // the error is y does not exist on t t.x = t.z; Not necessarily!

  60. Problem What is the type of variable t? Seems to be {x: number, z: number}? var t = {x:0, z:1}; t.x = t.y; // the error is y does not exist on t t.x = t.z; … Not necessarily! … … t.x = “a”;

  61. Problem What is the type of variable t? Seems to be {x: number, z: number}? var t = {x:0, z:1}; t.x = t.y; // the error is y does not exist on t t.x = t.z; … Not necessarily! … … t.x = “a”; Now becomes {x: number | string, z: number}.

  62. Type Shims A set of type bindings for the free identifiers that 1). is consistent with but 2). may not exist in a fixed version of the program containing the bug.

  63. Shim Example var t = {x:0, z:1}; t.x = t.y; // y does not exist on t t.x = t.z; annotate This shim is interface T { consistent, as T x:any; must be the z:any; supertype. } var t:T = {x:0, z:1}; t.x = t.y; t.x = t.z;

  64. � � � � � ��� ��� � � � � Annotation Quality we add the same annotations to p i Project Version History Type check a(p i ) 84% of the annotated fixed versions type check.

  65. Results Both Flow and TypeScript detect 15% of the collected bugs; the confidence range is [11.5%,18.5%] , at a 95% confidence level.

  66. Implications “That’s shocking. If you could make a change to the way we do development that would reduce the number of bugs being checked in by 10% or more overnight, that’s a no-brainer. Unless it doubles development time or something, we’d do it.” - An engineering manager at Microsoft

  67. Experimental Artefacts http://ttendency.cs.ucl.ac.uk/projects/type_study/index.html

  68. http://ttendency.cs.ucl.ac.uk/projects/type_study/index.html

Recommend


More recommend