-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Stack overflow on large doctests in edition 2024 on Windows #138248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Just by squinting at the code, I would bet on this line, which is passing that array by value: rust/src/librustdoc/doctest/runner.rs Line 147 in dea1661
I'd at least try passing Oh actually there's another |
I thought I would be able to reproduce this crash on Linux by shrinking my stack size. No luck. I can indeed get stack overflows when building the core doctests by making my stack size 1 MB, but also that stack size is too small to build the compiler so that can't be it. So I think this is somehow actually Windows-specific, or it depends on the very specific CI build configuration. |
For MSVC you increase the default stack limit by adding: compiler.arg(format!("-Clink_arg=/STACK:{}", 8 * 1024 * 1024)); Somewhere in rust/src/librustdoc/doctest.rs Line 529 in dea1661
Or use This could be justified for rustdoc as making the test framework more consistent cross-platform. Though fixing the underlying reason why we use so much stack space would be a good idea. |
Alternatively it could start a thread instead of running on the main thread. That way it could control the stack size directly on all platforms. However, that may be more hazardous for compatibility if something relies on being run on the main thread for some reason (I'm not sure what reason there would be for a doc test but I guess it's possible on some platforms). |
Ah! Of course this is the main thread so I can reproduce the problem on Linux with |
…ize, r=GuillaumeGomez Fix O(tests) stack usage in edition 2024 mergeable doctests Fixes rust-lang#138248 The important change here is that we are not passing a potentially-large array by value. Between the fact that `TestFn` cannot be `Clone` and `test_main` takes a `Vec<TestDescAndFn>`, the only way to call `test::test_main` without O(tests) stack use is to call `Vec::push` many times. The normal test harness does not have this problem because it calls `test_main_static` or `test_main_static_abort`, which take `&[TestDescAndFn]`. Changing `test::test_main` to take a slice is not a simple change, so I'm avoiding doing it here.
Rollup merge of rust-lang#138281 - saethlin:mergeable-doctests-stacksize, r=GuillaumeGomez Fix O(tests) stack usage in edition 2024 mergeable doctests Fixes rust-lang#138248 The important change here is that we are not passing a potentially-large array by value. Between the fact that `TestFn` cannot be `Clone` and `test_main` takes a `Vec<TestDescAndFn>`, the only way to call `test::test_main` without O(tests) stack use is to call `Vec::push` many times. The normal test harness does not have this problem because it calls `test_main_static` or `test_main_static_abort`, which take `&[TestDescAndFn]`. Changing `test::test_main` to take a slice is not a simple change, so I'm avoiding doing it here.
Over in #138162 I am trying to update the standard library to Rust 2024. I'm running into a problem where core's doctests are failing on x86_64-pc-windows-msvc.
The behavior is:
thread 'main' has overflowed its stack
running 1672 tests
test result: ok. 1671 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 109.68s
From what I can tell, there is a
const TESTS: [test::TestDescAndFn; 3641]
array in the combined test code. When callingtest::test_main
, it fails somewhere in there. I'm struggling a bit figuring out a good way to debug exactly where the stack is overflowing.There are a few issues here:
I haven't put together an isolated repro. I wonder if just creating something with 4,000 doctests would suffice? So far, I've been using
--persist-doctests
to get a copy of core's combined suite, and then runningrustc
directly on that.cc @notriddle @GuillaumeGomez
The text was updated successfully, but these errors were encountered: