Skip to content

Commit d71d5de

Browse files
authored
chore: Rename 'global' to 'function' in the monomorphization pass (#4774)
# Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* The original intention of this was to store functions and globals but after globals were implemented, only functions ended up being used in the `globals` hashmap. We also probably don't want to monomorphize globals into different copies going forward so I renamed the map to `functions` and clarified references to it to avoid confusion. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
1 parent 6bdc324 commit d71d5de

File tree

1 file changed

+10
-11
lines changed
  • compiler/noirc_frontend/src/monomorphization

1 file changed

+10
-11
lines changed

compiler/noirc_frontend/src/monomorphization/mod.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ struct LambdaContext {
5252
/// This struct holds the FIFO queue of functions to monomorphize, which is added to
5353
/// whenever a new (function, type) combination is encountered.
5454
struct Monomorphizer<'interner> {
55-
/// Globals are keyed by their unique ID and expected type so that we can monomorphize
56-
/// a new version of the global for each type. Note that 'global' here means 'globally
57-
/// visible' and thus includes both functions and global variables.
55+
/// Functions are keyed by their unique ID and expected type so that we can monomorphize
56+
/// a new version of the function for each type.
5857
///
5958
/// Using nested HashMaps here lets us avoid cloning HirTypes when calling .get()
60-
globals: HashMap<node_interner::FuncId, HashMap<HirType, FuncId>>,
59+
functions: HashMap<node_interner::FuncId, HashMap<HirType, FuncId>>,
6160

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

253252
/// Prerequisite: typ = typ.follow_bindings()
254-
fn define_global(&mut self, id: node_interner::FuncId, typ: HirType, new_id: FuncId) {
255-
self.globals.entry(id).or_default().insert(typ, new_id);
253+
fn define_function(&mut self, id: node_interner::FuncId, typ: HirType, new_id: FuncId) {
254+
self.functions.entry(id).or_default().insert(typ, new_id);
256255
}
257256

258257
fn compile_main(
@@ -786,7 +785,7 @@ impl<'interner> Monomorphizer<'interner> {
786785
})
787786
}
788787

789-
/// A local (ie non-global) ident only
788+
/// A local (ie non-function) ident only
790789
fn local_ident(
791790
&mut self,
792791
ident: &HirIdent,
@@ -1280,7 +1279,7 @@ impl<'interner> Monomorphizer<'interner> {
12801279
trait_method: Option<TraitMethodId>,
12811280
) -> FuncId {
12821281
let new_id = self.next_function_id();
1283-
self.define_global(id, function_type.clone(), new_id);
1282+
self.define_function(id, function_type.clone(), new_id);
12841283

12851284
let bindings = self.interner.get_instantiation_bindings(expr_id);
12861285
let bindings = self.follow_bindings(bindings);

0 commit comments

Comments
 (0)