diff --git a/compiler/noirc_evaluator/src/ssa/ir/function.rs b/compiler/noirc_evaluator/src/ssa/ir/function.rs index cc4653fd0ca..ac5a64bb2fd 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/function.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/function.rs @@ -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}; @@ -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 { @@ -217,6 +218,19 @@ impl Function { }) .sum() } + + /// Iterate over the numeric constants in the function. + pub fn constants(&self) -> impl Iterator { + 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 { @@ -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 })); } diff --git a/tooling/ast_fuzzer/src/input/dictionary.rs b/tooling/ast_fuzzer/src/input/dictionary.rs index d53ca4b96f8..b64788ed721 100644 --- a/tooling/ast_fuzzer/src/input/dictionary.rs +++ b/tooling/ast_fuzzer/src/input/dictionary.rs @@ -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 { - // 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 { + let mut constants = BTreeSet::new(); + for func in ssa.functions.values() { + for (constant, _) in func.constants() { + constants.insert(*constant); + } + } + constants }