Skip to content

Commit 8767aeb

Browse files
authored
Merge pull request #19126 from lnicola/sync-from-rust
minor: Sync from downstream
2 parents a888bf3 + 5b39181 commit 8767aeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+359
-215
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ jobs:
3535
~/.cargo/bin
3636
key: ${{ runner.os }}-${{ env.MDBOOK_VERSION }}--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ env.MDBOOK_TOC_VERSION }}--${{ env.MDBOOK_MERMAID_VERSION }}
3737

38-
- name: Cache linkcheck
39-
uses: actions/cache@v4
38+
- name: Restore cached Linkcheck
39+
if: github.event_name == 'schedule'
40+
id: cache-linkcheck-restore
41+
uses: actions/cache/restore@v4
4042
with:
41-
path: |
42-
~/book/linkcheck
43-
key: ${{ runner.os }}-${{ hashFiles('./book/linkcheck') }}
43+
path: book/linkcheck/cache.json
44+
key: linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ github.run_id }}
45+
restore-keys: |
46+
linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--
4447
4548
- name: Install latest nightly Rust toolchain
4649
if: steps.mdbook-cache.outputs.cache-hit != 'true'
@@ -59,6 +62,14 @@ jobs:
5962
- name: Check build
6063
run: ENABLE_LINKCHECK=1 mdbook build
6164

65+
- name: Save cached Linkcheck
66+
id: cache-linkcheck-save
67+
if: ${{ !cancelled() && github.event_name == 'schedule' }}
68+
uses: actions/cache/save@v4
69+
with:
70+
path: book/linkcheck/cache.json
71+
key: linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ github.run_id }}
72+
6273
- name: Deploy to gh-pages
6374
if: github.event_name == 'push'
6475
run: |

.github/workflows/rustc-pull.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: rustc-pull
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# Run at 04:00 UTC every Monday
7+
- cron: '0 4 * * 1'
8+
9+
jobs:
10+
pull:
11+
if: github.repository == 'rust-lang/rustc-dev-guide'
12+
runs-on: ubuntu-latest
13+
outputs:
14+
pr_url: ${{ steps.update-pr.outputs.pr_url }}
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
# We need the full history for josh to work
22+
fetch-depth: '0'
23+
- name: Install stable Rust toolchain
24+
run: rustup update stable
25+
- uses: Swatinem/rust-cache@v2
26+
with:
27+
workspaces: "josh-sync"
28+
# Cache the josh directory with checked out rustc
29+
cache-directories: "/home/runner/.cache/rustc-dev-guide-josh"
30+
- name: Install josh
31+
run: RUSTFLAGS="--cap-lints warn" cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04
32+
- name: Setup bot git name and email
33+
run: |
34+
git config --global user.name 'The rustc-dev-guide Cronjob Bot'
35+
git config --global user.email 'github-actions@github.com'
36+
- name: Perform rustc-pull
37+
run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull
38+
- name: Push changes to a branch
39+
run: |
40+
# Update a sticky branch that is used only for rustc pulls
41+
BRANCH="rustc-pull"
42+
git switch -c $BRANCH
43+
git push -u origin $BRANCH --force
44+
- name: Create pull request
45+
id: update-pr
46+
run: |
47+
# Check if an open pull request for an rustc pull update already exists
48+
# If it does, the previous push has just updated it
49+
# If not, we create it now
50+
RESULT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | length' --json title`
51+
if [[ "$RESULT" -eq 0 ]]; then
52+
echo "Creating new pull request"
53+
PR_URL=`gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.'`
54+
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
55+
else
56+
PR_URL=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | .[0].url' --json url,title`
57+
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
58+
fi
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
send-zulip-message:
62+
needs: [pull]
63+
if: ${{ !cancelled() }}
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Compute message
67+
id: message
68+
run: |
69+
if [ "${{ needs.pull.result }}" == "failure" ];
70+
then
71+
WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
72+
echo "message=Rustc pull sync failed. Check out the [workflow URL]($WORKFLOW_URL)." >> $GITHUB_OUTPUT
73+
else
74+
echo "message=Rustc pull sync succeeded. Check out the [PR](${{ needs.pull.outputs.pr_url }})." >> $GITHUB_OUTPUT
75+
fi
76+
- name: Send a Zulip message about updated PR
77+
uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5
78+
with:
79+
api-key: ${{ secrets.ZULIP_API_TOKEN }}
80+
email: "rustc-dev-guide-gha-notif-bot@rust-lang.zulipchat.com"
81+
organization-url: "https://rust-lang.zulipchat.com"
82+
to: 196385
83+
type: "stream"
84+
topic: "Subtree sync automation"
85+
content: ${{ steps.message.outputs.message }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ ci/date-check/target/
44

55
# Generated by check-in.sh
66
pulls.json
7+
8+
josh-sync/target

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ including the `<!-- toc -->` marker at the place where you want the TOC.
7474

7575
This repository is linked to `rust-lang/rust` as a [josh](https://josh-project.github.io/josh/intro.html) subtree. You can use the following commands to synchronize the subtree in both directions.
7676

77+
You'll need to install `josh-proxy` locally via
78+
79+
```
80+
cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04
81+
```
82+
Older versions of `josh-proxy` may not round trip commits losslessly so it is important to install this exact version.
83+
7784
### Pull changes from `rust-lang/rust` into this repository
7885
1) Checkout a new branch that will be used to create a PR into `rust-lang/rustc-dev-guide`
7986
2) Run the pull command

