Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Start working on a Rust specification #3355

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions text/0000-rust-spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
- Feature Name: `rust_spec`
- Start Date: 2022-12-06
- RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000)
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)

# Summary
[summary]: #summary

We should start working on a Rust specification.

# Goal of this RFC

The goal of this RFC is to reach consensus on:

- Whether we want a specification, and (if so),
- Some initial goals and non-goals, and
- How we want the work to be organised and coordinated.

This RFC _does not_ define the full scope of the specification
or discuss any details of how it would look like.
It only provides the minimal details necessary to be able to kick off the Rust specification work.

# Motivation

Why do we want a Rust specification at all?

There are many different kind of Rust users that would benefit from a Rust specification in their own way.
Things like the Rust Reference, the Unsafe Code Guidelines Project, the Rustonomicon, and so on,
all exist to fulfill certain needs of Rust users.
Unfortunately, their use is currently limited, because none of these are complete, entirely accurate, or normative.

Authors of unsafe code could benefit a lot from clear definitions of what is and isn't undefined behaviour.
Safety critical Rust software won't pass certification without a specification that clearly specifies how Rust code behaves.
Proposals and discussions about new Rust language features could be more efficient and precise
using accurately defined terms that everyone agrees on.
Questions about subtle interactions between features of the language could be answered
using precise information from a specification, instead a combination of guesses and several non-authoritative sources.

# Current state

Languages like C and C++ are standardized.
Rust is not. Standardization comes down to, basically:

1. Having an accurate specification (a document)
2. An (open) process for evolution of the language
3. Stability

Rust currently already has 2 and 3, but not 1.

