mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
chore: add Context::mod_cached
This commit is contained in:
parent
6e2abac74e
commit
6bbd71f8bd
2 changed files with 9 additions and 3 deletions
|
@ -50,7 +50,11 @@ pub enum SubstituteResult {
|
|||
|
||||
impl Context {
|
||||
pub(crate) fn mod_registered(&self, path: &Path) -> bool {
|
||||
self.shared.is_some() && self.promises().is_registered(path)
|
||||
(self.shared.is_some() && self.promises().is_registered(path)) || self.mod_cached(path)
|
||||
}
|
||||
|
||||
pub(crate) fn mod_cached(&self, path: &Path) -> bool {
|
||||
self.mod_cache().get(path).is_some() || self.py_mod_cache().get(path).is_some()
|
||||
}
|
||||
|
||||
/// Get the context of the module. If it was in analysis, wait until analysis is complete and join the thread.
|
||||
|
@ -58,6 +62,8 @@ impl Context {
|
|||
pub(crate) fn get_mod_with_path(&self, path: &Path) -> Option<&Context> {
|
||||
if self.module_path() == path {
|
||||
return self.get_module();
|
||||
} else if let Some(ctx) = self.get_module_from_stack(path) {
|
||||
return Some(ctx);
|
||||
}
|
||||
if self.shared.is_some()
|
||||
&& self.promises().is_registered(path)
|
||||
|
|
|
@ -1077,12 +1077,12 @@ impl Context {
|
|||
.or(Some(self))
|
||||
}
|
||||
|
||||
pub(crate) fn _get_module_from_stack(&self, path: &Path) -> Option<&Context> {
|
||||
pub(crate) fn get_module_from_stack(&self, path: &Path) -> Option<&Context> {
|
||||
self.get_outer().and_then(|outer| {
|
||||
if outer.kind == ContextKind::Module && outer.module_path() == path {
|
||||
Some(outer)
|
||||
} else {
|
||||
outer._get_module_from_stack(path)
|
||||
outer.get_module_from_stack(path)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue