Skip to content

Commit

Permalink
Fix possible type error
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Dec 12, 2024
1 parent 68ff7bd commit 660658a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 4 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ impl Binary {
if rhs_is_zero {
return SimplifyResult::SimplifiedTo(self.lhs);
}
if operand_type == NumericType::bool() && (lhs_is_one || rhs_is_one) {
let one = dfg.make_constant(FieldElement::one(), operand_type);
return SimplifyResult::SimplifiedTo(one);
}
if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) {
return SimplifyResult::SimplifiedTo(self.lhs);
}
Expand Down
19 changes: 8 additions & 11 deletions compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,14 @@ fn simplify_slice_push_back(
}

fn simplify_slice_pop_back(
element_type: Type,
slice_type: Type,
arguments: &[ValueId],
dfg: &mut DataFlowGraph,
block: BasicBlockId,
call_stack: CallStack,
) -> SimplifyResult {
let element_types = match element_type.clone() {
Type::Slice(element_types) | Type::Array(element_types, _) => element_types,
_ => {
unreachable!("ICE: Expected slice or array, but got {element_type}");
}
};

let element_count = element_type.element_size();
let element_types = slice_type.element_types();
let element_count = element_types.len();
let mut results = VecDeque::with_capacity(element_count + 1);

let new_slice_length = update_slice_length(arguments[0], dfg, BinaryOp::Sub, block);
Expand All @@ -507,14 +501,17 @@ fn simplify_slice_pop_back(
flattened_len = update_slice_length(flattened_len, dfg, BinaryOp::Sub, block);

// We must pop multiple elements in the case of a slice of tuples
for _ in 0..element_count {
// Iterating through element types in reverse here since we're popping from the end
for element_type in element_types.iter().rev() {
let get_last_elem_instr =
Instruction::ArrayGet { array: arguments[1], index: flattened_len };

let element_type = Some(vec![element_type.clone()]);
let get_last_elem = dfg
.insert_instruction_and_results(
get_last_elem_instr,
block,
Some(element_types.to_vec()),
element_type,
call_stack.clone(),
)
.first();
Expand Down

0 comments on commit 660658a

Please sign in to comment.