Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ mimalloc = "0.1.43"
nonmax = "0.5.5"
num-bigint = "0.4.6"
num-traits = "0.2.19"
papaya = "0.2.0"
petgraph = "0.7.1"
phf = "0.11.3"
pico-args = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ oxc_syntax = { workspace = true, features = ["serialize"] }
bitflags = { workspace = true }
convert_case = { workspace = true }
cow-utils = { workspace = true }
dashmap = { workspace = true }
fast-glob = { workspace = true }
globset = { workspace = true }
ignore = { workspace = true }
Expand All @@ -49,6 +48,7 @@ language-tags = { workspace = true }
lazy_static = { workspace = true }
memchr = { workspace = true }
nonmax = { workspace = true }
papaya = { workspace = true }
phf = { workspace = true, features = ["macros"] }
rayon = { workspace = true }
regex = { workspace = true }
Expand Down
26 changes: 14 additions & 12 deletions crates/oxc_linter/src/service/module_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::{
sync::{Arc, Condvar, Mutex},
};

use dashmap::{mapref::one::Ref, DashMap};
use papaya::HashMap;
use rustc_hash::{FxBuildHasher, FxHashMap};

use crate::ModuleRecord;

type FxDashMap<K, V> = DashMap<K, V, FxBuildHasher>;
type FxDashMap<K, V> = HashMap<K, V, FxBuildHasher>;

/// `CacheState` and `CacheStateEntry` are used to fix the problem where
/// there is a brief moment when a concurrent fetch can miss the cache.
Expand All @@ -21,7 +21,7 @@ type FxDashMap<K, V> = DashMap<K, V, FxBuildHasher>;
///
/// See the "problem section" in <https://medium.com/@polyglot_factotum/rust-concurrency-patterns-condvars-and-locks-e278f18db74f>
/// and the solution is copied here to fix the issue.
type CacheState = Mutex<FxHashMap<Box<Path>, Arc<(Mutex<CacheStateEntry>, Condvar)>>>;
type CacheState = Mutex<FxHashMap<OsString, Arc<(Mutex<CacheStateEntry>, Condvar)>>>;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum CacheStateEntry {
Expand All @@ -47,8 +47,8 @@ pub(super) struct ModuleCache {

impl ModuleCache {
#[inline]
pub fn get(&self, path: &Path) -> Option<Ref<'_, OsString, ModuleState>> {
self.modules.get(path.as_os_str())
pub fn get(&self, path: &Path) -> Option<ModuleState> {
self.modules.pin().get(path.as_os_str()).cloned()
}

#[inline]
Expand All @@ -59,17 +59,17 @@ impl ModuleCache {
pub(super) fn init_cache_state(&self, path: &Path) -> bool {
let (lock, cvar) = {
let mut state_map = self.cache_state.lock().expect("Failed to lock cache state");
&*Arc::clone(state_map.entry(path.to_path_buf().into_boxed_path()).or_insert_with(
|| Arc::new((Mutex::new(CacheStateEntry::ReadyToConstruct), Condvar::new())),
))
&*Arc::clone(state_map.entry(path.as_os_str().to_os_string()).or_insert_with(|| {
Arc::new((Mutex::new(CacheStateEntry::ReadyToConstruct), Condvar::new()))
}))
};
let mut state = cvar
.wait_while(lock.lock().expect("Failed lock inner cache state"), |state| {
matches!(*state, CacheStateEntry::PendingStore(_))
})
.unwrap();

let cache_hit = if self.modules.contains_key(path.as_os_str()) {
let cache_hit = if self.modules.pin().contains_key(path.as_os_str()) {
true
} else {
let i = if let CacheStateEntry::PendingStore(i) = *state { i.get() } else { 0 };
Expand All @@ -89,14 +89,16 @@ impl ModuleCache {
/// # Panics
/// If a cache entry for `path` does not exist. You must call `init_cache_state` first.
pub(super) fn add_resolved_module(&self, path: &Path, module_record: Arc<ModuleRecord>) {
self.modules.insert(path.as_os_str().to_os_string(), ModuleState::Resolved(module_record));
self.modules
.pin()
.insert(path.as_os_str().to_os_string(), ModuleState::Resolved(module_record));
self.update_cache_state(path);
}

/// # Panics
/// If a cache entry for `path` does not exist. You must call `init_cache_state` first.
pub(super) fn ignore_path(&self, path: &Path) {
self.modules.insert(path.as_os_str().to_os_string(), ModuleState::Ignored);
self.modules.pin().insert(path.as_os_str().to_os_string(), ModuleState::Ignored);
self.update_cache_state(path);
}

Expand All @@ -107,7 +109,7 @@ impl ModuleCache {
let mut state_map = self.cache_state.lock().expect("Failed to lock cache state");
&*Arc::clone(
state_map
.get_mut(path)
.get_mut(path.as_os_str())
.expect("Entry in http-cache state to have been previously inserted"),
)
};
Expand Down
16 changes: 8 additions & 8 deletions crates/oxc_linter/src/service/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ impl Runtime {
let path = resolution.path();
self.process_path(path, tx_error);
// Append target_module to loaded_modules
if let Some(target_ref) = self.modules.get(path) {
if let ModuleState::Resolved(target_module_record) = target_ref.value() {
module_record
.loaded_modules
.write()
.unwrap()
.insert(specifier.clone(), Arc::clone(target_module_record));
}
if let Some(ModuleState::Resolved(target_module_record)) =
self.modules.get(path)
{
module_record
.loaded_modules
.write()
.unwrap()
.insert(specifier.clone(), Arc::clone(&target_module_record));
};
});

Expand Down
Loading