fix: minor bugs

This commit is contained in:
Shunsuke Shibayama 2023-06-25 23:06:40 +09:00
parent 75a832e933
commit ddb483c2cf
9 changed files with 25 additions and 39 deletions

View file

@ -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

View file

@ -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",

View file

@ -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<F, T>(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<F, T>(run: F, name: &str) -> JoinHandle<T>
@ -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)

View file

@ -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[..] == "<module>" || ELS {
self.warn_unused_local_vars(mode);
if ELS {
self.module.context.shared().promises.join_children();
} else {

View file

@ -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
)
}
}

View file

@ -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.

View file

@ -30,10 +30,6 @@ Erg 内部オプション、ヘルプ (ヘルプ、著作権、ライセンス
コンパイラが表示をリッチにする。
## pre-commit
テストを実行する為に使用される。このフラグがないと特定の環境においてテストが失敗する。バグワークアラウンドである。
## large_thread
スレッドのスタックサイズを大きくする。Windowsでの実行やテスト実行のために使用される。

View file

@ -26,10 +26,6 @@ Erg 内部选项、帮助(帮助、版权、许可证等)和错误显示为繁
使得编译器显示丰富内容
## pre-commit
用于在预提交中运行测试。这是一个bug解决方案
## large_thread
增加线程堆栈大小。用于Windows执行和测试执行

View file

@ -26,10 +26,6 @@ Erg 內部選項、幫助(幫助、版權、許可證等)和錯誤顯示為繁
使得編譯器顯示豐富內容
## pre-commit
用于在預提交中運行測試。這是一個bug解決方案
## large_thread
增加線程堆棧大小。用于Windows執行和測試執行