Skip to content

Commit 177162b

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 e8f0e44 commit 177162b

File tree

4 files changed

+35
-38
lines changed

4 files changed

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

crates/spirv-std/src/lib.rs

Lines changed: 2 additions & 16 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;
@@ -129,19 +131,3 @@ extern "C" fn rust_eh_personality() {}
129131
#[doc(hidden)]
130132
/// [spirv_std_types]
131133
pub fn workaround_rustdoc_ice_84738() {}
132-
133-
#[doc(hidden)]
134-
pub fn debug_printf_assert_is_type<T>(ty: T) -> T {
135-
ty
136-
}
137-
138-
#[doc(hidden)]
139-
pub fn debug_printf_assert_is_vector<
140-
TY: crate::scalar::Scalar,
141-
V: crate::vector::Vector<TY, SIZE>,
142-
const SIZE: usize,
143-
>(
144-
vec: V,
145-
) -> V {
146-
vec
147-
}

tests/compiletests/ui/arch/debug_printf_type_checking.stderr

Lines changed: 17 additions & 20 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:134:8
78+
--> $SPIRV_STD_SRC/debug_printf.rs:7: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:134:8
106+
--> $SPIRV_STD_SRC/debug_printf.rs:7: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,14 +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:141:8
135-
|
136-
LL | pub fn debug_printf_assert_is_vector<
137-
| ----------------------------- required by a bound in this function
138-
LL | TY: crate::scalar::Scalar,
139-
LL | V: crate::vector::Vector<TY, SIZE>,
140-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `debug_printf_assert_is_vector`
133+
note: required by a bound in `assert_is_vector`
134+
--> $SPIRV_STD_SRC/debug_printf.rs:12:40
135+
|
136+
LL | pub fn assert_is_vector<TY: Scalar, V: Vector<TY, SIZE>, const SIZE: usize>(
137+
| ^^^^^^^^^^^^^^^^ required by this bound in `assert_is_vector`
141138
= note: this error originates in the macro `debug_printf` (in Nightly builds, run with -Z macro-backtrace for more info)
142139

143140
error[E0308]: mismatched types
@@ -155,12 +152,12 @@ help: the return type of this call is `Vec2` due to the type of the argument pas
155152
LL | debug_printf!("%f", Vec2::splat(33.3));
156153
| ^^^^^^^^^^^^^^^^^^^^-----------------^
157154
| |
158-
| this argument influences the return type of `debug_printf_assert_is_type`
155+
| this argument influences the return type of `assert_is_type`
159156
note: function defined here
160-
--> $SPIRV_STD_SRC/lib.rs:134:8
157+
--> $SPIRV_STD_SRC/debug_printf.rs:7:8
161158
|
162-
LL | pub fn debug_printf_assert_is_type<T>(ty: T) -> T {
163-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
159+
LL | pub fn assert_is_type<T>(ty: T) -> T {
160+
| ^^^^^^^^^^^^^^
164161
= note: this error originates in the macro `debug_printf` (in Nightly builds, run with -Z macro-backtrace for more info)
165162

166163
error: aborting due to 14 previous errors

0 commit comments

Comments
 (0)