From 9c33c4209c966d26409d4f4e21322a8e03e9845d Mon Sep 17 00:00:00 2001 From: David Mak Date: Fri, 30 Aug 2024 22:31:26 +0800 Subject: [PATCH] [core] Fix type of ndarray.element_type Should be the element type of the NDArray itself, not the pointer to its type. --- nac3artiq/src/codegen.rs | 8 ++++---- nac3core/src/codegen/classes.rs | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nac3artiq/src/codegen.rs b/nac3artiq/src/codegen.rs index 8c7809b6..4d4b4f19 100644 --- a/nac3artiq/src/codegen.rs +++ b/nac3artiq/src/codegen.rs @@ -461,8 +461,8 @@ fn format_rpc_arg<'ctx>( let llvm_usize = generator.get_size_type(ctx.ctx); let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, arg_ty); - let llvm_arg_ty = - NDArrayType::new(generator, ctx.ctx, ctx.get_llvm_type(generator, elem_ty)); + let llvm_elem_ty = ctx.get_llvm_type(generator, elem_ty); + let llvm_arg_ty = NDArrayType::new(generator, ctx.ctx, llvm_elem_ty); let llvm_arg = NDArrayValue::from_ptr_val(arg.into_pointer_value(), llvm_usize, None); let llvm_usize_sizeof = ctx @@ -472,7 +472,7 @@ fn format_rpc_arg<'ctx>( let llvm_pdata_sizeof = ctx .builder .build_int_truncate_or_bit_cast( - llvm_arg_ty.element_type().ptr_type(AddressSpace::default()).size_of(), + llvm_elem_ty.ptr_type(AddressSpace::default()).size_of(), llvm_usize, "", ) @@ -630,7 +630,7 @@ fn format_rpc_ret<'ctx>( let llvm_pdata_sizeof = ctx .builder .build_int_truncate_or_bit_cast( - llvm_ret_ty.element_type().size_of().unwrap(), + llvm_elem_ty.ptr_type(AddressSpace::default()).size_of(), llvm_usize, "", ) diff --git a/nac3core/src/codegen/classes.rs b/nac3core/src/codegen/classes.rs index 9ebac518..3d548205 100644 --- a/nac3core/src/codegen/classes.rs +++ b/nac3core/src/codegen/classes.rs @@ -1250,11 +1250,13 @@ impl<'ctx> NDArrayType<'ctx> { /// Returns the element type of this `ndarray` type. #[must_use] - pub fn element_type(&self) -> BasicTypeEnum<'ctx> { + pub fn element_type(&self) -> AnyTypeEnum<'ctx> { self.as_base_type() .get_element_type() .into_struct_type() .get_field_type_at_index(2) + .map(BasicTypeEnum::into_pointer_type) + .map(PointerType::get_element_type) .unwrap() } }