Static Type Analysis of Pattern Matching by Abstract Interpretation

Pattern matching is one of the most attractive features of functional programming languages. Recently, pattern matching has been applied to programming languages supporting the main current object oriented features. In this paper, we present a static type analysis based on the abstract interpretation framework aimed at proving the exhaustiveness of pattern matchings and the safety of type casts. The analysis is composed by two distinct abstract domains. The first domain collects information about dynamic typing, while the second one tracks the types that an object cannot be instance of. The analysis has been implemented and applied to all the Scala library. The experimental results underline that our approach scales up since it analyzes a method in 90 msec in average. In addition, the analysis is precise in practice as well, since we prove the exhaustiveness of 42% of pattern matchings and 27% of the type casts without any manual annotation on the code.

[1]  Ecma,et al.  Common Language Infrastructure (CLI) , 2001 .

[2]  Pietro Ferrara,et al.  Checkmate: A Generic Static Analyzer of Java Multithreaded Programs , 2009, 2009 Seventh IEEE International Conference on Software Engineering and Formal Methods.

[3]  David F. Bacon,et al.  Fast static analysis of C++ virtual function calls , 1996, OOPSLA '96.

[4]  Don Syme,et al.  Extensible pattern matching via a lightweight language extension , 2007, ICFP '07.

[5]  Colin Runciman,et al.  Not all patterns, but enough: an automatic verifier for partial but sufficient pattern matching , 2008, Haskell '08.

[6]  Erik Ernst,et al.  ECOOP 2007 - Object-Oriented Programming, 21st European Conference, Berlin, Germany, July 30 - August 3, 2007, Proceedings , 2007, ECOOP.

[7]  Mark N. Wegman,et al.  Analysis of pointers and structures (with retrospective) , 1990 .

[8]  Bertrand Meyer,et al.  Object-oriented software construction (2nd ed.) , 1997 .

[9]  Mark N. Wegman,et al.  Analysis of pointers and structures , 1990, SIGP.

[10]  Patrick Cousot,et al.  Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints , 1977, POPL.

[11]  Patrick Cousot,et al.  Systematic design of program analysis frameworks , 1979, POPL.

[12]  Patrick Cousot,et al.  The calculational design of a generic abstract interpreter , 1999 .

[13]  Manuel Fähndrich,et al.  On the Relative Completeness of Bytecode Analysis Versus Source Code Analysis , 2008, CC.

[14]  Martin Odersky,et al.  Translation Correctness for First-Order Object-Oriented Pattern Matching , 2007, APLAS.

[15]  Martin Odersky,et al.  Matching Objects with Patterns , 2007, ECOOP.

[16]  Patrick Cousot,et al.  Constructive design of a hierarchy of semantics of a transition system by abstract interpretation , 2002, MFPS.

[17]  Shlomo Nir,et al.  NATO ASI Series , 1995 .

[18]  Jan Vitek,et al.  Matchete: Paths through the Pattern Matching Jungle , 2008, PADL.

[19]  David Grove,et al.  Optimization of Object-Oriented Programs Using Static Class Hierarchy Analysis , 1995, ECOOP.

[20]  Ondrej Lhoták,et al.  OOMatch: pattern matching as dispatch in Java , 2007, OOPSLA '07.

[21]  Bertrand Meyer,et al.  Object-Oriented Software Construction, 2nd Edition , 1997 .

[22]  Manfred Broy,et al.  Calculational system design , 1999 .

[23]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[24]  Francesco Logozzo,et al.  RATA: Rapid Atomic Type Analysis by Abstract Interpretation - Application to JavaScript Optimization , 2010, CC.

[25]  Rajeev Kumar,et al.  Precise static type analysis for object oriented programs , 2007, SIGP.

[26]  Burak Emir,et al.  Object-oriented pattern matching , 2007 .

[27]  Fausto Spoto,et al.  Julia: A Generic Static Analyser for the Java Bytecode , 2005 .

[28]  Frank Yellin,et al.  The Java Virtual Machine Specification , 1996 .

[29]  Viktor Kuncak,et al.  On Static Analysis for Expressive Pattern Matching , 2008 .

[30]  簡聰富,et al.  物件導向軟體之架構(Object-Oriented Software Construction)探討 , 1989 .