A Mixed-Methods Study on the Implications of Unsafe Rust for Interoperation, Encapsulation, and Tooling

Ian McCormack,Tomas Dougan,Sam Estep,Hanan Hibshi,Jonathan Aldrich,Joshua Sunshine
2024-10-20
Abstract:The Rust programming language restricts aliasing to provide static safety guarantees. However, in certain situations, developers need to bypass these guarantees by using a set of unsafe features. If they are used incorrectly, these features can reintroduce the types of safety issues that Rust was designed to prevent. We seek to understand how current development tools can be improved to better assist developers who find it necessary to interact with unsafe code. To that end, we study how developers reason about foreign function calls, the limitations of the tools that they currently use, their motivations for using unsafe code, and how they reason about encapsulating it. We conducted a mixed-methods investigation consisting of semi-structured interviews with 19 developers, followed by a survey that reached an additional 160 developers. Our participants were motivated to use unsafe code when they perceived that there was no alternative, and most avoided using it. However, limited tooling support for foreign function calls made participants uncertain about their design choices, and certain foreign aliasing and concurrency patterns were difficult to encapsulate. To overcome these challenges, Rust developers need verification tools that can provide guarantees of soundness within multi-language applications.
Software Engineering
What problem does this paper attempt to address?
The problems that this paper attempts to solve mainly focus on the following aspects: 1. **Memory safety in cross - language calls**: The Rust language provides static safety guarantees through strict aliasing rules. However, when interacting with external languages, developers need to use the `unsafe` feature to bypass these safety restrictions. In this case, how to ensure memory safety in cross - language calls has become an important issue. The paper hopes to understand the challenges that developers encounter in these scenarios by studying their thinking patterns when handling cross - language calls. 2. **Limitations of existing tools**: Currently, most Rust development tools lack support for external function calls, which makes developers feel uncertain when designing and implementing cross - language applications. The paper aims to explore the tools currently used by developers and their limitations and put forward suggestions for improving the tools. 3. **Motivations for using `unsafe` code**: Although the Rust community advocates minimizing the use of `unsafe` code as much as possible, many developers still need to use these features. The paper attempts to understand the motivations of developers for using `unsafe` code and how they balance safety and functional requirements. 4. **Methods for encapsulating `unsafe` code**: Even when using `unsafe` code, developers also hope to encapsulate it under a safe interface to reduce potential safety risks. The paper studies how developers encapsulate `unsafe` code and the difficulties they encounter in this process. In summary, the main objective of this paper is to gain in - depth understanding of Rust developers' thinking patterns and challenges when handling cross - language calls, using existing tools, the motivations for using `unsafe` code, and encapsulating `unsafe` code through mixed - method research (including semi - structured interviews and questionnaires). Through these studies, the paper hopes to provide guidance for developing more effective tools and support to help developers better handle these complex issues.