mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +00:00
commit
01fae890a4
12 changed files with 244 additions and 67 deletions
|
@ -54,27 +54,37 @@ impl SharedCompilerResource {
|
|||
_self
|
||||
}
|
||||
|
||||
/// Clear all but builtin modules
|
||||
pub fn clear_all(&self) {
|
||||
self.mod_cache.initialize();
|
||||
self.py_mod_cache.initialize();
|
||||
self.index.initialize();
|
||||
self.graph.initialize();
|
||||
self.trait_impls.initialize();
|
||||
// self.trait_impls.initialize();
|
||||
self.promises.initialize();
|
||||
self.errors.clear();
|
||||
self.warns.clear();
|
||||
}
|
||||
|
||||
/// Clear all information about the module. All child modules are also cleared.
|
||||
pub fn clear(&self, path: &Path) {
|
||||
for child in self.graph.children(path) {
|
||||
self.clear(&child);
|
||||
}
|
||||
self.mod_cache.remove(path);
|
||||
self.py_mod_cache.remove(path);
|
||||
self.index.remove_path(path);
|
||||
self.graph.remove(path);
|
||||
self.promises.remove(path);
|
||||
// self.errors.remove(path);
|
||||
// self.warns.remove(path);
|
||||
}
|
||||
|
||||
pub fn rename_path(&self, old: &Path, new: PathBuf) {
|
||||
self.mod_cache.rename_path(old, new.clone());
|
||||
self.py_mod_cache.rename_path(old, new.clone());
|
||||
self.index.rename_path(old, new.clone());
|
||||
self.graph.rename_path(old, new);
|
||||
self.graph.rename_path(old, new.clone());
|
||||
self.promises.rename(old, new);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ impl ModuleGraph {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Do not erase relationships with modules that depend on `path`
|
||||
pub fn remove(&mut self, path: &Path) {
|
||||
let path = NormalizedPathBuf::new(path.to_path_buf());
|
||||
self.0.retain(|n| n.id != path);
|
||||
|
|
|
@ -61,6 +61,15 @@ impl TraitImpls {
|
|||
self.cache.remove(path)
|
||||
}
|
||||
|
||||
pub fn rename<Q: Eq + Hash + ?Sized>(&mut self, old: &Q, new: Str)
|
||||
where
|
||||
Str: Borrow<Q>,
|
||||
{
|
||||
if let Some(impls) = self.remove(old) {
|
||||
self.register(new, impls);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialize(&mut self) {
|
||||
self.cache.clear();
|
||||
}
|
||||
|
@ -123,6 +132,13 @@ impl SharedTraitImpls {
|
|||
self.0.borrow_mut().remove(path)
|
||||
}
|
||||
|
||||
pub fn rename<Q: Eq + Hash + ?Sized>(&self, old: &Q, new: Str)
|
||||
where
|
||||
Str: Borrow<Q>,
|
||||
{
|
||||
self.0.borrow_mut().rename(old, new);
|
||||
}
|
||||
|
||||
pub fn ref_inner(&self) -> MappedRwLockReadGuard<Dict<Str, Set<TraitImpl>>> {
|
||||
RwLockReadGuard::map(self.0.borrow(), |tis| &tis.cache)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::thread::{current, JoinHandle, ThreadId};
|
|||
use erg_common::dict::Dict;
|
||||
use erg_common::pathutil::NormalizedPathBuf;
|
||||
use erg_common::shared::Shared;
|
||||
use erg_common::spawn::safe_yield;
|
||||
|
||||
use super::SharedModuleGraph;
|
||||
|
||||
|
@ -102,6 +103,21 @@ impl SharedPromises {
|
|||
.insert(path, Promise::running(handle));
|
||||
}
|
||||
|
||||
pub fn remove(&self, path: &Path) {
|
||||
self.promises.borrow_mut().remove(path);
|
||||
}
|
||||
|
||||
pub fn initialize(&self) {
|
||||
self.promises.borrow_mut().clear();
|
||||
}
|
||||
|
||||
pub fn rename(&self, old: &Path, new: PathBuf) {
|
||||
let Some(promise) = self.promises.borrow_mut().remove(old) else {
|
||||
return;
|
||||
};
|
||||
self.promises.borrow_mut().insert(new.into(), promise);
|
||||
}
|
||||
|
||||
pub fn is_registered(&self, path: &Path) -> bool {
|
||||
self.promises.borrow().get(path).is_some()
|
||||
}
|
||||
|
@ -140,7 +156,7 @@ impl SharedPromises {
|
|||
.get(path)
|
||||
.is_some_and(|p| !p.is_finished())
|
||||
{
|
||||
std::thread::yield_now();
|
||||
safe_yield();
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -152,7 +168,7 @@ impl SharedPromises {
|
|||
|
||||
pub fn join(&self, path: &Path) -> std::thread::Result<()> {
|
||||
while let Some(Promise::Joining) | None = self.promises.borrow().get(path) {
|
||||
std::thread::yield_now();
|
||||
safe_yield();
|
||||
}
|
||||
let promise = self.promises.borrow_mut().get_mut(path).unwrap().take();
|
||||
self.join_checked(path, promise)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue