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

fix(experimental elaborator): Avoid defining globals twice #5103

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 2 additions & 22 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,6 @@
self.scopes.start_function();
self.current_item = Some(DependencyId::Function(id));

// Check whether the function has globals in the local module and add them to the scope
self.resolve_local_globals();
self.trait_bounds = function.def.where_clause.clone();

let is_low_level_or_oracle = function
Expand Down Expand Up @@ -360,7 +358,7 @@
// when multiple impls are available. Instead we default first to choose the Field or u64 impl.
for typ in &self.type_variables {
if let Type::TypeVariable(variable, kind) = typ.follow_bindings() {
let msg = "TypeChecker should only track defaultable type vars";

Check warning on line 361 in compiler/noirc_frontend/src/elaborator/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (defaultable)
variable.bind(kind.default_type().expect(msg));
}
}
Expand Down Expand Up @@ -497,18 +495,6 @@
None
}

fn resolve_local_globals(&mut self) {
let globals = vecmap(self.interner.get_all_globals(), |global| {
(global.id, global.local_id, global.ident.clone())
});
for (id, local_module_id, name) in globals {
if local_module_id == self.local_module {
let definition = DefinitionKind::Global(id);
self.add_global_variable_decl(name, definition);
}
}
}

/// TODO: This is currently only respected for generic free functions
/// there's a bunch of other places where trait constraints can pop up
fn resolve_trait_constraints(
Expand Down Expand Up @@ -571,9 +557,6 @@
self.scopes.start_function();
self.current_item = Some(DependencyId::Function(func_id));

// Check whether the function has globals in the local module and add them to the scope
self.resolve_local_globals();

let location = Location::new(func.name_ident().span(), self.file);
let id = self.interner.function_definition_id(func_id);
let name_ident = HirIdent::non_trait_method(id, location);
Expand Down Expand Up @@ -1189,7 +1172,6 @@
self.local_module = alias.module_id;

let generics = self.add_generics(&alias.type_alias_def.generics);
self.resolve_local_globals();
self.current_item = Some(DependencyId::Alias(alias_id));
let typ = self.resolve_type(alias.type_alias_def.typ);
self.interner.set_type_alias(alias_id, typ, generics);
Expand Down Expand Up @@ -1241,9 +1223,6 @@
self.recover_generics(|this| {
let generics = this.add_generics(&unresolved.generics);

// Check whether the struct definition has globals in the local module and add them to the scope
this.resolve_local_globals();

this.current_item = Some(DependencyId::Struct(struct_id));

this.resolving_ids.insert(struct_id);
Expand Down Expand Up @@ -1276,10 +1255,11 @@
self.push_err(ResolverError::MutableGlobal { span });
}

let name = let_stmt.pattern.name_ident().clone();
let (let_statement, _typ) = self.elaborate_let(let_stmt);

let statement_id = self.interner.get_global(global_id).let_statement;
self.interner.get_global_definition_mut(global_id).kind = definition_kind;
self.interner.get_global_definition_mut(global_id).kind = definition_kind.clone();
self.interner.replace_statement(statement_id, let_statement);
}

Expand Down
3 changes: 0 additions & 3 deletions compiler/noirc_frontend/src/elaborator/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ impl<'context> Elaborator<'context> {
let old_generic_count = self.generics.len();
self.scopes.start_function();

// Check whether the function has globals in the local module and add them to the scope
self.resolve_local_globals();

self.trait_bounds = where_clause.to_vec();

let kind = FunctionKind::Normal;
Expand Down
Loading