mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Revert legacy struct builder
This commit is contained in:
parent
ea6330b48b
commit
d39c8ba7be
1 changed files with 8 additions and 71 deletions
|
@ -1594,51 +1594,6 @@ fn build_tag_fields<'a, 'r, 'ctx, 'env>(
|
|||
(field_types, field_values)
|
||||
}
|
||||
|
||||
fn legacy_build_struct_while_debugging<'a, 'ctx>(
|
||||
env: &Env<'a, 'ctx, '_>,
|
||||
layout_interner: &mut STLayoutInterner<'a>,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
sorted_fields: &[Symbol],
|
||||
) -> StructValue<'ctx> {
|
||||
let ctx = env.context;
|
||||
|
||||
// Determine types
|
||||
let num_fields = sorted_fields.len();
|
||||
let mut field_types = Vec::with_capacity_in(num_fields, env.arena);
|
||||
let mut field_vals = Vec::with_capacity_in(num_fields, env.arena);
|
||||
|
||||
for symbol in sorted_fields.iter() {
|
||||
// Zero-sized fields have no runtime representation.
|
||||
// The layout of the struct expects them to be dropped!
|
||||
let (field_expr, field_layout) = scope.load_symbol_and_layout(symbol);
|
||||
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);
|
||||
|
||||
if layout_interner.is_passed_by_reference(field_layout) {
|
||||
let field_value = env.builder.new_build_load(
|
||||
field_type,
|
||||
field_expr.into_pointer_value(),
|
||||
"load_tag_to_put_in_struct",
|
||||
);
|
||||
|
||||
field_vals.push(field_value);
|
||||
} else {
|
||||
field_vals.push(field_expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the struct_type
|
||||
let struct_type = ctx.struct_type(field_types.into_bump_slice(), false);
|
||||
|
||||
// Insert field exprs into struct_val
|
||||
struct_from_fields(env, struct_type, field_vals.into_iter().enumerate())
|
||||
}
|
||||
|
||||
fn build_tag<'a, 'ctx>(
|
||||
env: &Env<'a, 'ctx, '_>,
|
||||
layout_interner: &mut STLayoutInterner<'a>,
|
||||
|
@ -1655,26 +1610,16 @@ fn build_tag<'a, 'ctx>(
|
|||
UnionLayout::NonRecursive(tags) => {
|
||||
debug_assert!(union_size > 1);
|
||||
|
||||
// TODO: this is the representation we want.
|
||||
// let data_layout_repr = LayoutRepr::Struct(tags[tag_id as usize]);
|
||||
// let data = RocStruct::build(env, layout_interner, data_layout_repr, scope, arguments);
|
||||
let data = legacy_build_struct_while_debugging(env, layout_interner, scope, arguments);
|
||||
let data_alloca = create_entry_block_alloca(
|
||||
env,
|
||||
parent,
|
||||
data.get_type().into(),
|
||||
"non_recursive_data_alloca",
|
||||
);
|
||||
env.builder.build_store(data_alloca, data);
|
||||
let data_layout_repr = LayoutRepr::Struct(tags[tag_id as usize]);
|
||||
let data = RocStruct::build(env, layout_interner, data_layout_repr, scope, arguments);
|
||||
|
||||
let roc_union =
|
||||
RocUnion::tagged_from_slices(layout_interner, env.context, tags, env.target_info);
|
||||
let data_layout = LayoutRepr::Struct(tags[tag_id as usize]);
|
||||
let value = roc_union.as_struct_value(
|
||||
env,
|
||||
layout_interner,
|
||||
RocStruct::ByReference(data_alloca),
|
||||
data_layout,
|
||||
data,
|
||||
data_layout_repr,
|
||||
Some(tag_id as _),
|
||||
);
|
||||
|
||||
|
@ -1805,19 +1750,11 @@ fn build_tag<'a, 'ctx>(
|
|||
&[other_fields],
|
||||
);
|
||||
|
||||
// TODO: this is the representation we want.
|
||||
// let data_layout_repr = LayoutRepr::Struct(other_fields);
|
||||
// let data = RocStruct::build(env, layout_interner, data_layout_repr, scope, arguments);
|
||||
let data = legacy_build_struct_while_debugging(env, layout_interner, scope, arguments);
|
||||
let data_layout = LayoutRepr::Struct(other_fields);
|
||||
let data_layout_repr = LayoutRepr::Struct(other_fields);
|
||||
let data = RocStruct::build(env, layout_interner, data_layout_repr, scope, arguments);
|
||||
|
||||
let value = roc_union.as_struct_value(
|
||||
env,
|
||||
layout_interner,
|
||||
RocStruct::ByValue(data),
|
||||
data_layout,
|
||||
None,
|
||||
);
|
||||
let value =
|
||||
roc_union.as_struct_value(env, layout_interner, data, data_layout_repr, None);
|
||||
|
||||
env.builder.build_store(data_ptr, value);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue