mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-14 15:23:15 +00:00
Fix a race condition when produced anonymous procedure literals with -use-separate-modules
This commit is contained in:
@@ -772,56 +772,6 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
|
||||
return {p->value, p->type};
|
||||
}
|
||||
|
||||
|
||||
gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) {
|
||||
mutex_lock(&m->gen->anonymous_proc_lits_mutex);
|
||||
defer (mutex_unlock(&m->gen->anonymous_proc_lits_mutex));
|
||||
|
||||
lbProcedure **found = map_get(&m->gen->anonymous_proc_lits, expr);
|
||||
if (found) {
|
||||
return lb_find_procedure_value_from_entity(m, (*found)->entity);
|
||||
}
|
||||
|
||||
ast_node(pl, ProcLit, expr);
|
||||
|
||||
// NOTE(bill): Generate a new name
|
||||
// parent$count
|
||||
isize name_len = prefix_name.len + 6 + 11;
|
||||
char *name_text = gb_alloc_array(permanent_allocator(), char, name_len);
|
||||
static std::atomic<i32> name_id;
|
||||
name_len = gb_snprintf(name_text, name_len, "%.*s$anon-%d", LIT(prefix_name), 1+name_id.fetch_add(1));
|
||||
String name = make_string((u8 *)name_text, name_len-1);
|
||||
|
||||
Type *type = type_of_expr(expr);
|
||||
|
||||
Token token = {};
|
||||
token.pos = ast_token(expr).pos;
|
||||
token.kind = Token_Ident;
|
||||
token.string = name;
|
||||
Entity *e = alloc_entity_procedure(nullptr, token, type, pl->tags);
|
||||
e->file = expr->file();
|
||||
e->decl_info = pl->decl;
|
||||
e->code_gen_module = m;
|
||||
e->flags |= EntityFlag_ProcBodyChecked;
|
||||
lbProcedure *p = lb_create_procedure(m, e);
|
||||
|
||||
lbValue value = {};
|
||||
value.value = p->value;
|
||||
value.type = p->type;
|
||||
|
||||
array_add(&m->procedures_to_generate, p);
|
||||
if (parent != nullptr) {
|
||||
array_add(&parent->children, p);
|
||||
} else {
|
||||
string_map_set(&m->members, name, value);
|
||||
}
|
||||
|
||||
map_set(&m->gen->anonymous_proc_lits, expr, p);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
gb_internal lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type) {
|
||||
lbAddr *found = map_get(&m->map_cell_info_map, type);
|
||||
if (found) {
|
||||
@@ -1513,7 +1463,7 @@ gb_internal WORKER_TASK_PROC(lb_generate_missing_procedures_to_check_worker_proc
|
||||
lbModule *m = cast(lbModule *)data;
|
||||
for (isize i = 0; i < m->missing_procedures_to_check.count; i++) {
|
||||
lbProcedure *p = m->missing_procedures_to_check[i];
|
||||
debugf("Generate missing procedure: %.*s\n", LIT(p->name));
|
||||
debugf("Generate missing procedure: %.*s module %p\n", LIT(p->name), m);
|
||||
lb_generate_procedure(m, p);
|
||||
}
|
||||
return 0;
|
||||
@@ -1577,7 +1527,6 @@ gb_internal void lb_llvm_module_passes(lbGenerator *gen, bool do_threading) {
|
||||
thread_pool_wait();
|
||||
}
|
||||
|
||||
|
||||
gb_internal String lb_filepath_ll_for_module(lbModule *m) {
|
||||
String path = concatenate3_strings(permanent_allocator(),
|
||||
build_context.build_paths[BuildPath_Output].basename,
|
||||
|
||||
Reference in New Issue
Block a user