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 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.

[1]  Greg Nelson,et al.  Extended static checking for Java , 2002, PLDI '02.

[2]  Philip Wadler,et al.  Threesomes, with and without blame , 2010, POPL '10.

[3]  Atsushi Igarashi,et al.  Polymorphic Contracts , 2011, ESOP.

[4]  Avik Chaudhuri,et al.  The ins and outs of gradual type inference , 2012, POPL '12.

[5]  Benjamin C. Pierce,et al.  Contracts made manifest , 2010, POPL '10.

[6]  David Walker,et al.  Dynamic Typing with Dependent Types , 2004, IFIP TCS.

[7]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[8]  Jeremy G. Siek Gradual Typing for Functional Languages , 2006 .

[9]  Frank Pfenning,et al.  Refinement types for ML , 1991, PLDI '91.

[10]  Olaf Chitil,et al.  Monadic, Prompt Lazy Assertions in Haskell , 2007, APLAS.

[11]  Stephen N. Freund,et al.  Sage: Hybrid Checking for Flexible Specifications , 2006 .

[12]  Jurriaan Hage,et al.  Implementation and Application of Functional Languages , 2011, Lecture Notes in Computer Science.

[13]  G. G. Stokes "J." , 1890, The New Yale Book of Quotations.

[14]  Andrew D. Gordon,et al.  Principles and Applications of Refinement Types , 2010, Logics and Languages for Reliability and Security.

[15]  Anne Rogers,et al.  Lazy Contract Checking for Immutable Data Structures , 2008, IFL.

[16]  Yasuhiko Minamide Runtime Behavior of Conversion Interpretation of Subtyping , 2001, IFL.

[17]  Jeremy G. Siek,et al.  Interpretations of the gradually-typed lambda calculus , 2012, Scheme '12.

[18]  Walid Taha,et al.  Gradual Typing for Objects , 2007, ECOOP.

[19]  Amal Ahmed,et al.  Parametric Polymorphism through Run-Time Sealing or, Theorems for Low, Low Prices! , 2008, ESOP.

[20]  Walid Taha,et al.  Exploring the Design Space of Higher-Order Casts , 2009, ESOP.

[21]  Matthias Felleisen,et al.  Option contracts , 2013, OOPSLA.

[22]  Martín Abadi,et al.  Dynamic typing in a statically-typed language , 1989, POPL '89.

[23]  Satish R. Thatte Quasi-static typing , 1989, POPL '90.

[24]  Patrick Maxim Rondon,et al.  Liquid types , 2008, PLDI '08.

[25]  Viktor Kuncak,et al.  Checking Data Structure Properties Orders of Magnitude Faster , 2014, RV.

[26]  Philip Wadler,et al.  Blame and coercion: together again for the first time , 2015, Journal of Functional Programming.

[27]  Ravi Chugh,et al.  Nested refinements: a logic for duck typing , 2012, POPL '12.

[28]  Matthias Felleisen,et al.  Contracts for higher-order functions , 2002, ICFP '02.

[29]  Ralf Hinze,et al.  Typed Contracts for Functional Programming , 2006, FLOPS.

[30]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[31]  Philip Wadler,et al.  Blame for all , 2011, POPL '11.

[32]  Bertrand Meyer,et al.  Eiffel: The Language , 1991 .

[33]  HriţcuCătălin,et al.  Semantic subtyping with an smt solver , 2012 .

[34]  Cormac Flanagan,et al.  Space-efficient gradual typing , 2010, High. Order Symb. Comput..

[35]  Sam Tobin-Hochstadt,et al.  Interlanguage migration: from scripts to programs , 2006, OOPSLA '06.

[36]  Cormac Flanagan,et al.  Hybrid type checking , 2006, POPL '06.

[37]  C. Flanagan,et al.  Gradual Information Flow Typing , 2011 .

[38]  Matthias Felleisen,et al.  Correct blame for contracts: no more scapegoating , 2011, POPL '11.

[39]  Andrew D. Gordon,et al.  Semantic subtyping with an SMT solver , 2010, ICFP '10.

[40]  Benjamin C. Pierce,et al.  Manifest contracts , 2013 .

[41]  Ronald Garcia,et al.  Calculating threesomes, with blame , 2013, ICFP.

[42]  Fritz Henglein,et al.  Dynamic Typing: Syntax and Proof Theory , 1994, Sci. Comput. Program..

[43]  Thierry Coquand,et al.  Inheritance as Implicit Coercion , 1991, Inf. Comput..

[44]  Philip Wadler,et al.  Well-Typed Programs Can't Be Blamed , 2009, ESOP.

[45]  Cormac Flanagan,et al.  Unifying Hybrid Types and Contracts , 2007, Trends in Functional Programming.

[46]  Benjamin C. Pierce,et al.  All Your IFCException Are Belong to Us , 2013, 2013 IEEE Symposium on Security and Privacy.

[47]  Didier Rémy,et al.  On the power of coercion abstraction , 2012, POPL '12.

[48]  Gavin M. Bierman,et al.  A theory of typed coercions and its applications , 2009, ICFP.

[49]  Robert Bruce Findler,et al.  Contracts as Pairs of Projections , 2006, FLOPS.

[50]  Zhong Shao Flexible representation analysis , 1997, ICFP '97.

[51]  Sam Tobin-Hochstadt,et al.  The design and implementation of typed scheme , 2008, POPL '08.