Skip to content

Commit

Permalink
chore: add feature single-thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Sep 12, 2024
1 parent 80b6426 commit f78e490
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions crates/erg_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions crates/erg_common/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
1 change: 1 addition & 0 deletions crates/erg_compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
11 changes: 8 additions & 3 deletions crates/erg_compiler/build_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -943,8 +943,13 @@ impl<ASTBuilder: ASTBuildable, HIRBuilder: Buildable>
}
}
};
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")
Expand Down
5 changes: 5 additions & 0 deletions crates/erg_compiler/module/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ impl SharedPromises {
.insert(path, Promise::running(handle));
}

pub fn mark_as_joined(&self, path: impl Into<NormalizedPathBuf>) {
let path = path.into();
self.promises.borrow_mut().insert(path, Promise::Joined);
}

pub fn remove(&self, path: &NormalizedPathBuf) -> Option<Promise> {
self.promises.borrow_mut().remove(path)
}
Expand Down
1 change: 1 addition & 0 deletions crates/erg_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions crates/erg_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit f78e490

Please sign in to comment.