Skip to content

Commit 4cf4f05

Browse files
committed
Use lots of indexmaps
Rm Ord helper code
1 parent f7a4632 commit 4cf4f05

File tree

3 files changed

+16
-51
lines changed

3 files changed

+16
-51
lines changed

chalk-solve/src/display/state.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Display for InvertedBoundVar {
3636
}
3737
}
3838

39-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
39+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
4040
enum UnifiedId<I: Interner> {
4141
AdtId(I::InternedAdtId),
4242
DefId(I::DefId),
@@ -46,21 +46,21 @@ enum UnifiedId<I: Interner> {
4646
pub struct IdAliasStore<T> {
4747
/// Map from the DefIds we've encountered to a u32 alias id unique to all ids
4848
/// the same name.
49-
aliases: BTreeMap<T, u32>,
49+
aliases: indexmap::IndexMap<T, u32>,
5050
/// Map from each name to the next unused u32 alias id.
51-
next_unused_for_name: BTreeMap<String, u32>,
51+
next_unused_for_name: indexmap::IndexMap<String, u32>,
5252
}
5353

54-
impl<T: Ord> Default for IdAliasStore<T> {
54+
impl<T: std::cmp::PartialEq + std::cmp::Eq + std::hash::Hash> Default for IdAliasStore<T> {
5555
fn default() -> Self {
5656
IdAliasStore {
57-
aliases: BTreeMap::default(),
58-
next_unused_for_name: BTreeMap::default(),
57+
aliases: indexmap::IndexMap::default(),
58+
next_unused_for_name: indexmap::IndexMap::default(),
5959
}
6060
}
6161
}
6262

63-
impl<T: Copy + Ord> IdAliasStore<T> {
63+
impl<T: Copy + std::cmp::PartialEq + std::cmp::Eq + std::hash::Hash> IdAliasStore<T> {
6464
fn alias_for_id_name(&mut self, id: T, name: String) -> String {
6565
let next_unused_for_name = &mut self.next_unused_for_name;
6666
let alias = *self.aliases.entry(id).or_insert_with(|| {

chalk-solve/src/logging_db.rs

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! `.chalk` files containing those definitions.
33
use std::{
44
borrow::Borrow,
5-
cmp::{Ord, Ordering},
6-
collections::BTreeSet,
5+
// cmp::{Ord, Ordering},
6+
// collections::BTreeSet,
77
fmt::{self, Debug, Display},
88
io::Write,
99
marker::PhantomData,
@@ -36,7 +36,7 @@ where
3636
I: Interner,
3737
{
3838
ws: WriterState<I, DB, P>,
39-
def_ids: Mutex<BTreeSet<RecordedItemId<I>>>,
39+
def_ids: Mutex<indexmap::IndexSet<RecordedItemId<I>>>,
4040
_phantom: PhantomData<DB>,
4141
}
4242

@@ -535,7 +535,7 @@ where
535535
}
536536
}
537537

538-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
538+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
539539
pub enum RecordedItemId<I: Interner> {
540540
Adt(AdtId<I>),
541541
Trait(TraitId<I>),
@@ -580,38 +580,3 @@ impl<I: Interner> From<GeneratorId<I>> for RecordedItemId<I> {
580580
RecordedItemId::Generator(v)
581581
}
582582
}
583-
584-
/// Utility for implementing Ord for RecordedItemId.
585-
#[derive(PartialEq, Eq, PartialOrd, Ord)]
586-
enum OrderedItemId<'a, DefId, AdtId> {
587-
DefId(&'a DefId),
588-
AdtId(&'a AdtId),
589-
}
590-
591-
impl<I: Interner> RecordedItemId<I> {
592-
/// Extract internal identifier. Allows for absolute ordering matching the
593-
/// order in which chalk saw things (and thus reproducing that order in
594-
/// printed programs)
595-
fn ordered_item_id(&self) -> OrderedItemId<'_, I::DefId, I::InternedAdtId> {
596-
match self {
597-
RecordedItemId::Trait(TraitId(x))
598-
| RecordedItemId::Impl(ImplId(x))
599-
| RecordedItemId::OpaqueTy(OpaqueTyId(x))
600-
| RecordedItemId::Generator(GeneratorId(x))
601-
| RecordedItemId::FnDef(FnDefId(x)) => OrderedItemId::DefId(x),
602-
RecordedItemId::Adt(AdtId(x)) => OrderedItemId::AdtId(x),
603-
}
604-
}
605-
}
606-
607-
impl<I: Interner> PartialOrd for RecordedItemId<I> {
608-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
609-
Some(self.cmp(other))
610-
}
611-
}
612-
613-
impl<I: Interner> Ord for RecordedItemId<I> {
614-
fn cmp(&self, other: &Self) -> Ordering {
615-
self.ordered_item_id().cmp(&other.ordered_item_id())
616-
}
617-
}

chalk-solve/src/logging_db/id_collector.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use chalk_ir::{
66
visit::{SuperVisit, Visit},
77
AliasTy, DebruijnIndex, TyKind, WhereClause,
88
};
9-
use std::collections::BTreeSet;
9+
// use std::collections::BTreeSet;
1010
use std::ops::ControlFlow;
1111

1212
/// Collects the identifiers needed to resolve all the names for a given
@@ -34,11 +34,11 @@ use std::ops::ControlFlow;
3434
/// resolution is successful.
3535
pub fn collect_unrecorded_ids<'i, I: Interner, DB: RustIrDatabase<I>>(
3636
db: &'i DB,
37-
identifiers: &'_ BTreeSet<RecordedItemId<I>>,
38-
) -> BTreeSet<RecordedItemId<I>> {
37+
identifiers: &'_ indexmap::IndexSet<RecordedItemId<I>>,
38+
) -> indexmap::IndexSet<RecordedItemId<I>> {
3939
let mut collector = IdCollector {
4040
db,
41-
found_identifiers: BTreeSet::new(),
41+
found_identifiers: indexmap::IndexSet::new(),
4242
};
4343
for id in identifiers {
4444
match *id {
@@ -96,7 +96,7 @@ pub fn collect_unrecorded_ids<'i, I: Interner, DB: RustIrDatabase<I>>(
9696

9797
struct IdCollector<'i, I: Interner, DB: RustIrDatabase<I>> {
9898
db: &'i DB,
99-
found_identifiers: BTreeSet<RecordedItemId<I>>,
99+
found_identifiers: indexmap::IndexSet<RecordedItemId<I>>,
100100
}
101101

102102
impl<'i, I: Interner, DB: RustIrDatabase<I>> IdCollector<'i, I, DB> {

0 commit comments

Comments
 (0)