Giter Site home page Giter Site logo

Comments (2)

regexident avatar regexident commented on May 27, 2024

I'll have to do a more thorough investigation for this, but my guess is that this difference is due to the fact that we make use of rust-analyzer's HIR, rather than it's AST. The HIR might be providing an already resolved dependency graph?

Previously we did depend on an AST (the one from rustc), but that resulted in lots of issues related to path solution,
which eventually lead me to switch to rust-analyzer and it's HIR, which ended up closing about a dozen issues at once.

However I have the feeling that in future we might want to analyze both, the AST, as well as the HIR, since the latter doesn't seem to have any information on inter-type dependencies, either.

from cargo-modules.

regexident avatar regexident commented on May 27, 2024

I'm closing this

$ cargo modules generate graph --with-uses generates the following graph:

                          ┌───────┐           
                          │ crate │           
                          └───────┘           
                              │               
                              │               
                              ▼               
                        ┌──────────┐          
                       ─│ crate::a │─ ─ ─ ─ ─ 
                      │ └──────────┘         │
                              │               
            ┌─────────┼───────┴────┐         │
            ▼                      ▼          
     ┌─────────────┐  │     ┌─────────────┐  │
┌ ─ ─│ crate::a::b │        │ crate::a::d │◀─ 
     └─────────────┘  │     └─────────────┘   
│           │                      │          
            │         │            │          
│           ▼                      ▼          
   ┌────────────────┐ │   ┌────────────────┐  
└ ▶│ crate::a::b::c │◀    │ crate::a::d::e │  
   └────────────────┘     └────────────────┘  

Where solid lines denote "owns" edges and dashed lines denote "uses" edges.

Corresponding dot code

$ cargo modules generate graph --with-uses:

digraph {

    graph [
        label="github_issue_79",
        labelloc=t,
        pad=0.4,
        layout=neato,
        overlap=false,
        splines="line",
        rankdir=LR,
        fontname="Helvetica", 
        fontsize="36",
    ];

    node [
        fontname="monospace",
        fontsize="10",
        shape="record",
        style="filled",
    ];

    edge [
        fontname="monospace",
        fontsize="10",
    ];

    "github_issue_79" [label="crate|github_issue_79", fillcolor="#5397c8"]; // "crate" node
    "github_issue_79::a" [label="pub mod|a", fillcolor="#81c169"]; // "mod" node
    "github_issue_79::a::b" [label="pub mod|a::b", fillcolor="#81c169"]; // "mod" node
    "github_issue_79::a::b::c" [label="pub(self) mod|a::b::c", fillcolor="#db5367"]; // "mod" node
    "github_issue_79::a::d" [label="pub mod|a::d", fillcolor="#81c169"]; // "mod" node
    "github_issue_79::a::d::e" [label="pub(self) mod|a::d::e", fillcolor="#db5367"]; // "mod" node

    "github_issue_79" -> "github_issue_79::a" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge
    "github_issue_79::a" -> "github_issue_79::a::b" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge
    "github_issue_79::a::b" -> "github_issue_79::a::b::c" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge
    "github_issue_79::a::b" -> "github_issue_79::a::b::c" [label="uses", color="#7f7f7f", style="dashed"] [constraint=false]; // "uses" edge
    "github_issue_79::a" -> "github_issue_79::a::d" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge
    "github_issue_79::a::d" -> "github_issue_79::a::d::e" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge
    "github_issue_79::a" -> "github_issue_79::a::b::c" [label="uses", color="#7f7f7f", style="dashed"] [constraint=false]; // "uses" edge
    "github_issue_79::a" -> "github_issue_79::a::d" [label="uses", color="#7f7f7f", style="dashed"] [constraint=false]; // "uses" edge

}

Since rust-analyzer resolves re-exports the edges in the generated graph do not directly correlate to use statements in the code.

As such:

  • the use self::b::X; in mod a ends up producing an edge a -> c, since a::b::X is a re-export of a::b::c::X.
  • the use self::d::Y; in mod a ends up producing an edge a -> d, since a::d::Y is a type-alias for a::b::c::X and not merely a re-export of it.
  • the use self::c; and use self::e; in mod b and mod d on the other hand have no effect whatsoever, since they are superfluous.
  • the pub use c::X; in mod b on the other hand does import X from mod c and is thus reflected in the graph as such.

from cargo-modules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.