mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Add a Newtype variant to LayoutWrapper
This commit is contained in:
parent
dd94d6ba16
commit
5274dbcd00
22 changed files with 348 additions and 265 deletions
|
@ -1385,8 +1385,8 @@ pub fn build_exp_expr<'a, 'ctx>(
|
|||
|
||||
let field_layouts = tag_layouts[*tag_id as usize];
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let struct_layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let struct_type = basic_type_from_layout(env, layout_interner, struct_layout);
|
||||
|
||||
let opaque_data_ptr = env
|
||||
|
@ -1442,8 +1442,8 @@ pub fn build_exp_expr<'a, 'ctx>(
|
|||
)
|
||||
}
|
||||
UnionLayout::NonNullableUnwrapped(field_layouts) => {
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let struct_layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let struct_type = basic_type_from_layout(env, layout_interner, struct_layout);
|
||||
let target_loaded_type = basic_type_from_layout(env, layout_interner, layout);
|
||||
|
@ -1493,8 +1493,8 @@ pub fn build_exp_expr<'a, 'ctx>(
|
|||
debug_assert_ne!(*tag_id != 0, *nullable_id);
|
||||
|
||||
let field_layouts = other_fields;
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let struct_layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let struct_type = basic_type_from_layout(env, layout_interner, struct_layout);
|
||||
let target_loaded_type = basic_type_from_layout(env, layout_interner, layout);
|
||||
|
@ -1696,7 +1696,10 @@ fn build_struct<'a, 'ctx>(
|
|||
// Zero-sized fields have no runtime representation.
|
||||
// The layout of the struct expects them to be dropped!
|
||||
let (field_expr, field_layout) = load_symbol_and_layout(scope, symbol);
|
||||
if !layout_interner.get(field_layout).is_dropped_because_empty() {
|
||||
if !layout_interner
|
||||
.get_repr(field_layout)
|
||||
.is_dropped_because_empty()
|
||||
{
|
||||
let field_type = basic_type_from_layout(env, layout_interner, field_layout);
|
||||
field_types.push(field_type);
|
||||
|
||||
|
@ -1780,8 +1783,8 @@ fn build_tag<'a, 'ctx>(
|
|||
use std::cmp::Ordering::*;
|
||||
match tag_id.cmp(&(*nullable_id as _)) {
|
||||
Equal => {
|
||||
let layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::Union(*union_layout));
|
||||
let layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::Union(*union_layout));
|
||||
|
||||
return basic_type_from_layout(env, layout_interner, layout)
|
||||
.into_pointer_type()
|
||||
|
@ -2133,7 +2136,8 @@ fn lookup_at_index_ptr2<'a, 'ctx>(
|
|||
) -> BasicValueEnum<'ctx> {
|
||||
let builder = env.builder;
|
||||
|
||||
let struct_layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let struct_layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let struct_type =
|
||||
basic_type_from_layout(env, layout_interner, struct_layout).into_struct_type();
|
||||
|
||||
|
@ -2850,7 +2854,7 @@ pub fn build_exp_stmt<'a, 'ctx>(
|
|||
LayoutRepr::Builtin(Builtin::Str) => todo!(),
|
||||
LayoutRepr::Builtin(Builtin::List(element_layout)) => {
|
||||
debug_assert!(value.is_struct_value());
|
||||
let element_layout = layout_interner.get(element_layout);
|
||||
let element_layout = layout_interner.get_repr(element_layout);
|
||||
let alignment =
|
||||
element_layout.alignment_bytes(layout_interner, env.target_info);
|
||||
|
||||
|
@ -3764,7 +3768,7 @@ fn expose_function_to_host_help_c_abi_generic<'a, 'ctx>(
|
|||
|
||||
builder.position_at_end(entry);
|
||||
|
||||
let wrapped_layout = layout_interner.insert_no_semantic(roc_call_result_layout(
|
||||
let wrapped_layout = layout_interner.insert_direct_no_semantic(roc_call_result_layout(
|
||||
env.arena,
|
||||
return_layout,
|
||||
env.target_info,
|
||||
|
@ -3905,7 +3909,7 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx>(
|
|||
|
||||
builder.position_at_end(last_block);
|
||||
|
||||
let wrapper_result = layout_interner.insert_no_semantic(LayoutRepr::struct_(
|
||||
let wrapper_result = layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(
|
||||
env.arena.alloc([Layout::U64, return_layout]),
|
||||
));
|
||||
|
||||
|
|
|
@ -973,7 +973,7 @@ fn build_tag_eq_help<'a, 'ctx>(
|
|||
env.builder.position_at_end(block);
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
|
@ -1046,7 +1046,7 @@ fn build_tag_eq_help<'a, 'ctx>(
|
|||
env.builder.position_at_end(block);
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
|
@ -1109,7 +1109,7 @@ fn build_tag_eq_help<'a, 'ctx>(
|
|||
env.builder.position_at_end(compare_other);
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(other_fields));
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(other_fields));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
|
@ -1214,7 +1214,7 @@ fn build_tag_eq_help<'a, 'ctx>(
|
|||
env.builder.position_at_end(block);
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
|
@ -1255,7 +1255,7 @@ fn build_tag_eq_help<'a, 'ctx>(
|
|||
env.builder.position_at_end(compare_fields);
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
|
|
|
@ -476,7 +476,7 @@ fn build_clone_tag<'a, 'ctx>(
|
|||
value: BasicValueEnum<'ctx>,
|
||||
union_layout: UnionLayout<'a>,
|
||||
) -> IntValue<'ctx> {
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let layout_id = layout_ids.get(Symbol::CLONE, &layout);
|
||||
let fn_name = layout_id.to_symbol_string(Symbol::CLONE, &env.interns);
|
||||
|
||||
|
@ -690,7 +690,7 @@ fn build_clone_tag_help<'a, 'ctx>(
|
|||
|
||||
// load the tag payload (if any)
|
||||
let payload_layout = LayoutRepr::struct_(field_layouts);
|
||||
let payload_in_layout = layout_interner.insert_no_semantic(payload_layout);
|
||||
let payload_in_layout = layout_interner.insert_direct_no_semantic(payload_layout);
|
||||
|
||||
let opaque_payload_ptr = env
|
||||
.builder
|
||||
|
@ -748,11 +748,12 @@ fn build_clone_tag_help<'a, 'ctx>(
|
|||
|
||||
let tag_value = tag_pointer_clear_tag_id(env, tag_value.into_pointer_value());
|
||||
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let layout = if union_layout.stores_tag_id_in_pointer(env.target_info) {
|
||||
layout
|
||||
} else {
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(
|
||||
env.arena.alloc([layout, union_layout.tag_id_layout()]),
|
||||
))
|
||||
};
|
||||
|
@ -797,7 +798,7 @@ fn build_clone_tag_help<'a, 'ctx>(
|
|||
|
||||
build_copy(env, ptr, offset, extra_offset.into());
|
||||
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(fields));
|
||||
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(fields));
|
||||
let basic_type = basic_type_from_layout(env, layout_interner, layout);
|
||||
|
||||
let (width, _) = union_layout.data_size_and_alignment(layout_interner, env.target_info);
|
||||
|
@ -853,7 +854,8 @@ fn build_clone_tag_help<'a, 'ctx>(
|
|||
other_tags[i]
|
||||
};
|
||||
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(fields));
|
||||
let layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(fields));
|
||||
let basic_type = basic_type_from_layout(env, layout_interner, layout);
|
||||
|
||||
let (width, _) =
|
||||
|
@ -928,7 +930,8 @@ fn build_clone_tag_help<'a, 'ctx>(
|
|||
// write the "pointer" af the current offset
|
||||
build_copy(env, ptr, offset, extra_offset.into());
|
||||
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(other_fields));
|
||||
let layout =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(other_fields));
|
||||
let basic_type = basic_type_from_layout(env, layout_interner, layout);
|
||||
|
||||
let cursors = Cursors {
|
||||
|
|
|
@ -267,7 +267,7 @@ fn modify_refcount_struct<'a, '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 layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(layouts));
|
||||
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(layouts));
|
||||
|
||||
let (_, fn_name) = function_name_from_mode(
|
||||
layout_ids,
|
||||
|
@ -609,8 +609,8 @@ fn modify_refcount_list<'a, 'ctx>(
|
|||
element_layout
|
||||
};
|
||||
|
||||
let list_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::Builtin(Builtin::List(element_layout)));
|
||||
let list_layout = layout_interner
|
||||
.insert_direct_no_semantic(LayoutRepr::Builtin(Builtin::List(element_layout)));
|
||||
let (_, fn_name) = function_name_from_mode(
|
||||
layout_ids,
|
||||
&env.interns,
|
||||
|
@ -859,7 +859,7 @@ fn modify_refcount_boxed<'a, '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 = layout_interner.insert_no_semantic(LayoutRepr::Boxed(inner_layout));
|
||||
let boxed_layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(inner_layout));
|
||||
|
||||
let (_, fn_name) = function_name_from_mode(
|
||||
layout_ids,
|
||||
|
@ -921,7 +921,7 @@ fn modify_refcount_box_help<'a, 'ctx>(
|
|||
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 = layout_interner.insert_no_semantic(LayoutRepr::Boxed(inner_layout));
|
||||
let boxed_layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Boxed(inner_layout));
|
||||
|
||||
match mode {
|
||||
Mode::Inc => {
|
||||
|
@ -1065,7 +1065,7 @@ fn build_rec_union<'a, 'ctx>(
|
|||
mode: Mode,
|
||||
union_layout: UnionLayout<'a>,
|
||||
) -> FunctionValue<'ctx> {
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
|
||||
let (_, fn_name) = function_name_from_mode(
|
||||
layout_ids,
|
||||
|
@ -1168,7 +1168,7 @@ fn build_rec_union_help<'a, 'ctx>(
|
|||
let refcount_ptr = PointerToRefcount::from_ptr_to_data(env, value_ptr);
|
||||
let call_mode = mode_to_call_mode(fn_val, mode);
|
||||
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
|
||||
match mode {
|
||||
Mode::Inc => {
|
||||
|
@ -1223,7 +1223,7 @@ enum DecOrReuse {
|
|||
|
||||
fn fields_need_no_refcounting(interner: &STLayoutInterner, field_layouts: &[InLayout]) -> bool {
|
||||
!field_layouts.iter().any(|x| {
|
||||
let x = interner.get(*x);
|
||||
let x = interner.get_repr(*x);
|
||||
x.is_refcounted() || x.contains_refcounted(interner)
|
||||
})
|
||||
}
|
||||
|
@ -1274,7 +1274,8 @@ fn build_rec_union_recursive_decrement<'a, 'ctx>(
|
|||
|
||||
env.builder.position_at_end(block);
|
||||
|
||||
let fields_struct = layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let fields_struct =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let wrapper_type = basic_type_from_layout(env, layout_interner, fields_struct);
|
||||
|
||||
// cast the opaque pointer to a pointer of the correct shape
|
||||
|
@ -1312,7 +1313,7 @@ fn build_rec_union_recursive_decrement<'a, 'ctx>(
|
|||
|
||||
// therefore we must cast it to our desired type
|
||||
let union_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let union_type = basic_type_from_layout(env, layout_interner, union_layout);
|
||||
let recursive_field_ptr = cast_basic_basic(env.builder, ptr_as_i64_ptr, union_type);
|
||||
|
||||
|
@ -1351,7 +1352,7 @@ fn build_rec_union_recursive_decrement<'a, 'ctx>(
|
|||
DecOrReuse::Reuse => {}
|
||||
DecOrReuse::Dec => {
|
||||
let union_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
refcount_ptr.modify(call_mode, union_layout, env, layout_interner);
|
||||
}
|
||||
}
|
||||
|
@ -1410,7 +1411,7 @@ fn build_rec_union_recursive_decrement<'a, 'ctx>(
|
|||
// increment/decrement the cons-cell itself
|
||||
if let DecOrReuse::Dec = decrement_or_reuse {
|
||||
let union_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
refcount_ptr.modify(call_mode, union_layout, env, layout_interner);
|
||||
}
|
||||
}
|
||||
|
@ -1470,7 +1471,8 @@ pub fn build_reset<'a, 'ctx>(
|
|||
) -> FunctionValue<'ctx> {
|
||||
let mode = Mode::Dec;
|
||||
|
||||
let union_layout_in = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let union_layout_in =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let layout_id = layout_ids.get(Symbol::DEC, &union_layout_in);
|
||||
let fn_name = layout_id.to_symbol_string(Symbol::DEC, &env.interns);
|
||||
let fn_name = format!("{}_reset", fn_name);
|
||||
|
@ -1566,7 +1568,7 @@ fn build_reuse_rec_union_help<'a, 'ctx>(
|
|||
|
||||
env.builder.position_at_end(should_recurse_block);
|
||||
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
|
||||
let do_recurse_block = env.context.append_basic_block(parent, "do_recurse");
|
||||
let no_recurse_block = env.context.append_basic_block(parent, "no_recurse");
|
||||
|
@ -1628,7 +1630,7 @@ fn modify_refcount_nonrecursive<'a, 'ctx>(
|
|||
fields: &'a [&'a [InLayout<'a>]],
|
||||
) -> FunctionValue<'ctx> {
|
||||
let union_layout = UnionLayout::NonRecursive(fields);
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
|
||||
let block = env.builder.get_insert_block().expect("to be in a function");
|
||||
let di_location = env.builder.get_current_debug_location().unwrap();
|
||||
|
@ -1698,7 +1700,7 @@ fn modify_refcount_nonrecursive_help<'a, 'ctx>(
|
|||
let before_block = env.builder.get_insert_block().expect("to be in a function");
|
||||
|
||||
let union_layout = UnionLayout::NonRecursive(tags);
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let layout = layout_interner.insert_direct_no_semantic(LayoutRepr::Union(union_layout));
|
||||
let union_struct_type = basic_type_from_layout(env, layout_interner, layout).into_struct_type();
|
||||
|
||||
// read the tag_id
|
||||
|
@ -1735,7 +1737,7 @@ fn modify_refcount_nonrecursive_help<'a, 'ctx>(
|
|||
for (tag_id, field_layouts) in tags.iter().enumerate() {
|
||||
// if none of the fields are or contain anything refcounted, just move on
|
||||
if !field_layouts.iter().any(|x| {
|
||||
let x = layout_interner.get(*x);
|
||||
let x = layout_interner.get_repr(*x);
|
||||
x.is_refcounted() || x.contains_refcounted(layout_interner)
|
||||
}) {
|
||||
continue;
|
||||
|
@ -1744,7 +1746,8 @@ fn modify_refcount_nonrecursive_help<'a, 'ctx>(
|
|||
let block = env.context.append_basic_block(parent, "tag_id_modify");
|
||||
env.builder.position_at_end(block);
|
||||
|
||||
let fields_struct = layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let fields_struct =
|
||||
layout_interner.insert_direct_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let data_struct_type = basic_type_from_layout(env, layout_interner, fields_struct);
|
||||
|
||||
debug_assert!(data_struct_type.is_struct_type());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue