Browse Source

Use local mutexes rather than a global one for the dependency insertion

gingerBill 2 years ago
parent
commit
0d87b2e8db
2 changed files with 11 additions and 30 deletions
  1. 6 24
      src/checker.cpp
  2. 5 6
      src/checker.hpp

+ 6 - 24
src/checker.cpp

@@ -743,21 +743,17 @@ gb_internal void check_scope_usage(Checker *c, Scope *scope) {
 
 
 gb_internal void add_dependency(CheckerInfo *info, DeclInfo *d, Entity *e) {
-	mutex_lock(&info->deps_mutex);
+	mutex_lock(&d->deps_mutex);
 	ptr_set_add(&d->deps, e);
-	mutex_unlock(&info->deps_mutex);
+	mutex_unlock(&d->deps_mutex);
 }
-gb_internal void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type, bool require_mutex) {
+gb_internal void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type) {
 	if (d == nullptr) {
 		return;
 	}
-	if (require_mutex) {
-		mutex_lock(&info->deps_mutex);
-	}
+	mutex_lock(&d->type_info_deps_mutex);
 	ptr_set_add(&d->type_info_deps, type);
-	if (require_mutex) {
-		mutex_unlock(&info->deps_mutex);
-	}
+	mutex_unlock(&d->type_info_deps_mutex);
 }
 
 gb_internal AstPackage *get_core_package(CheckerInfo *info, String name) {
@@ -1157,13 +1153,6 @@ gb_internal void init_checker_info(CheckerInfo *i) {
 	array_init(&i->required_foreign_imports_through_force, a, 0, 0);
 
 
-
-	i->allow_identifier_uses = false;
-	if (i->allow_identifier_uses) {
-		array_init(&i->identifier_uses, a);
-	}
-
-
 	TIME_SECTION("checker info: mpmc queues");
 
 	mpmc_init(&i->entity_queue, a, 1<<20);
@@ -1194,7 +1183,6 @@ gb_internal void destroy_checker_info(CheckerInfo *i) {
 	string_map_destroy(&i->files);
 	string_map_destroy(&i->packages);
 	array_free(&i->variable_init_order);
-	array_free(&i->identifier_uses);
 	array_free(&i->required_foreign_imports_through_force);
 
 	mpmc_destroy(&i->entity_queue);
@@ -1597,12 +1585,6 @@ gb_internal void add_entity_use(CheckerContext *c, Ast *identifier, Entity *enti
 
 		identifier->Ident.entity = entity;
 
-		if (c->info->allow_identifier_uses) {
-			mutex_lock(&c->info->identifier_uses_mutex);
-			array_add(&c->info->identifier_uses, identifier);
-			mutex_unlock(&c->info->identifier_uses_mutex);
-		}
-
 		String dmsg = entity->deprecated_message;
 		if (dmsg.len > 0) {
 			warning(identifier, "%.*s is deprecated: %.*s", LIT(entity->token.string), LIT(dmsg));
@@ -1767,7 +1749,7 @@ gb_internal void add_type_info_type_internal(CheckerContext *c, Type *t) {
 		return;
 	}
 
-	add_type_info_dependency(c->info, c->decl, t, false);
+	add_type_info_dependency(c->info, c->decl, t);
 
 	auto found = map_get(&c->info->type_info_map, t);
 	if (found != nullptr) {

+ 5 - 6
src/checker.hpp

@@ -179,8 +179,12 @@ struct DeclInfo {
 	CommentGroup *comment;
 	CommentGroup *docs;
 
-	PtrSet<Entity *>  deps;
+	BlockingMutex    deps_mutex;
+	PtrSet<Entity *> deps;
+
+	BlockingMutex     type_info_deps_mutex;
 	PtrSet<Type *>    type_info_deps;
+
 	Array<BlockLabel> labels;
 };
 
@@ -375,11 +379,6 @@ struct CheckerInfo {
 	BlockingMutex foreign_mutex; // NOT recursive
 	StringMap<Entity *> foreigns;
 
-	// only used by 'odin query'
-	bool          allow_identifier_uses;
-	BlockingMutex identifier_uses_mutex;
-	Array<Ast *>  identifier_uses;
-
 	// NOTE(bill): These are actually MPSC queues
 	// TODO(bill): Convert them to be MPSC queues
 	MPMCQueue<Entity *> definition_queue;