From 65900b36d3d11afeab59b710af7d23d373e0629a Mon Sep 17 00:00:00 2001 From: Aaron Councilman <aaronjc4@illinois.edu> Date: Wed, 20 Nov 2024 21:14:39 -0600 Subject: [PATCH] Fix type-checking of select to handle non-concrete condition type --- hercules_ir/src/typecheck.rs | 17 +++++------------ hercules_samples/products.hir | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 hercules_samples/products.hir diff --git a/hercules_ir/src/typecheck.rs b/hercules_ir/src/typecheck.rs index 4475dbba..c3ae21e6 100644 --- a/hercules_ir/src/typecheck.rs +++ b/hercules_ir/src/typecheck.rs @@ -688,26 +688,19 @@ fn typeflow( return Error(String::from("Ternary node must have exactly three inputs.")); } - if let Concrete(id) = inputs[0] { - match op { - TernaryOperator::Select => { + match op { + TernaryOperator::Select => { + if let Concrete(id) = inputs[0] { if !types[id.idx()].is_bool() { return Error(String::from( "Select ternary node input cannot have non-bool condition input.", )); } - - let data_ty = TypeSemilattice::meet(inputs[1], inputs[2]); - if let Concrete(data_id) = data_ty { - return Concrete(data_id); - } else { - return data_ty; - } } + + TypeSemilattice::meet(inputs[1], inputs[2]) } } - - Error(String::from("Unhandled ternary types.")) } Node::Call { control: _, diff --git a/hercules_samples/products.hir b/hercules_samples/products.hir new file mode 100644 index 00000000..9d191beb --- /dev/null +++ b/hercules_samples/products.hir @@ -0,0 +1,23 @@ +fn test(x : prod(i32, f32), b: bool) -> prod(i32, f32) + zero = constant(u64, 0) + one = constant(i32, 1) + two = constant(u64, 2) + three = constant(f32, 3.0) + + f_ctrl = fork(start, 10) + idx = thread_id(f_ctrl, 0) + + mod2 = rem(idx, two) + is_even = eq(mod2, zero) + field0 = read(res, field(0)) + field1 = read(res, field(1)) + add = add(field0, one) + mul = mul(field1, three) + upd0 = write(res, add, field(0)) + upd1 = write(res, mul, field(1)) + select = select(is_even, upd0, upd1) + + j_ctrl = join(f_ctrl) + res = reduce(j_ctrl, x, select) + + r = return(j_ctrl, res) -- GitLab