Skip to content

Commit

Permalink
frontend: Start report warnings when errors aren't present.
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Oct 30, 2024
1 parent 1f077ab commit 8eb802f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
21 changes: 15 additions & 6 deletions dora-frontend/src/error/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,32 @@ impl Diagnostic {
!self.errors.is_empty() || !self.warnings.is_empty()
}

pub fn dump(&mut self, sa: &Sema) {
pub fn dump(&mut self, sa: &Sema, report_all_warnings: bool) {
self.sort();

for err in &self.errors {
eprintln!("{}", message_for_error(err, "error", sa));
}

for err in &self.warnings {
if let Some(file_id) = err.file_id {
let file = sa.file(file_id);
if !report_all_warnings && file.package_id != sa.program_package_id() {
// Do not report warnings by default in standard library or boots for now.
continue;
}
}
eprintln!("{}", message_for_error(err, "warning", sa));
}

let no_errors = self.errors.len();
if !self.errors.is_empty() {
let no_errors = self.errors.len();

if no_errors == 1 {
eprintln!("{} error found.", no_errors);
} else {
eprintln!("{} errors found.", no_errors);
if no_errors == 1 {
eprintln!("{} error found.", no_errors);
} else {
eprintln!("{} errors found.", no_errors);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions dora-frontend/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ where
{
check(code, |sa| {
if sa.diag.borrow().has_errors() {
sa.diag.borrow_mut().dump(sa);
sa.diag.borrow_mut().dump(sa, false);
println!("{}", code);
panic!("unexpected error in test::parse()");
panic!("unexpected error in test");
}

f(sa)
Expand Down
4 changes: 4 additions & 0 deletions dora/src/driver/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub struct DriverFlags {
pub use_boots: Option<String>,
pub version: bool,
pub help: bool,
pub report_all_warnings: bool,
pub emit_debug: Option<String>,
pub emit_debug_native: bool,
pub emit_debug_compile: bool,
Expand Down Expand Up @@ -148,6 +149,7 @@ impl Default for DriverFlags {
use_boots: None,
version: false,
help: false,
report_all_warnings: false,
gc_events: false,
gc_stress: false,
gc_stress_in_lazy_compile: false,
Expand Down Expand Up @@ -226,6 +228,8 @@ pub fn parse_arguments() -> Result<DriverFlags, String> {
flags.check = true;
} else if arg == "-h" || arg == "--help" {
flags.help = true;
} else if arg == "--report-all-warnings" {
flags.report_all_warnings = true;
} else if arg.starts_with("--emit-ast=") {
flags.emit_ast = Some(argument_value(arg).into());
} else if arg.starts_with("--emit-asm=") {
Expand Down
10 changes: 5 additions & 5 deletions dora/src/driver/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn compile_into_program(flags: &DriverFlags, file: String) -> Result<Program, ()
let success = language::check_program(&mut sa);
assert_eq!(success, !sa.diag.borrow().has_errors());

if report_errors(&sa) {
if report_errors(&sa, flags.report_all_warnings) {
return Err(());
}

Expand Down Expand Up @@ -206,10 +206,10 @@ fn encode_and_decode_for_testing(prog: Program) -> Program {
decoded_prog
}

fn report_errors(sa: &Sema) -> bool {
if sa.diag.borrow().has_errors() {
sa.diag.borrow_mut().dump(&sa);
true
fn report_errors(sa: &Sema, report_all_warnings: bool) -> bool {
if sa.diag.borrow().has_errors_or_warnings() {
sa.diag.borrow_mut().dump(&sa, report_all_warnings);
sa.diag.borrow().has_errors()
} else {
false
}
Expand Down
2 changes: 1 addition & 1 deletion tools/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ set -e

cargo build
cargo test
cargo run -p dora -- --boots --gc-verbose --emit-compiler --bootstrap-compiler tests/boots/hello.dora
cargo run -p dora -- --boots --report-all-warnings --gc-verbose --emit-compiler --bootstrap-compiler tests/boots/hello.dora
ruby tools/tester.rb $@
cargo run -p dora -- test --boots --test-boots --gc-verify tests/hello-world.dora
2 changes: 1 addition & 1 deletion tools/test-boots
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -e

cargo run -p dora -- test --boots --test-boots --gc-verify tests/hello-world.dora
cargo run -p dora -- test --boots --report-all-warnings --test-boots --gc-verify tests/hello-world.dora
cargo run -p dora -- --boots --gc-verbose --emit-compiler --bootstrap-compiler tests/boots/hello.dora
ruby tools/tester.rb tests/boots
2 changes: 1 addition & 1 deletion tools/test-release
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ set -e

cargo build --release
cargo test --release
cargo run -p dora --release -- --boots --gc-verbose --emit-compiler --bootstrap-compiler tests/boots/hello.dora
cargo run -p dora --release -- --boots --report-all-warnings --gc-verbose --emit-compiler --bootstrap-compiler tests/boots/hello.dora
ruby tools/tester.rb --release $@
cargo run --release -p dora -- test --boots --test-boots tests/hello-world.dora

0 comments on commit 8eb802f

Please sign in to comment.