ABSTRACT
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.
Supplemental Material
- M. Abadi, L. Cardelli, B. C. Pierce, and G. Plotkin. Dynamic typing in a statically-typed language. In POPL, 1989. Google ScholarDigital Library
- J.-h. D. An, A. Chaudhuri, J. S. Foster, and M. Hicks. Dynamic inference of static types for ruby. In POPL, 2011. Google ScholarDigital Library
- C. Anderson, S. Drossopoulou, and P. Giannini. Towards Type Inference for JavaScript. In ECOOP, pages 428--452, June 2005. Google ScholarDigital Library
- J. Bengtson, K. Bhargavan, C. Fournet, A. Gordon, and S. Maffeis. Refinement types for secure implementations. In CSF, 2008. Google ScholarDigital Library
- Y. Bertot and P. Castéran. Interactive theorem proving and program development. coq'art: The calculus of inductive constructions, 2004. Google ScholarDigital Library
- G. M. Bierman, A. D. Gordon, C. Hritcu, and D. E. Langworthy. Semantic subtyping with an smt solver. In ICFP, 2010. Google ScholarDigital Library
- A. R. Bradley, Z. Manna, and H. B. Sipma. What's decidable about arrays? In VMCAI, pages 427--442, 2006. Google ScholarDigital Library
- R. Chugh, P. M. Rondon, and R. Jhala. Nested refinements: A logic for duck typing. http://arxiv.org/abs/1103.5055v2.Google Scholar
- R. Chugh, J. A. Meister, R. Jhala, and S. Lerner. Staged information flow for javascript. In Proceedings of PLDI 2009, pages 50--62, 2009. Google ScholarDigital Library
- J. Condit, B. Hackett, S. K. Lahiri, and S. Qadeer. Unifying type checking and property checking for low-level code. In POPL, 2009. Google ScholarDigital Library
- R. Davies. Practical Refinement-Type Checking. PhD thesis, Carnegie Mellon University, Pittsburgh, PA, USA, 2005. Google ScholarDigital Library
- L. de Moura and N. Bjørner. Z3: An efficient SMT solver. In TACAS, 2008. Google ScholarDigital Library
- L. de Moura and N. Bjørner. Generalized, efficient array decision procedures. In FMCAD, pages 45--52, 2009.Google ScholarCross Ref
- J. Dunfield. A Unified System of Type Refinements. PhD thesis, Carnegie Mellon University, Pittsburgh, PA, USA, 2007.Google Scholar
- R. B. Findler and M. Felleisen. Contracts for higher-order functions. In ICFP, pages 48--59, 2002. Google ScholarDigital Library
- C. Flanagan. Hybrid type checking. In POPL. ACM, 2006. Google ScholarDigital Library
- M. Furr, J. hoon (David) An, J. S. Foster, and M. W. Hicks. Static type inference for ruby. In SAC, pages 1859--1866, 2009. Google ScholarDigital Library
- A. Guha, C. Softoiu, and S. Krishnamurthi. Typing local control and state using flow analysis. In ESOP, 2011. Google ScholarDigital Library
- P. Heidegger and P. Thiemann. Recency types for analyzing scripting languages. In ECOOP, pages 200--224, 2010. Google ScholarDigital Library
- P. Hooimeijer and M. Veanes. An evaluation of automata algorithms for string analysis. In VMCAI, pages 248--262, 2011. Google ScholarDigital Library
- R. Jhala, R. Majumdar, and R.-G. Xu. State of the union: Type inference via craig interpolation. In TACAS, 2007. Google ScholarDigital Library
- A. J. Kennedy and B. C. Pierce. On decidability of nominal subtyping with variance. In FOOL-WOOD, 2007.Google Scholar
- K. Knowles and C. Flanagan. Hybrid type checking. ACM TOPLAS, 32 (2), 2010. Google ScholarDigital Library
- R. Komondoor, G. Ramalingam, S. Chandra, and J. Field. Dependent types for program understanding. In TACAS, pages 157--173, 2005. Google ScholarDigital Library
- J. McCarthy. Towards a mathematical science of computation. In In IFIP Congress, pages 21--28. North-Holland, 1962.Google Scholar
- G. Nelson and D. C. Oppen. Simplification by cooperating decision procedures. TOPLAS, 1979. Google ScholarDigital Library
- X. Ou, G. Tan, Y. Mandelbaum, and D. Walker. Dynamic typing with dependent types. In IFIP TCS, pages 437--450, 2004.Google ScholarCross Ref
- J. Palsberg and M. I. Schwartzbach. OO Type Systems. Wiley, 1994.Google Scholar
- B. C. Pierce and D. N. Turner. Local type inference. In POPL, pages 252--265, 1998. Google ScholarDigital Library
- D. Rémy. Type checking records and variants in a natural extension of ml. In POPL, 1989. Google ScholarDigital Library
- P. Rondon, M. Kawaguchi, and R. Jhala. Liquid types. In PLDI, 2008. Google ScholarDigital Library
- P. Rondon, M. Kawaguchi, and R. Jhala. Low-level liquid types. In POPL, pages 131--144, 2010. Google ScholarDigital Library
- R. Shostak. Deciding combinations of theories. Journal of the ACM, 31 (1): 1--12, 1984. Google ScholarDigital Library
- J. Siek and W. Taha. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, 2006.Google Scholar
- N. Swamy, J. Chen, and R. Chugh. Enforcing stateful authorization and information flow policies in fine. In ESOP, 2010. Google ScholarDigital Library
- The Dojo Foundation. Dojo toolkit. http://dojotoolkit.org/.Google Scholar
- }python-32The Python Software Foundation. Python 3.2 standard library. http://python.org/.Google Scholar
- P. Thiemann. Towards a type system for analyzing javascript programs. In ESOP, 2005. Google ScholarDigital Library
- S. Tobin-Hochstadt and M. Felleisen. Logical types for untyped languages. In ICFP, pages 117--128, 2010. Google ScholarDigital Library
- H. Xi and F. Pfenning. Dependent types in practical programming. In POPL, 1999. Google ScholarDigital Library
- T. Zhao. Type inference for scripting languages with implicit extension. In FOOL, 2010.Google Scholar
Index Terms
- Nested refinements: a logic for duck typing
Recommendations
Nested refinements: a logic for duck typing
POPL '12Programs 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 ...
Temporal Refinements for Guarded Recursive Types
Programming Languages and SystemsAbstractWe propose a logic for temporal properties of higher-order programs that handle infinite objects like streams or infinite trees, represented via coinductive types. Specifications of programs use safety and liveness properties. Programs can then be ...
Sums of uncertainty: refinements go gradual
POPL '17A long-standing shortcoming of statically typed functional languages is that type checking does not rule out pattern-matching failures (run-time match exceptions). Refinement types distinguish different values of datatypes; if a program annotated with ...
Comments