Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions compiler/noirc_evaluator/src/ssa/ir/function.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeSet;
use std::sync::Arc;

use acvm::FieldElement;
use iter_extended::vecmap;
use noirc_frontend::monomorphization::ast::InlineType;
use serde::{Deserialize, Serialize};
Expand All @@ -9,8 +10,8 @@ use super::basic_block::BasicBlockId;
use super::dfg::{DataFlowGraph, GlobalsGraph};
use super::instruction::TerminatorInstruction;
use super::map::Id;
use super::types::Type;
use super::value::ValueId;
use super::types::{NumericType, Type};
use super::value::{Value, ValueId};

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Serialize, Deserialize, PartialOrd, Ord)]
pub enum RuntimeType {
Expand Down Expand Up @@ -217,6 +218,19 @@ impl Function {
})
.sum()
}

/// Iterate over the numeric constants in the function.
pub fn constants(&self) -> impl Iterator<Item = (&FieldElement, &NumericType)> {
let local = self.dfg.values_iter();
let global = self.dfg.globals.values_iter();
local.chain(global).filter_map(|(_, value)| {
if let Value::NumericConstant { constant, typ } = value {
Some((constant, typ))
} else {
None
}
})
}
}

impl Clone for Function {
Expand Down Expand Up @@ -250,6 +264,6 @@ pub(crate) struct Signature {
fn sign_smoke() {
let mut signature = Signature::default();

signature.params.push(Type::Numeric(super::types::NumericType::NativeField));
signature.returns.push(Type::Numeric(super::types::NumericType::Unsigned { bit_size: 32 }));
signature.params.push(Type::Numeric(NumericType::NativeField));
signature.returns.push(Type::Numeric(NumericType::Unsigned { bit_size: 32 }));
}
12 changes: 9 additions & 3 deletions tooling/ast_fuzzer/src/input/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ use std::collections::BTreeSet;
use acir::FieldElement;
use noirc_evaluator::ssa::ssa_gen::Ssa;

pub(crate) fn build_dictionary_from_ssa(_ssa: &Ssa) -> BTreeSet<FieldElement> {
// TODO(#8467): Traverse the SSA to collect fields.
BTreeSet::new()
/// Collect all `Field` values in the SSA which could be interesting for fuzzing.
pub(crate) fn build_dictionary_from_ssa(ssa: &Ssa) -> BTreeSet<FieldElement> {
let mut constants = BTreeSet::new();
for func in ssa.functions.values() {
for (constant, _) in func.constants() {
constants.insert(*constant);
}
}
constants
}
Loading