skip to main content
article

Refinement types for TypeScript

Published:02 June 2016Publication History
Skip Abstract Section

Abstract

We present Refined TypeScript (RSC), a lightweight refinement type system for TypeScript, that enables static verification of higher-order, imperative programs. We develop a formal system for RSC that delineates the interaction between refinement types and mutability, and enables flow-sensitive reasoning by translating input programs to an equivalent intermediate SSA form. By establishing type safety for the intermediate form, we prove safety for the input programs. Next, we extend the core to account for imperative and dynamic features of TypeScript, including overloading, type reflection, ad hoc type hierarchies and object initialization. Finally, we evaluate RSC on a set of real-world benchmarks, including parts of the Octane benchmarks, D3, Transducers, and the TypeScript compiler. We show how RSC successfully establishes a number of value dependent properties, such as the safety of array accesses and downcasts, while incurring a modest overhead in type annotations and code restructuring.

References

  1. C. Anderson, P. Giannini, and S. Drossopoulou. Towards Type Inference for JavaScript. In Proceedings of ECOOP, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. G. M. Bierman, A. D. Gordon, C. Hri¸tcu, and D. Langworthy. Semantic Subtyping with an SMT Solver. In Proceedings of ICFP, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. G. M. Bierman, M. Abadi, and M. Torgersen. Understanding TypeScript. In Proceedings of ECOOP, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. M. Bostock. http://d3js.org/.Google ScholarGoogle Scholar
  5. R. Chugh, D. Herman, and R. Jhala. Dependent Types for JavaScript. In Proceedings of OOPSLA, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. R. Chugh, P. M. Rondon, and R. Jhala. Nested Refinements: A Logic for Duck Typing. In Proceedings of POPL, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Cognitect Labs. https://github.com/cognitect-labs/ transducers-js.Google ScholarGoogle Scholar
  8. A. Feldthaus and A. Møller. Checking Correctness of Type-Script Interfaces for JavaScript Libraries. In Proceedings of OOPLSA, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. C. Flanagan, K. R. M. Leino, M. Lillibridge, G. Nelson, J. B. Saxe, and R. Stata. Extended Static Checking for Java. In Proceedings of PLDI, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. M. Furr, J.-h. D. An, J. S. Foster, and M. Hicks. Static Type Inference for Ruby. In Proceedings of the Symposium on Applied Computing, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. P. Gardner, S. Maffeis, and G. D. Smith. Towards a program logic for JavaScript. In Proceedings of POPL, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Google Developers. https://developers.google.com/ octane/.Google ScholarGoogle Scholar
  13. C. S. Gordon, M. J. Parkinson, J. Parsons, A. Bromfield, and J. Duffy. Uniqueness and Reference Immutability for Safe Parallelism. In Proceedings of OOPSLA, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. C. S. Gordon, M. D. Ernst, and D. Grossman. Rely-guarantee References for Refinement Types over Aliased Mutable Data. In Proceedings of PLDI, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. A. Guha, M. Fredrikson, B. Livshits, and N. Swamy. Verified Security for Browser Extensions. In Proceedings of the IEEE Symposium on Security and Privacy, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. S. Guo and B. Hackett. Fast and Precise Hybrid Type Inference for JavaScript. In Proceeding of PLDI, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. C. Haack and E. Poll. Type-Based Object Immutability with Flexible Initialization. In Proceedings of ECOOP, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. A. Igarashi, B. C. Pierce, and P. Wadler. Featherweight Java: A Minimal Core Calculus for Java and GJ. ACM Trans. Program. Lang. Syst., May 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. K. Knowles and C. Flanagan. Hybrid Type Checking. ACM Trans. Program. Lang. Syst., Feb. 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. K. Knowles and C. Flanagan. Compositional Reasoning and Decidable Checking for Dependent Contract Types. In Proceedings of PLPV, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. B. S. Lerner, J. G. Politz, A. Guha, and S. Krishnamurthi. Te-JaS: Retrofitting Type Systems for JavaScript. In Proceedings of DLS, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Microsoft Corporation. TypeScript v1.4. http://www. typescriptlang.org/.Google ScholarGoogle Scholar
  23. F. Militão, J. Aldrich, and L. Caires. Rely-Guarantee Protocols. In Proceedings of ECOOP, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. G. Nelson. Techniques for Program Verification. Technical Report CSL81-10, Xerox Palo Alto Research Center, 1981.Google ScholarGoogle Scholar
  25. N. Nystrom, V. Saraswat, J. Palsberg, and C. Grothoff. Constrained Types for Object-oriented Languages. In Proceedings of OOPSLA, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. X. Qi and A. C. Myers. Masked Types for Sound Object Initialization. In Proceedings of POPL, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. A. Rastogi, N. Swamy, C. Fournet, G. Bierman, and P. Vekris. Safe & Efficient Gradual Typing for TypeScript. In Proceedings of POPL, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. P. M. Rondon, M. Kawaguci, and R. Jhala. Liquid Types. In Proceedings of PLDI, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. J. Rushby, S. Owre, and N. Shankar. Subtypes for Specifications: Predicate Subtyping in PVS. IEEE TSE, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. E. L. Seidel, N. Vazou, and R. Jhala. Type Targeted Testing. In Proceedings of ESOP, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. F. Smith, D. Walker, and G. Morrisett. Alias Types. In Proceedings of ESOP, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. A. J. Summers and P. Mueller. Freedom Before Commitment: A Lightweight Type System for Object Initialisation. In Proceedings of OOPSLA, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. N. Swamy, J. Chen, C. Fournet, P.-Y. Strub, K. Bhargavan, and J. Yang. Secure Distributed Programming with Valuedependent Types. In Proceedings of ICFP, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. O. Tardieu, N. Nystrom, I. Peshansky, and V. Saraswat. Constrained Kinds. In Proceedings of OOPSLA, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. P. Thiemann. Towards a Type System for Analyzing JavaScript Programs. In Proceedings of ESOP, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. S. Tobin-Hochstadt and M. Felleisen. Logical Types for Untyped Languages. In Proceedings of ICFP, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. N. Vazou, E. L. Seidel, R. Jhala, D. Vytiniotis, and S. Peyton-Jones. Refinement Types for Haskell. In Proceedings of ICFP, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. P. Vekris, B. Cosman, and R. Jhala. Refinement Types for TypeScript (Extended version). http://arxiv.org/abs/ 1604.02480.Google ScholarGoogle Scholar
  39. P. Vekris, B. Cosman, and R. Jhala. Trust, but Verify: Two-Phase Typing for Dynamic Languages. In Proceedings of ECOOP, 2015.Google ScholarGoogle Scholar
  40. H. Xi and F. Pfenning. Dependent Types in Practical Programming. In Proceedings of POPL, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. B. Yankov. http://definitelytyped.org.Google ScholarGoogle Scholar
  42. Y. Zibin, A. Potanin, M. Ali, S. Artzi, A. Kiezun, and M. D. Ernst. Object and Reference Immutability Using Java Generics. In Proceedings of ESEC/FSE, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Y. Zibin, A. Potanin, P. Li, M. Ali, and M. D. Ernst. Ownership and Immutability in Generic Java. In Proceedings of OOPSLA, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Y. Zibin, D. Cunningham, I. Peshansky, and V. Saraswat. Object Initialization in X10. In Proceedings of ECOOP, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Refinement types for TypeScript

      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 51, Issue 6
        PLDI '16
        June 2016
        726 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2980983
        • Editor:
        • Andy Gill
        Issue’s Table of Contents
        • cover image ACM Conferences
          PLDI '16: Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation
          June 2016
          726 pages
          ISBN:9781450342612
          DOI:10.1145/2908080
          • General Chair:
          • Chandra Krintz,
          • Program Chair:
          • Emery Berger

        Copyright © 2016 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 2 June 2016

        Check for updates

        Qualifiers

        • 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!