Recency Types for Analyzing Scripting Languages

  • Phillip Heidegger
  • Peter Thiemann
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6183)


With the current surge of scripting technologies, large programs are being built with dynamically typed languages. As these programs grow in size, semantics-based tools gain importance for detecting programming errors as well as for program understanding.

As a basis for such tools, we propose a descriptive type system for an imperative call-by-value lambda calculus with objects. The calculus models essential features of JavaScript, a widely used dynamically-typed language: first-class functions, objects as property maps, and prototypes.

Our type system infers precise singleton object types for recently allocated objects. These object types are handled flow-sensitively and change during the objects’ initialization phase. The notion of recency provides an automatic criterion to subsume these precise object types to summary object types, which are handled flow-insensitively. The criterion applies on a per-object basis. Thus, the type system identifies a generalized initialization phase for each object during which the change of its value is precisely reflected in the change of its type. Unlike with linear types, summary types may refer to singleton types and vice versa.

We prove the soundness of the type system and present a constraint-based inference algorithm. An implementation is available on the web.


Type System Object Type Typing Rule Type Soundness Subtyping Relation 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Altucher, R.Z., Landi, W.: An extended form of must alias analysis for dynamic allocation. In: Proc. 1995 ACM Symp. POPL, San Francisco, CA, USA, pp. 74–84. ACM Press, New York (January 1995)Google Scholar
  2. 2.
    Anderson, C., Giannini, P., Drossopoulou, S.: Towards type inference for javaScript. In: Black, A.P. (ed.) ECOOP 2005. LNCS, vol. 3586, pp. 428–452. Springer, Heidelberg (2005)Google Scholar
  3. 3.
    Balakrishnan, G., Reps, T.W.: Recency-abstraction for heap-allocated storage. In: Yi, K. (ed.) SAS 2006. LNCS, vol. 4134, pp. 221–239. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  4. 4.
    Bono, V., Fisher, K.: An imperative, first-order calculus with object extension. In: Jul, E. (ed.) ECOOP 1998. LNCS, vol. 1445, pp. 462–497. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  5. 5.
    Boyland, J., Noble, J., Retert, W.: Capabilities for sharing: A generalisation of uniqueness and read-only. In: Knudsen, J.L. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 2–27. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  6. 6.
    Chase, D.R., Wegman, M., Zadeck, F.K.: Analysis of pointers and structures. In: Proc. PLDI 1990, White Plains NY, USA, pp. 296–310. ACM, New York (June 1990)Google Scholar
  7. 7.
    Crockford, D.: JavaScript: The Good Parts, 170 p. O’Reilly Media, Sebastopol (2008)Google Scholar
  8. 8.
    ECMAScript Language Specification, ECMA International, ECMA-262, 3rd edn. (December 1999),
  9. 9.
    Fisher, K.: Type Systems for Object-Oriented Programming Languages. PhD thesis, Standford University, Stanford CS Technical Report STAN-CS-TR-98-1602 (1996)Google Scholar
  10. 10.
    Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: Proc. 1993 PLDI, Albuquerque, NM, USA, pp. 237–247 (June 1993)Google Scholar
  11. 11.
    Foster, J.S., Terauchi, T., Aiken, A.: Flow-sensitive type qualifiers. In: Proc. 2002 PLDI, Berlin, Germany, pp. 1–12. ACM Press, New York (June 2002)CrossRefGoogle Scholar
  12. 12.
    Fähndrich, M., Xia, S.: Establishing object invariants with delayed types. In: Proc. 22nd ACM Conf. OOPSLA, Montreal, QC, CA, pp. 337–350. ACM Press, New York (2007)Google Scholar
  13. 13.
    Gifford, D., Lucassen, J.: Integrating functional and imperative programming. In: Proc. 1986 ACM Conf. on Lisp and Functional Programming, pp. 28–38 (1986)Google Scholar
  14. 14.
    Heidegger, P., Thiemann, P.: Recency types for scripting languages. Universität Freiburg (July 2009),
  15. 15.
    Jagannathan, S., Thiemann, P., Weeks, S., Wright, A.: Single and loving it: Must-alias analysis for higher-order languages. In: Cardelli, L. (ed.) Proc. 25th ACM Symp. POPL, San Diego, CA, USA, pp. 329–341. ACM Press, New York (January 1998)Google Scholar
  16. 16.
    Jensen, S.H., Møller, A., Thiemann, P.: Type analysis for JavaScript. In: Palsberg, J., Su, Z. (eds.) SAS 2009. LNCS, vol. 5673, pp. 238–255. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  17. 17.
    Jones, N.D., Muchnick, S.S.: Flow analysis and optimization of Lisp-like languages. In: Proc.  6th ACM Symp. POPL, pp. 244–256. ACM Press, New York (1979)Google Scholar
  18. 18.
    Kehrt, M., Aldrich, J.: A theory of linear objects. In: FOOL 2008, San Francisco, CA, USA (January 2008),
  19. 19.
    Lebresne, S., Richards, G., Östlund, J., Wrigstad, T., Vitek, J.: Understanding the dynamics of JavaScript. In: International Workshop on Script to Program Evolution (STOP), Genova, Italy (July 2009)Google Scholar
  20. 20.
    Might, M., Shivers, O.: Improving flow analyses via ΓCFA: Abstract garbage collection and counting. In: Lawall, J. (ed.) Proc. ICFP 2006, Portland, Oregon, USA, pp. 13–25. ACM Press, New York (September 2006)CrossRefGoogle Scholar
  21. 21.
    Qi, X., Myers, A.C.: Masked types for sound object initialization. In: Pierce, B. (ed.) Proc. 36th ACM Symp. POPL, Savannah, GA, USA, pp. 53–65. ACM Press, New York (January 2009)Google Scholar
  22. 22.
    Smith, F., Walker, D., Morrisett, J.G.: Alias types. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, pp. 366–381. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  23. 23.
    Thiemann, P.: Towards a type system for analyzing JavaScript programs. In: Sagiv, M. (ed.) ESOP 2005. LNCS, vol. 3444, pp. 408–422. Springer, Heidelberg (2005)Google Scholar
  24. 24.
    Tobin-Hochstadt, S., Felleisen, M.: The design and implementation of typed scheme. In: Wadler, P. (ed.) Proc. 35th ACM Symp. POPL, San Francisco, CA, USA, pp. 395–406. ACM Press, New York (January 2008)Google Scholar
  25. 25.
    Walker, D., Morrisett, G.: Alias types for recursive data structures. In: Harper, R. (ed.) TIC 2000. LNCS, vol. 2071, pp. 177–206. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  26. 26.
    Wright, A., Felleisen, M.: A syntactic approach to type soundness. Information and Computation 115(1), 38–94 (1994)zbMATHCrossRefMathSciNetGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2010

Authors and Affiliations

  • Phillip Heidegger
    • 1
  • Peter Thiemann
    • 1
  1. 1.Albert-Ludwigs-Universität FreiburgGermany

Personalised recommendations