Skip to content

Commit 8f3e493

Browse files
committed
Auto merge of #156869 - yotamofek:wip/rustdoc-bumpalo, r=<try>
[PERF EXPERIMENT] thread bumpalo through rustdoc
2 parents c58275e + 731c73d commit 8f3e493

60 files changed

Lines changed: 2642 additions & 1366 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: 228 additions & 40 deletions
Large diffs are not rendered by default.

compiler/rustc_data_structures/src/fx.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
pub use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet, FxHasher};
1+
use std::alloc::Global;
2+
3+
pub use rustc_hash::{FxBuildHasher, FxHashSet, FxHasher};
24

35
pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;
46

7+
pub type FxHashMap<K, V, A = Global> = std::collections::HashMap<K, V, FxBuildHasher, A>;
58
pub type FxIndexMap<K, V> = indexmap::IndexMap<K, V, FxBuildHasher>;
69
pub type FxIndexSet<V> = indexmap::IndexSet<V, FxBuildHasher>;
710
pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;

compiler/rustc_data_structures/src/unord.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
//! ordering. This is a useful property for deterministic computations, such
33
//! as required by the query system.
44
5+
use std::alloc::{Allocator, Global};
56
use std::borrow::{Borrow, BorrowMut};
7+
use std::collections::HashMap;
68
use std::collections::hash_map::{Entry, OccupiedError};
79
use std::hash::Hash;
810
use std::iter::{Product, Sum};
@@ -450,11 +452,11 @@ impl<V: Hash + Eq + StableHash> StableHash for UnordSet<V> {
450452
/// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533)
451453
/// for more information.
452454
#[derive(Debug, Eq, PartialEq, Clone, Encodable_NoContext, Decodable_NoContext)]
453-
pub struct UnordMap<K: Eq + Hash, V> {
454-
inner: FxHashMap<K, V>,
455+
pub struct UnordMap<K: Eq + Hash, V, A: Allocator = Global> {
456+
inner: HashMap<K, V, FxBuildHasher, A>,
455457
}
456458

457-
impl<K: Eq + Hash, V> UnordCollection for UnordMap<K, V> {}
459+
impl<K: Eq + Hash, V, A: Allocator> UnordCollection for UnordMap<K, V, A> {}
458460

459461
impl<K: Eq + Hash, V> const Default for UnordMap<K, V> {
460462
#[inline]
@@ -463,7 +465,7 @@ impl<K: Eq + Hash, V> const Default for UnordMap<K, V> {
463465
}
464466
}
465467

466-
impl<K: Hash + Eq, V> Extend<(K, V)> for UnordMap<K, V> {
468+
impl<K: Hash + Eq, V, A: Allocator> Extend<(K, V)> for UnordMap<K, V, A> {
467469
#[inline]
468470
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) {
469471
self.inner.extend(iter)
@@ -487,7 +489,19 @@ impl<K: Hash + Eq, V, I: Iterator<Item = (K, V)>> From<UnordItems<(K, V), I>> fo
487489
impl<K: Eq + Hash, V> UnordMap<K, V> {
488490
#[inline]
489491
pub fn with_capacity(capacity: usize) -> Self {
490-
Self { inner: FxHashMap::with_capacity_and_hasher(capacity, Default::default()) }
492+
Self::with_capacity_in(capacity, Global)
493+
}
494+
}
495+
496+
impl<K: Eq + Hash, V, A: Allocator> UnordMap<K, V, A> {
497+
#[inline]
498+
pub fn new_in(alloc: A) -> Self {
499+
Self::with_capacity_in(0, alloc)
500+
}
501+
502+
#[inline]
503+
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
504+
Self { inner: HashMap::with_capacity_and_hasher_in(capacity, Default::default(), alloc) }
491505
}
492506

493507
#[inline]
@@ -501,7 +515,7 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
501515
}
502516

503517
#[inline]
504-
pub fn try_insert(&mut self, k: K, v: V) -> Result<&mut V, OccupiedError<'_, K, V>> {
518+
pub fn try_insert(&mut self, k: K, v: V) -> Result<&mut V, OccupiedError<'_, K, V, A>> {
505519
self.inner.try_insert(k, v)
506520
}
507521

@@ -520,7 +534,7 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
520534
}
521535

522536
#[inline]
523-
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
537+
pub fn entry(&mut self, key: K) -> Entry<'_, K, V, A> {
524538
self.inner.entry(key)
525539
}
526540

