fix: module cache bug

This commit is contained in:
Shunsuke Shibayama 2023-10-09 23:40:58 +09:00
parent c14a60e329
commit a31f23a093
5 changed files with 33 additions and 4 deletions

View file

@ -77,6 +77,16 @@ impl SharedCompilerResource {
self.warns.remove(path);
}
pub fn clear_path(&self, path: &NormalizedPathBuf) {
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: &NormalizedPathBuf, new: NormalizedPathBuf) {
self.mod_cache.rename_path(old, new.clone());
self.py_mod_cache.rename_path(old, new.clone());

View file

@ -64,6 +64,7 @@ impl ModuleGraph {
.unwrap_or(false)
}
/// (usually) `path` is not contained
pub fn children(&self, path: &NormalizedPathBuf) -> Set<NormalizedPathBuf> {
self.0
.iter()
@ -72,6 +73,7 @@ impl ModuleGraph {
.collect()
}
/// (usually) `path` is not contained
fn parents(&self, path: &NormalizedPathBuf) -> Option<&Set<NormalizedPathBuf>> {
self.0.iter().find(|n| &n.id == path).map(|n| &n.depends_on)
}
@ -200,10 +202,12 @@ impl SharedModuleGraph {
self.0.borrow().depends_on(path, target)
}
/// (usually) `path` is not contained
pub fn children(&self, path: &NormalizedPathBuf) -> Set<NormalizedPathBuf> {
self.0.borrow().children(path)
}
/// (usually) `path` is not contained
pub fn ancestors(&self, path: &NormalizedPathBuf) -> Set<NormalizedPathBuf> {
self.0.borrow().ancestors(path)
}