Skip to content

Commit c0a6879

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

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
@@ -5,13 +5,15 @@ use std::ops::Range;
55
pub enum Constraint {
66
Equal(i64),
77
Range(Range<i64>),
8+
Set(Vec<i64>),
89
}
910

1011
impl Constraint {
11-
pub fn to_range(&self) -> Range<i64> {
12+
pub fn to_vector(&self) -> Vec<i64> {
1213
match self {
13-
Constraint::Equal(eq) => *eq..*eq + 1,
14-
Constraint::Range(range) => range.clone(),
14+
Constraint::Equal(eq) => vec![*eq],
15+
Constraint::Range(range) => range.clone().collect::<Vec<i64>>(),
16+
Constraint::Set(values) => values.clone(),
1517
}
1618
}
1719
}

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)