mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-11 18:58:24 +03:00
Drop Layout::struct_no_name_order
This commit is contained in:
parent
1170b542b6
commit
4296d5a349
@ -403,7 +403,7 @@ fn build_entry_point<'a>(
|
||||
|
||||
let block = builder.add_block();
|
||||
|
||||
let struct_layout = interner.insert(Layout::struct_no_name_order(layouts));
|
||||
let struct_layout = interner.insert_no_semantic(LayoutRepr::struct_(layouts));
|
||||
let type_id = layout_spec(env, &mut builder, interner, struct_layout)?;
|
||||
|
||||
let argument = builder.add_unknown_with(block, &[], type_id)?;
|
||||
@ -460,9 +460,8 @@ fn proc_spec<'a>(
|
||||
)?;
|
||||
|
||||
let root = BlockExpr(block, value_id);
|
||||
let args_struct_layout = interner.insert(Layout::struct_no_name_order(
|
||||
argument_layouts.into_bump_slice(),
|
||||
));
|
||||
let args_struct_layout =
|
||||
interner.insert_no_semantic(LayoutRepr::struct_(argument_layouts.into_bump_slice()));
|
||||
let arg_type_id = layout_spec(&mut env, &mut builder, interner, args_struct_layout)?;
|
||||
let ret_type_id = layout_spec(&mut env, &mut builder, interner, proc.ret_layout)?;
|
||||
|
||||
|
@ -1348,7 +1348,7 @@ pub fn build_exp_expr<'a, 'ctx>(
|
||||
let field_layouts = tag_layouts[*tag_id as usize];
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert(Layout::struct_no_name_order(field_layouts));
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let struct_type = basic_type_from_layout(env, layout_interner, struct_layout);
|
||||
|
||||
let opaque_data_ptr = env
|
||||
@ -1405,7 +1405,7 @@ pub fn build_exp_expr<'a, 'ctx>(
|
||||
}
|
||||
UnionLayout::NonNullableUnwrapped(field_layouts) => {
|
||||
let struct_layout =
|
||||
layout_interner.insert(Layout::struct_no_name_order(field_layouts));
|
||||
layout_interner.insert_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);
|
||||
@ -1456,7 +1456,7 @@ pub fn build_exp_expr<'a, 'ctx>(
|
||||
|
||||
let field_layouts = other_fields;
|
||||
let struct_layout =
|
||||
layout_interner.insert(Layout::struct_no_name_order(field_layouts));
|
||||
layout_interner.insert_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);
|
||||
@ -2095,7 +2095,7 @@ fn lookup_at_index_ptr2<'a, 'ctx>(
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let builder = env.builder;
|
||||
|
||||
let struct_layout = layout_interner.insert(Layout::struct_no_name_order(field_layouts));
|
||||
let struct_layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let struct_type =
|
||||
basic_type_from_layout(env, layout_interner, struct_layout).into_struct_type();
|
||||
|
||||
@ -3718,7 +3718,7 @@ fn expose_function_to_host_help_c_abi_generic<'a, 'ctx>(
|
||||
|
||||
builder.position_at_end(entry);
|
||||
|
||||
let wrapped_layout = layout_interner.insert(roc_call_result_layout(
|
||||
let wrapped_layout = layout_interner.insert_no_semantic(roc_call_result_layout(
|
||||
env.arena,
|
||||
return_layout,
|
||||
env.target_info,
|
||||
@ -3859,7 +3859,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(Layout::struct_no_name_order(
|
||||
let wrapper_result = layout_interner.insert_no_semantic(LayoutRepr::struct_(
|
||||
env.arena.alloc([Layout::U64, return_layout]),
|
||||
));
|
||||
|
||||
@ -4473,10 +4473,10 @@ fn roc_call_result_layout<'a>(
|
||||
arena: &'a Bump,
|
||||
return_layout: InLayout<'a>,
|
||||
target_info: TargetInfo,
|
||||
) -> Layout<'a> {
|
||||
) -> LayoutRepr<'a> {
|
||||
let elements = [Layout::U64, Layout::usize(target_info), return_layout];
|
||||
|
||||
Layout::struct_no_name_order(arena.alloc(elements))
|
||||
LayoutRepr::struct_(arena.alloc(elements))
|
||||
}
|
||||
|
||||
fn roc_call_result_type<'ctx>(
|
||||
|
@ -11,7 +11,7 @@ use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::layout::{
|
||||
Builtin, InLayout, Layout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner, UnionLayout,
|
||||
Builtin, InLayout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner, UnionLayout,
|
||||
};
|
||||
|
||||
use super::build::{load_roc_value, use_roc_value, BuilderExt};
|
||||
@ -973,7 +973,7 @@ fn build_tag_eq_help<'a, 'ctx>(
|
||||
env.builder.position_at_end(block);
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert(Layout::struct_no_name_order(field_layouts));
|
||||
layout_interner.insert_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(Layout::struct_no_name_order(field_layouts));
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
@ -1108,7 +1108,8 @@ fn build_tag_eq_help<'a, 'ctx>(
|
||||
|
||||
env.builder.position_at_end(compare_other);
|
||||
|
||||
let struct_layout = layout_interner.insert(Layout::struct_no_name_order(other_fields));
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(other_fields));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
@ -1208,7 +1209,7 @@ fn build_tag_eq_help<'a, 'ctx>(
|
||||
env.builder.position_at_end(block);
|
||||
|
||||
let struct_layout =
|
||||
layout_interner.insert(Layout::struct_no_name_order(field_layouts));
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
@ -1248,7 +1249,8 @@ fn build_tag_eq_help<'a, 'ctx>(
|
||||
|
||||
env.builder.position_at_end(compare_fields);
|
||||
|
||||
let struct_layout = layout_interner.insert(Layout::struct_no_name_order(field_layouts));
|
||||
let struct_layout =
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
|
||||
let answer = eq_ptr_to_struct(
|
||||
env,
|
||||
|
@ -13,7 +13,7 @@ use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::ir::LookupType;
|
||||
use roc_mono::layout::{
|
||||
Builtin, InLayout, Layout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner, UnionLayout,
|
||||
Builtin, InLayout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner, UnionLayout,
|
||||
};
|
||||
use roc_region::all::Region;
|
||||
|
||||
@ -426,7 +426,7 @@ fn build_clone_struct<'a, 'ctx>(
|
||||
value: BasicValueEnum<'ctx>,
|
||||
field_layouts: &[InLayout<'a>],
|
||||
) -> IntValue<'ctx> {
|
||||
let layout = Layout::struct_no_name_order(field_layouts);
|
||||
let layout = LayoutRepr::struct_(field_layouts);
|
||||
|
||||
if layout.safe_to_memcpy(layout_interner) {
|
||||
build_copy(env, ptr, cursors.offset, value)
|
||||
@ -689,8 +689,8 @@ fn build_clone_tag_help<'a, 'ctx>(
|
||||
);
|
||||
|
||||
// load the tag payload (if any)
|
||||
let payload_layout = Layout::struct_no_name_order(field_layouts);
|
||||
let payload_in_layout = layout_interner.insert(payload_layout);
|
||||
let payload_layout = LayoutRepr::struct_(field_layouts);
|
||||
let payload_in_layout = layout_interner.insert_no_semantic(payload_layout);
|
||||
|
||||
let opaque_payload_ptr = env
|
||||
.builder
|
||||
@ -748,11 +748,11 @@ 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(Layout::struct_no_name_order(field_layouts));
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(field_layouts));
|
||||
let layout = if union_layout.stores_tag_id_in_pointer(env.target_info) {
|
||||
layout
|
||||
} else {
|
||||
layout_interner.insert(Layout::struct_no_name_order(
|
||||
layout_interner.insert_no_semantic(LayoutRepr::struct_(
|
||||
env.arena.alloc([layout, union_layout.tag_id_layout()]),
|
||||
))
|
||||
};
|
||||
@ -797,7 +797,7 @@ fn build_clone_tag_help<'a, 'ctx>(
|
||||
|
||||
build_copy(env, ptr, offset, extra_offset.into());
|
||||
|
||||
let layout = layout_interner.insert(Layout::struct_no_name_order(fields));
|
||||
let layout = layout_interner.insert_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 +853,7 @@ fn build_clone_tag_help<'a, 'ctx>(
|
||||
other_tags[i]
|
||||
};
|
||||
|
||||
let layout = layout_interner.insert(Layout::struct_no_name_order(fields));
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(fields));
|
||||
let basic_type = basic_type_from_layout(env, layout_interner, layout);
|
||||
|
||||
let (width, _) =
|
||||
@ -928,7 +928,7 @@ 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(Layout::struct_no_name_order(other_fields));
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(other_fields));
|
||||
let basic_type = basic_type_from_layout(env, layout_interner, layout);
|
||||
|
||||
let cursors = Cursors {
|
||||
|
@ -19,7 +19,7 @@ use inkwell::{AddressSpace, IntPredicate};
|
||||
use roc_module::symbol::Interns;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::layout::{
|
||||
Builtin, InLayout, Layout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner, UnionLayout,
|
||||
Builtin, InLayout, LayoutIds, LayoutInterner, LayoutRepr, STLayoutInterner, UnionLayout,
|
||||
};
|
||||
|
||||
use super::build::{cast_if_necessary_for_opaque_recursive_pointers, load_roc_value, FunctionSpec};
|
||||
@ -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(Layout::struct_no_name_order(layouts));
|
||||
let layout = layout_interner.insert_no_semantic(LayoutRepr::struct_(layouts));
|
||||
|
||||
let (_, fn_name) = function_name_from_mode(
|
||||
layout_ids,
|
||||
@ -1274,7 +1274,7 @@ fn build_rec_union_recursive_decrement<'a, 'ctx>(
|
||||
|
||||
env.builder.position_at_end(block);
|
||||
|
||||
let fields_struct = layout_interner.insert(Layout::struct_no_name_order(field_layouts));
|
||||
let fields_struct = layout_interner.insert_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
|
||||
@ -1744,7 +1744,7 @@ 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(Layout::struct_no_name_order(field_layouts));
|
||||
let fields_struct = layout_interner.insert_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());
|
||||
|
@ -2389,9 +2389,12 @@ pub fn call_higher_order_lowlevel<'a>(
|
||||
// If there is closure data, make sure we put in a struct it before passing it to the
|
||||
// external builtin impl. That way it's always an `i32` pointer.
|
||||
let wrapped_closure_data_sym = backend.create_symbol("wrapped_captures");
|
||||
let wrapped_captures_layout = backend.layout_interner.insert(Layout::struct_no_name_order(
|
||||
backend.env.arena.alloc([closure_data_layout]),
|
||||
));
|
||||
let wrapped_captures_layout =
|
||||
backend
|
||||
.layout_interner
|
||||
.insert_no_semantic(LayoutRepr::struct_(
|
||||
backend.env.arena.alloc([closure_data_layout]),
|
||||
));
|
||||
|
||||
// make sure that the wrapping struct is available in stack memory, so we can hand out a
|
||||
// pointer to it.
|
||||
|
@ -5941,8 +5941,10 @@ where
|
||||
Vec::from_iter_in(combined.iter().map(|(_, b)| **b), env.arena).into_bump_slice();
|
||||
|
||||
debug_assert_eq!(
|
||||
Layout::struct_no_name_order(field_layouts),
|
||||
layout_cache.get_in(lambda_set.runtime_representation())
|
||||
LayoutRepr::struct_(field_layouts),
|
||||
layout_cache
|
||||
.get_in(lambda_set.runtime_representation())
|
||||
.repr
|
||||
);
|
||||
|
||||
let expr = Expr::Struct(symbols);
|
||||
|
@ -1208,7 +1208,7 @@ fn store_pattern_help<'a>(
|
||||
fields.extend(arguments.iter().map(|x| x.1));
|
||||
|
||||
let layout =
|
||||
layout_cache.put_in(Layout::struct_no_name_order(fields.into_bump_slice()));
|
||||
layout_cache.put_in_no_semantic(LayoutRepr::struct_(fields.into_bump_slice()));
|
||||
|
||||
return store_newtype_pattern(
|
||||
env,
|
||||
|
@ -973,7 +973,7 @@ impl<'a> UnionLayout<'a> {
|
||||
{
|
||||
tags.iter()
|
||||
.map(|field_layouts| {
|
||||
Layout::struct_no_name_order(field_layouts).alignment_bytes(interner, target_info)
|
||||
LayoutRepr::struct_(field_layouts).alignment_bytes(interner, target_info)
|
||||
})
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
@ -989,13 +989,13 @@ impl<'a> UnionLayout<'a> {
|
||||
}
|
||||
UnionLayout::Recursive(tags) => Self::tags_alignment_bytes(interner, tags, target_info),
|
||||
UnionLayout::NonNullableUnwrapped(field_layouts) => {
|
||||
Layout::struct_no_name_order(field_layouts).alignment_bytes(interner, target_info)
|
||||
LayoutRepr::struct_(field_layouts).alignment_bytes(interner, target_info)
|
||||
}
|
||||
UnionLayout::NullableWrapped { other_tags, .. } => {
|
||||
Self::tags_alignment_bytes(interner, other_tags, target_info)
|
||||
}
|
||||
UnionLayout::NullableUnwrapped { other_fields, .. } => {
|
||||
Layout::struct_no_name_order(other_fields).alignment_bytes(interner, target_info)
|
||||
LayoutRepr::struct_(other_fields).alignment_bytes(interner, target_info)
|
||||
}
|
||||
};
|
||||
|
||||
@ -2458,19 +2458,6 @@ impl<'a> Layout<'a> {
|
||||
(data_width, data_align)
|
||||
}
|
||||
|
||||
/// Used to build a `Layout::Struct` where the field name order is irrelevant.
|
||||
// TODO: to be eliminated once we have SemanticRepr playing a role.
|
||||
pub fn struct_no_name_order(field_layouts: &'a [InLayout]) -> Self {
|
||||
if field_layouts.is_empty() {
|
||||
Self::UNIT_NAKED
|
||||
} else {
|
||||
Self {
|
||||
repr: LayoutRepr::Struct { field_layouts },
|
||||
semantic: SemanticRepr::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn runtime_representation<I>(&self, interner: &I) -> Self
|
||||
where
|
||||
I: LayoutInterner<'a>,
|
||||
@ -2503,6 +2490,10 @@ impl<'a> std::ops::Deref for Layout<'a> {
|
||||
}
|
||||
|
||||
impl<'a> LayoutRepr<'a> {
|
||||
pub const fn struct_(field_layouts: &'a [InLayout<'a>]) -> Self {
|
||||
Self::Struct { field_layouts }
|
||||
}
|
||||
|
||||
pub fn safe_to_memcpy<I>(&self, interner: &I) -> bool
|
||||
where
|
||||
I: LayoutInterner<'a>,
|
||||
@ -4091,9 +4082,8 @@ where
|
||||
let answer1 = if field_layouts.len() == 1 {
|
||||
field_layouts[0]
|
||||
} else {
|
||||
env.cache.put_in(Layout::struct_no_name_order(
|
||||
field_layouts.into_bump_slice(),
|
||||
))
|
||||
env.cache
|
||||
.put_in_no_semantic(LayoutRepr::struct_(field_layouts.into_bump_slice()))
|
||||
};
|
||||
|
||||
answer1
|
||||
@ -4104,9 +4094,8 @@ where
|
||||
if data_tag_arguments.len() == 1 {
|
||||
data_tag_arguments[0]
|
||||
} else {
|
||||
env.cache.put_in(Layout::struct_no_name_order(
|
||||
data_tag_arguments.into_bump_slice(),
|
||||
))
|
||||
env.cache
|
||||
.put_in_no_semantic(LayoutRepr::struct_(data_tag_arguments.into_bump_slice()))
|
||||
}
|
||||
}
|
||||
Wrapped(variant) => {
|
||||
|
@ -1593,7 +1593,7 @@ mod insert_recursive_layout {
|
||||
};
|
||||
let repr = LayoutRepr::Union(UnionLayout::Recursive(&*arena.alloc([
|
||||
&*arena.alloc([interner.insert(list_rec)]),
|
||||
&*arena.alloc_slice_fill_iter([interner.insert(Layout::struct_no_name_order(
|
||||
&*arena.alloc_slice_fill_iter([interner.insert_no_semantic(LayoutRepr::struct_(
|
||||
&*arena.alloc([Layout::NAKED_RECURSIVE_PTR]),
|
||||
))]),
|
||||
])));
|
||||
|
@ -419,9 +419,10 @@ fn jit_to_ast_help<'a, A: ReplApp<'a>>(
|
||||
),
|
||||
LayoutRepr::Struct { field_layouts, .. } => {
|
||||
let fields = [Layout::U64, layout];
|
||||
// TODO: no need to intern here
|
||||
let layout = env
|
||||
.layout_cache
|
||||
.put_in(Layout::struct_no_name_order(env.arena.alloc(fields)));
|
||||
.put_in_no_semantic(LayoutRepr::struct_(env.arena.alloc(fields)));
|
||||
|
||||
let result_stack_size = env.layout_cache.interner.stack_size(layout);
|
||||
|
||||
@ -1033,7 +1034,7 @@ fn struct_to_ast<'a, M: ReplAppMemory>(
|
||||
|
||||
let struct_layout = env
|
||||
.layout_cache
|
||||
.put_in(Layout::struct_no_name_order(inner_layouts));
|
||||
.put_in_no_semantic(LayoutRepr::struct_(inner_layouts));
|
||||
let loc_expr = &*arena.alloc(Loc {
|
||||
value: addr_to_ast(
|
||||
env,
|
||||
|
Loading…
Reference in New Issue
Block a user