Removed analyse top pass. Remove sub module tracking. Fix errors where ? should be ~

This commit is contained in:
Christoffer Lerno
2026-02-02 12:20:34 +01:00
parent d509b4caa1
commit 6bc606a9b1
10 changed files with 20 additions and 33 deletions

View File

@@ -1667,7 +1667,6 @@ typedef struct Module_
CompilationUnit **units;
Module *parent_module;
Module *top_module;
Module **sub_modules;
Decl **benchmarks;
Decl **tests;
Decl **lambdas_to_evaluate;

View File

@@ -43,7 +43,6 @@ typedef enum
{
ANALYSIS_NOT_BEGUN,
ANALYSIS_MODULE_HIERARCHY,
ANALYSIS_MODULE_TOP,
ANALYSIS_IMPORTS,
ANALYSIS_REGISTER_GLOBAL_DECLARATIONS,
ANALYSIS_INCLUDES,

View File

@@ -9680,7 +9680,7 @@ static inline bool sema_expr_analyse_or_error(SemaContext *context, Expr *expr,
CHECK_ON_DEFINED(failed_ref);
if (else_type == type_fault)
{
RETURN_SEMA_ERROR(right, "There is no common type for %s and %s, did you perhaps forget a '?' after the last expression?", type_quoted_error_string(type), type_quoted_error_string(else_type));
RETURN_SEMA_ERROR(right, "There is no common type for %s and %s, did you perhaps forget a '~' after the last expression?", type_quoted_error_string(type), type_quoted_error_string(else_type));
}
RETURN_SEMA_ERROR(right, "Cannot find a common type for %s and %s.", type_quoted_error_string(type), type_quoted_error_string(else_type));
}
@@ -9965,7 +9965,7 @@ static inline bool sema_expr_analyse_optional(SemaContext *context, Expr *expr,
if (inner->expr_kind == EXPR_OPTIONAL)
{
if (failed_ref) goto ON_FAILED;
RETURN_SEMA_ERROR(inner, "It looks like you added one too many '?' after the error.");
RETURN_SEMA_ERROR(inner, "It looks like you added one too many '~' after the error.");
}
Type *type = inner->type->canonical;
@@ -9973,7 +9973,7 @@ static inline bool sema_expr_analyse_optional(SemaContext *context, Expr *expr,
if (type != type_fault)
{
if (failed_ref) goto ON_FAILED;
RETURN_SEMA_ERROR(inner, "You cannot use the '?' operator on expressions of type %s",
RETURN_SEMA_ERROR(inner, "You cannot use the '~' operator on expressions of type %s",
type_quoted_error_string(type));
}
ASSERT_SPAN(expr, type->type_kind == TYPE_ANYFAULT || type->decl->resolve_status == RESOLVE_DONE);
@@ -11696,7 +11696,7 @@ static inline bool sema_expr_analyse_compound_literal(SemaContext *context, Expr
Type *type = type_info->type;
if (type_is_optional(type))
{
RETURN_SEMA_ERROR(type_info, "The type here should always be written as a plain type and not an optional, please remove the '?'.");
RETURN_SEMA_ERROR(type_info, "The type here should always be written as a plain type and not an optional, please remove the '~'.");
}
if (!sema_resolve_type_structure(context, type)) return false;
if (!sema_expr_analyse_initializer_list(context, type, expr->expr_compound_literal.initializer, no_match_ref)) return false;
@@ -11975,7 +11975,7 @@ bool sema_analyse_expr_rhs(SemaContext *context, Type *to, Expr *expr, bool allo
if (flat != type_fault && sema_cast_const(expr))
{
if (no_match_ref) goto NO_MATCH_REF;
print_error_after(expr->span, "You need to add a trailing '?' here to make this an optional.");
print_error_after(expr->span, "You need to add a trailing '~' here to make this an optional.");
return false;
}
}

View File

@@ -73,7 +73,6 @@ void sema_append_contract_asserts(AstId assert_first, Ast* compound_stmt);
Decl *sema_create_runner_main(SemaContext *context, Decl *decl);
void sema_analyse_pass_top(Module *module);
void sema_analyse_pass_module_hierarchy(Module *module);
void sema_analysis_pass_process_imports(Module *module);
void sema_analysis_pass_register_global_declarations(Module *module);

View File

@@ -228,13 +228,11 @@ Decl *sema_find_decl_in_modules(Module **module_list, Path *path, const char *in
INLINE bool module_inclusion_match(Module *a, Module *b)
{
Module *temp;
// Quick check
if (a->top_module != b->top_module) return false;
if (a->name->len < b->name->len)
{
temp = a;
Module *temp = a;
a = b;
b = temp;
}

View File

@@ -18,13 +18,6 @@ void parent_path(StringSlice *slice)
slice->len = 0;
}
void sema_analyse_pass_top(Module *module)
{
Module *parent = module;
while (parent->parent_module) parent = parent->parent_module;
module->top_module = parent;
}
void sema_analyse_pass_module_hierarchy(Module *module)
{
const char *name = module->name->module;
@@ -42,11 +35,9 @@ void sema_analyse_pass_module_hierarchy(Module *module)
Path *checked_name = checked->name;
if (checked_name->len != slice.len) continue;
// Found the parent! We're done, we add this parent
// and this as a child.
if (memcmp(checked_name->module, slice.ptr, slice.len) == 0)
{
module->parent_module = checked;
vec_add(checked->sub_modules, module);
return;
}
}
@@ -55,12 +46,17 @@ void sema_analyse_pass_module_hierarchy(Module *module)
DEBUG_LOG("Creating parent module for %s: %s", module->name->module, path->module);
Module *parent_module = compiler_find_or_create_module(path);
module->parent_module = parent_module;
vec_add(parent_module->sub_modules, module);
sema_analyze_stage(parent_module, ANALYSIS_MODULE_HIERARCHY);
}
void sema_analysis_pass_process_imports(Module *module)
{
DEBUG_LOG("Pass: Set the top module '%s'.", module->name->module);
Module *parent = module;
while (parent->parent_module) parent = parent->parent_module;
module->top_module = parent;
DEBUG_LOG("Pass: Importing dependencies for files in module '%s'.", module->name->module);
unsigned total_import_count = 0;
@@ -167,18 +163,17 @@ static bool sema_check_if_implicit_generic(SemaContext *context, Decl *decl)
{
if (!decl->func_decl.type_parent) return false;
TypeInfo *typedecl = type_infoptr(decl->func_decl.type_parent);
Decl *d = NULL;
if (typedecl->resolve_status == RESOLVE_DONE)
{
CanonicalType *type = typedecl->type->canonical;
if (!type_is_user_defined(type)) return false;
d = type->decl;
return type_is_user_defined(type) && type->decl->is_template;
}
else if (typedecl->kind == TYPE_INFO_IDENTIFIER && typedecl->subtype == TYPE_COMPRESSED_NONE)
if (typedecl->kind == TYPE_INFO_IDENTIFIER && typedecl->subtype == TYPE_COMPRESSED_NONE)
{
d = sema_resolve_maybe_parameterized_symbol(context, typedecl->unresolved.name, typedecl->unresolved.path, typedecl->span);
Decl *d = sema_resolve_maybe_parameterized_symbol(context, typedecl->unresolved.name, typedecl->unresolved.path, typedecl->span);
return d && d->is_template; // NOLINT because apparently this is not checking for NULL!?
}
return d && d->is_template;
return false;
}
void unit_register_optional_global_decl(CompilationUnit *unit, Decl *decl)

View File

@@ -174,9 +174,6 @@ void sema_analyze_stage(Module *module, AnalysisStage stage)
case ANALYSIS_MODULE_HIERARCHY:
sema_analyse_pass_module_hierarchy(module);
break;
case ANALYSIS_MODULE_TOP:
sema_analyse_pass_top(module);
break;
case ANALYSIS_IMPORTS:
sema_analysis_pass_process_imports(module);
break;