Skip to content

Commit 731c73d

Browse files
committed
more
1 parent 4d95059 commit 731c73d

16 files changed

Lines changed: 695 additions & 502 deletions

File tree

Cargo.lock

Lines changed: 217 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ pulldown-cmark-escape = { version = "0.11.0", features = ["simd"] }
2525
regex = "1"
2626
rustdoc-json-types = { path = "../rustdoc-json-types" }
2727
serde = { version = "1.0", features = ["derive"] }
28-
serde_alloc = "0.1.0-alpha.1"
28+
serde_alloc = "0.1.0-alpha.3"
2929
serde_json = "1.0"
30+
serde_with = "3.20.0"
3031
smallvec = "1.8.1"
3132
stringdex = "=0.0.6"
3233
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/inline.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,32 +235,52 @@ pub(crate) fn load_attrs<'hir>(tcx: TyCtxt<'hir>, did: DefId) -> &'hir [hir::Att
235235
tcx.get_all_attrs(did)
236236
}
237237

238-
pub(crate) fn item_relative_path(tcx: TyCtxt<'_>, def_id: DefId) -> Vec<Symbol> {
239-
tcx.def_path(def_id).data.into_iter().filter_map(|elem| elem.data.get_opt_name()).collect()
238+
pub(crate) fn item_relative_path<A: Allocator + Copy>(
239+
tcx: TyCtxt<'_>,
240+
def_id: DefId,
241+
alloc: A,
242+
) -> Vec<Symbol, A> {
243+
let mut vec = Vec::new_in(alloc);
244+
tcx.def_path(def_id)
245+
.data
246+
.into_iter()
247+
.filter_map(|elem| elem.data.get_opt_name())
248+
.collect_into(&mut vec);
249+
vec
240250
}
241251

242252
/// Get the public Rust path to an item. This is used to generate the URL to the item's page.
243253
///
244254
/// In particular: we handle macro differently: if it's not a macro 2.0 oe a built-in macro, then
245255
/// it is generated at the top-level of the crate and its path will be `[crate_name, macro_name]`.
246-
pub(crate) fn get_item_path(tcx: TyCtxt<'_>, def_id: DefId, kind: ItemType) -> Vec<Symbol> {
256+
pub(crate) fn get_item_path<A: Allocator + Copy>(
257+
tcx: TyCtxt<'_>,
258+
def_id: DefId,
259+
kind: ItemType,
260+
alloc: A,
261+
) -> Vec<Symbol, A> {
247262
let crate_name = tcx.crate_name(def_id.krate);
248-
let relative = item_relative_path(tcx, def_id);
263+
let relative = item_relative_path(tcx, def_id, alloc);
249264

265+
let mut vec = Vec::new_in(alloc);
250266
if let ItemType::Macro = kind {
251267
// Check to see if it is a macro 2.0 or built-in macro
252268
// More information in <https://rust-lang.github.io/rfcs/1584-macros.html>.
253269
if matches!(
254270
CStore::from_tcx(tcx).load_macro_untracked(tcx, def_id),
255271
LoadedMacro::MacroDef { def, .. } if !def.macro_rules
256272
) {
257-
once(crate_name).chain(relative).collect()
273+
once(crate_name).chain(relative).collect_into(&mut vec);
258274
} else {
259-
vec![crate_name, *relative.last().expect("relative was empty")]
275+
[crate_name, *relative.last().expect("relative was empty")]
276+
.into_iter()
277+
.collect_into(&mut vec);
260278
}
261279
} else {
262-
once(crate_name).chain(relative).collect()
280+
once(crate_name).chain(relative).collect_into(&mut vec);
263281
}
282+
283+
vec
264284
}
265285

266286
/// Record an external fully qualified name in the external_paths cache.
@@ -280,7 +300,9 @@ pub(crate) fn record_extern_fqn<A: Allocator + Copy>(
280300
return;
281301
}
282302

283-
let item_path = get_item_path(cx.tcx, did, kind);
303+
let alloc = *cx.cache.search_index.allocator();
304+
305+
let item_path = get_item_path(cx.tcx, did, kind, alloc);
284306

285307
if did.is_local() {
286308
cx.cache.exact_paths.insert(did, item_path);

0 commit comments

Comments
 (0)