mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 14:01:08 +01:00
Update codespan-reporting to 0.13 (#9243)
This commit is contained in:
1 parent
4d13af7a1a
commit
384b7bb027
8 files changed
+131
-45
No files matched your search
@@ -195,6 +195,7 @@ By @kpreid in [#9042](https://github.com/gfx-rs/wgpu/pull/9042).
|
||||
- Prevent UB from incorrectly using ray queries on HLSL. By @Vecvec in [#8763](https://github.com/gfx-rs/wgpu/pull/8763).
|
||||
- Added support for dual-source blending in SPIR-V shaders. By @andyleiserson in [#8865](https://github.com/gfx-rs/wgpu/pull/8865).
|
||||
- Added `supported_capabilities` to all backends. By @inner-daemons in [#9068](https://github.com/gfx-rs/wgpu/pull/9068).
|
||||
- Updated codespan-reporting to 0.13. By @cwfitzgerald in [#9243](https://github.com/gfx-rs/wgpu/pull/9243).
|
||||
|
||||
#### Metal
|
||||
|
||||
|
||||
Generated
+2
-2
@@ -717,9 +717,9 @@ checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.12.0"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81"
|
||||
checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"termcolor",
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ bytemuck = { version = "1.22", features = [
|
||||
cargo_metadata = "0.23"
|
||||
cfg_aliases = "0.2.1"
|
||||
cfg-if = "1"
|
||||
codespan-reporting = { version = "0.12", default-features = false }
|
||||
codespan-reporting = { version = "0.13", default-features = false }
|
||||
ctor = "0.6"
|
||||
diff = "0.1"
|
||||
document-features = "0.2.10"
|
||||
|
||||
+47
-19
@@ -44,17 +44,11 @@ impl fmt::Display for ShaderError<crate::WithSpan<crate::valid::ValidationError>
|
||||
let files = SimpleFile::new(label, replace_control_chars(&self.source));
|
||||
let config = term::Config::default();
|
||||
|
||||
let writer = {
|
||||
let mut writer = DiagnosticBuffer::new();
|
||||
term::emit(
|
||||
writer.inner_mut(),
|
||||
&config,
|
||||
&files,
|
||||
&self.inner.diagnostic(),
|
||||
)
|
||||
let mut writer = DiagnosticBuffer::new();
|
||||
writer
|
||||
.emit_to_self(&config, &files, &self.inner.diagnostic())
|
||||
.expect("cannot write error");
|
||||
writer.into_string()
|
||||
};
|
||||
let writer = writer.into_string();
|
||||
|
||||
write!(f, "\nShader validation {writer}")
|
||||
}
|
||||
@@ -63,25 +57,46 @@ impl fmt::Display for ShaderError<crate::WithSpan<crate::valid::ValidationError>
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "termcolor")] {
|
||||
type DiagnosticBufferInner = codespan_reporting::term::termcolor::NoColor<alloc::vec::Vec<u8>>;
|
||||
pub(crate) use codespan_reporting::term::termcolor::WriteColor as _ErrorWrite;
|
||||
} else if #[cfg(feature = "stderr")] {
|
||||
type DiagnosticBufferInner = alloc::vec::Vec<u8>;
|
||||
pub(crate) use std::io::Write as _ErrorWrite;
|
||||
} else {
|
||||
type DiagnosticBufferInner = String;
|
||||
pub(crate) use core::fmt::Write as _ErrorWrite;
|
||||
}
|
||||
}
|
||||
|
||||
// Using this indirect export to avoid duplicating the expect(...) for all three cases above.
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(all(feature = "stderr", feature = "termcolor"))] {
|
||||
pub(crate) use codespan_reporting::term::termcolor::WriteColor as _ErrorWrite;
|
||||
} else if #[cfg(feature = "stderr")] {
|
||||
pub(crate) use std::io::Write as _ErrorWrite;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stderr")]
|
||||
pub(crate) use _ErrorWrite as ErrorWrite;
|
||||
|
||||
#[cfg(feature = "stderr")]
|
||||
#[cfg_attr(
|
||||
not(any(feature = "spv-in", feature = "glsl-in")),
|
||||
expect(
|
||||
unused_imports,
|
||||
reason = "only need `ErrorWrite` with an appropriate front-end."
|
||||
dead_code,
|
||||
reason = "only need `emit_to_writer` with an appropriate front-end."
|
||||
)
|
||||
)]
|
||||
pub(crate) use _ErrorWrite as ErrorWrite;
|
||||
pub(crate) fn emit_to_writer<'files, F: codespan_reporting::files::Files<'files> + ?Sized>(
|
||||
writer: &mut impl ErrorWrite,
|
||||
config: &codespan_reporting::term::Config,
|
||||
files: &'files F,
|
||||
diagnostic: &codespan_reporting::diagnostic::Diagnostic<F::FileId>,
|
||||
) -> Result<(), codespan_reporting::files::Error> {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "termcolor")] {
|
||||
codespan_reporting::term::emit_to_write_style(writer, config, files, diagnostic)
|
||||
} else {
|
||||
codespan_reporting::term::emit_to_io_write(writer, config, files, diagnostic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct DiagnosticBuffer {
|
||||
inner: DiagnosticBufferInner,
|
||||
@@ -109,8 +124,21 @@ impl DiagnosticBuffer {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
pub const fn inner_mut(&mut self) -> &mut DiagnosticBufferInner {
|
||||
&mut self.inner
|
||||
pub fn emit_to_self<'files, F: codespan_reporting::files::Files<'files> + ?Sized>(
|
||||
&mut self,
|
||||
config: &codespan_reporting::term::Config,
|
||||
files: &'files F,
|
||||
diagnostic: &codespan_reporting::diagnostic::Diagnostic<F::FileId>,
|
||||
) -> Result<(), codespan_reporting::files::Error> {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "termcolor")] {
|
||||
codespan_reporting::term::emit_to_write_style(&mut self.inner, config, files, diagnostic)
|
||||
} else if #[cfg(feature = "stderr")] {
|
||||
codespan_reporting::term::emit_to_io_write(&mut self.inner, config, files, diagnostic)
|
||||
} else {
|
||||
codespan_reporting::term::emit_to_string(&mut self.inner, config, files, diagnostic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> String {
|
||||
|
||||
@@ -12,8 +12,10 @@ use pp_rs::token::PreprocessorError;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::token::TokenValue;
|
||||
#[cfg(feature = "stderr")]
|
||||
use crate::error::ErrorWrite;
|
||||
use crate::{error::replace_control_chars, SourceLocation};
|
||||
use crate::{error::ErrorWrite, proc::ConstantEvaluatorError, Span};
|
||||
use crate::{proc::ConstantEvaluatorError, Span};
|
||||
|
||||
fn join_with_comma(list: &[ExpectedToken]) -> String {
|
||||
let mut string = "".to_string();
|
||||
@@ -165,31 +167,70 @@ pub struct ParseErrors {
|
||||
}
|
||||
|
||||
impl ParseErrors {
|
||||
#[cfg(feature = "stderr")]
|
||||
pub fn emit_to_writer(&self, writer: &mut impl ErrorWrite, source: &str) {
|
||||
self.emit_to_writer_with_path(writer, source, "glsl");
|
||||
}
|
||||
|
||||
#[cfg(feature = "stderr")]
|
||||
pub fn emit_to_writer_with_path(&self, writer: &mut impl ErrorWrite, source: &str, path: &str) {
|
||||
let path = path.to_string();
|
||||
let files = SimpleFile::new(path, replace_control_chars(source));
|
||||
let config = term::Config::default();
|
||||
|
||||
for err in &self.errors {
|
||||
let mut diagnostic = Diagnostic::error().with_message(err.kind.to_string());
|
||||
let diagnostic = Self::make_diagnostic(err);
|
||||
crate::error::emit_to_writer(writer, &config, &files, &diagnostic)
|
||||
.expect("cannot write error");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(range) = err.meta.to_range() {
|
||||
diagnostic = diagnostic.with_labels(vec![Label::primary((), range)]);
|
||||
/// Emits a summary of the errors to standard error stream.
|
||||
#[cfg(feature = "stderr")]
|
||||
pub fn emit_to_stderr(&self, source: &str) {
|
||||
self.emit_to_stderr_with_path(source, "glsl")
|
||||
}
|
||||
|
||||
/// Emits a summary of the errors to standard error stream.
|
||||
#[cfg(feature = "stderr")]
|
||||
pub fn emit_to_stderr_with_path(&self, source: &str, path: &str) {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "termcolor")] {
|
||||
let writer = term::termcolor::StandardStream::stderr(term::termcolor::ColorChoice::Auto);
|
||||
self.emit_to_writer_with_path(&mut writer.lock(), source, path);
|
||||
} else {
|
||||
let writer = std::io::stderr();
|
||||
self.emit_to_writer_with_path(&mut writer.lock(), source, path);
|
||||
}
|
||||
|
||||
term::emit(writer, &config, &files, &diagnostic).expect("cannot write error");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn emit_to_string(&self, source: &str) -> String {
|
||||
self.emit_to_string_with_path(source, "glsl")
|
||||
}
|
||||
|
||||
pub fn emit_to_string_with_path(&self, source: &str, path: &str) -> String {
|
||||
let path = path.to_string();
|
||||
let files = SimpleFile::new(path, replace_control_chars(source));
|
||||
let config = term::Config::default();
|
||||
|
||||
let mut writer = crate::error::DiagnosticBuffer::new();
|
||||
self.emit_to_writer(writer.inner_mut(), source);
|
||||
for err in &self.errors {
|
||||
let diagnostic = Self::make_diagnostic(err);
|
||||
writer
|
||||
.emit_to_self(&config, &files, &diagnostic)
|
||||
.expect("cannot write error");
|
||||
}
|
||||
writer.into_string()
|
||||
}
|
||||
|
||||
fn make_diagnostic(err: &Error) -> Diagnostic<()> {
|
||||
let mut diagnostic = Diagnostic::error().with_message(err.kind.to_string());
|
||||
if let Some(range) = err.meta.to_range() {
|
||||
diagnostic = diagnostic.with_labels(vec![Label::primary((), range)]);
|
||||
}
|
||||
diagnostic
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for ParseErrors {
|
||||
|
||||
@@ -8,11 +8,9 @@ use codespan_reporting::files::SimpleFile;
|
||||
use codespan_reporting::term;
|
||||
|
||||
use super::ModuleState;
|
||||
use crate::{
|
||||
arena::Handle,
|
||||
error::{replace_control_chars, ErrorWrite},
|
||||
front::atomic_upgrade,
|
||||
};
|
||||
#[cfg(feature = "stderr")]
|
||||
use crate::error::ErrorWrite;
|
||||
use crate::{arena::Handle, error::replace_control_chars, front::atomic_upgrade};
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
@@ -159,22 +157,36 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl Error {
|
||||
#[cfg(feature = "stderr")]
|
||||
pub fn emit_to_writer(&self, writer: &mut impl ErrorWrite, source: &str) {
|
||||
self.emit_to_writer_with_path(writer, source, "glsl");
|
||||
self.emit_to_writer_with_path(writer, source, "spv");
|
||||
}
|
||||
|
||||
#[cfg(feature = "stderr")]
|
||||
pub fn emit_to_writer_with_path(&self, writer: &mut impl ErrorWrite, source: &str, path: &str) {
|
||||
let path = path.to_string();
|
||||
let files = SimpleFile::new(path, replace_control_chars(source));
|
||||
let config = term::Config::default();
|
||||
let diagnostic = Diagnostic::error().with_message(format!("{self:?}"));
|
||||
|
||||
term::emit(writer, &config, &files, &diagnostic).expect("cannot write error");
|
||||
crate::error::emit_to_writer(writer, &config, &files, &diagnostic)
|
||||
.expect("cannot write error");
|
||||
}
|
||||
|
||||
pub fn emit_to_string(&self, source: &str) -> String {
|
||||
self.emit_to_string_with_path(source, "spv")
|
||||
}
|
||||
|
||||
pub fn emit_to_string_with_path(&self, source: &str, path: &str) -> String {
|
||||
let path = path.to_string();
|
||||
let files = SimpleFile::new(path, replace_control_chars(source));
|
||||
let config = term::Config::default();
|
||||
let diagnostic = Diagnostic::error().with_message(format!("{self:?}"));
|
||||
|
||||
let mut writer = crate::error::DiagnosticBuffer::new();
|
||||
self.emit_to_writer(writer.inner_mut(), source);
|
||||
writer
|
||||
.emit_to_self(&config, &files, &diagnostic)
|
||||
.expect("cannot write error");
|
||||
writer.into_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,13 +86,14 @@ impl ParseError {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "termcolor")] {
|
||||
let writer = term::termcolor::StandardStream::stderr(term::termcolor::ColorChoice::Auto);
|
||||
term::emit_to_write_style(&mut writer.lock(), &config, &files, &self.diagnostic())
|
||||
.expect("cannot write error");
|
||||
} else {
|
||||
let writer = std::io::stderr();
|
||||
term::emit_to_io_write(&mut writer.lock(), &config, &files, &self.diagnostic())
|
||||
.expect("cannot write error");
|
||||
}
|
||||
}
|
||||
|
||||
term::emit(&mut writer.lock(), &config, &files, &self.diagnostic())
|
||||
.expect("cannot write error");
|
||||
}
|
||||
|
||||
/// Emits a summary of the error to a string.
|
||||
@@ -110,7 +111,8 @@ impl ParseError {
|
||||
let config = term::Config::default();
|
||||
|
||||
let mut writer = crate::error::DiagnosticBuffer::new();
|
||||
term::emit(writer.inner_mut(), &config, &files, &self.diagnostic())
|
||||
writer
|
||||
.emit_to_self(&config, &files, &self.diagnostic())
|
||||
.expect("cannot write error");
|
||||
writer.into_string()
|
||||
}
|
||||
|
||||
+6
-4
@@ -294,13 +294,14 @@ impl<E> WithSpan<E> {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "termcolor")] {
|
||||
let writer = term::termcolor::StandardStream::stderr(term::termcolor::ColorChoice::Auto);
|
||||
term::emit_to_write_style(&mut writer.lock(), &config, &files, &self.diagnostic())
|
||||
.expect("cannot write error");
|
||||
} else {
|
||||
let writer = std::io::stderr();
|
||||
term::emit_to_io_write(&mut writer.lock(), &config, &files, &self.diagnostic())
|
||||
.expect("cannot write error");
|
||||
}
|
||||
}
|
||||
|
||||
term::emit(&mut writer.lock(), &config, &files, &self.diagnostic())
|
||||
.expect("cannot write error");
|
||||
}
|
||||
|
||||
/// Emits a summary of the error to a string.
|
||||
@@ -322,7 +323,8 @@ impl<E> WithSpan<E> {
|
||||
let config = term::Config::default();
|
||||
|
||||
let mut writer = crate::error::DiagnosticBuffer::new();
|
||||
term::emit(writer.inner_mut(), &config, &files, &self.diagnostic())
|
||||
writer
|
||||
.emit_to_self(&config, &files, &self.diagnostic())
|
||||
.expect("cannot write error");
|
||||
writer.into_string()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user