Skip to content
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
18 changes: 11 additions & 7 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,9 @@ pub fn check_crate(
crate_id: CrateId,
options: &CompileOptions,
) -> CompilationResult<()> {
let error_on_unused_imports = true;
let diagnostics = CrateDefMap::collect_defs(
crate_id,
context,
options.debug_comptime_in_file.as_deref(),
error_on_unused_imports,
);
let diagnostics =
CrateDefMap::collect_defs(crate_id, context, options.debug_comptime_in_file.as_deref());
let crate_files = context.crate_files(&crate_id);
let warnings_and_errors: Vec<FileDiagnostic> = diagnostics
.into_iter()
.map(|(error, file_id)| {
Expand All @@ -328,6 +324,14 @@ pub fn check_crate(
// We filter out any warnings if they're going to be ignored later on to free up memory.
!options.silence_warnings || diagnostic.diagnostic.kind != DiagnosticKind::Warning
})
.filter(|error| {
// Only keep warnings from the crate we are checking
if error.diagnostic.is_warning() {
crate_files.contains(&error.file_id)
} else {
true
}
})
.collect();

if has_errors(&warnings_and_errors, options.deny_warnings) {
Expand Down
13 changes: 2 additions & 11 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ impl DefCollector {
ast: SortedModule,
root_file_id: FileId,
debug_comptime_in_file: Option<&str>,
error_on_unused_items: bool,
) -> Vec<(CompilationError, FileId)> {
let mut errors: Vec<(CompilationError, FileId)> = vec![];
let crate_id = def_map.krate;
Expand All @@ -288,13 +287,7 @@ impl DefCollector {
let crate_graph = &context.crate_graph[crate_id];

for dep in crate_graph.dependencies.clone() {
let error_on_usage_tracker = false;
errors.extend(CrateDefMap::collect_defs(
dep.crate_id,
context,
debug_comptime_in_file,
error_on_usage_tracker,
));
errors.extend(CrateDefMap::collect_defs(dep.crate_id, context, debug_comptime_in_file));

let dep_def_map =
context.def_map(&dep.crate_id).expect("ice: def map was just created");
Expand Down Expand Up @@ -464,9 +457,7 @@ impl DefCollector {

errors.append(&mut more_errors);

if error_on_unused_items {
Self::check_unused_items(context, crate_id, &mut errors);
}
Self::check_unused_items(context, crate_id, &mut errors);

errors
}
Expand Down
8 changes: 5 additions & 3 deletions compiler/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::token::{FunctionAttribute, SecondaryAttribute, TestScope};
use fm::{FileId, FileManager};
use noirc_arena::{Arena, Index};
use noirc_errors::Location;
use std::collections::{BTreeMap, HashMap};
use std::collections::{BTreeMap, HashMap, HashSet};
mod module_def;
pub use module_def::*;
mod item_scope;
Expand Down Expand Up @@ -78,7 +78,6 @@ impl CrateDefMap {
crate_id: CrateId,
context: &mut Context,
debug_comptime_in_file: Option<&str>,
error_on_unused_imports: bool,
) -> Vec<(CompilationError, FileId)> {
// Check if this Crate has already been compiled
// XXX: There is probably a better alternative for this.
Expand Down Expand Up @@ -121,7 +120,6 @@ impl CrateDefMap {
ast,
root_file_id,
debug_comptime_in_file,
error_on_unused_imports,
));

errors.extend(
Expand Down Expand Up @@ -159,6 +157,10 @@ impl CrateDefMap {
self.modules[module_id.0].location.file
}

pub fn file_ids(&self) -> HashSet<FileId> {
self.modules.iter().map(|(_, module_data)| module_data.location.file).collect()
}

/// Go through all modules in this crate, and find all functions in
/// each module with the #[test] attribute
pub fn get_all_test_functions<'a>(
Expand Down
6 changes: 5 additions & 1 deletion compiler/noirc_frontend/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use fm::{FileId, FileManager};
use iter_extended::vecmap;
use noirc_errors::Location;
use std::borrow::Cow;
use std::collections::{BTreeMap, HashMap};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::path::PathBuf;
use std::rc::Rc;

Expand Down Expand Up @@ -301,6 +301,10 @@ impl Context<'_, '_> {
})
}

pub fn crate_files(&self, crate_id: &CrateId) -> HashSet<FileId> {
self.def_maps.get(crate_id).map(|def_map| def_map.file_ids()).unwrap_or_default()
}

/// Activates LSP mode, which will track references for all definitions.
pub fn activate_lsp_mode(&mut self) {
self.def_interner.lsp_mode = true;
Expand Down
2 changes: 0 additions & 2 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub(crate) fn get_program_with_maybe_parser_errors(
};

let debug_comptime_in_file = None;
let error_on_unused_imports = true;

// Now we want to populate the CrateDefMap using the DefCollector
errors.extend(DefCollector::collect_crate_and_dependencies(
Expand All @@ -123,7 +122,6 @@ pub(crate) fn get_program_with_maybe_parser_errors(
program.clone().into_sorted(),
root_file_id,
debug_comptime_in_file,
error_on_unused_imports,
));
}
(program, context, errors)
Expand Down