zjp-CN / term-rustdoc

[WIP] A TUI for Rust docs that aims to improve the UX on tree view and generic code.
17 stars 1 forks source link

stack overflow when compiling the JSON doc for actix v0.13.0 #2

Closed zjp-CN closed 8 months ago

zjp-CN commented 8 months ago

actix

The stack overflow error happens on Ubuntu and Windows.

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow
fish: Job 1, 'cargo r' terminated by signal SIGABRT (Abort)
thread '<unknown>' has overflowed its stack
error: process didn't exit successfully: `target\debug\term-rustdoc.exe` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)

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

#[test]
fn compile_actix_0_13_0() {
    let doc = rustdoc_json::Builder::default()
        .toolchain("nightly")
        .target_dir("./target")
        .manifest_path(
            "/root/.cargo/registry/src/.../actix-0.13.0/Cargo.toml",
        )
        .build()
        .unwrap();
    dbg!(&doc);
}

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.

term-rustdoc $ ll target/doc/
total 6.0M
-rw-r--r-- 1 root root 1.8M Feb 23 23:17 actix.json
-rw-r--r-- 1 root root 4.2M Feb 23 23:23 bitvec.json
zjp-CN commented 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)
zjp-CN commented 8 months ago

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.