Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Polymorphic Reachability Types: Tracking Freshness, Aliasing, and Separation in Higher-Order Generic Programs

Published: 05 January 2024 Publication History

Abstract

Fueled by the success of Rust, many programming languages are adding substructural features to their type systems. The promise of tracking properties such as lifetimes and sharing is tremendous, not just for low-level memory management, but also for controlling higher-level resources and capabilities. But so are the difficulties in adapting successful techniques from Rust to higher-level languages, where they need to interact with other advanced features, especially various flavors of functional and type-level abstraction. What would it take to bring full-fidelity reasoning about lifetimes and sharing to mainstream languages? Reachability types are a recent proposal that has shown promise in scaling to higher-order but monomorphic settings, tracking aliasing and separation on top of a substrate inspired by separation logic. However, naive extensions on top of the prior reachability type system λ* with type polymorphism and/or precise reachability polymorphism are unsound, making λ* unsuitable for adoption in real languages. Combining reachability and type polymorphism that is precise, sound, and parametric remains an open challenge.
This paper presents a rethinking of the design of reachability tracking and proposes new polymorphic reachability type systems. We introduce a new freshness qualifier to indicate variables whose reachability sets may grow during evaluation steps. The new system tracks variables reachable in a single step and computes transitive closures only when necessary, thus preserving chains of reachability over known variables that can be refined using substitution. These ideas yield the simply-typed λ-calculus with precise lightweight, i.e., quantifier-free, reachability polymorphism, and the F<:-calculus with bounded parametric polymorphism over types and reachability qualifiers, paving the way for making true tracking of lifetimes and sharing practical for mainstream languages. We prove type soundness and the preservation of separation property in Coq. We discuss various applications (e.g., safe capability programming), possible effect system extensions, and compare our system with Scala’s capture types.

References

