skip to main content
research-article
Open access

Leveraging Rust Types for Program Synthesis

Published: 06 June 2023 Publication History

Abstract

The Rust type system guarantees memory safety and data-race freedom. However, to satisfy Rust's type rules, many familiar implementation patterns must be adapted substantially. These necessary adaptations complicate programming and might hinder language adoption. In this paper, we demonstrate that, in contrast to manual programming, automatic synthesis is not complicated by Rust's type system, but rather benefits in two major ways. First, a Rust synthesizer can get away with significantly simpler specifications. While in more traditional imperative languages, synthesizers often require lengthy annotations in a complex logic to describe the shape of data structures, aliasing, and potential side effects, in Rust, all this information can be inferred from the types, letting the user focus on specifying functional properties using a slight extension of Rust expressions. Second, the Rust type system reduces the search space for synthesis, which improves performance.
In this work, we present the first approach to automatically synthesizing correct-by-construction programs in safe Rust. The key ingredient of our synthesis procedure is Synthetic Ownership Logic, a new program logic for deriving programs that are guaranteed to satisfy both a user-provided functional specification and, importantly, Rust's intricate type system. We implement this logic in a new tool called RusSOL. Our evaluation shows the effectiveness of RusSOL, both in terms of annotation burden and performance, in synthesizing provably correct solutions to common problems faced by new Rust developers.

References

