mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
get rid of InPlace
This commit is contained in:
parent
3ba643df70
commit
af4ee51560
4 changed files with 26 additions and 80 deletions
|
@ -52,7 +52,7 @@ use roc_mono::ir::{
|
|||
BranchInfo, CallType, EntryPoint, ExceptionId, JoinPointId, ModifyRc, OptLevel, ProcLayout,
|
||||
Wrapped,
|
||||
};
|
||||
use roc_mono::layout::{Builtin, InPlace, LambdaSet, Layout, LayoutIds, UnionLayout};
|
||||
use roc_mono::layout::{Builtin, LambdaSet, Layout, LayoutIds, UnionLayout};
|
||||
|
||||
/// This is for Inkwell's FunctionValue::verify - we want to know the verification
|
||||
/// output in debug builds, but we don't want it to print to stdout in release builds!
|
||||
|
@ -1637,9 +1637,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
}
|
||||
}
|
||||
EmptyArray => empty_polymorphic_list(env),
|
||||
Array { elem_layout, elems } => {
|
||||
list_literal(env, layout.in_place(), scope, elem_layout, elems)
|
||||
}
|
||||
Array { elem_layout, elems } => list_literal(env, scope, elem_layout, elems),
|
||||
RuntimeErrorFunction(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
@ -1793,7 +1791,6 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>(
|
|||
|
||||
fn list_literal<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
inplace: InPlace,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
elem_layout: &Layout<'a>,
|
||||
elems: &&[Symbol],
|
||||
|
@ -1807,7 +1804,7 @@ fn list_literal<'a, 'ctx, 'env>(
|
|||
let len_type = env.ptr_int();
|
||||
let len = len_type.const_int(len_u64, false);
|
||||
|
||||
allocate_list(env, inplace, elem_layout, len)
|
||||
allocate_list(env, elem_layout, len)
|
||||
};
|
||||
|
||||
// Copy the elements from the list literal into the array
|
||||
|
@ -4164,13 +4161,13 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
// Str.concat : Str, Str -> Str
|
||||
debug_assert_eq!(args.len(), 2);
|
||||
|
||||
str_concat(env, layout.in_place(), scope, args[0], args[1])
|
||||
str_concat(env, scope, args[0], args[1])
|
||||
}
|
||||
StrJoinWith => {
|
||||
// Str.joinWith : List Str, Str -> Str
|
||||
debug_assert_eq!(args.len(), 2);
|
||||
|
||||
str_join_with(env, layout.in_place(), scope, args[0], args[1])
|
||||
str_join_with(env, scope, args[0], args[1])
|
||||
}
|
||||
StrStartsWith => {
|
||||
// Str.startsWith : Str, Str -> Bool
|
||||
|
@ -4224,7 +4221,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
// Str.split : Str, Str -> List Str
|
||||
debug_assert_eq!(args.len(), 2);
|
||||
|
||||
str_split(env, scope, layout.in_place(), args[0], args[1])
|
||||
str_split(env, scope, args[0], args[1])
|
||||
}
|
||||
StrIsEmpty => {
|
||||
// Str.isEmpty : Str -> Str
|
||||
|
@ -4259,7 +4256,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
|
||||
let (arg, arg_layout) = load_symbol_and_layout(scope, &args[0]);
|
||||
|
||||
list_single(env, layout.in_place(), arg, arg_layout)
|
||||
list_single(env, arg, arg_layout)
|
||||
}
|
||||
ListRepeat => {
|
||||
// List.repeat : Int, elem -> List elem
|
||||
|
@ -4276,7 +4273,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
|
||||
let (list, list_layout) = load_symbol_and_layout(scope, &args[0]);
|
||||
|
||||
list_reverse(env, layout.in_place(), list, list_layout)
|
||||
list_reverse(env, list, list_layout)
|
||||
}
|
||||
ListConcat => {
|
||||
debug_assert_eq!(args.len(), 2);
|
||||
|
@ -4285,14 +4282,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
|
||||
let second_list = load_symbol(scope, &args[1]);
|
||||
|
||||
list_concat(
|
||||
env,
|
||||
layout.in_place(),
|
||||
parent,
|
||||
first_list,
|
||||
second_list,
|
||||
list_layout,
|
||||
)
|
||||
list_concat(env, parent, first_list, second_list, list_layout)
|
||||
}
|
||||
ListContains => {
|
||||
// List.contains : List elem, elem -> Bool
|
||||
|
@ -4325,7 +4315,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
let original_wrapper = load_symbol(scope, &args[0]).into_struct_value();
|
||||
let (elem, elem_layout) = load_symbol_and_layout(scope, &args[1]);
|
||||
|
||||
list_append(env, layout.in_place(), original_wrapper, elem, elem_layout)
|
||||
list_append(env, original_wrapper, elem, elem_layout)
|
||||
}
|
||||
ListSwap => {
|
||||
// List.swap : List elem, Nat, Nat -> List elem
|
||||
|
@ -4377,7 +4367,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
let original_wrapper = load_symbol(scope, &args[0]).into_struct_value();
|
||||
let (elem, elem_layout) = load_symbol_and_layout(scope, &args[1]);
|
||||
|
||||
list_prepend(env, layout.in_place(), original_wrapper, elem, elem_layout)
|
||||
list_prepend(env, original_wrapper, elem, elem_layout)
|
||||
}
|
||||
ListJoin => {
|
||||
// List.join : List (List elem) -> List elem
|
||||
|
@ -4385,7 +4375,7 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
|
||||
let (list, outer_list_layout) = load_symbol_and_layout(scope, &args[0]);
|
||||
|
||||
list_join(env, layout.in_place(), parent, list, outer_list_layout)
|
||||
list_join(env, parent, list, outer_list_layout)
|
||||
}
|
||||
NumAbs | NumNeg | NumRound | NumSqrtUnchecked | NumLogUnchecked | NumSin | NumCos
|
||||
| NumCeiling | NumFloor | NumToFloat | NumIsFinite | NumAtan | NumAcos | NumAsin => {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
};
|
||||
let rc1 = crate::llvm::refcounting::refcount_1(ctx, env.ptr_bytes);
|
||||
|
||||
allocate_with_refcount_help(env, elem_layout, number_of_data_bytes, rc1)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue, Str
|
|||
use inkwell::AddressSpace;
|
||||
use roc_builtins::bitcode;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::layout::{Builtin, InPlace, Layout};
|
||||
use roc_mono::layout::{Builtin, Layout};
|
||||
|
||||
use super::build::load_symbol;
|
||||
|
||||
|
@ -16,7 +16,6 @@ pub static CHAR_LAYOUT: Layout = Layout::Builtin(Builtin::Int8);
|
|||
pub fn str_split<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
inplace: InPlace,
|
||||
str_symbol: Symbol,
|
||||
delimiter_symbol: Symbol,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
|
@ -33,7 +32,7 @@ pub fn str_split<'a, 'ctx, 'env>(
|
|||
.into_int_value();
|
||||
|
||||
// a pointer to the elements
|
||||
let ret_list_ptr = allocate_list(env, inplace, &Layout::Builtin(Builtin::Str), segment_count);
|
||||
let ret_list_ptr = allocate_list(env, &Layout::Builtin(Builtin::Str), segment_count);
|
||||
|
||||
// get the RocStr type defined by zig
|
||||
let roc_str_type = env.module.get_struct_type("str.RocStr").unwrap();
|
||||
|
@ -109,7 +108,6 @@ pub fn destructure<'ctx>(
|
|||
/// Str.concat : Str, Str -> Str
|
||||
pub fn str_concat<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
inplace: InPlace,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
str1_symbol: Symbol,
|
||||
str2_symbol: Symbol,
|
||||
|
@ -120,14 +118,7 @@ pub fn str_concat<'a, 'ctx, 'env>(
|
|||
|
||||
call_bitcode_fn(
|
||||
env,
|
||||
&[
|
||||
env.context
|
||||
.i8_type()
|
||||
.const_int(inplace as u64, false)
|
||||
.into(),
|
||||
str1_i128.into(),
|
||||
str2_i128.into(),
|
||||
],
|
||||
&[str1_i128.into(), str2_i128.into()],
|
||||
&bitcode::STR_CONCAT,
|
||||
)
|
||||
}
|
||||
|
@ -135,7 +126,6 @@ pub fn str_concat<'a, 'ctx, 'env>(
|
|||
/// Str.join : List Str, Str -> Str
|
||||
pub fn str_join_with<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
_inplace: InPlace,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
list_symbol: Symbol,
|
||||
str_symbol: Symbol,
|
||||
|
|
|
@ -20,13 +20,6 @@ impl Layout<'_> {
|
|||
pub const TAG_SIZE: Layout<'static> = Layout::Builtin(Builtin::Int64);
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(u8)]
|
||||
pub enum InPlace {
|
||||
InPlace,
|
||||
Clone,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum LayoutProblem {
|
||||
UnresolvedTypeVar(Variable),
|
||||
|
@ -60,19 +53,6 @@ pub enum Layout<'a> {
|
|||
Closure(&'a [Layout<'a>], LambdaSet<'a>, &'a Layout<'a>),
|
||||
}
|
||||
|
||||
impl<'a> Layout<'a> {
|
||||
pub fn in_place(&self) -> InPlace {
|
||||
match self {
|
||||
Layout::Builtin(Builtin::EmptyList) => InPlace::InPlace,
|
||||
Layout::Builtin(Builtin::List(_)) => InPlace::Clone,
|
||||
Layout::Builtin(Builtin::EmptyStr) => InPlace::InPlace,
|
||||
Layout::Builtin(Builtin::Str) => InPlace::Clone,
|
||||
Layout::Builtin(Builtin::Int1) => InPlace::Clone,
|
||||
_ => unreachable!("Layout {:?} does not have an inplace", self),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum UnionLayout<'a> {
|
||||
/// A non-recursive tag union
|
||||
|
@ -720,8 +700,6 @@ impl<'a> CachedVariable<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
// use ven_ena::unify::{InPlace, Snapshot, UnificationTable, UnifyKey};
|
||||
|
||||
impl<'a> ven_ena::unify::UnifyKey for CachedVariable<'a> {
|
||||
type Value = CachedLayout<'a>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue