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

Analyze and forbid dependency from one mod to another? #219

Open
fzyzcjy opened this issue Nov 15, 2023 · 6 comments
Open

Analyze and forbid dependency from one mod to another? #219

fzyzcjy opened this issue Nov 15, 2023 · 6 comments

Comments

@fzyzcjy
Copy link

fzyzcjy commented Nov 15, 2023

Hi thanks for the tool! Given the acyclic option, I guess this crate does analyze all dependencies between mods. However, it seems that currently it only outputs a dot graph that shows the ownership between modules, instead of dependency relationship.

In my case, say I have mod A, B, C. I want to check automatically that, the mod A is never used by mod B (but can be used by mod C), such that it satisfies things like layered architecture.

@regexident
Copy link
Owner

For "dependency" (/"uses") relationships though need to add the --uses flag to your cargo modules generate graph … command (which has --no-uses as implicit default).

That said there currently is no way (yet) for the tool to detect dependencies from function bodies though, which is an admittedly big blind spot of the --uses flag.

@fzyzcjy
Copy link
Author

fzyzcjy commented Nov 21, 2023

Thank you for the information!

That said there currently is no way (yet) for the tool to detect dependencies from function bodies though, which is an admittedly big blind spot of the --uses flag.

So I wonder will this be implemented in the future?

@regexident
Copy link
Owner

I very much hope so!

The tool uses rust-analyzer (RA) as a library dependency and I simply haven't yet been able to fully figure out how walk the types used inside a function body.

The internal API of RA is mostly rather sparsely documented, and often very indirect in nature due to its extensive use of interning, which makes navigating it somewhat difficult as an outsider. As such implementing a new feature in cargo-modules frequently turns into first having to search the RA codebase for potentially useful types and methods and then trying to figure out how to actually use them by reading through any usages within RA itself. The function body stuff has been particularly opaque so far, as it doesn't seem to work like the rest of RA. I recently found a possible approach but unfortunately ultimately couldn't manage to make it work. I'm not giving up just yet though.

Occasionally I've asked the RA devs for help on their Zulip but it feels kinda bad to ask them for customer support for their private API that isn't really intended for public use, afaict.

@fzyzcjy
Copy link
Author

fzyzcjy commented Nov 24, 2023

I see, thank you!

@regexident
Copy link
Owner

You may want to watch this one #227 😉

@fzyzcjy
Copy link
Author

fzyzcjy commented Nov 28, 2023

Wow that looks great, thank you! 😄

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

2 participants