From f78e4909de12954ce1efa69f746912d6fa242c4f Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Fri, 13 Sep 2024 01:07:25 +0900 Subject: [PATCH] chore: add feature `single-thread` --- Cargo.toml | 1 + crates/erg_common/Cargo.toml | 1 + crates/erg_common/consts.rs | 1 + crates/erg_compiler/Cargo.toml | 1 + crates/erg_compiler/build_package.rs | 11 ++++++++--- crates/erg_compiler/module/promise.rs | 5 +++++ crates/erg_linter/Cargo.toml | 1 + crates/erg_parser/Cargo.toml | 1 + 8 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7bf2b0c0..4b4018d15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,6 +70,7 @@ full-repl = ["erg_common/full-repl"] full = ["els", "full-repl", "unicode", "pretty"] experimental = ["erg_common/experimental", "erg_parser/experimental", "erg_compiler/experimental", "erg_linter/experimental"] log-level-error = ["erg_common/log-level-error", "erg_parser/log-level-error", "erg_compiler/log-level-error", "erg_linter/log-level-error"] +single-thread = ["erg_common/single-thread", "erg_parser/single-thread", "erg_compiler/single-thread", "erg_linter/single-thread"] [workspace.dependencies] erg_common = { version = "0.6.43", path = "./crates/erg_common" } diff --git a/crates/erg_common/Cargo.toml b/crates/erg_common/Cargo.toml index 0d58e81c4..32d712380 100644 --- a/crates/erg_common/Cargo.toml +++ b/crates/erg_common/Cargo.toml @@ -26,6 +26,7 @@ full-repl = ["dep:crossterm"] experimental = [] pylib = ["dep:pyo3"] log-level-error = [] +single-thread = [] [target.'cfg(unix)'.dependencies] backtrace-on-stack-overflow = { version = "0.3.0", optional = true } diff --git a/crates/erg_common/consts.rs b/crates/erg_common/consts.rs index ca842cd25..62e4bd0ad 100644 --- a/crates/erg_common/consts.rs +++ b/crates/erg_common/consts.rs @@ -11,3 +11,4 @@ pub const LOG_LEVEL_ERROR: bool = cfg!(feature = "log-level-error"); pub const EXPERIMENTAL_MODE: bool = cfg!(feature = "experimental"); pub const BACKTRACE_MODE: bool = cfg!(feature = "backtrace"); pub const GAL: bool = cfg!(feature = "gal"); +pub const SINGLE_THREAD: bool = cfg!(feature = "single-thread"); diff --git a/crates/erg_compiler/Cargo.toml b/crates/erg_compiler/Cargo.toml index fdf5164ce..c2502bf36 100644 --- a/crates/erg_compiler/Cargo.toml +++ b/crates/erg_compiler/Cargo.toml @@ -43,6 +43,7 @@ experimental = ["erg_common/experimental", "erg_parser/experimental"] pylib = ["dep:pyo3", "erg_common/pylib", "erg_parser/pylib"] pylib_compiler = ["pylib"] log-level-error = ["erg_common/log-level-error", "erg_parser/log-level-error"] +single-thread = ["erg_common/single-thread", "erg_parser/single-thread"] [dependencies] erg_common = { workspace = true } diff --git a/crates/erg_compiler/build_package.rs b/crates/erg_compiler/build_package.rs index 8f96e9108..0c46ec8f1 100644 --- a/crates/erg_compiler/build_package.rs +++ b/crates/erg_compiler/build_package.rs @@ -13,7 +13,7 @@ use std::time::{Duration, SystemTime}; use erg_common::config::ErgMode; use erg_common::config::ErgConfig; -use erg_common::consts::{ELS, ERG_MODE}; +use erg_common::consts::{ELS, ERG_MODE, SINGLE_THREAD}; use erg_common::debug_power_assert; use erg_common::dict::Dict; use erg_common::env::is_std_decl_path; @@ -943,8 +943,13 @@ impl } } }; - let handle = spawn_new_thread(run, &__name__); - self.shared.promises.insert(path, handle); + if SINGLE_THREAD { + run(); + self.shared.promises.mark_as_joined(path); + } else { + let handle = spawn_new_thread(run, &__name__); + self.shared.promises.insert(path, handle); + } } /// FIXME: bug with inter-process sharing of type variables (pyimport "math") diff --git a/crates/erg_compiler/module/promise.rs b/crates/erg_compiler/module/promise.rs index af351bf62..42525989e 100644 --- a/crates/erg_compiler/module/promise.rs +++ b/crates/erg_compiler/module/promise.rs @@ -119,6 +119,11 @@ impl SharedPromises { .insert(path, Promise::running(handle)); } + pub fn mark_as_joined(&self, path: impl Into) { + let path = path.into(); + self.promises.borrow_mut().insert(path, Promise::Joined); + } + pub fn remove(&self, path: &NormalizedPathBuf) -> Option { self.promises.borrow_mut().remove(path) } diff --git a/crates/erg_linter/Cargo.toml b/crates/erg_linter/Cargo.toml index cc2cdf78b..9c1a46071 100644 --- a/crates/erg_linter/Cargo.toml +++ b/crates/erg_linter/Cargo.toml @@ -40,6 +40,7 @@ full-repl = ["erg_common/full-repl"] full = ["full-repl", "unicode", "pretty"] experimental = ["erg_common/experimental", "erg_parser/experimental", "erg_compiler/experimental"] log-level-error = ["erg_common/log-level-error", "erg_parser/log-level-error", "erg_compiler/log-level-error"] +single-thread = ["erg_common/single-thread", "erg_parser/single-thread", "erg_compiler/single-thread"] [dependencies] erg_common = { workspace = true } diff --git a/crates/erg_parser/Cargo.toml b/crates/erg_parser/Cargo.toml index a3be80877..b19e87880 100644 --- a/crates/erg_parser/Cargo.toml +++ b/crates/erg_parser/Cargo.toml @@ -21,6 +21,7 @@ experimental = ["erg_common/experimental"] pylib = ["dep:pyo3", "erg_common/pylib"] pylib_parser = ["pylib"] log-level-error = ["erg_common/log-level-error"] +single-thread = ["erg_common/single-thread"] [dependencies] erg_common = { workspace = true }