mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 09:22:22 -07:00
Correct did you mean logic and make thread-safe-er
This commit is contained in:
@@ -476,7 +476,7 @@ String odin_root_dir(void) {
|
||||
return global_module_path;
|
||||
}
|
||||
|
||||
gbAllocator a = heap_allocator();
|
||||
gbAllocator a = permanent_allocator();
|
||||
char const *found = gb_get_env("ODIN_ROOT", a);
|
||||
if (found) {
|
||||
String path = path_to_full_path(a, make_string_c(found));
|
||||
@@ -679,7 +679,8 @@ String path_to_fullpath(gbAllocator a, String s) {
|
||||
mutex_lock(&fullpath_mutex);
|
||||
defer (mutex_unlock(&fullpath_mutex));
|
||||
|
||||
String16 string16 = string_to_string16(temporary_allocator(), s);
|
||||
String16 string16 = string_to_string16(heap_allocator(), s);
|
||||
defer (gb_free(heap_allocator(), string16.text));
|
||||
|
||||
DWORD len = GetFullPathNameW(&string16[0], 0, nullptr, nullptr);
|
||||
if (len != 0) {
|
||||
|
||||
@@ -3726,7 +3726,12 @@ void check_did_you_mean_print(DidYouMeanAnswers *d) {
|
||||
}
|
||||
}
|
||||
|
||||
gb_global BlockingMutex did_you_mean_mutex;
|
||||
|
||||
void check_did_you_mean_type(String const &name, Array<Entity *> const &fields) {
|
||||
mutex_lock(&did_you_mean_mutex);
|
||||
defer (mutex_unlock(&did_you_mean_mutex));
|
||||
|
||||
DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), fields.count, name);
|
||||
defer (did_you_mean_destroy(&d));
|
||||
|
||||
@@ -3737,6 +3742,9 @@ void check_did_you_mean_type(String const &name, Array<Entity *> const &fields)
|
||||
}
|
||||
|
||||
void check_did_you_mean_scope(String const &name, Scope *scope) {
|
||||
mutex_lock(&did_you_mean_mutex);
|
||||
defer (mutex_unlock(&did_you_mean_mutex));
|
||||
|
||||
DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), scope->elements.entries.count, name);
|
||||
defer (did_you_mean_destroy(&d));
|
||||
|
||||
|
||||
+16
-3
@@ -656,7 +656,16 @@ AstPackage *get_core_package(CheckerInfo *info, String name) {
|
||||
String path = get_fullpath_core(a, name);
|
||||
defer (gb_free(a, path.text));
|
||||
auto found = string_map_get(&info->packages, path);
|
||||
GB_ASSERT_MSG(found != nullptr, "Missing core package %.*s", LIT(name));
|
||||
if (found == nullptr) {
|
||||
gb_printf_err("Name: %.*s\n", LIT(name));
|
||||
gb_printf_err("Fullpath: %.*s\n", LIT(path));
|
||||
|
||||
for_array(i, info->packages.entries) {
|
||||
auto *entry = &info->packages.entries[i];
|
||||
gb_printf_err("%.*s\n", LIT(entry->key.string));
|
||||
}
|
||||
GB_ASSERT_MSG(found != nullptr, "Missing core package %.*s", LIT(name));
|
||||
}
|
||||
return *found;
|
||||
}
|
||||
|
||||
@@ -4578,9 +4587,11 @@ bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *untyped, Proc
|
||||
ctx.decl = pi->decl;
|
||||
ctx.procs_to_check_queue = procs_to_check_queue;
|
||||
GB_ASSERT(procs_to_check_queue != nullptr);
|
||||
|
||||
|
||||
GB_ASSERT(pi->type->kind == Type_Proc);
|
||||
TypeProc *pt = &pi->type->Proc;
|
||||
String name = pi->token.string;
|
||||
|
||||
if (pt->is_polymorphic && !pt->is_poly_specialized) {
|
||||
Token token = pi->token;
|
||||
if (pi->poly_def_node != nullptr) {
|
||||
@@ -4658,7 +4669,8 @@ void check_unchecked_bodies(Checker *c) {
|
||||
if (pi->body == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
debugf("unchecked: %.*s\n", LIT(e->token.string));
|
||||
mpmc_enqueue(&c->procs_to_check_queue, pi);
|
||||
}
|
||||
}
|
||||
@@ -4762,6 +4774,7 @@ void check_procedure_bodies(Checker *c) {
|
||||
if (!build_context.threaded_checker) {
|
||||
worker_count = 0;
|
||||
}
|
||||
worker_count = 0;
|
||||
if (worker_count == 0) {
|
||||
auto *this_queue = &c->procs_to_check_queue;
|
||||
|
||||
|
||||
+9
-10
@@ -57,8 +57,8 @@ struct MemoryBlock {
|
||||
};
|
||||
|
||||
struct Arena {
|
||||
MemoryBlock * curr_block;
|
||||
isize minimum_block_size;
|
||||
MemoryBlock *curr_block;
|
||||
isize minimum_block_size;
|
||||
bool use_local_mutex;
|
||||
BlockingMutex local_mutex;
|
||||
};
|
||||
@@ -69,8 +69,14 @@ gb_global isize DEFAULT_PAGE_SIZE = 4096;
|
||||
|
||||
MemoryBlock *virtual_memory_alloc(isize size);
|
||||
void virtual_memory_dealloc(MemoryBlock *block);
|
||||
void *arena_alloc(Arena *arena, isize min_size, isize alignment);
|
||||
void arena_free_all(Arena *arena);
|
||||
|
||||
void arena_init_local_mutex(Arena *arena) {
|
||||
mutex_init(&arena->local_mutex);
|
||||
arena->use_local_mutex = true;
|
||||
}
|
||||
|
||||
isize arena_align_forward_offset(Arena *arena, isize alignment) {
|
||||
isize alignment_offset = 0;
|
||||
isize ptr = cast(isize)(arena->curr_block->base + arena->curr_block->used);
|
||||
@@ -81,17 +87,9 @@ isize arena_align_forward_offset(Arena *arena, isize alignment) {
|
||||
return alignment_offset;
|
||||
}
|
||||
|
||||
void arena_init_local_mutex(Arena *arena) {
|
||||
mutex_init(&arena->local_mutex);
|
||||
arena->use_local_mutex = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *arena_alloc(Arena *arena, isize min_size, isize alignment) {
|
||||
GB_ASSERT(gb_is_power_of_two(alignment));
|
||||
|
||||
|
||||
BlockingMutex *mutex = &global_memory_allocator_mutex;
|
||||
if (arena->use_local_mutex) {
|
||||
mutex = &arena->local_mutex;
|
||||
@@ -289,6 +287,7 @@ GB_ALLOCATOR_PROC(arena_allocator_proc) {
|
||||
}
|
||||
break;
|
||||
case gbAllocation_FreeAll:
|
||||
GB_PANIC("use arena_free_all directly");
|
||||
arena_free_all(arena);
|
||||
break;
|
||||
}
|
||||
|
||||
+2
-6
@@ -2019,6 +2019,7 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
virtual_memory_init();
|
||||
mutex_init(&fullpath_mutex);
|
||||
mutex_init(&hash_exact_value_mutex);
|
||||
mutex_init(&did_you_mean_mutex);
|
||||
|
||||
init_string_buffer_memory();
|
||||
init_string_interner();
|
||||
@@ -2199,8 +2200,6 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
arena_free_all(&temporary_arena);
|
||||
|
||||
TIME_SECTION("type check");
|
||||
|
||||
checker->parser = parser;
|
||||
@@ -2212,8 +2211,6 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
arena_free_all(&temporary_arena);
|
||||
|
||||
if (build_context.generate_docs) {
|
||||
if (global_error_collector.count != 0) {
|
||||
return 1;
|
||||
@@ -2249,8 +2246,6 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
}
|
||||
lb_generate_code(gen);
|
||||
|
||||
arena_free_all(&temporary_arena);
|
||||
|
||||
switch (build_context.build_mode) {
|
||||
case BuildMode_Executable:
|
||||
case BuildMode_DynamicLibrary:
|
||||
@@ -2269,6 +2264,7 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
}
|
||||
|
||||
remove_temp_files(gen);
|
||||
arena_free_all(&temporary_arena);
|
||||
|
||||
if (run_output) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
|
||||
Reference in New Issue
Block a user