1
Fork 0

Rollup merge of #116560 - ouz-a:efficient_ids, r=oli-obk

In smir use `FxIndexMap` to store indexed ids

Previously we used `vec` for storing indexed types, which is fine for small cases but will lead to huge performance issues when we use `smir` for real world cases.

Addresses https://github.com/rust-lang/project-stable-mir/issues/35

r? ``@oli-obk``
This commit is contained in:
Guillaume Gomez 2023-10-10 18:44:46 +02:00 committed by GitHub
commit 100713ef08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 36 deletions

View file

@ -22,7 +22,8 @@ use std::fmt;
use std::fmt::Debug;
use self::ty::{
GenericPredicates, Generics, ImplDef, ImplTrait, Span, TraitDecl, TraitDef, Ty, TyKind,
GenericPredicates, Generics, ImplDef, ImplTrait, IndexedVal, Span, TraitDecl, TraitDef, Ty,
TyKind,
};
#[macro_use]
@ -41,7 +42,7 @@ pub type CrateNum = usize;
/// A unique identification number for each item accessible for the current compilation unit.
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct DefId(pub usize);
pub struct DefId(usize);
impl Debug for DefId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -52,9 +53,28 @@ impl Debug for DefId {
}
}
impl IndexedVal for DefId {
fn to_val(index: usize) -> Self {
DefId(index)
}
fn to_index(&self) -> usize {
self.0
}
}
/// A unique identification number for each provenance
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct AllocId(pub usize);
pub struct AllocId(usize);
impl IndexedVal for AllocId {
fn to_val(index: usize) -> Self {
AllocId(index)
}
fn to_index(&self) -> usize {
self.0
}
}
/// A list of crate items.
pub type CrateItems = Vec<CrateItem>;