diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-12-14 13:09:05 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-12-14 13:09:05 +0100 |
| commit | 4dfb91d238bc1f43ae9494d6fa9fa23697bb5630 (patch) | |
| tree | 4343fc17b94b804bdc6503a12fe9b91ff38a8606 /src | |
| parent | 664ede88faf57b8fc09715fc66cd9e46490ce64d (diff) | |
| download | rust-4dfb91d238bc1f43ae9494d6fa9fa23697bb5630.tar.gz rust-4dfb91d238bc1f43ae9494d6fa9fa23697bb5630.zip | |
Always run rustc in a thread
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_driver/lib.rs | 66 |
1 files changed, 5 insertions, 61 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 41c9b22afe0..cec0f31819d 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1482,69 +1482,13 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any where F: FnOnce() -> R + Send + 'static, R: Send + 'static, { - #[cfg(all(unix, not(target_os = "haiku")))] - let spawn_thread = unsafe { - // Fetch the current resource limits - let mut rlim = libc::rlimit { - rlim_cur: 0, - rlim_max: 0, - }; - if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { - let err = io::Error::last_os_error(); - error!("in_rustc_thread: error calling getrlimit: {}", err); - true - } else if rlim.rlim_max < STACK_SIZE as libc::rlim_t { - true - } else if rlim.rlim_cur < STACK_SIZE as libc::rlim_t { - std::rt::deinit_stack_guard(); - rlim.rlim_cur = STACK_SIZE as libc::rlim_t; - if libc::setrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { - let err = io::Error::last_os_error(); - error!("in_rustc_thread: error calling setrlimit: {}", err); - std::rt::update_stack_guard(); - true - } else { - std::rt::update_stack_guard(); - false - } - } else { - false - } - }; - - // We set the stack size at link time. See src/rustc/rustc.rs. - #[cfg(windows)] - let spawn_thread = false; - - #[cfg(target_os = "haiku")] - let spawn_thread = unsafe { - // Haiku does not have setrlimit implemented for the stack size. - // By default it does have the 16 MB stack limit, but we check this in - // case the minimum STACK_SIZE changes or Haiku's defaults change. - let mut rlim = libc::rlimit { - rlim_cur: 0, - rlim_max: 0, - }; - if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { - let err = io::Error::last_os_error(); - error!("in_rustc_thread: error calling getrlimit: {}", err); - true - } else if rlim.rlim_cur >= STACK_SIZE { - false - } else { - true - } - }; - - #[cfg(not(any(windows, unix)))] - let spawn_thread = true; - - // The or condition is added from backward compatibility. - if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() { + // We need a thread for soundness of thread local storage in rustc. For debugging purposes + // we allow an escape hatch where everything runs on the main thread. + if env::var_os("RUSTC_UNSTABLE_NO_MAIN_THREAD").is_none() { let mut cfg = thread::Builder::new().name(name); - // FIXME: Hacks on hacks. If the env is trying to override the stack size - // then *don't* set it explicitly. + // If the env is trying to override the stack size then *don't* set it explicitly. + // The libstd thread impl will fetch the `RUST_MIN_STACK` env var itself. if env::var_os("RUST_MIN_STACK").is_none() { cfg = cfg.stack_size(STACK_SIZE); } |
