diff --git a/compiler/build/src/program.rs b/compiler/build/src/program.rs index 4aa85ef553..0816d4e788 100644 --- a/compiler/build/src/program.rs +++ b/compiler/build/src/program.rs @@ -42,10 +42,12 @@ pub fn gen_from_mono_module( use std::time::SystemTime; use roc_reporting::report::{ - can_problem, mono_problem, type_problem, RocDocAllocator, DEFAULT_PALETTE, + can_problem, mono_problem, type_problem, Report, RocDocAllocator, DEFAULT_PALETTE, }; let code_gen_start = SystemTime::now(); + let total_problems = loaded.total_problems(); + let palette = DEFAULT_PALETTE; for (home, (module_path, src)) in loaded.sources { let mut src_lines: Vec<&str> = Vec::new(); @@ -56,7 +58,6 @@ pub fn gen_from_mono_module( } else { src_lines.extend(src.split('\n')); } - let palette = DEFAULT_PALETTE; // Report parsing and canonicalization problems let alloc = RocDocAllocator::new(&src_lines, home, &loaded.interns); @@ -92,6 +93,16 @@ pub fn gen_from_mono_module( } } + // If we printed any problems, print a horizontal rule at the end, + // and then clear any ANSI escape codes (e.g. colors) we've used. + // + // The horizontal rule is nice when running the program right after + // compiling it, as it lets you clearly see where the compiler + // errors/warnings end and the program output begins. + if total_problems > 0 { + println!("{}\u{001B}[0m\n", Report::horizontal_rule(&palette)); + } + // Generate the binary let ptr_bytes = target.pointer_width().unwrap().bytes() as u32; let context = Context::create(); diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 728d71b9dc..6c0f33c81d 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -721,6 +721,12 @@ pub struct MonomorphizedModule<'a> { pub timings: MutMap, } +impl<'a> MonomorphizedModule<'a> { + pub fn total_problems(&self) -> usize { + self.can_problems.len() + self.type_problems.len() + self.mono_problems.len() + } +} + #[derive(Debug, Default)] pub struct VariablySizedLayouts<'a> { rigids: MutMap>, diff --git a/compiler/reporting/src/report.rs b/compiler/reporting/src/report.rs index 27e5b1ece4..a99b57bc47 100644 --- a/compiler/reporting/src/report.rs +++ b/compiler/reporting/src/report.rs @@ -119,6 +119,10 @@ impl<'b> Report<'b> { ]) } } + + pub fn horizontal_rule(palette: &'b Palette) -> String { + format!("{}{}", palette.header, "─".repeat(80)) + } } pub struct Palette<'a> {