mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
get rid of InPlace
This commit is contained in:
parent
3ba643df70
commit
af4ee51560
4 changed files with 26 additions and 80 deletions
|
@ -14,7 +14,7 @@ use inkwell::types::{BasicType, BasicTypeEnum, PointerType};
|
|||
use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue, StructValue};
|
||||
use inkwell::{AddressSpace, IntPredicate};
|
||||
use roc_builtins::bitcode;
|
||||
use roc_mono::layout::{Builtin, InPlace, Layout, LayoutIds};
|
||||
use roc_mono::layout::{Builtin, Layout, LayoutIds};
|
||||
|
||||
fn list_returned_from_zig<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
|
@ -83,7 +83,6 @@ pub fn pass_as_opaque<'a, 'ctx, 'env>(
|
|||
/// List.single : a -> List a
|
||||
pub fn list_single<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
_inplace: InPlace,
|
||||
element: BasicValueEnum<'ctx>,
|
||||
element_layout: &Layout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
|
@ -124,7 +123,6 @@ pub fn list_repeat<'a, 'ctx, 'env>(
|
|||
/// List.prepend : List elem, elem -> List elem
|
||||
pub fn list_prepend<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
inplace: InPlace,
|
||||
original_wrapper: StructValue<'ctx>,
|
||||
elem: BasicValueEnum<'ctx>,
|
||||
elem_layout: &Layout<'a>,
|
||||
|
@ -146,7 +144,7 @@ pub fn list_prepend<'a, 'ctx, 'env>(
|
|||
);
|
||||
|
||||
// Allocate space for the new array that we'll copy into.
|
||||
let clone_ptr = allocate_list(env, inplace, elem_layout, new_list_len);
|
||||
let clone_ptr = allocate_list(env, elem_layout, new_list_len);
|
||||
|
||||
builder.build_store(clone_ptr, elem);
|
||||
|
||||
|
@ -189,7 +187,6 @@ pub fn list_prepend<'a, 'ctx, 'env>(
|
|||
/// List.join : List (List elem) -> List elem
|
||||
pub fn list_join<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
_inplace: InPlace,
|
||||
_parent: FunctionValue<'ctx>,
|
||||
outer_list: BasicValueEnum<'ctx>,
|
||||
outer_list_layout: &Layout<'a>,
|
||||
|
@ -221,17 +218,16 @@ pub fn list_join<'a, 'ctx, 'env>(
|
|||
/// List.reverse : List elem -> List elem
|
||||
pub fn list_reverse<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
_output_inplace: InPlace,
|
||||
list: BasicValueEnum<'ctx>,
|
||||
list_layout: &Layout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let (_, element_layout) = match *list_layout {
|
||||
Layout::Builtin(Builtin::EmptyList) => (
|
||||
InPlace::InPlace,
|
||||
let element_layout = match *list_layout {
|
||||
Layout::Builtin(Builtin::EmptyList) => {
|
||||
// this pointer will never actually be dereferenced
|
||||
Layout::Builtin(Builtin::Int64),
|
||||
),
|
||||
Layout::Builtin(Builtin::List(elem_layout)) => (InPlace::Clone, *elem_layout),
|
||||
Layout::Builtin(Builtin::Int64)
|
||||
}
|
||||
|
||||
Layout::Builtin(Builtin::List(elem_layout)) => *elem_layout,
|
||||
|
||||
_ => unreachable!("Invalid layout {:?} in List.reverse", list_layout),
|
||||
};
|
||||
|
@ -287,7 +283,6 @@ pub fn list_get_unsafe<'a, 'ctx, 'env>(
|
|||
/// List.append : List elem, elem -> List elem
|
||||
pub fn list_append<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
_inplace: InPlace,
|
||||
original_wrapper: StructValue<'ctx>,
|
||||
element: BasicValueEnum<'ctx>,
|
||||
element_layout: &Layout<'a>,
|
||||
|
@ -804,7 +799,6 @@ pub fn list_map3<'a, 'ctx, 'env>(
|
|||
/// List.concat : List elem, List elem -> List elem
|
||||
pub fn list_concat<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
_inplace: InPlace,
|
||||
_parent: FunctionValue<'ctx>,
|
||||
first_list: BasicValueEnum<'ctx>,
|
||||
second_list: BasicValueEnum<'ctx>,
|
||||
|
@ -1070,7 +1064,6 @@ pub fn load_list_ptr<'ctx>(
|
|||
|
||||
pub fn allocate_list<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
inplace: InPlace,
|
||||
elem_layout: &Layout<'a>,
|
||||
number_of_elements: IntValue<'ctx>,
|
||||
) -> PointerValue<'ctx> {
|
||||
|
@ -1083,14 +1076,9 @@ pub fn allocate_list<'a, 'ctx, 'env>(
|
|||
let number_of_data_bytes =
|
||||
builder.build_int_mul(bytes_per_element, number_of_elements, "data_length");
|
||||
|
||||
let rc1 = match inplace {
|
||||
InPlace::InPlace => number_of_elements,
|
||||
InPlace::Clone => {
|
||||
// the refcount of a new list is initially 1
|
||||
// we assume that the list is indeed used (dead variables are eliminated)
|
||||
crate::llvm::refcounting::refcount_1(ctx, env.ptr_bytes)
|
||||
}
|
||||
};
|
||||
// the refcount of a new list is initially 1
|
||||
// we assume that the list is indeed used (dead variables are eliminated)
|
||||
let rc1 = crate::llvm::refcounting::refcount_1(ctx, env.ptr_bytes);
|
||||
|
||||
allocate_with_refcount_help(env, elem_layout, number_of_data_bytes, rc1)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue