Use RecursiveMutex to fix a race condition with parapoly records

This commit is contained in:
gingerBill
2025-09-26 10:18:46 +01:00
parent 42b9039a1f
commit 01c10f3f5e
5 changed files with 16 additions and 8 deletions
+7 -3
View File
@@ -1293,6 +1293,11 @@ gb_internal void check_assignment(CheckerContext *c, Operand *operand, Type *typ
error_line("\t Got: %s\n", s_got); error_line("\t Got: %s\n", s_got);
gb_string_free(s_got); gb_string_free(s_got);
gb_string_free(s_expected); gb_string_free(s_expected);
Type *tx = x->Proc.params->Tuple.variables[0]->type;
Type *ty = y->Proc.params->Tuple.variables[0]->type;
gb_printf_err("%s kind:%.*s e:%p ot:%p\n", type_to_string(tx), LIT(type_strings[tx->kind]), tx->Named.type_name, tx->Named.type_name->TypeName.original_type_for_parapoly);
gb_printf_err("%s kind:%.*s e:%p ot:%p\n", type_to_string(ty), LIT(type_strings[ty->kind]), ty->Named.type_name, ty->Named.type_name->TypeName.original_type_for_parapoly);
} else { } else {
gbString s_expected = type_to_string(y); gbString s_expected = type_to_string(y);
gbString s_got = type_to_string(x); gbString s_got = type_to_string(x);
@@ -7908,11 +7913,10 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
{ {
GenTypesData *found_gen_types = ensure_polymorphic_record_entity_has_gen_types(c, original_type); GenTypesData *found_gen_types = ensure_polymorphic_record_entity_has_gen_types(c, original_type);
mutex_lock(&found_gen_types->mutex);
defer (mutex_unlock(&found_gen_types->mutex));
rw_mutex_shared_lock(&found_gen_types->mutex);
Entity *found_entity = find_polymorphic_record_entity(found_gen_types, param_count, ordered_operands); Entity *found_entity = find_polymorphic_record_entity(found_gen_types, param_count, ordered_operands);
rw_mutex_shared_unlock(&found_gen_types->mutex);
if (found_entity) { if (found_entity) {
operand->mode = Addressing_Type; operand->mode = Addressing_Type;
operand->type = found_entity->type; operand->type = found_entity->type;
+3 -2
View File
@@ -312,6 +312,7 @@ gb_internal void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, T
e->state = EntityState_Resolved; e->state = EntityState_Resolved;
e->file = ctx->file; e->file = ctx->file;
e->pkg = pkg; e->pkg = pkg;
e->TypeName.original_type_for_parapoly = original_type;
add_entity_use(ctx, node, e); add_entity_use(ctx, node, e);
} }
@@ -321,8 +322,8 @@ gb_internal void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, T
e->TypeName.objc_metadata = original_type->Named.type_name->TypeName.objc_metadata; e->TypeName.objc_metadata = original_type->Named.type_name->TypeName.objc_metadata;
auto *found_gen_types = ensure_polymorphic_record_entity_has_gen_types(ctx, original_type); auto *found_gen_types = ensure_polymorphic_record_entity_has_gen_types(ctx, original_type);
rw_mutex_lock(&found_gen_types->mutex); mutex_lock(&found_gen_types->mutex);
defer (rw_mutex_unlock(&found_gen_types->mutex)); defer (mutex_unlock(&found_gen_types->mutex));
for (Entity *prev : found_gen_types->types) { for (Entity *prev : found_gen_types->types) {
if (prev == e) { if (prev == e) {
+1 -1
View File
@@ -417,7 +417,7 @@ struct GenProcsData {
struct GenTypesData { struct GenTypesData {
Array<Entity *> types; Array<Entity *> types;
RwMutex mutex; RecursiveMutex mutex;
}; };
struct Defineable { struct Defineable {
+1
View File
@@ -234,6 +234,7 @@ struct Entity {
} Variable; } Variable;
struct { struct {
Type * type_parameter_specialization; Type * type_parameter_specialization;
Type * original_type_for_parapoly;
String ir_mangled_name; String ir_mangled_name;
bool is_type_alias; bool is_type_alias;
bool objc_is_implementation; bool objc_is_implementation;
+4 -2
View File
@@ -18,8 +18,8 @@ enum BasicKind {
Basic_u16, Basic_u16,
Basic_i32, Basic_i32,
Basic_u32, Basic_u32,
Basic_i64, Basic_i64
Basic_u64, , Basic_u64,
Basic_i128, Basic_i128,
Basic_u128, Basic_u128,
@@ -2860,6 +2860,7 @@ gb_internal bool are_types_identical(Type *x, Type *y) {
return false; return false;
} }
// MUTEX_GUARD(&g_type_mutex);
return are_types_identical_internal(x, y, false); return are_types_identical_internal(x, y, false);
} }
gb_internal bool are_types_identical_unique_tuples(Type *x, Type *y) { gb_internal bool are_types_identical_unique_tuples(Type *x, Type *y) {
@@ -2887,6 +2888,7 @@ gb_internal bool are_types_identical_unique_tuples(Type *x, Type *y) {
return false; return false;
} }
// MUTEX_GUARD(&g_type_mutex);
return are_types_identical_internal(x, y, true); return are_types_identical_internal(x, y, true);
} }