Skip to content

Commit

Permalink
clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
vezenovm committed Jan 23, 2024
1 parent f2fca62 commit 2bc9965
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 61 deletions.
3 changes: 1 addition & 2 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport};
pub(crate) use acir_ir::generated_acir::GeneratedAcir;

use acvm::acir::native_types::Witness;
use acvm::acir::BlackBoxFunc;
use acvm::{
acir::{circuit::opcodes::BlockId, native_types::Expression},
FieldElement,
Expand Down Expand Up @@ -405,7 +404,7 @@ impl Context {
) -> Result<Vec<SsaReport>, RuntimeError> {
let instruction = &dfg[instruction_id];
self.acir_context.set_call_stack(dfg.get_call_stack(instruction_id));
let mut warnings = Vec::new();
let warnings = Vec::new();
match instruction {
Instruction::Binary(binary) => {
let result_acir_var = self.convert_ssa_binary(binary, dfg)?;
Expand Down
10 changes: 0 additions & 10 deletions compiler/noirc_evaluator/src/ssa/ir/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,6 @@ impl DataFlowGraph {
let mut last_id = None;

for instruction in instructions {
// Constrain instructions contain a reference to another instruction and thus need to be handled appropriately
// as to have a call stack associated with it. We want the assert message call to have the same call stack as the
// constrain for which we are resolving an assert message.
match &instruction {
Instruction::Constrain(_, _, assert_msg_instruction) => {
assert_msg_instruction
.map(|id| self.locations.insert(id, call_stack.clone()));
}
_ => {}
}
let id = self.make_instruction(instruction, ctrl_typevars.clone());
self.blocks[block].insert_instruction(id);
self.locations.insert(id, call_stack.clone());
Expand Down
8 changes: 4 additions & 4 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl Instruction {
| Instruction::Load { address: value } => {
f(*value);
}
Instruction::Constrain(lhs, rhs, assert_message) => {
Instruction::Constrain(lhs, rhs, _) => {
f(*lhs);
f(*rhs);
}
Expand Down Expand Up @@ -437,7 +437,7 @@ impl Instruction {
}
}
Instruction::Constrain(lhs, rhs, msg) => {
let constraints = decompose_constrain(*lhs, *rhs, msg.clone(), dfg);
let constraints = decompose_constrain(*lhs, *rhs, *msg, dfg);
if constraints.is_empty() {
Remove
} else {
Expand Down Expand Up @@ -659,7 +659,7 @@ fn decompose_constrain(
let one = dfg.make_constant(one, Type::bool());

[
decompose_constrain(lhs, one, msg.clone(), dfg),
decompose_constrain(lhs, one, msg, dfg),
decompose_constrain(rhs, one, msg, dfg),
]
.concat()
Expand Down Expand Up @@ -687,7 +687,7 @@ fn decompose_constrain(
let zero = dfg.make_constant(zero, dfg.type_of_value(lhs));

[
decompose_constrain(lhs, zero, msg.clone(), dfg),
decompose_constrain(lhs, zero, msg, dfg),
decompose_constrain(rhs, zero, msg, dfg),
]
.concat()
Expand Down
8 changes: 1 addition & 7 deletions compiler/noirc_evaluator/src/ssa/opt/bubble_up_constrains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ impl Ssa {
HashMap::with_capacity(instructions.len());

let dfg = &function.dfg;
let mut assert_message_instructions = Vec::new();
for instruction in instructions {
let (lhs, rhs) = match dfg[instruction] {
Instruction::Constrain(lhs, rhs, assert_message_instr) => {
assert_message_instr.map(|instr| {
assert_message_instructions.push(instr);
});
(lhs, rhs)
}
Instruction::Constrain(lhs, rhs, _) => (lhs, rhs),
_ => {
filtered_instructions.push(instruction);
continue;
Expand Down
3 changes: 2 additions & 1 deletion compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ impl<'a> FunctionContext<'a> {
let rhs_as_unsigned = self.insert_safe_cast(rhs, Type::unsigned(bit_size), location);
let lhs_sign = self.builder.insert_binary(lhs_as_unsigned, BinaryOp::Lt, half_width);
let mut rhs_sign = self.builder.insert_binary(rhs_as_unsigned, BinaryOp::Lt, half_width);
let message = if is_sub {
// TODO: bring back assert_messages from codegen
let _message = if is_sub {
// lhs - rhs = lhs + (-rhs)
rhs_sign = self.builder.insert_not(rhs_sign);
"attempt to subtract with overflow".to_string()
Expand Down
5 changes: 1 addition & 4 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use crate::{
errors::RuntimeError,
ssa::{
function_builder::data_bus::DataBusBuilder,
ir::{
instruction::{Instruction, Intrinsic},
types::NumericType,
},
ir::{instruction::Intrinsic, types::NumericType},
},
};

Expand Down
4 changes: 1 addition & 3 deletions noirc_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// use noirc_frontend::macros_api::{parse_program, SortedModule, CrateId

use noirc_frontend::macros_api::parse_program;
use noirc_frontend::macros_api::HirContext;
use noirc_frontend::macros_api::SortedModule;
use noirc_frontend::macros_api::{CrateId, FileId};
use noirc_frontend::macros_api::{
Expression, ExpressionKind, HirContext, Ident, Path, PathKind, Span, Statement, StatementKind,
};
use noirc_frontend::macros_api::{MacroError, MacroProcessor};

pub struct AssertMessageMacro;
Expand Down
59 changes: 29 additions & 30 deletions tooling/nargo/src/ops/execute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use acvm::acir::circuit::OpcodeLocation;
use acvm::pwg::{ACVMForeignCallResult, ACVMStatus, ErrorLocation, OpcodeResolutionError, ACVM};
use acvm::BlackBoxFunctionSolver;
use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap};
Expand Down Expand Up @@ -49,11 +48,10 @@ pub fn execute_circuit<B: BlackBoxFunctionSolver, F: ForeignCallExecutor>(
}
ACVMStatus::RequiresForeignCall(foreign_call) => {
let foreign_call_result = foreign_call_executor.execute(&foreign_call)?;
match &foreign_call_result {
ACVMForeignCallResult::ResolvedAssertMessage(assert_message) => {
current_assertion_message = Some(assert_message.to_owned());
}
_ => {}
if let ACVMForeignCallResult::ResolvedAssertMessage(assert_message) =
&foreign_call_result
{
current_assertion_message = Some(assert_message.to_owned());
}
acvm.resolve_pending_foreign_call(foreign_call_result);
}
Expand All @@ -63,29 +61,30 @@ pub fn execute_circuit<B: BlackBoxFunctionSolver, F: ForeignCallExecutor>(
Ok(acvm.finalize())
}

fn resolve_call_stack(error: &OpcodeResolutionError) -> Option<Vec<OpcodeLocation>> {
match error {
OpcodeResolutionError::UnsatisfiedConstrain {
opcode_location: ErrorLocation::Resolved(opcode_location),
} => Some(vec![*opcode_location]),
OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => Some(call_stack.clone()),
_ => None,
}
}
// TODO: bring these back for assert message made during compilation codegen
// fn resolve_call_stack(error: &OpcodeResolutionError) -> Option<Vec<OpcodeLocation>> {
// match error {
// OpcodeResolutionError::UnsatisfiedConstrain {
// opcode_location: ErrorLocation::Resolved(opcode_location),
// } => Some(vec![*opcode_location]),
// OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => Some(call_stack.clone()),
// _ => None,
// }
// }

fn resolve_comptime_assert_message(error: &OpcodeResolutionError, circuit: &Circuit) -> NargoError {
let call_stack = resolve_call_stack(error);
// fn resolve_comptime_assert_message(error: &OpcodeResolutionError, circuit: &Circuit) -> NargoError {
// let call_stack = resolve_call_stack(error);

NargoError::ExecutionError(match call_stack {
Some(call_stack) => {
if let Some(assert_message) = circuit
.get_assert_message(*call_stack.last().expect("Call stacks should not be empty"))
{
ExecutionError::AssertionFailed(assert_message.to_owned(), call_stack)
} else {
ExecutionError::SolvingError(error.clone())
}
}
None => ExecutionError::SolvingError(error.clone()),
})
}
// NargoError::ExecutionError(match call_stack {
// Some(call_stack) => {
// if let Some(assert_message) = circuit
// .get_assert_message(*call_stack.last().expect("Call stacks should not be empty"))
// {
// ExecutionError::AssertionFailed(assert_message.to_owned(), call_stack)
// } else {
// ExecutionError::SolvingError(error.clone())
// }
// }
// None => ExecutionError::SolvingError(error.clone()),
// })
// }

0 comments on commit 2bc9965

Please sign in to comment.