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

Add ignore_warnings flag. #7079

Merged
merged 1 commit into from
Jan 19, 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
7 changes: 7 additions & 0 deletions crates/bin/cairo-execute/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ struct BuildArgs {
/// Allows the compilation to succeed with warnings.
#[arg(long, conflicts_with = "prebuilt")]
allow_warnings: bool,
/// Allow warnings and don't print them (implies allow_warnings).
#[arg(long, conflicts_with = "prebuilt")]
ignore_warnings: bool,
/// Path to the executable function.
#[arg(long, conflicts_with = "prebuilt")]
executable: Option<String>,
Expand Down Expand Up @@ -132,6 +135,10 @@ fn main() -> anyhow::Result<()> {
if args.build.allow_warnings {
reporter = reporter.allow_warnings();
}
if args.build.ignore_warnings {
reporter = reporter.ignore_all_warnings();
}

Executable::new(compile_executable(
&args.path,
args.build.executable.as_deref(),
Expand Down
15 changes: 13 additions & 2 deletions crates/cairo-lang-compiler/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl DiagnosticCallback for Option<Box<dyn DiagnosticCallback + '_>> {
/// Collects compilation diagnostics and presents them in preconfigured way.
pub struct DiagnosticsReporter<'a> {
callback: Option<Box<dyn DiagnosticCallback + 'a>>,
/// Ignore warnings in these crates. This should be subset of `crate_ids`.
// Ignore all warnings, the `ignore_warnings_crate_ids` field is irrelevant in this case.
ignore_all_warnings: bool,
/// Ignore warnings in specific crates. This should be subset of `crate_ids`.
/// Adding ids that are not in `crate_ids` have no effect.
ignore_warnings_crate_ids: Vec<CrateId>,
/// Check diagnostics for these crates only.
Expand All @@ -56,6 +58,7 @@ impl DiagnosticsReporter<'static> {
Self {
callback: None,
crate_ids: vec![],
ignore_all_warnings: false,
ignore_warnings_crate_ids: vec![],
allow_warnings: false,
skip_lowering_diagnostics: false,
Expand Down Expand Up @@ -100,6 +103,7 @@ impl<'a> DiagnosticsReporter<'a> {
Self {
callback: Some(Box::new(callback)),
crate_ids: vec![],
ignore_all_warnings: false,
ignore_warnings_crate_ids: vec![],
allow_warnings: false,
skip_lowering_diagnostics: false,
Expand Down Expand Up @@ -127,6 +131,12 @@ impl<'a> DiagnosticsReporter<'a> {
self
}

/// Ignores warnings in all cargo crates.
pub fn ignore_all_warnings(mut self) -> Self {
self.ignore_all_warnings = true;
self
}

/// Returns the crate ids for which the diagnostics will be checked.
fn crates_of_interest(&self, db: &dyn LoweringGroup) -> Vec<CrateId> {
if self.crate_ids.is_empty() { db.crates() } else { self.crate_ids.clone() }
Expand Down Expand Up @@ -164,7 +174,8 @@ impl<'a> DiagnosticsReporter<'a> {
found_diagnostics = true;
}

let ignore_warnings_in_crate = self.ignore_warnings_crate_ids.contains(crate_id);
let ignore_warnings_in_crate =
self.ignore_all_warnings || self.ignore_warnings_crate_ids.contains(crate_id);
let modules = db.crate_modules(*crate_id);
let mut processed_file_ids = UnorderedHashSet::<_>::default();
for module_id in modules.iter() {
Expand Down
Loading