Implementing Semantic Querying of Rust Code

external page Rustis a new programming language that aims to be a safe replacement for C and C++. Therefore, the Rust type system provides strong guarantees such as a data race freedom. However, sometimes the type system is too restrictive, and as an escape hatch, Rust provides unsafe external page blocks and functions. On the one hand, the type system allows a programmer to do more things in the unsafe code; on the other hand, the programmer has to make sure that their unsafe code does not violate the type system's assumptions. Even though not violating these assumptions is critical for the correctness of many programs, the Rust community is still discussing what should be allowed in unsafe code and what should not. Therefore, there is a need for the community to understand how Rust programmers use unsafe code.

One possible way to help the community is to provide a tool that allows efficiently finding and summarising all code fragments that match a specific pattern. For example, it would be interesting to know what safe Rust functions are most often called from unsafe blocks. While a text-based code search could be used to find all functions called from unsafe blocks, telling which of the called functions are safe requires having the type information. However, all current search tools that support Rust are text-based and, as a result, cannot handle such queries.

Goals

The main goal of this project is to develop a tool that allows semantic querying over all public Rust code. The core subgoals of this project are:

  1. Go over the unsafe code guidelines team discussions and collect questions the team tried to answer by manually investigating the code.
  2. Design a query language in which it is possible to express the collected questions as queries.
  3. Extend the compiler with an option to save the AST of a Rust crate being compiled.
  4. Implement a database for storing ASTs that allows executing queries written in the designed query language efficiently.
  5. Extract ASTs of all crates from https://crates.io/ and import them into the database.
  6. Evaluate the effort needed with the new system to answer the questions collected earlier.

The extension subgoals that should be implemented if time permits:

  1. Implement a web service that given a query would respond with results within 5 seconds for most queries.
  2. Implement support for incremental updates of the database that allow importing ASTs of packages newly published to https://crates.io/ without rebuilding the entire database.
  3. Implement visualisations of results that have a specific shape to enable the users to comprehend the results quickly. For example, a query that returns a sequence of tuples “(String, Int)” could be visualised by using a bar chart.

Useful Prerequisites

The following skills would be helpful, but can also be learned during the project:

  • Experience with Rust

Opportunities

The project offers the following opportunities:

  • Make an important contribution to the Rust community.
  • Gain experience with the Rust programming language.

Contacts

JavaScript has been disabled in your browser