Skip to content

Commit dc679a8

Browse files
committed
Fixed experimental usage of static-alloc
1 parent 06bf2b2 commit dc679a8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/types/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use llvm_sys::core::LLVMDumpType;
3737
use llvm_sys::core::{LLVMAlignOf, LLVMGetTypeContext, LLVMFunctionType, LLVMArrayType, LLVMGetUndef, LLVMPointerType, LLVMPrintTypeToString, LLVMTypeIsSized, LLVMSizeOf, LLVMVectorType, LLVMGetElementType, LLVMConstNull};
3838
use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef};
3939
#[cfg(feature = "experimental")]
40-
use static_alloc::Slab;
40+
use static_alloc::Bump;
4141

4242
use std::fmt;
4343
use std::marker::PhantomData;
@@ -115,15 +115,19 @@ impl<'ctx> Type<'ctx> {
115115

116116
#[cfg(feature = "experimental")]
117117
fn fn_type(&self, param_types: &[BasicTypeEnum<'ctx>], is_var_args: bool) -> FunctionType<'ctx> {
118-
let pool: Slab<[usize; 16]> = Slab::uninit();
119-
let mut fixed_vec = pool.fixed_vec(param_types.len()).expect("Found more than 16 params");
118+
let pool: Bump<[usize; 16]> = Bump::uninit();
119+
let mut pool_start = None;
120120

121-
for param_type in param_types {
122-
fixed_vec.push(param_type.as_type_ref()).expect("Unexpected error");
121+
for (i, param_type) in param_types.iter().enumerate() {
122+
let addr = pool.leak(param_type.as_type_ref()).expect("Found more than 16 params");
123+
124+
if i == 0 {
125+
pool_start = Some(addr as *mut _);
126+
}
123127
}
124128

125129
let fn_type = unsafe {
126-
LLVMFunctionType(self.ty, fixed_vec.as_mut_ptr(), fixed_vec.len() as u32, is_var_args as i32)
130+
LLVMFunctionType(self.ty, pool_start.unwrap_or(std::ptr::null_mut()), param_types.len() as u32, is_var_args as i32)
127131
};
128132

129133
FunctionType::new(fn_type)

0 commit comments

Comments
 (0)