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: pass macro processors by reference #4501

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 2 additions & 5 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,8 @@ pub fn check_crate(
deny_warnings: bool,
disable_macros: bool,
) -> CompilationResult<()> {
let macros: Vec<&dyn MacroProcessor> = if disable_macros {
vec![]
} else {
vec![&aztec_macros::AztecMacro as &dyn MacroProcessor]
};
let macros: &[&dyn MacroProcessor] =
if disable_macros { &[] } else { &[&aztec_macros::AztecMacro as &dyn MacroProcessor] };

let mut errors = vec![];
let diagnostics = CrateDefMap::collect_defs(crate_id, context, macros);
Expand Down
10 changes: 3 additions & 7 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
context: &mut Context,
ast: SortedModule,
root_file_id: FileId,
macro_processors: Vec<&dyn MacroProcessor>,
macro_processors: &[&dyn MacroProcessor],
) -> Vec<(CompilationError, FileId)> {
let mut errors: Vec<(CompilationError, FileId)> = vec![];
let crate_id = def_map.krate;
Expand All @@ -220,11 +220,7 @@
let crate_graph = &context.crate_graph[crate_id];

for dep in crate_graph.dependencies.clone() {
errors.extend(CrateDefMap::collect_defs(
dep.crate_id,
context,
macro_processors.clone(),
));
errors.extend(CrateDefMap::collect_defs(dep.crate_id, context, macro_processors));

let dep_def_root =
context.def_map(&dep.crate_id).expect("ice: def map was just created").root;
Expand Down Expand Up @@ -257,7 +253,7 @@
context.def_maps.insert(crate_id, def_collector.def_map);

// TODO(#4653): generalize this function
for macro_processor in &macro_processors {
for macro_processor in macro_processors {
macro_processor
.process_unresolved_traits_impls(
&crate_id,
Expand Down Expand Up @@ -480,7 +476,7 @@
.collect()
}

// TODO(vitkov): Move this out of here and into type_check

Check warning on line 479 in compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (vitkov)
#[allow(clippy::too_many_arguments)]
pub(crate) fn check_methods_signatures(
resolver: &mut Resolver,
Expand Down
12 changes: 3 additions & 9 deletions compiler/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl CrateDefMap {
pub fn collect_defs(
crate_id: CrateId,
context: &mut Context,
macro_processors: Vec<&dyn MacroProcessor>,
macro_processors: &[&dyn MacroProcessor],
) -> Vec<(CompilationError, FileId)> {
// Check if this Crate has already been compiled
// XXX: There is probably a better alternative for this.
Expand All @@ -90,7 +90,7 @@ impl CrateDefMap {
let (ast, parsing_errors) = context.parsed_file_results(root_file_id);
let mut ast = ast.into_sorted();

for macro_processor in &macro_processors {
for macro_processor in macro_processors {
match macro_processor.process_untyped_ast(ast.clone(), &crate_id, context) {
Ok(processed_ast) => {
ast = processed_ast;
Expand All @@ -115,13 +115,7 @@ impl CrateDefMap {
};

// Now we want to populate the CrateDefMap using the DefCollector
errors.extend(DefCollector::collect(
def_map,
context,
ast,
root_file_id,
macro_processors.clone(),
));
errors.extend(DefCollector::collect(def_map, context, ast, root_file_id, macro_processors));

errors.extend(
parsing_errors.iter().map(|e| (e.clone().into(), root_file_id)).collect::<Vec<_>>(),
Expand Down
Loading