Avoiding Rust Deadlocks via Visualizing Lifetime

Researcher(s)

Sponsoring Agency
Web3 Foundation

Summary

Lifetime is a core concept in Rust. Besides safety checks, it is also leveraged by the Rust compiler to conduct automated resource management. For example, there is no explicit Unlock() in Rust. A Lock() function call returns a reference to the protected variable, and when the reference ends its lifetime, the compiler automatically releases the acquired lock (by implicitly calling Unlock()). However, lifetime computation in Rust is too complex, and it is challenging for Rust programmers to infer where a variable’s lifetime ends. As a result, it is not uncommon for programmers to incorrectly identify the location where an implicit unlock is called, leading to deadlocks. In this project, we will build an IDE tool for visualizing the lifetime scope of a user-selected Rust variable. We believe our tool can help Rust programmers avoid deadlocks at the development stage. After writing a piece of code involving a mutex, a programmer can select the return value of a locking operation or the locking operation itself (when the return is not saved to a variable). Our tool will visualize the lifetime scope of the return value (i.e., the critical section). The programmer can then inspect whether the end of the critical section is expected. In addition, our tool will conduct deadlock detection for the selected critical section and provide detailed debugging information for identified bugs, such as highlighting blocking operations or function calls leading to blocking operations.

Research Area

Term
 -