Decoupled generics (#2695)

This commit is contained in:
Christoffer Lerno
2025-12-29 17:01:03 +01:00
committed by GitHub
parent bf1d401566
commit d96624c578
68 changed files with 1263 additions and 808 deletions

View File

@@ -238,6 +238,7 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls)
FOREACH(Decl *, decl, decls)
{
decl->unit = unit;
ASSERT(decl->is_template && decl->generic_id);
switch (decl->decl_kind)
{
case DECL_ALIAS_PATH:
@@ -258,6 +259,8 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls)
case DECL_ENUM_CONSTANT:
case DECL_ERASED:
case DECL_GROUP:
case DECL_GENERIC:
case DECL_GENERIC_INSTANCE:
case DECL_LABEL:
UNREACHABLE_VOID
case DECL_ALIAS:
@@ -278,6 +281,8 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls)
break;
}
htable_set(&unit->module->symbols, (void *)decl->name, decl);
htable_set(&unit->local_symbols, (void *)decl->name, decl);
if (decl->visibility == VISIBLE_PUBLIC)
{
global_context_add_decl(decl);
@@ -285,25 +290,20 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls)
}
}
static void analyze_generic_module(Module *module)
static void analyze_generics(Module *module)
{
ASSERT(module->parameters && module->is_generic);
FOREACH(CompilationUnit *, unit, module->units)
{
register_generic_decls(unit, unit->global_decls);
register_generic_decls(unit, unit->global_cond_decls);
FOREACH(Decl *, section, unit->generic_decls)
{
register_generic_decls(unit, section->generic_decl.decls);
register_generic_decls(unit, section->generic_decl.conditional_decls);
}
}
}
static void sema_analyze_to_stage(AnalysisStage stage)
{
if (stage <= ANALYSIS_MODULE_TOP)
{
FOREACH(Module *, module, compiler.context.generic_module_list)
{
sema_analyze_stage(module, stage);
}
}
FOREACH(Module *, module, compiler.context.module_list)
{
sema_analyze_stage(module, stage);
@@ -485,9 +485,9 @@ void sema_analysis_run(void)
// We parse the generic modules, just by storing the decls.
FOREACH(Module *, module, compiler.context.generic_module_list)
FOREACH(Module *, module, compiler.context.module_list)
{
analyze_generic_module(module);
analyze_generics(module);
}
for (AnalysisStage stage = ANALYSIS_NOT_BEGUN + 1; stage <= ANALYSIS_LAST; stage++)