Skip to content

Commit b31c100

Browse files
author
Rajkumar Natarajan
committed
issue_130_7 updated with review comments
1 parent 9de0e2c commit b31c100

File tree

3 files changed

+170
-136
lines changed

3 files changed

+170
-136
lines changed

src/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- [Adding new tests](./tests/adding.md)
1515
- [Using `compiletest` + commands to control test execution](./compiletest.md)
1616
- [Walkthrough: a typical contribution](./walkthrough.md)
17-
- [Implementing new features](./implementing_new_feature.md)
17+
- [Implementing new features](./implementing_new_features.md)
1818
- [Stabilizing Features](./stabilization_guide.md)
1919
- [Debugging the Compiler](./compiler-debugging.md)
2020
- [Profiling the compiler](./profiling.md)

src/implementing_new_feature.md

-135
This file was deleted.

src/implementing_new_features.md

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Implement New Feature
2+
3+
When you want to implement a new significant feature in the compiler,
4+
you need to go through this process to make sure everything goes
5+
smoothly.
6+
7+
## The @rfcbot (p)FCP process
8+
9+
When the change is small and uncontroversial, then it can be done
10+
with just writing a PR and getting r+ from someone who knows that
11+
part of the code. However, if the change is potentially controversial,
12+
it would be a bad idea to push it without consensus from the rest
13+
of the team (both in the "distributed system" sense to make sure
14+
you don't break anything you don't know about, and in the social
15+
sense to avoid PR fights).
16+
17+
If such a change seems to be too small to require a full formal RFC
18+
process (e.g. a big refactoring of the code, or a
19+
"technically-breaking" change, or a "big bugfix" that basically
20+
amounts to a small feature) but is still too controversial or
21+
big to get by with a single r+, you can start a pFCP (or, if you
22+
don't have r+ rights, ask someone who has them to start one - and
23+
unless they have a concern themselves, they should).
24+
25+
Again, the pFCP process is only needed if you need consensus - if you
26+
don't think anyone would have a problem with your change, it's ok to
27+
get by with only an r+. For example, it is OK to add or modify unstable command-line flags or attributes without an pFCP for compiler
28+
development or standard library use, as long as you don't expect them
29+
to be in wide use in the nightly ecosystem.
30+
31+
You don't need to have the implementation fully ready for r+ to ask
32+
for a pFCP, but it is generally a good idea to have at least a proof
33+
of concept so that people can see what you are talking about.
34+
35+
That starts a "proposed final comment period" (pFCP), which requires
36+
all members of the team to sign off the FCP. After they all do so,
37+
there's a week long "final comment period" where everybody can comment,
38+
and if no new concerns are raised, the PR/issue gets FCP approval.
39+
40+
## The logistics of writing features
41+
42+
There are a few "logistic" hoops you might need to go through in
43+
order to implement a feature in a working way.
44+
45+
### Warning Cycles
46+
47+
In some cases, a feature or bugfix might break some existing programs
48+
in some edge cases. In that case, you might want to do a crater run
49+
to assess the impact and possibly add a future-compatibility lint,
50+
similar to those used for
51+
[edition-gated lints](./diag.md#edition-gated-lints).
52+
53+
### Stability
54+
55+
We [value the stability of Rust]. Code that works and runs on stable
56+
should (mostly) not break. Because of that, we don't want to release
57+
a feature to the world with only team consensus and code review -
58+
we want to gain real-world experience on using that feature on nightly,
59+
and we might want to change the feature based on that experience.
60+
61+
To allow for that, we must make sure users don't accidentally depend
62+
on that new feature - otherwise, especially if experimentation takes
63+
time or is delayed and the feature takes the trains to stable,
64+
it would end up de facto stable and we'll not be able to make changes
65+
in it without breaking people's code.
66+
67+
The way we do that is that we make sure all new features are feature
68+
gated - they can't be used without a enabling a feature gate
69+
`(#[feature(foo)])`, which can't be done in a stable/beta compiler.
70+
See the [stability in code] section for the technical details.
71+
72+
Eventually, after we gain enough experience using the feature,
73+
make the necessary changes, and are satisfied, we expose it to
74+
the world using the stabilization process described [here].
75+
Until then, the feature is not set in stone: every part of the
76+
feature can be changed, or the feature might be completely
77+
rewritten or removed. Features are not supposed to gain tenure
78+
by being unstable and unchanged for a year.
79+
80+
### Tracking Issues
81+
82+
To keep track of the status of an unstable feature, the
83+
experience we get while using it on nightly, and of the
84+
concerns that block its stabilization, every feature-gate
85+
needs a tracking issue.
86+
87+
General discussions about the feature should be done on
88+
the tracking issue.
89+
90+
For features that have an RFC, you should use the RFC's
91+
tracking issue for the feature.
92+
93+
For other features, you'll have to make a tracking issue
94+
for that feature. The issue title should be "Tracking issue
95+
for YOUR FEATURE".
96+
97+
For tracking issues for features (as opposed to future-compat
98+
warnings), I don't think the description has to contain
99+
anything specific. Generally we put the list of items required
100+
for stabilization using a github list, e.g.
101+
102+
```txt
103+
**Steps:**
104+
105+
- [ ] Implement the RFC (cc @rust-lang/compiler -- can anyone write up mentoring instructions?)
106+
- [ ] Adjust documentation ([see instructions on forge][doc-guide])
107+
- Note: no stabilization step here.
108+
```
109+
110+
## Stability in code
111+
112+
The below steps needs to be followed in order to implement
113+
a new unstable feature:
114+
115+
1. Open a [tracking issue] - if you have an RFC, you can use
116+
the tracking issue for the RFC.
117+
118+
2. Pick a name for the feature gate (for RFCs, use the name
119+
in the RFC).
120+
121+
3. Add a feature gate declaration to `libsyntax/feature_gate.rs`
122+
in the active `declare_features` block:
123+
124+
```rust,ignore
125+
// description of feature
126+
(active, $feature_name, "$current_nightly_version", Some($tracking_issue_number), $edition)
127+
```
128+
129+
where `$edition` has the type `Option<Edition>`, and is typically
130+
just `None`.
131+
132+
For example:
133+
134+
```rust,ignore
135+
// allow '|' at beginning of match arms (RFC 1925)
136+
( active, match_beginning_vert, "1.21.0", Some(44101), None),
137+
```
138+
139+
The current version is not actually important – the important
140+
version is when you are stabilizing a feature.
141+
142+
4. Prevent usage of the new feature unless the feature gate is set.
143+
You can check it in most places in the compiler using the
144+
expression `tcx.features().$feature_name` (or
145+
`sess.features_untracked().borrow().$feature_name` if the
146+
tcx is unavailable)
147+
148+
If the feature gate is not set, you should either maintain
149+
the pre-feature behavior or raise an error, depending on
150+
what makes sense.
151+
152+
5. Add a test to ensure the feature cannot be used without
153+
a feature gate, by creating `feature-gate-$feature_name.rs`
154+
and `feature-gate-$feature_name.stderr` files under the
155+
`src/test/ui/feature-gates` directory.
156+
157+
6. Add a section to the unstable book, in
158+
`src/doc/unstable-book/src/language-features/$feature_name.md`.
159+
160+
7. Write a lots of tests for the new feature.
161+
PRs without tests will not be accepted!
162+
163+
8. Get your PR reviewed and land it. You have now successfully
164+
implemented a feature in Rust!
165+
166+
[value the stability of Rust]: https://github.com/rust-lang/rfcs/blob/master/text/1122-language-semver.md
167+
[stability in code]:
168+
[here]: https://rust-lang.github.io/rustc-guide/stabilization_guide.html
169+
[tracking issue]:

0 commit comments

Comments
 (0)