Skip to content

Commit dcad42e

Browse files
feat: added a new variant of Constraint struct, to enable support for
discrete constant values
1 parent 5269582 commit dcad42e

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ pub enum Constraint {
88
Equal(i64),
99
/// Test a range of values, e.g. `0..16`.
1010
Range(Range<i64>),
11+
Set(Vec<i64>),
1112
}
1213

1314
impl Constraint {
14-
pub fn to_range(&self) -> Range<i64> {
15+
pub fn to_vector(&self) -> Vec<i64> {
1516
match self {
16-
Constraint::Equal(eq) => *eq..*eq + 1,
17-
Constraint::Range(range) => range.clone(),
17+
Constraint::Equal(eq) => vec![*eq],
18+
Constraint::Range(range) => range.clone().collect::<Vec<i64>>(),
19+
Constraint::Set(values) => values.clone(),
1820
}
1921
}
2022
}

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.to_vector()) {
4444
let ty = current.ty.c_type();
4545

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

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ pub fn generate_rust_constraint_blocks<T: IntrinsicTypeDefinition>(
176176
name: String,
177177
) -> String {
178178
if let Some((current, constraints)) = constraints.split_last() {
179-
let range = current
180-
.constraint
181-
.iter()
182-
.map(|c| c.to_range())
183-
.flat_map(|r| r.into_iter());
179+
let range = current.constraint.iter().flat_map(|c| c.to_vector());
184180

185181
let body_indentation = indentation.nested();
186182
range

0 commit comments

Comments
 (0)