Skip to content

Commit

Permalink
chore: regression test for #5462 (noir-lang/noir#6286)
Browse files Browse the repository at this point in the history
feat(improve): Remove scan through globals (noir-lang/noir#6282)
feat: show LSP diagnostic related information (noir-lang/noir#6277)
feat: trait inheritance (noir-lang/noir#6252)
feat: optimize reading a workspace's files (noir-lang/noir#6281)
fix: prevent compiler panic when popping from empty slices (noir-lang/noir#6274)
feat(test): Include the PoseidonHasher in the fuzzing (noir-lang/noir#6280)
feat: slightly improve "unexpected token" error message (noir-lang/noir#6279)
feat(test): Fuzz poseidon hases against an external library (noir-lang/noir#6273)
feat: remove byte decomposition in `compute_decomposition` (noir-lang/noir#6159)
fix: address inactive public key check in `verify_signature_noir` (noir-lang/noir#6270)
feat(test): Fuzz test poseidon2 hash equivalence (noir-lang/noir#6265)
fix!: Integer division is not the inverse of integer multiplication (noir-lang/noir#6243)
feat(perf): Flamegraphs for test program execution benchmarks (noir-lang/noir#6253)
fix: visibility for impl methods (noir-lang/noir#6261)
feat: Add `checked_transmute` (noir-lang/noir#6262)
feat!: kind size checks (noir-lang/noir#6137)
feat: don't crash LSP when there are errors resolving the workspace (noir-lang/noir#6257)
fix: don't warn on unuse global if it has an abi annotation (noir-lang/noir#6258)
fix: don't warn on unused struct that has an abi annotation (noir-lang/noir#6254)
feat: don't suggest private struct fields in LSP (noir-lang/noir#6256)
feat: visibility for struct fields (noir-lang/noir#6221)
fix: handle dfg databus in SSA normalization (noir-lang/noir#6249)
fix: homogeneous input points for EC ADD (noir-lang/noir#6241)
chore: add regression test for #5756 (noir-lang/noir#5770)
feat: allow `unconstrained` after visibility (noir-lang/noir#6246)
feat: optimize `Quoted::as_expr` by parsing just once (noir-lang/noir#6237)
fix(frontend): Do not warn when a nested struct is provided as input to main (noir-lang/noir#6239)
fix!: Change tag attributes to require a ' prefix (noir-lang/noir#6235)
feat: recover from '=' instead of ':' in struct constructor/pattern (noir-lang/noir#6236)
  • Loading branch information
AztecBot committed Oct 12, 2024
2 parents 444777b + 23b90bb commit 1199fb0
Show file tree
Hide file tree
Showing 54 changed files with 832 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8232bfaf0a88dcba5a6949489b81d78c3413c5bc
ae87d287ab1fae0f999dfd0d1166fbddb927ba97
2 changes: 1 addition & 1 deletion noir/noir-repo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions noir/noir-repo/acvm-repo/blackbox_solver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ num-bigint = "0.4"
blake2 = "0.10.6"
blake3 = "1.5.0"
sha2.workspace = true
sha3.workspace = true
keccak = "0.1.4"
k256 = { version = "0.11.0", features = [
"ecdsa",
Expand Down
5 changes: 5 additions & 0 deletions noir/noir-repo/compiler/fm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ impl FileManager {
self.id_to_path.get(&file_id).map(|path| path.as_path())
}

pub fn has_file(&self, file_name: &Path) -> bool {
let file_name = self.root.join(file_name);
self.name_to_id(file_name).is_some()
}

// TODO: This should accept a &Path instead of a PathBuf
pub fn name_to_id(&self, file_name: PathBuf) -> Option<FileId> {
self.file_map.get_file_id(&PathString::from_path(file_name))
Expand Down
2 changes: 1 addition & 1 deletion noir/noir-repo/compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
pub struct CustomDiagnostic {
pub message: String,
pub secondaries: Vec<CustomLabel>,
notes: Vec<String>,
pub notes: Vec<String>,
pub kind: DiagnosticKind,
pub deprecated: bool,
pub unnecessary: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ impl Intrinsic {
// These apply a constraint that the input must fit into a specified number of limbs.
Intrinsic::ToBits(_) | Intrinsic::ToRadix(_) => true,

// These imply a check that the slice is non-empty and should fail otherwise.
Intrinsic::SlicePopBack | Intrinsic::SlicePopFront | Intrinsic::SliceRemove => true,

Intrinsic::ArrayLen
| Intrinsic::ArrayAsStrUnchecked
| Intrinsic::AsSlice
| Intrinsic::SlicePushBack
| Intrinsic::SlicePushFront
| Intrinsic::SlicePopBack
| Intrinsic::SlicePopFront
| Intrinsic::SliceInsert
| Intrinsic::SliceRemove
| Intrinsic::StrAsBytes
| Intrinsic::FromField
| Intrinsic::AsField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ pub(super) fn simplify_call(
}
}
Intrinsic::SlicePopBack => {
let length = dfg.get_numeric_constant(arguments[0]);
if length.map_or(true, |length| length.is_zero()) {
// If the length is zero then we're trying to pop the last element from an empty slice.
// Defer the error to acir_gen.
return SimplifyResult::None;
}

let slice = dfg.get_array_constant(arguments[1]);
if let Some((_, typ)) = slice {
simplify_slice_pop_back(typ, arguments, dfg, block, call_stack.clone())
Expand All @@ -174,6 +181,13 @@ pub(super) fn simplify_call(
}
}
Intrinsic::SlicePopFront => {
let length = dfg.get_numeric_constant(arguments[0]);
if length.map_or(true, |length| length.is_zero()) {
// If the length is zero then we're trying to pop the first element from an empty slice.
// Defer the error to acir_gen.
return SimplifyResult::None;
}

let slice = dfg.get_array_constant(arguments[1]);
if let Some((mut slice, typ)) = slice {
let element_count = typ.element_size();
Expand Down Expand Up @@ -225,6 +239,13 @@ pub(super) fn simplify_call(
}
}
Intrinsic::SliceRemove => {
let length = dfg.get_numeric_constant(arguments[0]);
if length.map_or(true, |length| length.is_zero()) {
// If the length is zero then we're trying to remove an element from an empty slice.
// Defer the error to acir_gen.
return SimplifyResult::None;
}

let slice = dfg.get_array_constant(arguments[1]);
let index = dfg.get_numeric_constant(arguments[2]);
if let (Some((mut slice, typ)), Some(index)) = (slice, index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Function {
assert_eq!(reachable_blocks.len(), 1, "Expected there to be 1 block remaining in Acir function for array_set optimization");
}

let mut context = Context::new(&self.dfg, matches!(self.runtime(), RuntimeType::Brillig(_)));
let mut context = Context::new(&self.dfg, matches!(self.runtime(), RuntimeType::Brillig));

for block in reachable_blocks.iter() {
context.analyze_last_uses(*block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ impl<'a> SliceCapacityTracker<'a> {
let slice_contents = arguments[argument_index];

if let Some(contents_capacity) = slice_sizes.get(&slice_contents) {
let new_capacity = *contents_capacity - 1;
// We use a saturating sub here as calling `pop_front` or `pop_back`
// on a zero-length slice would otherwise underflow.
let new_capacity = contents_capacity.saturating_sub(1);
slice_sizes.insert(result_slice, new_capacity);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Function {
/// The structure of this pass is simple:
/// Go through each block and re-insert all instructions.
pub(crate) fn remove_bit_shifts(&mut self) {
if matches!(self.runtime(), RuntimeType::Brillig(_)) {
if let RuntimeType::Brillig = self.runtime() {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Ssa {

impl Function {
pub(crate) fn remove_enable_side_effects(&mut self) {
if matches!(self.runtime(), RuntimeType::Brillig(_)) {
if matches!(self.runtime(), RuntimeType::Brillig) {
// Brillig functions do not make use of the `EnableSideEffects` instruction so are unaffected by this pass.
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Ssa {
impl Function {
pub(crate) fn remove_if_else(&mut self) {
// This should match the check in flatten_cfg
if matches!(self.runtime(), RuntimeType::Brillig(_)) {
if let crate::ssa::ir::function::RuntimeType::Brillig = self.runtime() {
// skip
} else {
Context::default().remove_if_else(self);
Expand Down Expand Up @@ -119,7 +119,9 @@ impl Context {
}
SizeChange::Dec { old, new } => {
let old_capacity = self.get_or_find_capacity(&function.dfg, old);
self.slice_sizes.insert(new, old_capacity - 1);
// We use a saturating sub here as calling `pop_front` or `pop_back` on a zero-length slice
// would otherwise underflow.
self.slice_sizes.insert(new, old_capacity.saturating_sub(1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Function {
self.dfg.replace_result(instruction_id, original_return_id);

let is_within_unconstrained = self.dfg.make_constant(
FieldElement::from(matches!(self.runtime(), RuntimeType::Brillig(_))),
FieldElement::from(matches!(self.runtime(), RuntimeType::Brillig)),
Type::bool(),
);
// Replace all uses of the original return value with the constant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Function {
// Loop unrolling in brillig can lead to a code explosion currently. This can
// also be true for ACIR, but we have no alternative to unrolling in ACIR.
// Brillig also generally prefers smaller code rather than faster code.
if !matches!(self.runtime(), RuntimeType::Brillig(_)) {
if self.runtime() != RuntimeType::Brillig {
errors.extend(find_all_loops(self).unroll_each_loop(self));
}
}
Expand Down
8 changes: 7 additions & 1 deletion noir/noir-repo/compiler/noirc_frontend/src/ast/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use super::{Documented, GenericTypeArgs, ItemVisibility};
pub struct NoirTrait {
pub name: Ident,
pub generics: UnresolvedGenerics,
pub bounds: Vec<TraitBound>,
pub where_clause: Vec<UnresolvedTraitConstraint>,
pub span: Span,
pub items: Vec<Documented<TraitItem>>,
Expand Down Expand Up @@ -134,7 +135,12 @@ impl Display for NoirTrait {
let generics = vecmap(&self.generics, |generic| generic.to_string());
let generics = if generics.is_empty() { "".into() } else { generics.join(", ") };

writeln!(f, "trait {}{} {{", self.name, generics)?;
write!(f, "trait {}{}", self.name, generics)?;
if !self.bounds.is_empty() {
let bounds = vecmap(&self.bounds, |bound| bound.to_string()).join(" + ");
write!(f, ": {}", bounds)?;
}
writeln!(f, " {{")?;

for item in self.items.iter() {
let item = item.to_string();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
HirPrefixExpression,
},
stmt::HirStatement,
traits::TraitConstraint,
traits::{ResolvedTraitBound, TraitConstraint},
},
node_interner::{DefinitionKind, ExprId, FuncId, InternedStatementKind, TraitMethodId},
token::Tokens,
Expand Down Expand Up @@ -743,9 +743,11 @@ impl<'context> Elaborator<'context> {
// that implements the trait.
let constraint = TraitConstraint {
typ: operand_type.clone(),
trait_id: trait_id.trait_id,
trait_generics: TraitGenerics::default(),
span,
trait_bound: ResolvedTraitBound {
trait_id: trait_id.trait_id,
trait_generics: TraitGenerics::default(),
span,
},
};
self.push_trait_constraint(constraint, expr_id);
self.type_check_operator_method(expr_id, trait_id, operand_type, span);
Expand Down
Loading

0 comments on commit 1199fb0

Please sign in to comment.