Skip to content

Commit

Permalink
feat: almost finish emitter implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 30, 2023
1 parent 381eb55 commit b2152f1
Show file tree
Hide file tree
Showing 10 changed files with 771 additions and 73 deletions.
186 changes: 178 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ sulk-parser = { version = "0.0.0", path = "crates/parser" }

alloy-primitives = "0.5"

# diagnostics
anstream = "0.6"
anstyle = "1.0"
# ariadne = "0.3"
annotate-snippets = "0.10"

# serde
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# macros
proc-macro2 = "1.0"
quote = "1.0"
Expand All @@ -51,12 +61,12 @@ rayon = "1.8"

# testing
criterion = "0.5"
expect-test = "1.4"
rand = "0.8"

# misc
ahash = "0.8"
bumpalo = "3.14"
expect-test = "1.4"
hex = { package = "const-hex", version = "1.10" }
index_vec = "0.1.3"
indexmap = "2.1"
Expand Down
10 changes: 10 additions & 0 deletions crates/interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,15 @@ sulk-macros.workspace = true
bumpalo.workspace = true
scoped-tls.workspace = true

# diagnostics
anstream.workspace = true
anstyle.workspace = true
annotate-snippets.workspace = true

# json
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }

[features]
nightly = ["sulk-data-structures/nightly", "sulk-macros/nightly"]
json = ["dep:serde", "dep:serde_json"]
7 changes: 6 additions & 1 deletion crates/interface/src/diagnostics/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
marker::PhantomData,
mem::ManuallyDrop,
ops::{Deref, DerefMut},
panic::Location,
};
use sulk_data_structures::Never;

Expand Down Expand Up @@ -146,7 +147,11 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {

/// Emits the diagnostic.
#[track_caller]
pub fn emit(self) -> G::EmitResult {
pub fn emit(mut self) -> G::EmitResult {
// TODO: Check on some flag in dcx
if cfg!(debug_assertions) {
self.diagnostic.locations_note(Location::caller());
}
self.consume_no_panic(G::emit_producing_guarantee)
}

Expand Down
12 changes: 6 additions & 6 deletions crates/interface/src/diagnostics/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
Diagnostic, DiagnosticBuilder, DiagnosticMessage, DynEmitter, EmissionGuarantee,
ErrorGuaranteed, FatalAbort, Level, SilentEmitter,
emitter::EmitterWriter, ColorConfig, Diagnostic, DiagnosticBuilder, DiagnosticMessage,
DynEmitter, EmissionGuarantee, ErrorGuaranteed, FatalAbort, Level, SilentEmitter,
};
use crate::SourceMap;
use sulk_data_structures::{
Expand Down Expand Up @@ -52,9 +52,8 @@ impl DiagCtxt {
}

/// Creates a new `DiagCtxt` with a TTY emitter.
pub fn with_tty_emitter(sm: Option<Lrc<SourceMap>>) -> Self {
let _ = sm;
todo!("tty emitter")
pub fn with_tty_emitter(source_map: Option<Lrc<SourceMap>>) -> Self {
Self::new(Box::new(EmitterWriter::stderr(ColorConfig::Auto).source_map(source_map)))
}

/// Creates a new `DiagCtxt` with a silent emitter.
Expand Down Expand Up @@ -174,7 +173,8 @@ impl DiagCtxtInner {

if diagnostic.is_error() {
self.bump_err_count();
Some(ErrorGuaranteed(()))
#[allow(deprecated)]
Some(ErrorGuaranteed::new_unchecked())
} else {
self.bump_warn_count();
None
Expand Down
Loading

0 comments on commit b2152f1

Please sign in to comment.