Skip to content

Commit

Permalink
Rename contexts to highlight the inner contexts are shared rather tha…
Browse files Browse the repository at this point in the history
…n used directly
  • Loading branch information
jfecher committed Apr 21, 2023
1 parent 282fd18 commit 750e1e0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::ssa_refactor::ir::{
function::{Function, FunctionId},
};

use super::Builder;
use super::SharedBuilderContext;

/// The per-function context for each ssa function being generated.
///
Expand All @@ -13,7 +13,7 @@ use super::Builder;
/// Contrary to the name, this struct has the capacity to build as many
/// functions as needed, although it is limited to one function at a time.
pub(crate) struct FunctionBuilder<'ssa> {
global_context: &'ssa Builder,
global_context: &'ssa SharedBuilderContext,

current_function: Function,
current_function_id: FunctionId,
Expand All @@ -24,7 +24,7 @@ pub(crate) struct FunctionBuilder<'ssa> {
}

impl<'ssa> FunctionBuilder<'ssa> {
pub(crate) fn new(parameters: usize, context: &'ssa Builder) -> Self {
pub(crate) fn new(parameters: usize, context: &'ssa SharedBuilderContext) -> Self {
let new_function = Function::new(parameters);
let current_block = new_function.entry_block();

Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_evaluator/src/ssa_refactor/ssa_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use crate::ssa_refactor::ir::{
/// The global context while building the ssa representation.
/// Because this may be shared across threads, it is synchronized internally as necessary.
#[derive(Default)]
pub(crate) struct Builder {
pub(crate) struct SharedBuilderContext {
function_count: AtomicCounter<Function>,
}

impl Builder {
impl SharedBuilderContext {
pub(super) fn next_function(&self) -> FunctionId {
self.function_count.next()
}
Expand Down
12 changes: 6 additions & 6 deletions crates/noirc_evaluator/src/ssa_refactor/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::{Mutex, RwLock};
use noirc_frontend::monomorphization::ast::{self, LocalId};
use noirc_frontend::monomorphization::ast::{FuncId, Program};

use crate::ssa_refactor::ssa_builder::Builder;
use crate::ssa_refactor::ssa_builder::SharedBuilderContext;
use crate::ssa_refactor::{
ir::function::FunctionId as IrFunctionId, ssa_builder::function_builder::FunctionBuilder,
};
Expand All @@ -17,11 +17,11 @@ type FunctionQueue = Vec<(ast::FuncId, IrFunctionId)>;
pub(super) struct FunctionContext<'a> {
definitions: HashMap<LocalId, Value>,
function_builder: FunctionBuilder<'a>,
shared_context: &'a Context,
shared_context: &'a SharedContext,
}

/// Shared context for all functions during ssa codegen
pub(super) struct Context {
pub(super) struct SharedContext {
functions: RwLock<HashMap<FuncId, IrFunctionId>>,
function_queue: Mutex<FunctionQueue>,
pub(super) program: Program,
Expand All @@ -30,8 +30,8 @@ pub(super) struct Context {
impl<'a> FunctionContext<'a> {
pub(super) fn new(
parameter_count: usize,
shared_context: &'a Context,
shared_builder_context: &'a Builder,
shared_context: &'a SharedContext,
shared_builder_context: &'a SharedBuilderContext,
) -> Self {
Self {
definitions: HashMap::new(),
Expand All @@ -49,7 +49,7 @@ impl<'a> FunctionContext<'a> {
}
}

impl Context {
impl SharedContext {
pub(super) fn new(program: Program) -> Self {
Self { functions: Default::default(), function_queue: Default::default(), program }
}
Expand Down
8 changes: 4 additions & 4 deletions crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
mod context;
mod value;

use context::Context;
use context::SharedContext;
use noirc_errors::Location;
use noirc_frontend::monomorphization::ast::{self, Expression, Program};

use self::{context::FunctionContext, value::Value};

use super::ssa_builder::Builder;
use super::ssa_builder::SharedBuilderContext;

pub(crate) fn generate_ssa(program: Program) {
let context = Context::new(program);
let builder_context = Builder::default();
let context = SharedContext::new(program);
let builder_context = SharedBuilderContext::default();

let main = context.program.main();
// TODO struct parameter counting
Expand Down

0 comments on commit 750e1e0

Please sign in to comment.