Four major changes coming to Rust

InfoWorld ·

Over its decade-and-a-half lifetime, the Rust programming language has evolved dramatically. Rust has always been about ensuring safe programming with strong typing that doesn’t sacrifice speed. But how it expresses those capabilities has matured and expanded, and that movement hasn’t slowed. If anything, it has accelerated. At any given time in Rust’s development, you could point to dozens of different initiatives to improve the language . As of the end of 2026, four of these stand far above the rest, because of how broad their impact could be and how deeply they touch on many aspects of Rust. The next-generation trait solver Rust’s type system uses “traits” to define the functionality that a given type has and can share with other types. If we described a trait named ExportToJSON , we might have a matching impl , or implementation, for a data type: impl ExportToJSON for CSV The Rust compiler tries to find matching implementations for each reference to a trait. This is highly important for generic functions, since it may not be obvious if an implementation exists for a given invocation of a function. The current version of the trait solver has problems dealing with situations like self-referential types. Those aren’t common, but Rust programmers must consciously avoid constructing them to keep the trait solver from getting tied up in knots. Sometimes, because of this, it’s the developer who gets ensnarled. A new version of the trait solver takes a totally different approach to the problem. It draws on ideas gleaned from an earlier attempt to rewrite the trait solver (called “ Chalk ”), and uses a sophisticated caching mechanism both to avoid problems with self-referential types and potentially run faster than the current solver. The current version of the new trait solver covers some use cases, but not all of them. The next step is to ensure that the solver can cover all use cases, including async features. Once that happens, Rust developers will have far more freedom in the ways we can use traits. The new borrow checker, ‘Polonius’ The borrow checker is as fundamental to the Rust language as it gets. It ensures at compile time that a given object only has one “owner” at a time, so that certain bugs never make it into a running program. Having two parts of a program try to modify the same object at the same time is a common bug avoided with the borrow checker. For a long time now, the borrow checker has had many limitations that in certain circumstances results in flagging memory-safe code as unsafe. One way to deal with this would be to modify the borrow checker to scan the program’s control-flow graph, or the way it actually executes, as opposed to analyzing its lexical scopes, or the way the program is coded. (The term for this is “ non-lexical lifetimes ”.) Making this happen, as it turned out, required more than a patch here and there. It meant a total overhaul of how the borrow checker worked. This project, dubbed “ Polonius ” (from Hamlet —“Neither a borrower nor a lender be”), currently exists in an early form as a library crate . This makes sense, since the Rust compiler is itself written in Rust. But Polonius also been integrated into the nightly edition of the rustc compiler, so you can experiment with it by activating a feature flag. Still, the new borrow checker is far from production-ready. The mission going forward is to make Polonius stable, and to expand its analyses beyond the most common cases while keeping it speedy. Once Polonius becomes ready for regular use, it will resolve many borrow-checking issues that currently make Rust code awkward or hard to reason about — and will make it easier to write safe Rust code that is larger in scope and ambition. A parallel front end for faster compilation In 2023, the Rust compiler team introduced a feature in its nightly builds intended to speed up compilation: using parallelism on the compiler front end. Rust already used parallelism to speed up compilation on the back end — i.e., to execute code-generation operations in parallel. It didn’t use parallelism for front-end operations like parsing, type checking, and borrow checking. For many programs, the front end is a bigger compiler bottleneck than the back end. Today, most of the pieces are in place to make the compiler front end highly parallel, and the parallel front end is available as a nightly feature for those who want to experiment with it. What’s still missing are good ways to test this feature — for instance, to ensure the resulting code is consistent. Also still lacking is support for parallelizing some language features, such as macro expansion. High-level machine learning optimizations There’s been much talk lately about the best languages for machine learning applications. Python is a big name on that list, not because of its speed but because of its convenience. It lets you quickly stitch together machine learning systems from components written in faster languages — like Rust, for instance. However, although Rust has speed, type safety, and other vaunted features, it lacks a few capabilities that would make it well-suited to developing machine learning applications, including the ability to develop machine learning models entirely in Rust. The biggest omissions have to do with tensors and matrices and their operations, i.e. the data structures and calculations used to build machine learning apps. Rust does support matrix operations, but doesn’t yet support compiling and deploying code for those operations to dedicated acceleration hardware like TPUs. Rust also lacks higher-level optimizations for those data structures, like being able to re-order or combine them in compilation, which would be effective on any hardware (CPU, GPU, TPU, etc.). Another idea being explored is adding MLIR support to the Rust compiler as a target. MLIR, or Multi-Level Intermediate Representation, allows LLVM (used in the Rust compiler back end for code generation) to generate intermediate code that can be highly specialized. For instance, GPU-specific or TPU-specific code is easier to generate through MLIR. This would make Rust a more viable language for creating machine learning models, with training and inference taking place on any supported target platform or hardware type. Faster compilation and a borrow checker and trait solver that support a broader range of safe and valid code are quality-of-life improvements that will benefit every developer using the Rust language. But the improvements around making Rust a better language for writing low-level machine learning components hint at how Rust could in time become a powerful way to write other kinds of hardware-level, domain-specific code.

Источник: InfoWorld