Skip to content

Commit d31f2b5

Browse files
committed
Auto merge of #156869 - yotamofek:wip/rustdoc-bumpalo, r=<try>
[PERF EXPERIMENT] thread bumpalo through rustdoc
2 parents dd8b2d6 + bd85210 commit d31f2b5

55 files changed

Lines changed: 2239 additions & 1156 deletions

Some content is hidden

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

Cargo.lock

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ dependencies = [
373373

374374
[[package]]
375375
name = "bumpalo"
376-
version = "3.19.0"
376+
version = "3.20.3"
377377
source = "registry+https://github.com/rust-lang/crates.io-index"
378-
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
378+
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
379379

380380
[[package]]
381381
name = "bytecheck"
@@ -4922,6 +4922,7 @@ dependencies = [
49224922
"arrayvec",
49234923
"askama",
49244924
"base64",
4925+
"bumpalo",
49254926
"expect-test",
49264927
"indexmap",
49274928
"itertools",
@@ -4931,6 +4932,7 @@ dependencies = [
49314932
"regex",
49324933
"rustdoc-json-types",
49334934
"serde",
4935+
"serde_alloc",
49344936
"serde_json",
49354937
"sha2",
49364938
"smallvec",
@@ -5181,6 +5183,15 @@ dependencies = [
51815183
"serde",
51825184
]
51835185

5186+
[[package]]
5187+
name = "serde_alloc"
5188+
version = "0.1.0-alpha.1"
5189+
source = "registry+https://github.com/rust-lang/crates.io-index"
5190+
checksum = "727f51fdf8729c8fbd227ab2a5745c54c76e8771c63ce1282fd9ba894a7eff78"
5191+
dependencies = [
5192+
"serde_core",
5193+
]
5194+
51845195
[[package]]
51855196
name = "serde_core"
51865197
version = "1.0.228"

src/librustdoc/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ path = "lib.rs"
1010
[dependencies]
1111
# tidy-alphabetical-start
1212
arrayvec = { version = "0.7", default-features = false }
13-
askama = { version = "0.16.0", default-features = false, features = ["alloc", "config", "derive"] }
13+
askama = { version = "0.16.0", default-features = false, features = [
14+
"alloc",
15+
"config",
16+
"derive",
17+
] }
1418
base64 = "0.21.7"
19+
bumpalo = { version = "3", features = ["allocator_api"] }
1520
indexmap = { version = "2", features = ["serde"] }
1621
itertools = "0.12"
1722
minifier = { version = "0.3.5", default-features = false }
@@ -20,6 +25,7 @@ pulldown-cmark-escape = { version = "0.11.0", features = ["simd"] }
2025
regex = "1"
2126
rustdoc-json-types = { path = "../rustdoc-json-types" }
2227
serde = { version = "1.0", features = ["derive"] }
28+
serde_alloc = "0.1.0-alpha.1"
2329
serde_json = "1.0"
2430
smallvec = "1.8.1"
2531
stringdex = "=0.0.6"

src/librustdoc/clean/auto_trait.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::alloc::Allocator;
2+
13
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet, IndexEntry};
24
use rustc_data_structures::thin_vec::ThinVec;
35
use rustc_hir as hir;
@@ -16,8 +18,8 @@ use crate::clean::{
1618
use crate::core::DocContext;
1719

1820
#[instrument(level = "debug", skip(cx))]
19-
pub(crate) fn synthesize_auto_trait_impls<'tcx>(
20-
cx: &mut DocContext<'tcx>,
21+
pub(crate) fn synthesize_auto_trait_impls<'tcx, A: Allocator + Copy>(
22+
cx: &mut DocContext<'tcx, A>,
2123
item_def_id: DefId,
2224
) -> Vec<clean::Item> {
2325
let tcx = cx.tcx;
@@ -60,8 +62,8 @@ pub(crate) fn synthesize_auto_trait_impls<'tcx>(
6062
}
6163

6264
#[instrument(level = "debug", skip(cx, finder))]
63-
fn synthesize_auto_trait_impl<'tcx>(
64-
cx: &mut DocContext<'tcx>,
65+
fn synthesize_auto_trait_impl<'tcx, A: Allocator + Copy>(
66+
cx: &mut DocContext<'tcx, A>,
6567
ty: Ty<'tcx>,
6668
trait_def_id: DefId,
6769
typing_env: ty::TypingEnv<'tcx>,
@@ -142,8 +144,8 @@ enum DiscardPositiveImpls {
142144
}
143145

144146
#[instrument(level = "debug", skip(cx, region_data, vid_to_region))]
145-
fn clean_param_env<'tcx>(
146-
cx: &mut DocContext<'tcx>,
147+
fn clean_param_env<'tcx, A: Allocator + Copy>(
148+
cx: &mut DocContext<'tcx, A>,
147149
item_def_id: DefId,
148150
param_env: ty::ParamEnv<'tcx>,
149151
region_data: RegionConstraintData<'tcx>,

src/librustdoc/clean/blanket_impl.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::alloc::Allocator;
2+
13
use rustc_data_structures::thin_vec::ThinVec;
24
use rustc_hir as hir;
35
use rustc_infer::infer::{DefineOpaqueTypes, InferOk, TyCtxtInferExt};
@@ -15,8 +17,8 @@ use crate::clean::{
1517
use crate::core::DocContext;
1618

1719
#[instrument(level = "debug", skip(cx))]
18-
pub(crate) fn synthesize_blanket_impls(
19-
cx: &mut DocContext<'_>,
20+
pub(crate) fn synthesize_blanket_impls<A: Allocator + Copy>(
21+
cx: &mut DocContext<'_, A>,
2022
item_def_id: DefId,
2123
) -> Vec<clean::Item> {
2224
let tcx = cx.tcx;

src/librustdoc/clean/inline.rs

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Support for inlining external documentation into the current AST.
22
3+
use std::alloc::Allocator;
34
use std::iter::once;
45
use std::sync::Arc;
56

@@ -38,15 +39,15 @@ use crate::formats::item_type::ItemType;
3839
///
3940
/// The returned value is `None` if the definition could not be inlined,
4041
/// and `Some` of a vector of items if it was successfully expanded.
41-
pub(crate) fn try_inline(
42-
cx: &mut DocContext<'_>,
42+
pub(crate) fn try_inline<A: Allocator + Copy>(
43+
cx: &mut DocContext<'_, A>,
4344
res: Res,
4445
name: Symbol,
4546
attrs: Option<(&[hir::Attribute], Option<LocalDefId>)>,
4647
visited: &mut DefIdSet,
4748
) -> Option<Vec<clean::Item>> {
48-
fn try_inline_inner(
49-
cx: &mut DocContext<'_>,
49+
fn try_inline_inner<A: Allocator + Copy>(
50+
cx: &mut DocContext<'_, A>,
5051
kind: clean::ItemKind,
5152
did: DefId,
5253
name: Symbol,
@@ -178,8 +179,8 @@ pub(crate) fn try_inline(
178179
Some(ret)
179180
}
180181

181-
pub(crate) fn try_inline_glob(
182-
cx: &mut DocContext<'_>,
182+
pub(crate) fn try_inline_glob<A: Allocator + Copy>(
183+
cx: &mut DocContext<'_, A>,
183184
res: Res,
184185
current_mod: LocalModDefId,
185186
visited: &mut DefIdSet,
@@ -266,7 +267,11 @@ pub(crate) fn get_item_path(tcx: TyCtxt<'_>, def_id: DefId, kind: ItemType) -> V
266267
///
267268
/// These names are used later on by HTML rendering to generate things like
268269
/// source links back to the original item.
269-
pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) {
270+
pub(crate) fn record_extern_fqn<A: Allocator + Copy>(
271+
cx: &mut DocContext<'_, A>,
272+
did: DefId,
273+
kind: ItemType,
274+
) {
270275
if did.is_local() {
271276
if cx.cache.exact_paths.contains_key(&did) {
272277
return;
@@ -284,7 +289,10 @@ pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemT
284289
}
285290
}
286291

287-
pub(crate) fn build_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait {
292+
pub(crate) fn build_trait<A: Allocator + Copy>(
293+
cx: &mut DocContext<'_, A>,
294+
did: DefId,
295+
) -> clean::Trait {
288296
let trait_items = cx
289297
.tcx
290298
.associated_items(did)
@@ -305,7 +313,10 @@ pub(crate) fn build_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait {
305313
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
306314
}
307315

308-
fn build_trait_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::TraitAlias {
316+
fn build_trait_alias<A: Allocator + Copy>(
317+
cx: &mut DocContext<'_, A>,
318+
did: DefId,
319+
) -> clean::TraitAlias {
309320
let generics = clean_ty_generics(cx, did);
310321
let (generics, mut bounds) = separate_self_bounds(generics);
311322

@@ -318,7 +329,10 @@ fn build_trait_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::TraitAlias {
318329
clean::TraitAlias { generics, bounds }
319330
}
320331

321-
pub(super) fn build_function(cx: &mut DocContext<'_>, def_id: DefId) -> Box<clean::Function> {
332+
pub(super) fn build_function<A: Allocator + Copy>(
333+
cx: &mut DocContext<'_, A>,
334+
def_id: DefId,
335+
) -> Box<clean::Function> {
322336
let sig = cx.tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip();
323337
// The generics need to be cleaned before the signature.
324338
let mut generics = clean_ty_generics(cx, def_id);
@@ -349,14 +363,14 @@ pub(super) fn build_function(cx: &mut DocContext<'_>, def_id: DefId) -> Box<clea
349363
Box::new(clean::Function { decl, generics })
350364
}
351365

352-
fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum {
366+
fn build_enum<A: Allocator + Copy>(cx: &mut DocContext<'_, A>, did: DefId) -> clean::Enum {
353367
clean::Enum {
354368
generics: clean_ty_generics(cx, did),
355369
variants: cx.tcx.adt_def(did).variants().iter().map(|v| clean_variant_def(v, cx)).collect(),
356370
}
357371
}
358372

359-
fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct {
373+
fn build_struct<A: Allocator + Copy>(cx: &mut DocContext<'_, A>, did: DefId) -> clean::Struct {
360374
let variant = cx.tcx.adt_def(did).non_enum_variant();
361375

362376
clean::Struct {
@@ -366,16 +380,16 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct {
366380
}
367381
}
368382

369-
fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
383+
fn build_union<A: Allocator + Copy>(cx: &mut DocContext<'_, A>, did: DefId) -> clean::Union {
370384
let variant = cx.tcx.adt_def(did).non_enum_variant();
371385

372386
let generics = clean_ty_generics(cx, did);
373387
let fields = variant.fields.iter().map(|x| clean_middle_field(x, cx)).collect();
374388
clean::Union { generics, fields }
375389
}
376390

377-
fn build_type_alias(
378-
cx: &mut DocContext<'_>,
391+
fn build_type_alias<A: Allocator + Copy>(
392+
cx: &mut DocContext<'_, A>,
379393
did: DefId,
380394
ret: &mut Vec<Item>,
381395
) -> Box<clean::TypeAlias> {
@@ -392,8 +406,8 @@ fn build_type_alias(
392406
}
393407

394408
/// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport.
395-
pub(crate) fn build_impls(
396-
cx: &mut DocContext<'_>,
409+
pub(crate) fn build_impls<A: Allocator + Copy>(
410+
cx: &mut DocContext<'_, A>,
397411
did: DefId,
398412
attrs: Option<(&[hir::Attribute], Option<LocalDefId>)>,
399413
ret: &mut Vec<clean::Item>,
@@ -452,8 +466,8 @@ pub(crate) fn merge_attrs(
452466
}
453467

454468
/// Inline an `impl`, inherent or of a trait. The `did` must be for an `impl`.
455-
pub(crate) fn build_impl(
456-
cx: &mut DocContext<'_>,
469+
pub(crate) fn build_impl<A: Allocator + Copy>(
470+
cx: &mut DocContext<'_, A>,
457471
did: DefId,
458472
attrs: Option<(&[hir::Attribute], Option<LocalDefId>)>,
459473
ret: &mut Vec<clean::Item>,
@@ -473,7 +487,7 @@ pub(crate) fn build_impl(
473487
.is_some_and(|stab| stab.is_unstable() && stab.feature == sym::rustc_private)
474488
};
475489
let document_compiler_internal = is_compiler_internal(LOCAL_CRATE.as_def_id());
476-
let is_directly_public = |cx: &mut DocContext<'_>, did| {
490+
let is_directly_public = |cx: &mut DocContext<'_, A>, did| {
477491
cx.cache.effective_visibilities.is_directly_public(tcx, did)
478492
&& (document_compiler_internal || !is_compiler_internal(did))
479493
};
@@ -665,15 +679,19 @@ pub(crate) fn build_impl(
665679
));
666680
}
667681

668-
fn build_module(cx: &mut DocContext<'_>, did: DefId, visited: &mut DefIdSet) -> clean::Module {
682+
fn build_module<A: Allocator + Copy>(
683+
cx: &mut DocContext<'_, A>,
684+
did: DefId,
685+
visited: &mut DefIdSet,
686+
) -> clean::Module {
669687
let items = build_module_items(cx, did, visited, &mut FxHashSet::default(), None, None);
670688

671689
let span = clean::Span::new(cx.tcx.def_span(did));
672690
clean::Module { items, span }
673691
}
674692

675-
fn build_module_items(
676-
cx: &mut DocContext<'_>,
693+
fn build_module_items<A: Allocator + Copy>(
694+
cx: &mut DocContext<'_, A>,
677695
did: DefId,
678696
visited: &mut DefIdSet,
679697
inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
@@ -755,7 +773,10 @@ pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
755773
}
756774
}
757775

758-
fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
776+
fn build_const_item<A: Allocator + Copy>(
777+
cx: &mut DocContext<'_, A>,
778+
def_id: DefId,
779+
) -> clean::Constant {
759780
let mut generics = clean_ty_generics(cx, def_id);
760781
clean::simplify::move_bounds_to_generic_parameters(&mut generics);
761782
let ty = clean_middle_ty(
@@ -767,7 +788,11 @@ fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
767788
clean::Constant { generics, type_: ty, kind: clean::ConstantKind::Extern { def_id } }
768789
}
769790

770-
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
791+
fn build_static<A: Allocator + Copy>(
792+
cx: &mut DocContext<'_, A>,
793+
did: DefId,
794+
mutable: bool,
795+
) -> clean::Static {
771796
clean::Static {
772797
type_: Box::new(clean_middle_ty(
773798
ty::Binder::dummy(cx.tcx.type_of(did).instantiate_identity().skip_norm_wip()),
@@ -829,7 +854,7 @@ fn separate_self_bounds(mut g: clean::Generics) -> (clean::Generics, Vec<clean::
829854
(g, ty_bounds)
830855
}
831856

832-
pub(crate) fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
857+
pub(crate) fn record_extern_trait<A: Allocator + Copy>(cx: &mut DocContext<'_, A>, did: DefId) {
833858
if did.is_local()
834859
|| cx.external_traits.contains_key(&did)
835860
|| cx.active_extern_traits.contains(&did)

0 commit comments

Comments
 (0)