Dead Code Elimination through Dependent Types
- 337 Downloads
Pattern matching is an important feature in various functional programming languages such as SML, Caml, Haskell, etc. In these languages, unreachable or redundant matching clauses, which can be regarded as a special form of dead code, are a rich source for program errors. Therefore, eliminating unreachable matching clauses at compiletime can significantly enhance program error detection. Furthermore, this can also lead to significantly more efficient code at run-time.
We present a novel approach to eliminating unreachable matching clauses through the use of the dependent type system of DML, a functional programming language that enriches ML with a restricted form of dependent types. We then prove the correctness of the approach, which consists of the major technical contribution of the paper. In addition, we demonstrate the applicability of our approach to dead code elimination through some realistic examples. This constitutes a practical application of dependent types to functional programming, and in return it provides us with further support for the methodology adopted in our research on dependent types in practical programming.
KeywordsDependent Type Functional Programming Dead Computation Type Annotation Constraint Domain
Unable to display preview. Download preview PDF.
- Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman. Compilers. Addison-Wesley, Reading, Massachusetts, 1986.Google Scholar
- Rowan Davies. Practical refinement-type checking. Thesis Proposal, November 1997.Google Scholar
- Manuel Fähndrich and Alexander Aiken. Program analysis using mixed term and set constraints. In Proceedings of the 4th International Static Analysis Symposium, September 1997.Google Scholar
- Tim Freeman and Frank Pfenning. Refinement types for ML. In ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 268–277, Toronto, Ontario, 1991.Google Scholar
- F. Gecseg and M Steinb. Tree automata. Akademiai Kiado, 1991.Google Scholar
- Paul Hudak, S. L. Peyton Jones, and Philip Wadler. Report on the programming language Haskell, a non-strict purely-functional programming language, Version 1.2. SIGPLAN Notices, 27(5), May 1992.Google Scholar
- John Hughes. Compile-time analysis of functional programs. In D. Turner, editor, Research Topics in Functional Programming, pages 117–153. Addison-Wesley, 1990.Google Scholar
- N. Jones and S. Muchnick. Flow analysis and optimization of lisp-like structures. In Conference Record of 6th ACM SIGPLAN Symposium on Principles of Programming Languages, pages 244–256, January 1979.Google Scholar
- Gilles Kahn. Natural semantics. In Proceedings of the Symposium on Theoretical Aspects of Computer Science, pages 22–39. Springer-Verlag LNCS 247, 1987.Google Scholar
- J. Knoop, O. Rüthing, and B. Steffen. Partial dead code elimination. In Proceedings of the ACM SIGPLAN Conference on Programming Language Implementation and Design, pages 147–158, June 1994.Google Scholar
- Y. Liu and D. Stoller. Dead code elimination using program-based regular tree grammars. Available at ftp://ftp.cs.indiana.edu/pub/liu/ElimDeadRec-TR97.ps.Z.
- Robin Milner, Mads Tofte, Robert W. Harper, and D. MacQueen. The Definition of Standard ML. MIT Press, Cambridge,Massachusetts, 1997.Google Scholar
- Heintze Nevin. Set-based Program Analysis of ML programs. Ph. D dissertation, Carnegie Mellon University, 1992.Google Scholar
- F. Tip. A survey of program slicing. Journal of Programming Languages, 3(3):121–189, 1995.Google Scholar
- P. Wadler and J. Hughes. Projections for strictness analysis. In Proceedings of the 3rd International Conference on Functional Programming and Computer Architecture, volume 274 of Lecture Notes in Computer Science, pages 385–407. Springer-Verlag, 1987.Google Scholar
- Pierre Weis and Xavier Leroy. Le langage Caml. InterEditions, Paris, 1993.Google Scholar
- H. Xi and F. Pfenning. Eliminating array bound checking through dependent types. In Proceedings of ACM SIGPLAN Conference on Programming Language Design and Implementation, pages 249–257, June 1998.Google Scholar
- H. Xi and F. Pfenning. Dependent types in practical programming. In Proceedings of ACM SIGPLAN Symposium on Principles of Programming Languages, January 1999.Google Scholar
- Hongwei Xi. Some examples of DML programming. Available at http://www.cs.cmu.edu/~hwxi/DML/examples/, November 1997.
- Hongwei Xi. Dependent Types in Practical Programming. PhD thesis, Carnegie Mellon University, 1998. pp. viii+189. Forthcoming. The current version is available as http://www.cs.cmu.edu/~hwxi/DML/thesis.ps.
- K. Yi and S. Ryu. Towards a cost-effective estimation of uncaught exceptions in standard ml programs. In Proceedings of the 4th International Static Analysis Symposium, September 1997.Google Scholar