Stream: t-compiler/rust-analyzer

Topic: Extract callgraph of a crate


Robin Moussu (Nov 08 2020 at 15:57, on Zulip):

Hello, hello!
In order to have a good understanding of an unknown codebase, I would like to be able to interactively visualize the whole call graph. I searched before, and didn't found one. But since I have some free time, I could build it myself! The pipeline is relatively simple:

@Joshua Nelson told me that I could write a Visitor that only looks at functions. He also told me that I can take a look at ReplaceBodyWithLoop as an example. More specifically, apparently what I need is tcx.hir().krate().body_ids to be able to look at each function body one at at time.

My question is: how do I write my main()? More specifically, how do I build that tcx?

Joshua Nelson (Nov 08 2020 at 16:01, on Zulip):

@Robin Moussu sorry, those were instructions for rustc, not rust-analyzer

Joshua Nelson (Nov 08 2020 at 16:01, on Zulip):

I don't know how rust-analyzer works

Robin Moussu (Nov 08 2020 at 16:03, on Zulip):

You are right, I messed-up the acronyms in my head. Where should I move it?

Joshua Nelson (Nov 08 2020 at 16:04, on Zulip):

well it depends if you want to use r-a or not :sweat_smile:

Robin Moussu (Nov 08 2020 at 16:05, on Zulip):

Given that you started to give me some good pointer, I will go with rustc!

Joshua Nelson (Nov 08 2020 at 16:05, on Zulip):

see https://github.com/rust-lang/rust-clippy/blob/master/src/driver.rs#L418-L422 for examples of how to use rustc_driver then

Joshua Nelson (Nov 08 2020 at 16:05, on Zulip):

rustdoc overcomplicates this, don't look there

Joshua Nelson (Nov 08 2020 at 16:06, on Zulip):

Robin Moussu said:

You are right, I messed-up the acronyms in my head. Where should I move it?

#t-compiler/help is a good place

Robin Moussu (Nov 08 2020 at 16:09, on Zulip):

Moved: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate

Jeremy Kolb (Nov 09 2020 at 15:31, on Zulip):

call_hierarchy does some of this

Last update: Jul 24 2021 at 19:30UTC