mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 05:08:14 +00:00
Entity * to std::atomic<Entity *> to remove the need for a PtrMap+Mutex
This commit is contained in:
+4
-4
@@ -1549,7 +1549,7 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
|||||||
"\tother at %s",
|
"\tother at %s",
|
||||||
LIT(name), token_pos_to_string(pos));
|
LIT(name), token_pos_to_string(pos));
|
||||||
} else if (name == "main") {
|
} else if (name == "main") {
|
||||||
if (d->entity->pkg->kind != Package_Runtime) {
|
if (d->entity.load()->pkg->kind != Package_Runtime) {
|
||||||
error(d->proc_lit, "The link name 'main' is reserved for internal use");
|
error(d->proc_lit, "The link name 'main' is reserved for internal use");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1967,8 +1967,8 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
|
|||||||
ctx->curr_proc_sig = type;
|
ctx->curr_proc_sig = type;
|
||||||
ctx->curr_proc_calling_convention = type->Proc.calling_convention;
|
ctx->curr_proc_calling_convention = type->Proc.calling_convention;
|
||||||
|
|
||||||
if (decl->parent && decl->entity && decl->parent->entity) {
|
if (decl->parent && decl->entity.load() && decl->parent->entity) {
|
||||||
decl->entity->parent_proc_decl = decl->parent;
|
decl->entity.load()->parent_proc_decl = decl->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->pkg->name != "runtime") {
|
if (ctx->pkg->name != "runtime") {
|
||||||
@@ -2072,7 +2072,7 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
|
|||||||
GB_ASSERT(decl->proc_checked_state != ProcCheckedState_Checked);
|
GB_ASSERT(decl->proc_checked_state != ProcCheckedState_Checked);
|
||||||
if (decl->defer_use_checked) {
|
if (decl->defer_use_checked) {
|
||||||
GB_ASSERT(is_type_polymorphic(type, true));
|
GB_ASSERT(is_type_polymorphic(type, true));
|
||||||
error(token, "Defer Use Checked: %.*s", LIT(decl->entity->token.string));
|
error(token, "Defer Use Checked: %.*s", LIT(decl->entity.load()->token.string));
|
||||||
GB_ASSERT(decl->defer_use_checked == false);
|
GB_ASSERT(decl->defer_use_checked == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -608,7 +608,7 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
|
|||||||
entity->flags |= EntityFlag_Disabled;
|
entity->flags |= EntityFlag_Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->entity = entity;
|
d->entity.store(entity);
|
||||||
|
|
||||||
AstFile *file = nullptr;
|
AstFile *file = nullptr;
|
||||||
{
|
{
|
||||||
@@ -8335,9 +8335,10 @@ gb_internal ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *c
|
|||||||
if (c->curr_proc_decl == nullptr) {
|
if (c->curr_proc_decl == nullptr) {
|
||||||
error(call, "Calling a '#force_inline' procedure that enables target features is not allowed at file scope");
|
error(call, "Calling a '#force_inline' procedure that enables target features is not allowed at file scope");
|
||||||
} else {
|
} else {
|
||||||
GB_ASSERT(c->curr_proc_decl->entity);
|
Entity *e = c->curr_proc_decl->entity.load();
|
||||||
GB_ASSERT(c->curr_proc_decl->entity->type->kind == Type_Proc);
|
GB_ASSERT(e);
|
||||||
String scope_features = c->curr_proc_decl->entity->type->Proc.enable_target_feature;
|
GB_ASSERT(e->type->kind == Type_Proc);
|
||||||
|
String scope_features = e->type->Proc.enable_target_feature;
|
||||||
if (!check_target_feature_is_superset_of(scope_features, pt->Proc.enable_target_feature, &invalid)) {
|
if (!check_target_feature_is_superset_of(scope_features, pt->Proc.enable_target_feature, &invalid)) {
|
||||||
ERROR_BLOCK();
|
ERROR_BLOCK();
|
||||||
error(call, "Inlined procedure enables target feature '%.*s', this requires the calling procedure to at least enable the same feature", LIT(invalid));
|
error(call, "Inlined procedure enables target feature '%.*s', this requires the calling procedure to at least enable the same feature", LIT(invalid));
|
||||||
|
|||||||
+1
-1
@@ -2055,8 +2055,8 @@ gb_internal void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, En
|
|||||||
add_entity_definition(info, identifier, e);
|
add_entity_definition(info, identifier, e);
|
||||||
GB_ASSERT(e->decl_info == nullptr);
|
GB_ASSERT(e->decl_info == nullptr);
|
||||||
e->decl_info = d;
|
e->decl_info = d;
|
||||||
d->entity = e;
|
|
||||||
e->pkg = c->pkg;
|
e->pkg = c->pkg;
|
||||||
|
d->entity.store(e);
|
||||||
|
|
||||||
isize queue_count = -1;
|
isize queue_count = -1;
|
||||||
bool is_lazy = false;
|
bool is_lazy = false;
|
||||||
|
|||||||
+1
-1
@@ -209,7 +209,7 @@ struct DeclInfo {
|
|||||||
|
|
||||||
Scope * scope;
|
Scope * scope;
|
||||||
|
|
||||||
Entity *entity;
|
std::atomic<Entity *> entity;
|
||||||
|
|
||||||
Ast * decl_node;
|
Ast * decl_node;
|
||||||
Ast * type_expr;
|
Ast * type_expr;
|
||||||
|
|||||||
@@ -238,9 +238,6 @@ struct lbGenerator : LinkerData {
|
|||||||
PtrMap<LLVMContextRef, lbModule *> modules_through_ctx;
|
PtrMap<LLVMContextRef, lbModule *> modules_through_ctx;
|
||||||
lbModule default_module;
|
lbModule default_module;
|
||||||
|
|
||||||
RecursiveMutex anonymous_proc_lits_mutex;
|
|
||||||
PtrMap<Ast *, lbProcedure *> anonymous_proc_lits;
|
|
||||||
|
|
||||||
isize used_module_count;
|
isize used_module_count;
|
||||||
|
|
||||||
lbProcedure *startup_runtime;
|
lbProcedure *startup_runtime;
|
||||||
|
|||||||
@@ -157,7 +157,6 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
|
|||||||
|
|
||||||
map_init(&gen->modules, gen->info->packages.count*2);
|
map_init(&gen->modules, gen->info->packages.count*2);
|
||||||
map_init(&gen->modules_through_ctx, gen->info->packages.count*2);
|
map_init(&gen->modules_through_ctx, gen->info->packages.count*2);
|
||||||
map_init(&gen->anonymous_proc_lits, 1024);
|
|
||||||
|
|
||||||
if (USE_SEPARATE_MODULES) {
|
if (USE_SEPARATE_MODULES) {
|
||||||
bool module_per_file = build_context.module_per_file && build_context.optimization_level <= 0;
|
bool module_per_file = build_context.module_per_file && build_context.optimization_level <= 0;
|
||||||
@@ -3084,18 +3083,14 @@ gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e)
|
|||||||
|
|
||||||
|
|
||||||
gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) {
|
gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) {
|
||||||
lbGenerator *gen = m->gen;
|
// lbGenerator *gen = m->gen;
|
||||||
|
ast_node(pl, ProcLit, expr);
|
||||||
|
|
||||||
mutex_lock(&gen->anonymous_proc_lits_mutex);
|
if (pl->decl->entity.load() != nullptr) {
|
||||||
defer (mutex_unlock(&gen->anonymous_proc_lits_mutex));
|
return lb_find_procedure_value_from_entity(m, pl->decl->entity.load());
|
||||||
|
|
||||||
TokenPos pos = ast_token(expr).pos;
|
|
||||||
lbProcedure **found = map_get(&gen->anonymous_proc_lits, expr);
|
|
||||||
if (found) {
|
|
||||||
return lb_find_procedure_value_from_entity(m, (*found)->entity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_node(pl, ProcLit, expr);
|
TokenPos pos = ast_token(expr).pos;
|
||||||
|
|
||||||
// NOTE(bill): Generate a new name
|
// NOTE(bill): Generate a new name
|
||||||
// parent$count
|
// parent$count
|
||||||
@@ -3114,15 +3109,18 @@ gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &pr
|
|||||||
token.string = name;
|
token.string = name;
|
||||||
Entity *e = alloc_entity_procedure(nullptr, token, type, pl->tags);
|
Entity *e = alloc_entity_procedure(nullptr, token, type, pl->tags);
|
||||||
e->file = expr->file();
|
e->file = expr->file();
|
||||||
|
e->pkg = e->file->pkg;
|
||||||
|
e->scope = e->file->scope;
|
||||||
|
|
||||||
// NOTE(bill): this is to prevent a race condition since these procedure literals can be created anywhere at any time
|
// NOTE(bill): this is to prevent a race condition since these procedure literals can be created anywhere at any time
|
||||||
pl->decl->code_gen_module = m;
|
pl->decl->code_gen_module = m;
|
||||||
e->decl_info = pl->decl;
|
e->decl_info = pl->decl;
|
||||||
pl->decl->entity = e;
|
|
||||||
e->parent_proc_decl = pl->decl->parent;
|
e->parent_proc_decl = pl->decl->parent;
|
||||||
e->Procedure.is_anonymous = true;
|
e->Procedure.is_anonymous = true;
|
||||||
e->flags |= EntityFlag_ProcBodyChecked;
|
e->flags |= EntityFlag_ProcBodyChecked;
|
||||||
|
|
||||||
|
pl->decl->entity.store(e);
|
||||||
|
|
||||||
lbProcedure *p = lb_create_procedure(m, e);
|
lbProcedure *p = lb_create_procedure(m, e);
|
||||||
GB_ASSERT(e->code_gen_module == m);
|
GB_ASSERT(e->code_gen_module == m);
|
||||||
|
|
||||||
@@ -3130,7 +3128,6 @@ gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &pr
|
|||||||
value.value = p->value;
|
value.value = p->value;
|
||||||
value.type = p->type;
|
value.type = p->type;
|
||||||
|
|
||||||
map_set(&gen->anonymous_proc_lits, expr, p);
|
|
||||||
array_add(&m->procedures_to_generate, p);
|
array_add(&m->procedures_to_generate, p);
|
||||||
if (parent != nullptr) {
|
if (parent != nullptr) {
|
||||||
array_add(&parent->children, p);
|
array_add(&parent->children, p);
|
||||||
|
|||||||
@@ -2211,7 +2211,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
|
|||||||
GB_ASSERT(e != nullptr);
|
GB_ASSERT(e != nullptr);
|
||||||
|
|
||||||
if (e->parent_proc_decl != nullptr && e->parent_proc_decl->entity != nullptr) {
|
if (e->parent_proc_decl != nullptr && e->parent_proc_decl->entity != nullptr) {
|
||||||
procedure = e->parent_proc_decl->entity->token.string;
|
procedure = e->parent_proc_decl->entity.load()->token.string;
|
||||||
} else {
|
} else {
|
||||||
procedure = str_lit("");
|
procedure = str_lit("");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -394,8 +394,9 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ
|
|||||||
String proc_name = {};
|
String proc_name = {};
|
||||||
if (t->Named.type_name->parent_proc_decl) {
|
if (t->Named.type_name->parent_proc_decl) {
|
||||||
DeclInfo *decl = t->Named.type_name->parent_proc_decl;
|
DeclInfo *decl = t->Named.type_name->parent_proc_decl;
|
||||||
if (decl->entity && decl->entity->kind == Entity_Procedure) {
|
Entity *e = decl->entity.load();
|
||||||
proc_name = decl->entity->token.string;
|
if (e && e->kind == Entity_Procedure) {
|
||||||
|
proc_name = e->token.string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TokenPos pos = t->Named.type_name->token.pos;
|
TokenPos pos = t->Named.type_name->token.pos;
|
||||||
|
|||||||
Reference in New Issue
Block a user