Allow unions with one variant to be constant

This commit is contained in:
gingerBill
2025-09-19 11:56:44 +01:00
parent 1a4da5cb0f
commit 6338e0a8a3
4 changed files with 82 additions and 4 deletions

View File

@@ -2226,6 +2226,18 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
if (is_type_union_maybe_pointer(type)) {
LLVMTypeRef variant = lb_type(m, type->Union.variants[0]);
array_add(&fields, variant);
} else if (type->Union.variants.count == 1) {
LLVMTypeRef block_type = lb_type(m, type->Union.variants[0]);
LLVMTypeRef tag_type = lb_type(m, union_tag_type(type));
array_add(&fields, block_type);
array_add(&fields, tag_type);
i64 used_size = lb_sizeof(block_type) + lb_sizeof(tag_type);
i64 padding = size - used_size;
if (padding > 0) {
LLVMTypeRef padding_type = lb_type_padding_filler(m, padding, align);
array_add(&fields, padding_type);
}
} else {
LLVMTypeRef block_type = nullptr;
@@ -3131,7 +3143,6 @@ gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &pr
lbValue *found = map_get(&target_module->values, e);
rw_mutex_shared_unlock(&target_module->values_mutex);
if (found == nullptr) {
// THIS IS THE RACE CONDITION
lbProcedure *missing_proc_in_target_module = lb_create_procedure(target_module, e, false);
array_add(&target_module->missing_procedures_to_check, missing_proc_in_target_module);
}