Split type and inline cycles into separate loops

This commit is contained in:
gingerBill
2025-09-10 13:26:07 +01:00
parent 629777b988
commit 70d396c8ad
2 changed files with 29 additions and 15 deletions

View File

@@ -2552,14 +2552,12 @@ gb_internal void add_min_dep_type_info(Checker *c, Type *t) {
}
}
gb_internal void add_dependency_to_set(Checker *c, Entity *entity) {
if (entity == nullptr) {
return;
}
CheckerInfo *info = &c->info;
auto *set = &info->minimum_dependency_set;
if (entity->type != nullptr &&
is_type_polymorphic(entity->type)) {
@@ -2569,8 +2567,11 @@ gb_internal void add_dependency_to_set(Checker *c, Entity *entity) {
}
}
if (ptr_set_update(set, entity)) {
return;
{
MUTEX_GUARD(&info->minimum_dependency_type_info_mutex);
if (ptr_set_update(&info->minimum_dependency_set, entity)) {
return;
}
}
DeclInfo *decl = decl_info_of_entity(entity);
@@ -7173,25 +7174,35 @@ gb_internal void check_parsed_files(Checker *c) {
}
check_merge_queues_into_arrays(c);
TIME_SECTION("check for type cycles and inline cycles");
TIME_SECTION("check for type cycles");
// NOTE(bill): Check for illegal cyclic type declarations
for_array(i, c->info.definitions) {
Entity *e = c->info.definitions[i];
if (e->kind == Entity_TypeName && e->type != nullptr && is_type_typed(e->type)) {
if (e->kind != Entity_TypeName) {
continue;
}
if (e->type != nullptr && is_type_typed(e->type)) {
if (e->TypeName.is_type_alias) {
// Ignore for the time being
} else {
(void)type_align_of(e->type);
}
} else if (e->kind == Entity_Procedure) {
DeclInfo *decl = e->decl_info;
ast_node(pl, ProcLit, decl->proc_lit);
if (pl->inlining == ProcInlining_inline) {
for (Entity *dep : decl->deps) {
if (dep == e) {
error(e->token, "Cannot inline recursive procedure '%.*s'", LIT(e->token.string));
break;
}
}
}
TIME_SECTION("check for inline cycles");
for_array(i, c->info.definitions) {
Entity *e = c->info.definitions[i];
if (e->kind != Entity_Procedure) {
continue;
}
DeclInfo *decl = e->decl_info;
ast_node(pl, ProcLit, decl->proc_lit);
if (pl->inlining == ProcInlining_inline) {
for (Entity *dep : decl->deps) {
if (dep == e) {
error(e->token, "Cannot inline recursive procedure '%.*s'", LIT(e->token.string));
break;
}
}
}

View File

@@ -448,7 +448,10 @@ struct CheckerInfo {
AstPackage * init_package;
Scope * init_scope;
Entity * entry_point;
BlockingMutex minimum_dependency_set_mutex;
PtrSet<Entity *> minimum_dependency_set;
BlockingMutex minimum_dependency_type_info_mutex;
PtrMap</*type info hash*/u64, /*min dep index*/isize> min_dep_type_info_index_map;
TypeSet min_dep_type_info_set;