|
25 | 25 | #![feature(rustc_diagnostic_macros)]
|
26 | 26 | #![feature(slice_sort_by_cached_key)]
|
27 | 27 | #![feature(set_stdio)]
|
28 |
| -#![feature(rustc_stack_internals)] |
29 | 28 | #![feature(no_debug)]
|
30 | 29 |
|
31 | 30 | #![recursion_limit="256"]
|
@@ -1481,69 +1480,13 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any
|
1481 | 1480 | where F: FnOnce() -> R + Send + 'static,
|
1482 | 1481 | R: Send + 'static,
|
1483 | 1482 | {
|
1484 |
| - #[cfg(all(unix, not(target_os = "haiku")))] |
1485 |
| - let spawn_thread = unsafe { |
1486 |
| - // Fetch the current resource limits |
1487 |
| - let mut rlim = libc::rlimit { |
1488 |
| - rlim_cur: 0, |
1489 |
| - rlim_max: 0, |
1490 |
| - }; |
1491 |
| - if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { |
1492 |
| - let err = io::Error::last_os_error(); |
1493 |
| - error!("in_rustc_thread: error calling getrlimit: {}", err); |
1494 |
| - true |
1495 |
| - } else if rlim.rlim_max < STACK_SIZE as libc::rlim_t { |
1496 |
| - true |
1497 |
| - } else if rlim.rlim_cur < STACK_SIZE as libc::rlim_t { |
1498 |
| - std::rt::deinit_stack_guard(); |
1499 |
| - rlim.rlim_cur = STACK_SIZE as libc::rlim_t; |
1500 |
| - if libc::setrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { |
1501 |
| - let err = io::Error::last_os_error(); |
1502 |
| - error!("in_rustc_thread: error calling setrlimit: {}", err); |
1503 |
| - std::rt::update_stack_guard(); |
1504 |
| - true |
1505 |
| - } else { |
1506 |
| - std::rt::update_stack_guard(); |
1507 |
| - false |
1508 |
| - } |
1509 |
| - } else { |
1510 |
| - false |
1511 |
| - } |
1512 |
| - }; |
1513 |
| - |
1514 |
| - // We set the stack size at link time. See src/rustc/rustc.rs. |
1515 |
| - #[cfg(windows)] |
1516 |
| - let spawn_thread = false; |
1517 |
| - |
1518 |
| - #[cfg(target_os = "haiku")] |
1519 |
| - let spawn_thread = unsafe { |
1520 |
| - // Haiku does not have setrlimit implemented for the stack size. |
1521 |
| - // By default it does have the 16 MB stack limit, but we check this in |
1522 |
| - // case the minimum STACK_SIZE changes or Haiku's defaults change. |
1523 |
| - let mut rlim = libc::rlimit { |
1524 |
| - rlim_cur: 0, |
1525 |
| - rlim_max: 0, |
1526 |
| - }; |
1527 |
| - if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 { |
1528 |
| - let err = io::Error::last_os_error(); |
1529 |
| - error!("in_rustc_thread: error calling getrlimit: {}", err); |
1530 |
| - true |
1531 |
| - } else if rlim.rlim_cur >= STACK_SIZE { |
1532 |
| - false |
1533 |
| - } else { |
1534 |
| - true |
1535 |
| - } |
1536 |
| - }; |
1537 |
| - |
1538 |
| - #[cfg(not(any(windows, unix)))] |
1539 |
| - let spawn_thread = true; |
1540 |
| - |
1541 |
| - // The or condition is added from backward compatibility. |
1542 |
| - if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() { |
| 1483 | + // We need a thread for soundness of thread local storage in rustc. For debugging purposes |
| 1484 | + // we allow an escape hatch where everything runs on the main thread. |
| 1485 | + if env::var_os("RUSTC_UNSTABLE_NO_MAIN_THREAD").is_none() { |
1543 | 1486 | let mut cfg = thread::Builder::new().name(name);
|
1544 | 1487 |
|
1545 |
| - // FIXME: Hacks on hacks. If the env is trying to override the stack size |
1546 |
| - // then *don't* set it explicitly. |
| 1488 | + // If the env is trying to override the stack size then *don't* set it explicitly. |
| 1489 | + // The libstd thread impl will fetch the `RUST_MIN_STACK` env var itself. |
1547 | 1490 | if env::var_os("RUST_MIN_STACK").is_none() {
|
1548 | 1491 | cfg = cfg.stack_size(STACK_SIZE);
|
1549 | 1492 | }
|
|
0 commit comments