mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-29 01:33:56 +00:00
Allow unions with one variant to be constant
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user