Abstract
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.
Chapter PDF
Similar content being viewed by others
References
Bacon, D.F., Sweeney, P.F.: Fast static analysis of C++ virtual function calls. In: OOPSLA 1996, pp. 324–341. ACM, New York (1996)
Cardelli, L.: Type systems. In: Tucker, A.B. (ed.) The Computer Science and Engineering Handbook, ch. 97. CRC Press, Boca Raton (2004)
Chase, D.R., Wegman, M., Zadeck, F.K.: Analysis of pointers and structures. In: PLDI 1990. ACM, New York (1990)
Cousot, P.: The calculational design of a generic abstract interpreter. In: Calculational System Design. NATO ASI Series F. IOS Press, Amsterdam (1999)
Cousot, P.: Constructive design of a hierarchy of semantics of a transition system by abstract interpretation. Theoretical Computer Science 277, 47–103 (2002)
Cousot, P., Cousot, R.: Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In: POPL 1977. ACM, New York (1977)
Cousot, P., Cousot, R.: Systematic design of program analysis frameworks. In: POPL 1979. ACM, New York (1979)
Dean, J., Grove, D., Chambers, C.: Optimization of object-oriented programs using static class hierarchy analysis. In: Olthoff, W. (ed.) ECOOP 1995. LNCS, vol. 952, pp. 77–101. Springer, Heidelberg (1995)
Dotta, M., Suter, P., Kuncak, V.: On static analysis for expressive pattern matching. Technical report, EPFL (2008)
Standard ECMA-335. Common Language Infrastructure (CLI), 4th edn. ECMA (June 2006)
Emir, B.: Object-oriented pattern matching. PhD thesis, EPFL (2007)
Emir, B., Ma, Q., Odersky, M.: Translation correctness for first-order object-oriented pattern matching. In: Shao, Z. (ed.) APLAS 2007. LNCS, vol. 4807, pp. 54–70. Springer, Heidelberg (2007)
Emir, B., Odersky, M., Williams, J.: Matching objects with patterns. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 273–298. Springer, Heidelberg (2007)
Ferrara, P.: Checkmate: a generic static analyzer of java multithreaded programs. In: Proceedings of SEFM 2009. IEEE Computer Society, Los Alamitos (2009)
Hirzel, M., Nystrom, N., Bloom, B., Vitek, J.: Matchete: Paths through the pattern matching jungle. In: Hudak, P., Warren, D.S. (eds.) PADL 2008. LNCS, vol. 4902, pp. 150–166. Springer, Heidelberg (2008)
Kumar, R., Chakraborty, S.S.: Precise static type analysis for object oriented programs. SIGPLAN Not. 42, 17–26 (2007)
Lindholm, T., Yellin, F.: Java Virtual Machine Specification. Addison-Wesley Longman Publishing Co., Inc., Boston (1999)
Logozzo, F., Fähndrich, M.: On the relative completeness of bytecode analysis versus source code analysis. In: Hendren, L. (ed.) CC 2008. LNCS, vol. 4959, pp. 197–212. Springer, Heidelberg (2008)
Logozzo, F., Venter, H.: Rata: Rapid atomic type analysis by abstract interpretation. Application to JavaScript optimization. In: Gupta, R. (ed.) CC 2010. LNCS, vol. 6011, pp. 66–83. Springer, Heidelberg (2010)
Meyer, B.: Object-Oriented Software Construction, 2nd edn. Prentice Hall, Englewood Cliffs (1997)
Mitchell, N., Runciman, C.: Not all patterns, but enough: An automatic verifier for partial but sufficient pattern matching. SIGPLAN Not. 44, 49–60 (2009)
Odersky, M.: The Scala Language Specification (2008)
Richard, A., Lhotak, O.: Oomatch: pattern matching as dispatch in Java. In: OOPSLA 2007, pp. 771–772. ACM, New York (2007)
Spoto, F.: Julia: A Generic Static Analyser for the Java Bytecode. In: Proceedings of FTfJP 2005 (2005)
Syme, D., Neverov, G., Margetson, J.: Extensible pattern matching via a lightweight language extension. SIGPLAN Not. 42(9), 29–40 (2007)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2010 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Ferrara, P. (2010). Static Type Analysis of Pattern Matching by Abstract Interpretation. In: Hatcliff, J., Zucca, E. (eds) Formal Techniques for Distributed Systems. FMOODS FORTE 2010 2010. Lecture Notes in Computer Science, vol 6117. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-13464-7_15
Download citation
DOI: https://doi.org/10.1007/978-3-642-13464-7_15
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-13463-0
Online ISBN: 978-3-642-13464-7
eBook Packages: Computer ScienceComputer Science (R0)