Semantic subtyping with an SMT solver

We study a first-order functional language with the novel combination of the ideas of refinement type (the subset of a type to satisfy a Boolean expression) and type-test (a Boolean expression testing whether a value belongs to a type). Our core calculus can express a rich variety of typing idioms; for example, intersection, union, negation, singleton, nullable, variant, and algebraic types are all derivable. We formulate a semantics in which expressions denote terms, and types are interpreted as first-order logic formulas. Subtyping is defined as valid implication between the semantics of types. The formulas are interpreted in a specific model that we axiomatize using standard first-order theories. On this basis, we present a novel type-checking algorithm able to eliminate many dynamic tests and to detect many errors statically. The key idea is to rely on an SMT solver to compute subtyping efficiently. Moreover, interpreting types as formulas allows us to call the SMT solver at run-time to compute instances of types.

[1]  Philip Wadler,et al.  Comprehending monads , 1990, LISP and Functional Programming.

[2]  Yitzhak Mandelbaum,et al.  The next 700 data description languages , 2010 .

[3]  Benjamin C. Pierce,et al.  Mechanized Metatheory for the Masses: The PoplMark Challenge , 2005, TPHOLs.

[4]  J W Ballard,et al.  Data on the web? , 1995, Science.

[5]  Andrew D. Gordon,et al.  Refinement Types for Secure Implementations , 2008, 2008 21st IEEE Computer Security Foundations Symposium.

[6]  Peter Buneman,et al.  Union Types for Semistructured Data , 1999, DBPL.

[7]  Alexander Aiken,et al.  Soft typing with conditional types , 1994, POPL '94.

[8]  L. D. Moura,et al.  The YICES SMT Solver , 2006 .

[9]  Andrew D. Gordon,et al.  An advisor for web services security policies , 2005, SWS '05.

[10]  Michael J. Maher,et al.  Constraint Logic Programming: A Survey , 1994, J. Log. Program..

[11]  Bengt Nordström,et al.  Types and Specifications , 1983, IFIP Congress.

[12]  Burkhart Wolff,et al.  HOL-Boogie - An Interactive Prover for the Boogie Program-Verifier , 2008, TPHOLs.

[13]  Philip Wadler,et al.  The essence of XML , 2003, POPL '03.

[14]  John McCarthy,et al.  Towards a Mathematical Science of Computation , 1962, IFIP Congress.

[15]  Rod M. Burstall,et al.  HOPE: An experimental applicative language , 1980, LISP Conference.

[16]  Giuseppe Castagna,et al.  Semantic subtyping: Dealing set-theoretically with function, union, intersection, and negation types , 2008, JACM.

[17]  Natarajan Shankar,et al.  Subtypes for Specifications: Predicate Subtyping in PVS , 1998, IEEE Trans. Software Eng..

[18]  Gavin M. Bierman,et al.  Lost in translation: formalizing proposed extensions to c# , 2007, OOPSLA.

[19]  Jürgen Giesl Termination of Nested and Mutually Recursive Algorithms , 2004, Journal of Automated Reasoning.

[20]  Stephen N. Freund,et al.  Sage: Unified Hybrid Checking for First-Class Types, General Refinement Types, and Dynamic (Extended Report) , 2007 .

[21]  Brian Beckman,et al.  LINQ: reconciling object, relations and XML in the .NET framework , 2006, SIGMOD Conference.

[22]  José-Luis Ruiz-Reina,et al.  Efficient execution in an automated reasoning environment , 2008, J. Funct. Program..

[23]  Bor-Yuh Evan Chang,et al.  Boogie: A Modular Reusable Verifier for Object-Oriented Programs , 2005, FMCO.

[24]  Lawrence C. Paulson,et al.  Translating Higher-Order Clauses to First-Order Clauses , 2007, Journal of Automated Reasoning.

[25]  Juan Chen,et al.  Enforcing Stateful Authorization and Information Flow Policies in Fine , 2010, ESOP.

[26]  Frank Pfenning,et al.  Dependent types in practical programming , 1999, POPL '99.

[27]  Jens Palsberg,et al.  Constrained types for object-oriented languages , 2008, OOPSLA.

[28]  Joshua Dunfield,et al.  A unified system of type refinements , 2007 .

[29]  Andrew D. Gordon,et al.  Typing One-to-One and One-to-Many Correspondences in Security Protocols , 2002, ISSS.

[30]  B. Pierce Programming with intersection types, union types, and polymorphism , 1991 .

[31]  Ruzica Piskac,et al.  Complete functional synthesis , 2010, PLDI '10.

[32]  Matthieu Sozeau,et al.  Subset Coercions in Coq , 2006, TYPES.

[33]  Giuseppe Castagna,et al.  Patterns and Types for Querying XML Documents , 2005, DBPL.

[34]  Luca Cardelli,et al.  Deciding validity in a spatial logic for trees , 2005, J. Funct. Program..

[35]  James Cheney,et al.  Provenance as dependency analysis† , 2007, Mathematical Structures in Computer Science.

[36]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[37]  Nikolaj Bjørner,et al.  Efficient E-Matching for SMT Solvers , 2007, CADE.

[38]  Albert Oliveras,et al.  Design and Results of the 3rd Annual Satisfiability Modulo Theories Competition (SMT-Comp 2007) , 2008, Int. J. Artif. Intell. Tools.

[39]  Gang Chen,et al.  Dependent Types with Subtyping and Late-Bound Overloading , 2001, Inf. Comput..

[40]  Vaughan R. Pratt,et al.  Five paradigm shifts in programming language design and their realization in Viron, a dataflow programming environment , 1983, POPL '83.

[41]  Robert Cartwright,et al.  Soft typing , 1991, PLDI '91.

[42]  Benjamin C. Pierce,et al.  Local type inference , 1998, POPL '98.

[43]  Flemming M. Damm,et al.  Subtyping with Union Types, Intersection Types and Recursive Types , 1994, TACS.

[44]  Limsoon Wong,et al.  Principles of Programming with Complex Objects and Collection Types , 1995, Theor. Comput. Sci..

[45]  Cliff B. Jones,et al.  Systematic software development using VDM , 1986, Prentice Hall International Series in Computer Science.

[46]  Sara Cohen,et al.  User-defined aggregate functions: bridging theory and practice , 2006, SIGMOD Conference.

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

[48]  Tachio Terauchi Dependent types from counterexamples , 2010, POPL '10.

[49]  S Vadera Systematic software development using VDM , 1986 .

[50]  Pierre Genevès,et al.  Efficient static analysis of XML paths and types , 2007, PLDI '07.

[51]  Sam Tobin-Hochstadt,et al.  Logical types for untyped languages , 2010, ICFP '10.

[52]  Ranjit Jhala,et al.  Type-based data structure verification , 2009, PLDI '09.

[53]  Satish Chandra,et al.  Dependent Types for Program Understanding , 2005, TACAS.

[54]  Andrew D. Gordon,et al.  Proceedings of the 21st IEEE Computer Security Foundations Symposium, CSF 2008, Pittsburgh, Pennsylvania, USA, 23-25 June 2008 , 2008, CSF.

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

[56]  Rupak Majumdar,et al.  State of the Union: Type Inference Via Craig Interpolation , 2007, TACAS.

[57]  C. Tinelli,et al.  The SMT-LIB Standard : Version 1 . 0 Working Draft , 2004 .

[58]  Michael Backes,et al.  Automatically Verifying Typing Constraints for a Data Processing Language , 2011, CPP.

[59]  Nikolaj Bjørner,et al.  Generalized, efficient array decision procedures , 2009, 2009 Formal Methods in Computer-Aided Design.

[60]  Rupak Majumdar,et al.  HMC: Verifying Functional Programs Using Abstract Interpreters , 2011, CAV.

[61]  Naoki Kobayashi,et al.  Dependent type inference with interpolants , 2009, PPDP '09.

[62]  Cesare Tinelli,et al.  The SMT-LIB Standard: Version 1.2 , 2005 .

[63]  Lawrence C. Paulson,et al.  Translating higher-order problems to first-order clauses , 2006 .

[64]  Kenneth Knowles,et al.  Hybrid type checking , 2010, TOPL.

[65]  Giuseppe Castagna,et al.  CDuce: an XML-centric general-purpose language , 2003, ICFP '03.

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

[67]  David Detlefs,et al.  Simplify: a theorem prover for program checking , 2005, JACM.

[68]  Nikolaj Bjørner,et al.  Z3: An Efficient SMT Solver , 2008, TACAS.

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

[70]  Frank Pfenning,et al.  Tridirectional typechecking , 2004, POPL.

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

[72]  Dan Grossman,et al.  Searching for type-error messages , 2007, PLDI '07.

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

[74]  Alexei Kopylov,et al.  Dependent intersection: a new way of defining records in type theory , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[75]  Benjamin C. Pierce,et al.  Regular expression types for XML , 2005, ACM Trans. Program. Lang. Syst..

[76]  Robert S. Boyer,et al.  The Boyer-Moore theorem prover and its interactive enhancement , 1995 .

[77]  John C. Reynolds,et al.  Design of the programming language FORSYTHE , 1997 .

[78]  Benjamin C. Pierce,et al.  XDuce: A statically typed XML processing language , 2003, TOIT.

[79]  K. Rustan M. Leino,et al.  Reasoning about comprehensions with first-order SMT solvers , 2009, SAC '09.

[80]  James C. King,et al.  Symbolic execution and program testing , 1976, CACM.

[81]  Douglas Crockford,et al.  The application/json Media Type for JavaScript Object Notation (JSON) , 2006, RFC.

[82]  Paul Anderson,et al.  Towards a High-Level Machine Configuration System , 1994, LISA.

[83]  David Aspinall,et al.  Subtyping with Singleton Types , 1994, CSL.

[84]  Frank Pfenning,et al.  A Bidirectional Refinement Type System for LF , 2007, LFMTP@CADE.

[85]  David E. Langworthy,et al.  The Oslo Modeling Language: Draft Specification - October 2008 , 2008 .

[86]  Alexander Aiken,et al.  Type inclusion constraints and type inference , 1993, FPCA '93.

[87]  Mark Burgess,et al.  A System Engineer's Guide to Host Configuration and Maintenance Using Cfengine , 2007, Short Topics in System Administration.

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