diff --git a/src/check_expr.cpp b/src/check_expr.cpp index d5e5f7952..8bc73229e 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -5112,27 +5112,6 @@ gb_internal bool check_identifier_exists(Scope *s, Ast *node, bool nested = fals return false; } -gb_internal isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs_count, isize tuple_index, isize tuple_count) { - if (lhs != nullptr && c->decl != nullptr) { - for (isize j = 0; (tuple_index + j) < lhs_count && j < tuple_count; j++) { - Entity *e = lhs[tuple_index + j]; - if (e != nullptr) { - DeclInfo *decl = decl_info_of_entity(e); - if (decl != nullptr) { - rw_mutex_shared_lock(&decl->deps_mutex); - rw_mutex_lock(&c->decl->deps_mutex); - for (Entity *dep : decl->deps) { - ptr_set_add(&c->decl->deps, dep); - } - rw_mutex_unlock(&c->decl->deps_mutex); - rw_mutex_shared_unlock(&decl->deps_mutex); - } - } - } - } - return tuple_count; -} - gb_internal bool check_no_copy_assignment(Operand const &o, String const &context) { if (o.type && is_type_no_copy(o.type)) { Ast *expr = unparen_expr(o.expr); @@ -5240,6 +5219,31 @@ enum UnpackFlag : u32 { gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array *operands, Slice const &rhs_arguments, UnpackFlags flags) { + auto const &add_dependencies_from_unpacking = [](CheckerContext *c, Entity **lhs, isize lhs_count, isize tuple_index, isize tuple_count) -> isize { + if (lhs == nullptr || c->decl == nullptr) { + return tuple_count; + } + for (isize j = 0; (tuple_index + j) < lhs_count && j < tuple_count; j++) { + Entity *e = lhs[tuple_index + j]; + if (e == nullptr) { + continue; + } + DeclInfo *decl = decl_info_of_entity(e); + if (decl == nullptr) { + continue; + } + rw_mutex_shared_lock(&decl->deps_mutex); + rw_mutex_lock(&c->decl->deps_mutex); + for (Entity *dep : decl->deps) { + ptr_set_add(&c->decl->deps, dep); + } + rw_mutex_unlock(&c->decl->deps_mutex); + rw_mutex_shared_unlock(&decl->deps_mutex); + } + return tuple_count; + }; + + bool allow_ok = (flags & UnpackFlag_AllowOk) != 0; bool is_variadic = (flags & UnpackFlag_IsVariadic) != 0; bool allow_undef = (flags & UnpackFlag_AllowUndef) != 0; diff --git a/src/tilde.cpp b/src/tilde.cpp index 64fe70ec4..fc51a1156 100644 --- a/src/tilde.cpp +++ b/src/tilde.cpp @@ -241,9 +241,9 @@ gb_internal TB_Symbol *cg_find_symbol_from_entity(cgModule *m, Entity *e) { GB_ASSERT(e != nullptr); rw_mutex_lock(&m->values_mutex); - defer (rw_mutex_unlock(&m->values_mutex)); TB_Symbol **found = map_get(&m->symbols, e); if (found) { + rw_mutex_unlock(&m->values_mutex); return *found; } @@ -252,8 +252,23 @@ gb_internal TB_Symbol *cg_find_symbol_from_entity(cgModule *m, Entity *e) { if (proc_found) { TB_Symbol *symbol = (*proc_found)->symbol; map_set(&m->symbols, e, symbol); + rw_mutex_unlock(&m->values_mutex); return symbol; } + rw_mutex_unlock(&m->values_mutex); + + if (e->kind == Entity_Procedure) { + debugf("[Tilde] try to generate procedure %.*s as it was not in the minimum_dependency_set", LIT(e->token.string)); + // IMPORTANT TODO(bill): This is an utter bodge, try and fix this shit + cgProcedure *p = cg_procedure_create(m, e); + if (p != nullptr) { + GB_ASSERT(p->symbol != nullptr); + cg_add_procedure_to_queue(p); + return p->symbol; + } + } + + GB_PANIC("could not find entity's symbol %.*s", LIT(e->token.string)); return nullptr; } @@ -662,6 +677,9 @@ gb_internal WORKER_TASK_PROC(cg_procedure_generate_worker_proc) { } gb_internal void cg_add_procedure_to_queue(cgProcedure *p) { + if (p == nullptr) { + return; + } cgModule *m = p->module; if (m->do_threading) { thread_pool_add_task(cg_procedure_generate_worker_proc, p); diff --git a/src/tilde.hpp b/src/tilde.hpp index 7f2ee8076..6ff5602b5 100644 --- a/src/tilde.hpp +++ b/src/tilde.hpp @@ -264,6 +264,7 @@ gb_global cgProcedure *cg_cleanup_runtime_proc = nullptr; gb_internal TB_Arena *cg_arena(void); +gb_internal cgProcedure *cg_procedure_create(cgModule *m, Entity *entity, bool ignore_body=false); gb_internal void cg_add_procedure_to_queue(cgProcedure *p); gb_internal void cg_setup_type_info_data(cgModule *m); gb_internal cgProcedure *cg_procedure_generate_anonymous(cgModule *m, Ast *expr, cgProcedure *parent); diff --git a/src/tilde/tb.lib b/src/tilde/tb.lib index adf355d07..43e477536 100644 Binary files a/src/tilde/tb.lib and b/src/tilde/tb.lib differ diff --git a/src/tilde_proc.cpp b/src/tilde_proc.cpp index 7e751ac82..8cfc564a7 100644 --- a/src/tilde_proc.cpp +++ b/src/tilde_proc.cpp @@ -18,7 +18,7 @@ gb_internal TB_FunctionPrototype *cg_procedure_type_as_prototype(cgModule *m, Ty return proto; } -gb_internal cgProcedure *cg_procedure_create(cgModule *m, Entity *entity, bool ignore_body=false) { +gb_internal cgProcedure *cg_procedure_create(cgModule *m, Entity *entity, bool ignore_body) { GB_ASSERT(entity != nullptr); GB_ASSERT(entity->kind == Entity_Procedure); if (!entity->Procedure.is_foreign) { @@ -385,7 +385,7 @@ gb_internal WORKER_TASK_PROC(cg_procedure_compile_worker_proc) { if ( - // string_starts_with(p->name, str_lit("bug@main")) || + // string_starts_with(p->name, str_lit("runtime@_windows_default_alloc_or_resize")) || false ) { emit_asm = true; @@ -434,7 +434,8 @@ gb_internal void cg_procedure_generate(cgProcedure *p) { if ( - // string_starts_with(p->name, str_lit("bug@main")) || + // string_starts_with(p->name, str_lit("runtime@_windows_default_alloc")) || + // p->name == str_lit("runtime@_windows_default_alloc_or_resize") || false ) { // IR Printing TB_Arena *arena = tb_default_arena();