book.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ exclude = [
5252
# 500 is returned for HEAD request
5353
"code\\.visualstudio\\.com/docs/editor/tasks",
5454
]
55-
cache-timeout = 86400
55+
# The scheduled CI runs every day and so we need to reuse a part of the cache
56+
# in order to face "Server returned 429 Too Many Requests" errors for github.com.
57+
cache-timeout = 90000
5658
warning-policy = "error"
5759

5860
[output.html.redirect]

examples/rustc-driver-example.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ extern crate rustc_span;
1515

1616
use std::io;
1717
use std::path::Path;
18+
use std::sync::Arc;
1819

1920
use rustc_ast_pretty::pprust::item_to_string;
20-
use rustc_data_structures::sync::Lrc;
21-
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
21+
use rustc_driver::{Compilation, run_compiler};
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -43,18 +43,22 @@ fn main() {
4343
}
4444
}
4545

46-
fn read_binary_file(&self, _path: &Path) -> io::Result<Lrc<[u8]>> {
46+
fn read_binary_file(&self, _path: &Path) -> io::Result<Arc<[u8]>> {
4747
Err(io::Error::other("oops"))
4848
}
4949
}
5050

5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
57-
krate: &rustc_ast::Crate,
61+
krate: &mut rustc_ast::Crate,
5862
) -> Compilation {
5963
for item in &krate.items {
6064
println!("{}", item_to_string(&item));
@@ -83,10 +87,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
8387
}
8488

8589
fn main() {
86-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
87-
mut compiler => {
88-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
89-
compiler.run();
90-
}
91-
}
90+
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
9291
}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ extern crate rustc_span;
1515

1616
use std::io;
1717
use std::path::Path;
18+
use std::sync::Arc;
1819

1920
use rustc_ast_pretty::pprust::item_to_string;
20-
use rustc_data_structures::sync::Lrc;
21-
use rustc_driver::{Compilation, RunCompiler};
22-
use rustc_interface::interface::Compiler;
21+
use rustc_driver::{Compilation, run_compiler};
22+
use rustc_interface::interface::{Compiler, Config};
2323
use rustc_middle::ty::TyCtxt;
2424

2525
struct MyFileLoader;
@@ -43,18 +43,22 @@ fn main() {
4343
}
4444
}
4545

46-
fn read_binary_file(&self, _path: &Path) -> io::Result<Lrc<[u8]>> {
46+
fn read_binary_file(&self, _path: &Path) -> io::Result<Arc<[u8]>> {
4747
Err(io::Error::other("oops"))
4848
}
4949
}
5050

5151
struct MyCallbacks;
5252

