identifying change patterns in software history
play

Identifying change patterns in software history Jason Dagit | - PowerPoint PPT Presentation

Identifying change patterns in software history Jason Dagit | Galois, Inc Motivation Tools to detect changes exist. For example, traditional line-based diff: Pro: diff is very general and programming language agnostic Con: diff is not


  1. Identifying change patterns in software history Jason Dagit | Galois, Inc

  2. Motivation Tools to detect changes exist. For example, traditional line-based diff: • Pro: diff is very general and programming language agnostic • Con: diff is not structurally aware: if( foo ){ if( foo ) bar; { } bar; } We need tools for interpreting changes. � 2013 Galois, Inc. All Right Reserved. c

  3. Motivation Common looping pattern with loop counter initialized to zero: for ( � = 0; � < � ; � ) { � } We also want to see how source code changes . � 2013 Galois, Inc. All Right Reserved. c

  4. Example from Clojure: Related edits Our tool found these related edits: PersistentArrayMap.java public Object kvreduce (IFn f, Object init ){ for(int i=0;i < array . length ;i +=2){ init = f. invoke (init , array [i], array [i +1]); - if(RT. isReduced ( init )) - return (( IDeref ) init ). deref (); } return init ; } PersistentHashMap.java public Object kvreduce (IFn f, Object init ){ - for( INode node : array ){ - if( node != null ){ + for( INode node : array ) + { + if( node != null ) init = node . kvreduce (f, init ); - if(RT. isReduced ( init )) - return (( IDeref ) init ). deref (); - } - } + } return init ; } � 2013 Galois, Inc. All Right Reserved. c

  5. Approach Key Idea: We can find structural patterns by generalizing sufficiently similar difference trees. • Difference trees computed using structural diff of AST • Similarity is measured using a tree edit distance score • Generalization is accomplished through antiunification � 2013 Galois, Inc. All Right Reserved. c

  6. Workflow source code version history a.c b.c compare sequential a.c a.c versions of each file v1 v2 treediff forest of diff subtrees tree similarity group by similarity antiunify antiunify antiunify to obtain P1 P2 patterns � 2013 Galois, Inc. All Right Reserved. c

  7. ATerms i++; AAppl "ExpStmt" [AAppl "PostIncrement" [AAppl "ExpName" [AAppl "Name" [AList [AAppl "Ident" [AAppl "\"i\"" []]]]]]] Generic tree structure—programming language agnostic. Easy to modify parsers to generate ATerms. � 2013 Galois, Inc. All Right Reserved. c

  8. Structural diff   A A A     = treediff   , B C B F     B mismatch(C,F)   D lefthole(D) Keep just the differences with a bit of context: A B t a = t b = mismatch(C,F) lefthole(D) Output also gives us an edit distance. � 2013 Galois, Inc. All Right Reserved. c

  9. Workflow source code version history a.c b.c compare sequential a.c a.c versions of each file v1 v2 treediff forest of diff subtrees tree similarity group by similarity antiunify antiunify antiunify to obtain P1 P2 patterns � 2013 Galois, Inc. All Right Reserved. c

  10. Similarity grouping We define the similarity score by: ∆( t a , t b ) := min ( d ( t a , t b ) , d ( t b , t a )) max ( | t a | , | t b | ) where d is the tree edit distance score. Similarity matrix D given by D ij = ∆( t i , t j ). Given threshold τ ∈ [0 , 1] we say t i and t j are similar if D ij ≥ τ . Group trees such that all elements in the group are within τ . � 2013 Galois, Inc. All Right Reserved. c

  11. ANTLR similarity groups with τ = 0 . 01 10 similarity groups from ANTLR source, when τ = 0 . 01: 7 are patterns: � ; if( � ) � ; if( � ) { � } � ; return � ; for( � � : � ) � ; for( � = � ; � < � ; � ) � ; throw RuntimeException ( � + � ); � 2013 Galois, Inc. All Right Reserved. c

  12. ANTLR similarity groups with τ = 0 . 01 3 are constants (no � s): try { walker . grammarSpec (); } catch ( RecognitionException re ){ ErrorManager . internalError ("bad grammar AST structure ",re ); } while (sp != StackLimitedNFAToDFAConverter . NFA_EMPTY_STACK_CONTEXT ) { n++; sp = sp. parent ; } switch ( gtype ) { case ANTLRParser . LEXER_GRAMMAR : return legalLexerOptions . contains (key ); case ANTLRParser . PARSER_GRAMMAR : return legalParserOptions . contains (key ); case ANTLRParser . TREE_GRAMMAR : return legalTreeParserOptions . contains (key ); default : return legalParserOptions . contains (key ); } � 2013 Galois, Inc. All Right Reserved. c

  13. Workflow source code version history a.c b.c compare sequential a.c a.c versions of each file v1 v2 treediff forest of diff subtrees tree similarity group by similarity antiunify antiunify antiunify to obtain P1 P2 patterns � 2013 Galois, Inc. All Right Reserved. c

  14. Antiunification   A A     A   = au , subst l , subst r   ,   B C B F   � 1 � 2     D where, subst l = { � 1 �→ B , � 2 �→ C } subst r = { � 1 �→ B , � 2 �→ F } D � 2013 Galois, Inc. All Right Reserved. c

  15. Similarity groups versus threshold What happens to similarity groups when we vary the threshold? 30 ¡ 25 ¡ Number ¡of ¡groups ¡ 20 ¡ addi.ons ¡ 15 ¡ dele.ons ¡ 10 ¡ modifica.ons ¡ 5 ¡ 0 ¡ 0 ¡ 0.2 ¡ 0.4 ¡ 0.6 ¡ 0.8 ¡ 1 ¡ Threshold ¡ Number of additions, deletions, and modifications by threshold for the Clojure source. � 2013 Galois, Inc. All Right Reserved. c

  16. Patterns as a function of threshold Generic Loop pattern, τ = 0 . 15: for ( � = � ; � < � ; � ) { � } Loop counter is initialized to zero, τ = 0 . 25: for ( � = 0; � < � ; � ) { � } Loop termination criteria becomes more specific, τ = 0 . 35: for ( � = 0; � < � . � ; � ) { � } � 2013 Galois, Inc. All Right Reserved. c

  17. Future work • We only consider structural patterns • Example: We don’t detect design patterns • Not semantically aware • Example: changing the name of a loop variable leads to � • Generate rewrite rules based on before and after patterns • Use patterns for searching as a structural grep -like mechanism • Correlate patterns with bug fixes � 2013 Galois, Inc. All Right Reserved. c

  18. Thank you! Questions? This work was supported in part by the US Department of Energy Office of Science, Advanced Scientic Computing Research contract no. DE-SC0004968. Additional support was provided by Galois, Inc. � 2013 Galois, Inc. All Right Reserved. c

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend