Nested refinements: a logic for duck typing

Programs written in dynamic languages make heavy use of features --- run-time type tests, value-indexed dictionaries, polymorphism, and higher-order functions --- that are beyond the reach of type systems that employ either purely syntactic or purely semantic reasoning. We present a core calculus, System D, that merges these two modes of reasoning into a single powerful mechanism of nested refinement types wherein the typing relation is itself a predicate in the refinement logic. System D coordinates SMT-based logical implication and syntactic subtyping to automatically typecheck sophisticated dynamic language programs. By coupling nested refinements with McCarthy's theory of finite maps, System D can precisely reason about the interaction of higher-order functions, polymorphism, and dictionaries. The addition of type predicates to the refinement logic creates a circularity that leads to unique technical challenges in the metatheory, which we solve with a novel stratification approach that we use to prove the soundness of System D.

[1]  Tian Zhao Type Inference for Scripting languages with Implicit Extension , 2010 .

[2]  Sorin Lerner,et al.  Staged information flow for javascript , 2009, PLDI '09.

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

[4]  Ranjit Jhala,et al.  Low-level liquid types , 2010, POPL '10.

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

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

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

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

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

[10]  Henny B. Sipma,et al.  What's Decidable About Arrays? , 2006, VMCAI.

[11]  Pierre Castéran,et al.  Interactive Theorem Proving and Program Development , 2004, Texts in Theoretical Computer Science An EATCS Series.

[12]  Jeffrey S. Foster,et al.  Static type inference for Ruby , 2009, SAC '09.

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

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

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

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

[17]  Avik Chaudhuri,et al.  Dynamic inference of static types for ruby , 2011, POPL '11.

[18]  Margus Veanes,et al.  An Evaluation of Automata Algorithms for String Analysis , 2011, VMCAI.

[19]  Peter Thiemann Towards a Type System for Analyzing JavaScript Programs , 2005, ESOP.

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

[21]  Sophia Drossopoulou,et al.  Towards Type Inference for JavaScript , 2005, ECOOP.

[22]  Didier Rémy,et al.  Type checking records and variants in a natural extension of ML , 1989, POPL '89.

[23]  Robert E. Shostak,et al.  Deciding Combinations of Theories , 1982, JACM.

[24]  Greg Nelson,et al.  Simplification by Cooperating Decision Procedures , 1979, TOPL.

[25]  Frank Pfenning,et al.  Practical refinement-type checking , 2005 .

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

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

[28]  Shuvendu K. Lahiri,et al.  Unifying type checking and property checking for low-level code , 2009, POPL '09.

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

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

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

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

[33]  Yves Bertot,et al.  Interactive Theorem Proving and Program Development: Coq'Art The Calculus of Inductive Constructions , 2010 .

[34]  Peter Thiemann,et al.  Recency Types for Analyzing Scripting Languages , 2010, ECOOP.

[35]  Shriram Krishnamurthi,et al.  Typing Local Control and State Using Flow Analysis , 2011, ESOP.

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

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

[38]  B. Pierce,et al.  On Decidability of Nominal Subtyping with Variance , 2006 .

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