@@ -25,12 +25,20 @@ pub trait OverloadSet: Clone + std::fmt::Debug {
25
25
fn is_empty ( & self ) -> bool ;
26
26
27
27
/// Return the smallest number of subexpressions in any type rule
28
- /// in the set. Return `None` if `self` is empty.
29
- fn min_subexpressions ( & self ) -> Option < usize > ;
28
+ /// in the set.
29
+ ///
30
+ /// # Panics
31
+ ///
32
+ /// Panics if `self` is empty.
33
+ fn min_subexpressions ( & self ) -> usize ;
30
34
31
35
/// Return the largest number of subexpressions in any type rule
32
- /// in the set. Return `None` if `self` is empty.
33
- fn max_subexpressions ( & self ) -> Option < usize > ;
36
+ /// in the set.
37
+ ///
38
+ /// # Panics
39
+ ///
40
+ /// Panics if `self` is empty.
41
+ fn max_subexpressions ( & self ) -> usize ;
34
42
35
43
/// Limit `self` to the overloads that can accept a given
36
44
/// subexpression.
@@ -78,12 +86,15 @@ pub trait OverloadSet: Clone + std::fmt::Debug {
78
86
/// [concretize]: https://gpuweb.github.io/gpuweb/wgsl/#concretization
79
87
fn concrete_only ( self , types : & crate :: UniqueArena < crate :: Type > ) -> Self ;
80
88
81
- /// Return the most preferred candidate, or `None` if `self` is empty .
89
+ /// Return the most preferred candidate.
82
90
///
83
91
/// Rank the candidates in `self` as described in WGSL's [overload
84
92
/// resolution algorithm][ora], and return a singleton set containing the
85
93
/// most preferred candidate.
86
94
///
95
+ /// If there is no most preferred candidate, return `None`,
96
+ /// indicating that the expression is ambiguous.
97
+ ///
87
98
/// As it's described in the spec, choosing the most preferred candidate
88
99
/// depends on the ranks of the conversions being applied to each argument,
89
100
/// so it's impossible to determine the most preferred candidate from the
@@ -93,6 +104,10 @@ pub trait OverloadSet: Clone + std::fmt::Debug {
93
104
/// leaf scalar type for all its subexpressions, then the most abstract
94
105
/// overload must be the most preferred candidate.
95
106
///
107
+ /// # Panics
108
+ ///
109
+ /// Panics if `self` is empty.
110
+ ///
96
111
/// [ora]: https://gpuweb.github.io/gpuweb/wgsl/#overload-resolution-section
97
112
fn most_preferred ( & self ) -> Option < Self :: Rule > ;
98
113
@@ -139,13 +154,13 @@ impl OverloadSet for AnyOverloadSet {
139
154
}
140
155
}
141
156
142
- fn min_subexpressions ( & self ) -> Option < usize > {
157
+ fn min_subexpressions ( & self ) -> usize {
143
158
match * self {
144
159
AnyOverloadSet :: List ( ref list) => list. min_subexpressions ( ) ,
145
160
}
146
161
}
147
162
148
- fn max_subexpressions ( & self ) -> Option < usize > {
163
+ fn max_subexpressions ( & self ) -> usize {
149
164
match * self {
150
165
AnyOverloadSet :: List ( ref list) => list. max_subexpressions ( ) ,
151
166
}
@@ -165,7 +180,7 @@ impl OverloadSet for AnyOverloadSet {
165
180
166
181
fn most_preferred ( & self ) -> Option < AnyRule > {
167
182
match * self {
168
- AnyOverloadSet :: List ( ref list) => list. most_preferred ( ) . map ( AnyRule :: List ) ,
183
+ AnyOverloadSet :: List ( ref list) => list. most_preferred ( ) . map ( AnyRule :: List )
169
184
}
170
185
}
171
186
@@ -216,6 +231,10 @@ impl crate::MathFunction {
216
231
const VEC3F : Ti = Ti :: Vector { size : Vs :: Tri , scalar : Sc :: F32 } ;
217
232
const VEC4F : Ti = Ti :: Vector { size : Vs :: Quad , scalar : Sc :: F32 } ;
218
233
234
+ const VEC2AF : Ti = Ti :: Vector { size : Vs :: Bi , scalar : Sc :: ABSTRACT_FLOAT } ;
235
+ const VEC3AF : Ti = Ti :: Vector { size : Vs :: Tri , scalar : Sc :: ABSTRACT_FLOAT } ;
236
+ const VEC4AF : Ti = Ti :: Vector { size : Vs :: Quad , scalar : Sc :: ABSTRACT_FLOAT } ;
237
+
219
238
const VEC2I : Ti = Ti :: Vector { size : Vs :: Bi , scalar : Sc :: I32 } ;
220
239
const VEC3I : Ti = Ti :: Vector { size : Vs :: Tri , scalar : Sc :: I32 } ;
221
240
const VEC4I : Ti = Ti :: Vector { size : Vs :: Quad , scalar : Sc :: I32 } ;
@@ -266,9 +285,29 @@ impl crate::MathFunction {
266
285
} ,
267
286
] ;
268
287
288
+ static POW : & [ list:: Rule ] = & [
289
+ list:: Rule {
290
+ subexpressions : & [ Ti :: Scalar ( Sc :: F32 ) , Ti :: Scalar ( Sc :: F32 ) ] ,
291
+ conclusion : Ti :: Scalar ( Sc :: F32 ) ,
292
+ } ,
293
+ list:: Rule {
294
+ subexpressions : & [ Ti :: Scalar ( Sc :: ABSTRACT_FLOAT ) , Ti :: Scalar ( Sc :: ABSTRACT_FLOAT ) ] ,
295
+ conclusion : Ti :: Scalar ( Sc :: ABSTRACT_FLOAT ) ,
296
+ } ,
297
+ list:: Rule {
298
+ subexpressions : & [ VEC2F , VEC2F ] ,
299
+ conclusion : VEC2F ,
300
+ } ,
301
+ list:: Rule {
302
+ subexpressions : & [ VEC2AF , VEC2AF ] ,
303
+ conclusion : VEC2AF ,
304
+ } ,
305
+ ] ;
306
+
269
307
match self {
270
308
Mf :: Sin => AnyOverloadSet :: List ( list:: List :: from_rules ( COMPONENT_WISE_FLOAT ) ) ,
271
309
Mf :: Dot => AnyOverloadSet :: List ( list:: List :: from_rules ( DOT_PRODUCT ) ) ,
310
+ Mf :: Pow => AnyOverloadSet :: List ( list:: List :: from_rules ( POW ) ) ,
272
311
_ => todo ! ( ) ,
273
312
}
274
313
}
0 commit comments