Fix race condition with polymorphic record generation

This commit is contained in:
gingerBill
2023-01-12 16:06:09 +00:00
parent 38136e15fc
commit 34f9170189
+12 -12
View File
@@ -380,8 +380,7 @@ gb_internal void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, T
gb_internal Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_params, gb_internal Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_params,
bool *is_polymorphic_, bool *is_polymorphic_,
Ast *node, Array<Operand> *poly_operands, Ast *node, Array<Operand> *poly_operands) {
Type *named_type, Type *original_type_for_poly) {
Type *polymorphic_params_type = nullptr; Type *polymorphic_params_type = nullptr;
bool can_check_fields = true; bool can_check_fields = true;
GB_ASSERT(is_polymorphic_ != nullptr); GB_ASSERT(is_polymorphic_ != nullptr);
@@ -548,11 +547,6 @@ gb_internal Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *poly
} }
} }
if (original_type_for_poly != nullptr) {
GB_ASSERT(named_type != nullptr);
add_polymorphic_record_entity(ctx, node, named_type, original_type_for_poly);
}
if (!*is_polymorphic_) { if (!*is_polymorphic_) {
*is_polymorphic_ = polymorphic_params != nullptr && poly_operands == nullptr; *is_polymorphic_ = polymorphic_params != nullptr && poly_operands == nullptr;
} }
@@ -620,10 +614,13 @@ gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *
struct_type->Struct.polymorphic_params = check_record_polymorphic_params( struct_type->Struct.polymorphic_params = check_record_polymorphic_params(
ctx, st->polymorphic_params, ctx, st->polymorphic_params,
&struct_type->Struct.is_polymorphic, &struct_type->Struct.is_polymorphic,
node, poly_operands, node, poly_operands
named_type, original_type_for_poly );
);;
struct_type->Struct.is_poly_specialized = check_record_poly_operand_specialization(ctx, struct_type, poly_operands, &struct_type->Struct.is_polymorphic); struct_type->Struct.is_poly_specialized = check_record_poly_operand_specialization(ctx, struct_type, poly_operands, &struct_type->Struct.is_polymorphic);
if (original_type_for_poly) {
GB_ASSERT(named_type != nullptr);
add_polymorphic_record_entity(ctx, node, named_type, original_type_for_poly);
}
if (!struct_type->Struct.is_polymorphic) { if (!struct_type->Struct.is_polymorphic) {
if (st->where_clauses.count > 0 && st->polymorphic_params == nullptr) { if (st->where_clauses.count > 0 && st->polymorphic_params == nullptr) {
@@ -655,10 +652,13 @@ gb_internal void check_union_type(CheckerContext *ctx, Type *union_type, Ast *no
union_type->Union.polymorphic_params = check_record_polymorphic_params( union_type->Union.polymorphic_params = check_record_polymorphic_params(
ctx, ut->polymorphic_params, ctx, ut->polymorphic_params,
&union_type->Union.is_polymorphic, &union_type->Union.is_polymorphic,
node, poly_operands, node, poly_operands
named_type, original_type_for_poly
); );
union_type->Union.is_poly_specialized = check_record_poly_operand_specialization(ctx, union_type, poly_operands, &union_type->Union.is_polymorphic); union_type->Union.is_poly_specialized = check_record_poly_operand_specialization(ctx, union_type, poly_operands, &union_type->Union.is_polymorphic);
if (original_type_for_poly) {
GB_ASSERT(named_type != nullptr);
add_polymorphic_record_entity(ctx, node, named_type, original_type_for_poly);
}
if (!union_type->Union.is_polymorphic) { if (!union_type->Union.is_polymorphic) {
if (ut->where_clauses.count > 0 && ut->polymorphic_params == nullptr) { if (ut->where_clauses.count > 0 && ut->polymorphic_params == nullptr) {