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: Rename 'global' to 'function' in the monomorphization pass #4774

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ struct LambdaContext {
/// This struct holds the FIFO queue of functions to monomorphize, which is added to
/// whenever a new (function, type) combination is encountered.
struct Monomorphizer<'interner> {
/// Globals are keyed by their unique ID and expected type so that we can monomorphize
/// a new version of the global for each type. Note that 'global' here means 'globally
/// visible' and thus includes both functions and global variables.
/// Functions are keyed by their unique ID and expected type so that we can monomorphize
/// a new version of the function for each type.
///
/// Using nested HashMaps here lets us avoid cloning HirTypes when calling .get()
globals: HashMap<node_interner::FuncId, HashMap<HirType, FuncId>>,
functions: HashMap<node_interner::FuncId, HashMap<HirType, FuncId>>,

/// Unlike globals, locals are only keyed by their unique ID because they are never
/// Unlike functions, locals are only keyed by their unique ID because they are never
/// duplicated during monomorphization. Doing so would allow them to be used polymorphically
/// but would also cause them to be re-evaluated which is a performance trap that would
/// confuse users.
Expand Down Expand Up @@ -165,7 +164,7 @@ pub fn monomorphize_debug(
impl<'interner> Monomorphizer<'interner> {
fn new(interner: &'interner mut NodeInterner, debug_type_tracker: DebugTypeTracker) -> Self {
Monomorphizer {
globals: HashMap::new(),
functions: HashMap::new(),
locals: HashMap::new(),
queue: VecDeque::new(),
finished_functions: BTreeMap::new(),
Expand Down Expand Up @@ -203,7 +202,7 @@ impl<'interner> Monomorphizer<'interner> {
trait_method: Option<TraitMethodId>,
) -> Definition {
let typ = typ.follow_bindings();
match self.globals.get(&id).and_then(|inner_map| inner_map.get(&typ)) {
match self.functions.get(&id).and_then(|inner_map| inner_map.get(&typ)) {
Some(id) => Definition::Function(*id),
None => {
// Function has not been monomorphized yet
Expand Down Expand Up @@ -251,8 +250,8 @@ impl<'interner> Monomorphizer<'interner> {
}

/// Prerequisite: typ = typ.follow_bindings()
fn define_global(&mut self, id: node_interner::FuncId, typ: HirType, new_id: FuncId) {
self.globals.entry(id).or_default().insert(typ, new_id);
fn define_function(&mut self, id: node_interner::FuncId, typ: HirType, new_id: FuncId) {
self.functions.entry(id).or_default().insert(typ, new_id);
}

fn compile_main(
Expand Down Expand Up @@ -786,7 +785,7 @@ impl<'interner> Monomorphizer<'interner> {
})
}

/// A local (ie non-global) ident only
/// A local (ie non-function) ident only
fn local_ident(
&mut self,
ident: &HirIdent,
Expand Down Expand Up @@ -1280,7 +1279,7 @@ impl<'interner> Monomorphizer<'interner> {
trait_method: Option<TraitMethodId>,
) -> FuncId {
let new_id = self.next_function_id();
self.define_global(id, function_type.clone(), new_id);
self.define_function(id, function_type.clone(), new_id);

let bindings = self.interner.get_instantiation_bindings(expr_id);
let bindings = self.follow_bindings(bindings);
Expand Down
Loading