cargo-callgraph
cargo-callgraph copied to clipboard
To do list
Goal
Given the following rust code:
fn main() {
let fct = get_fct();
let fct = forward_fct(fct);
fct();
}
fn foo() {
bar()
}
fn bar() {
}
fn get_fct() -> impl Fn() {
foo
}
fn forward_fct<Fct: Fn()>(fct: Fct) -> Fct {
fct
}
Currently, this is what is being generated
- [x] extracting all function information (ie, their name, arguments, types of arguments and return type) for the function that exists in the current crate
- [ ] extract information about function not leaving in the current-crate
- [x] extract internal dependencies (dependencies between the arguments, return type, and the function call)
- [x] writing the graphviz generator (i.e. converting the internal representation to text)
- [ ] use
impl Trait
instead of the concrete types- [x] in arguments
- [ ] in return types
- [ ] in the dependent types of the struct being implemented
- [x] call it with cargo (as a drop-in replacement of
rustdoc
) to run it on a whole project
- [ ] track indirect dependencies thought
Fn
/FnMut
/FnOnce
traits - [ ] group functions by modules
- [ ] add link to documentation (ie, create clickable links to the output of
rustdoc
)
- [ ] How do I create a
Bar
from aFoo
? → highlight the callgraph - [ ] create a command line tool to answer "what are the caller of
foo()
, including through function pointers and traits" - [ ] add a big "you are here" in the svg
- [ ] select which functions/crates should be extracted
General algorithm
This is what I am planning to do. This may change in the future if my understanding of the problem space changes.
First, for each functions (and function-like object like closure), locate all function call. Then for each arguments of the called function track if they come from the argument or the function being analyzed, a constant, or from the return value of another function called in the analyzed function. Multiple source are possible, and the control flow is ignored. Once done for all functions, we can walk back to the source of all arguments, and all indirect calls.