fix(els): minor bugs

This commit is contained in:
Shunsuke Shibayama 2024-02-26 11:42:19 +09:00
parent f612340e80
commit 46610a1ae0
7 changed files with 55 additions and 18 deletions

View file

@ -289,6 +289,19 @@ impl SharedModuleCache {
ref_.get(path).map(|entry| &entry.module)
}
pub fn raw_ref_ctx_with_timeout<Q: Eq + Hash + ?Sized>(
&self,
path: &Q,
timeout: std::time::Duration,
) -> Option<&ModuleContext>
where
NormalizedPathBuf: Borrow<Q>,
{
let _ref = self.0.try_borrow_for(timeout)?;
let ref_ = unsafe { self.0.as_ptr().as_ref().unwrap() };
ref_.get(path).map(|entry| &entry.module)
}
// HACK: <builtins> is referenced very frequently and mutable references are not taken,
// so it can be take without lock.
pub fn raw_ref_builtins_ctx(&self) -> Option<&ModuleContext> {

View file

@ -142,11 +142,15 @@ impl SharedCompilerResource {
}
}
pub fn raw_ref_ctx(&self, path: &std::path::Path) -> Option<&ModuleContext> {
pub fn raw_ref_ctx_with_timeout(
&self,
path: &std::path::Path,
timeout: std::time::Duration,
) -> Option<&ModuleContext> {
if path.to_string_lossy().ends_with(".d.er") {
self.py_mod_cache.raw_ref_ctx(path)
self.py_mod_cache.raw_ref_ctx_with_timeout(path, timeout)
} else {
self.mod_cache.raw_ref_ctx(path)
self.mod_cache.raw_ref_ctx_with_timeout(path, timeout)
}
}