remove unused AGCContext
This commit is contained in:
parent
30b9a5e48d
commit
44ca1a607a
|
@ -198,7 +198,6 @@ impl<T: ?Sized + Sync + Send + 'static> LazyInterned<T> {
|
|||
pub trait InternedCompare {
|
||||
type InternedCompareKey: Ord + Hash;
|
||||
fn interned_compare_key_ref(this: &Self) -> Self::InternedCompareKey;
|
||||
fn interned_compare_key_weak(this: &std::sync::Weak<Self>) -> Self::InternedCompareKey;
|
||||
}
|
||||
|
||||
/// Warning: doesn't do what you want with `T = dyn Trait`,
|
||||
|
@ -272,9 +271,6 @@ impl<T> InternedCompare for T {
|
|||
fn interned_compare_key_ref(this: &Self) -> Self::InternedCompareKey {
|
||||
PtrEqWithMetadata(this)
|
||||
}
|
||||
fn interned_compare_key_weak(this: &std::sync::Weak<Self>) -> Self::InternedCompareKey {
|
||||
PtrEqWithMetadata(this.as_ptr())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> InternedCompare for [T] {
|
||||
|
@ -282,9 +278,6 @@ impl<T> InternedCompare for [T] {
|
|||
fn interned_compare_key_ref(this: &Self) -> Self::InternedCompareKey {
|
||||
PtrEqWithMetadata(this)
|
||||
}
|
||||
fn interned_compare_key_weak(this: &std::sync::Weak<Self>) -> Self::InternedCompareKey {
|
||||
PtrEqWithMetadata(this.as_ptr())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
|
@ -295,9 +288,6 @@ impl InternedCompare for BitSlice {
|
|||
fn interned_compare_key_ref(this: &Self) -> Self::InternedCompareKey {
|
||||
BitSlicePtrEq(this.as_bitptr(), this.len())
|
||||
}
|
||||
fn interned_compare_key_weak(_this: &std::sync::Weak<Self>) -> Self::InternedCompareKey {
|
||||
unreachable!("not currently implementable since Weak<BitSlice> can't be constructed")
|
||||
}
|
||||
}
|
||||
|
||||
impl InternedCompare for str {
|
||||
|
@ -305,9 +295,6 @@ impl InternedCompare for str {
|
|||
fn interned_compare_key_ref(this: &Self) -> Self::InternedCompareKey {
|
||||
PtrEqWithMetadata(this)
|
||||
}
|
||||
fn interned_compare_key_weak(this: &std::sync::Weak<Self>) -> Self::InternedCompareKey {
|
||||
PtrEqWithMetadata(this.as_ptr())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait InternContext: 'static + Send + Sync + Hash + Ord + fmt::Debug + Clone {
|
||||
|
@ -408,121 +395,6 @@ impl BitSliceInternContext for GlobalContext {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AGCContext(std::sync::Arc<TypeIdMap>);
|
||||
|
||||
impl AGCContext {
|
||||
pub fn new() -> Self {
|
||||
Self(std::sync::Arc::new(TypeIdMap::new()))
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AGCContext {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct AGCContextId(*const ());
|
||||
|
||||
impl fmt::Debug for AGCContextId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl AGCContext {
|
||||
pub fn id(&self) -> AGCContextId {
|
||||
AGCContextId(std::sync::Arc::as_ptr(&self.0).cast())
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for AGCContext {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.id().hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for AGCContext {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.id().cmp(&other.id())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for AGCContext {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for AGCContext {}
|
||||
|
||||
impl PartialEq for AGCContext {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id().eq(&other.id())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for AGCContext {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("AGCContext")
|
||||
.field("id", &self.id())
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl InternContext for AGCContext {
|
||||
type InternedImpl<T: ?Sized + 'static + Send + Sync> = std::sync::Weak<T>;
|
||||
type InternedGuardImpl<T: ?Sized + 'static + Send + Sync> = std::sync::Arc<T>;
|
||||
type AllContextsAreIdentical = ConstBool<false>;
|
||||
|
||||
fn interned_compare_key<T: InternedCompare + ?Sized + 'static + Send + Sync>(
|
||||
v: &Self::InternedImpl<T>,
|
||||
) -> T::InternedCompareKey {
|
||||
T::interned_compare_key_weak(v)
|
||||
}
|
||||
fn guard<T: ?Sized + 'static + Send + Sync>(
|
||||
v: &Self::InternedImpl<T>,
|
||||
) -> Self::InternedGuardImpl<T> {
|
||||
v.upgrade().expect("expired")
|
||||
}
|
||||
fn try_guard<T: ?Sized + 'static + Send + Sync>(
|
||||
v: &Self::InternedImpl<T>,
|
||||
) -> Option<Self::InternedGuardImpl<T>> {
|
||||
v.upgrade()
|
||||
}
|
||||
fn unguard<T: ?Sized + 'static + Send + Sync>(
|
||||
v: &Self::InternedGuardImpl<T>,
|
||||
) -> Self::InternedImpl<T> {
|
||||
std::sync::Arc::downgrade(v)
|
||||
}
|
||||
fn alloc_str(&self, value: Cow<'_, str>) -> Self::InternedGuardImpl<str> {
|
||||
match value {
|
||||
Cow::Borrowed(value) => value.into(),
|
||||
Cow::Owned(value) => value.into(),
|
||||
}
|
||||
}
|
||||
fn alloc_slice<T: Clone + Send + Sync + 'static>(
|
||||
&self,
|
||||
value: Cow<'_, [T]>,
|
||||
) -> Self::InternedGuardImpl<[T]> {
|
||||
match value {
|
||||
Cow::Borrowed(value) => value.into(),
|
||||
Cow::Owned(value) => value.into(),
|
||||
}
|
||||
}
|
||||
fn alloc_sized<T: Clone + Send + Sync + 'static>(
|
||||
&self,
|
||||
value: Cow<'_, T>,
|
||||
) -> Self::InternedGuardImpl<T> {
|
||||
std::sync::Arc::new(value.into_owned())
|
||||
}
|
||||
fn interner<T: ?Sized + Send + Sync + 'static>(&self) -> &Interner<T, Self> {
|
||||
self.0.get_or_insert_default()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Intern<C: InternContext = GlobalContext>: Any + Send + Sync {
|
||||
fn intern_with_ctx(&self, context: &C) -> Interned<Self, C>;
|
||||
fn intern_sized_with_ctx(self, context: &C) -> Interned<Self, C>
|
||||
|
|
Loading…
Reference in a new issue