Skip to content

Commit

Permalink
chore: fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Mar 22, 2024
1 parent ccb2cce commit f5a21ca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
27 changes: 25 additions & 2 deletions crates/erg_common/cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::{Borrow, ToOwned};
use std::hash::Hash;
use std::sync::Arc;
use std::thread::LocalKey;

use crate::dict::Dict;
use crate::set::Set;
Expand Down Expand Up @@ -72,6 +71,30 @@ impl<T: Hash + Eq> CacheSet<T> {
}
}

#[derive(Debug, Clone)]
pub struct CacheDict<K, V: ?Sized>(Shared<Dict<K, Arc<V>>>);

pub struct GlobalCacheDict<K: 'static, V: ?Sized + 'static>(LocalKey<Shared<CacheDict<K, V>>>);
impl<K: Hash + Eq, V: ?Sized> Default for CacheDict<K, V> {
fn default() -> Self {
Self::new()
}
}

impl<K: Hash + Eq, V: ?Sized> CacheDict<K, V> {
pub fn new() -> Self {
Self(Shared::new(Dict::new()))
}
}

impl<K: Hash + Eq, V> CacheDict<K, V> {
pub fn get<Q: ?Sized + Hash + Eq>(&self, k: &Q) -> Option<Arc<V>>
where
K: Borrow<Q>,
{
self.0.borrow().get(k).cloned()
}

pub fn insert(&self, k: K, v: V) {
self.0.borrow_mut().insert(k, Arc::new(v));
}
}
8 changes: 2 additions & 6 deletions crates/erg_compiler/ty/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,17 +1611,13 @@ pub mod value_set {
if !is_homogeneous(set) {
return None;
}
set.iter()
.max_by(|x, y| x.try_cmp(y).unwrap())
.map(Clone::clone)
set.iter().max_by(|x, y| x.try_cmp(y).unwrap()).cloned()
}

pub fn min(set: &Set<ValueObj>) -> Option<ValueObj> {
if !is_homogeneous(set) {
return None;
}
set.iter()
.min_by(|x, y| x.try_cmp(y).unwrap())
.map(Clone::clone)
set.iter().min_by(|x, y| x.try_cmp(y).unwrap()).cloned()
}
}
4 changes: 1 addition & 3 deletions crates/erg_parser/desugar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,9 +1121,7 @@ impl Desugarer {
loc.col_end().unwrap_or(0),
));
let name = Expr::from(Identifier::private_from_varname(name));
let Some(key) = keys.next() else {
return None;
};
let key = keys.next()?;
let attr_name = Expr::from(Literal::str(
format!("\"{}\"", key.inspect().clone()),
key.ln_begin().unwrap_or(0),
Expand Down

0 comments on commit f5a21ca

Please sign in to comment.