Rollup merge of #147800 - makai410:rp-cache-obj, r=celinval
Add `Cacheable` trait alias in `rustc_public_bridge` r? `@celinval`
This commit is contained in:
commit
8cd557d4ec
1 changed files with 14 additions and 12 deletions
|
|
@ -21,6 +21,7 @@
|
|||
#![doc(rust_logo)]
|
||||
#![feature(rustdoc_internals)]
|
||||
#![feature(sized_hierarchy)]
|
||||
#![feature(trait_alias)]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
|
@ -45,6 +46,9 @@ pub mod context;
|
|||
#[deprecated(note = "please use `rustc_public::rustc_internal` instead")]
|
||||
pub mod rustc_internal {}
|
||||
|
||||
/// Trait alias for types that can be cached in [`Tables`].
|
||||
pub trait Cacheable = Copy + Debug + PartialEq + IndexedVal;
|
||||
|
||||
/// A container which is used for TLS.
|
||||
pub struct Container<'tcx, B: Bridge> {
|
||||
pub tables: RefCell<Tables<'tcx, B>>,
|
||||
|
|
@ -213,14 +217,14 @@ impl<'tcx, B: Bridge> Tables<'tcx, B> {
|
|||
/// A trait defining types that are used to emulate rustc_public components, which is really
|
||||
/// useful when programming in rustc_public-agnostic settings.
|
||||
pub trait Bridge: Sized {
|
||||
type DefId: Copy + Debug + PartialEq + IndexedVal;
|
||||
type AllocId: Copy + Debug + PartialEq + IndexedVal;
|
||||
type Span: Copy + Debug + PartialEq + IndexedVal;
|
||||
type Ty: Copy + Debug + PartialEq + IndexedVal;
|
||||
type InstanceDef: Copy + Debug + PartialEq + IndexedVal;
|
||||
type TyConstId: Copy + Debug + PartialEq + IndexedVal;
|
||||
type MirConstId: Copy + Debug + PartialEq + IndexedVal;
|
||||
type Layout: Copy + Debug + PartialEq + IndexedVal;
|
||||
type DefId: Cacheable;
|
||||
type AllocId: Cacheable;
|
||||
type Span: Cacheable;
|
||||
type Ty: Cacheable;
|
||||
type InstanceDef: Cacheable;
|
||||
type TyConstId: Cacheable;
|
||||
type MirConstId: Cacheable;
|
||||
type Layout: Cacheable;
|
||||
|
||||
type Error: Error;
|
||||
type CrateItem: CrateItem<Self>;
|
||||
|
|
@ -266,7 +270,7 @@ impl<K, V> Default for IndexMap<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<K: PartialEq + Hash + Eq, V: Copy + Debug + PartialEq + IndexedVal> IndexMap<K, V> {
|
||||
impl<K: PartialEq + Hash + Eq, V: Cacheable> IndexMap<K, V> {
|
||||
pub fn create_or_fetch(&mut self, key: K) -> V {
|
||||
let len = self.index_map.len();
|
||||
let v = self.index_map.entry(key).or_insert(V::to_val(len));
|
||||
|
|
@ -274,9 +278,7 @@ impl<K: PartialEq + Hash + Eq, V: Copy + Debug + PartialEq + IndexedVal> IndexMa
|
|||
}
|
||||
}
|
||||
|
||||
impl<K: PartialEq + Hash + Eq, V: Copy + Debug + PartialEq + IndexedVal> Index<V>
|
||||
for IndexMap<K, V>
|
||||
{
|
||||
impl<K: PartialEq + Hash + Eq, V: Cacheable> Index<V> for IndexMap<K, V> {
|
||||
type Output = K;
|
||||
|
||||
fn index(&self, index: V) -> &Self::Output {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue