Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Try custom index types for indexmap #96751

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"curl",
"indexmap",
"indexmap 1.8.0",
"serde",
"serde_json",
"toml",
Expand Down Expand Up @@ -337,7 +337,7 @@ dependencies = [
"humantime 2.0.1",
"ignore",
"im-rc",
"indexmap",
"indexmap 1.8.0",
"itertools",
"jobserver",
"lazy_static",
Expand Down Expand Up @@ -562,7 +562,7 @@ dependencies = [
"chalk-derive",
"chalk-ir",
"ena",
"indexmap",
"indexmap 1.8.0",
"itertools",
"petgraph",
"rustc-hash",
Expand Down Expand Up @@ -608,7 +608,7 @@ checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7"
dependencies = [
"atty",
"bitflags",
"indexmap",
"indexmap 1.8.0",
"lazy_static",
"os_str_bytes",
"strsim 0.10.0",
Expand Down Expand Up @@ -1574,7 +1574,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
dependencies = [
"fallible-iterator",
"indexmap",
"indexmap 1.8.0",
"stable_deref_trait",
]

Expand Down Expand Up @@ -1821,10 +1821,18 @@ checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
dependencies = [
"autocfg",
"hashbrown 0.11.2",
"rustc-rayon",
"serde",
]

[[package]]
name = "indexmap"
version = "2.0.0-pre"
source = "git+https://github.com/cuviper/indexmap?branch=indexable#3b6d807f460308e6de30cd34f9516aca624615f2"
dependencies = [
"hashbrown 0.12.0",
"rustc-rayon",
]

[[package]]
name = "indoc"
version = "1.0.3"
Expand Down Expand Up @@ -2515,7 +2523,7 @@ dependencies = [
"crc32fast",
"flate2",
"hashbrown 0.11.2",
"indexmap",
"indexmap 1.8.0",
"memchr",
]

Expand Down Expand Up @@ -2777,7 +2785,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
dependencies = [
"fixedbitset",
"indexmap",
"indexmap 1.8.0",
]

[[package]]
Expand Down Expand Up @@ -3676,7 +3684,7 @@ dependencies = [
"bitflags",
"cfg-if 0.1.10",
"ena",
"indexmap",
"indexmap 2.0.0-pre",
"jobserver",
"libc",
"measureme 10.0.0",
Expand Down Expand Up @@ -3858,6 +3866,7 @@ name = "rustc_index"
version = "0.0.0"
dependencies = [
"arrayvec",
"indexmap 2.0.0-pre",
"rustc_macros",
"rustc_serialize",
"smallvec",
Expand Down Expand Up @@ -4320,7 +4329,7 @@ dependencies = [
name = "rustc_serialize"
version = "0.0.0"
dependencies = [
"indexmap",
"indexmap 2.0.0-pre",
"rustc_macros",
"smallvec",
]
Expand Down Expand Up @@ -4731,7 +4740,7 @@ version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95"
dependencies = [
"indexmap",
"indexmap 1.8.0",
"itoa",
"ryu",
"serde",
Expand Down Expand Up @@ -5326,7 +5335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "744e9ed5b352340aa47ce033716991b5589e23781acb97cad37d4ea70560f55b"
dependencies = [
"combine",
"indexmap",
"indexmap 1.8.0",
"itertools",
"kstring 1.0.6",
"serde",
Expand All @@ -5339,7 +5348,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba98375fd631b83696f87c64e4ed8e29e6a1f3404d6aed95fa95163bad38e705"
dependencies = [
"combine",
"indexmap",
"indexmap 1.8.0",
"itertools",
"kstring 2.0.0",
"serde",
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_borrowck/src/borrow_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct BorrowSet<'tcx> {
/// by the `Location` of the assignment statement in which it
/// appears on the right hand side. Thus the location is the map
/// key, and its position in the map corresponds to `BorrowIndex`.
pub location_map: FxIndexMap<Location, BorrowData<'tcx>>,
pub location_map: FxIndexMap<Location, BorrowData<'tcx>, BorrowIndex>,

/// Locations which activate borrows.
/// NOTE: a given location may activate more than one borrow in the future
Expand All @@ -36,7 +36,7 @@ impl<'tcx> Index<BorrowIndex> for BorrowSet<'tcx> {
type Output = BorrowData<'tcx>;

fn index(&self, index: BorrowIndex) -> &BorrowData<'tcx> {
&self.location_map[index.as_usize()]
&self.location_map[index]
}
}

Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'tcx> BorrowSet<'tcx> {
}

crate fn get_index_of(&self, location: &Location) -> Option<BorrowIndex> {
self.location_map.get_index_of(location).map(BorrowIndex::from)
self.location_map.get_index_of(location)
}

crate fn contains(&self, location: &Location) -> bool {
Expand All @@ -176,7 +176,7 @@ impl<'tcx> BorrowSet<'tcx> {
struct GatherBorrows<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
body: &'a Body<'tcx>,
location_map: FxIndexMap<Location, BorrowData<'tcx>>,
location_map: FxIndexMap<Location, BorrowData<'tcx>, BorrowIndex>,
activation_map: FxHashMap<Location, Vec<BorrowIndex>>,
local_map: FxHashMap<mir::Local, FxHashSet<BorrowIndex>>,

Expand Down Expand Up @@ -217,7 +217,6 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
assigned_place: *assigned_place,
};
let (idx, _) = self.location_map.insert_full(location, borrow);
let idx = BorrowIndex::from(idx);

self.insert_as_pending_if_two_phase(location, assigned_place, kind, idx);

Expand All @@ -237,7 +236,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
//
// TMP = &mut place
if let Some(&borrow_index) = self.pending_activations.get(temp) {
let borrow_data = &mut self.location_map[borrow_index.as_usize()];
let borrow_data = &mut self.location_map[borrow_index];

// Watch out: the use of TMP in the borrow itself
// doesn't count as an activation. =)
Expand Down Expand Up @@ -326,7 +325,7 @@ impl<'a, 'tcx> GatherBorrows<'a, 'tcx> {
// Consider the borrow not activated to start. When we find an activation, we'll update
// this field.
{
let borrow_data = &mut self.location_map[borrow_index.as_usize()];
let borrow_data = &mut self.location_map[borrow_index];
borrow_data.activation_location = TwoPhaseActivation::NotActivated;
}

Expand All @@ -342,7 +341,7 @@ impl<'a, 'tcx> GatherBorrows<'a, 'tcx> {
at borrow_index: {:?} with associated data {:?}",
temp,
old_index,
self.location_map[old_index.as_usize()]
self.location_map[old_index]
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ impl_visitable! {

rustc_index::newtype_index! {
pub struct BorrowIndex {
DEBUG_FORMAT = "bw{}"
DEBUG_FORMAT = "bw{}",
INDEXMAP,
}
}

Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/region_infer/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ rustc_index::newtype_index! {

rustc_index::newtype_index! {
/// A single integer representing a `ty::Placeholder`.
pub struct PlaceholderIndex { DEBUG_FORMAT = "PlaceholderIndex({})" }
pub struct PlaceholderIndex { DEBUG_FORMAT = "PlaceholderIndex({})", INDEXMAP }
}

/// An individual element in a region value -- the value of a
Expand Down Expand Up @@ -179,21 +179,21 @@ impl<N: Idx> LivenessValues<N> {
/// NLL.
#[derive(Default)]
crate struct PlaceholderIndices {
indices: FxIndexSet<ty::PlaceholderRegion>,
indices: FxIndexSet<ty::PlaceholderRegion, PlaceholderIndex>,
}

impl PlaceholderIndices {
crate fn insert(&mut self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
let (index, _) = self.indices.insert_full(placeholder);
index.into()
index
}

crate fn lookup_index(&self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
self.indices.get_index_of(&placeholder).unwrap().into()
self.indices.get_index_of(&placeholder).unwrap()
}

crate fn lookup_placeholder(&self, placeholder: PlaceholderIndex) -> ty::PlaceholderRegion {
self.indices[placeholder.index()]
self.indices[placeholder]
}

crate fn len(&self) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
}

struct CoverageMapGenerator {
filenames: FxIndexSet<CString>,
filenames: FxIndexSet<CString, u32>,
}

impl CoverageMapGenerator {
Expand Down Expand Up @@ -185,7 +185,7 @@ impl CoverageMapGenerator {
.expect("null error converting filename to C string");
debug!(" file_id: {} = '{:?}'", current_file_id, c_filename);
let (filenames_index, _) = self.filenames.insert_full(c_filename);
virtual_file_mapping.push(filenames_index as u32);
virtual_file_mapping.push(filenames_index);
}
debug!("Adding counter {:?} to map for {:?}", counter, region);
mapping_regions.push(CounterMappingRegion::code_region(
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ doctest = false
[dependencies]
arrayvec = { version = "0.7", default-features = false }
ena = "0.14"
indexmap = { version = "1.8.0" }
# indexmap = { version = "1.8.0" }
indexmap = { git = "https://github.com/cuviper/indexmap", branch = "indexable" }
tracing = "0.1"
jobserver_crate = { version = "0.1.13", package = "jobserver" }
rustc_serialize = { path = "../rustc_serialize" }
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_data_structures/src/fx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::hash::BuildHasherDefault;

pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};

pub type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
pub type FxIndexMap<K, V, Idx = usize> =
indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>, Idx>;
pub type FxIndexSet<V, Idx = usize> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>, Idx>;

#[macro_export]
macro_rules! define_id_collections {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl<T: HashStable<CTX>, CTX> HashStable<CTX> for Vec<T> {
}
}

impl<K, V, R, CTX> HashStable<CTX> for indexmap::IndexMap<K, V, R>
impl<K, V, R, Idx, CTX> HashStable<CTX> for indexmap::IndexMap<K, V, R, Idx>
where
K: HashStable<CTX> + Eq + Hash,
V: HashStable<CTX>,
Expand All @@ -369,7 +369,7 @@ where
}
}

impl<K, R, CTX> HashStable<CTX> for indexmap::IndexSet<K, R>
impl<K, R, Idx, CTX> HashStable<CTX> for indexmap::IndexSet<K, R, Idx>
where
K: HashStable<CTX> + Eq + Hash,
R: BuildHasher,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ doctest = false

[dependencies]
arrayvec = { version = "0.7", default-features = false }
indexmap = { git = "https://github.com/cuviper/indexmap", branch = "indexable" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_macros = { path = "../rustc_macros" }
smallvec = "1"
4 changes: 4 additions & 0 deletions compiler/rustc_index/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ macro_rules! static_assert_size {
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
};
}

pub mod map {
pub use indexmap::{Indexable, IndexMap};
}
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub fn transitive_bounds_that_define_assoc_type<'tcx>(
assoc_name: Ident,
) -> impl Iterator<Item = ty::PolyTraitRef<'tcx>> {
let mut stack: Vec<_> = bounds.collect();
let mut visited = FxIndexSet::default();
let mut visited = FxIndexSet::<_, usize>::default();

std::iter::from_fn(move || {
while let Some(trait_ref) = stack.pop() {
Expand Down
Loading