skip to main content
research-article
Open Access

Relational nullable types with Boolean unification

Published:15 October 2021Publication History
Skip Abstract Section

Abstract

We present a simple, practical, and expressive relational nullable type system. A relational nullable type system captures whether an expression may evaluate to null based on its type, but also based on the type of other related expressions. The type system extends the Hindley-Milner type system with Boolean constraints, supports parametric polymorphism, and preserves principal types modulo Boolean equivalence. We show how to support full Hindley-Milner style type inference with an extension of Algorithm W.

We conduct a preliminary study of open source projects showing that there is a need for relational nullable type systems across a wide range of programming languages. The most important findings from the study are: (i) programmers use programming patterns where the nullability of one expression depends on the nullability of other related expressions, (ii) such invariants are commonly enforced with run-time exceptions, and (iii) reasoning about these programming patterns requires not only knowledge of when an expression may evaluate to null, but also when it may evaluate to a non-null value. We incorporate these observations in the design of the proposed relational nullable type system.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

This is a presentation of the work Relational Nullable Types with Boolean Unification by Magnus Madsen and Jaco van de Pol.

References

  1. Nada Amin and Ross Tate. 2016. Java and Scala’s Type Systems are Unsound: the Existential Crisis of Null Pointers. Proc. Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Franz Baader. 1998. On the Complexity of Boolean Unification. Inform. Process. Lett.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Subarno Banerjee, Lazaro Clapp, and Manu Sridharan. 2019. Nullaway: Practical Type-based Null Safety for Java. In Proc. Joint Symposium on European Software Engineering and the Foundations of Software Engineering (ESEC/FSE). Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. George Boole. 1847. The mathematical analysis of logic.Google ScholarGoogle Scholar
  5. Alexandre Boudet, Jean-Pierre Jouannaud, and Manfred Schmidt-Schauß. 1989. Unification in Boolean Rings and Abelian Groups. Journal of Symbolic Computation. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Dan Brotherston, Werner Dietl, and Ondřej Lhoták. 2017. Granullar: Gradual Nullable Types for Java. In Proc. International Conference on Compiler Construction (CC). Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Wolfram Buttner and Helmut Simonis. 1987. Embedding Boolean Expressions into Logic Programming. Journal of Symbolic Computation. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Patrice Chalin and Perry R James. 2007. Non-Null References by Default in Java: Alleviating the Nullity Annotation Burden. In Proc. European Conference on Object-Oriented Programming (ECOOP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Olaf Chitil. 2001. Compositional explanation of types and algorithmic debugging of type errors. In Proc. International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Luis Damas. 1984. Type Assignment in Programming Languages. Ph. D. Dissertation. The University of Edinburgh.Google ScholarGoogle Scholar
  11. Manuel Fähndrich and K Rustan M Leino. 2003. Declaring and Checking Non-Null Types in an Object-Oriented Language. In Proc. Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Manuel Fähndrich and Songtao Xia. 2007. Establishing Object Invariants with Delayed Types. In Proc. Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Roger Hindley. 1969. The Principal Type-scheme of an Object in Combinatory Logic. Transactions of the American Mathematical Society (AMS).Google ScholarGoogle Scholar
  14. Laurent Hubert, Thomas Jensen, and David Pichardie. 2008. Semantic Foundations and Inference of Non-Null Annotations. In International Conference on Formal Methods for Open Object-Based Distributed Systems (FMOODS). Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Mark P Jones. 2003. Qualified Types: Theory and Practice. Cambridge University Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Leopold Löwenheim. 1908. Über das Auflösungsproblem im logischen Klassenkalkul.Google ScholarGoogle Scholar
  17. Magnus Madsen and Ondřej Lhoták. 2018. Safe and Sound Program Analysis with Flix. In Proc. International Symposium on Software Testing and Analysis (ISSTA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Magnus Madsen and Ondřej Lhoták. 2020. Fixpoints for the Masses: Programming with first-class Datalog Constraints. Proc. of the ACM on Programming Languages, 4, OOPSLA (2020). Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Magnus Madsen and Jaco van de Pol. 2020. Polymorphic Types and Effects with Boolean Unification. Proc. of the ACM on Programming Languages, 4, OOPSLA (2020). Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Magnus Madsen, Ming-Ho Yee, and Ondrej Lhoták. 2016. From Datalog to Flix: A Declarative Language for Fixed Points on Lattices. In Proc. Programming Language Design and Implementation (PLDI). Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Chris Male, David J Pearce, Alex Potanin, and Constantine Dymnikov. 2008. Java Bytecode Verification for NonNull Types. In Proc. International Conference on Compiler Construction (CC). Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Alberto Martelli and Ugo Montanari. 1982. An efficient unification algorithm. ACM Transactions on Programming Languages and Systems (TOPLAS). Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Urusula Martin and Tobias Nipkow. 1989. Boolean Unification - The Story So Far. Journal of Symbolic Computation. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. System Sci..Google ScholarGoogle Scholar
  25. Abel Nieto, Marianna Rapoport, Gregor Richards, and Ondřej Lhoták. 2020. Blame for Null. In Proc. European Conference on Object-Oriented Programming (ECOOP 2020).Google ScholarGoogle Scholar
  26. Abel Nieto, Yaoyu Zhao, Ondřej Lhoták, Angela Chang, and Justin Pu. 2020. Scala with Explicit Nulls. In Proc. European Conference on Object-Oriented Programming (ECOOP 2020).Google ScholarGoogle Scholar
  27. Benjamin C Pierce and David N Turner. 2000. Local type inference. ACM Transactions on Programming Languages and Systems (TOPLAS). Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Xin Qi and Andrew C Myers. 2009. Masked Types for Sound Object Initialization. In Proc. Principles of Programming Languages (POPL). Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Patrick M Rondon, Ming Kawaguci, and Ranjit Jhala. 2008. Liquid types. In Proc. Programming Language Design and Implementation (PLDI). Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Sergiu Rudeanu. 1974. Boolean Functions and Equations.Google ScholarGoogle Scholar
  31. Fausto Spoto. 2008. Nullness Analysis in Boolean Form. In Proc. International Conference on Software Engineering and Formal Methods (SEFM). Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Alexander J Summers and Peter Müller. 2011. Freedom Before Commitment: A Lightweight Type System for Object Initialisation. In Proc. Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Sam Tobin-Hochstadt and Matthias Felleisen. 2010. Logical types for untyped languages. In Proc. International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Mads Tofte and Jean-Pierre Talpin. 1997. Region-based Memory Management. Information and Computation. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Niki Vazou, Eric L Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon Peyton-Jones. 2014. Refinement types for Haskell. In Proc. International Conference on Functional Programming (ICFP). Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Philip Wadler and Stephen Blott. 1989. How to make ad-hoc polymorphism less ad hoc. In Proc. Symposium on Principles of Programming Languages (POPL). Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Andrew K Wright and Matthias Felleisen. 1994. A Syntactic Approach to Type Soundness. Information and Computation. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Relational nullable types with Boolean unification

    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

    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!