remove Boxed layout

This commit is contained in:
Folkert 2023-07-05 18:57:29 +02:00
parent d64930c17f
commit 6d2d65bb1e
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
24 changed files with 52 additions and 1377 deletions

View file

@ -120,7 +120,7 @@ impl<'a> LlvmAlignment<'a> for LayoutRepr<'a> {
.llvm_alignment_bytes(interner),
Builtin(builtin) => builtin.llvm_alignment_bytes(interner),
RecursivePointer(_) => interner.target_info().ptr_width() as u32,
Ptr(_) | Boxed(_) => interner.target_info().ptr_width() as u32,
Ptr(_) => interner.target_info().ptr_width() as u32,
}
}
}

View file

@ -179,7 +179,7 @@ fn build_eq<'a, 'ctx>(
rhs_val,
),
LayoutRepr::Ptr(inner_layout) | LayoutRepr::Boxed(inner_layout) => build_box_eq(
LayoutRepr::Ptr(inner_layout) => build_box_eq(
env,
layout_interner,
layout_ids,
@ -379,7 +379,7 @@ fn build_neq<'a, 'ctx>(
result.into()
}
LayoutRepr::Ptr(inner_layout) | LayoutRepr::Boxed(inner_layout) => {
LayoutRepr::Ptr(inner_layout) => {
let is_equal = build_box_eq(
env,
layout_interner,

View file

@ -31,7 +31,7 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>(
layout_interner.get_repr(lambda_set.runtime_representation()),
),
Ptr(inner_layout) | Boxed(inner_layout) => {
Ptr(inner_layout) => {
let inner_type = basic_type_from_layout(
env,
layout_interner,

View file

@ -18,7 +18,7 @@ use roc_mono::layout::{
use roc_region::all::Region;
use super::build::BuilderExt;
use super::build::{add_func, load_roc_value, FunctionSpec, LlvmBackendMode};
use super::build::{add_func, FunctionSpec, LlvmBackendMode};
use super::convert::struct_type_from_union_layout;
use super::scope::Scope;
use super::struct_::RocStruct;
@ -353,43 +353,6 @@ fn build_clone<'a, 'ctx>(
}
}
LayoutRepr::Boxed(inner_layout) => {
// write the offset
build_copy(env, ptr, cursors.offset, cursors.extra_offset.into());
let source = value.into_pointer_value();
let value = load_roc_value(
env,
layout_interner,
layout_interner.get_repr(inner_layout),
source,
"inner",
);
let inner_width = env
.ptr_int()
.const_int(layout_interner.stack_size(inner_layout) as u64, false);
let new_extra = env
.builder
.build_int_add(cursors.offset, inner_width, "new_extra");
let cursors = Cursors {
offset: cursors.extra_offset,
extra_offset: new_extra,
};
build_clone(
env,
layout_interner,
layout_ids,
ptr,
cursors,
value,
layout_interner.get_repr(inner_layout),
)
}
LayoutRepr::Ptr(_) => {
unreachable!("for internal use only")
}

View file

@ -561,12 +561,6 @@ fn modify_refcount_layout_build_function<'a, 'ctx>(
modify_refcount_builtin(env, layout_interner, layout_ids, mode, layout, &builtin)
}
Boxed(inner) => {
let function = modify_refcount_boxed(env, layout_interner, layout_ids, mode, inner);
Some(function)
}
Ptr(_inner) => {
debug_assert_eq!(true, false);
@ -897,130 +891,6 @@ fn modify_refcount_str_help<'a, 'ctx>(
builder.build_return(None);
}
fn modify_refcount_boxed<'a, 'ctx>(
env: &Env<'a, 'ctx, '_>,
layout_interner: &STLayoutInterner<'a>,
layout_ids: &mut LayoutIds<'a>,
mode: Mode,
inner_layout: InLayout<'a>,
) -> FunctionValue<'ctx> {
let block = env.builder.get_insert_block().expect("to be in a function");
let di_location = env.builder.get_current_debug_location().unwrap();
let boxed_layout = LayoutRepr::Boxed(inner_layout);
let (_, fn_name) = function_name_from_mode(
layout_ids,
&env.interns,
"increment_boxed",
"decrement_boxed",
boxed_layout,
mode,
);
let function = match env.module.get_function(fn_name.as_str()) {
Some(function_value) => function_value,
None => {
let basic_type = basic_type_from_layout(env, layout_interner, boxed_layout);
let function_value = build_header(env, basic_type, mode, &fn_name);
modify_refcount_box_help(
env,
layout_interner,
layout_ids,
mode,
inner_layout,
function_value,
);
function_value
}
};
env.builder.position_at_end(block);
env.builder.set_current_debug_location(di_location);
function
}
fn modify_refcount_box_help<'a, 'ctx>(
env: &Env<'a, 'ctx, '_>,
layout_interner: &STLayoutInterner<'a>,
layout_ids: &mut LayoutIds<'a>,
mode: Mode,
inner_layout: InLayout<'a>,
fn_val: FunctionValue<'ctx>,
) {
let builder = env.builder;
let ctx = env.context;
// Add a basic block for the entry point
let entry = ctx.append_basic_block(fn_val, "entry");
builder.position_at_end(entry);
debug_info_init!(env, fn_val);
// Add args to scope
let arg_symbol = Symbol::ARG_1;
let arg_val = fn_val.get_param_iter().next().unwrap();
arg_val.set_name(arg_symbol.as_str(&env.interns));
let boxed = arg_val.into_pointer_value();
let refcount_ptr = PointerToRefcount::from_ptr_to_data(env, boxed);
let call_mode = mode_to_call_mode(fn_val, mode);
let boxed_layout = LayoutRepr::Boxed(inner_layout);
match mode {
Mode::Inc => {
refcount_ptr.modify(call_mode, boxed_layout, env, layout_interner);
builder.build_return(None);
}
Mode::Dec => {
// if the box is unique, also decrement its inner value
let do_recurse_block = env.context.append_basic_block(fn_val, "do_recurse");
let no_recurse_block = env.context.append_basic_block(fn_val, "no_recurse");
builder.build_conditional_branch(
refcount_ptr.is_1(env),
do_recurse_block,
no_recurse_block,
);
{
env.builder.position_at_end(do_recurse_block);
let inner = load_roc_value(
env,
layout_interner,
layout_interner.get_repr(inner_layout),
boxed,
"inner",
);
modify_refcount_layout(
env,
layout_interner,
layout_ids,
call_mode,
inner,
inner_layout,
);
refcount_ptr.modify(call_mode, boxed_layout, env, layout_interner);
env.builder.build_return(None);
}
{
env.builder.position_at_end(no_recurse_block);
refcount_ptr.modify(call_mode, boxed_layout, env, layout_interner);
env.builder.build_return(None);
}
}
}
}
/// Build an increment or decrement function for a specific layout
fn build_header<'ctx>(
env: &Env<'_, 'ctx, '_>,