Skip to content

Commit 67ccf2f

Browse files
committed
format args decompiler: move support functions in spirv-std to mod debug_printf
Currently, every time `lib.rs` changes, there's a change in the debug printf compiletest stderr, which is causing a lot of churn.
1 parent 85f6c47 commit 67ccf2f

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

crates/spirv-std/macros/src/debug_printf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ pub fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream {
205205

206206
let assert_fn = match format_argument {
207207
FormatType::Scalar { ty } => {
208-
quote::quote! { spirv_std::debug_printf_assert_is_type::<#ty> }
208+
quote::quote! { spirv_std::debug_printf::assert_is_type::<#ty> }
209209
}
210210
FormatType::Vector { ty, width } => {
211-
quote::quote! { spirv_std::debug_printf_assert_is_vector::<#ty, _, #width> }
211+
quote::quote! { spirv_std::debug_printf::assert_is_vector::<#ty, _, #width> }
212212
}
213213
};
214214

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! support functions for debug printf
2+
3+
use crate::{Scalar, Vector};
4+
5+
#[doc(hidden)]
6+
pub fn assert_is_type<T>(ty: T) -> T {
7+
ty
8+
}
9+
10+
#[doc(hidden)]
11+
pub fn assert_is_vector<TY: Scalar, V: Vector<TY, SIZE>, const SIZE: usize>(vec: V) -> V {
12+
vec
13+
}

crates/spirv-std/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@
8888
#[macro_use]
8989
pub extern crate spirv_std_macros as macros;
9090
pub use macros::spirv;
91+
pub use macros::{debug_printf, debug_printfln};
9192

9293
pub mod arch;
9394
pub mod byte_addressable_buffer;
95+
pub mod debug_printf;
9496
pub mod float;
9597
pub mod image;
9698
pub mod indirect_command;
@@ -130,15 +132,3 @@ extern "C" fn rust_eh_personality() {}
130132
#[doc(hidden)]
131133
/// [spirv_std_types]
132134
pub fn workaround_rustdoc_ice_84738() {}
133-
134-
#[doc(hidden)]
135-
pub fn debug_printf_assert_is_type<T>(ty: T) -> T {
136-
ty
137-
}
138-
139-
#[doc(hidden)]
140-
pub fn debug_printf_assert_is_vector<TY: Scalar, V: Vector<TY, SIZE>, const SIZE: usize>(
141-
vec: V,
142-
) -> V {
143-
vec
144-
}

tests/compiletests/ui/arch/debug_printf_type_checking.stderr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ help: the return type of this call is `u32` due to the type of the argument pass
7373
LL | debug_printf!("%f", 11_u32);
7474
| ^^^^^^^^^^^^^^^^^^^^------^
7575
| |
76-
| this argument influences the return type of `debug_printf_assert_is_type`
76+
| this argument influences the return type of `assert_is_type`
7777
note: function defined here
78-
--> $SPIRV_STD_SRC/lib.rs:135:8
78+
--> $SPIRV_STD_SRC/debug_printf.rs:6:8
7979
|
80-
LL | pub fn debug_printf_assert_is_type<T>(ty: T) -> T {
81-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
LL | pub fn assert_is_type<T>(ty: T) -> T {
81+
| ^^^^^^^^^^^^^^
8282
= note: this error originates in the macro `debug_printf` (in Nightly builds, run with -Z macro-backtrace for more info)
8383
help: change the type of the numeric literal from `u32` to `f32`
8484
|
@@ -101,12 +101,12 @@ help: the return type of this call is `f32` due to the type of the argument pass
101101
LL | debug_printf!("%u", 11.0_f32);
102102
| ^^^^^^^^^^^^^^^^^^^^--------^
103103
| |
104-
| this argument influences the return type of `debug_printf_assert_is_type`
104+
| this argument influences the return type of `assert_is_type`
105105
note: function defined here
106-
--> $SPIRV_STD_SRC/lib.rs:135:8
106+
--> $SPIRV_STD_SRC/debug_printf.rs:6:8
107107
|
108-
LL | pub fn debug_printf_assert_is_type<T>(ty: T) -> T {
109-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
108+
LL | pub fn assert_is_type<T>(ty: T) -> T {
109+
| ^^^^^^^^^^^^^^
110110
= note: this error originates in the macro `debug_printf` (in Nightly builds, run with -Z macro-backtrace for more info)
111111
help: change the type of the numeric literal from `f32` to `u32`
112112
|
@@ -130,11 +130,11 @@ LL | debug_printf!("%v2f", 11.0);
130130
`IVec2` implements `Vector<i32, 2>`
131131
`IVec3` implements `Vector<i32, 3>`
132132
and 8 others
133-
note: required by a bound in `debug_printf_assert_is_vector`
134-
--> $SPIRV_STD_SRC/lib.rs:140:53
133+
note: required by a bound in `assert_is_vector`
134+
--> $SPIRV_STD_SRC/debug_printf.rs:11:40
135135
|
136-
LL | pub fn debug_printf_assert_is_vector<TY: Scalar, V: Vector<TY, SIZE>, const SIZE: usize>(
137-
| ^^^^^^^^^^^^^^^^ required by this bound in `debug_printf_assert_is_vector`
136+
LL | pub fn assert_is_vector<TY: Scalar, V: Vector<TY, SIZE>, const SIZE: usize>(vec: V) -> V {
137+
| ^^^^^^^^^^^^^^^^ required by this bound in `assert_is_vector`
138138
= note: this error originates in the macro `debug_printf` (in Nightly builds, run with -Z macro-backtrace for more info)
139139

140140
error[E0308]: mismatched types
@@ -152,12 +152,12 @@ help: the return type of this call is `Vec2` due to the type of the argument pas
152152
LL | debug_printf!("%f", Vec2::splat(33.3));
153153
| ^^^^^^^^^^^^^^^^^^^^-----------------^
154154
| |
155-
| this argument influences the return type of `debug_printf_assert_is_type`
155+
| this argument influences the return type of `assert_is_type`
156156
note: function defined here
157-
--> $SPIRV_STD_SRC/lib.rs:135:8
157+
--> $SPIRV_STD_SRC/debug_printf.rs:6:8
158158
|
159-
LL | pub fn debug_printf_assert_is_type<T>(ty: T) -> T {
160-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
159+
LL | pub fn assert_is_type<T>(ty: T) -> T {
160+
| ^^^^^^^^^^^^^^
161161
= note: this error originates in the macro `debug_printf` (in Nightly builds, run with -Z macro-backtrace for more info)
162162

163163
error: aborting due to 14 previous errors

0 commit comments

Comments
 (0)