skip to main content
research-article

Flow-sensitive type recovery in linear-log time

Published:22 October 2011Publication History
Skip Abstract Section

Abstract

The flexibility of dynamically typed languages such as JavaScript, Python, Ruby, and Scheme comes at the cost of run-time type checks. Some of these checks can be eliminated via control-flow analysis. However, traditional control-flow analysis (CFA) is not ideal for this task as it ignores flow-sensitive information that can be gained from dynamic type predicates, such as JavaScript's 'instanceof' and Scheme's 'pair?', and from type-restricted operators, such as Scheme's 'car'. Yet, adding flow-sensitivity to a traditional CFA worsens the already significant compile-time cost of traditional CFA. This makes it unsuitable for use in just-in-time compilers. In response, we have developed a fast, flow-sensitive type-recovery algorithm based on the linear-time, flow-insensitive sub-0CFA. The algorithm has been implemented as an experimental optimization for the commercial Chez Scheme compiler, where it has proven to be effective, justifying the elimination of about 60% of run-time type checks in a large set of benchmarks. The algorithm processes on average over 100,000 lines of code per second and scales well asymptotically, running in only O(n log n) time. We achieve this compile-time performance and scalability through a novel combination of data structures and algorithms.

References

  1. Alfred V. Aho, John E. Hopcroft, and Jeffrey D. Ullman. On finding lowest common ancestors in trees. In Proceedings of the fifth annual ACM symposium on Theory of computing, pages 253--265. ACM, 1973. 10.1145/800125.804056. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Stephen Alstrup, Cyril Gavoille, Haim Kaplan, and Theis Rauhe. Nearest common ancestors: A survey and a new algorithm for a distributed environment. Theory of Computing Systems, 37 (3): 441--456, May 2004. 10.1007/s00224-004--1155--5.Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. J. Michael Ashley and R. Kent Dybvig. A practical and flexible flow analysis for higher-order languages. ACM Transactions on Programming Languages and Systems (TOPLAS), 20 (4): 845--868, July 1998. 10.1145/291891.291898. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. John P. Banning. An efficient way to find the side effects of procedure calls and the aliases of variables. In Proceedings of the 6th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, pages 29--41. ACM, 1979. 10.1145/567752.567756. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Robert Cartwright and Mike Fagan. Soft typing. In Proceedings of the ACM SIGPLAN 1991 conference on Programming language design and implementation, pages 278--292. ACM, 1991. 10.1145/113445.113469. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Swarat Chaudhuri. Subcubic algorithms for recursive state machines. In Proceedings of the 35th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 159--169. ACM, 2008. 10.1145/1328438.1328460. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. William D. Clinger. Description of benchmarks, 2008. URL http://www.larcenists.org/benchmarksAboutR6.html.Google ScholarGoogle Scholar
  8. Patrick Cousot and Radhia Cousot. Systematic design of program analysis frameworks. In Proceedings of the 6th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, pages 269--282. ACM, 1979. 10.1145/567752.567778. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Manuvir Das, Sorin Lerner, and Mark Seigle. ESP: Path-sensitive program verification in polynomial time. In Proceedings of the ACM SIGPLAN 2002 Conference on Programming language design and implementation, pages 57--68. ACM, 2002. 10.1145/512529.512538. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. R. Kent Dybvig. Chez Scheme Version 8 User's Guide. Cadence Research Systems, 2010.Google ScholarGoogle Scholar
  11. Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. Typing local control and state using flow analysis. In Programming Languages and Systems, volume 6602, pages 256--275. Springer Berlin / Heidelberg, 2011. 10.1007/978--3--642--19718--5_14. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }Heintze-McAllester:ICFP97Nevin Heintze and David McAllester. On the complexity of set-based analysis. In Proceedings of the second ACM SIGPLAN international conference on Functional programming, pages 150--163. ACM, 1997. 10.1145/258948.258963. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. }Heintze-McAllester:PLDI97Nevin Heintze and David McAllester. Linear-time subtransitive control flow analysis. In Proceedings of the ACM SIGPLAN 1997 conference on Programming language design and implementation, pages 261--272. ACM, 1997. 10.1145/258915.258939. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Fritz Henglein. Global tagging optimization by type inference. ACM SIGPLAN Lisp Pointers, V (1): 205--215, January 1992. 10.1145/141478.141542. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Fritz Henglein. Dynamic typing: Syntax and proof theory. Science of Computer Programming, 22 (3): 197--230, June 1994. 10.1016/0167--6423(94)00004--2. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Fritz Henglein. Simple closure analysis. Semantics Report D-193, DIKU, University of Copenhagen, 1992.Google ScholarGoogle Scholar
  17. Suresh Jagannathan and Stephen Weeks. A unified treatment of flow analysis in higher-order languages. In Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 393--407. ACM, 1995. 10.1145/199448.199536. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Suresh Jagannathan, Peter Thiemann, Stephen Weeks, and Andrew Wright. Single and loving it: Must-alias analysis for higher-order languages. In Proceedings of the 25th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 329--341. ACM, 1998. 10.1145/268946.268973. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Simon Jensen, Anders Møller, and Peter Thiemann. Type analysis for JavaScript. In Static Analysis, volume 5673, pages 238--255. Springer Berlin / Heidelberg, 2009. 10.1007/978--3--642-03237-0_17. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. David Melski and Thomas Reps. Interconvertibility of a class of set constraints and context-free-language reachability. Theoretical Computer Science, 248 (1--2): 29--98, October 2000. 10.1016/S0304--3975(00)00049--9. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Jan Midtgaard and David Van Horn. Subcubic control flow analysis algorithms. Computer Science Research Report 125, Roskilde University, Roskilde, Denmark, May 2009. Revised version to appear in Higher-Order and Symbolic Computation.Google ScholarGoogle Scholar
  22. Torben Æ. Mogensen. Glossary for partial evaluation and related topics. Higher-Order and Symbolic Computation, 13 (4): 355--368, December 2000. 10.1023/A:1026551132647. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Christian Mossin. Higher-order value flow graphs. Nordic Journal of Computing, 5 (3): 214--234, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Mozilla Corporation. Doctor JS, 2011. http://doctorjs.org/.Google ScholarGoogle Scholar
  25. Eugene W. Myers. Efficient applicative data types. In Proceedings of the 11th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, pages 66--75. ACM, 1984. 10.1145/800017.800517. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Flemming Nielson, Hanne Riis Nielson, and Chris Hankin. Principles of Program Analysis. Springer-Verlag, 1999. ISBN 978--3--540--65410-0. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. William Pugh. Skip lists: A probabilistic alternative to balanced trees. Communications of the ACM, 33 (6): 668--676, June 1990. 10.1145/78973.78977. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Manuel Serrano. Control flow analysis: A functional languages compilation paradigm. In Proceedings of the 1995 ACM symposium on Applied computing, pages 118--122. ACM, 1995. 10.1145/315891.315934. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Olin Shivers. Data-flow analysis and type recovery in Scheme. In Peter Lee, editor, Topics in Advanced Language Implementations, pages 47--87. The MIT Press, 1991.Google ScholarGoogle Scholar
  30. Olin Shivers. Control flow analysis in Scheme. In Proceedings of the ACM SIGPLAN 1988 conference on Programming Language design and Implementation, pages 164--174. ACM, 1988. 10.1145/53990.54007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Jeremy G. Siek and Walid Taha. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, pages 81--92, September 2006.Google ScholarGoogle Scholar
  32. Peter A. Steenkiste. The implementation of tags and run-time type checking. In Peter Lee, editor, Topics in Advanced Language Implementations, pages 3--24. The MIT Press, 1991.Google ScholarGoogle Scholar
  33. Sam Tobin-Hochstadt and Matthias Felleisen. Logical types for untyped languages. In Proceedings of the 15th ACM SIGPLAN international conference on Functional programming, pages 117--128. ACM, 2010. 10.1145/1863543.1863561. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Dimitrios Vardoulakis and Olin Shivers. CFA2: A context-free approach to control-flow analysis. In Programming Languages and Systems, volume 6012, pages 570--589. Springer Berlin / Heidelberg, 2010. 10.1007/978--3--642--11957--6_30.Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Mark N. Wegman and F. Kenneth Zadeck. Constant propagation with conditional branches. ACM Transactions on Programming Languages and Systems (TOPLAS), 13 (2): 181--210, April 1991. 10.1145/103135.103136. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Flow-sensitive type recovery in linear-log time

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 46, Issue 10
      OOPSLA '11
      October 2011
      1063 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2076021
      Issue’s Table of Contents
      • cover image ACM Conferences
        OOPSLA '11: Proceedings of the 2011 ACM international conference on Object oriented programming systems languages and applications
        October 2011
        1104 pages
        ISBN:9781450309400
        DOI:10.1145/2048066

      Copyright © 2011 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 22 October 2011

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!