src/bootstrap/src/utils/proc_macro_deps.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub static CRATES: &[&str] = &[
4040
"memchr",
4141
"minimal-lexical",
4242
"nom",
43+
"num-conv",
4344
"pest",
4445
"pest_generator",
4546
"pest_meta",
@@ -61,6 +62,7 @@ pub static CRATES: &[&str] = &[
6162
"syn",
6263
"synstructure",
6364
"thiserror",
65+
"time-core",
6466
"tinystr",
6567
"type-map",
6668
"typenum",

src/librustdoc/Cargo.toml

Lines changed: 8 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,7 +25,9 @@ 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.3"
2329
serde_json = "1.0"
30+
serde_with = "3.20.0"
2431
smallvec = "1.8.1"
2532
stringdex = "=0.0.6"
2633
tempfile = "3"

src/librustdoc/alloc.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use std::alloc::Allocator;
2+
use std::marker::PhantomData;
3+
4+
use serde_with::SerializeAs;
5+
6+
#[macro_export]
7+
macro_rules! vec_in {
8+
(in: $alloc:expr $(,)?) => (
9+
::std::vec::Vec::new_in($alloc)
10+
);
11+
(in: $alloc:expr, $elem:expr; $n:expr) => (
12+
::std::vec::from_elem_in($elem, $n, $alloc)
13+
);
14+
(in: $alloc:expr, $($x:expr),+ $(,)?) => ({
15+
let alloc = $alloc;
16+
let mut v = ::std::vec::Vec::with_capacity_in(
17+
const { [$($crate::vec_in!(@count $x)),+].len() },
18+
alloc,
19+
);
20+
$(v.push($x);)+
21+
v
22+
});
23+
(@count $_x:expr) => { () };
24+
}
25+
26+
pub(crate) trait FromIteratorWithAlloc<A: Allocator, E>: Sized {
27+
fn from_iter_with_alloc<T>(iter: T, alloc: A) -> Self
28+
where
29+
T: IntoIterator<Item = E>;
30+
}
31+
32+
impl<A: Allocator, E> FromIteratorWithAlloc<A, E> for Vec<E, A> {
33+
fn from_iter_with_alloc<T>(iter: T, alloc: A) -> Self
34+
where
35+
T: IntoIterator<Item = E>,
36+
{
37+
let mut vec = Vec::new_in(alloc);
38+
iter.into_iter().collect_into(&mut vec);
39+
vec
40+
}
41+
}
42+
43+
pub(crate) trait CollectIn: Iterator {
44+
fn collect_in<A: Allocator + Copy, B: FromIteratorWithAlloc<A, Self::Item>>(self, alloc: A) -> B
45+
where
46+
Self: Sized,
47+
{
48+
FromIteratorWithAlloc::from_iter_with_alloc(self, alloc)
49+
}
50+
}
51+
52+
impl<T> CollectIn for T where T: Iterator {}
53+
54+
pub struct AsSlice<T>(PhantomData<fn() -> [T]>);
55+
56+
impl<T, U, A> SerializeAs<Vec<T, A>> for AsSlice<U>
57+
where
58+
U: SerializeAs<T>,
59+
A: Allocator,
60+
{
61+
fn serialize_as<S>(source: &Vec<T, A>, serializer: S) -> Result<S::Ok, S::Error>
62+
where
63+
S: serde::Serializer,
64+
{
65+
<[U]>::serialize_as(source, serializer)
66+
}
67+
}

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;

0 commit comments

Comments
 (0)