From 53d09b86f7c3d4d7f7d30e639b3d535fbd398e6e Mon Sep 17 00:00:00 2001 From: David Mak Date: Tue, 17 Dec 2024 16:48:31 +0800 Subject: [PATCH] [core] codegen/types: Refactor ProxyType - Add alloca_type() function to obtain the type that should be passed into a `build_alloca` call - Provide default implementations for raw_alloca and array_alloca - Add raw_alloca_var and array_alloca_var to distinguish alloca instructions placed at the front of the function vs at the current builder location --- nac3core/src/codegen/expr.rs | 2 +- nac3core/src/codegen/types/list.rs | 53 ++++++----------- nac3core/src/codegen/types/mod.rs | 58 ++++++++++++++++--- .../src/codegen/types/ndarray/contiguous.rs | 53 +++++++---------- .../src/codegen/types/ndarray/indexing.rs | 51 ++++++---------- nac3core/src/codegen/types/ndarray/mod.rs | 56 +++++++----------- nac3core/src/codegen/types/ndarray/nditer.rs | 55 +++++++----------- nac3core/src/codegen/types/range.rs | 47 +++++---------- nac3core/src/codegen/types/utils/slice.rs | 55 +++++++----------- .../src/codegen/values/ndarray/contiguous.rs | 2 +- .../src/codegen/values/ndarray/indexing.rs | 2 +- 11 files changed, 189 insertions(+), 245 deletions(-) diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index 66624162..4efa68c6 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -1108,7 +1108,7 @@ pub fn allocate_list<'ctx, G: CodeGenerator + ?Sized>( // List structure; type { ty*, size_t } let arr_ty = ListType::new(generator, ctx.ctx, llvm_elem_ty); - let list = arr_ty.alloca(generator, ctx, name); + let list = arr_ty.alloca_var(generator, ctx, name); let length = ctx.builder.build_int_z_extend(length, llvm_usize, "").unwrap(); list.store_size(ctx, generator, length); diff --git a/nac3core/src/codegen/types/list.rs b/nac3core/src/codegen/types/list.rs index 8de30867..d001ce0f 100644 --- a/nac3core/src/codegen/types/list.rs +++ b/nac3core/src/codegen/types/list.rs @@ -1,13 +1,12 @@ use inkwell::{ context::Context, types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType}, - values::{IntValue, PointerValue}, AddressSpace, }; use super::ProxyType; use crate::codegen::{ - values::{ArraySliceValue, ListValue, ProxyValue}, + values::{ListValue, ProxyValue}, CodeGenContext, CodeGenerator, }; @@ -114,14 +113,28 @@ impl<'ctx> ListType<'ctx> { /// Allocates an instance of [`ListValue`] as if by calling `alloca` on the base type. #[must_use] - pub fn alloca( + pub fn alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + name: Option<&'ctx str>, + ) -> >::Value { + >::Value::from_pointer_value( + self.raw_alloca(ctx, name), + self.llvm_usize, + name, + ) + } + + /// Allocates an instance of [`ListValue`] as if by calling `alloca` on the base type. + #[must_use] + pub fn alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, name: Option<&'ctx str>, ) -> >::Value { >::Value::from_pointer_value( - self.raw_alloca(generator, ctx, name), + self.raw_alloca_var(generator, ctx, name), self.llvm_usize, name, ) @@ -162,36 +175,8 @@ impl<'ctx> ProxyType<'ctx> for ListType<'ctx> { Self::is_representable(llvm_ty, generator.get_size_type(ctx)) } - fn raw_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - name: Option<&'ctx str>, - ) -> PointerValue<'ctx> { - generator - .gen_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - name, - ) - .unwrap() - } - - fn array_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - size: IntValue<'ctx>, - name: Option<&'ctx str>, - ) -> ArraySliceValue<'ctx> { - generator - .gen_array_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - size, - name, - ) - .unwrap() + fn alloca_type(&self) -> impl BasicType<'ctx> { + self.as_base_type().get_element_type().into_struct_type() } fn as_base_type(&self) -> Self::Base { diff --git a/nac3core/src/codegen/types/mod.rs b/nac3core/src/codegen/types/mod.rs index 03d6d387..98bd43ba 100644 --- a/nac3core/src/codegen/types/mod.rs +++ b/nac3core/src/codegen/types/mod.rs @@ -57,24 +57,66 @@ pub trait ProxyType<'ctx>: Into { llvm_ty: Self::Base, ) -> Result<(), String>; - /// Creates a new value of this type by invoking `alloca`, returning a [`PointerValue`] instance - /// representing the allocated value. - fn raw_alloca( + /// Returns the type that should be used in `alloca` IR statements. + fn alloca_type(&self) -> impl BasicType<'ctx>; + + /// Creates a new value of this type by invoking `alloca` at the current builder location, + /// returning a [`PointerValue`] instance representing the allocated value. + fn raw_alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + name: Option<&'ctx str>, + ) -> PointerValue<'ctx> { + ctx.builder + .build_alloca(self.alloca_type().as_basic_type_enum(), name.unwrap_or_default()) + .unwrap() + } + + /// Creates a new value of this type by invoking `alloca` at the beginning of the function, + /// returning a [`PointerValue`] instance representing the allocated value. + fn raw_alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, name: Option<&'ctx str>, - ) -> PointerValue<'ctx>; + ) -> PointerValue<'ctx> { + generator.gen_var_alloc(ctx, self.alloca_type().as_basic_type_enum(), name).unwrap() + } - /// Creates a new array value of this type, returning an [`ArraySliceValue`] encapsulating the - /// resulting array. - fn array_alloca( + /// Creates a new array value of this type by invoking `alloca` at the current builder location, + /// returning an [`ArraySliceValue`] encapsulating the resulting array. + fn array_alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + size: IntValue<'ctx>, + name: Option<&'ctx str>, + ) -> ArraySliceValue<'ctx> { + ArraySliceValue::from_ptr_val( + ctx.builder + .build_array_alloca( + self.alloca_type().as_basic_type_enum(), + size, + name.unwrap_or_default(), + ) + .unwrap(), + size, + name, + ) + } + + /// Creates a new array value of this type by invoking `alloca` at the beginning of the + /// function, returning an [`ArraySliceValue`] encapsulating the resulting array. + fn array_alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, size: IntValue<'ctx>, name: Option<&'ctx str>, - ) -> ArraySliceValue<'ctx>; + ) -> ArraySliceValue<'ctx> { + generator + .gen_array_var_alloc(ctx, self.alloca_type().as_basic_type_enum(), size, name) + .unwrap() + } /// Returns the [base type][Self::Base] of this proxy. fn as_base_type(&self) -> Self::Base; diff --git a/nac3core/src/codegen/types/ndarray/contiguous.rs b/nac3core/src/codegen/types/ndarray/contiguous.rs index 4be55474..5ef3e23c 100644 --- a/nac3core/src/codegen/types/ndarray/contiguous.rs +++ b/nac3core/src/codegen/types/ndarray/contiguous.rs @@ -16,7 +16,7 @@ use crate::{ }, ProxyType, }, - values::{ndarray::ContiguousNDArrayValue, ArraySliceValue, ProxyValue}, + values::{ndarray::ContiguousNDArrayValue, ProxyValue}, CodeGenContext, CodeGenerator, }, toplevel::numpy::unpack_ndarray_var_tys, @@ -159,14 +159,29 @@ impl<'ctx> ContiguousNDArrayType<'ctx> { /// Allocates an instance of [`ContiguousNDArrayValue`] as if by calling `alloca` on the base type. #[must_use] - pub fn alloca( + pub fn alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + name: Option<&'ctx str>, + ) -> >::Value { + >::Value::from_pointer_value( + self.raw_alloca(ctx, name), + self.item, + self.llvm_usize, + name, + ) + } + + /// Allocates an instance of [`ContiguousNDArrayValue`] as if by calling `alloca` on the base type. + #[must_use] + pub fn alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, name: Option<&'ctx str>, ) -> >::Value { >::Value::from_pointer_value( - self.raw_alloca(generator, ctx, name), + self.raw_alloca_var(generator, ctx, name), self.item, self.llvm_usize, name, @@ -213,36 +228,8 @@ impl<'ctx> ProxyType<'ctx> for ContiguousNDArrayType<'ctx> { Self::is_representable(llvm_ty, generator.get_size_type(ctx)) } - fn raw_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - name: Option<&'ctx str>, - ) -> PointerValue<'ctx> { - generator - .gen_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - name, - ) - .unwrap() - } - - fn array_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - size: IntValue<'ctx>, - name: Option<&'ctx str>, - ) -> ArraySliceValue<'ctx> { - generator - .gen_array_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - size, - name, - ) - .unwrap() + fn alloca_type(&self) -> impl BasicType<'ctx> { + self.as_base_type().get_element_type().into_struct_type() } fn as_base_type(&self) -> Self::Base { diff --git a/nac3core/src/codegen/types/ndarray/indexing.rs b/nac3core/src/codegen/types/ndarray/indexing.rs index 6bbd3e8b..41599847 100644 --- a/nac3core/src/codegen/types/ndarray/indexing.rs +++ b/nac3core/src/codegen/types/ndarray/indexing.rs @@ -91,14 +91,27 @@ impl<'ctx> NDIndexType<'ctx> { } #[must_use] - pub fn alloca( + pub fn alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + name: Option<&'ctx str>, + ) -> >::Value { + >::Value::from_pointer_value( + self.raw_alloca(ctx, name), + self.llvm_usize, + name, + ) + } + + #[must_use] + pub fn alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, name: Option<&'ctx str>, ) -> >::Value { >::Value::from_pointer_value( - self.raw_alloca(generator, ctx, name), + self.raw_alloca_var(generator, ctx, name), self.llvm_usize, name, ) @@ -114,7 +127,7 @@ impl<'ctx> NDIndexType<'ctx> { ) -> ArraySliceValue<'ctx> { // Allocate the LLVM ndindices. let num_ndindices = self.llvm_usize.const_int(in_ndindices.len() as u64, false); - let ndindices = self.array_alloca(generator, ctx, num_ndindices, None); + let ndindices = self.array_alloca_var(generator, ctx, num_ndindices, None); // Initialize all of them. for (i, in_ndindex) in in_ndindices.iter().enumerate() { @@ -171,36 +184,8 @@ impl<'ctx> ProxyType<'ctx> for NDIndexType<'ctx> { Self::is_representable(llvm_ty, generator.get_size_type(ctx)) } - fn raw_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - name: Option<&'ctx str>, - ) -> PointerValue<'ctx> { - generator - .gen_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - name, - ) - .unwrap() - } - - fn array_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - size: IntValue<'ctx>, - name: Option<&'ctx str>, - ) -> ArraySliceValue<'ctx> { - generator - .gen_array_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - size, - name, - ) - .unwrap() + fn alloca_type(&self) -> impl BasicType<'ctx> { + self.as_base_type().get_element_type().into_struct_type() } fn as_base_type(&self) -> Self::Base { diff --git a/nac3core/src/codegen/types/ndarray/mod.rs b/nac3core/src/codegen/types/ndarray/mod.rs index b655f352..5037c087 100644 --- a/nac3core/src/codegen/types/ndarray/mod.rs +++ b/nac3core/src/codegen/types/ndarray/mod.rs @@ -14,7 +14,7 @@ use super::{ }; use crate::{ codegen::{ - values::{ndarray::NDArrayValue, ArraySliceValue, ProxyValue, TypedArrayLikeMutator}, + values::{ndarray::NDArrayValue, ProxyValue, TypedArrayLikeMutator}, {CodeGenContext, CodeGenerator}, }, toplevel::{helper::extract_ndims, numpy::unpack_ndarray_var_tys}, @@ -183,14 +183,30 @@ impl<'ctx> NDArrayType<'ctx> { /// Allocates an instance of [`NDArrayValue`] as if by calling `alloca` on the base type. #[must_use] - pub fn alloca( + pub fn alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + name: Option<&'ctx str>, + ) -> >::Value { + >::Value::from_pointer_value( + self.raw_alloca(ctx, name), + self.dtype, + self.ndims, + self.llvm_usize, + name, + ) + } + + /// Allocates an instance of [`NDArrayValue`] as if by calling `alloca` on the base type. + #[must_use] + pub fn alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, name: Option<&'ctx str>, ) -> >::Value { >::Value::from_pointer_value( - self.raw_alloca(generator, ctx, name), + self.raw_alloca_var(generator, ctx, name), self.dtype, self.ndims, self.llvm_usize, @@ -214,7 +230,7 @@ impl<'ctx> NDArrayType<'ctx> { ndims: IntValue<'ctx>, name: Option<&'ctx str>, ) -> >::Value { - let ndarray = self.alloca(generator, ctx, name); + let ndarray = self.alloca_var(generator, ctx, name); let itemsize = ctx .builder @@ -425,36 +441,8 @@ impl<'ctx> ProxyType<'ctx> for NDArrayType<'ctx> { Self::is_representable(llvm_ty, generator.get_size_type(ctx)) } - fn raw_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - name: Option<&'ctx str>, - ) -> PointerValue<'ctx> { - generator - .gen_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - name, - ) - .unwrap() - } - - fn array_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - size: IntValue<'ctx>, - name: Option<&'ctx str>, - ) -> ArraySliceValue<'ctx> { - generator - .gen_array_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - size, - name, - ) - .unwrap() + fn alloca_type(&self) -> impl BasicType<'ctx> { + self.as_base_type().get_element_type().into_struct_type() } fn as_base_type(&self) -> Self::Base { diff --git a/nac3core/src/codegen/types/ndarray/nditer.rs b/nac3core/src/codegen/types/ndarray/nditer.rs index ed98aa4b..bcb8c571 100644 --- a/nac3core/src/codegen/types/ndarray/nditer.rs +++ b/nac3core/src/codegen/types/ndarray/nditer.rs @@ -110,7 +110,24 @@ impl<'ctx> NDIterType<'ctx> { } #[must_use] - pub fn alloca( + pub fn alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + parent: NDArrayValue<'ctx>, + indices: ArraySliceValue<'ctx>, + name: Option<&'ctx str>, + ) -> >::Value { + >::Value::from_pointer_value( + self.raw_alloca(ctx, name), + parent, + indices, + self.llvm_usize, + name, + ) + } + + #[must_use] + pub fn alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, @@ -119,7 +136,7 @@ impl<'ctx> NDIterType<'ctx> { name: Option<&'ctx str>, ) -> >::Value { >::Value::from_pointer_value( - self.raw_alloca(generator, ctx, name), + self.raw_alloca_var(generator, ctx, name), parent, indices, self.llvm_usize, @@ -140,7 +157,7 @@ impl<'ctx> NDIterType<'ctx> { ctx: &mut CodeGenContext<'ctx, '_>, ndarray: NDArrayValue<'ctx>, ) -> >::Value { - let nditer = self.raw_alloca(generator, ctx, None); + let nditer = self.raw_alloca_var(generator, ctx, None); let ndims = ndarray.load_ndims(ctx); // The caller has the responsibility to allocate 'indices' for `NDIter`. @@ -198,36 +215,8 @@ impl<'ctx> ProxyType<'ctx> for NDIterType<'ctx> { Self::is_representable(llvm_ty, generator.get_size_type(ctx)) } - fn raw_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - name: Option<&'ctx str>, - ) -> PointerValue<'ctx> { - generator - .gen_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - name, - ) - .unwrap() - } - - fn array_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - size: IntValue<'ctx>, - name: Option<&'ctx str>, - ) -> ArraySliceValue<'ctx> { - generator - .gen_array_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - size, - name, - ) - .unwrap() + fn alloca_type(&self) -> impl BasicType<'ctx> { + self.as_base_type().get_element_type().into_struct_type() } fn as_base_type(&self) -> Self::Base { diff --git a/nac3core/src/codegen/types/range.rs b/nac3core/src/codegen/types/range.rs index dc241b6e..4bd6f3cf 100644 --- a/nac3core/src/codegen/types/range.rs +++ b/nac3core/src/codegen/types/range.rs @@ -1,13 +1,12 @@ use inkwell::{ context::Context, types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType}, - values::{IntValue, PointerValue}, AddressSpace, }; use super::ProxyType; use crate::codegen::{ - values::{ArraySliceValue, ProxyValue, RangeValue}, + values::{ProxyValue, RangeValue}, {CodeGenContext, CodeGenerator}, }; @@ -80,13 +79,23 @@ impl<'ctx> RangeType<'ctx> { /// Allocates an instance of [`RangeValue`] as if by calling `alloca` on the base type. #[must_use] pub fn alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + name: Option<&'ctx str>, + ) -> >::Value { + >::Value::from_pointer_value(self.raw_alloca(ctx, name), name) + } + + /// Allocates an instance of [`RangeValue`] as if by calling `alloca` on the base type. + #[must_use] + pub fn alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, name: Option<&'ctx str>, ) -> >::Value { >::Value::from_pointer_value( - self.raw_alloca(generator, ctx, name), + self.raw_alloca_var(generator, ctx, name), name, ) } @@ -126,36 +135,8 @@ impl<'ctx> ProxyType<'ctx> for RangeType<'ctx> { Self::is_representable(llvm_ty) } - fn raw_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - name: Option<&'ctx str>, - ) -> PointerValue<'ctx> { - generator - .gen_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - name, - ) - .unwrap() - } - - fn array_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - size: IntValue<'ctx>, - name: Option<&'ctx str>, - ) -> ArraySliceValue<'ctx> { - generator - .gen_array_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - size, - name, - ) - .unwrap() + fn alloca_type(&self) -> impl BasicType<'ctx> { + self.as_base_type().get_element_type().into_struct_type() } fn as_base_type(&self) -> Self::Base { diff --git a/nac3core/src/codegen/types/utils/slice.rs b/nac3core/src/codegen/types/utils/slice.rs index dd7643f7..034f3756 100644 --- a/nac3core/src/codegen/types/utils/slice.rs +++ b/nac3core/src/codegen/types/utils/slice.rs @@ -1,7 +1,7 @@ use inkwell::{ context::{AsContextRef, Context, ContextRef}, types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType}, - values::{IntValue, PointerValue}, + values::IntValue, AddressSpace, }; use itertools::Itertools; @@ -15,7 +15,7 @@ use crate::codegen::{ }, ProxyType, }, - values::{utils::SliceValue, ArraySliceValue, ProxyValue}, + values::{utils::SliceValue, ProxyValue}, CodeGenContext, CodeGenerator, }; @@ -156,14 +156,29 @@ impl<'ctx> SliceType<'ctx> { /// Allocates an instance of [`ContiguousNDArrayValue`] as if by calling `alloca` on the base type. #[must_use] - pub fn alloca( + pub fn alloca( + &self, + ctx: &mut CodeGenContext<'ctx, '_>, + name: Option<&'ctx str>, + ) -> >::Value { + >::Value::from_pointer_value( + self.raw_alloca(ctx, name), + self.int_ty, + self.llvm_usize, + name, + ) + } + + /// Allocates an instance of [`ContiguousNDArrayValue`] as if by calling `alloca` on the base type. + #[must_use] + pub fn alloca_var( &self, generator: &mut G, ctx: &mut CodeGenContext<'ctx, '_>, name: Option<&'ctx str>, ) -> >::Value { >::Value::from_pointer_value( - self.raw_alloca(generator, ctx, name), + self.raw_alloca_var(generator, ctx, name), self.int_ty, self.llvm_usize, name, @@ -210,36 +225,8 @@ impl<'ctx> ProxyType<'ctx> for SliceType<'ctx> { Self::is_representable(llvm_ty, generator.get_size_type(ctx)) } - fn raw_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - name: Option<&'ctx str>, - ) -> PointerValue<'ctx> { - generator - .gen_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - name, - ) - .unwrap() - } - - fn array_alloca( - &self, - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - size: IntValue<'ctx>, - name: Option<&'ctx str>, - ) -> ArraySliceValue<'ctx> { - generator - .gen_array_var_alloc( - ctx, - self.as_base_type().get_element_type().into_struct_type().into(), - size, - name, - ) - .unwrap() + fn alloca_type(&self) -> impl BasicType<'ctx> { + self.as_base_type().get_element_type().into_struct_type() } fn as_base_type(&self) -> Self::Base { diff --git a/nac3core/src/codegen/values/ndarray/contiguous.rs b/nac3core/src/codegen/values/ndarray/contiguous.rs index 87e2f1d8..f3b03dd1 100644 --- a/nac3core/src/codegen/values/ndarray/contiguous.rs +++ b/nac3core/src/codegen/values/ndarray/contiguous.rs @@ -118,7 +118,7 @@ impl<'ctx> NDArrayValue<'ctx> { ctx: &mut CodeGenContext<'ctx, '_>, ) -> ContiguousNDArrayValue<'ctx> { let result = ContiguousNDArrayType::new(generator, ctx.ctx, self.dtype) - .alloca(generator, ctx, self.name); + .alloca_var(generator, ctx, self.name); // Set ndims and shape. let ndims = self diff --git a/nac3core/src/codegen/values/ndarray/indexing.rs b/nac3core/src/codegen/values/ndarray/indexing.rs index 69c00807..3d575028 100644 --- a/nac3core/src/codegen/values/ndarray/indexing.rs +++ b/nac3core/src/codegen/values/ndarray/indexing.rs @@ -248,7 +248,7 @@ impl<'ctx> RustNDIndex<'ctx> { RustNDIndex::Slice(in_rust_slice) => { let user_slice_ptr = SliceType::new(ctx.ctx, ctx.ctx.i32_type(), generator.get_size_type(ctx.ctx)) - .alloca(generator, ctx, None); + .alloca_var(generator, ctx, None); in_rust_slice.write_to_slice(ctx, user_slice_ptr); dst_ndindex.store_data(