[1]
Martín Abadi and Leslie Lamport. 1988. The Existence of Refinement Mappings. In LICS. IEEE Computer Society, 165–175. https://doi.org/10.1109/LICS.1988.5115
[2]
Vytautas Astrauskas, Peter Müller, Federico Poli, and Alexander J. Summers. 2019. Leveraging Rust Types for Modular Specification and Verification. Proc. ACM Program. Lang., 3, OOPSLA (2019), 147:1–147:30. https://doi.org/10.1145/3360573
[3]
Aria Beingessner. 2015. Learning Rust With Entirely Too Many Linked Lists. https://rust-unofficial.github.io/too-many-lists/
[4]
John Boyland. 2013. Fractional Permissions. In Aliasing in Object-Oriented Programming. Types, Analysis and Verification (LNCS, Vol. 7850). Springer, 270–288. https://doi.org/10.1007/978-3-642-36946-9_10
[5]
Andreea Costea, Amy Zhu, Nadia Polikarpova, and Ilya Sergey. 2020. Concise Read-Only Specifications for Better Synthesis of Programs with Pointers. In ESOP (LNCS, Vol. 12075). Springer, 141–168. https://doi.org/10.1007/978-3-030-44914-8_6
[6]
Xavier Denis, Jacques-Henri Jourdan, and Claude Marché. 2021. The CREUSOT Environment for the Deductive Verification of Rust Programs. Inria Saclay - Île de France. https://hal.inria.fr/hal-03526634
[7]
Jonáš Fiala, Shachar Itzhaky, Peter Müller, Nadia Polikarpova, and Ilya Sergey. 2023. Reproduction Package for Article “Leveraging Rust Types for Program Synthesis”. https://doi.org/10.5281/zenodo.7811786
[8]
Son Ho and Jonathan Protzenko. 2022. Aeneas: Rust verification by functional translation. Proc. ACM Program. Lang., 6, ICFP (2022), 711–741. https://doi.org/10.1145/3547647
[9]
Shachar Itzhaky, Hila Peleg, Nadia Polikarpova, Reuben N. S. Rowe, and Ilya Sergey. 2021. Cyclic Program Synthesis. In PLDI. ACM, 944–959. https://doi.org/10.1145/3453483.3454087
[10]
Shachar Itzhaky, Hila Peleg, Nadia Polikarpova, Reuben N. S. Rowe, and Ilya Sergey. 2021. Deductive Synthesis of Programs with Pointers: Techniques, Challenges, Opportunities - (Invited Paper). In CAV (LNCS, Vol. 12759). Springer, 110–134. https://doi.org/10.1007/978-3-030-81685-8_5
[11]
Ralf Jung, Hoang-Hai Dang, Jeehoon Kang, and Derek Dreyer. 2019. Stacked Borrows: An Aliasing Model for Rust. Proc. ACM Program. Lang., 4, POPL (2019), Article 41, dec, 32 pages. https://doi.org/10.1145/3371109
[12]
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
[13]
Etienne Kneuss, Ivan Kuraj, Viktor Kuncak, and Philippe Suter. 2013. Synthesis modulo recursive functions. In OOPSLA. ACM, 407–426. https://doi.org/10.1145/2509136.2509555
[14]
Andrea Lattuada, Travis Hance, Chanhee Cho, Matthias Brun, Isitha Subasinghe, Yi Zhou, Jon Howell, Bryan Parno, and Chris Hawblitzel. 2023. Verus: Verifying Rust Programs using Linear Ghost Types. Proc. ACM Program. Lang., To appear.
[15]
Nico Lehmann, Adam Geller, Niki Vazou, and Ranjit Jhala. 2023. Flux: Liquid Types for Rust. Proc. ACM Program. Lang., 7, PLDI (2023), To appear.
[16]
Zohar Manna and Richard J. Waldinger. 1980. A Deductive Approach to Program Synthesis. ACM Trans. Program. Lang. Syst., 2, 1 (1980), 90–121. https://doi.org/10.1145/357084.357090
[17]
Nicholas D. Matsakis and Felix S. Klock II. 2014. The Rust language. In Proceedings of the 2014 ACM SIGAda annual conference on High integrity language technology, HILT 2014. ACM, 103–104. https://doi.org/10.1145/2663171.2663188
[18]
Yusuke Matsushita, Xavier Denis, Jacques-Henri Jourdan, and Derek Dreyer. 2022. RustHornBelt: a semantic foundation for functional verification of Rust programs with unsafe code. In PLDI. ACM, 841–856. https://doi.org/10.1145/3519939.3523704
[19]
Yusuke Matsushita, Takeshi Tsukada, and Naoki Kobayashi. 2021. RustHorn: CHC-based Verification for Rust Programs. ACM Trans. Program. Lang. Syst., 43, 4 (2021), 15:1–15:54. https://doi.org/10.1145/3462205
[20]
Peter Müller, Malte Schwerhoff, and Alexander J. Summers. 2016. Viper: A Verification Infrastructure for Permission-Based Reasoning. In VMCAI (LNCS, Vol. 9583). Springer, 41–62. https://doi.org/10.1007/978-3-662-49122-5_2
[21]
Peter W. O’Hearn, John C. Reynolds, and Hongseok Yang. 2001. Local Reasoning about Programs that Alter Data Structures. In CSL (LNCS, Vol. 2142). Springer, 1–19. https://doi.org/10.1007/3-540-44802-0_1
[22]
Nadia Polikarpova and Ilya Sergey. 2019. Structuring the Synthesis of Heap-Manipulating Programs. Proc. ACM Program. Lang., 3, POPL (2019), 72:1–72:30. https://doi.org/10.1145/3290385
[23]
The Rust Team. 2017. The Rust programming language. http://rust-lang.org
[24]
Jan Smans, Bart Jacobs, and Frank Piessens. 2010. Heap-Dependent Expressions in Separation Logic. In FMOODS/FORTE (LNCS, Vol. 6117). Springer, 170–185. https://doi.org/10.1007/978-3-642-13464-7_14
[25]
Yoshiki Takashima, Ruben Martins, Limin Jia, and Corina S. Păsăreanu. 2021. SyRust: Automatic Testing of Rust Libraries with Semantic-Aware Program Synthesis. In PLDI. ACM, 899–913. https://doi.org/10.1145/3453483.3454084
[26]
Philip Wadler. 1989. Theorems for Free!. In FPCA. ACM, 347–359. https://doi.org/10.1145/99370.99404
[27]
Aaron Weiss, Daniel Patterson, Nicholas D. Matsakis, and Amal Ahmed. 2019. Oxide: The Essence of Rust. CoRR, abs/1903.00982 (2019), arXiv:1903.00982. arxiv:1903.00982
[28]
Fabian Wolff, Aurel Bílý, Christoph Matheja, Peter Müller, and Alexander J. Summers. 2021. Modular specification and verification of closures in Rust. Proc. ACM Program. Lang., 5, OOPSLA (2021), 1–29. https://doi.org/10.1145/3485522

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 7, Issue PLDI
June 2023
2020 pages
EISSN:2475-1421
DOI:10.1145/3554310
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: 06 June 2023
Published in PACMPL Volume 7, Issue PLDI

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Rust
  2. program logic
  3. program synthesis
  4. type systems

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)553
  • Downloads (Last 6 weeks)60
Reflects downloads up to 10 Feb 2025

Other Metrics

Citations

Cited By

View all

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media