aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-01-04 13:52:38 +0000
committergingerBill <bill@gingerbill.org>2023-01-04 13:52:38 +0000
commitd4e18109da5fa051d689be84a6ecf1e77348c74e (patch)
treed2c359f5ddb40b8d82d913d7763a4944e4587a01 /src
parentd06a0e7093c3f06a474a040385f1b9dfdfce29ad (diff)
Move walking of dependencies for procedures to just before calculating the min dep set
Diffstat (limited to 'src')
-rw-r--r--src/check_builtin.cpp3
-rw-r--r--src/check_decl.cpp31
-rw-r--r--src/checker.cpp76
-rw-r--r--src/checker.hpp5
4 files changed, 71 insertions, 44 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 606283c32..294bc7da8 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -1118,8 +1118,7 @@ gb_internal bool cache_load_file_directive(CheckerContext *c, Ast *call, String
}
});
- char *c_str = alloc_cstring(heap_allocator(), path);
- defer (gb_free(heap_allocator(), c_str));
+ char *c_str = alloc_cstring(temporary_allocator(), path);
gbFile f = {};
if (cache == nullptr) {
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 72c69b5dc..07b547feb 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -1576,36 +1576,5 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
check_scope_usage(ctx->checker, ctx->scope);
- if (decl->parent != nullptr) {
- Scope *ps = decl->parent->scope;
- if (ps->flags & (ScopeFlag_File & ScopeFlag_Pkg & ScopeFlag_Global)) {
- return true;
- } else {
- // NOTE(bill): Add the dependencies from the procedure literal (lambda)
- // But only at the procedure level
-
- rw_mutex_shared_lock(&decl->deps_mutex);
- rw_mutex_lock(&decl->parent->deps_mutex);
-
- for (Entity *e : decl->deps) {
- ptr_set_add(&decl->parent->deps, e);
- }
-
- rw_mutex_unlock(&decl->parent->deps_mutex);
- rw_mutex_shared_unlock(&decl->deps_mutex);
-
-
- rw_mutex_shared_lock(&decl->type_info_deps_mutex);
- rw_mutex_lock(&decl->parent->type_info_deps_mutex);
-
- for (Type *t : decl->type_info_deps) {
- ptr_set_add(&decl->parent->type_info_deps, t);
- }
-
- rw_mutex_unlock(&decl->parent->type_info_deps_mutex);
- rw_mutex_shared_unlock(&decl->type_info_deps_mutex);
- }
- }
-
return true;
}
diff --git a/src/checker.cpp b/src/checker.cpp
index b8709f15e..5fc9a5551 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -174,6 +174,12 @@ gb_internal void import_graph_node_swap(ImportGraphNode **data, isize i, isize j
gb_internal void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) {
gb_zero_item(d);
+ if (parent) {
+ mutex_lock(&parent->next_mutex);
+ d->next_sibling = parent->next_child;
+ parent->next_child = d;
+ mutex_unlock(&parent->next_mutex);
+ }
d->parent = parent;
d->scope = scope;
ptr_set_init(&d->deps, 0);
@@ -5316,15 +5322,8 @@ gb_internal WORKER_TASK_PROC(check_proc_info_worker_proc) {
return 1;
}
-
-gb_internal void check_procedure_bodies(Checker *c) {
- GB_ASSERT(c != nullptr);
-
-
+gb_internal void check_init_worker_data(Checker *c) {
u32 thread_count = cast(u32)global_thread_pool.threads.count;
- if (!build_context.threaded_checker) {
- thread_count = 1;
- }
check_procedure_bodies_worker_data = gb_alloc_array(permanent_allocator(), CheckProcedureBodyWorkerData, thread_count);
@@ -5332,10 +5331,15 @@ gb_internal void check_procedure_bodies(Checker *c) {
check_procedure_bodies_worker_data[i].c = c;
map_init(&check_procedure_bodies_worker_data[i].untyped);
}
+}
- defer (for (isize i = 0; i < thread_count; i++) {
- map_destroy(&check_procedure_bodies_worker_data[i].untyped);
- });
+gb_internal void check_procedure_bodies(Checker *c) {
+ GB_ASSERT(c != nullptr);
+
+ u32 thread_count = cast(u32)global_thread_pool.threads.count;
+ if (!build_context.threaded_checker) {
+ thread_count = 1;
+ }
if (thread_count == 1) {
UntypedExprInfoMap *untyped = &check_procedure_bodies_worker_data[0].untyped;
@@ -5636,6 +5640,50 @@ gb_internal void add_type_info_for_type_definitions(Checker *c) {
}
}
+gb_internal void check_walk_all_dependencies(DeclInfo *decl) {
+ if (decl == nullptr) {
+ return;
+ }
+ for (DeclInfo *child = decl->next_child; child != nullptr; child = child->next_sibling) {
+ check_walk_all_dependencies(child);
+ }
+ if (decl->parent && decl->parent->entity && decl->parent->entity->kind == Entity_Procedure) {
+ Scope *ps = decl->parent->scope;
+ if (ps->flags & (ScopeFlag_File & ScopeFlag_Pkg & ScopeFlag_Global)) {
+ return;
+ } else {
+ // NOTE(bill): Add the dependencies from the procedure literal (lambda)
+ // But only at the procedure level
+ rw_mutex_shared_lock(&decl->deps_mutex);
+ rw_mutex_lock(&decl->parent->deps_mutex);
+
+ for (Entity *e : decl->deps) {
+ ptr_set_add(&decl->parent->deps, e);
+ }
+
+ rw_mutex_unlock(&decl->parent->deps_mutex);
+ rw_mutex_shared_unlock(&decl->deps_mutex);
+
+ rw_mutex_shared_lock(&decl->type_info_deps_mutex);
+ rw_mutex_lock(&decl->parent->type_info_deps_mutex);
+
+ for (Type *t : decl->type_info_deps) {
+ ptr_set_add(&decl->parent->type_info_deps, t);
+ }
+
+ rw_mutex_unlock(&decl->parent->type_info_deps_mutex);
+ rw_mutex_shared_unlock(&decl->type_info_deps_mutex);
+ }
+ }
+}
+
+gb_internal void check_update_dependency_tree_for_procedures(Checker *c) {
+ for (Entity *e : c->info.entities) {
+ DeclInfo *decl = e->decl_info;
+ check_walk_all_dependencies(decl);
+ }
+}
+
gb_internal void check_parsed_files(Checker *c) {
TIME_SECTION("map full filepaths to scope");
add_type_info_type(&c->builtin_ctx, t_invalid);
@@ -5657,6 +5705,9 @@ gb_internal void check_parsed_files(Checker *c) {
}
}
+ TIME_SECTION("init worker data");
+ check_init_worker_data(c);
+
TIME_SECTION("create file scopes");
check_create_file_scopes(c);
@@ -5744,6 +5795,9 @@ gb_internal void check_parsed_files(Checker *c) {
add_type_info_for_type_definitions(c);
check_merge_queues_into_arrays(c);
+ TIME_SECTION("update dependency tree for procedures");
+ check_update_dependency_tree_for_procedures(c);
+
TIME_SECTION("generate minimum dependency set");
generate_minimum_dependency_set(c, c->info.entry_point);
diff --git a/src/checker.hpp b/src/checker.hpp
index bb870e077..821d43922 100644
--- a/src/checker.hpp
+++ b/src/checker.hpp
@@ -159,6 +159,11 @@ char const *ProcCheckedState_strings[ProcCheckedState_COUNT] {
// DeclInfo is used to store information of certain declarations to allow for "any order" usage
struct DeclInfo {
DeclInfo * parent; // NOTE(bill): only used for procedure literals at the moment
+
+ BlockingMutex next_mutex;
+ DeclInfo * next_child;
+ DeclInfo * next_sibling;
+
Scope * scope;
Entity *entity;