From 62d02a103e7edf08bb104f8e55aaad27b39bb743 Mon Sep 17 00:00:00 2001 From: 0xYYY <0xYYY@pm.me> Date: Sun, 12 Feb 2023 19:33:39 +0800 Subject: [PATCH] chore: Follow rust naming convention (#801) * chore: follow rust naming convention * chore: fmt * chore: revert lvalue changes --- crates/noirc_evaluator/src/lib.rs | 8 ++++---- crates/noirc_evaluator/src/ssa/context.rs | 8 ++++---- crates/noirc_evaluator/src/ssa/function.rs | 16 ++++++++-------- crates/noirc_evaluator/src/ssa/inline.rs | 6 +++--- crates/noirc_evaluator/src/ssa/ssa_gen.rs | 8 ++++---- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/noirc_evaluator/src/lib.rs b/crates/noirc_evaluator/src/lib.rs index 22ff5c792c..8d7d78219b 100644 --- a/crates/noirc_evaluator/src/lib.rs +++ b/crates/noirc_evaluator/src/lib.rs @@ -11,7 +11,7 @@ use errors::{RuntimeError, RuntimeErrorKind}; use iter_extended::btree_map; use noirc_abi::{AbiType, AbiVisibility}; use noirc_frontend::monomorphization::ast::*; -use ssa::{node, ssa_gen::IRGenerator}; +use ssa::{node, ssa_gen::IrGenerator}; use std::collections::BTreeMap; pub struct Evaluator { @@ -110,7 +110,7 @@ impl Evaluator { program: Program, enable_logging: bool, ) -> Result<(), RuntimeError> { - let mut ir_gen = IRGenerator::new(program); + let mut ir_gen = IrGenerator::new(program); self.parse_abi_alt(&mut ir_gen); // Now call the main function @@ -140,7 +140,7 @@ impl Evaluator { def: Definition, param_type: &AbiType, visibility: &AbiVisibility, - ir_gen: &mut IRGenerator, + ir_gen: &mut IrGenerator, ) -> Result<(), RuntimeErrorKind> { match param_type { AbiType::Field => { @@ -274,7 +274,7 @@ impl Evaluator { /// Noted in the noirc_abi, it is possible to convert Toml -> NoirTypes /// However, this intermediate representation is useful as it allows us to have /// intermediate Types which the core type system does not know about like Strings. - fn parse_abi_alt(&mut self, ir_gen: &mut IRGenerator) { + fn parse_abi_alt(&mut self, ir_gen: &mut IrGenerator) { // XXX: Currently, the syntax only supports public witnesses // u8 and arrays are assumed to be private // This is not a short-coming of the ABI, but of the grammar diff --git a/crates/noirc_evaluator/src/ssa/context.rs b/crates/noirc_evaluator/src/ssa/context.rs index 604623e12d..366b9e7c65 100644 --- a/crates/noirc_evaluator/src/ssa/context.rs +++ b/crates/noirc_evaluator/src/ssa/context.rs @@ -3,7 +3,7 @@ use crate::ssa::{ acir_gen::Acir, block::{BasicBlock, BlockId}, conditional::{DecisionTree, TreeBuilder}, - function::{FuncIndex, SSAFunction}, + function::{FuncIndex, SsaFunction}, inline::StackFrame, mem::{ArrayId, Memory}, node::{ @@ -32,7 +32,7 @@ pub struct SsaContext { pub sealed_blocks: HashSet, pub mem: Memory, - pub functions: HashMap, + pub functions: HashMap, pub opcode_ids: HashMap, //Adjacency Matrix of the call graph; list of rows where each row indicates the functions called by the function whose FuncIndex is the row number @@ -374,7 +374,7 @@ impl SsaContext { id } - pub fn ssa_func(&self, func_id: FuncId) -> Option<&SSAFunction> { + pub fn ssa_func(&self, func_id: FuncId) -> Option<&SsaFunction> { self.functions.get(&func_id) } @@ -385,7 +385,7 @@ impl SsaContext { } } - pub fn try_get_ssa_func(&self, id: NodeId) -> Option<&SSAFunction> { + pub fn try_get_ssa_func(&self, id: NodeId) -> Option<&SsaFunction> { self.try_get_func_id(id).and_then(|id| self.ssa_func(id)) } diff --git a/crates/noirc_evaluator/src/ssa/function.rs b/crates/noirc_evaluator/src/ssa/function.rs index 23d09b5333..d98b8b4e21 100644 --- a/crates/noirc_evaluator/src/ssa/function.rs +++ b/crates/noirc_evaluator/src/ssa/function.rs @@ -5,7 +5,7 @@ use crate::ssa::{ context::SsaContext, mem::ArrayId, node::{Node, NodeId, ObjectType, Opcode, Operation}, - ssa_gen::IRGenerator, + ssa_gen::IrGenerator, {block, builtin, node, ssa_form}, }; use iter_extended::try_vecmap; @@ -22,7 +22,7 @@ impl FuncIndex { } #[derive(Clone, Debug)] -pub struct SSAFunction { +pub struct SsaFunction { pub entry_block: BlockId, pub id: FuncId, pub idx: FuncIndex, @@ -35,15 +35,15 @@ pub struct SSAFunction { pub decision: DecisionTree, } -impl SSAFunction { +impl SsaFunction { pub fn new( id: FuncId, name: &str, block_id: BlockId, idx: FuncIndex, ctx: &mut SsaContext, - ) -> SSAFunction { - SSAFunction { + ) -> SsaFunction { + SsaFunction { entry_block: block_id, id, node_id: ctx.push_function_id(id, name), @@ -55,7 +55,7 @@ impl SSAFunction { } } - pub fn compile(&self, ir_gen: &mut IRGenerator) -> Result { + pub fn compile(&self, ir_gen: &mut IrGenerator) -> Result { let function_cfg = block::bfs(self.entry_block, None, &ir_gen.context); block::compute_sub_dom(&mut ir_gen.context, &function_cfg); //Optimization @@ -137,7 +137,7 @@ impl SSAFunction { } } -impl IRGenerator { +impl IrGenerator { /// Creates an ssa function and returns its type upon success pub fn create_function( &mut self, @@ -150,7 +150,7 @@ impl IRGenerator { let function = &mut self.program[func_id]; let mut func = - SSAFunction::new(func_id, &function.name, func_block, index, &mut self.context); + SsaFunction::new(func_id, &function.name, func_block, index, &mut self.context); //arguments: for (param_id, mutable, name, typ) in std::mem::take(&mut function.parameters) { diff --git a/crates/noirc_evaluator/src/ssa/inline.rs b/crates/noirc_evaluator/src/ssa/inline.rs index 180cf71633..4b009d99b5 100644 --- a/crates/noirc_evaluator/src/ssa/inline.rs +++ b/crates/noirc_evaluator/src/ssa/inline.rs @@ -185,7 +185,7 @@ impl StackFrame { //Return false if the inlined function performs a function call pub fn inline( ctx: &mut SsaContext, - ssa_func: &function::SSAFunction, + ssa_func: &function::SsaFunction, args: &[NodeId], arrays: &[(ArrayId, u32)], block: BlockId, @@ -437,7 +437,7 @@ impl node::Operation { return id; } } - function::SSAFunction::get_mapped_value(Some(&id), ctx, inline_map, block_id) + function::SsaFunction::get_mapped_value(Some(&id), ctx, inline_map, block_id) }); } //However we deliberately not use the default case to force review of the behavior if a new type of operation is added. @@ -450,7 +450,7 @@ impl node::Operation { | Operation::Return(_) | Operation::Load {.. } | Operation::Store { .. } | Operation::Call { .. } => { self.map_id_mut(|id| { - function::SSAFunction::get_mapped_value(Some(&id), ctx, inline_map, block_id) + function::SsaFunction::get_mapped_value(Some(&id), ctx, inline_map, block_id) }); } } diff --git a/crates/noirc_evaluator/src/ssa/ssa_gen.rs b/crates/noirc_evaluator/src/ssa/ssa_gen.rs index 6f89388bb2..5408359842 100644 --- a/crates/noirc_evaluator/src/ssa/ssa_gen.rs +++ b/crates/noirc_evaluator/src/ssa/ssa_gen.rs @@ -21,7 +21,7 @@ use num_bigint::BigUint; use num_traits::Zero; use std::collections::{BTreeMap, HashMap}; -pub struct IRGenerator { +pub struct IrGenerator { pub context: SsaContext, pub function_context: Option, @@ -32,9 +32,9 @@ pub struct IRGenerator { pub program: Program, } -impl IRGenerator { - pub fn new(program: Program) -> IRGenerator { - IRGenerator { +impl IrGenerator { + pub fn new(program: Program) -> IrGenerator { + IrGenerator { context: SsaContext::new(), variable_values: HashMap::new(), function_context: None,