Skip to content

Commit e75413c

Browse files
committed
Add rust spec RFC.
1 parent 9653bae commit e75413c

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed

text/0000-rust-spec.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
- Feature Name: `rust_spec`
2+
- Start Date: 2022-12-06
3+
- RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000)
4+
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
5+
6+
# Summary
7+
[summary]: #summary
8+
9+
We should start working on a Rust specification.
10+
11+
# Goal of this RFC
12+
13+
The goal of this RFC is to reach consensus on:
14+
15+
- Whether we want a specification, and (if so),
16+
- Some initial goals and non-goals, and
17+
- How we want the work to be organised and coordinated.
18+
19+
This RFC _does not_ define the full scope of the specification
20+
or discuss any details of how it would look like.
21+
It only provides the minimal details necessary to be able to kick off the Rust specification work.
22+
23+
# Motivation
24+
25+
Why do we want a Rust specification at all?
26+
27+
There are many different kind of Rust users that would benefit from a Rust specification in their own way.
28+
Things like the Rust Reference, the Unsafe Code Guidelines Project, the Rustonomicon, and so on,
29+
all exist to fulfill certain needs of Rust users.
30+
Unfortunately, their use is currently limited, because none of these are complete, entirely accurate, or normative.
31+
32+
Authors of unsafe code could benefit a lot from clear definitions of what is and isn't undefined behaviour.
33+
Safety critical Rust software won't pass certification without a specification that clearly specifies how Rust code behaves.
34+
Proposals and discussions about new Rust language features could be more efficient and precise
35+
using accurately defined terms that everyone agrees on.
36+
Questions about subtle interactions between features of the language could be answered
37+
using precise information from a specification, instead a combination of guesses and several non-authoritative sources.
38+
39+
# Current state
40+
41+
Languages like C and C++ are standardized.
42+
Rust is not. Standardization comes down to, basically:
43+
44+
1. Having an accurate specification (a document)
45+
2. An (open) process for evolution of the language
46+
3. Stability
47+
48+
Rust currently already has 2 and 3, but not 1.
49+
50+
For 1, we currently have:
51+
the (incomplete) [Rust Reference](https://doc.rust-lang.org/stable/reference/),
52+
the [Standard Library Reference Documentation](https://doc.rust-lang.org/stable/std/),
53+
the [Rust Nomicon](https://doc.rust-lang.org/nightly/nomicon/),
54+
the [Unsafe Code Guidelines Project](https://github.com/rust-lang/unsafe-code-guidelines/),
55+
[Miri](https://github.com/rust-lang/miri/),
56+
the collection of [accepted RFCs](https://rust-lang.github.io/rfcs/),
57+
the [Ferrocene Language Specification](https://spec.ferrocene.dev/),
58+
lots context and decisions spread over [tons of GitHub issues](https://github.com/rust-lang/rust/issues/),
59+
[MiniRust](https://github.com/RalfJung/minirust),
60+
the [source code](https://github.com/rust-lang/rust/),
61+
and more.
62+
63+
These are currently all incomplete, and/or not a good source to rely on.
64+
65+
More background information is available in [this blog post](https://blog.m-ou.se/rust-standard/).
66+
67+
# Goals and non-goals
68+
69+
- The goal of the Rust specification work is the creation of a document, the Rust specification.
70+
71+
- The goal is _not_ to change how the language evolves;
72+
the relevant teams (Language, Libs-API, …) remain in charge of the evolution of their respective parts of Rust,
73+
and will continue to use processes as they see fit (e.g. RFCs).
74+
75+
- The specification will only be considered "official" once the relevant teams have approved of its contents.
76+
Changes to the official specification must be approved by the relevant team(s).
77+
78+
- The goal is to serve the needs of Rust users, such as
79+
authors of unsafe Rust code, those working on safety critical Rust software,
80+
language designers, maintainers of Rust tooling, and so on.
81+
82+
- It is _not_ a primary goal of the specification to aid in the development of alternative Rust implementations,
83+
although authors of alternative compilers might still find the specification to be useful.
84+
85+
What this means is that, unlike the C or C++ standard,
86+
the Rust specification does not provide a set of requirements for a compiler to be able to call itself "a Rust™ compiler".
87+
Instead, it specifies the behaviour of the Rust compiler.
88+
(So, not "A Rust implementation should …", but instead "Rust will …".)
89+
90+
- The scope remains to be determined, but at least includes all topics currently included in
91+
the (incomplete) [Rust Reference](https://doc.rust-lang.org/stable/reference/).
92+
93+
- The Rust specification is expected to replace the current Rust Reference.
94+
95+
- The scope of the specification can grow over time, depending on the needs of Rust users and
96+
time and motivation of those working on it.
97+
98+
For example, it might grow over time to also specify details of Cargo,
99+
compiler flags, procedural macros, or other parts that we might initially consider out of scope.
100+
101+
- The specification is specific to the latest version of Rust.
102+
A copy of the specification is included with each Rust release,
103+
as we currently already do with much of our documentation.
104+
105+
While the specification might include notes about the Rust version that a feature was introduced in
106+
for informative purposes (similar to standard library documentation),
107+
it does not attempt to accurately specify older, unsupported versions of Rust.
108+
109+
- The specification specifies all Rust _editions_, as supported by the latest version of the Rust compiler.
110+
111+
- Once the specification reaches an initial usable version,
112+
the relevant teams are expected to incorporate it in their process for language evolution.
113+
For example, the language team could require a new language feature to be included
114+
in the specification as a requirement for stabilization.
115+
116+
- The specification will be written in English and will be freely available under a permissive license
117+
that allows for translations and other derived works, just like all our existing documentation and code.
118+
119+
# Coordination and editing
120+
121+
Writing, editing, and in general coordinating all that's necessary for the creation of a Rust specification is a large amount for work.
122+
While there are many volunteers willing to work on specific parts of it,
123+
it's unlikely we'd end up with a complete, consistent, properly maintained specification if we rely entirely on volunteers.
124+
125+
So this RFC proposes that we ask the Rust Foundation to coordinate and take responsibility
126+
for the parts of the work that would otherwise not get done.
127+
The foundation should hire a technical editor (or perhaps multiple people)
128+
who will work with the Rust teams and contributors to create the Rust specification.
129+
The editor will be responsible for maintaining the document and will coordinate with the relevant teams
130+
(e.g. the language team, the operational semantics team, the compiler, the types team, the library API team, and so on)
131+
to collect all relevant information and make sure that consensus is reached on everything that will end up in the official specification.
132+
133+
The relevant Rust teams keep authority on their respective parts of Rust.
134+
The Rust Foundation supports and coordinates the work, but the Rust teams will remain in charge of what Rust is.
135+
136+
# Questions deliberately left open
137+
138+
This RFC deliberately leaves many questions open, to be answered later in the process.
139+
For example:
140+
141+
- The starting point of the Rust specification.
142+
143+
The Rust specification could take the [Ferrocene Specification](https://spec.ferrocene.dev/) or
144+
the [Rust Reference](https://doc.rust-lang.org/stable/reference/) as starting point,
145+
or start from scratch, as the editor sees fit.
146+
(The contents will still require approval from the Rust teams, regardless.)
147+
148+
- The shape, form, and structure of the document.
149+
150+
- The scope of the Rust specification.
151+
152+
It should include at least all topics covered in
153+
[the Rust Reference](https://doc.rust-lang.org/stable/reference/),
154+
but the scope can grow depending on ongoing efforts in the Rust team and the needs of the Rust community.
155+
156+
- How certain topics will be specified.
157+
158+
Certain parts of the specification might use a formal language
159+
for specifying behavior or syntax.
160+
For example, the grammar might be specified as EBNF,
161+
and parts of the borrow checker or memory model might be specified by
162+
a more formal definition that the document refers to.
163+
164+
- The depth of the specification for various topics.
165+
166+
For example, it might specify only the existence of `#[allow(…)]` (etc.) without naming any lints,
167+
or at the other extreme it might fully specify the behaviour of every single lint.
168+
As another example, it could only specify the overall guarantees of the borrow checker
169+
(e.g. "it won't allow UB in safe code"), or it could precisely specify what currently is and isn't accepted by the borrow checker.
170+
The right level of detail for each topic should be discussed and agreed upon by the involved parties,
171+
and can change over time.

0 commit comments

Comments
 (0)