For 1, we currently have:
the (incomplete) [Rust Reference](https://doc.rust-lang.org/stable/reference/),
the [Standard Library Reference Documentation](https://doc.rust-lang.org/stable/std/),
the [Rust Nomicon](https://doc.rust-lang.org/nightly/nomicon/),
the [Unsafe Code Guidelines Project](https://github.com/rust-lang/unsafe-code-guidelines/),
[Miri](https://github.com/rust-lang/miri/),
the collection of [accepted RFCs](https://rust-lang.github.io/rfcs/),
the [Ferrocene Language Specification](https://spec.ferrocene.dev/),
lots context and decisions spread over [tons of GitHub issues](https://github.com/rust-lang/rust/issues/),
[MiniRust](https://github.com/RalfJung/minirust),
the [source code](https://github.com/rust-lang/rust/),
and more.

These are currently all incomplete, and/or not a good source to rely on.

More background information is available in [this blog post](https://blog.m-ou.se/rust-standard/).

# Goals and non-goals

- The goal of the Rust specification work is the creation of a document, the Rust specification.

- The goal is _not_ to change how the language evolves;
the relevant teams (Language, Libs-API, …) remain in charge of the evolution of their respective parts of Rust,
and will continue to use processes as they see fit (e.g. RFCs).

- The specification will only be considered "official" once the relevant teams have approved of its contents.
Changes to the official specification must be approved by the relevant team(s).

- The goal is to serve the needs of Rust users, such as
authors of unsafe Rust code, those working on safety critical Rust software,
language designers, maintainers of Rust tooling, and so on.

- It is _not_ a primary goal of the specification to aid in the development of alternative Rust implementations,
although authors of alternative compilers might still find the specification to be useful.

What this means is that, unlike the C or C++ standard,
the Rust specification does not provide a set of requirements for a compiler to be able to call itself "a Rust™ compiler".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete nit, but Rust is a registered trademark, so it should be Rust®, not Rust™.

Instead, it specifies the behaviour of the Rust compiler.
(So, not "A Rust implementation should …", but instead "Rust will …".)

- The scope remains to be determined, but at least includes all topics currently included in
the (incomplete) [Rust Reference](https://doc.rust-lang.org/stable/reference/).

- The Rust specification is expected to replace the current Rust Reference.

- The scope of the specification can grow over time, depending on the needs of Rust users and
time and motivation of those working on it.

For example, it might grow over time to also specify details of Cargo,
compiler flags, procedural macros, or other parts that we might initially consider out of scope.

- The specification is specific to the latest version of Rust.
A copy of the specification is included with each Rust release,
as we currently already do with much of our documentation.

While the specification might include notes about the Rust version that a feature was introduced in
for informative purposes (similar to standard library documentation),
it does not attempt to accurately specify older, unsupported versions of Rust.

- The specification specifies all Rust _editions_, as supported by the latest version of the Rust compiler.

- Once the specification reaches an initial usable version,
the relevant teams are expected to incorporate it in their process for language evolution.
For example, the language team could require a new language feature to be included
in the specification as a requirement for stabilization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the risk of over-specifying things, who would/might be expected to write the language for the standard? My concern is that adding more steps, particularly nontrivial ones, could slow development a fair amount. While I could probably write a spec for some things that I propose, doing so takes a lot of time. Is this where the later-mentioned technical editor would come in?

Copy link
Contributor

@skade skade Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the role of an editor is very often to take the raw bits and make sure there's consistent and strict language all over the document. It also makes sense for that person to be someone who is mainly assigned to that, so that capacity problems are avoided.

From my experience with working with a technical editor, I write up the facts and issues in short form, the longer formulation and cross-checking is up to the editor, and I sign off the final text.

It's also not just additional work: the process of formulating the behaviour together can help in the implementation.

Copy link
Member

@jyn514 jyn514 Dec 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At what point will it be required that a spec exists for new features? If it's never required, the spec becomes non-normative and turns into the Reference we have today, but doing it in an RFC adds a burden like @jhpratt mentioned. My preference is that documenting features in the spec is required before they're stabilized.


- The specification will be written in English and will be freely available under a permissive license
that allows for translations and other derived works, just like all our existing documentation and code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this is not intended to exclude parts of the spec being written in formal languages. :) (e.g., like a-mir-formality or MiniRust)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's not my intention at all. See also this point later in the RFC:

  • How certain topics will be specified.

    Certain parts of the specification might use a formal language for specifying behavior or syntax. For example, the grammar might be specified as EBNF, and parts of the borrow checker or memory model might be specified by a more formal definition that the document refers to.


# Coordination and editing

Writing, editing, and in general coordinating all that's necessary for the creation of a Rust specification is a large amount for work.
While there are many volunteers willing to work on specific parts of it,
it's unlikely we'd end up with a complete, consistent, properly maintained specification if we rely entirely on volunteers.

So this RFC proposes that we ask the Rust Foundation to coordinate and take responsibility
for the parts of the work that would otherwise not get done.
The foundation should hire a technical editor (or perhaps multiple people)
who will work with the Rust teams and contributors to create the Rust specification.
The editor will be responsible for maintaining the document and will coordinate with the relevant teams
(e.g. the language team, the operational semantics team, the compiler, the types team, the library API team, and so on)
to collect all relevant information and make sure that consensus is reached on everything that will end up in the official specification.

The relevant Rust teams keep authority on their respective parts of Rust.
The Rust Foundation supports and coordinates the work, but the Rust teams will remain in charge of what Rust is.

# Questions deliberately left open

This RFC deliberately leaves many questions open, to be answered later in the process.
For example:

- The starting point of the Rust specification.

The Rust specification could take the [Ferrocene Specification](https://spec.ferrocene.dev/) or
the [Rust Reference](https://doc.rust-lang.org/stable/reference/) as starting point,
or start from scratch, as the editor sees fit.
(The contents will still require approval from the Rust teams, regardless.)

- The shape, form, and structure of the document.

- The scope of the Rust specification.

It should include at least all topics covered in
[the Rust Reference](https://doc.rust-lang.org/stable/reference/),
but the scope can grow depending on ongoing efforts in the Rust team and the needs of the Rust community.

- How certain topics will be specified.

Certain parts of the specification might use a formal language
for specifying behavior or syntax.
For example, the grammar might be specified as EBNF,
and parts of the borrow checker or memory model might be specified by
a more formal definition that the document refers to.

- The depth of the specification for various topics.

For example, it might specify only the existence of `#[allow(…)]` (etc.) without naming any lints,
or at the other extreme it might fully specify the behaviour of every single lint.
As another example, it could only specify the overall guarantees of the borrow checker
(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.
The right level of detail for each topic should be discussed and agreed upon by the involved parties,
and can change over time.