Skip to content

Commit 7dd81ca

Browse files
feat: Added another variant of the Constraint enum
1 parent fa2913c commit 7dd81ca

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
use serde::Deserialize;
22
use std::ops::Range;
33

4+
/// Describes the values to test for a const generic parameter.
45
#[derive(Debug, PartialEq, Clone, Deserialize)]
56
pub enum Constraint {
7+
/// Test a single value.
68
Equal(i64),
9+
/// Test a range of values, e.g. `0..16`.
710
Range(Range<i64>),
11+
/// Test discrete values, e.g. `vec![1, 2, 4, 8]`.
12+
Set(Vec<i64>),
813
}
914

1015
impl Constraint {
11-
pub fn to_range(&self) -> Range<i64> {
16+
/// Iterate over the values of this constraint.
17+
pub fn iter<'a>(&'a self) -> impl Iterator<Item = i64> + 'a {
1218
match self {
13-
Constraint::Equal(eq) => *eq..*eq + 1,
14-
Constraint::Range(range) => range.clone(),
19+
Constraint::Equal(i) => std::slice::Iter::default().copied().chain(*i..*i + 1),
20+
Constraint::Range(range) => std::slice::Iter::default().copied().chain(range.clone()),
21+
Constraint::Set(items) => items.iter().copied().chain(std::ops::Range::default()),
1522
}
1623
}
1724
}

crates/intrinsic-test/src/common/gen_c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn generate_c_constraint_blocks<'a, T: IntrinsicTypeDefinition + 'a>(
4040
};
4141

4242
let body_indentation = indentation.nested();
43-
for i in current.constraint.iter().flat_map(|c| c.to_range()) {
43+
for i in current.constraint.iter().flat_map(|c| c.iter()) {
4444
let ty = current.ty.c_type();
4545

4646
writeln!(w, "{indentation}{{")?;

crates/intrinsic-test/src/common/gen_rust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub fn generate_rust_test_loop<T: IntrinsicTypeDefinition>(
255255

256256
/// Generate the specializations (unique sequences of const-generic arguments) for this intrinsic.
257257
fn generate_rust_specializations<'a>(
258-
constraints: &mut impl Iterator<Item = std::ops::Range<i64>>,
258+
constraints: &mut impl Iterator<Item = impl Iterator<Item = i64>>,
259259
) -> Vec<Vec<u8>> {
260260
let mut specializations = vec![vec![]];
261261

@@ -292,7 +292,7 @@ pub fn create_rust_test_module<T: IntrinsicTypeDefinition>(
292292
let specializations = generate_rust_specializations(
293293
&mut arguments
294294
.iter()
295-
.filter_map(|i| i.constraint.as_ref().map(|v| v.to_range())),
295+
.filter_map(|i| i.constraint.as_ref().map(|v| v.iter())),
296296
);
297297

298298
generate_rust_test_loop(w, intrinsic, indentation, &specializations, PASSES)?;

0 commit comments

Comments
 (0)