Skip to content
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

Recursive reexported module should stop when the inner module duplicates as ancestor module #3

Closed
zjp-CN opened this issue Feb 24, 2024 · 1 comment

Comments

@zjp-CN
Copy link
Owner

zjp-CN commented Feb 24, 2024

This is a follow-up to #2 .

Background

actix contains infinite recursive modules:

actix
├── [Mod] dev
│   └── [Mod] prelude (src code: pub use crate::dev)
│       └── [Mod] dev (this module duplicates as an ancestor module, leading to stack overflows)
└── [Mod] prelude
    └── [Mod] dev (src code: pub use crate::prelude::*)
        └── [Mod] prelude (this module duplicates as an ancestor module, leading to stack overflows)

The HTML rendering version show them as the source code does:

But the rendering is imperfect as tree view because a complete tree always is cached as known lines.

Even though the syntax of use actix::prelude::dev::prelude is acceptable in Rust and for human, it's definitely not encouraged to use. (Well, it might serve as an odd macro trick.)

So to solve the problem of stack overflows, there are several ways:

  • Stop as long as a reexported module occurs: this is not acceptable, because there would be nothing useful to show. futures crate is an example for this: it's a highly reexporting crate. Doing so means only two empty modules are shown
  • Stop at a limited recursive level: this is how JSON rustdoc works I guess, because the doc provides IDs and the ability for the program to find next item in the recursion, but the recursion doesn't occur in deserialization from JSON.
  • Stop when the module has already been the ancestor in path. This will be the solution in term-rustdoc, thus it still displays the reexported items in modules, but except for the duplicate. We can make users conscious of the duplicate by including the actix::prelude::dev::prelude line with extra information that say the path exists and is usable. But the reason to not have it prevails: not encouraged to use for coding, much less important to know for users and simpler code for term-rustdoc.
@zjp-CN
Copy link
Owner Author

zjp-CN commented Feb 24, 2024

├── [Mod] actix::prelude
│   ... (non-module items omitted under prelude module)
│   ├─➤ [Mod] actors
│   ├── [Mod] dev
│   ... (non-module items omitted under dev module)
│   │   ├─➤ [Mod] actix::dev::channel
│   │   └── [Mod] prelude
│   │       ├─➤ [Mod] actors
│   │       ├─➤ [Mod] fut
│   │       ╰─➤ [Mod] io
│   ├─➤ [Mod] fut
│   ╰─➤ [Mod] io

vs HTML version

//Module actix::prelude
pub use crate::actors;	
pub use crate::dev;	
pub use crate::fut;	
pub use crate::io;

//Module actix::dev
pub use crate::prelude::*;	
pub mod channel { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant