skip to main content
research-article

Optimal inference of fields in row-polymorphic records

Published:09 June 2014Publication History
Skip Abstract Section

Abstract

Flexible records are a powerful concept in type systems that form the basis of, for instance, objects in dynamically typed languages. One caveat of using flexible records is that a program may try to access a record field that does not exist. We present a type inference algorithm that checks for these runtime errors. The novelty of our algorithm is that it satisfies a clear notion of completeness: The inferred types are optimal in the sense that type annotations cannot increase the set of typeable programs. Under certain assumptions, our algorithm guarantees the following stronger property: it rejects a program if and only if it contains a path from an empty record to a field access on which the field has not been added. We derive this optimal algorithm by abstracting a semantics to types. The derived inference rules use a novel combination of type terms and Boolean functions that retains the simplicity of unification-based type inference but adds the ability of Boolean functions to express implications, thereby addressing the challenge of combining implications and types. By following our derivation method, we show how various operations such as record concatenation and branching if a field exists lead to Boolean satisfiability problems of different complexity. Analogously, we show that more expressive type systems give rise to SMT problems. On the practical side, we present an implementation of the select and update operations and give practical evidence that these are sufficient in real-world applications.

References

  1. J. Brauer, A. King, and J. Kriener. Existential Quantification as Incremental SAT. In G. Gopalakrishnan and S. Qadeer, editors, Computer Aided Verification, LNCS, page 16. Springer, July 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. L. Cardelli and J. C. Mitchell. Operations on Records. In Mathematical Structures in Computer Science, volume 1, pages 3--48, 1991.Google ScholarGoogle ScholarCross RefCross Ref
  3. P. Cousot. Types as Abstract Interpretations. In Principles of Programming Languages, pages 316--331, Paris, France, Jan. 1997. ACM. invited paper. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. P. Cousot and R. Cousot. Static Determination of Dynamic Properties of Programs. In B. Robinet, editor, International Symposium on Programming, pages 106--130, Paris, France, Apr. 1976.Google ScholarGoogle Scholar
  5. P. Cousot and R. Cousot. Systematic Design of Program Analysis Frameworks. In Principles of Programming Languages, pages 269--282, San Antonio, Texas, USA, Jan. 1979. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. L. Damas and R. Milner. Principal Type-Schemes for Functional Programs. In Principles of Programming Languages, pages 207--212, Albuquerque, New Mexico, USA, 1982. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. W. F. Dowling and J. H. Gallier. Linear-Time Algorithms for Testing the Satisfiability of Propositional Horn Formulae. J. Log. Program., 1 (3):267--284, 1984.Google ScholarGoogle ScholarCross RefCross Ref
  8. R. Giacobazzi, F. Ranzato, and F. Scozzari. Making abstract interpretations complete. Journal of the ACM, 47(2):361--416, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. K. Glynn, P. J. Stuckey, and M. Sulzmann. Boolean Constraints for Binding-time Analysis. In Programs as Data Objects, number 2053 in LNCS, pages 39--62. Springer, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. R. Gori and G. Levi. An Experiment in Type Inference and Verification by Abstract Interpretation. In A. Cortesi, editor, Verification, Model Checking, and Abstract Interpretation, volume 2294 of LNCS, pages 237--241, Venice, Italy, Jan. 2002. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. A. Igarashi, B. C. Pierce, and P. Wadler. Featherweight Java: a minimal core calculus for Java and GJ. ACM Transactions on Programming Languages and Systems, 23(3):396--450, May 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. T. Jim. What are principal typings and what are they good for? In Principles of Programming Languages, pages 42--53, St. Petersburg Beach, Florida, USA, 1996. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. A. Kfoury, J. Tiuryn, and P. Urzyczyn. The Undecidability of the Semi-unification Problem. Information and Computation, 102(1):83--101, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. J.-L. Lassez, M. J. Maher, and K. Marriott. Unification Revisited. In M. Boscarol, L. C. Aiello, and G. Levi, editors, Foundations of Logic and Functional Programming, volume 306 of LNCS, pages 67--113, Trento, Italy, Dec. 1986. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. R. Milner. A Theory of Type Polymorphism in Programming. Journal of Computer and System Sciences, 17(3):348--375, 1978.Google ScholarGoogle ScholarCross RefCross Ref
  16. A. Mycroft. Polymorphic Type Schemes and Recursive Definitions. In M. Paul and B. Robinet, editors, Symposium on Programming, volume 167 of LNCS, pages 217--228, Toulouse, France, Apr. 1984. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. M. Odersky, M. Sulzmann, and M. Wehr. Type Inference with Constrained Types. Theory and Practice of Object Systems, 5(1):35--55, Jan. 1999. ISSN 1074-3227. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. F. Pottier. A Versatile Constraint-Based Type Inference System. Nordic Journal of Computing, 7(4):312--347, Nov. 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. D. Rémy. Type Inference for Records in a Natural Extension of ML. In C. A. Gunter and J. C. Mitchell, editors, Theoretical Aspects Of Object-Oriented Programming. Types, Semantics and Language Design. MIT Press, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. E. Robbins, A. King, and H. Jacob. Theory Propagation and Rational-Trees. In T. Schrijvers, editor, Principles and Practice of Declarative Programming, pages 193--204, Madrid, Spain, 2013. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. D. A. Schmidt. Comparing Completeness Properties of Static Analyses and Their Logics. In N. Kobayashi, editor, Asian Symposium on Programming Languages and Systems, volume 4279 of LNCS, pages 183--199, Sydney, Australia, Nov. 2006. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. T. Schrijvers, S. Peyton-Jones, M. Sulzmann, and D. Vytiniotis. Complete and Decidable Type Inference for GADTs. In International Conference on Functional programming, pages 341--352, Edinburgh, UK, Sept. 2009. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. A. Simon. Deriving a Complete Type Inference for Hindley-Milner and Vector Sizes using Expansion. Science of Computer Programming, 2014.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. A. Simon. Optimal Inference of Fields in Row-Polymorphic Records (proof appendix). Technical report, TU Munich, June 2014.Google ScholarGoogle Scholar
  25. A. Simon and J. Kranz. The GDSL toolkit: Generating Frontends for the Analysis of Machine Code. In Program Protection and Reverse Engineering Workshop, San Diego, California, USA, Jan. 2014. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. V. Simonet and F. Pottier. A Constraint-Based Approach to Guarded Algebraic Data Types. Transactions on Programming Languages and Systems, 29(1), Jan. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. D. Vytiniotis, S. L. Peyton Jones, and T. Schrijvers. Let Should not be Generalized. In A. Kennedy and N. Benton, editors, Types in Languages Design and Implementation, pages 39--50, Madrid, Spain, Jan. 2010. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. J. B. Wells. The Essence of Principal Typings. In P. Widmayer, F. T. Ruiz, R. M. Bueno, M. Hennessy, S. Eidenbenz, and R. Conejo, editors, Colloquium on Automata, Languages and Programming, volume 2380 of LNCS, pages 913--925, Malaga, Spain, July 2002. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Optimal inference of fields in row-polymorphic records

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Article Metrics

              • Downloads (Last 12 months)10
              • Downloads (Last 6 weeks)3

              Other Metrics

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!