Add uncomment add_type_info_type calls for type assertions

This commit is contained in:
gingerBill
2023-01-05 11:54:21 +00:00
parent bbb2164e38
commit 1517f1d779
5 changed files with 71 additions and 65 deletions
+32 -28
View File
@@ -1411,6 +1411,37 @@ end:;
}
gb_internal void add_deps_from_child_to_parent(DeclInfo *decl) {
if (decl && decl->parent) {
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);
}
}
}
struct ProcUsingVar {
Entity *e;
Entity *uvar;
@@ -1576,34 +1607,7 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
check_scope_usage(ctx->checker, ctx->scope);
// if (decl->parent) {
// 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);
// }
// }
add_deps_from_child_to_parent(decl);
return true;
}
+4 -4
View File
@@ -8777,8 +8777,8 @@ gb_internal ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *no
return kind;
}
// add_type_info_type(c, o->type);
// add_type_info_type(c, bsrc->Union.variants[0]);
add_type_info_type(c, o->type);
add_type_info_type(c, bsrc->Union.variants[0]);
o->type = bsrc->Union.variants[0];
o->mode = Addressing_OptionalOk;
@@ -8810,8 +8810,8 @@ gb_internal ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *no
return kind;
}
// add_type_info_type(c, o->type);
// add_type_info_type(c, t);
add_type_info_type(c, o->type);
add_type_info_type(c, t);
o->type = t;
o->mode = Addressing_OptionalOk;
+5 -33
View File
@@ -2026,14 +2026,13 @@ gb_internal void add_min_dep_type_info(Checker *c, Type *t) {
ti_index = type_info_index(&c->info, t, false);
}
GB_ASSERT(ti_index >= 0);
if (map_get(set, ti_index)) {
// Type already exists;
return;
}
// IMPORTANT NOTE(bill): this must be copied as `map_set` takes a const ref
// and effectively assigns the `+1` of the value
isize const count = set->entries.count;
map_set(set, ti_index, count);
if (map_set_if_not_previously_exists(set, ti_index, count)) {
// Type already exists;
return;
}
// Add nested types
if (t->kind == Type_Named) {
@@ -5650,34 +5649,7 @@ gb_internal void check_walk_all_dependencies(DeclInfo *decl) {
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);
}
}
add_deps_from_child_to_parent(decl);
}
gb_internal void check_update_dependency_tree_for_procedures(Checker *c) {
+1
View File
@@ -1920,6 +1920,7 @@ gb_internal void lb_generate_code(lbGenerator *gen) {
if (!ptr_set_exists(min_dep_set, e)) {
continue;
}
DeclInfo *decl = decl_info_of_entity(e);
if (decl == nullptr) {
continue;
+29
View File
@@ -52,6 +52,7 @@ template <typename K, typename V> gb_internal void map_init (PtrMap<
template <typename K, typename V> gb_internal void map_destroy (PtrMap<K, V> *h);
template <typename K, typename V> gb_internal V * map_get (PtrMap<K, V> *h, K key);
template <typename K, typename V> gb_internal void map_set (PtrMap<K, V> *h, K key, V const &value);
template <typename K, typename V> gb_internal bool map_set_if_not_previously_exists(PtrMap<K, V> *h, K key, V const &value); // returns true if it previously existed
template <typename K, typename V> gb_internal void map_remove (PtrMap<K, V> *h, K key);
template <typename K, typename V> gb_internal void map_clear (PtrMap<K, V> *h);
template <typename K, typename V> gb_internal void map_grow (PtrMap<K, V> *h);
@@ -240,6 +241,34 @@ gb_internal void map_set(PtrMap<K, V> *h, K key, V const &value) {
}
}
// returns true if it previously existed
template <typename K, typename V>
gb_internal bool map_set_if_not_previously_exists(PtrMap<K, V> *h, K key, V const &value) {
MapIndex index;
MapFindResult fr;
if (h->hashes.count == 0) {
map_grow(h);
}
fr = map__find(h, key);
if (fr.entry_index != MAP_SENTINEL) {
return true;
} else {
index = map__add_entry(h, key);
if (fr.entry_prev != MAP_SENTINEL) {
h->entries.data[fr.entry_prev].next = index;
} else {
h->hashes.data[fr.hash_index] = index;
}
}
h->entries.data[index].value = value;
if (map__full(h)) {
map_grow(h);
}
return false;
}
template <typename K, typename V>
gb_internal void map__erase(PtrMap<K, V> *h, MapFindResult const &fr) {
MapFindResult last;