From cd2fe631032c0e5d568f8fef6d9d93f6fe7db19a Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 8 Feb 2024 14:31:08 +0000 Subject: [PATCH 1/3] feat: perform constraints on uncasted values if they are the same type --- .../src/ssa/ir/instruction/constrain.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs index 0ae0f8f2892..fa8a79b148c 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs @@ -120,6 +120,20 @@ pub(super) fn decompose_constrain( } } + + (Value::Instruction { instruction: instruction_lhs, .. }, Value::Instruction { instruction: instruction_rhs, .. }) => + { + match (&dfg[*instruction_lhs], &dfg[*instruction_rhs]) { + // Here's we're casting two values just to enforce an equality on them. + // + // This is equivalent to enforcing equality on the original values. + (Instruction::Cast(original_lhs, _), Instruction::Cast(original_rhs, _)) if dfg.type_of_value(*original_lhs) == dfg.type_of_value(*original_rhs) => { + vec![Instruction::Constrain(*original_lhs, *original_rhs, msg.clone())] + } + + _ => vec![Instruction::Constrain(lhs, rhs, msg.clone())], + } + } _ => vec![Instruction::Constrain(lhs, rhs, msg.clone())], } } From 7bb713b1ae5dca423f70b38fcd4c1080fdfb1224 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 8 Feb 2024 14:35:23 +0000 Subject: [PATCH 2/3] chore: formatting --- .../src/ssa/ir/instruction/constrain.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs index fa8a79b148c..3f273d67ea0 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs @@ -120,14 +120,17 @@ pub(super) fn decompose_constrain( } } - - (Value::Instruction { instruction: instruction_lhs, .. }, Value::Instruction { instruction: instruction_rhs, .. }) => - { + ( + Value::Instruction { instruction: instruction_lhs, .. }, + Value::Instruction { instruction: instruction_rhs, .. }, + ) => { match (&dfg[*instruction_lhs], &dfg[*instruction_rhs]) { // Here's we're casting two values just to enforce an equality on them. // // This is equivalent to enforcing equality on the original values. - (Instruction::Cast(original_lhs, _), Instruction::Cast(original_rhs, _)) if dfg.type_of_value(*original_lhs) == dfg.type_of_value(*original_rhs) => { + (Instruction::Cast(original_lhs, _), Instruction::Cast(original_rhs, _)) + if dfg.type_of_value(*original_lhs) == dfg.type_of_value(*original_rhs) => + { vec![Instruction::Constrain(*original_lhs, *original_rhs, msg.clone())] } From 5d442d209268122f61f03948e27b638359ced7bc Mon Sep 17 00:00:00 2001 From: jfecher Date: Thu, 8 Feb 2024 09:00:17 -0600 Subject: [PATCH 3/3] Update compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs --- compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs index 3f273d67ea0..b4198e2cfec 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs @@ -125,7 +125,7 @@ pub(super) fn decompose_constrain( Value::Instruction { instruction: instruction_rhs, .. }, ) => { match (&dfg[*instruction_lhs], &dfg[*instruction_rhs]) { - // Here's we're casting two values just to enforce an equality on them. + // Casting two values just to enforce an equality on them. // // This is equivalent to enforcing equality on the original values. (Instruction::Cast(original_lhs, _), Instruction::Cast(original_rhs, _))