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

feat: don't report warnings for dependencies #6926

Merged
merged 9 commits into from
Jan 6, 2025
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 @@
};

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 @@
program.clone().into_sorted(),
root_file_id,
debug_comptime_in_file,
error_on_unused_imports,
));
}
(program, context, errors)
Expand Down Expand Up @@ -3170,7 +3168,7 @@
}

#[test]
fn dont_infer_globals_to_u32_from_type_use() {

Check warning on line 3171 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (dont)
let src = r#"
global ARRAY_LEN = 3;
global STR_LEN: _ = 2;
Expand Down Expand Up @@ -3200,7 +3198,7 @@
}

#[test]
fn dont_infer_partial_global_types() {

Check warning on line 3201 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (dont)
let src = r#"
pub global ARRAY: [Field; _] = [0; 3];
pub global NESTED_ARRAY: [[Field; _]; 3] = [[]; 3];
Expand Down Expand Up @@ -3438,7 +3436,7 @@

#[test]
fn unconditional_recursion_fail() {
let srcs = vec![

Check warning on line 3439 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (srcs)
r#"
fn main() {
main()
Expand Down Expand Up @@ -3500,7 +3498,7 @@
"#,
];

for src in srcs {

Check warning on line 3501 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (srcs)
let errors = get_program_errors(src);
assert!(
!errors.is_empty(),
Expand All @@ -3519,7 +3517,7 @@

#[test]
fn unconditional_recursion_pass() {
let srcs = vec![

Check warning on line 3520 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (srcs)
r#"
fn main() {
if false { main(); }
Expand Down Expand Up @@ -3561,7 +3559,7 @@
"#,
];

for src in srcs {

Check warning on line 3562 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (srcs)
assert_no_errors(src);
}
}
Expand Down
Loading