Skip to content

Commit 874b750

Browse files
committed
[naga] Move some helper functions to type_methods
1 parent b599252 commit 874b750

File tree

5 files changed

+43
-37
lines changed

5 files changed

+43
-37
lines changed

naga/src/common/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,5 @@ pub mod wgsl;
88
pub use diagnostic_debug::{DiagnosticDebug, ForDebug, ForDebugWithTypes};
99
pub use diagnostic_display::DiagnosticDisplay;
1010

11-
/// Helper function that returns the string corresponding to the [`VectorSize`](crate::VectorSize)
12-
pub const fn vector_size_str(size: crate::VectorSize) -> &'static str {
13-
match size {
14-
crate::VectorSize::Bi => "2",
15-
crate::VectorSize::Tri => "3",
16-
crate::VectorSize::Quad => "4",
17-
}
18-
}
11+
// Re-exported here for backwards compatibility
12+
pub use super::proc::vector_size_str;

naga/src/proc/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ pub use namer::{EntryPointIndex, ExternalTextureNameKey, NameKey, Namer};
2424
pub use overloads::{Conclusion, MissingSpecialType, OverloadSet, Rule};
2525
pub use terminator::ensure_block_returns;
2626
use thiserror::Error;
27-
pub use type_methods::min_max_float_representable_by;
27+
pub use type_methods::{
28+
concrete_int_scalars, min_max_float_representable_by, vector_size_str, vector_sizes,
29+
};
2830
pub use typifier::{compare_types, ResolveContext, ResolveError, TypeResolution};
2931

3032
use crate::non_max_u32::NonMaxU32;

naga/src/proc/overloads/mathfunction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use crate::proc::overloads::any_overload_set::AnyOverloadSet;
44
use crate::proc::overloads::list::List;
55
use crate::proc::overloads::regular::regular;
66
use crate::proc::overloads::utils::{
7-
concrete_int_scalars, float_scalars, float_scalars_unimplemented_abstract, list, pairs, rule,
8-
scalar_or_vecn, triples, vector_sizes,
7+
float_scalars, float_scalars_unimplemented_abstract, list, pairs, rule, scalar_or_vecn, triples,
98
};
109
use crate::proc::overloads::OverloadSet;
10+
use crate::proc::type_methods::{concrete_int_scalars, vector_sizes};
1111

1212
use crate::ir;
1313

naga/src/proc/overloads/utils.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@ use crate::proc::TypeResolution;
99

1010
use alloc::vec::Vec;
1111

12-
/// Produce all vector sizes.
13-
pub fn vector_sizes() -> impl Iterator<Item = ir::VectorSize> + Clone {
14-
static SIZES: [ir::VectorSize; 3] = [
15-
ir::VectorSize::Bi,
16-
ir::VectorSize::Tri,
17-
ir::VectorSize::Quad,
18-
];
19-
20-
SIZES.iter().cloned()
21-
}
22-
2312
/// Produce all the floating-point [`ir::Scalar`]s.
2413
///
2514
/// Note that `F32` must appear before other sizes; this is how we
@@ -40,20 +29,6 @@ pub fn float_scalars_unimplemented_abstract() -> impl Iterator<Item = ir::Scalar
4029
[ir::Scalar::F32, ir::Scalar::F16, ir::Scalar::F64].into_iter()
4130
}
4231

43-
/// Produce all concrete integer [`ir::Scalar`]s.
44-
///
45-
/// Note that `I32` and `U32` must come first; this is how we
46-
/// represent conversion rank.
47-
pub fn concrete_int_scalars() -> impl Iterator<Item = ir::Scalar> {
48-
[
49-
ir::Scalar::I32,
50-
ir::Scalar::U32,
51-
ir::Scalar::I64,
52-
ir::Scalar::U64,
53-
]
54-
.into_iter()
55-
}
56-
5732
/// Produce the scalar and vector [`ir::TypeInner`]s that have `s` as
5833
/// their scalar.
5934
pub fn scalar_or_vecn(scalar: ir::Scalar) -> impl Iterator<Item = ir::TypeInner> {

naga/src/proc/type_methods.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
//! Methods on [`TypeInner`], [`Scalar`], and [`ScalarKind`].
1+
//! Methods on or related to [`TypeInner`], [`Scalar`], [`ScalarKind`], and [`VectorSize`].
22
//!
33
//! [`TypeInner`]: crate::TypeInner
44
//! [`Scalar`]: crate::Scalar
55
//! [`ScalarKind`]: crate::ScalarKind
6+
//! [`VectorSize`]: crate::VectorSize
67
78
use crate::{ir, valid::MAX_TYPE_SIZE};
89

@@ -97,6 +98,31 @@ impl crate::Scalar {
9798
}
9899
}
99100

101+
/// Produce all concrete integer [`ir::Scalar`]s.
102+
///
103+
/// Note that `I32` and `U32` must come first; this represents conversion rank
104+
/// in overload resolution.
105+
pub fn concrete_int_scalars() -> impl Iterator<Item = ir::Scalar> {
106+
[
107+
ir::Scalar::I32,
108+
ir::Scalar::U32,
109+
ir::Scalar::I64,
110+
ir::Scalar::U64,
111+
]
112+
.into_iter()
113+
}
114+
115+
/// Produce all vector sizes.
116+
pub fn vector_sizes() -> impl Iterator<Item = ir::VectorSize> + Clone {
117+
static SIZES: [ir::VectorSize; 3] = [
118+
ir::VectorSize::Bi,
119+
ir::VectorSize::Tri,
120+
ir::VectorSize::Quad,
121+
];
122+
123+
SIZES.iter().cloned()
124+
}
125+
100126
const POINTER_SPAN: u32 = 4;
101127

102128
impl crate::TypeInner {
@@ -612,3 +638,12 @@ pub fn min_max_float_representable_by(
612638
_ => unreachable!(),
613639
}
614640
}
641+
642+
/// Helper function that returns the string corresponding to the [`VectorSize`](crate::VectorSize)
643+
pub const fn vector_size_str(size: crate::VectorSize) -> &'static str {
644+
match size {
645+
crate::VectorSize::Bi => "2",
646+
crate::VectorSize::Tri => "3",
647+
crate::VectorSize::Quad => "4",
648+
}
649+
}

0 commit comments

Comments
 (0)