diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.toml index bb881cd937..88a08f4f19 100644 --- a/cranelift/codegen/Cargo.toml +++ b/cranelift/codegen/Cargo.toml @@ -99,7 +99,7 @@ incremental-cache = [ # Enable support for the Souper harvester. souper-harvest = ["souper-ir", "souper-ir/stringify"] -# Provide fancy Miette-produced errors for ISLE. +# Report any ISLE errors in pretty-printed style. isle-errors = ["cranelift-isle/fancy-errors"] # Put ISLE generated files in isle_generated_code/, for easier diff --git a/cranelift/docs/isle-integration.md b/cranelift/docs/isle-integration.md index fde0e16436..fce5e03ea9 100644 --- a/cranelift/docs/isle-integration.md +++ b/cranelift/docs/isle-integration.md @@ -40,8 +40,7 @@ could cause significant confusion. If there are any errors during ISLE compilation (e.g., a type mismatch), you will see a basic error message with a file, line number, and one-line error. To see a more detailed output with context, `--features isle-errors` can be used. -This will leverage the `miette` error-reporting library to give pretty-printed -errors with source context. +This will give pretty-printed errors with source context. Additionally, the `cranelift-codegen-meta` crate will automatically generate ISLE `extern` declarations and helpers for working with CLIF. The code that does diff --git a/cranelift/isle/isle/src/error.rs b/cranelift/isle/isle/src/error.rs index d8c543c5bc..d919e36d1d 100644 --- a/cranelift/isle/isle/src/error.rs +++ b/cranelift/isle/isle/src/error.rs @@ -157,29 +157,24 @@ impl Errors { f: &mut std::fmt::Formatter, diagnostics: Vec>, ) -> std::fmt::Result { - let line_starts: Vec> = self + let line_ends: Vec> = self .file_texts .iter() - .map(|text| { - let mut end = 0; - text.split_inclusive('\n') - .map(|line| { - let start = end; - end += line.len(); - start - }) - .collect() - }) + .map(|text| text.match_indices('\n').map(|(i, _)| i + 1).collect()) .collect(); let pos = |file_id: usize, offset| { - let starts = &line_starts[file_id]; - let line = starts.partition_point(|&start| start <= offset); + let ends = &line_ends[file_id]; + let line0 = ends.partition_point(|&end| end <= offset); let text = &self.file_texts[file_id]; - let line_range = starts[line - 1]..starts.get(line).copied().unwrap_or(text.len()); - let col = offset - line_range.start + 1; + let start = line0.checked_sub(1).map_or(0, |prev| ends[prev]); + let end = ends.get(line0).copied().unwrap_or(text.len()); + let col = offset - start + 1; format!( "{}:{}:{}: {}", - self.filenames[file_id], line, col, &text[line_range] + self.filenames[file_id], + line0 + 1, + col, + &text[start..end] ) }; for diagnostic in diagnostics { @@ -190,6 +185,7 @@ impl Errors { for note in diagnostic.notes { writeln!(f, "{}", note)?; } + writeln!(f)?; } Ok(()) } @@ -219,10 +215,9 @@ impl Span { Span { from: pos, // This is a slight hack (we don't actually look at the - // file to find line/col of next char); but the span - // aspect, vs. just the starting point, is only relevant - // for miette and when miette is enabled we use only the - // `offset` here to provide its SourceSpans. + // file to find line/col of next char); but the `to` + // position only matters for pretty-printed errors and only + // the offset is used in that case. to: Pos { file: pos.file, offset: pos.offset + 1, diff --git a/cranelift/isle/isle/src/sema.rs b/cranelift/isle/isle/src/sema.rs index 4990ae99cf..d45ae68900 100644 --- a/cranelift/isle/isle/src/sema.rs +++ b/cranelift/isle/isle/src/sema.rs @@ -1176,7 +1176,7 @@ impl TermEnv { () }) }) - .collect::, _>>(); + .collect::, _>>(); let arg_tys = match arg_tys { Ok(a) => a, Err(_) => {