File tree 3 files changed +29
-14
lines changed
3 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ mod types;
6
6
7
7
pub use diagnostics:: DisplayFilterableTriggeringRule ;
8
8
pub use to_wgsl:: { address_space_str, ToWgsl , TryToWgsl } ;
9
- pub use types:: TypeContext ;
9
+ pub use types:: { write_scalar_for_diagnostics , TypeContext } ;
Original file line number Diff line number Diff line change @@ -299,3 +299,30 @@ impl From<core::fmt::Error> for WriteTypeError {
299
299
Self :: Format ( err)
300
300
}
301
301
}
302
+
303
+ /// Write `scalar` in WGSL as appropriate for diagnostic messages.
304
+ ///
305
+ /// If `scalar` can be expressed in WGSL, write its WGSL form to `out`.
306
+ ///
307
+ /// If `scalar` is an abstract type, write something suggestive and
308
+ /// human-readable to `out`.
309
+ ///
310
+ /// Otherwise, write something human-readable that includes the
311
+ /// [`Debug`] representation of `scalar`.
312
+ ///
313
+ /// [`Debug`]: core::fmt::Debug
314
+ pub fn write_scalar_for_diagnostics < W : Write > ( scalar : Scalar , out : & mut W ) -> core:: fmt:: Result {
315
+ match scalar. kind {
316
+ crate :: ScalarKind :: Sint
317
+ | crate :: ScalarKind :: Uint
318
+ | crate :: ScalarKind :: Float
319
+ | crate :: ScalarKind :: Bool => write ! ( out, "{{non-WGSL Naga scalar {scalar:?}}}" ) ,
320
+
321
+ // The abstract types are kind of an odd pseudo-WGSL category:
322
+ // they are definitely part of the spec, but they are not expressible
323
+ // in WGSL itself. So we want to call them out by name in error messages,
324
+ // but the WGSL backend should never generate these.
325
+ crate :: ScalarKind :: AbstractInt => out. write_str ( "{AbstractInt}" ) ,
326
+ crate :: ScalarKind :: AbstractFloat => out. write_str ( "{AbstractFloat}" ) ,
327
+ }
328
+ }
Original file line number Diff line number Diff line change @@ -86,19 +86,7 @@ impl<W: fmt::Write> TypeContext<W> for GlobalCtx<'_> {
86
86
}
87
87
88
88
fn write_non_wgsl_scalar ( & self , scalar : Scalar , out : & mut W ) -> fmt:: Result {
89
- match scalar. kind {
90
- crate :: ScalarKind :: Sint
91
- | crate :: ScalarKind :: Uint
92
- | crate :: ScalarKind :: Float
93
- | crate :: ScalarKind :: Bool => write ! ( out, "{{non-WGSL Naga scalar {scalar:?}}}" ) ,
94
-
95
- // The abstract types are kind of an odd pseudo-WGSL category:
96
- // they are definitely part of the spec, but they are not expressible
97
- // in WGSL itself. So we want to call them out by name in error messages,
98
- // but the WGSL backend should never generate these.
99
- crate :: ScalarKind :: AbstractInt => out. write_str ( "{AbstractInt}" ) ,
100
- crate :: ScalarKind :: AbstractFloat => out. write_str ( "{AbstractFloat}" ) ,
101
- }
89
+ crate :: common:: wgsl:: write_scalar_for_diagnostics ( scalar, out)
102
90
}
103
91
}
104
92
You can’t perform that action at this time.
0 commit comments