Rust-like borrowing with 2nd-class values (short paper)

The Rust programming language demonstrates that memory safety can be achieved in a practical systems language, based on a sophisticated type system that controls object lifetimes and aliasing through notions of ownership and borrowing. While Scala has traditionally targeted only managed language runtimes, the ScalaNative effort makes Scala a viable low-level language as well. Thus, memory safety becomes an important concern, and the question bears asking what, if anything, Scala can learn from Rust. In addition, Rust's type system can encode forms of protocols, state machines, and session types, which would also be useful for Scala in general. A key challenge is that Rust's typing rules are inherently flow-sensitive, but Scala's type system is not. In this paper, we sketch one possible method of achieving static guarantees similar to Rust with only mild extensions to Scala's type system. Our solution is based on two components: First, the observation that continuation passing style (CPS) or monadic style can transform a flow-sensitive checking problem into a type-checking problem based on scopes. Second, on a previously presented type system extension with second-class values, which we use to model scope-based lifetimes.

[1]  Craig Chambers,et al.  Alias annotations for program understanding , 2002, OOPSLA '02.

[2]  Joel Moses The function of FUNCTION in LISP or why the FUNARG problem should be called the environment problem , 1970, SIGS.

[3]  John Hogg,et al.  Islands: aliasing protection in object-oriented languages , 1991, OOPSLA '91.

[4]  Martin Odersky,et al.  Scala-virtualized , 2012, PEPM '12.

[5]  James Noble,et al.  Ownership types for flexible alias protection , 1998, OOPSLA '98.

[6]  Eugene Burmako,et al.  Scala macros: let our powers combine!: on how rich syntax and static types work with metaprogramming , 2013, SCALA@ECOOP.

[7]  David A. Schmidt,et al.  Stackability in the Simply-Typed Call-by-Value lambda Calculus , 1998, Sci. Comput. Program..

[8]  Martin Odersky,et al.  Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform , 2009, ICFP.

[9]  C. Bambi,et al.  Fundamental Concepts , 2018, Tutorial Guide to X-ray and Gamma-ray Astronomy.

[10]  Sophia Drossopoulou,et al.  Generic Universe Types , 2007, ECOOP.

[11]  Peter Müller,et al.  Ownership transfer in universe types , 2007, OOPSLA.

[12]  Tobias Wrigstad,et al.  Ownership-Based Alias Managemant , 2006 .

[13]  Walid Taha,et al.  Environment classifiers , 2003, POPL.

[14]  Dave Clarke,et al.  External Uniqueness Is Unique Enough , 2003, ECOOP.

[15]  Eric C. Reed Patina : A Formalization of the Rust Programming Language , 2015 .

[16]  John Hannan A Type-Based Escape Analysis for Functional Languages , 1998, J. Funct. Program..

[17]  David A. Schmidt,et al.  Stackability in the Simply-Typed Call-by-Value lambda Calculus , 1998, Sci. Comput. Program..

[18]  Derek Dreyer,et al.  RustBelt: securing the foundations of the rust programming language , 2017, Proc. ACM Program. Lang..

[19]  Jonathan Aldrich,et al.  A type system for borrowing permissions , 2012, POPL '12.

[20]  Éric Tanter,et al.  Beyond static and dynamic scope , 2009, DLS '09.

[21]  Philipp Haller,et al.  Isolated Actors for Race-Free Concurrent Programming , 2010 .

[22]  Christopher Strachey,et al.  Fundamental Concepts in Programming Languages , 2000, High. Order Symb. Comput..

[23]  Nicholas D. Matsakis,et al.  The rust language , 2014, HILT '14.

[24]  Tiark Rompf,et al.  Gentrification gone too far? affordable 2nd-class values for fun and (co-)effect , 2016, OOPSLA.

[25]  Dave Clarke,et al.  Ownership Types: A Survey , 2013, Aliasing in Object-Oriented Programming.

[26]  Martin Odersky,et al.  Capabilities for Uniqueness and Borrowing , 2010, ECOOP.

[27]  Sophia Drossopoulou,et al.  Deny capabilities for safe, fast actors , 2015, AGERE!@SPLASH.

[28]  John Tang Boyland,et al.  Alias burying: Unique variables without destructive reads , 2001, Softw. Pract. Exp..

[29]  Philipp Haller,et al.  LaCasa: lightweight affinity and object capabilities in Scala , 2016, OOPSLA.

[30]  Jan Vitek,et al.  Implicit ownership types for memory management , 2008, Sci. Comput. Program..