Cascade: A Universal Programmer-assisted Type Qualifier Inference Tool Mohsen Vakilian* Amarin Phaosawasdi* Michael D. Ernst † Ralph E. Johnson* *University of Illinois at Urbana-Champaign 1 † University of Washington
Type qualifiers allow additional static type checks static int oldSubindex( @Nullable MathVector ic , int l) { int i = 0; for (int k = 0; k < MathVector.NDIM; k++) { if (((int) ic .value(k) & l) != 0) i += Cell.NSUB >> (k + 1); } return i; } 2
Java 8 supports custom type systems* ◼ Locking ◼ Aliasing ◼ Interning ◼ Immutability ◼ Tainting *checkerframework.org 3
Java 8 supports custom type systems* ◼ Locking + additional static checks ◼ Aliasing ◼ Interning ◼ Immutability ◼ Tainting *checkerframework.org 4
Java 8 supports custom type systems* ◼ Locking + additional static checks ◼ Aliasing ◼ Interning - additional code annotation ◼ Immutability ◼ Tainting *checkerframework.org 5
The manual annotation process is tedious Run type checker 6
The manual annotation process is tedious Run type checker Add or remove qualifiers 7
The manual annotation process is tedious Refactor code Run type checker Add or remove qualifiers 8
Type qualifier inference tools run in batch mode Annotated Program program Infer 9
Type qualifier inference tools run in batch mode Nullness Julia, Nit, JastAddJ Nullness, SALSA Nullness, Xylem, Annotated Daikon Nullness Program program Infer Immutability Javarifier, Pidasai, ReImInfer Ownership Universe and Ownership Type Inference System 10
Type qualifier inference tools run in batch mode Strengths Annotated ◼ Optimal under certain Program program Infer conditions ◼ Large change without user involvement 11
Type qualifier inference tools run in batch mode Weaknesses Annotated ◼ Limited to one set of Program program qualifiers Infer ◼ Unpredictable ◼ Rigid ◼ Inaccurate 12
Type qualifier inference tools run in batch mode Refactor code Annotated Program program Infer Run type checker Add or remove qualifiers 13
Type qualifier inference tools run in batch mode Refactor code Annotated Program program Infer Run type checker Automate! Add or remove qualifiers 14
Type qualifier inference tools run in batch mode Human insight Refactor code needed Annotated Program program Infer Run type checker Add or remove qualifiers 15
Batch-mode tools make arbitrary decisions 16
17
BUG 18
Batch-mode tools make arbitrary decisions BUG 19
Type qualifier inference is a refactoring ◼ Adding type qualifiers preserves the program behavior ◼ Adding maintainable type qualifiers that match the programmer's intention requires code refactoring 20
Cascade: A Universal Programmer-assisted Type Qualifier Inference Tool Type Checker Type Inference Cascade 21
Cascade: A Universal Programmer-assisted Type Qualifier Inference Tool Compositional Refactoring Cascade Speculative Analysis 22
Inferring Primitive Changes from Error Messages Type Checker Error Fix incompatible types in argument. root = root.loadTree(q, xqic); Nullness ^ found : @Nullable MathVector required: @NonNull MathVector 23
Inferring Primitive Changes from Error Messages Type Checker Error Fix incompatible types in argument. Change parameter xpic root = root.loadTree(q, xqic); Nullness of loadTree() to ^ @Nullable MathVector found : @Nullable MathVector required: @NonNull MathVector 24
Inferring Primitive Changes from Error Messages Type Checker Error Fix incompatible types in argument. Change parameter xpic root = root.loadTree(q, xqic); Nullness of loadTree() to ^ @Nullable MathVector found : @Nullable MathVector required: @NonNull MathVector call to value(int) not allowed on the given receiver. Mutability ic.value(k); ^ found : @ReadOnly MathVector required: @Mutable MathVector 25
Inferring Primitive Changes from Error Messages Type Checker Error Fix incompatible types in argument. Change parameter xpic root = root.loadTree(q, xqic); Nullness of loadTree() to ^ @Nullable MathVector found : @Nullable MathVector required: @NonNull MathVector call to value(int) not allowed on the given receiver. Change receiver parameter Mutability ic.value(k); of value() to ^ @ReadOnly MathVector found : @ReadOnly MathVector required: @Mutable MathVector 26
Speculative analysis suggests a change composition 27
Speculative analysis suggests a change composition 28
Speculative analysis suggests a change composition 29
Speculative analysis suggests a change composition 30
Cascade Tree 31
Cascade Tree 32
Cascade Tree 33
34
35
36
The speculative analysis computes a tree recursively Program p e 1 Error 37
The speculative analysis computes a tree recursively Program Fix p c 1 e 1 Error 38
The speculative analysis computes a tree recursively Program Fix p c 1 (p) e 2 c 1 e 1 e 3 Error 39
The speculative analysis computes a tree recursively Program Fix c 2 p c 1 (p) e 2 c 1 e 1 e 3 c 3 Error 40
The speculative analysis computes a tree recursively Program c 2 (c 1 (p)) Fix c 2 p c 1 (p) e 3 e 2 c 1 e 1 e 3 c 3 (c 1 (p)) c 3 e 4 Error 41
A change is represented as an AST path Primitive Change Representation Compilation Unit + Variable Variable Decl. Fixer Decl. + New Type Compilation Unit + Method Method Return Fixer Decl. + New Type Method Receiver Compilation Unit + Method Fixer Decl. + New Type 42
Research Questions How does Cascade compare with Julia , a batch qualifier inference tool? ◼ Learnability ◼ Quality of results ◼ Task completion time ◼ Control over process ◼ Willingness to use 43
User study Subjects: ◼ 12 computer science graduate students from 9 different research labs ◼ Familiar with Java and Eclipse ◼ Average of 10 years of programming experience 44
Training ◼ Nullness Checker ◼ Julia ◼ Cascade github.com/reprogrammer/tqi-study 45
Task Design Julia then Cascade Cascade then Julia MST then BH 3 participants 3 participants BH then MST 3 participants 3 participants BH Barnes-Hut, a hierarchical force-calculation algorithm MST Bentley’s algorithm for finding the minimum spanning tree of a graph 46
Users complete tasks faster with Cascade t test ◼ p = 0.01 ◼ Cohen’s d = 1.13 47
Users added less inaccurate annotations with Cascade BH + MST Julia Cascade Correct 13.9 9.6 Incorrect 2.8 0.1 Redundant 1.7 0.4 Unnecessary warning 7.2 0 suppressions 48
Postquestionnaire Results Questions Cascad Equal Julia (T = Julia or Cascade) e Rating better better I found T easy to learn . 3 6 3 I know why T inserted 8 4 0 each annotation. Using T, I have control over the process of 9 0 3 annotating the code. I'm willing to use T in the 11 0 1 49 future.
Qualitative Interview Results The participants believe that: ◼ Cascade's speculative analysis is useful (N = 8). ◼ Cascade is more predictable (N = 7). ◼ Cascade's tree computation is slow (N = 5). ◼ The overhead of fixing Julia's annotations is high (N = 7). 50
Future Work ◼ Improve the performance of Cascade. ◼ Evaluate compositional refactoring and Cascade in the field . ◼ Make Cascade support bidirectional speculative analysis. 51
Cascade: A Universal Type Qualifier Inference Tool ◼ Cascade is easy to use and helps users complete tasks fast . ◼ Compositional refactoring and speculative analysis . ◼ Less is sometimes more in the automation of software evolution tasks. ◼ More automation is not always better ◼ Some tasks need problem-solving and creativity ◼ Applicable to other fields 52
Recommend
More recommend