Skip to content

Commit da2b5bb

Browse files
authored
Unrolled build for #149700
Rollup merge of #149700 - notriddle:alias-loading, r=GuillaumeGomez rustdoc: fix bugs with search aliases and merging These bugs cause a crash and a perf problem with aliases, caused by loading the search index when it's not expected. cc `@weihanglo` r? `@GuillaumeGomez`
2 parents ba86c04 + 6fb8d9f commit da2b5bb

File tree

6 files changed

+124
-4
lines changed

6 files changed

+124
-4
lines changed

src/librustdoc/html/render/search_index.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use tracing::instrument;
2424

2525
use crate::clean::types::{Function, Generics, ItemId, Type, WherePredicate};
2626
use crate::clean::{self, utils};
27+
use crate::config::ShouldMerge;
2728
use crate::error::Error;
2829
use crate::formats::cache::{Cache, OrphanImplItem};
2930
use crate::formats::item_type::ItemType;
@@ -721,7 +722,9 @@ impl SerializedSearchIndex {
721722
}
722723
},
723724
),
724-
self.alias_pointers[id].and_then(|alias| map.get(&alias).copied()),
725+
self.alias_pointers[id].and_then(|alias| {
726+
if self.names[alias].is_empty() { None } else { map.get(&alias).copied() }
727+
}),
725728
);
726729
}
727730
new.generic_inverted_index = self
@@ -1248,6 +1251,7 @@ pub(crate) fn build_index(
12481251
tcx: TyCtxt<'_>,
12491252
doc_root: &Path,
12501253
resource_suffix: &str,
1254+
should_merge: &ShouldMerge,
12511255
) -> Result<SerializedSearchIndex, Error> {
12521256
let mut search_index = std::mem::take(&mut cache.search_index);
12531257

@@ -1298,7 +1302,11 @@ pub(crate) fn build_index(
12981302
//
12991303
// if there's already a search index, load it into memory and add the new entries to it
13001304
// otherwise, do nothing
1301-
let mut serialized_index = SerializedSearchIndex::load(doc_root, resource_suffix)?;
1305+
let mut serialized_index = if should_merge.read_rendered_cci {
1306+
SerializedSearchIndex::load(doc_root, resource_suffix)?
1307+
} else {
1308+
SerializedSearchIndex::default()
1309+
};
13021310

13031311
// The crate always goes first in this list
13041312
let crate_name = krate.name(tcx);

src/librustdoc/html/render/write_shared.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ pub(crate) fn write_shared(
6666
// Write shared runs within a flock; disable thread dispatching of IO temporarily.
6767
let _lock = try_err!(flock::Lock::new(&lock_file, true, true, true), &lock_file);
6868

69-
let search_index =
70-
build_index(krate, &mut cx.shared.cache, tcx, &cx.dst, &cx.shared.resource_suffix)?;
69+
let search_index = build_index(
70+
krate,
71+
&mut cx.shared.cache,
72+
tcx,
73+
&cx.dst,
74+
&cx.shared.resource_suffix,
75+
&opt.should_merge,
76+
)?;
7177

7278
let crate_name = krate.name(cx.tcx());
7379
let crate_name = crate_name.as_str(); // rand
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub struct Dep1;
2+
pub struct Dep2;
3+
pub struct Dep3;
4+
pub struct Dep4;
5+
6+
//@ hasraw crates.js 'dep1'
7+
//@ hasraw search.index/name/*.js 'Dep1'
8+
//@ has dep1/index.html
9+
#[doc(alias = "dep1_missing")]
10+
pub struct Dep5;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ hasraw crates.js 'dep2'
2+
//@ hasraw search.index/name/*.js 'Second'
3+
//@ has dep2/index.html
4+
pub struct Second;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ !hasraw crates.js 'dep_missing'
2+
//@ !hasraw search.index/name/*.js 'DepMissing'
3+
//@ has dep_missing/index.html
4+
pub struct DepMissing;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Running --merge=finalize without an input crate root should not trigger ICE.
2+
// Issue: https://github.com/rust-lang/rust/issues/146646
3+
4+
//@ needs-target-std
5+
6+
use run_make_support::{htmldocck, path, rustdoc};
7+
8+
fn main() {
9+
let out_dir = path("out");
10+
let merged_dir = path("merged");
11+
let parts_out_dir = path("parts");
12+
13+
rustdoc()
14+
.input("dep1.rs")
15+
.out_dir(&out_dir)
16+
.arg("-Zunstable-options")
17+
.arg(format!("--parts-out-dir={}", parts_out_dir.display()))
18+
.arg("--merge=none")
19+
.run();
20+
assert!(parts_out_dir.join("dep1.json").exists());
21+
22+
let output = rustdoc()
23+
.arg("-Zunstable-options")
24+
.out_dir(&out_dir)
25+
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
26+
.arg("--merge=finalize")
27+
.run();
28+
output.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
29+
30+
rustdoc()
31+
.input("dep2.rs")
32+
.out_dir(&out_dir)
33+
.arg("-Zunstable-options")
34+
.arg(format!("--parts-out-dir={}", parts_out_dir.display()))
35+
.arg("--merge=none")
36+
.run();
37+
assert!(parts_out_dir.join("dep2.json").exists());
38+
39+
let output2 = rustdoc()
40+
.arg("-Zunstable-options")
41+
.out_dir(&out_dir)
42+
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
43+
.arg("--merge=finalize")
44+
.run();
45+
output2.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
46+
47+
rustdoc()
48+
.input("dep1.rs")
49+
.out_dir(&out_dir)
50+
.arg("-Zunstable-options")
51+
.arg(format!("--parts-out-dir={}", parts_out_dir.display()))
52+
.arg("--merge=none")
53+
.run();
54+
assert!(parts_out_dir.join("dep1.json").exists());
55+
56+
let output3 = rustdoc()
57+
.arg("-Zunstable-options")
58+
.out_dir(&out_dir)
59+
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
60+
.arg("--merge=finalize")
61+
.run();
62+
output3.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
63+
64+
// dep_missing is different, because --parts-out-dir is not supplied
65+
rustdoc().input("dep_missing.rs").out_dir(&out_dir).run();
66+
assert!(parts_out_dir.join("dep2.json").exists());
67+
68+
rustdoc()
69+
.input("dep1.rs")
70+
.out_dir(&out_dir)
71+
.arg("-Zunstable-options")
72+
.arg(format!("--parts-out-dir={}", parts_out_dir.display()))
73+
.arg("--merge=none")
74+
.run();
75+
assert!(parts_out_dir.join("dep1.json").exists());
76+
77+
let output4 = rustdoc()
78+
.arg("-Zunstable-options")
79+
.out_dir(&out_dir)
80+
.arg(format!("--include-parts-dir={}", parts_out_dir.display()))
81+
.arg("--merge=finalize")
82+
.run();
83+
output4.assert_stderr_not_contains("error: the compiler unexpectedly panicked. this is a bug.");
84+
85+
htmldocck().arg(&out_dir).arg("dep1.rs").run();
86+
htmldocck().arg(&out_dir).arg("dep2.rs").run();
87+
htmldocck().arg(&out_dir).arg("dep_missing.rs").run();
88+
}

0 commit comments

Comments
 (0)