mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 05:54:33 +00:00
chore: add Planner
This commit is contained in:
parent
3085229801
commit
e71c0d7720
7 changed files with 250 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use erg_common::config::ErgConfig;
|
||||
use erg_common::pathutil::NormalizedPathBuf;
|
||||
|
||||
use crate::context::Context;
|
||||
|
||||
|
@ -48,7 +49,7 @@ impl SharedCompilerResource {
|
|||
self_
|
||||
}
|
||||
|
||||
pub fn inherit(&self, path: PathBuf) -> Self {
|
||||
pub fn inherit<P: Into<NormalizedPathBuf>>(&self, path: P) -> Self {
|
||||
let mut _self = self.clone();
|
||||
_self.promises.path = path.into();
|
||||
_self
|
||||
|
|
|
@ -106,6 +106,7 @@ impl ModuleGraph {
|
|||
|
||||
/// returns Err (and do nothing) if this operation makes a cycle
|
||||
pub fn inc_ref(&mut self, referrer: &Path, depends_on: PathBuf) -> Result<(), IncRefError> {
|
||||
self.add_node_if_none(referrer);
|
||||
let referrer = NormalizedPathBuf::new(referrer.to_path_buf());
|
||||
let depends_on = NormalizedPathBuf::new(depends_on);
|
||||
if self.ancestors(&depends_on).contains(&referrer) && referrer != depends_on {
|
||||
|
@ -141,6 +142,9 @@ impl ModuleGraph {
|
|||
pub fn remove(&mut self, path: &Path) {
|
||||
let path = NormalizedPathBuf::new(path.to_path_buf());
|
||||
self.0.retain(|n| n.id != path);
|
||||
for node in self.0.iter_mut() {
|
||||
node.depends_on.retain(|p| *p != path);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rename_path(&mut self, old: &Path, new: PathBuf) {
|
||||
|
@ -238,4 +242,8 @@ impl SharedModuleGraph {
|
|||
pub fn initialize(&self) {
|
||||
self.0.borrow_mut().initialize();
|
||||
}
|
||||
|
||||
pub fn clone_inner(&self) -> ModuleGraph {
|
||||
self.0.borrow().clone()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue