tamer: diagnose::Diagnostic: Remove Error trait bound

Diagnostic events need not be errors.  While that was the original intent,
it'd also be nice to be able to use the diagnostic system for any type of
logging, where the verbosity level would determine the type of report that
is output (whether source information should be provided).

Then we could have e.g. AirAggregate produce events describing what actions
are occurring, which could be much more useful than a trace in many
contexts, and would be able to operate via a runtime toggle/filter without
having an adverse effect on performance (since the diagnostic rendering
itself is the hit; the underlying data are cheap).

Anyway---I'm addressing this now to generalize the reporter in the lowering
pipeline, so that it can report on not just errors but anything.

DEV-13162
main
Mike Gerwitz 2023-06-01 12:38:23 -04:00
parent 2bf3122402
commit 0f20f22cfb
2 changed files with 21 additions and 11 deletions

View File

@ -17,7 +17,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//! Diagnostic system for error reporting.
//! Diagnostic system for error reporting and logging.
//!
//! This system is heavily motivated by Rust's.
//! While the data structures and organization may differ,
@ -81,12 +81,15 @@ pub mod panic;
mod report;
mod resolve;
use std::{
borrow::Cow,
convert::Infallible,
fmt::{self, Debug, Display},
};
pub use report::{Reporter, VisualReporter};
pub use resolve::FsSpanResolver;
use core::fmt;
use std::{borrow::Cow, convert::Infallible, error::Error, fmt::Display};
use crate::span::Span;
/// No annotated description is applicable for the diagnostic message.
@ -97,12 +100,17 @@ use crate::span::Span;
/// depends on the error context.
pub const NO_DESC: Vec<AnnotatedSpan> = vec![];
/// Diagnostic report.
/// An event able to describe itself for diagnostic reporting.
///
/// This describes an error condition or other special event using a series
/// of [`Span`]s to describe the source, cause, and circumstances around
/// an event.
pub trait Diagnostic: Error + Sized {
/// This describes an event using a series of [`Span`]s to describe the
/// source, cause, and circumstances around an event.
///
/// A diagnostic event is not necessarily an error condition;
/// for example,
/// a user may request logging of compilation events to inspect the
/// state of the system or help them to debug why the system is
/// interpreting their program in a certain way.
pub trait Diagnostic: Display + Debug + Sized {
/// Produce a series of [`AnnotatedSpan`]s describing the source and
/// circumstances of the diagnostic event.
fn describe(&self) -> Vec<AnnotatedSpan>;
@ -283,7 +291,7 @@ pub trait Annotate: Sized {
self.annotate(Level::Error, Some(label.into()))
}
/// Like [`Annotate::error`],
/// Like [`Annotate::error`]r
/// but only styles the span as a [`Level::Error`] without attaching a
/// label.
///

View File

@ -107,7 +107,9 @@ impl<T: Token, E: Diagnostic + PartialEq> Display for ParseError<T, E> {
}
}
impl<T: Token, E: Diagnostic + PartialEq + 'static> Error for ParseError<T, E> {
impl<T: Token, E: Diagnostic + Error + PartialEq + 'static> Error
for ParseError<T, E>
{
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::UnexpectedToken(_, _) => None,