Abstract
The standard algorithm for higher-order contract checking can lead to unbounded space consumption and can destroy tail recursion, altering a program's asymptotic space complexity. While space efficiency for gradual types---contracts mediating untyped and typed code---is well studied, sound space efficiency for manifest contracts---contracts that check stronger properties than simple types, e.g., "is a natural'' instead of "is an integer''---remains an open problem.
We show how to achieve sound space efficiency for manifest contracts with strong predicate contracts. The essential trick is breaking the contract checking down into coercions: structured, blame-annotated lists of checks. By carefully preventing duplicate coercions from appearing, we can restore space efficiency while keeping the same observable behavior.
Supplemental Material
Available for Download
- J. F. Belo, M. Greenberg, A. Igarashi, and B. C. Pierce. Polymorphic contracts. In European Symposium on Programming (ESOP), 2011. Google Scholar
Digital Library
- G. M. Bierman, A. D. Gordon, C. Hri\ctcu, and D. Langworthy. Semantic subtyping with an SMT solver. In International Conference on Functional Programming (ICFP), 2010. Google Scholar
Digital Library
- C. Dimoulas, R. Findler, and M. Felleisen. Option contracts. In OOPSLA, pages 475 -- 494, 2013. Google Scholar
Digital Library
- R. B. Findler. Contracts as pairs of projections. In Symposium on Logic Programming, 2006. Google Scholar
Digital Library
- R. B. Findler and M. Felleisen. Contracts for higher-order functions. In International Conference on Functional Programming (ICFP), 2002. Google Scholar
Digital Library
- R. B. Findler, S.-Y. Guo, and A. Rogers. Lazy contract checking for immutable data structures. In Implementation and Application of Functional Languages, pages 111--128. 2008. 10.1007/978--3--540--85373--2_7. Google Scholar
Digital Library
- C. Flanagan. Hybrid type checking. In Principles of Programming Languages (POPL), 2006. Google Scholar
Digital Library
- R. Garcia. Calculating threesomes, with blame. In International Conference on Functional Programming (ICFP), 2013. Google Scholar
Digital Library
- M. Greenberg. Manifest Contracts. PhD thesis, University of Pennsylvania, November 2013. Google Scholar
Digital Library
- M. Greenberg. Space-efficient manifest contracts, 2014. URL http://arxiv.org/abs/1410.2813. Technical report.Google Scholar
- M. Greenberg, B. C. Pierce, and S. Weirich. Contracts made manifest. In Principles of Programming Languages (POPL), 2010. Google Scholar
Digital Library
- M. Greenberg, B. C. Pierce, and S. Weirich. Contracts made manifest. Journal of Functional Programming (JFP), 22 (3): 225--274, May 2012. Google Scholar
Digital Library
- J. Gronski and C. Flanagan. Unifying hybrid types and contracts. In Trends in Functional Programming (TFP), 2007.Google Scholar
- F. Henglein. Dynamic typing: Syntax and proof theory. Sci. Comput. Program., 22 (3): 197--230, 1994. Google Scholar
Digital Library
- D. Herman, A. Tomb, and C. Flanagan. Space-efficient gradual typing. In Trends in Functional Programming (TFP), pages 404--419, 2007.Google Scholar
- D. Herman, A. Tomb, and C. Flanagan. Space-efficient gradual typing. Higher Order Symbol. Comput., 23 (2): 167--189, June 2010. Google Scholar
Digital Library
- K. Knowles and C. Flanagan. Hybrid type checking. ACM Trans. Prog. Lang. Syst., 32: 6:1--6:34, 2010. Google Scholar
Digital Library
- K. Knowles, A. Tomb, J. Gronski, S. N. Freund, and C. Flanagan. Sage: Hybrid checking for flexible specifications. In Scheme and Functional Programming Workshop, 2006.Google Scholar
- E. Koukoutos and V. Kuncak. Checking data structure properties orders of magnitude faster. In Runtime Verification, pages 263--268. 2014. 10.1007/978--3--319--11164--3_22.Google Scholar
Cross Ref
- R. Lipton, October 2010. URL http://goo.gl/6Grgt0.Google Scholar
- R. Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17: 348--375, Aug. 1978.Google Scholar
Cross Ref
- PLT. Racket contract system, 2013. URL http://pre.plt-scheme.org/docs/html/guide/contracts.html.Google Scholar
- A. Rastogi, A. Chaudhuri, and B. Hosmer. The ins and outs of gradual type inference. In Principles of Programming Languages (POPL), 2012. 10.1145/2103656.2103714. Google Scholar
Digital Library
- J. Siek, R. Garcia, and W. Taha. Exploring the design space of higher-order casts. In Programming Languages and Systems, volume 5502 of LNCS, pages 17--31. 2009. Google Scholar
Digital Library
- J. Siek, P. Thiemann, and P. Wadler. Blame, coercion, and threesomes: Together again for the first time. Draft., 2014. URL http://homepages.inf.ed.ac.uk/wadler/topics/blame.html#coercions.Google Scholar
- J. G. Siek and R. Garcia. Interpretations of the gradually-typed lambda calculus. In Scheme and Functional Programming (SFP), 2012. Google Scholar
Digital Library
- J. G. Siek and W. Taha. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, September 2006.Google Scholar
- J. G. Siek and P. Wadler. Threesomes, with and without blame. In Principles of Programming Languages (POPL), pages 365--376, 2010. Google Scholar
Digital Library
- N. Swamy, M. Hicks, and G. M. Bierman. A theory of typed coercions and its applications. In International Conference on Functional Programming (ICFP), pages 329--340, 2009. ISBN 978--1--60558--332--7. Google Scholar
Digital Library
- S. Tobin-Hochstadt and M. Felleisen. Interlanguage migration: From scripts to programs. In OOPSLA, 2006. 10.1145/1176617.1176755. Google Scholar
Digital Library
- P. Wadler and R. B. Findler. Well-typed programs can't be blamed. In European Symposium on Programming (ESOP), 2009. Google Scholar
Digital Library
- A. K. Wright and M. Felleisen. A syntactic approach to type soundness. Information and Computation, 115: 38--94, 1994. Google Scholar
Digital Library
Index Terms
Space-Efficient Manifest Contracts
Recommendations
Space-Efficient Manifest Contracts
The standard algorithm for higher-order contract checking can lead to unbounded space consumption and can destroy tail recursion, altering a program's asymptotic space complexity. While space efficiency for gradual types---contracts mediating untyped ...







Comments