From c5e81da007582358219c8f344ff5a4b7b8c63c00 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Tue, 26 Sep 2023 17:53:00 +0100 Subject: [PATCH] Review comments Signed-off-by: Sean Young --- src/emit/binary.rs | 21 ++++++--------------- src/emit/expression.rs | 16 ++++++++-------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/emit/binary.rs b/src/emit/binary.rs index fbee12fac3..fdf1129ab6 100644 --- a/src/emit/binary.rs +++ b/src/emit/binary.rs @@ -893,23 +893,14 @@ impl<'a> Binary<'a> { self.module.get_struct_type("struct.vector").unwrap().into() } Type::Array(base_ty, dims) => { - let mut aty = self.llvm_field_ty(base_ty, ns); - - for dim in dims { - match dim { - ArrayLength::Fixed(d) => { - aty = aty.array_type(d.to_u32().unwrap()).into(); - } + dims.iter() + .fold(self.llvm_field_ty(base_ty, ns), |aty, dim| match dim { + ArrayLength::Fixed(d) => aty.array_type(d.to_u32().unwrap()).into(), ArrayLength::Dynamic => { - aty = self.module.get_struct_type("struct.vector").unwrap().into(); - } - ArrayLength::AnyFixed => { - unreachable!() + self.module.get_struct_type("struct.vector").unwrap().into() } - } - } - - aty + ArrayLength::AnyFixed => unreachable!(), + }) } Type::Struct(StructType::SolParameters) => self .module diff --git a/src/emit/expression.rs b/src/emit/expression.rs index 77fa4ef84e..305e5ffa17 100644 --- a/src/emit/expression.rs +++ b/src/emit/expression.rs @@ -2186,7 +2186,7 @@ pub(super) fn expression_to_slice<'a, T: TargetRuntime<'a> + ?Sized>( bin.builder.build_store(output_len, len); } - return (output, llvm_length); + (output, llvm_length) } Expression::AllocDynamicBytes { initializer: Some(initializer), @@ -2195,16 +2195,16 @@ pub(super) fn expression_to_slice<'a, T: TargetRuntime<'a> + ?Sized>( let ptr = bin.emit_global_string("slice_constant", initializer, true); let len = i64_const!(initializer.len() as u64); - return (ptr, len); + (ptr, len) } - _ => (), - } - - let from = e.ty(); + _ => { + let from = e.ty(); - let val = expression(target, bin, e, vartab, function, ns); + let val = expression(target, bin, e, vartab, function, ns); - basic_value_to_slice(bin, val, &from, to, function, ns) + basic_value_to_slice(bin, val, &from, to, function, ns) + } + } } /// Convert basic enum value to a slice. This function calls itself recursively