Skip to content

Commit 575761d

Browse files
authored
Merge pull request #965 from m-ou-se/libs-aspirations
Rust Library Team Aspirations
2 parents 0983518 + 0e07b6d commit 575761d

File tree

1 file changed

+217
-0
lines changed

1 file changed

+217
-0
lines changed
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
---
2+
layout: post
3+
title: Rust Library Team Aspirations
4+
author: Mara Bos
5+
description: Rust Library Team Aspirations
6+
team: The Rust Library Team <https://www.rust-lang.org/governance/teams/library>
7+
---
8+
9+
Over the past years, Rust has grown from a language used by a few dedicated users
10+
into a well-known language used by lots of highly visible projects and
11+
successful companies.
12+
As the Rust user base, the community, and the ecosystem continues to grow,
13+
we need to look forward and consider how we need to scale to adapt
14+
to the needs of the ever expanding Rust ecosystem.
15+
16+
Recently, the compiler team shared [their blog post](https://blog.rust-lang.org/inside-rust/2022/02/22/compiler-team-ambitions-2022.html)
17+
detailing their ambitions for 2022,
18+
and the language team published [a roadmap](https://blog.rust-lang.org/inside-rust/2022/04/04/lang-roadmap-2024.html)
19+
with their vision for Rust in 2024.
20+
21+
In this blog post, we, the Rust library team, will share our perspective
22+
on the future of the Rust standard library and the library ecosystem.
23+
24+
It's important to note that
25+
the role of the team is to coordinate changes and to guide, review and decide.
26+
The majority of the work itself is done by contributors, like yourself,
27+
both in and outside the Rust team.
28+
While we often also participate in design and implementation work,
29+
we do so as contributors, like everyone else.
30+
31+
What follows is an (incomplete) summary of topics we think
32+
are important and would like to coordinate and guide;
33+
things that we'd love to see happen,
34+
as an invitation and source of inspiration.
35+
36+
### Scalability
37+
38+
As mentioned above, the Rust language, standard library, and ecosystem
39+
is growing and getting more mature.
40+
We need to invest in ways to keep evolving these smoothly.
41+
42+
**Evolvability of the standard library and fixing mistakes**
43+
44+
The stability guarantee of Rust makes it hard to evolve the standard library.
45+
Unlike most crates, we cannot release a new major version, as that would effectively be releasing a 'Rust 2.0'.
46+
So, once an API is stable, we have to keep it there forever, meaning that we have to be extremely careful
47+
when stabilizing anything new.
48+
49+
While we are very careful with adding new APIs, mistakes can still happen.
50+
There are a few things we would do differently if we could go back in time, based on current experience.
51+
There are not a lot of these cases, but over time these can still accumulate to the point that
52+
it'd be useful to have a mechanism to correct past mistakes.
53+
54+
The Rust language has the concept of [editions](https://doc.rust-lang.org/edition-guide/editions/index.html)
55+
to be able to make breaking changes in the language itself, without disrupting Rust users.
56+
The library, however, can make very limited use of editions to correct mistakes.
57+
We have used them for the [`panic!()` macro](https://doc.rust-lang.org/edition-guide/rust-2021/panic-macro-consistency.html)
58+
and [the prelude](https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html).
59+
However, in general, it's extremely tricky to make use of the edition mechanism for backwards incompatible
60+
library changes, as crates of different editions can be mixed, while all using the same standard library.
61+
62+
There are also cases when adding a new API can subtly break existing Rust code,
63+
even when not changing any existing API.
64+
This can happen, for example, when a type gets a new method that was already available through
65+
a popular trait, such as `itertools::Itertools` or `num::Integer`.
66+
Adding a method to the standard library can result in an existing method call resolving differently,
67+
potentially breaking code.
68+
This is usually considered 'acceptable' breakage, but as Rust usage grows,
69+
the impact of such breakage increases, often making such breakage unacceptable in practice.
70+
71+
So, in order to keep evolving the standard library, we'd like to collaborate on language features
72+
that alleviate these issues:
73+
74+
- [Edition based method disambiguation](https://github.com/rust-lang/rfcs/pull/3240)
75+
- A way to fix the `Range` types, such that `1..2` can be `Copy`.
76+
- A way to remove or improve lock poisoning without breaking existing code.
77+
- General mechanisms to provide for the library what editions provide for the language.
78+
79+
**People and collaboration**
80+
81+
The most important thing to keep Rust and the ecosystem scalable,
82+
are the people: Rust team members, maintainers of crates in the ecosystem,
83+
reviewers, contributors, and so on.
84+
It's important we keep working on how we collaborate and make it
85+
as easy as possible for everyone to get involved in a way that works for them.
86+
87+
Concretely, we want to work on:
88+
89+
- Better and more complete guidelines for contributors and reviewers; and
90+
- More interaction with the rest of the ecosystem.
91+
92+
**Making `std` less special / Empowering other crates in the ecosystem**
93+
94+
The standard library uses a
95+
[huge amount of unstable language features](https://github.com/rust-lang/rust/issues/94970)
96+
that other crates in the ecosystem cannot (or should not) use.
97+
While this is unavoidable for `core`, because it contains everything related
98+
to Rust's built-in types, we should be able to make `alloc` and `std` less
99+
dependent on unstable features.
100+
Maybe some day these libraries could be no different than any other
101+
popular crate in the ecosystem.
102+
103+
A big part of the work here will be in collaboration with the language team,
104+
to help move the unstable language features we need towards a state where
105+
they can be stabilized.
106+
107+
**Adapting to different platforms**
108+
109+
As Rust's popularity increases, it is used on an increasingly wider variety of platforms.
110+
The Rust standard library does an okay job at abstracting away some of the
111+
differences between popular platforms like Linux and Windows,
112+
through things like `File` and `TcpStream`,
113+
but we don't do a great job for targets that do not look like those,
114+
such as Wasm or kernel modules.
115+
116+
For example, `core` includes `f32` and `f64`, even if the platform doesn't support floating point operations,
117+
and `std` includes `File::open`, even if it isn't implemented and always fails on the specific platform you're targeting.
118+
119+
In order to better support the ever growing diversity of platforms Rust is used on,
120+
we would like to collaborate with the language and compiler teams to make it easier
121+
for the standard library to properly support targets with very different needs,
122+
without it becoming hugely inconvenient for maintainers, contributors, or users:
123+
124+
- Make it easier to port std to a new platform, possibly allowing the relevant code
125+
to live outside of the `rust-lang/rust` repository for less popular platforms.
126+
- A better way to allow only parts of `std` to be available, depending on the platform.
127+
For example, a `where Platform: Unix` bound, or something like a [`#[cfg]` portibility lint](https://rust-lang.github.io/rfcs/1868-portability-lint.html).
128+
- A way to allow non-portable functionality to be available when on platforms
129+
that would support it, such as allowing infallible conversion between `u64` and
130+
`usize` in code that declares it only runs on 64-bit platforms.
131+
- Make the standard library more modular, allowing to disable e.g. floating point support
132+
or file system support on certain platforms.
133+
134+
### Improving and adding new APIs
135+
136+
A main focus of the library team is and will always be the public interface of the standard library.
137+
As of last year, we even have a separate team to make the final calls for API changes and additions:
138+
the [library API team](https://www.rust-lang.org/governance/teams/library#Library%20API%20team).
139+
140+
Rust purposely has a minimal standard library. Lots of commonly used functionality is
141+
found in other crates in the ecosystem, rather than the standard library.
142+
143+
Where exactly we draw the line between things that should and shouldn't go in the standard library
144+
can be tricky to define and is somewhat flexible, but there are a few categories we're most interested in.
145+
146+
**Ergonomics**
147+
148+
A lot of additions to the standard library are very small ones that increase ergonomics.
149+
Quite often, these are things that were already possible in some way, just not in an ergonomic way.
150+
Some recent examples are:
151+
152+
- `abs_diff()`
153+
- `Path::is_symlink`
154+
- `iter::from_fn`
155+
- `NonZero*::saturating_add`
156+
157+
While we always have to consider the trade-off for niche features to the already large interface
158+
on some types and traits, additions like these continue to happen regularly.
159+
160+
**Standardizing some bigger features the ecosystem needs**
161+
162+
As Rust grows into new territories, there is more and more a need
163+
for certain features to be included in the standard library.
164+
This is especially true for things where a consistent, standard, interface is
165+
important.
166+
Some of the bigger examples are:
167+
168+
- Async traits and functions
169+
- Allocators and fallible allocation
170+
- Error and panic handling
171+
- Portable SIMD
172+
- Benchmarking and custom test/bench frameworks
173+
174+
**Reducing and improving unsafe code**
175+
176+
By providing the right low level APIs and abstractions, we can greatly minimize
177+
the amount of complex unsafe code that users need to write. Tools like
178+
`MaybeUninit` guide users to correct unsafe code that's easy to follow and
179+
prove correct. Even better, some APIs can entirely remove the need for unsafe
180+
code in many situations.
181+
This includes situations where users tend to reach for `unsafe` for performance reasons.
182+
183+
- `std::arch`
184+
- `std::simd`
185+
- Scoped threads
186+
- More atomic primitives
187+
- '`Iterator`' with static length for arrays
188+
- Improving `MaybeUninit` and related methods
189+
- Extending `NonNull` and pointer methods
190+
- A more complete interface to `OsString`, `Path`, and `CString`
191+
- Documentation for `Pin` and other 'unsafe' types
192+
- File descriptors (`OwnedFd`, `AsFd`, etc) and handles (`OwnedHandle`, `AsHandle`, etc)
193+
194+
### Improving implementations of things within the standard library
195+
196+
Historically, the implementation details of the standard library got less attention
197+
than its public API.
198+
Recently, however, we're seeing more and more contributions towards improving the implementation
199+
of various parts of the standard library.
200+
201+
These are some parts that we're especially interested in seeing improvements in:
202+
203+
- `core::fmt` and the implementation of `format_args!()` and `fmt::Arguments`
204+
- [Synchronization primitives like `Mutex`, `RwLock`, and `Condvar`](https://github.com/rust-lang/rust/issues/93740)
205+
- Cleanups in platform-specific code in `std::sys`
206+
- Avoiding allocations wherever possible, [such as when calling functions in `std::fs`](https://github.com/rust-lang/rust/pull/93668)
207+
- Making widely used types [such as `std::io::Error`](https://github.com/rust-lang/rust/pull/87869) more light-weight
208+
- Cleaning up all unnecessary `SeqCst` memory ordering
209+
- Optimizing thread local variables
210+
211+
### Conclusion
212+
213+
We hope this summary provides a healthy amount of inspiration and excitement,
214+
and gives you an idea of what direction the library team is headed.
215+
If you want to help out, whether you want to work on implementation work,
216+
design, documentation, organisation, or any other kind of helpful work,
217+
you're warmly invited to [get involved](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs)!

0 commit comments

Comments
 (0)