aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2025-02-18 13:31:34 +0000
committergingerBill <bill@gingerbill.org>2025-02-18 13:31:34 +0000
commit19b59461b04f4b6b63fa24d70e9c9376b3dd3249 (patch)
tree0d88108de7e47e98d3033dfe34f93fb932711fa5 /src
parent721bcf2249fe2f2f6dd462833fede983205d6c5a (diff)
Use `TypeSet` for DeclInfo deps
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp4
-rw-r--r--src/checker.cpp10
-rw-r--r--src/checker.hpp80
-rw-r--r--src/name_canonicalization.cpp37
4 files changed, 71 insertions, 60 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index d6f8e6fa7..5607ea725 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -1742,8 +1742,8 @@ gb_internal void add_deps_from_child_to_parent(DeclInfo *decl) {
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);
+ for (auto const &tt : decl->type_info_deps) {
+ type_set_add(&decl->parent->type_info_deps, tt);
}
rw_mutex_unlock(&decl->parent->type_info_deps_mutex);
diff --git a/src/checker.cpp b/src/checker.cpp
index 32e5ca405..38da38b0c 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -173,7 +173,7 @@ gb_internal void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) {
d->parent = parent;
d->scope = scope;
ptr_set_init(&d->deps, 0);
- ptr_set_init(&d->type_info_deps, 0);
+ type_set_init(&d->type_info_deps, 0);
d->labels.allocator = heap_allocator();
d->variadic_reuses.allocator = heap_allocator();
d->variadic_reuse_max_bytes = 0;
@@ -838,7 +838,7 @@ gb_internal void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *
}
}
rw_mutex_lock(&d->type_info_deps_mutex);
- ptr_set_add(&d->type_info_deps, type);
+ type_set_add(&d->type_info_deps, type);
rw_mutex_unlock(&d->type_info_deps_mutex);
}
@@ -2506,8 +2506,8 @@ gb_internal void add_dependency_to_set(Checker *c, Entity *entity) {
if (decl == nullptr) {
return;
}
- for (Type *t : decl->type_info_deps) {
- add_min_dep_type_info(c, t);
+ for (TypeInfoPair const tt : decl->type_info_deps) {
+ add_min_dep_type_info(c, tt.type);
}
for (Entity *e : decl->deps) {
@@ -6742,7 +6742,7 @@ gb_internal void check_parsed_files(Checker *c) {
auto const &tt = c->info.type_info_types[i];
bool exists = map_set_if_not_previously_exists(&c->info.minimum_dependency_type_info_index_map, cast(uintptr)tt.hash, i);
if (!exists) {
- continue
+ continue;
}
for (auto const &entry : c->info.minimum_dependency_type_info_index_map) {
if (entry.key != cast(uintptr)tt.hash) {
diff --git a/src/checker.hpp b/src/checker.hpp
index 52676d4ee..b8878d745 100644
--- a/src/checker.hpp
+++ b/src/checker.hpp
@@ -167,6 +167,61 @@ typedef DECL_ATTRIBUTE_PROC(DeclAttributeProc);
gb_internal void check_decl_attributes(CheckerContext *c, Array<Ast *> const &attributes, DeclAttributeProc *proc, AttributeContext *ac);
+struct TypeInfoPair {
+ Type *type;
+ u64 hash; // see: type_hash_canonical_type
+};
+
+struct TypeSet {
+ TypeInfoPair *keys;
+ usize count;
+ usize capacity;
+};
+
+static constexpr u64 TYPE_SET_TOMBSTONE = ~(u64)(0ull);
+
+struct TypeSetIterator {
+ TypeSet *set;
+ usize index;
+
+ TypeSetIterator &operator++() noexcept {
+ for (;;) {
+ ++index;
+ if (set->capacity == index) {
+ return *this;
+ }
+ TypeInfoPair key = set->keys[index];
+ if (key.hash != 0 && key.hash != TYPE_SET_TOMBSTONE) {
+ return *this;
+ }
+ }
+ }
+
+ bool operator==(TypeSetIterator const &other) const noexcept {
+ return this->set == other.set && this->index == other.index;
+ }
+
+
+ operator TypeInfoPair *() const {
+ return &set->keys[index];
+ }
+};
+
+
+gb_internal void type_set_init (TypeSet *s, isize capacity = 16);
+gb_internal void type_set_destroy(TypeSet *s);
+gb_internal Type *type_set_add (TypeSet *s, Type *ptr);
+gb_internal Type *type_set_add (TypeSet *s, TypeInfoPair pair);
+gb_internal bool type_set_update (TypeSet *s, Type *ptr); // returns true if it previously existed
+gb_internal bool type_set_update (TypeSet *s, TypeInfoPair pair); // returns true if it previously existed
+gb_internal bool type_set_exists (TypeSet *s, Type *ptr);
+gb_internal void type_set_remove (TypeSet *s, Type *ptr);
+gb_internal void type_set_clear (TypeSet *s);
+gb_internal TypeInfoPair *type_set_retrieve(TypeSet *s, Type *ptr);
+
+gb_internal TypeSetIterator begin(TypeSet &set) noexcept;
+gb_internal TypeSetIterator end(TypeSet &set) noexcept;
+
enum ProcCheckedState : u8 {
ProcCheckedState_Unchecked,
@@ -221,8 +276,8 @@ struct DeclInfo {
RwMutex deps_mutex;
PtrSet<Entity *> deps;
- RwMutex type_info_deps_mutex;
- PtrSet<Type *> type_info_deps; // TODO(bill): Use TypeSet
+ RwMutex type_info_deps_mutex;
+ TypeSet type_info_deps;
BlockingMutex type_and_value_mutex;
@@ -409,27 +464,6 @@ struct Defineable {
String pos_str;
};
-struct TypeInfoPair {
- Type *type;
- u64 hash; // see: type_hash_canonical_type
-};
-
-struct TypeSet {
- TypeInfoPair *keys;
- usize count;
- usize capacity;
-};
-
-gb_internal void type_set_init (TypeSet *s, isize capacity = 16);
-gb_internal void type_set_destroy(TypeSet *s);
-gb_internal Type *type_set_add (TypeSet *s, Type *ptr);
-gb_internal bool type_set_update (TypeSet *s, Type *ptr); // returns true if it previously existed
-gb_internal bool type_set_update (TypeSet *s, TypeInfoPair pair); // returns true if it previously existed
-gb_internal bool type_set_exists (TypeSet *s, Type *ptr);
-gb_internal void type_set_remove (TypeSet *s, Type *ptr);
-gb_internal void type_set_clear (TypeSet *s);
-gb_internal TypeInfoPair *type_set_retrieve(TypeSet *s, Type *ptr);
-
// CheckerInfo stores all the symbol information for a type-checked program
struct CheckerInfo {
Checker *checker;
diff --git a/src/name_canonicalization.cpp b/src/name_canonicalization.cpp
index de35312da..ef0e23f38 100644
--- a/src/name_canonicalization.cpp
+++ b/src/name_canonicalization.cpp
@@ -57,11 +57,10 @@ gb_internal GB_COMPARE_PROC(type_info_pair_cmp) {
return x->hash < y->hash ? -1 : +1;
}
-static constexpr u64 TYPE_SET_TOMBSTONE = ~(u64)(0ull);
-
gb_internal void type_set_init (TypeSet *s, isize capacity);
gb_internal void type_set_destroy(TypeSet *s);
gb_internal Type *type_set_add (TypeSet *s, Type *ptr);
+gb_internal Type *type_set_add (TypeSet *s, TypeInfoPair pair);
gb_internal bool type_set_update (TypeSet *s, Type *ptr); // returns true if it previously existed
gb_internal bool type_set_update (TypeSet *s, TypeInfoPair pair); // returns true if it previously existed
gb_internal bool type_set_exists (TypeSet *s, Type *ptr);
@@ -73,34 +72,6 @@ gb_internal gbAllocator type_set_allocator(void) {
return heap_allocator();
}
-struct TypeSetIterator {
- TypeSet *set;
- usize index;
-
- TypeSetIterator &operator++() noexcept {
- for (;;) {
- ++index;
- if (set->capacity == index) {
- return *this;
- }
- TypeInfoPair key = set->keys[index];
- if (key.hash != 0 && key.hash != TYPE_SET_TOMBSTONE) {
- return *this;
- }
- }
- }
-
- bool operator==(TypeSetIterator const &other) const noexcept {
- return this->set == other.set && this->index == other.index;
- }
-
-
- operator TypeInfoPair *() const {
- return &set->keys[index];
- }
-};
-
-
gb_internal TypeSetIterator begin(TypeSet &set) noexcept {
usize index = 0;
while (index < set.capacity) {
@@ -257,6 +228,12 @@ gb_internal Type *type_set_add(TypeSet *s, Type *ptr) {
return ptr;
}
+gb_internal Type *type_set_add(TypeSet *s, TypeInfoPair pair) {
+ type_set_update(s, pair);
+ return pair.type;
+}
+
+
gb_internal void type_set_remove(TypeSet *s, Type *ptr) {
isize index = type_set__find(s, ptr);