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

chore(refactor): Remove globals field on Ssa object and use only the shared globals graph #7156

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

vezenovm
Copy link
Contributor

Description

Problem*

No issue, but just a general refactor. We have repeated declaration of globals (the shared globals: Arc<GlobalsGraph> field on DataFlowGraph and the globals: Function on Ssa). We need the globals field on the DFG for resolving constants #7040. However, the globals field on the Ssa object is only used by the SSA printer and the brillig codegen. Which in both case could use the globals graph from any function.

Summary*

I removed globals: Function from Ssa and use the globals graph from a function in the places where the Ssa field was being used.

Certain interfaces such as the printer and Brillig codegen still utilize the DataFlowGraph type so some conversions from a GlobalsGraph to a DataFlowGraph were necessary to avoid larger changes.

Additional Context

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@vezenovm vezenovm marked this pull request as draft January 22, 2025 20:36
@vezenovm vezenovm marked this pull request as ready for review January 22, 2025 21:43
@vezenovm vezenovm requested a review from a team January 22, 2025 21:43
return brillig;
}

let func_id = brillig_reachable_function_ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this func_id? Is it this Function?

Copy link
Contributor Author

@vezenovm vezenovm Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is just the first function from brillig_reachable_function_ids. The globals graph is computed a single time and shared among all functions (see #7040), so we can use any func id here. I switched to using self.main_id to be more explicit.

@@ -25,7 +26,8 @@ impl Ssa {
let mut context = Context::default();
context.populate_functions(&self.functions);
for function in self.functions.values_mut() {
context.normalize_ids(function, &self.globals);
let globals = (*function.dfg.globals).clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this clone before passing a reference avoidable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not as GlobalsGraph cannot be moved out of Arc as it does not implement Copy. I have moved it out of the loop though.

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

Successfully merging this pull request may close these issues.

2 participants