Skip to content

Commit e04e19d

Browse files
committedJun 4, 2023
Auto merge of #112270 - matthiaskrgr:rollup-umplsb6, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #109093 (add `#[doc(alias="flatmap")]` to `Option::and_then`) - #110701 (Fix `x test core` when download-rustc is enabled) - #111982 (Revert "Enable incremental independent of stage") - #112158 (Add portable-simd mention) - #112172 (doc: improve explanation) - #112178 (Fix bug where private item with intermediate doc hidden re-export was not inlined) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a28e125 + 0d6749c commit e04e19d

File tree

11 files changed

+185
-45
lines changed

11 files changed

+185
-45
lines changed
 

‎library/core/src/option.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ impl<T> Option<T> {
14021402
/// let item_2_0 = arr_2d.get(2).and_then(|row| row.get(0));
14031403
/// assert_eq!(item_2_0, None);
14041404
/// ```
1405+
#[doc(alias = "flatmap")]
14051406
#[inline]
14061407
#[stable(feature = "rust1", since = "1.0.0")]
14071408
pub fn and_then<U, F>(self, f: F) -> Option<U>

‎library/std/src/sync/once.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Once {
9191
/// return).
9292
///
9393
/// If the given closure recursively invokes `call_once` on the same [`Once`]
94-
/// instance the exact behavior is not specified, allowed outcomes are
94+
/// instance, the exact behavior is not specified: allowed outcomes are
9595
/// a panic or a deadlock.
9696
///
9797
/// # Examples

‎src/bootstrap/builder.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ impl<'a> Builder<'a> {
995995
}
996996

997997
pub fn sysroot(&self, compiler: Compiler) -> Interned<PathBuf> {
998-
self.ensure(compile::Sysroot { compiler })
998+
self.ensure(compile::Sysroot::new(compiler))
999999
}
10001000

10011001
/// Returns the libdir where the standard library and other artifacts are
@@ -1786,7 +1786,10 @@ impl<'a> Builder<'a> {
17861786
cargo.env("RUSTC_TLS_MODEL_INITIAL_EXEC", "1");
17871787
}
17881788

1789-
if self.config.incremental {
1789+
// Ignore incremental modes except for stage0, since we're
1790+
// not guaranteeing correctness across builds if the compiler
1791+
// is changing under your feet.
1792+
if self.config.incremental && compiler.stage == 0 {
17901793
cargo.env("CARGO_INCREMENTAL", "1");
17911794
} else {
17921795
// Don't rely on any default setting for incr. comp. in Cargo

‎src/bootstrap/compile.rs

+92-28
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ pub struct Std {
4040
///
4141
/// This shouldn't be used from other steps; see the comment on [`Rustc`].
4242
crates: Interned<Vec<String>>,
43+
/// When using download-rustc, we need to use a new build of `std` for running unit tests of Std itself,
44+
/// but we need to use the downloaded copy of std for linking to rustdoc. Allow this to be overriden by `builder.ensure` from other steps.
45+
force_recompile: bool,
4346
}
4447

4548
impl Std {
4649
pub fn new(compiler: Compiler, target: TargetSelection) -> Self {
47-
Self { target, compiler, crates: Default::default() }
50+
Self { target, compiler, crates: Default::default(), force_recompile: false }
51+
}
52+
53+
pub fn force_recompile(compiler: Compiler, target: TargetSelection) -> Self {
54+
Self { target, compiler, crates: Default::default(), force_recompile: true }
4855
}
4956
}
5057

@@ -77,6 +84,7 @@ impl Step for Std {
7784
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
7885
target: run.target,
7986
crates: make_run_crates(&run, "library"),
87+
force_recompile: false,
8088
});
8189
}
8290

@@ -89,11 +97,20 @@ impl Step for Std {
8997
let target = self.target;
9098
let compiler = self.compiler;
9199

92-
// When using `download-rustc`, we already have artifacts for the host available
93-
// (they were copied in `impl Step for Sysroot`). Don't recompile them.
94-
// NOTE: the ABI of the beta compiler is different from the ABI of the downloaded compiler,
95-
// so its artifacts can't be reused.
96-
if builder.download_rustc() && compiler.stage != 0 && target == builder.build.build {
100+
// When using `download-rustc`, we already have artifacts for the host available. Don't
101+
// recompile them.
102+
if builder.download_rustc() && target == builder.build.build
103+
// NOTE: the beta compiler may generate different artifacts than the downloaded compiler, so
104+
// its artifacts can't be reused.
105+
&& compiler.stage != 0
106+
// This check is specific to testing std itself; see `test::Std` for more details.
107+
&& !self.force_recompile
108+
{
109+
cp_rustc_component_to_ci_sysroot(
110+
builder,
111+
compiler,
112+
builder.config.ci_rust_std_contents(),
113+
);
97114
return;
98115
}
99116

@@ -428,6 +445,8 @@ struct StdLink {
428445
pub target: TargetSelection,
429446
/// Not actually used; only present to make sure the cache invalidation is correct.
430447
crates: Interned<Vec<String>>,
448+
/// See [`Std::force_recompile`].
449+
force_recompile: bool,
431450
}
432451

433452
impl StdLink {
@@ -437,6 +456,7 @@ impl StdLink {
437456
target_compiler: std.compiler,
438457
target: std.target,
439458
crates: std.crates,
459+
force_recompile: std.force_recompile,
440460
}
441461
}
442462
}
@@ -460,8 +480,24 @@ impl Step for StdLink {
460480
let compiler = self.compiler;
461481
let target_compiler = self.target_compiler;
462482
let target = self.target;
463-
let libdir = builder.sysroot_libdir(target_compiler, target);
464-
let hostdir = builder.sysroot_libdir(target_compiler, compiler.host);
483+
484+
// NOTE: intentionally does *not* check `target == builder.build` to avoid having to add the same check in `test::Crate`.
485+
let (libdir, hostdir) = if self.force_recompile && builder.download_rustc() {
486+
// NOTE: copies part of `sysroot_libdir` to avoid having to add a new `force_recompile` argument there too
487+
let lib = builder.sysroot_libdir_relative(self.compiler);
488+
let sysroot = builder.ensure(crate::compile::Sysroot {
489+
compiler: self.compiler,
490+
force_recompile: self.force_recompile,
491+
});
492+
let libdir = sysroot.join(lib).join("rustlib").join(target.triple).join("lib");
493+
let hostdir = sysroot.join(lib).join("rustlib").join(compiler.host.triple).join("lib");
494+
(INTERNER.intern_path(libdir), INTERNER.intern_path(hostdir))
495+
} else {
496+
let libdir = builder.sysroot_libdir(target_compiler, target);
497+
let hostdir = builder.sysroot_libdir(target_compiler, compiler.host);
498+
(libdir, hostdir)
499+
};
500+
465501
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
466502
}
467503
}
@@ -594,6 +630,25 @@ impl Step for StartupObjects {
594630
}
595631
}
596632

633+
fn cp_rustc_component_to_ci_sysroot(
634+
builder: &Builder<'_>,
635+
compiler: Compiler,
636+
contents: Vec<String>,
637+
) {
638+
let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false });
639+
640+
let ci_rustc_dir = builder.out.join(&*builder.build.build.triple).join("ci-rustc");
641+
for file in contents {
642+
let src = ci_rustc_dir.join(&file);
643+
let dst = sysroot.join(file);
644+
if src.is_dir() {
645+
t!(fs::create_dir_all(dst));
646+
} else {
647+
builder.copy(&src, &dst);
648+
}
649+
}
650+
}
651+
597652
#[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
598653
pub struct Rustc {
599654
pub target: TargetSelection,
@@ -653,18 +708,11 @@ impl Step for Rustc {
653708
if builder.download_rustc() && compiler.stage != 0 {
654709
// Copy the existing artifacts instead of rebuilding them.
655710
// NOTE: this path is only taken for tools linking to rustc-dev (including ui-fulldeps tests).
656-
let sysroot = builder.ensure(Sysroot { compiler });
657-
658-
let ci_rustc_dir = builder.out.join(&*builder.build.build.triple).join("ci-rustc");
659-
for file in builder.config.rustc_dev_contents() {
660-
let src = ci_rustc_dir.join(&file);
661-
let dst = sysroot.join(file);
662-
if src.is_dir() {
663-
t!(fs::create_dir_all(dst));
664-
} else {
665-
builder.copy(&src, &dst);
666-
}
667-
}
711+
cp_rustc_component_to_ci_sysroot(
712+
builder,
713+
compiler,
714+
builder.config.ci_rustc_dev_contents(),
715+
);
668716
return;
669717
}
670718

@@ -1225,6 +1273,14 @@ pub fn compiler_file(
12251273
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
12261274
pub struct Sysroot {
12271275
pub compiler: Compiler,
1276+
/// See [`Std::force_recompile`].
1277+
force_recompile: bool,
1278+
}
1279+
1280+
impl Sysroot {
1281+
pub(crate) fn new(compiler: Compiler) -> Self {
1282+
Sysroot { compiler, force_recompile: false }
1283+
}
12281284
}
12291285

12301286
impl Step for Sysroot {
@@ -1247,6 +1303,8 @@ impl Step for Sysroot {
12471303
let sysroot_dir = |stage| {
12481304
if stage == 0 {
12491305
host_dir.join("stage0-sysroot")
1306+
} else if self.force_recompile && stage == compiler.stage {
1307+
host_dir.join(format!("stage{stage}-test-sysroot"))
12501308
} else if builder.download_rustc() && compiler.stage != builder.top_stage {
12511309
host_dir.join("ci-rustc-sysroot")
12521310
} else {
@@ -1286,14 +1344,19 @@ impl Step for Sysroot {
12861344
// 2. The sysroot is deleted and recreated between each invocation, so running `x test
12871345
// ui-fulldeps && x test ui` can't cause failures.
12881346
let mut filtered_files = Vec::new();
1289-
// Don't trim directories or files that aren't loaded per-target; they can't cause conflicts.
1290-
let suffix = format!("lib/rustlib/{}/lib", compiler.host);
1291-
for path in builder.config.rustc_dev_contents() {
1292-
let path = Path::new(&path);
1293-
if path.parent().map_or(false, |parent| parent.ends_with(&suffix)) {
1294-
filtered_files.push(path.file_name().unwrap().to_owned());
1347+
let mut add_filtered_files = |suffix, contents| {
1348+
for path in contents {
1349+
let path = Path::new(&path);
1350+
if path.parent().map_or(false, |parent| parent.ends_with(&suffix)) {
1351+
filtered_files.push(path.file_name().unwrap().to_owned());
1352+
}
12951353
}
1296-
}
1354+
};
1355+
let suffix = format!("lib/rustlib/{}/lib", compiler.host);
1356+
add_filtered_files(suffix.as_str(), builder.config.ci_rustc_dev_contents());
1357+
// NOTE: we can't copy std eagerly because `stage2-test-sysroot` needs to have only the
1358+
// newly compiled std, not the downloaded std.
1359+
add_filtered_files("lib", builder.config.ci_rust_std_contents());
12971360

12981361
let filtered_extensions = [OsStr::new("rmeta"), OsStr::new("rlib"), OsStr::new("so")];
12991362
let ci_rustc_dir = builder.ci_rustc_dir(builder.config.build);
@@ -1411,7 +1474,8 @@ impl Step for Assemble {
14111474

14121475
// If we're downloading a compiler from CI, we can use the same compiler for all stages other than 0.
14131476
if builder.download_rustc() {
1414-
let sysroot = builder.ensure(Sysroot { compiler: target_compiler });
1477+
let sysroot =
1478+
builder.ensure(Sysroot { compiler: target_compiler, force_recompile: false });
14151479
// Ensure that `libLLVM.so` ends up in the newly created target directory,
14161480
// so that tools using `rustc_private` can use it.
14171481
dist::maybe_install_llvm_target(builder, target_compiler.host, &sysroot);

‎src/bootstrap/download.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,8 @@ impl Config {
271271
// `compile::Sysroot` needs to know the contents of the `rustc-dev` tarball to avoid adding
272272
// it to the sysroot unless it was explicitly requested. But parsing the 100 MB tarball is slow.
273273
// Cache the entries when we extract it so we only have to read it once.
274-
let mut recorded_entries = if dst.ends_with("ci-rustc") && pattern == "rustc-dev" {
275-
Some(BufWriter::new(t!(File::create(dst.join(".rustc-dev-contents")))))
276-
} else {
277-
None
278-
};
274+
let mut recorded_entries =
275+
if dst.ends_with("ci-rustc") { recorded_entries(dst, pattern) } else { None };
279276

280277
for member in t!(tar.entries()) {
281278
let mut member = t!(member);
@@ -332,6 +329,17 @@ impl Config {
332329
}
333330
}
334331

332+
fn recorded_entries(dst: &Path, pattern: &str) -> Option<BufWriter<File>> {
333+
let name = if pattern == "rustc-dev" {
334+
".rustc-dev-contents"
335+
} else if pattern.starts_with("rust-std") {
336+
".rust-std-contents"
337+
} else {
338+
return None;
339+
};
340+
Some(BufWriter::new(t!(File::create(dst.join(name)))))
341+
}
342+
335343
enum DownloadSource {
336344
CI,
337345
Dist,
@@ -382,11 +390,20 @@ impl Config {
382390
Some(rustfmt_path)
383391
}
384392

385-
pub(crate) fn rustc_dev_contents(&self) -> Vec<String> {
393+
pub(crate) fn ci_rust_std_contents(&self) -> Vec<String> {
394+
self.ci_component_contents(".rust-std-contents")
395+
}
396+
397+
pub(crate) fn ci_rustc_dev_contents(&self) -> Vec<String> {
398+
self.ci_component_contents(".rustc-dev-contents")
399+
}
400+
401+
fn ci_component_contents(&self, stamp_file: &str) -> Vec<String> {
386402
assert!(self.download_rustc());
387403
let ci_rustc_dir = self.out.join(&*self.build.triple).join("ci-rustc");
388-
let rustc_dev_contents_file = t!(File::open(ci_rustc_dir.join(".rustc-dev-contents")));
389-
t!(BufReader::new(rustc_dev_contents_file).lines().collect())
404+
let stamp_file = ci_rustc_dir.join(stamp_file);
405+
let contents_file = t!(File::open(&stamp_file), stamp_file.display().to_string());
406+
t!(BufReader::new(contents_file).lines().collect())
390407
}
391408

392409
pub(crate) fn download_ci_rustc(&self, commit: &str) {

‎src/bootstrap/test.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,8 @@ impl Step for Crate {
22042204
let target = self.target;
22052205
let mode = self.mode;
22062206

2207-
builder.ensure(compile::Std::new(compiler, target));
2207+
// See [field@compile::Std::force_recompile].
2208+
builder.ensure(compile::Std::force_recompile(compiler, target));
22082209
builder.ensure(RemoteCopyLibs { compiler, target });
22092210

22102211
// If we're not doing a full bootstrap but we're testing a stage2
@@ -2218,6 +2219,16 @@ impl Step for Crate {
22182219
match mode {
22192220
Mode::Std => {
22202221
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2222+
// `std_cargo` actually does the wrong thing: it passes `--sysroot build/host/stage2`,
2223+
// but we want to use the force-recompile std we just built in `build/host/stage2-test-sysroot`.
2224+
// Override it.
2225+
if builder.download_rustc() {
2226+
let sysroot = builder
2227+
.out
2228+
.join(compiler.host.triple)
2229+
.join(format!("stage{}-test-sysroot", compiler.stage));
2230+
cargo.env("RUSTC_SYSROOT", sysroot);
2231+
}
22212232
}
22222233
Mode::Rustc => {
22232234
compile::rustc_cargo(builder, &mut cargo, target, compiler.stage);
@@ -2269,6 +2280,11 @@ impl Step for CrateRustdoc {
22692280
// isn't really necessary.
22702281
builder.compiler_for(builder.top_stage, target, target)
22712282
};
2283+
// NOTE: normally `ensure(Rustc)` automatically runs `ensure(Std)` for us. However, when
2284+
// using `download-rustc`, the rustc_private artifacts may be in a *different sysroot* from
2285+
// the target rustdoc (`ci-rustc-sysroot` vs `stage2`). In that case, we need to ensure this
2286+
// explicitly to make sure it ends up in the stage2 sysroot.
2287+
builder.ensure(compile::Std::new(compiler, target));
22722288
builder.ensure(compile::Rustc::new(compiler, target));
22732289

22742290
let mut cargo = tool::prepare_tool_cargo(
@@ -2320,7 +2336,13 @@ impl Step for CrateRustdoc {
23202336
dylib_path.insert(0, PathBuf::from(&*libdir));
23212337
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
23222338

2323-
let _guard = builder.msg(builder.kind, compiler.stage, "rustdoc", compiler.host, target);
2339+
let _guard = builder.msg_sysroot_tool(
2340+
builder.kind,
2341+
compiler.stage,
2342+
"rustdoc",
2343+
compiler.host,
2344+
target,
2345+
);
23242346
run_cargo_test(
23252347
cargo,
23262348
&[],

‎src/librustdoc/clean/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,8 @@ fn get_all_import_attributes<'hir>(
21802180
// This is the "original" reexport so we get all its attributes without filtering them.
21812181
attrs = import_attrs.iter().map(|attr| (Cow::Borrowed(attr), Some(def_id))).collect();
21822182
first = false;
2183-
} else {
2183+
// We don't add attributes of an intermediate re-export if it has `#[doc(hidden)]`.
2184+
} else if !cx.tcx.is_doc_hidden(def_id) {
21842185
add_without_unwanted_attributes(&mut attrs, import_attrs, is_inline, Some(def_id));
21852186
}
21862187
}

‎src/librustdoc/visit_ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
246246
glob: bool,
247247
please_inline: bool,
248248
) -> bool {
249-
debug!("maybe_inline_local res: {:?}", res);
249+
debug!("maybe_inline_local (renamed: {renamed:?}) res: {res:?}");
250250

251251
if renamed == Some(kw::Underscore) {
252252
// We never inline `_` reexports.
@@ -308,6 +308,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
308308
.cache
309309
.effective_visibilities
310310
.is_directly_public(tcx, item_def_id.to_def_id()) &&
311+
!tcx.is_doc_hidden(item_def_id) &&
311312
!inherits_doc_hidden(tcx, item_def_id, None)
312313
{
313314
// The imported item is public and not `doc(hidden)` so no need to inline it.

0 commit comments

Comments
 (0)
Please sign in to comment.