From ddb483c2cf733dba776fd6a5589f28871a2c3e62 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sun, 25 Jun 2023 23:06:40 +0900 Subject: [PATCH] fix: minor bugs --- .pre-commit-config.yaml | 2 +- Cargo.toml | 1 - crates/erg_common/spawn.rs | 37 +++++++++++++-------------- crates/erg_compiler/lower.rs | 2 +- crates/erg_compiler/module/index.rs | 6 ++++- doc/EN/dev_guide/build_features.md | 4 --- doc/JA/dev_guide/build_features.md | 4 --- doc/zh_CN/dev_guide/build_features.md | 4 --- doc/zh_TW/dev_guide/build_features.md | 4 --- 9 files changed, 25 insertions(+), 39 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 107c3668..4ad9cb50 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: - id: cargo-test exclude: ^doc/|^.github/|^.gitmessage|.md name: Cargo test - entry: cargo test --features large_thread --features pre-commit -- --nocapture + entry: cargo test -- --nocapture language: system pass_filenames: false # - id: rust-clippy diff --git a/Cargo.toml b/Cargo.toml index efeb9ecd..b6b45e21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,6 @@ traditional_chinese = [ ] unicode = ["erg_common/unicode", "erg_parser/unicode", "erg_compiler/unicode", "els/unicode"] pretty = ["erg_common/pretty", "erg_parser/pretty", "erg_compiler/pretty", "els/pretty"] -pre-commit = [] large_thread = [ "erg_common/large_thread", "erg_parser/large_thread", diff --git a/crates/erg_common/spawn.rs b/crates/erg_common/spawn.rs index cb0ac630..e4070dac 100644 --- a/crates/erg_common/spawn.rs +++ b/crates/erg_common/spawn.rs @@ -2,6 +2,12 @@ pub use backtrace_on_stack_overflow; use std::thread::{self, JoinHandle}; +const STACK_SIZE: usize = if cfg!(feature = "large_thread") { + 8 * 1024 * 1024 +} else { + 4 * 1024 * 1024 +}; + #[macro_export] macro_rules! enable_overflow_stacktrace { () => { @@ -12,30 +18,24 @@ macro_rules! enable_overflow_stacktrace { }; } -/// Execute a function in a new thread on Windows, otherwise just run it. -/// -/// Windows has a smaller default stack size than other OSs, which may cause a stack overflow, especially in the parsing process. +/// Execute the function in a new thread. +/// The default stack size is 4MB, and with the `large_thread` flag, the stack size is 8MB. pub fn exec_new_thread(run: F, name: &str) -> T where F: FnOnce() -> T + Send + 'static, T: Send + 'static, { enable_overflow_stacktrace!(); - if cfg!(windows) || cfg!(feature = "large_thread") { - const STACK_SIZE: usize = 4 * 1024 * 1024; - let child = thread::Builder::new() - .name(name.to_string()) - .stack_size(STACK_SIZE) - .spawn(run) - .unwrap(); - // Wait for thread to join - child.join().unwrap_or_else(|err| { - eprintln!("Thread panicked: {err:?}"); - std::process::exit(1); - }) - } else { - run() - } + let child = thread::Builder::new() + .name(name.to_string()) + .stack_size(STACK_SIZE) + .spawn(run) + .unwrap(); + // Wait for thread to join + child.join().unwrap_or_else(|err| { + eprintln!("Thread panicked: {err:?}"); + std::process::exit(1); + }) } pub fn spawn_new_thread(run: F, name: &str) -> JoinHandle @@ -44,7 +44,6 @@ where T: Send + 'static, { enable_overflow_stacktrace!(); - const STACK_SIZE: usize = 4 * 1024 * 1024; thread::Builder::new() .name(name.to_string()) .stack_size(STACK_SIZE) diff --git a/crates/erg_compiler/lower.rs b/crates/erg_compiler/lower.rs index 1adc7af9..561566ba 100644 --- a/crates/erg_compiler/lower.rs +++ b/crates/erg_compiler/lower.rs @@ -2520,8 +2520,8 @@ impl ASTLowerer { self.warn_implicit_union(&hir); self.warn_unused_expr(&hir.module, mode); self.check_doc_comments(&hir); + self.warn_unused_local_vars(mode); if &self.module.context.name[..] == "" || ELS { - self.warn_unused_local_vars(mode); if ELS { self.module.context.shared().promises.join_children(); } else { diff --git a/crates/erg_compiler/module/index.rs b/crates/erg_compiler/module/index.rs index 0df12c15..b87dd389 100644 --- a/crates/erg_compiler/module/index.rs +++ b/crates/erg_compiler/module/index.rs @@ -35,7 +35,11 @@ pub struct ModuleIndexValue { impl fmt::Display for ModuleIndexValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{{ vi: {}, referrers: {} }}", self.vi, self.referrers) + write!( + f, + "{{ name: {}, vi: {}, referrers: {} }}", + self.name, self.vi, self.referrers + ) } } diff --git a/doc/EN/dev_guide/build_features.md b/doc/EN/dev_guide/build_features.md index 746050ef..c9076441 100644 --- a/doc/EN/dev_guide/build_features.md +++ b/doc/EN/dev_guide/build_features.md @@ -28,10 +28,6 @@ Erg internal options, help (help, copyright, license, etc.) and errors are displ The compiler makes the display rich. -## pre-commit - -Used to run tests in pre-commit. It's a bug workaround. - ## large_thread Increase the thread stack size. Used for Windows execution and test execution. diff --git a/doc/JA/dev_guide/build_features.md b/doc/JA/dev_guide/build_features.md index 8f623db1..f41561b0 100644 --- a/doc/JA/dev_guide/build_features.md +++ b/doc/JA/dev_guide/build_features.md @@ -30,10 +30,6 @@ Erg 内部オプション、ヘルプ (ヘルプ、著作権、ライセンス コンパイラが表示をリッチにする。 -## pre-commit - -テストを実行する為に使用される。このフラグがないと特定の環境においてテストが失敗する。バグワークアラウンドである。 - ## large_thread スレッドのスタックサイズを大きくする。Windowsでの実行やテスト実行のために使用される。 diff --git a/doc/zh_CN/dev_guide/build_features.md b/doc/zh_CN/dev_guide/build_features.md index cc6b0c87..5a1e74b4 100644 --- a/doc/zh_CN/dev_guide/build_features.md +++ b/doc/zh_CN/dev_guide/build_features.md @@ -26,10 +26,6 @@ Erg 内部选项、帮助(帮助、版权、许可证等)和错误显示为繁 使得编译器显示丰富内容 -## pre-commit - -用于在预提交中运行测试。这是一个bug解决方案 - ## large_thread 增加线程堆栈大小。用于Windows执行和测试执行 diff --git a/doc/zh_TW/dev_guide/build_features.md b/doc/zh_TW/dev_guide/build_features.md index 3d6de4bd..c1f75479 100644 --- a/doc/zh_TW/dev_guide/build_features.md +++ b/doc/zh_TW/dev_guide/build_features.md @@ -26,10 +26,6 @@ Erg 內部選項、幫助(幫助、版權、許可證等)和錯誤顯示為繁 使得編譯器顯示豐富內容 -## pre-commit - -用于在預提交中運行測試。這是一個bug解決方案 - ## large_thread 增加線程堆棧大小。用于Windows執行和測試執行