Skip to content

Commit

Permalink
chore: remove redundant params of PackageBuilder::parse
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Aug 25, 2024
1 parent 82522ed commit 32968ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 4 additions & 0 deletions crates/erg_common/pathutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ impl NormalizedPathBuf {
pub fn to_path_buf(&self) -> PathBuf {
self.0.clone()
}

pub fn try_read(&self) -> std::io::Result<String> {
std::fs::read_to_string(&self.0)
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down
19 changes: 7 additions & 12 deletions crates/erg_compiler/build_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
None => return Ok(()),
};
let from_path = NormalizedPathBuf::from(cfg.input.path());
let mut import_cfg = cfg.inherit(import_path.clone());
let import_cfg = cfg.inherit(import_path.clone());
let import_path = NormalizedPathBuf::from(import_path.clone());
self.shared.graph.add_node_if_none(&import_path);
// If we import `foo/bar`, we also need to import `foo`
Expand All @@ -714,7 +714,7 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
let root_import_path = root_path.and_then(|path| cfg.input.resolve_path(path, cfg));
if let Some(root_import_path) = root_import_path.map(NormalizedPathBuf::from) {
if project_entry_dir_of(&root_import_path) != project_entry_dir_of(&from_path) {
let mut root_import_cfg = cfg.inherit(root_import_path.to_path_buf());
let root_import_cfg = cfg.inherit(root_import_path.to_path_buf());
self.shared.graph.add_node_if_none(&root_import_path);
let _ = self
.shared
Expand All @@ -725,8 +725,7 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
|| self.asts.contains_key(&root_import_path)
{
// pass
} else if let Ok(mut ast) = self.parse(cfg, &mut root_import_cfg, &root_import_path)
{
} else if let Ok(mut ast) = self.parse(&root_import_path) {
let _ = self.resolve(&mut ast, &root_import_cfg);
let prev = self.asts.insert(root_import_path, (__name__.clone(), ast));
debug_assert!(prev.is_none());
Expand All @@ -747,7 +746,7 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
{
return Ok(());
}
let Ok(mut ast) = self.parse(cfg, &mut import_cfg, &import_path) else {
let Ok(mut ast) = self.parse(&import_path) else {
return Ok(());
};
if let Err(mut errs) = self.resolve(&mut ast, &import_cfg) {
Expand All @@ -770,15 +769,11 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
Ok(())
}

fn parse(
&mut self,
cfg: &ErgConfig,
import_cfg: &mut ErgConfig,
import_path: &NormalizedPathBuf,
) -> Result<AST, ()> {
let Ok(src) = import_cfg.input.try_read() else {
fn parse(&mut self, import_path: &NormalizedPathBuf) -> Result<AST, ()> {
let Ok(src) = import_path.try_read() else {
return Err(());
};
let cfg = self.cfg.inherit(import_path.to_path_buf());
let result = if import_path.extension() == Some(OsStr::new("er")) {
let mut ast_builder = DefaultASTBuilder::new(cfg.copy());
ast_builder.build_ast(src)
Expand Down

0 comments on commit 32968ba

Please sign in to comment.