Enhancing RUSTDOC to Allow Search by Types

Abstract: Programming languages have benefited from increased attention lately. With corporations like Google, Facebook and Mozilla investing in language design, there is a lot of activity in the mainstream languages domain. State of the art features like advanced type systems that were only available to more research-centered languages such as Haskell, are now making their way into the mainstream through languages like Rust. Rust is an up-and-coming system programming language that aims to fill the same role as C and C++, but in a much safer way. To achieve this, it brings a rich type system, alongside a pragmatic implementation of region based memory management, a feature that allows safe memory handling without the need of a garbage collector. Aiming for the mainstream, Rust comes with tooling to aid developers in their work. One such tool is Rustdoc, a program that automatically generates documentation based on type information and programmer comments. We aim to enhance Rustdoc to provide more advanced search support through features that are impossible to implement for dynamic languages, and even static languages with less advanced type systems, like C and Go.

Progress in type inference algorithms [4] has led to statically typed languages that are easier to use and more appealing to programmers. Thanks to their performance compared to dynamic languages, programming languages such as Scala, Go and Hack (Facebook’s version of typed PHP) are increasingly gaining popularity. Besides the mentioned ease of use and good performance, all these languages also come with great tooling.

While not specifically part of the language, accompanying tools are critical to a programming language’s success. They represent the ways in which a programmer interacts with the code. For example, any language should have (or support) a good debugger to make finding bugs easier. Also, it should have an easy to use package management and build system. Many programmers find the XML configuration files of Java package systems cumbersome. To overcome this, Scala brings a simpler format for specifying dependencies.

Another important tool is the documentation generator. Good languages are used in large projects, and large projects need great documentation. Having a standard way of generating documentation pages is key to effortless knowledge sharing. Java has Javadoc, Scala has Scaladoc and Go has Godoc. They all do a good job of generating formatted, Web-accessible documentation from source code. However, they share a key shortcoming – they only support searching symbols by name. Search by name covers one aspect of programming – the situation where the programmer encounters a function and wants to know what it does. But there is also the case when the programmer needs to find a function that does a particular operation, and because of various reasons (new language, new naming standards, new codebase etc.) the name of that function is unknown. In this situation, the ability to search by type would be perfect.

An important benefit of static typing, besides allowing for compile-time checking, is that the types act as documentation. So why shouldn’t the documentation generators use this information?

Our project aims to add this exact functionality to Rustdoc – the documentation generator of the up-and-coming (currently in alpha) Rust [14] programming language. Rust has a rich type system, similar to that of Haskell and ML, which allows representing complex information through the type annotations. Because of this, we consider it a great target language for searching documentation by types.

The rest of this article is structured as follows: first, we will introduce Rust, its features and look at an existing implementation of searching documentation by type for Haskell. Then, we will discuss our implementation for Rustdoc. Following this, we will examine the usage as well as the performance of our solution. Finally, we will present our conclusions as well as possible future work for the project.