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

Consolidate multiple implementations of function call graphs across codebase #7228

Open
TomAFrench opened this issue Jan 29, 2025 · 0 comments

Comments

@TomAFrench
Copy link
Member

We've gradually accumulated multiple implementations of a graph to track which functions are calling other functions during SSA.

Examples are:

fn compute_callers(ssa: &Ssa) -> BTreeMap<FunctionId, BTreeMap<FunctionId, usize>> {
ssa.functions
.iter()
.flat_map(|(caller_id, function)| {
let called_functions = called_functions_vec(function);
called_functions.into_iter().map(|callee_id| (*caller_id, callee_id))
})
.fold(
// Make sure an entry exists even for ones that don't get called.
ssa.functions.keys().map(|id| (*id, BTreeMap::new())).collect(),
|mut acc, (caller_id, callee_id)| {
let callers = acc.entry(callee_id).or_default();
*callers.entry(caller_id).or_default() += 1;
acc
},
)
}
/// Compute for each function the set of functions called by it, and how many times it does so.
fn compute_callees(ssa: &Ssa) -> BTreeMap<FunctionId, BTreeMap<FunctionId, usize>> {
ssa.functions
.iter()
.flat_map(|(caller_id, function)| {
let called_functions = called_functions_vec(function);
called_functions.into_iter().map(|callee_id| (*caller_id, callee_id))
})
.fold(
// Make sure an entry exists even for ones that don't call anything.
ssa.functions.keys().map(|id| (*id, BTreeMap::new())).collect(),
|mut acc, (caller_id, callee_id)| {
let callees = acc.entry(caller_id).or_default();
*callees.entry(callee_id).or_default() += 1;
acc
},
)
}

The purity callgraph added in #7197.

The callgraph to mark reachable globals in https://github.com/noir-lang/noir/blob/master/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs added in #7188

We should see if we can standardize these to avoid code duplication and potential inconsistencies.

@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant