Skip to content

Commit 3b17667

Browse files
committed
Merge from rust-lang/rust
2 parents 4828149 + b6b204e commit 3b17667

20 files changed

+181
-102
lines changed

.github/workflows/rustc-pull.yml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: rustc-pull
33
on:
44
workflow_dispatch:
55
schedule:
6-
# Run at 04:00 UTC every Monday
7-
- cron: '0 4 * * 1'
6+
# Run at 04:00 UTC every Monday and Thursday
7+
- cron: '0 4 * * 1,4'
88

99
jobs:
1010
pull:
@@ -34,15 +34,35 @@ jobs:
3434
git config --global user.name 'The rustc-dev-guide Cronjob Bot'
3535
git config --global user.email 'github-actions@github.com'
3636
- name: Perform rustc-pull
37-
run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull
37+
id: rustc-pull
38+
# Turn off -e to disable early exit
39+
shell: bash {0}
40+
run: |
41+
cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull
42+
exitcode=$?
43+
44+
# If no pull was performed, we want to mark this job as successful,
45+
# but we do not want to perform the follow-up steps.
46+
if [ $exitcode -eq 0 ]; then
47+
echo "pull_result=pull-finished" >> $GITHUB_OUTPUT
48+
elif [ $exitcode -eq 2 ]; then
49+
echo "pull_result=skipped" >> $GITHUB_OUTPUT
50+
exitcode=0
51+
fi
52+
53+
exit ${exitcode}
3854
- name: Push changes to a branch
55+
if: ${{ steps.rustc-pull.outputs.pull_result == 'pull-finished' }}
3956
run: |
4057
# Update a sticky branch that is used only for rustc pulls
4158
BRANCH="rustc-pull"
4259
git switch -c $BRANCH
4360
git push -u origin $BRANCH --force
4461
- name: Create pull request
4562
id: update-pr
63+
if: ${{ steps.rustc-pull.outputs.pull_result == 'pull-finished' }}
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4666
run: |
4767
# Check if an open pull request for an rustc pull update already exists
4868
# If it does, the previous push has just updated it
@@ -54,26 +74,35 @@ jobs:
5474
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
5575
else
5676
PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`
77+
echo "Updating pull request ${PR_URL}"
5778
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
5879
fi
59-
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6180
send-zulip-message:
6281
needs: [pull]
6382
if: ${{ !cancelled() }}
6483
runs-on: ubuntu-latest
6584
steps:
85+
- uses: actions/checkout@v4
6686
- name: Compute message
67-
id: message
87+
id: create-message
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6890
run: |
69-
if [ "${{ needs.pull.result }}" == "failure" ];
70-
then
91+
if [ "${{ needs.pull.result }}" == "failure" ]; then
7192
WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
7293
echo "message=Rustc pull sync failed. Check out the [workflow URL]($WORKFLOW_URL)." >> $GITHUB_OUTPUT
7394
else
74-
echo "message=Rustc pull sync succeeded. Check out the [PR](${{ needs.pull.outputs.pr_url }})." >> $GITHUB_OUTPUT
95+
CREATED_AT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].createdAt' --json createdAt,title`
96+
PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`
97+
week_ago=$(date +%F -d '7 days ago')
98+
99+
# If there is an open PR that is at least a week old, post a message about it
100+
if [[ -n $DATE_GH && $DATE_GH < $week_ago ]]; then
101+
echo "message=A PR with a Rustc pull has been opened for more a week. Check out the [PR](${PR_URL})." >> $GITHUB_OUTPUT
102+
fi
75103
fi
76104
- name: Send a Zulip message about updated PR
105+
if: ${{ steps.create-message.outputs.message != '' }}
77106
uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5
78107
with:
79108
api-key: ${{ secrets.ZULIP_API_TOKEN }}

examples/rustc-driver-interacting-with-the-ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl rustc_driver::Callbacks for MyCallbacks {
7575
let item = hir_krate.item(id);
7676
// Use pattern-matching to find a specific node inside the main function.
7777
if let rustc_hir::ItemKind::Fn(_, _, body_id) = item.kind {
78-
let expr = &tcx.hir().body(body_id).value;
78+
let expr = &tcx.hir_body(body_id).value;
7979
if let rustc_hir::ExprKind::Block(block, _) = expr.kind {
8080
if let rustc_hir::StmtKind::Let(let_stmt) = block.stmts[0].kind {
8181
if let Some(expr) = let_stmt.init {

josh-sync/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::Parser;
2-
use crate::sync::GitSync;
2+
use crate::sync::{GitSync, RustcPullError};
33

44
mod sync;
55

@@ -22,7 +22,18 @@ fn main() -> anyhow::Result<()> {
2222
let sync = GitSync::from_current_dir()?;
2323
match args {
2424
Args::RustcPull => {
25-
sync.rustc_pull(None)?;
25+
if let Err(error) = sync.rustc_pull(None) {
26+
match error {
27+
RustcPullError::NothingToPull => {
28+
eprintln!("Nothing to pull");
29+
std::process::exit(2);
30+
}
31+
RustcPullError::PullFailed(error) => {
32+
eprintln!("Pull failure: {error:?}");
33+
std::process::exit(1);
34+
}
35+
}
36+
}
2637
}
2738
Args::RustcPush { github_username, branch } => {
2839
sync.rustc_push(github_username, branch)?;

josh-sync/src/sync.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ const JOSH_FILTER: &str = ":/src/doc/rustc-dev-guide";
1111
const JOSH_PORT: u16 = 42042;
1212
const UPSTREAM_REPO: &str = "rust-lang/rust";
1313

14+
pub enum RustcPullError {
15+
/// No changes are available to be pulled.
16+
NothingToPull,
17+
/// A rustc-pull has failed, probably a git operation error has occurred.
18+
PullFailed(anyhow::Error)
19+
}
20+
21+
impl<E> From<E> for RustcPullError where E: Into<anyhow::Error> {
22+
fn from(error: E) -> Self {
23+
Self::PullFailed(error.into())
24+
}
25+
}
26+
1427
pub struct GitSync {
1528
dir: PathBuf,
1629
}
@@ -24,7 +37,7 @@ impl GitSync {
2437
})
2538
}
2639

27-
pub fn rustc_pull(&self, commit: Option<String>) -> anyhow::Result<()> {
40+
pub fn rustc_pull(&self, commit: Option<String>) -> Result<(), RustcPullError> {
2841
let sh = Shell::new()?;
2942
sh.change_dir(&self.dir);
3043
let commit = commit.map(Ok).unwrap_or_else(|| {
@@ -38,7 +51,7 @@ impl GitSync {
3851
})?;
3952
// Make sure the repo is clean.
4053
if cmd!(sh, "git status --untracked-files=no --porcelain").read()?.is_empty().not() {
41-
bail!("working directory must be clean before performing rustc pull");
54+
return Err(anyhow::anyhow!("working directory must be clean before performing rustc pull").into());
4255
}
4356
// Make sure josh is running.
4457
let josh = Self::start_josh()?;
@@ -47,7 +60,7 @@ impl GitSync {
4760

4861
let previous_base_commit = sh.read_file("rust-version")?.trim().to_string();
4962
if previous_base_commit == commit {
50-
return Err(anyhow::anyhow!("No changes since last pull"));
63+
return Err(RustcPullError::NothingToPull);
5164
}
5265

5366
// Update rust-version file. As a separate commit, since making it part of
@@ -94,12 +107,13 @@ impl GitSync {
94107
cmd!(sh, "git reset --hard HEAD^")
95108
.run()
96109
.expect("FAILED to clean up after creating the preparation commit");
97-
return Err(anyhow::anyhow!("No merge was performed, nothing to pull. Rolled back the preparation commit."));
110+
eprintln!("No merge was performed, no changes to pull were found. Rolled back the preparation commit.");
111+
return Err(RustcPullError::NothingToPull);
98112
}
99113

100114
// Check that the number of roots did not increase.
101115
if num_roots()? != num_roots_before {
102-
bail!("Josh created a new root commit. This is probably not the history you want.");
116+
return Err(anyhow::anyhow!("Josh created a new root commit. This is probably not the history you want.").into());
103117
}
104118

105119
drop(josh);

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
66d6064f9eb888018775e08f84747ee6f39ba28e
1+
124cc92199ffa924f6b4c7cc819a85b65e0c3984

src/appendix/bibliography.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Rust, as well as publications about Rust.
8282
* [Ownership is Theft: Experiences Building an Embedded OS in Rust - Amit Levy, et. al.](https://amitlevy.com/papers/tock-plos2015.pdf)
8383
* [You can't spell trust without Rust](https://faultlore.com/blah/papers/thesis.pdf). Aria Beingessner's master's thesis.
8484
* [Rust-Bio: a fast and safe bioinformatics library](https://rust-bio.github.io/). Johannes Köster
85-
* [Safe, Correct, and Fast Low-Level Networking](https://octarineparrot.com/assets/msci_paper.pdf). Robert Clipsham's master's thesis.
85+
* [Safe, Correct, and Fast Low-Level Networking](https://csperkins.org/research/thesis-msci-clipsham.pdf). Robert Clipsham's master's thesis.
8686
* [Formalizing Rust traits](https://open.library.ubc.ca/cIRcle/collections/ubctheses/24/items/1.0220521). Jonatan Milewski's master's thesis.
8787
* [Rust as a Language for High Performance GC Implementation](https://dl.acm.org/doi/pdf/10.1145/3241624.2926707)
8888
* [Simple Verification of Rust Programs via Functional Purification](https://github.com/Kha/electrolysis). Sebastian Ullrich's master's thesis.

src/building/bootstrapping/debugging-bootstrap.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ $ BOOTSTRAP_TRACING=CONFIG_HANDLING=TRACE ./x build library --stage 1
7676

7777
[tracing-env-filter]: https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html
7878

79+
##### FIXME(#96176): specific tracing for `compiler()` vs `compiler_for()`
80+
81+
The additional targets `COMPILER` and `COMPILER_FOR` are used to help trace what
82+
`builder.compiler()` and `builder.compiler_for()` does. They should be removed
83+
if [#96176][cleanup-compiler-for] is resolved.
84+
85+
[cleanup-compiler-for]: https://github.com/rust-lang/rust/issues/96176
86+
7987
### Using `tracing` in bootstrap
8088

8189
Both `tracing::*` macros and the `tracing::instrument` proc-macro attribute need to be gated behind `tracing` feature. Examples:
@@ -121,6 +129,14 @@ For `#[instrument]`, it's recommended to:
121129
- Explicitly pick an instrumentation name via `name = ".."` to distinguish between e.g. `run` of different steps.
122130
- Take care to not cause diverging behavior via tracing, e.g. building extra things only when tracing infra is enabled.
123131

