From b09fce8a8630d3ddb2298cda2bc345355a3e6f9d Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Wed, 14 Dec 2022 05:38:50 +0900 Subject: [PATCH] Add ErgConfig::inherit and remove with_module_path --- compiler/erg_common/config.rs | 16 ++++++++-------- compiler/erg_compiler/context/register.rs | 5 ++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/compiler/erg_common/config.rs b/compiler/erg_common/config.rs index 163e6bac..6a74c59a 100644 --- a/compiler/erg_common/config.rs +++ b/compiler/erg_common/config.rs @@ -225,14 +225,6 @@ impl ErgConfig { } } - pub fn with_module_path(path: PathBuf) -> Self { - Self { - module: Box::leak(path.to_str().unwrap().to_string().into_boxed_str()), - input: Input::File(path), - ..ErgConfig::default() - } - } - /// cloneのエイリアス(実際のcloneコストは低いので) #[inline] pub fn copy(&self) -> Self { @@ -247,6 +239,14 @@ impl ErgConfig { } } + pub fn inherit(&self, path: PathBuf) -> Self { + Self { + module: Box::leak(path.to_str().unwrap().to_string().into_boxed_str()), + input: Input::File(path), + ..self.copy() + } + } + pub fn parse() -> Self { let mut args = env::args(); args.next(); // "ergc" diff --git a/compiler/erg_compiler/context/register.rs b/compiler/erg_compiler/context/register.rs index 1a47524e..98bc6c78 100644 --- a/compiler/erg_compiler/context/register.rs +++ b/compiler/erg_compiler/context/register.rs @@ -1,7 +1,6 @@ use std::option::Option; use std::path::{Path, PathBuf}; -use erg_common::config::ErgConfig; use erg_common::env::erg_pystd_path; use erg_common::levenshtein::get_similar_name; use erg_common::python_util::BUILTIN_PYTHON_MODS; @@ -1215,7 +1214,7 @@ impl Context { if mod_cache.get(&path).is_some() { return Ok(path); } - let cfg = ErgConfig::with_module_path(path.clone()); + let cfg = self.cfg.inherit(path.clone()); let src = cfg.input.read(); let mut builder = HIRBuilder::new_with_cache(cfg, __name__, mod_cache.clone(), py_mod_cache.clone()); @@ -1307,7 +1306,7 @@ impl Context { if py_mod_cache.get(&path).is_some() { return Ok(path); } - let cfg = ErgConfig::with_module_path(path.clone()); + let cfg = self.cfg.inherit(path.clone()); let src = cfg.input.read(); let mut builder = HIRBuilder::new_with_cache( cfg,