diff --git a/crates/compiler/can/src/builtins.rs b/crates/compiler/can/src/builtins.rs index 9d24d154de5..bda1d64dab5 100644 --- a/crates/compiler/can/src/builtins.rs +++ b/crates/compiler/can/src/builtins.rs @@ -88,7 +88,6 @@ macro_rules! map_symbol_to_lowlevel_and_arity { LowLevel::PtrStore => unimplemented!(), LowLevel::PtrLoad => unimplemented!(), LowLevel::PtrClearTagId => unimplemented!(), - LowLevel::Alloca => unimplemented!(), LowLevel::RefCountIncRcPtr => unimplemented!(), LowLevel::RefCountDecRcPtr=> unimplemented!(), LowLevel::RefCountIncDataPtr => unimplemented!(), diff --git a/crates/compiler/gen_dev/src/lib.rs b/crates/compiler/gen_dev/src/lib.rs index c2af72ce992..90b2d0cf9d1 100644 --- a/crates/compiler/gen_dev/src/lib.rs +++ b/crates/compiler/gen_dev/src/lib.rs @@ -1626,10 +1626,6 @@ trait Backend<'a> { self.build_ptr_clear_tag_id(*sym, args[0]); } - LowLevel::Alloca => { - self.build_alloca(*sym, Some(args[0]), arg_layouts[0]); - } - LowLevel::RefCountDecRcPtr => self.build_fn_call( sym, bitcode::UTILS_DECREF_RC_PTR.to_string(), diff --git a/crates/compiler/gen_llvm/src/llvm/lowlevel.rs b/crates/compiler/gen_llvm/src/llvm/lowlevel.rs index 1bf9d0287d6..5e79ec4abff 100644 --- a/crates/compiler/gen_llvm/src/llvm/lowlevel.rs +++ b/crates/compiler/gen_llvm/src/llvm/lowlevel.rs @@ -30,8 +30,8 @@ use crate::llvm::{ }, build::{ cast_basic_basic, complex_bitcast_check_size, create_entry_block_alloca, - entry_block_alloca_zerofill, function_value_by_func_spec, load_roc_value, - roc_function_call, tag_pointer_clear_tag_id, BuilderExt, FuncBorrowSpec, RocReturn, + function_value_by_func_spec, load_roc_value, roc_function_call, tag_pointer_clear_tag_id, + BuilderExt, FuncBorrowSpec, RocReturn, }, build_list::{ list_append_unsafe, list_concat, list_drop_at, list_get_unsafe, list_len, list_map, @@ -1331,16 +1331,6 @@ pub(crate) fn run_low_level<'a, 'ctx>( tag_pointer_clear_tag_id(env, ptr.into_pointer_value()).into() } - Alloca => { - arguments!(initial_value); - - let ptr = entry_block_alloca_zerofill(env, initial_value.get_type(), "stack_value"); - - env.builder.build_store(ptr, initial_value); - - ptr.into() - } - RefCountIncRcPtr | RefCountDecRcPtr | RefCountIncDataPtr | RefCountDecDataPtr => { unreachable!("Not used in LLVM backend: {:?}", op); } diff --git a/crates/compiler/gen_wasm/src/low_level.rs b/crates/compiler/gen_wasm/src/low_level.rs index 31e5ea84921..a8ee65f0f31 100644 --- a/crates/compiler/gen_wasm/src/low_level.rs +++ b/crates/compiler/gen_wasm/src/low_level.rs @@ -1992,42 +1992,6 @@ impl<'a> LowLevelCall<'a> { backend.code_builder.i32_const(-4); // 11111111...1100 backend.code_builder.i32_and(); } - Alloca => { - // Alloca : a -> Ptr a - let arg = self.arguments[0]; - let arg_layout = backend.storage.symbol_layouts.get(&arg).unwrap(); - - let (size, alignment_bytes) = backend - .layout_interner - .stack_size_and_alignment(*arg_layout); - - let (frame_ptr, offset) = backend - .storage - .allocate_anonymous_stack_memory(size, alignment_bytes); - - // write the default value into the stack memory - backend.storage.copy_value_to_memory( - &mut backend.code_builder, - frame_ptr, - offset, - arg, - ); - - // create a local variable for the pointer - let ptr_local_id = match backend.storage.ensure_value_has_local( - &mut backend.code_builder, - self.ret_symbol, - self.ret_storage.clone(), - ) { - StoredValue::Local { local_id, .. } => local_id, - _ => internal_error!("A pointer will always be an i32"), - }; - - backend.code_builder.get_local(frame_ptr); - backend.code_builder.i32_const(offset as i32); - backend.code_builder.i32_add(); - backend.code_builder.set_local(ptr_local_id); - } Hash => todo!("{:?}", self.lowlevel), diff --git a/crates/compiler/module/src/low_level.rs b/crates/compiler/module/src/low_level.rs index 3a4514a0696..8a6dfcef4c3 100644 --- a/crates/compiler/module/src/low_level.rs +++ b/crates/compiler/module/src/low_level.rs @@ -121,7 +121,6 @@ pub enum LowLevel { PtrStore, PtrLoad, PtrClearTagId, - Alloca, RefCountIncRcPtr, RefCountDecRcPtr, RefCountIncDataPtr, @@ -237,7 +236,6 @@ macro_rules! map_symbol_to_lowlevel { LowLevel::PtrStore => unimplemented!(), LowLevel::PtrLoad => unimplemented!(), LowLevel::PtrClearTagId => unimplemented!(), - LowLevel::Alloca => unimplemented!(), LowLevel::RefCountIncRcPtr => unimplemented!(), LowLevel::RefCountDecRcPtr=> unimplemented!(), LowLevel::RefCountIncDataPtr => unimplemented!(), diff --git a/crates/compiler/mono/src/borrow.rs b/crates/compiler/mono/src/borrow.rs index 877e619fd58..aa8c6b8e942 100644 --- a/crates/compiler/mono/src/borrow.rs +++ b/crates/compiler/mono/src/borrow.rs @@ -1076,7 +1076,6 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[Ownership] { PtrStore => arena.alloc_slice_copy(&[owned, owned]), PtrLoad => arena.alloc_slice_copy(&[owned]), PtrCast => arena.alloc_slice_copy(&[owned]), - Alloca => arena.alloc_slice_copy(&[owned]), PtrClearTagId | RefCountIncRcPtr | RefCountDecRcPtr | RefCountIncDataPtr | RefCountDecDataPtr | RefCountIsUnique => { diff --git a/crates/compiler/mono/src/drop_specialization.rs b/crates/compiler/mono/src/drop_specialization.rs index a9898006ddb..7e2e3899fd2 100644 --- a/crates/compiler/mono/src/drop_specialization.rs +++ b/crates/compiler/mono/src/drop_specialization.rs @@ -1615,7 +1615,6 @@ fn low_level_no_rc(lowlevel: &LowLevel) -> RC { PtrStore => RC::NoRc, PtrLoad => RC::NoRc, PtrCast => RC::NoRc, - Alloca => RC::NoRc, PtrClearTagId | RefCountIncRcPtr | RefCountDecRcPtr | RefCountIncDataPtr | RefCountDecDataPtr | RefCountIsUnique => { diff --git a/crates/compiler/mono/src/inc_dec.rs b/crates/compiler/mono/src/inc_dec.rs index c578e96b2ae..17fef2059f6 100644 --- a/crates/compiler/mono/src/inc_dec.rs +++ b/crates/compiler/mono/src/inc_dec.rs @@ -1123,8 +1123,10 @@ fn insert_refcount_operations_binding<'a>( Expr::Reset { .. } | Expr::ResetRef { .. } => { unreachable!("Reset(ref) should not exist at this point") } - Expr::Alloca { .. } => { - unreachable!("Alloca should not exist at this point") + Expr::Alloca { initializer, .. } => { + let new_let = new_let!(stmt); + + inc_owned!(initializer.as_ref().copied().into_iter(), new_let) } } } diff --git a/crates/compiler/mono/src/tail_recursion.rs b/crates/compiler/mono/src/tail_recursion.rs index dae54729e71..2b317f29068 100644 --- a/crates/compiler/mono/src/tail_recursion.rs +++ b/crates/compiler/mono/src/tail_recursion.rs @@ -744,15 +744,10 @@ impl<'a> TrmcEnv<'a> { .interner .insert_direct_no_semantic(LayoutRepr::Ptr(return_layout)); - let call = Call { - call_type: CallType::LowLevel { - op: LowLevel::Alloca, - update_mode: UpdateModeId::BACKEND_DUMMY, - }, - arguments: arena.alloc([null_symbol]), + let ptr_null = Expr::Alloca { + initializer: Some(null_symbol), + element_layout: return_layout, }; - - let ptr_null = Expr::Call(call); let let_ptr = |next| Stmt::Let(initial_ptr_symbol, ptr_null, ptr_return_layout, next); let joinpoint_id = JoinPointId(env.named_unique_symbol("trmc"));