5353
impl rustc_driver::Callbacks for MyCallbacks {
54+
fn config(&mut self, config: &mut Config) {
55+
config.file_loader = Some(Box::new(MyFileLoader));
56+
}
57+
5458
fn after_crate_root_parsing(
5559
&mut self,
5660
_compiler: &Compiler,
57-
krate: &rustc_ast::Crate,
61+
krate: &mut rustc_ast::Crate,
5862
) -> Compilation {
5963
for item in &krate.items {
6064
println!("{}", item_to_string(&item));
@@ -90,10 +94,5 @@ impl rustc_driver::Callbacks for MyCallbacks {
9094
}
9195

9296
fn main() {
93-
match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) {
94-
mut compiler => {
95-
compiler.set_file_loader(Some(Box::new(MyFileLoader)));
96-
compiler.run();
97-
}
98-
}
97+
run_compiler(&["main.rs".to_string()], &mut MyCallbacks);
9998
}

examples/rustc-interface-getting-diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ extern crate rustc_interface;
1010
extern crate rustc_session;
1111
extern crate rustc_span;
1212

13+
use std::sync::{Arc, Mutex};
14+
1315
use rustc_errors::emitter::Emitter;
1416
use rustc_errors::registry::{self, Registry};
1517
use rustc_errors::translation::Translate;
1618
use rustc_errors::{DiagCtxt, DiagInner, FluentBundle};
1719
use rustc_session::config;
1820
use rustc_span::source_map::SourceMap;
1921

20-
use std::sync::{Arc, Mutex};
21-
2222
struct DebugEmitter {
2323
source_map: Arc<SourceMap>,
2424
diagnostics: Arc<Mutex<Vec<DiagInner>>>,
@@ -67,10 +67,10 @@ fn main() {
6767
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES.to_owned(),
6868
lint_caps: rustc_hash::FxHashMap::default(),
6969
psess_created: Some(Box::new(|parse_sess| {
70-
parse_sess.set_dcx(DiagCtxt::new(Box::new(DebugEmitter {
70+
parse_sess.dcx().set_emitter(Box::new(DebugEmitter {
7171
source_map: parse_sess.clone_source_map(),
7272
diagnostics,
73-
})));
73+
}));
7474
})),
7575
register_lints: None,
7676
override_queries: None,

josh-sync/src/sync.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ impl GitSync {
4545
let josh_url =
4646
format!("http://localhost:{JOSH_PORT}/{UPSTREAM_REPO}.git@{commit}{JOSH_FILTER}.git");
4747

48+
let previous_base_commit = sh.read_file("rust-version")?.trim().to_string();
49+
if previous_base_commit == commit {
50+
return Err(anyhow::anyhow!("No changes since last pull"));
51+
}
52+
4853
// Update rust-version file. As a separate commit, since making it part of
4954
// the merge has confused the heck out of josh in the past.
5055
// We pass `--no-verify` to avoid running git hooks.
@@ -76,12 +81,22 @@ impl GitSync {
7681
};
7782
let num_roots_before = num_roots()?;
7883

84+
let sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout;
85+
7986
// Merge the fetched commit.
8087
const MERGE_COMMIT_MESSAGE: &str = "Merge from rustc";
8188
cmd!(sh, "git merge FETCH_HEAD --no-verify --no-ff -m {MERGE_COMMIT_MESSAGE}")
8289
.run()
8390
.context("FAILED to merge new commits, something went wrong")?;
8491

92+
let current_sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout;
93+
if current_sha == sha {
94+
cmd!(sh, "git reset --hard HEAD^")
95+
.run()
96+
.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."));
98+
}
99+
85100
// Check that the number of roots did not increase.
86101
if num_roots()? != num_roots_before {
87102
bail!("Josh created a new root commit. This is probably not the history you want.");

rust-version

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

src/about-this-guide.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ You might also find the following sites useful:
7272
- The [Rust reference][rr], even though it doesn't specifically talk about
7373
Rust's internals, is a great resource nonetheless
7474
- Although out of date, [Tom Lee's great blog article][tlgba] is very helpful
75-
- [rustaceans.org][ro] is helpful, but mostly dedicated to IRC
7675
- The [Rust Compiler Testing Docs][rctd]
7776
- For [@bors], [this cheat sheet][cheatsheet] is helpful
7877
- Google is always helpful when programming.

src/appendix/code-index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ Item | Kind | Short description | Chapter |
1414
`Diag` | struct | A struct for a compiler diagnostic, such as an error or lint | [Emitting Diagnostics] | [compiler/rustc_errors/src/diagnostic.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.Diag.html)
1515
`DocContext` | struct | A state container used by rustdoc when crawling through a crate to gather its documentation | [Rustdoc] | [src/librustdoc/core.rs](https://github.com/rust-lang/rust/blob/master/src/librustdoc/core.rs)
1616
`HirId` | struct | One of four types of HIR node identifiers | [Identifiers in the HIR] | [compiler/rustc_hir/src/hir_id.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir_id/struct.HirId.html)
17+
`Lexer` | struct | This is the lexer used during parsing. It consumes characters from the raw source code being compiled and produces a series of tokens for use by the rest of the parser | [The parser] | [compiler/rustc_parse/src/lexer/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/lexer/struct.Lexer.html)
1718
`NodeId` | struct | One of four types of HIR node identifiers. Being phased out | [Identifiers in the HIR] | [compiler/rustc_ast/src/ast.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/node_id/struct.NodeId.html)
1819
`P` | struct | An owned immutable smart pointer. By contrast, `&T` is not owned, and `Box<T>` is not immutable. | None | [compiler/rustc_ast/src/ptr.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ptr/struct.P.html)
1920
`ParamEnv` | struct | Information about generic parameters or `Self`, useful for working with associated or generic items | [Parameter Environment] | [compiler/rustc_middle/src/ty/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.ParamEnv.html)
2021
`ParseSess` | struct | This struct contains information about a parsing session | [The parser] | [compiler/rustc_session/src/parse/parse.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/parse/struct.ParseSess.html)
21-
`Query` | struct | Represents the result of query to the `Compiler` interface and allows stealing, borrowing, and returning the results of compiler passes. | [The Rustc Driver and Interface] | [compiler/rustc_interface/src/queries.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/queries/struct.Query.html)
2222
`Rib` | struct | Represents a single scope of names | [Name resolution] | [compiler/rustc_resolve/src/lib.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/late/struct.Rib.html)
2323
`Session` | struct | The data associated with a compilation session | [The parser], [The Rustc Driver and Interface] | [compiler/rustc_session/src/session.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/struct.Session.html)
2424
`SourceFile` | struct | Part of the `SourceMap`. Maps AST nodes to their source code for a single source file. Was previously called FileMap | [The parser] | [compiler/rustc_span/src/lib.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.SourceFile.html)
2525
`SourceMap` | struct | Maps AST nodes to their source code. It is composed of `SourceFile`s. Was previously called CodeMap | [The parser] | [compiler/rustc_span/src/source_map.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/source_map/struct.SourceMap.html)
2626
`Span` | struct | A location in the user's source code, used for error reporting primarily | [Emitting Diagnostics] | [compiler/rustc_span/src/span_encoding.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html)
27-
`StringReader` | struct | This is the lexer used during parsing. It consumes characters from the raw source code being compiled and produces a series of tokens for use by the rest of the parser | [The parser] | [compiler/rustc_parse/src/lexer/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/lexer/struct.StringReader.html)
2827
`rustc_ast::token_stream::TokenStream` | struct | An abstract sequence of tokens, organized into `TokenTree`s | [The parser], [Macro expansion] | [compiler/rustc_ast/src/tokenstream.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/tokenstream/struct.TokenStream.html)
2928
`TraitDef` | struct | This struct contains a trait's definition with type information | [The `ty` modules] | [compiler/rustc_middle/src/ty/trait_def.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/trait_def/struct.TraitDef.html)
3029
`TraitRef` | struct | The combination of a trait and its input types (e.g. `P0: Trait<P1...Pn>`) | [Trait Solving: Goals and Clauses] | [compiler/rustc_middle/src/ty/sty.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/type.TraitRef.html)

src/appendix/glossary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Term | Meaning
6969
<span id="rib">rib</span> | A data structure in the name resolver that keeps track of a single scope for names. ([see more](../name-resolution.md))
7070
<span id="rpit">RPIT</span> | A return-position `impl Trait`. ([see the reference](https://doc.rust-lang.org/reference/types/impl-trait.html#abstract-return-types)).
7171
<span id="rpitit">RPITIT</span> | A return-position `impl Trait` in trait. Unlike RPIT, this is desugared to a generic associated type (GAT). Introduced in [RFC 3425](https://rust-lang.github.io/rfcs/3425-return-position-impl-trait-in-traits.html). ([see more](../return-position-impl-trait-in-trait.md))
72-
<span id="scrutinee">scrutinee</div> | A scrutinee is the expression that is matched on in `match` expressions and similar pattern matching constructs. For example, in `match x { A => 1, B => 2 }`, the expression `x` is the scrutinee.
72+
<span id="scrutinee">scrutinee</span> | A scrutinee is the expression that is matched on in `match` expressions and similar pattern matching constructs. For example, in `match x { A => 1, B => 2 }`, the expression `x` is the scrutinee.
7373
<span id="sess">`sess`</span> | The compiler _session_, which stores global data used throughout compilation
7474
<span id="side-tables">side tables</span> | Because the [AST](#ast) and HIR are immutable once created, we often carry extra information about them in the form of hashtables, indexed by the id of a particular node.
7575
<span id="sigil">sigil</span> | Like a keyword but composed entirely of non-alphanumeric tokens. For example, `&` is a sigil for references.

src/backend/backend-agnostic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ heavily on other parts of the crate. The separation of the code must not affect
4545
the logic of the code nor its performance.
4646

4747
For these reasons, the separation process involves two transformations that
48-
have to be done at the same time for the resulting code to compile :
48+
have to be done at the same time for the resulting code to compile:
4949

5050
1. replace all the LLVM-specific types by generics inside function signatures
5151
and structure definitions;

src/backend/libs-and-metadata.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ format is specific to `rustc`, and may change over time. This file contains:
4242
### dylib
4343

4444
A `dylib` is a platform-specific shared library. It includes the `rustc`
45-
[metadata] in a special link section called `.rustc` in a compressed format.
45+
[metadata] in a special link section called `.rustc`.
4646

4747
### rmeta
4848

0 commit comments

Comments
 (0)