132+
### Profiling bootstrap
133+
134+
You can use the `COMMAND` tracing target to trace execution of most commands spawned by bootstrap. If you also use the `BOOTSTRAP_PROFILE=1` environment variable, bootstrap will generate a Chrome JSON trace file, which can be visualized in Chrome's `chrome://tracing` page or on https://ui.perfetto.dev.
135+
136+
```bash
137+
$ BOOTSTRAP_TRACING=COMMAND=trace BOOTSTRAP_PROFILE=1 ./x build library
138+
```
139+
124140
### rust-analyzer integration?
125141

126142
Unfortunately, because bootstrap is a `rust-analyzer.linkedProjects`, you can't ask r-a to check/build bootstrap itself with `tracing` feature enabled to get relevant completions, due to lack of support as described in <https://github.com/rust-lang/rust-analyzer/issues/8521>.

src/building/suggested.md

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,24 @@ and follow the same instructions as above.
135135
### Emacs
136136

137137
Emacs provides support for rust-analyzer with project-local configuration
138-
through [Eglot](https://www.gnu.org/software/emacs/manual/html_node/eglot/).
138+
through [Eglot](https://www.gnu.org/software/emacs/manual/html_node/eglot/).
139139
Steps for setting up Eglot with rust-analyzer can be [found
140-
here](https://rust-analyzer.github.io/manual.html#eglot).
140+
here](https://rust-analyzer.github.io/manual.html#eglot).
141141
Having set up Emacs & Eglot for Rust development in general, you can run
142142
`./x setup editor` and select `emacs`, which will prompt you to create
143143
`.dir-locals.el` with the recommended configuration for Eglot.
144-
The recommended settings live at [`src/etc/rust_analyzer_eglot.el`].
144+
The recommended settings live at [`src/etc/rust_analyzer_eglot.el`].
145145
For more information on project-specific Eglot configuration, consult [the
146146
manual](https://www.gnu.org/software/emacs/manual/html_node/eglot/Project_002dspecific-configuration.html).
147147

148148
### Helix
149149

150-
Helix comes with built-in LSP and rust-analyzer support.
150+
Helix comes with built-in LSP and rust-analyzer support.
151151
It can be configured through `languages.toml`, as described
152-
[here](https://docs.helix-editor.com/languages.html).
152+
[here](https://docs.helix-editor.com/languages.html).
153153
You can run `./x setup editor` and select `helix`, which will prompt you to
154154
create `languages.toml` with the recommended configuration for Helix. The
155-
recommended settings live at [`src/etc/rust_analyzer_helix.toml`].
155+
recommended settings live at [`src/etc/rust_analyzer_helix.toml`].
156156

157157
## Check, check, and check again
158158

@@ -181,7 +181,7 @@ example, running `tidy` and `linkchecker` is useful when editing Markdown files,
181181
whereas UI tests are much less likely to be helpful. While `x suggest` is a
182182
useful tool, it does not guarantee perfect coverage (just as PR CI isn't a
183183
substitute for bors). See the [dedicated chapter](../tests/suggest-tests.md) for
184-
more information and contribution instructions.
184+
more information and contribution instructions.
185185

186186
Please note that `x suggest` is in a beta state currently and the tests that it
187187
will suggest are limited.
@@ -332,29 +332,22 @@ git worktree add -b my-feature ../rust2 master
332332
You can then use that rust2 folder as a separate workspace for modifying and
333333
building `rustc`!
334334

335-
## Using nix-shell
335+
## Working with nix
336336

337-
If you're using nix, you can use the following nix-shell to work on Rust:
337+
Several nix configurations are defined in `src/tools/nix-dev-shell`.
338338

339-
```nix
340-
{ pkgs ? import <nixpkgs> {} }:
341-
pkgs.mkShell {
342-
name = "rustc";
343-
nativeBuildInputs = with pkgs; [
344-
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
345-
];
346-
buildInputs = with pkgs; [
347-
openssl glibc.out glibc.static
348-
];
349-
# Avoid creating text files for ICEs.
350-
RUSTC_ICE = "0";
351-
# Provide `libstdc++.so.6` for the self-contained lld.
352-
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [
353-
stdenv.cc.cc.lib
354-
]}";
355-
}
339+
If you're using direnv, you can create a symbol link to `src/tools/nix-dev-shell/envrc-flake` or `src/tools/nix-dev-shell/envrc-shell`
340+
341+
```bash
342+
ln -s ./src/tools/nix-dev-shell/envrc-flake ./.envrc # Use flake
343+
```
344+
or
345+
```bash
346+
ln -s ./src/tools/nix-dev-shell/envrc-shell ./.envrc # Use nix-shell
356347
```
357348

349+
### Note
350+
358351
Note that when using nix on a not-NixOS distribution, it may be necessary to set
359352
**`patch-binaries-for-nix = true` in `config.toml`**. Bootstrap tries to detect
360353
whether it's running in nix and enable patching automatically, but this

src/diagnostics.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ The trait implementation allows you to check certain syntactic constructs
601601
as the linter walks the AST. You can then choose to emit lints in a
602602
very similar way to compile errors.
603603

604-
You also declare the metadata of a particular lint via the `declare_lint!`
605-
macro. [This macro](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html) includes the name, the default level, a short description, and some
604+
You also declare the metadata of a particular lint via the [`declare_lint!`]
605+
macro. This macro includes the name, the default level, a short description, and some
606606
more details.
607607

608608
Note that the lint and the lint pass must be registered with the compiler.
@@ -671,6 +671,8 @@ example-use-loop = denote infinite loops with `loop {"{"} ... {"}"}`
671671
.suggestion = use `loop`
672672
```
673673

674+
[`declare_lint!`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html
675+
674676
### Edition-gated lints
675677

676678
Sometimes we want to change the behavior of a lint in a new edition. To do this,

src/getting-started.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ it's easy to pick up work without a large time commitment:
101101
- [Rustdoc Askama Migration](https://github.com/rust-lang/rust/issues/108868)
102102
- [Diagnostic Translation](https://github.com/rust-lang/rust/issues/100717)
103103
- [Move UI tests to subdirectories](https://github.com/rust-lang/rust/issues/73494)
104-
- [Port run-make tests from Make to Rust](https://github.com/rust-lang/rust/issues/121876)
105104

106105
If you find more recurring work, please feel free to add it here!
107106

src/implementing_new_features.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ smoothly.
99
**NOTE: this section is for *language* features, not *library* features,
1010
which use [a different process].**
1111

12+
See also [the Rust Language Design Team's procedures][lang-propose] for
13+
proposing changes to the language.
14+
1215
[a different process]: ./stability.md
16+
[lang-propose]: https://lang-team.rust-lang.org/how_to/propose.html
1317

1418
## The @rfcbot FCP process
1519

src/mir/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ The most important rule for
304304
this representation is that every value must be uniquely represented. In other
305305
words: a specific value must only be representable in one specific way. For example: there is only
306306
one way to represent an array of two integers as a `ValTree`:
307-
`ValTree::Branch(&[ValTree::Leaf(first_int), ValTree::Leaf(second_int)])`.
307+
`Branch([Leaf(first_int), Leaf(second_int)])`.
308308
Even though theoretically a `[u32; 2]` could be encoded in a `u64` and thus just be a
309-
`ValTree::Leaf(bits_of_two_u32)`, that is not a legal construction of `ValTree`
309+
`Leaf(bits_of_two_u32)`, that is not a legal construction of `ValTree`
310310
(and is very complex to do, so it is unlikely anyone is tempted to do so).
311311

312312
These rules also mean that some values are not representable. There can be no `union`s in type

src/parallel-rustc.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ are implemented differently depending on whether `parallel-compiler` is true.
4646

4747
| data structure | parallel | non-parallel |
4848
| -------------------------------- | --------------------------------------------------- | ------------ |
49-
| Weak | std::sync::Weak | std::rc::Weak |
50-
| Atomic{Bool}/{Usize}/{U32}/{U64} | std::sync::atomic::Atomic{Bool}/{Usize}/{U32}/{U64} | (std::cell::Cell<bool/usize/u32/u64>) |
5149
| OnceCell | std::sync::OnceLock | std::cell::OnceCell |
5250
| Lock\<T> | (parking_lot::Mutex\<T>) | (std::cell::RefCell) |
5351
| RwLock\<T> | (parking_lot::RwLock\<T>) | (std::cell::RefCell) |
@@ -58,7 +56,6 @@ are implemented differently depending on whether `parallel-compiler` is true.
5856
| WriteGuard | parking_lot::RwLockWriteGuard | std::cell::RefMut |
5957
| MappedWriteGuard | parking_lot::MappedRwLockWriteGuard | std::cell::RefMut |
6058
| LockGuard | parking_lot::MutexGuard | std::cell::RefMut |
61-
| MappedLockGuard | parking_lot::MappedMutexGuard | std::cell::RefMut |
6259

6360
- These thread-safe data structures are interspersed during compilation which
6461
can cause lock contention resulting in degraded performance as the number of
@@ -173,12 +170,10 @@ Here are some resources that can be used to learn more:
173170
- [This list of interior mutability in the compiler by nikomatsakis][imlist]
174171

175172
[`rayon`]: https://crates.io/crates/rayon
176-
[Arc]: https://doc.rust-lang.org/std/sync/struct.Arc.html
177173
[imlist]: https://github.com/nikomatsakis/rustc-parallelization/blob/master/interior-mutability-list.md
178174
[irlo0]: https://internals.rust-lang.org/t/parallelizing-rustc-using-rayon/6606
179175
[irlo1]: https://internals.rust-lang.org/t/help-test-parallel-rustc/11503
180176
[monomorphization]: backend/monomorph.md
181177
[parallel-rustdoc]: https://github.com/rust-lang/rust/issues/82741
182-
[Rc]: https://doc.rust-lang.org/std/rc/struct.Rc.html
183178
[rustc-rayon]: https://github.com/rust-lang/rustc-rayon
184179
[tracking]: https://github.com/rust-lang/rust/issues/48685

0 commit comments

Comments
 (0)