Skip to content

Commit

Permalink
debug failing tests by updating '<' -> '<=' where needed, cargo clipp…
Browse files Browse the repository at this point in the history
…y/fmt
  • Loading branch information
michaeljklein committed Jan 9, 2025
1 parent 36cdd91 commit 3cc4f7d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ impl Context<'_> {
fn pow(&mut self, lhs: ValueId, rhs: ValueId) -> ValueId {
let typ = self.function.dfg.type_of_value(rhs);
if let Type::Numeric(NumericType::Unsigned { bit_size }) = typ {
let to_bits = self.function.dfg.import_intrinsic(Intrinsic::ToBitsUnsafe(Endian::Little));
let to_bits =
self.function.dfg.import_intrinsic(Intrinsic::ToBitsUnsafe(Endian::Little));
let result_types = vec![Type::Array(Arc::new(vec![Type::bool()]), bit_size)];
let rhs_bits = self.insert_call(to_bits, vec![rhs], result_types);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,14 @@ fn static_assert(
let predicate = get_bool(predicate)?;
let message = get_str(interner, message)?;

"TODO need to evaluate static_assert's predicate more?!";
if predicate {
Ok(Value::Unit)
} else {
failing_constraint((*message).clone(), location, call_stack)
failing_constraint(
format!("static_assert failed: {}", message).clone(),
location,
call_stack,
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion compiler/noirc_frontend/src/tests/metaprogramming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ fn comptime_code_rejects_dynamic_variable() {

assert_eq!(errors.len(), 1);
match &errors[0].0 {
CompilationError::InterpreterError(InterpreterError::NonComptimeVarReferenced { name, .. }) => {
CompilationError::InterpreterError(InterpreterError::NonComptimeVarReferenced {
name,
..
}) => {
assert_eq!(name, "x");
}
_ => panic!("expected an InterpreterError"),
Expand Down
8 changes: 4 additions & 4 deletions noir_stdlib/src/field/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Field {
/// (e.g. 254 for the BN254 field) cause a compile-time error.
// docs:start:to_le_bits
pub fn to_le_bits<let N: u32>(self: Self) -> [u1; N] {
static_assert(N < modulus_num_bits() as u32, "N must be less than modulus_num_bits");
static_assert(N <= modulus_num_bits() as u32, "N must be less than or equal to modulus_num_bits");
self.to_le_bits_unsafe()
}
// docs:end:to_le_bits
Expand Down Expand Up @@ -78,7 +78,7 @@ impl Field {
/// (e.g. 254 for the BN254 field) cause a compile-time error.
// docs:start:to_be_bits
pub fn to_be_bits<let N: u32>(self: Self) -> [u1; N] {
static_assert(N < modulus_num_bits() as u32, "N must be less than modulus_num_bits");
static_assert(N <= modulus_num_bits() as u32, "N must be less than or equal to modulus_num_bits");
self.to_be_bits_unsafe()
}
// docs:end:to_be_bits
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Field {

// `_radix` must be less than 256
fn __to_le_radix<let N: u32>(self, radix: u32) -> [u8; N] {
static_assert(N < modulus_num_bits() as u32, "N must be less than modulus_num_bits");
static_assert(N <= modulus_num_bits() as u32, "N must be less than or equal to modulus_num_bits");
// TODO(https://github.com/noir-lang/noir/issues/6964): assert(radix < 256, "`_radix` must be less than 256");
self.__to_le_radix_unsafe(radix)
}
Expand All @@ -188,7 +188,7 @@ impl Field {

// `_radix` must be less than 256
fn __to_be_radix<let N: u32>(self, radix: u32) -> [u8; N] {
static_assert(N < modulus_num_bits() as u32, "N must be less than modulus_num_bits");
static_assert(N <= modulus_num_bits() as u32, "N must be less than or equal to modulus_num_bits");
// TODO(https://github.com/noir-lang/noir/issues/6964): assert(radix < 256, "`_radix` must be less than 256");
self.__to_be_radix_unsafe(radix)
}
Expand Down
9 changes: 6 additions & 3 deletions tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,12 @@ mod tests {
)
// TODO: collect all errors and only error at the end! (i.e. don't fail fast)
.unwrap_or_else(|err| {
let error_string: String = err.iter().map(|diagnostic| {
format!("{}\n---\n", diagnostic_to_string(diagnostic, &file_manager))
}).collect();
let error_string: String = err
.iter()
.map(|diagnostic| {
format!("{}\n---\n", diagnostic_to_string(diagnostic, &file_manager))
})
.collect();
panic!("Failed to compile:\n\n{}", error_string)
});

Expand Down
5 changes: 4 additions & 1 deletion tooling/nargo_cli/src/cli/test_cmd/formatters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ fn package_start(package_name: &str, test_count: usize) -> std::io::Result<()> {
Ok(())
}

pub(crate) fn diagnostic_to_string(file_diagnostic: &FileDiagnostic, file_manager: &FileManager) -> String {
pub(crate) fn diagnostic_to_string(
file_diagnostic: &FileDiagnostic,
file_manager: &FileManager,
) -> String {
let file_map = file_manager.as_file_map();

let custom_diagnostic = &file_diagnostic.diagnostic;
Expand Down

0 comments on commit 3cc4f7d

Please sign in to comment.