Skip to content

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Mar 9, 2025

Fixes #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.

@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2025

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 9, 2025
@rust-log-analyzer

This comment has been minimized.

@saethlin saethlin force-pushed the mergeable-doctests-stacksize branch from 90fecc7 to 76ab62e Compare March 9, 2025 21:45
@saethlin saethlin marked this pull request as draft March 9, 2025 21:46
@saethlin saethlin force-pushed the mergeable-doctests-stacksize branch from 76ab62e to 1ccb982 Compare March 9, 2025 21:54
@saethlin saethlin marked this pull request as ready for review March 9, 2025 22:23
@saethlin
Copy link
Member Author

saethlin commented Mar 9, 2025

Took me a while to figure out what was going on; I broke the test runner and somehow that made rustdoc fall back to not merging doctests. Should be good now, and I had to redesign the approach a bit to get it to compile 🤦

@@ -136,19 +133,23 @@ mod __doctest_mod {{

#[rustc_main]
fn main() -> std::process::ExitCode {{
const TESTS: [test::TestDescAndFn; {nb_tests}] = [{ids}];
let tests = {{
let mut tests = Vec::new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you at least use with_capacity since we already have nb_tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah!

@saethlin saethlin force-pushed the mergeable-doctests-stacksize branch from 1ccb982 to 295c70e Compare March 10, 2025 04:04
@GuillaumeGomez
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 10, 2025

📌 Commit 295c70e has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 10, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#137931 (Add remark for missing `llvm-tools` component re. `rustc_private` linker failures related to not finding LLVM libraries)
 - rust-lang#138138 (Pass `InferCtxt` to `InlineAsmCtxt` to properly taint on error)
 - rust-lang#138223 (Fix post-merge workflow)
 - rust-lang#138268 (Handle empty test suites in GitHub job summary report)
 - rust-lang#138278 (Delegation: fix ICE with invalid `MethodCall` generation)
 - rust-lang#138281 (Fix O(tests) stack usage in edition 2024 mergeable doctests)
 - rust-lang#138305 (Subtree update of `rust-analyzer`)
 - rust-lang#138306 (Revert "Use workspace lints for crates in `compiler/` rust-lang#138084")

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d1a875c into rust-lang:master Mar 10, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 10, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2025
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.
@saethlin saethlin deleted the mergeable-doctests-stacksize branch May 4, 2025 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stack overflow on large doctests in edition 2024 on Windows
5 participants