diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen.rs index a0afcd1b421..15c4e06afa6 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen.rs @@ -21,6 +21,24 @@ use super::{ }; use crate::{errors::InternalError, ssa::ir::function::Function}; +/// Generates a complete Brillig entry point artifact for a given SSA-level [Function], linking all dependencies. +/// +/// This function is responsible for generating a final Brillig artifact corresponding to a compiled SSA [Function]. +/// It sets up the entry point context, registers input/output parameters, and recursively resolves and links +/// all transitive Brillig function dependencies. +/// +/// # Parameters +/// - func: The SSA [Function] to compile as the entry point. +/// - arguments: Brillig-compatible [BrilligParameter] inputs to the function +/// - brillig: The [context structure][Brillig] of all known Brillig artifacts for dependency resolution. +/// - options: Brillig compilation options (e.g., debug trace settings). +/// +/// # Returns +/// - Ok([GeneratedBrillig]): Fully linked artifact for the entry point that can be executed as a Brillig program. +/// - Err([InternalError]): If linking fails to find a dependency +/// +/// # Panics +/// - If the global memory size for the function has not been precomputed. pub(crate) fn gen_brillig_for( func: &Function, arguments: Vec, diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs index cdc6df26240..818bc96bcfa 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs @@ -1,3 +1,4 @@ +//! Codegen for native (black box) function calls. use acvm::{ AcirField, acir::{ @@ -424,6 +425,8 @@ pub(crate) fn convert_black_box_call( brillig_context: &mut BrilligContext, array_or_vector: BrilligVariable, diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs index 73595c25da8..1cc72821026 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs @@ -1,3 +1,15 @@ +//! This module handles allocation, tracking, and lifetime management of variables +//! within a Brillig compiled SSA basic block. +//! +//! [BlockVariables] maintains a set of SSA [ValueId]s that are live and available +//! during the compilation of a single SSA block into Brillig instructions. It cooperates +//! with the [FunctionContext] to manage the mapping from SSA values to [BrilligVariable]s +//! and with the [BrilligContext] for allocating registers. +//! +//! Variables are: +//! - Allocated when first defined in a block (if not already global or hoisted to the global space). +//! - Cached for reuse to avoid redundant register allocation. +//! - Deallocated explicitly when no longer needed (as determined by SSA liveness). use acvm::FieldElement; use fxhash::FxHashSet as HashSet; @@ -19,6 +31,15 @@ use crate::{ use super::brillig_fn::FunctionContext; +/// Tracks SSA variables that are live and usable during Brillig compilation of a block. +/// +/// This structure is meant to be instantiated per SSA basic block and initialized using the +/// the set of live variables that must be available at the block's entry. +/// +/// It implements: +/// - A set of active [ValueId]s that are allocated and usable. +/// - The interface to define new variables as needed for instructions within the block. +/// - Utilities to remove, check, and retrieve variables during Brillig codegen. #[derive(Debug, Default)] pub(crate) struct BlockVariables { available_variables: HashSet, diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs index 732166af923..3dfd7ddf3c3 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs @@ -1,3 +1,4 @@ +//! Codegen for converting SSA globals to Brillig bytecode. use std::collections::{BTreeMap, BTreeSet}; use acvm::FieldElement; diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs index 6114fd35a38..fd424778aa4 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs @@ -1,3 +1,4 @@ +//! Codegen for converting SSA slice intrinsic functions to Brillig bytecode. use acvm::acir::brillig::MemoryAddress; use crate::brillig::brillig_ir::{ diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_calls.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_calls.rs index 5036326fbc9..114acadadfd 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_calls.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_calls.rs @@ -10,7 +10,6 @@ use super::{ }; impl BrilligContext { - // impl BrilligContext { pub(crate) fn codegen_call( &mut self, func_id: FunctionId,