[1]
Amal Ahmed, Matthew Fluet, and Greg Morrisett. 2007. L^ 3: A Linear Language with Locations. Fundam. Informaticae, 77, 4 (2007), 397–449.
[2]
Jonathan Aldrich, Joshua Sunshine, Darpan Saini, and Zachary Sparks. 2009. Typestate-oriented programming. In OOPSLA Companion. ACM, 1015–1022.
[3]
Roberto M. Amadio and Luca Cardelli. 1993. Subtyping Recursive Types. ACM Trans. Program. Lang. Syst., 15, 4 (1993), 575–631.
[4]
Nada Amin, Samuel Grütter, Martin Odersky, Tiark Rompf, and Sandro Stucki. 2016. The Essence of Dependent Object Types. In A List of Successes That Can Change the World (Lecture Notes in Computer Science, Vol. 9600). Springer, 249–272.
[5]
Thibaut Balabonski, François Pottier, and Jonathan Protzenko. 2016. The Design and Formalization of Mezzo, a Permission-Based Programming Language. ACM Trans. Program. Lang. Syst., 38, 4 (2016), 14:1–14:94.
[6]
Yuyan Bao, Guannan Wei, Oliver Bračevac, Yuxuan Jiang, Qiyang He, and Tiark Rompf. 2021. Reachability types: tracking aliasing and separation in higher-order functional programs. Proc. ACM Program. Lang., 5, OOPSLA (2021), 1–32.
[7]
Erik Barendsen and Sjaak Smetsers. 1996. Uniqueness Typing for Functional Languages with Graph Rewriting Semantics. Math. Struct. Comput. Sci., 6, 6 (1996), 579–612. https://doi.org/10.1017/S0960129500070109
[8]
Jean-Philippe Bernardy, Mathieu Boespflug, Ryan R. Newton, Simon Peyton Jones, and Arnaud Spiwack. 2018. Linear Haskell: practical linearity in a higher-order polymorphic language. Proc. ACM Program. Lang., 2, POPL (2018), 5:1–5:29.
[9]
Aleksander Boruch-Gruszecki, Jonathan Immanuel Brachthäuser, Edward Lee, Ondrej Lhoták, and Martin Odersky. 2021. Tracking Captured Variables in Types. CoRR, abs/2105.11896 (2021).
[10]
Aleksander Boruch-Gruszecki, Martin Odersky, Edward Lee, Ondřej Lhoták, and Jonathan Brachthäuser. 2023. Capturing Types. ACM Trans. Program. Lang. Syst., sep, issn:0164-0925 https://doi.org/10.1145/3618003 Just Accepted
[11]
Chandrasekhar Boyapati, Robert Lee, and Martin C. Rinard. 2002. Ownership types for safe programming: preventing data races and deadlocks. In OOPSLA. ACM, 211–230. https://doi.org/10.1145/582419.582440
[12]
John Boyland. 2003. Checking Interference with Fractional Permissions. In Static Analysis, Radhia Cousot (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 55–72. isbn:978-3-540-44898-3
[13]
Jonathan Immanuel Brachthäuser, Philipp Schuster, Edward Lee, and Aleksander Boruch-Gruszecki. 2022. Effects, capabilities, and boxes: from scope-based reasoning to type-based reasoning and back. Proc. ACM Program. Lang., 6, OOPSLA (2022), 1–30.
[14]
Jonathan Immanuel Brachthäuser, Philipp Schuster, and Klaus Ostermann. 2020. Effects as capabilities: effect handlers and lightweight effect polymorphism. Proc. ACM Program. Lang., 4, OOPSLA (2020), 126:1–126:30.
[15]
Oliver Bračevac, Guannan Wei, Songlin Jia, Supun Abeysinghe, Yuxuan Jiang, Yuyan Bao, and Tiark Rompf. 2023. Graph IRs for Impure Higher-Order Languages: Making Aggressive Optimizations Affordable with Precise Effect Dependencies. Proc. ACM Program. Lang., 7, OOPSLA2 (2023), Article 236, oct, 31 pages. https://doi.org/10.1145/3622813
[16]
Nicholas Cameron and Sophia Drossopoulou. 2009. Existential Quantification for Variant Ownership. In ESOP (Lecture Notes in Computer Science, Vol. 5502). Springer, 128–142. https://doi.org/10.1007/978-3-642-00590-9_10
[17]
Nicholas Robert Cameron. 2009. Existential Types for Variance - Java Wildcards and Ownership Types. Ph. D. Dissertation. Imperial College London, UK.
[18]
Luca Cardelli, Simone Martini, John C. Mitchell, and Andre Scedrov. 1994. An Extension of System F with Subtyping. Inf. Comput., 109, 1/2 (1994), 4–56.
[19]
David Clarke. 2003. Object Ownership and Containment. Ph. D. Dissertation. University of New South Wales.
[20]
David Clarke, James Noble, and John Potter. 2001. Simple Ownership Types for Object Containment. In ECOOP (Lecture Notes in Computer Science, Vol. 2072). Springer, 53–76. https://doi.org/10.1007/3-540-45337-7_4
[21]
Dave Clarke, Johan Östlund, Ilya Sergey, and Tobias Wrigstad. 2013. Ownership Types: A Survey. In Aliasing in Object-Oriented Programming (Lecture Notes in Computer Science, Vol. 7850). Springer, 15–58.
[22]
David Clarke, John Potter, and James Noble. 1998. Ownership Types for Flexible Alias Protection. In OOPSLA. ACM, 48–64.
[23]
Sylvan Clebsch, Sebastian Blessing, Juliana Franco, and Sophia Drossopoulou. 2015. Ownership and reference counting based garbage collection in the actor world. In ICOOOLPS’2015. ACM.
[24]
Matthew Collinson, David J. Pym, and Edmund Robinson. 2008. Bunched polymorphism. Math. Struct. Comput. Sci., 18, 6 (2008), 1091–1132. https://doi.org/10.1017/S0960129508007159
[25]
Pierre-Louis Curien and Giorgio Ghelli. 1992. Coherence of Subsumption, Minimum Typing and Type-Checking in F_≤. Math. Struct. Comput. Sci., 2, 1 (1992), 55–91.
[26]
Edsko de Vries, Rinus Plasmeijer, and David M. Abrahamson. 2006. Uniqueness Typing Redefined. In IFL (Lecture Notes in Computer Science, Vol. 4449). Springer, 181–198. https://doi.org/10.1007/978-3-540-74130-5_11
[27]
Edsko de Vries, Rinus Plasmeijer, and David M. Abrahamson. 2007. Uniqueness Typing Simplified. In IFL (Lecture Notes in Computer Science, Vol. 5083). Springer, 201–218. https://doi.org/10.1007/978-3-540-85373-2_12
[28]
Werner Dietl, Sophia Drossopoulou, and Peter Müller. 2011. Separating ownership topology and encapsulation with generic universe types. ACM Trans. Program. Lang. Syst., 33, 6 (2011), 20:1–20:62. https://doi.org/10.1145/2049706.2049709
[29]
Jana Dunfield and Neel Krishnaswami. 2022. Bidirectional Typing. ACM Comput. Surv., 54, 5 (2022), 98:1–98:38.
[30]
Ronald Garcia, Éric Tanter, Roger Wolff, and Jonathan Aldrich. 2014. Foundations of Typestate-Oriented Programming. ACM Trans. Program. Lang. Syst., 36, 4 (2014), 12:1–12:44.
[31]
Colin S. Gordon. 2020. Designing with Static Capabilities and Effects: Use, Mention, and Invariants (Pearl). In ECOOP (LIPIcs, Vol. 166). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 10:1–10:25.
[32]
Colin S. Gordon. 2021. Polymorphic Iterable Sequential Effect Systems. ACM Trans. Program. Lang. Syst., 43, 1 (2021), 4:1–4:79.
[33]
Dan Grossman, J. Gregory Morrisett, Trevor Jim, Michael W. Hicks, Yanling Wang, and James Cheney. 2002. Region-Based Memory Management in Cyclone. In PLDI. ACM, 282–293.
[34]
John Hogg. 1991. Islands: Aliasing Protection in Object-Oriented Languages. In OOPSLA. ACM, 271–285. https://doi.org/10.1145/117954.117975
[35]
Junyoung Jang, Samuel Gélineau, Stefan Monnier, and Brigitte Pientka. 2022. Mœ bius: metaprogramming using contextual types: the stage where system f can pattern match on itself. Proc. ACM Program. Lang., 6, POPL (2022), 1–27.
[36]
Ralf Jung, Jacques-Henri Jourdan, Robbert Krebbers, and Derek Dreyer. 2018. RustBelt: securing the foundations of the rust programming language. Proc. ACM Program. Lang., 2, POPL (2018), 66:1–66:34. https://doi.org/10.1145/3158154
[37]
Oleg Kiselyov, Yukiyoshi Kameyama, and Yuto Sudo. 2016. Refined Environment Classifiers - Type- and Scope-Safe Code Generation with Mutable Cells. In APLAS (Lecture Notes in Computer Science, Vol. 10017). 271–291.
[38]
Daniel Marshall, Michael Vollmer, and Dominic Orchard. 2022. Linearity and Uniqueness: An Entente Cordiale. In ESOP (Lecture Notes in Computer Science, Vol. 13240). Springer, 346–375. https://doi.org/10.1007/978-3-030-99336-8_13
[39]
Nicholas D. Matsakis and Felix S. II Klock. 2014. The Rust language. In HILT. ACM, 103–104. https://doi.org/10.1145/2663171.2663188
[40]
Peter Müller and Arnd Poetzsch-Heffter. 2000. A type system for controlling representation exposure in Java. In ECOOP Workshop on Formal Techniques for Java Programs.
[41]
Karl Naden, Robert Bocchino, Jonathan Aldrich, and Kevin Bierhoff. 2012. A type system for borrowing permissions. In POPL. ACM, 557–570. https://doi.org/10.1145/2103656.2103722
[42]
Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Contextual modal type theory. ACM Trans. Comput. Log., 9, 3 (2008), 23:1–23:49.
[43]
James Noble, Jan Vitek, and John Potter. 1998. Flexible Alias Protection. In ECOOP (Lecture Notes in Computer Science, Vol. 1445). Springer, 158–185. https://doi.org/10.1007/BFb0054091
[44]
Martin Odersky. 2023. Scala 3 Reference - Capture Checking. https://docs.scala-lang.org/scala3/reference/experimental/cc.html
[45]
Martin Odersky, Aleksander Boruch-Gruszecki, Jonathan Immanuel Brachthäuser, Edward Lee, and Ondrej Lhoták. 2021. Safer exceptions for Scala. In SCALA/SPLASH. ACM, 1–11.
[46]
Martin Odersky, Aleksander Boruch-Gruszecki, Edward Lee, Jonathan Immanuel Brachthäuser, and Ondrej Lhoták. 2022. Scoped Capabilities for Polymorphic Effects. CoRR, abs/2207.03402 (2022).
[47]
Martin Odersky, Christoph Zenger, and Matthias Zenger. 2001. Colored local type inference. In POPL. ACM, 41–53.
[48]
Peter W. O’Hearn. 2003. On bunched typing. J. Funct. Program., 13, 4 (2003), 747–796.
[49]
Peter W. O’Hearn, John Power, Makoto Takeyama, and Robert D. Tennent. 1999. Syntactic Control of Interference Revisited. Theor. Comput. Sci., 228, 1-2 (1999), 211–252. https://doi.org/10.1016/S0304-3975(98)00359-4
[50]
Peter W. O’Hearn, John C. Reynolds, and Hongseok Yang. 2001. Local Reasoning about Programs that Alter Data Structures. In CSL (Lecture Notes in Computer Science, Vol. 2142). Springer, 1–19.
[51]
Leo Osvald, Grégory M. Essertel, Xilun Wu, Lilliam I. González Alayón, and Tiark Rompf. 2016. Gentrification gone too far? affordable 2nd-class values for fun and (co-)effect. In OOPSLA. ACM, 234–251.
[52]
Lionel Parreaux, Antoine Voizard, Amir Shaikhha, and Christoph E. Koch. 2018. Unifying analytic and statically-typed quasiquotes. Proc. ACM Program. Lang., 2, POPL (2018), 13:1–13:33.
[53]
Benjamin C. Pierce. 1992. Bounded Quantification is Undecidable. In POPL. ACM Press, 305–315.
[54]
Benjamin C. Pierce. 2002. Types and programming languages. MIT Press.
[55]
Benjamin C. Pierce and David N. Turner. 2000. Local type inference. ACM Trans. Program. Lang. Syst., 22, 1 (2000), 1–44.
[56]
Alex Potanin, James Noble, Dave Clarke, and Robert Biddle. 2006. Generic ownership for generic Java. In OOPSLA. ACM, 311–324. https://doi.org/10.1145/1167473.1167500
[57]
John C. Reynolds. 1978. Syntactic Control of Interference. In POPL. ACM Press, 39–46. https://doi.org/10.1145/512760.512766
[58]
John C. Reynolds. 1988. Preliminary design of the programming language Forsythe. Tech Report, CMU-CS-88-159, Carnegie Mellon University, https://doi.org/10.1184/R1/6608582.v1
[59]
John C. Reynolds. 1989. Syntactic Control of Inference, Part 2. In ICALP (Lecture Notes in Computer Science, Vol. 372). Springer, 704–722. https://doi.org/10.1007/BFb0035793
[60]
John C. Reynolds. 2002. Separation Logic: A Logic for Shared Mutable Data Structures. In LICS. IEEE Computer Society, 55–74.
[61]
Tiark Rompf and Nada Amin. 2016. Type soundness for dependent object types (DOT). In OOPSLA. ACM, 624–641.
[62]
Gabriel Scherer and Jan Hoffmann. 2013. Tracking Data-Flow with Open Closure Types. In LPAR (Lecture Notes in Computer Science, Vol. 8312). Springer, 710–726.
[63]
Jeremy G. Siek, Michael M. Vitousek, and Jonathan D. Turner. 2012. Effects for Funargs. CoRR, abs/1201.0023 (2012).
[64]
Frederick Smith, David Walker, and J. Gregory Morrisett. 2000. Alias Types. In ESOP (Lecture Notes in Computer Science, Vol. 1782). Springer, 366–381. https://doi.org/10.1007/3-540-46425-5_24
[65]
Mads Tofte and Jean-Pierre Talpin. 1997. Region-based Memory Management. Inf. Comput., 132, 2 (1997), 109–176. https://doi.org/10.1006/inco.1996.2613
[66]
Philip Wadler. 1990. Linear Types can Change the World!. In Programming Concepts and Methods. North-Holland, 561.
[67]
Guannan Wei, Oliver Bračevac, Songlin Jia, Yuyan Bao, and Tiark Rompf. 2023. Polymorphic Reachability Types: Tracking Freshness, Aliasing, and Separation in Higher-Order Generic Programs (Extended Version). CoRR, abs/2307.13844 (2023).
[68]
Anxhelo Xhebraj, Oliver Bracevac, Guannan Wei, and Tiark Rompf. 2022. What If We Don’t Pop the Stack? The Return of 2nd-Class Values. In ECOOP (LIPIcs, Vol. 222). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 15:1–15:29.
[69]
Tian Zhao, Jason Baker, James Hunt, James Noble, and Jan Vitek. 2008. Implicit ownership types for memory management. Science of Computer Programming, 71, 3 (2008), 213–241.
[70]
Litao Zhou, Yaoda Zhou, and Bruno C. d. S. Oliveira. 2023. Recursive Subtyping for All. Proc. ACM Program. Lang., 7, POPL (2023), 1396–1425.
[71]
Yaoda Zhou, Jinxu Zhao, and Bruno C. d. S. Oliveira. 2022. Revisiting Iso-Recursive Subtyping. ACM Trans. Program. Lang. Syst., 44, 4 (2022), 24:1–24:54.

Cited By

View all
  • (2024)Functional Ownership through Fractional UniquenessProceedings of the ACM on Programming Languages10.1145/36498488:OOPSLA1(1040-1070)Online publication date: 29-Apr-2024
  • (2024)Qualifying System F<:: Some Terms and Conditions May ApplyProceedings of the ACM on Programming Languages10.1145/36498328:OOPSLA1(583-612)Online publication date: 29-Apr-2024

Index Terms

  1. Polymorphic Reachability Types: Tracking Freshness, Aliasing, and Separation in Higher-Order Generic Programs

      Recommendations

      Comments

      Information & Contributors

      Information

      Published In

      cover image Proceedings of the ACM on Programming Languages
      Proceedings of the ACM on Programming Languages  Volume 8, Issue POPL
      January 2024
      2820 pages
      EISSN:2475-1421
      DOI:10.1145/3554315
      Issue’s Table of Contents
      This work is licensed under a Creative Commons Attribution 4.0 International License.

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      Published: 05 January 2024
      Published in PACMPL Volume 8, Issue POPL

      Permissions

      Request permissions for this article.

      Check for updates

      Author Tags

      1. aliasing
      2. effects
      3. polymorphism
      4. reachability types
      5. type systems

      Qualifiers

      • Research-article

      Funding Sources

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

      • Downloads (Last 12 months)611
      • Downloads (Last 6 weeks)60
      Reflects downloads up to 05 Jan 2025

      Other Metrics

      Citations

      Cited By

      View all
      • (2024)Functional Ownership through Fractional UniquenessProceedings of the ACM on Programming Languages10.1145/36498488:OOPSLA1(1040-1070)Online publication date: 29-Apr-2024
      • (2024)Qualifying System F<:: Some Terms and Conditions May ApplyProceedings of the ACM on Programming Languages10.1145/36498328:OOPSLA1(583-612)Online publication date: 29-Apr-2024

      View Options

      View options

      PDF

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Login options

      Full Access

      Media

      Figures

      Other

      Tables

      Share

      Share

      Share this Publication link

      Share on social media