Closed zjp-CN closed 8 months ago
Well, after adding more logging spots, I found the problem lies term_rustdoc::tree::CrateDoc::new
which is written by myself...
use term_rustdoc::tree::CrateDoc;
#[test]
fn compile_actix_0_13_0() {
let json_path = rustdoc_json::Builder::default()
.toolchain("nightly")
.target_dir("./target")
.manifest_path(
"/root/.cargo/registry/src/.../actix-0.13.0/Cargo.toml",
)
.build()
.unwrap();
dbg!(&json_path);
let file = std::fs::File::open(&json_path).unwrap();
let json: rustdoc_types::Crate = serde_json::from_reader(file).unwrap();
println!("parse done");
let crate_doc = CrateDoc::new(json);
dbg!(&crate_doc);
}
// output:
[tests/compile_doc.rs:13:5] &json_path = "./target/doc/actix.json"
parse done
thread 'compile_actix_0_13_0' has overflowed its stack
fatal runtime error: stack overflow
error: test failed, to rerun pass `-p term-rustdoc --test compile_doc`
Caused by:
process didn't exit successfully: `.../target/debug/deps/compile_doc-bf8897ace5a7f80e compile_actix_0_13_0 --exact --nocapture` (signal: 6, SIGABRT: process abort signal)
actix reexports dev module and prelude module under each other module, causing recursive modules and the stack overflows.
With the fix, reexported modules should be taken carefully. For now, let's stop when hitting them. Logging becomes
2024-02-24T06:56:11.973652Z WARN term_rustdoc::tree::nodes::imports: Stop at the reexported actors module. Need to check how to deal with it.
2024-02-24T06:56:11.973797Z WARN term_rustdoc::tree::nodes::imports: Stop at the reexported dev module. Need to check how to deal with it.
2024-02-24T06:56:11.973839Z WARN term_rustdoc::tree::nodes::imports: Stop at the reexported fut module. Need to check how to deal with it.
2024-02-24T06:56:11.973899Z WARN term_rustdoc::tree::nodes::imports: Stop at the reexported io module. Need to check how to deal with it.
2024-02-24T06:56:11.974174Z WARN term_rustdoc::tree::nodes::imports: Stop at the reexported prelude module. Need to check how to deal with it.
In later commits, handle them properly.
The stack overflow error happens on Ubuntu and Windows.
But if I write a test that uses rustdoc_json to compile the doc exactly as the program does, it won't cause stack overflow...
For cached docs in the picture, they do not cause stack overflow either. Especially for the large doc among them, bitvec, the doc compilation succeeds.