skip to main content
research-article
Open Access

Foundations of Typestate-Oriented Programming

Published:28 October 2014Publication History
Skip Abstract Section

Abstract

Typestate reflects how the legal operations on imperative objects can change at runtime as their internal state changes. A typestate checker can statically ensure, for instance, that an object method is only called when the object is in a state for which the operation is well defined. Prior work has shown how modular typestate checking can be achieved thanks to access permissions and state guarantees. However, typestate was not treated as a primitive language concept: typestate checkers are an additional verification layer on top of an existing language. In contrast, a typestate-oriented programming (TSOP) language directly supports expressing typestates. For example, in the Plaid programming language, the typestate of an object directly corresponds to its class, and that class can change dynamically. Plaid objects have not only typestate-dependent interfaces but also typestate-dependent behaviors and runtime representations.

This article lays foundations for TSOP by formalizing a nominal object-oriented language with mutable state that integrates typestate change and typestate checking as primitive concepts. We first describe a statically typed language—Featherweight Typestate (FT)—where the types of object references are augmented with access permissions and state guarantees. We describe a novel flow-sensitive permission-based type system for FT. Because static typestate checking is still too rigid for some applications, we then extend this language into a gradually typed language—Gradual Featherweight Typestate (GFT). This language extends the notion of gradual typing to account for typestate: gradual typestate checking seamlessly combines static and dynamic checking by automatically inserting runtime checks into programs. The gradual type system of GFT allows programmers to write dynamically safe code even when the static type checker can only partly verify it.

References

  1. Amal Ahmed, Matthew Fluet, and Greg Morrisett. 2007. L3: A linear language with locations. Fundamenta Informaticae 77, 4, 397--449. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Jonathan Aldrich, Joshua Sunshine, Darpan Saini, and Zachary Sparks. 2009. Typestate-oriented programming. In Proceedings of the 24th ACM SIGPLAN Conference Companion on Object-Oriented Programming Systems Languages and Applications (OOPSLA’09). ACM, New York, NY, 1015--1022. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Henry G. Baker. 1994. Minimizing reference count updating with deferred and anchored pointers for functional data structures. ACM SIGPLAN Notices 29, 9, 38--43. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Kevin Bierhoff and Jonathan Aldrich. 2007. Modular typestate checking of aliased objects. In Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems and Applications. ACM, New York, NY, 301--320. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Kevin Bierhoff, Nels E. Beckman, and Jonathan Aldrich. 2009. Practical API protocol checking with access permissions. In Proceedings of the 23rd European Conference on Object-Oriented Programming (ECOOP’09). Springer-Verlag, Berlin, Heidelberg, 195--219. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Gavin Bierman, Erik Meijer, and Mads Torgersen. 2010. Adding dynamic types to C. In Proceedings of the 24th European Conference on Object-Oriented Programming (ECOOP’10). Springer-Verlag, Berlin, Heidelberg, 76--100. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Eric Bodden. 2010. Efficient hybrid typestate analysis by determining continuation-equivalent states. In Proceedings of the 32nd ACM/IEEE International Conference on Software Engineering (ICSE’10). ACM, New York, NY, 5--14. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. John Boyland. 2003. Checking interference with fractional permissions. In Proceedings of the 10th International Conference on Static Analysis (SAS’03). Springer-Verlag, Berlin, Heidelberg, 55--72. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. John Boyland and William Retert. 2005. Connecting effects and uniqueness with adoption. In Proceedings of the 32nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’05). ACM, New York, NY, 283--295. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Robert DeLine and Manuel Fähndrich. 2004. Typestates for objects. In ECOOP 2004—Object-Oriented Programming. Lecture Notes in Computer Science, Vol. 3086. Springer, 465--490.Google ScholarGoogle Scholar
  11. Sophia Drossopoulou, Ferruccio Damiani, Mariangiola Dezani-Ciancaglini, and Paola Giannini. 2001. Fickle: Dynamic object re-classification. In Proceedings of the 15th European Conference on Object-Oriented Programming (ECOOP’01). Springer-Verlag, Berlin, Heidelberg. 130--149. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Stephen J. Fink, Eran Yahav, Nurit Dor, G. Ramalingam, and Emmanuel Geay. 2008. Effective typestate verification in the presence of aliasing. ACM Transactions on Software Engineering and Methodology 17, 2, Article No. 9. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1994. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Boston, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Ronald Garcia, Roger Wolff, Éric Tanter, and Jonathan Aldrich. 2013. Featherweight Typestate. Technical Report CMU-ISR-13-112. Carnegie Mellon University, Pittsburgh, PA.Google ScholarGoogle Scholar
  15. Simon Gay, Vasco Vasconcelos, António Ravara, Nils Gesbert, and Alexandre Caldeira. 2010. Modular session types for distributed object-oriented programming. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’10). ACM, New York, NY, 299--312. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Jean-Yves Girard. 1987. Linear logic. Theoretical Computer Science 50, 1, 1--102. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Atsushi Igarashi, Benjamin C. Pierce, and Philip Wadler. 2001. Featherweight Java: A minimal core calculus for Java and GJ. ACM Transactions on Programming Languages and Systems 23, 3, 396--450. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Ciera Jaspan and Jonathan Aldrich. 2009. Checking framework interactions with relationships. In ECOOP 2009—Object-Oriented Programming. Lecture Notes in Computer Science, Vol. 5653. Springer, 27--51. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Kenneth Knowles and Cormac Flanagan. 2010. Hybrid type checking. ACM Transactions on Programming Languages and Systems 32, 2, 6:1--6:34. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Yossi Levanoni and Erez Petrank. 2006. An on-the-fly reference-counting garbage collector for Java. ACM Transactions on Programming Languages and Systems 28, 1, 1--69. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Karl Naden, Robert Bocchino, Jonathan Aldrich, and Kevin Bierhoff. 2012. A type system for borrowing permissions. In Proceedings of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL’12). ACM, New York, NY, 557--570. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Nomair A. Naeem and Ondrej Lhoták. 2008. Typestate-like analysis of multiple interacting objects. In Proceedings of the 23rd ACM SIGPLAN Conference on Object-Oriented Programming Systems Languages and Applications (OOPSLA’08). ACM, New York, NY, 347--366. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Mangala G. Nanda, Christian Grothoff, and Satish Chandra. 2005. Deriving object typestates in the presence of inter-object references. In Proceedings of the 20th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’05). ACM, New York, NY, 77--96. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Benjamin C. Pierce. 2002. Types and Programming Languages. MIT Press, Cambridge, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Amr Sabry and Matthias Felleisen. 1993. Reasoning about programs in continuation-passing style. Lisp and Symbolic Computation 6, 3--4, 289--360. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Darpan Saini, Joshua Sunshine, and Jonathan Aldrich. 2010. A theory of typestate-oriented programming. In Proceedings of the 12th Workshop on Formal Techniques for Java-Like Programs (FTFJP’10). ACM, New York, NY, Article No. 9. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Jeremy Siek and Walid Taha. 2006. Gradual typing for functional languages. In Proceedings of the Scheme and Functional Programming Workshop. ACM, New York, NY.Google ScholarGoogle Scholar
  28. Jeremy Siek and Walid Taha. 2007. Gradual typing for objects. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP’07). Springer-Verlag, Berlin, Heidelberg, 2--27. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Jeremy G. Siek and Manish Vachharajani. 2008. Gradual typing with unification-based inference. In Proceedings of the 2008 Symposium on Dynamic Languages (DLS’08). ACM, New York, NY, 7:1--7:12. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Sven Stork. 2013. Æminium: Freeing Programmers from the Shackles of Sequentiality. Ph.D. Dissertation. Carnegie Mellon University, Pittsburgh, PA.Google ScholarGoogle Scholar
  31. Robert E. Strom and Shaula Yemini. 1986. Typestate: A programming language concept for enhancing software reliability. IEEE Transactions on Software Engineering 12, 1, 157--171. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Joshua Sunshine, Karl Naden, Sven Stork, Jonathan Aldrich, and Éric Tanter. 2011. First-class state change in plaid. In Proceedings of the 2011 ACM International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’11). ACM, New York, NY, 713--732. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. David Walker. 2005. Substructural type systems. In Advanced Topics in Types and Programming Languages, Benjamin Pierce (Ed.). MIT Press, Cambridge, MA, 3--43.Google ScholarGoogle Scholar
  34. Roger Wolff, Ronald Garcia, Éric Tanter, and Jonathan Aldrich. 2011. Gradual typestate. In ECOOP 2011—Object-Oriented Programming. Lecture Notes in Computer Science, Vol. 6813. Springer, 459--483. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Roger Wolff, Ronald Garcia, Éric Tanter, and Jonathan Aldrich. 2013. Gradual Featherweight Typestate. Technical Report CMU-ISR-13-113. Carnegie Mellon University, Pittsburgh, PA.Google ScholarGoogle Scholar

Index Terms

  1. Foundations of Typestate-Oriented Programming

      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 Transactions on Programming Languages and Systems
        ACM Transactions on Programming Languages and Systems  Volume 36, Issue 4
        October 2014
        184 pages
        ISSN:0164-0925
        EISSN:1558-4593
        DOI:10.1145/2684821
        Issue’s Table of Contents

        Copyright © 2014 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 28 October 2014
        • Accepted: 1 May 2014
        • Revised: 1 March 2014
        • Received: 1 May 2012
        Published in toplas Volume 36, Issue 4

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article
        • Research
        • Refereed

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader