mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Make naga span methods take path as generic AsRef Path (#7643)
Co-authored-by: Erich Gubler <erichdongubler@gmail.com> Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
parent
73eb83ded1
commit
645354a528
@ -56,6 +56,7 @@ Bottom level categories:
|
|||||||
#### Naga
|
#### Naga
|
||||||
|
|
||||||
- When emitting GLSL, Uniform and Storage Buffer memory layouts are now emitted even if no explicit binding is given. By @cloone8 in [#7579](https://github.com/gfx-rs/wgpu/pull/7579).
|
- When emitting GLSL, Uniform and Storage Buffer memory layouts are now emitted even if no explicit binding is given. By @cloone8 in [#7579](https://github.com/gfx-rs/wgpu/pull/7579).
|
||||||
|
- Diagnostic rendering methods (i.e., `naga::{front::wgsl::ParseError,WithSpan}::emit_error_to_string_with_path`) now accept more types for their `path` argument via a new sealed `AsDiagnosticFilePath` trait. By @atlv24, @bushrat011899, and @ErichDonGubler in [#7643](https://github.com/gfx-rs/wgpu/pull/7643).
|
||||||
- Add support for [quad operations](https://www.w3.org/TR/WGSL/#quad-builtin-functions) (requires `SUBGROUP` feature to be enabled). By @dzamkov and @valaphee in [#7683](https://github.com/gfx-rs/wgpu/pull/7683).
|
- Add support for [quad operations](https://www.w3.org/TR/WGSL/#quad-builtin-functions) (requires `SUBGROUP` feature to be enabled). By @dzamkov and @valaphee in [#7683](https://github.com/gfx-rs/wgpu/pull/7683).
|
||||||
- Add support for `atomicCompareExchangeWeak` in HLSL and GLSL backends. By @cryvosh in [#7658](https://github.com/gfx-rs/wgpu/pull/7658)
|
- Add support for `atomicCompareExchangeWeak` in HLSL and GLSL backends. By @cryvosh in [#7658](https://github.com/gfx-rs/wgpu/pull/7658)
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ default = []
|
|||||||
dot-out = []
|
dot-out = []
|
||||||
glsl-in = ["dep:pp-rs"]
|
glsl-in = ["dep:pp-rs"]
|
||||||
glsl-out = []
|
glsl-out = []
|
||||||
|
std = []
|
||||||
|
|
||||||
## Enables outputting to the Metal Shading Language (MSL).
|
## Enables outputting to the Metal Shading Language (MSL).
|
||||||
##
|
##
|
||||||
|
|||||||
79
naga/src/as_diagnostic_file_path.rs
Normal file
79
naga/src/as_diagnostic_file_path.rs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
//! [`AsDiagnosticFilePath`] and its supporting items.
|
||||||
|
|
||||||
|
use alloc::borrow::Cow;
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use alloc::string::String;
|
||||||
|
|
||||||
|
mod sealed {
|
||||||
|
pub trait Sealed {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A trait that abstracts over types accepted for conversion to the most
|
||||||
|
/// featureful path representation possible; that is:
|
||||||
|
///
|
||||||
|
/// - When `no_std` is active, this is implemented for [`String`], [`str`], and [`Cow`] (i.e.,
|
||||||
|
/// `Cow<'_, str>`).
|
||||||
|
/// - Otherwise, types that implement `AsRef<Path>` (to extract a `&Path`).
|
||||||
|
///
|
||||||
|
/// This type is used as the type bounds for various diagnostic rendering methods, i.e.,
|
||||||
|
/// [`WithSpan::emit_to_string_with_path`](crate::span::WithSpan::emit_to_string_with_path).
|
||||||
|
///
|
||||||
|
/// [`String`]: alloc::string::String
|
||||||
|
pub trait AsDiagnosticFilePath: sealed::Sealed {
|
||||||
|
fn to_string_lossy(&self) -> Cow<'_, str>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
impl<T: AsRef<Path> + ?Sized> AsDiagnosticFilePath for T {
|
||||||
|
fn to_string_lossy(&self) -> Cow<'_, str> {
|
||||||
|
self.as_ref().to_string_lossy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
impl<T: AsRef<Path> + ?Sized> sealed::Sealed for T {}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl AsDiagnosticFilePath for String {
|
||||||
|
fn to_string_lossy(&self) -> Cow<'_, str> {
|
||||||
|
Cow::Borrowed(self.as_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl sealed::Sealed for String {}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl AsDiagnosticFilePath for str {
|
||||||
|
fn to_string_lossy(&self) -> Cow<'_, str> {
|
||||||
|
Cow::Borrowed(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl sealed::Sealed for str {}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl AsDiagnosticFilePath for Cow<'_, str> {
|
||||||
|
fn to_string_lossy(&self) -> Cow<'_, str> {
|
||||||
|
use core::borrow::Borrow;
|
||||||
|
Cow::Borrowed(self.borrow())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl sealed::Sealed for Cow<'_, str> {}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl<T: AsDiagnosticFilePath + ?Sized> AsDiagnosticFilePath for &T {
|
||||||
|
fn to_string_lossy(&self) -> Cow<'_, str> {
|
||||||
|
(*self).to_string_lossy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl<T: AsDiagnosticFilePath + ?Sized> sealed::Sealed for &T {}
|
||||||
@ -106,6 +106,7 @@ extern crate std;
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
mod arena;
|
mod arena;
|
||||||
|
mod as_diagnostic_file_path;
|
||||||
pub mod back;
|
pub mod back;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
#[cfg(feature = "compact")]
|
#[cfg(feature = "compact")]
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use alloc::{
|
|||||||
};
|
};
|
||||||
use core::{error::Error, fmt, ops::Range};
|
use core::{error::Error, fmt, ops::Range};
|
||||||
|
|
||||||
use crate::{Arena, Handle, UniqueArena};
|
use crate::{as_diagnostic_file_path::AsDiagnosticFilePath, Arena, Handle, UniqueArena};
|
||||||
|
|
||||||
/// A source code span, used for error reporting.
|
/// A source code span, used for error reporting.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Default)]
|
#[derive(Clone, Copy, Debug, PartialEq, Default)]
|
||||||
@ -283,12 +283,14 @@ impl<E> WithSpan<E> {
|
|||||||
|
|
||||||
/// Emits a summary of the error to standard error stream.
|
/// Emits a summary of the error to standard error stream.
|
||||||
#[cfg(feature = "stderr")]
|
#[cfg(feature = "stderr")]
|
||||||
pub fn emit_to_stderr_with_path(&self, source: &str, path: &str)
|
pub fn emit_to_stderr_with_path<P>(&self, source: &str, path: P)
|
||||||
where
|
where
|
||||||
E: Error,
|
E: Error,
|
||||||
|
P: AsDiagnosticFilePath,
|
||||||
{
|
{
|
||||||
use codespan_reporting::{files, term};
|
use codespan_reporting::{files, term};
|
||||||
|
|
||||||
|
let path = path.to_string_lossy();
|
||||||
let files = files::SimpleFile::new(path, source);
|
let files = files::SimpleFile::new(path, source);
|
||||||
let config = term::Config::default();
|
let config = term::Config::default();
|
||||||
|
|
||||||
@ -313,12 +315,14 @@ impl<E> WithSpan<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Emits a summary of the error to a string.
|
/// Emits a summary of the error to a string.
|
||||||
pub fn emit_to_string_with_path(&self, source: &str, path: &str) -> String
|
pub fn emit_to_string_with_path<P>(&self, source: &str, path: P) -> String
|
||||||
where
|
where
|
||||||
E: Error,
|
E: Error,
|
||||||
|
P: AsDiagnosticFilePath,
|
||||||
{
|
{
|
||||||
use codespan_reporting::{files, term};
|
use codespan_reporting::{files, term};
|
||||||
|
|
||||||
|
let path = path.to_string_lossy();
|
||||||
let files = files::SimpleFile::new(path, source);
|
let files = files::SimpleFile::new(path, source);
|
||||||
let config = term::Config::default();
|
let config = term::Config::default();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user