From 6d1861153babccb8dcad95c7b8717d7082b3216c Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Fri, 10 Jan 2025 15:25:34 -0300 Subject: [PATCH] chore: simplify a couple of enum variants (#7025) --- .../src/ssa/opt/constant_folding.rs | 14 +++++++------- .../src/elaborator/path_resolution.rs | 10 ++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs b/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs index db249f3bc3..89c48fb3f1 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs @@ -560,7 +560,7 @@ impl<'brillig> Context<'brillig> { ); match evaluation_result { - EvaluationResult::NotABrilligCall | EvaluationResult::CannotEvaluate(_) => None, + EvaluationResult::NotABrilligCall | EvaluationResult::CannotEvaluate => None, EvaluationResult::Evaluated(memory_values) => { let mut memory_index = 0; let new_results = vecmap(old_results, |old_result| { @@ -601,14 +601,14 @@ impl<'brillig> Context<'brillig> { }; if !arguments.iter().all(|argument| dfg.is_constant(*argument)) { - return EvaluationResult::CannotEvaluate(*func_id); + return EvaluationResult::CannotEvaluate; } let mut brillig_arguments = Vec::new(); for argument in arguments { let typ = dfg.type_of_value(*argument); let Some(parameter) = type_to_brillig_parameter(&typ) else { - return EvaluationResult::CannotEvaluate(*func_id); + return EvaluationResult::CannotEvaluate; }; brillig_arguments.push(parameter); } @@ -617,12 +617,12 @@ impl<'brillig> Context<'brillig> { for return_id in func.returns().iter() { let typ = func.dfg.type_of_value(*return_id); if type_to_brillig_parameter(&typ).is_none() { - return EvaluationResult::CannotEvaluate(*func_id); + return EvaluationResult::CannotEvaluate; } } let Ok(generated_brillig) = gen_brillig_for(func, brillig_arguments, brillig) else { - return EvaluationResult::CannotEvaluate(*func_id); + return EvaluationResult::CannotEvaluate; }; let mut calldata = Vec::new(); @@ -639,7 +639,7 @@ impl<'brillig> Context<'brillig> { VM::new(calldata, bytecode, foreign_call_results, &black_box_solver, profiling_active); let vm_status: VMStatus<_> = vm.process_opcodes(); let VMStatus::Finished { return_data_offset, return_data_size } = vm_status else { - return EvaluationResult::CannotEvaluate(*func_id); + return EvaluationResult::CannotEvaluate; }; let memory = @@ -771,7 +771,7 @@ enum EvaluationResult { NotABrilligCall, /// The instruction was a call to a brillig function, but we couldn't evaluate it. /// This can occur in the situation where the brillig function reaches a "trap" or a foreign call opcode. - CannotEvaluate(FunctionId), + CannotEvaluate, /// The instruction was a call to a brillig function and we were able to evaluate it, /// returning evaluation memory values. Evaluated(Vec>), diff --git a/compiler/noirc_frontend/src/elaborator/path_resolution.rs b/compiler/noirc_frontend/src/elaborator/path_resolution.rs index 010c5305fb..0d0b153b6b 100644 --- a/compiler/noirc_frontend/src/elaborator/path_resolution.rs +++ b/compiler/noirc_frontend/src/elaborator/path_resolution.rs @@ -79,7 +79,7 @@ pub struct Turbofish { /// Any item that can appear before the last segment in a path. #[derive(Debug)] enum IntermediatePathResolutionItem { - Module(ModuleId), + Module, Struct(StructId, Option), TypeAlias(TypeAliasId, Option), Trait(TraitId, Option), @@ -180,7 +180,7 @@ impl<'context> Elaborator<'context> { let mut current_module_id = starting_module; let mut current_module = self.get_module(starting_module); - let mut intermediate_item = IntermediatePathResolutionItem::Module(current_module_id); + let mut intermediate_item = IntermediatePathResolutionItem::Module; let first_segment = &path.segments.first().expect("ice: could not fetch first segment").ident; @@ -222,7 +222,7 @@ impl<'context> Elaborator<'context> { }); } - (id, false, IntermediatePathResolutionItem::Module(id)) + (id, false, IntermediatePathResolutionItem::Module) } ModuleDefId::TypeId(id) => ( id.module_id(), @@ -460,9 +460,7 @@ fn merge_intermediate_path_resolution_item_with_module_def_id( ModuleDefId::TraitId(trait_id) => PathResolutionItem::Trait(trait_id), ModuleDefId::GlobalId(global_id) => PathResolutionItem::Global(global_id), ModuleDefId::FunctionId(func_id) => match intermediate_item { - IntermediatePathResolutionItem::Module(_) => { - PathResolutionItem::ModuleFunction(func_id) - } + IntermediatePathResolutionItem::Module => PathResolutionItem::ModuleFunction(func_id), IntermediatePathResolutionItem::Struct(struct_id, generics) => { PathResolutionItem::StructFunction(struct_id, generics, func_id) }