mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-06 21:17:40 +00:00
Make all maps use heap allocator implicitly
This commit is contained in:
@@ -1110,7 +1110,7 @@ gb_internal bool cache_load_file_directive(CheckerContext *c, Ast *call, String
|
||||
new_cache->path = path;
|
||||
new_cache->data = data;
|
||||
new_cache->file_error = file_error;
|
||||
string_map_init(&new_cache->hashes, heap_allocator(), 32);
|
||||
string_map_init(&new_cache->hashes, 32);
|
||||
string_map_set(&c->info->load_file_cache, path, new_cache);
|
||||
if (cache_) *cache_ = new_cache;
|
||||
} else {
|
||||
|
||||
@@ -5753,7 +5753,7 @@ gb_internal CallArgumentData check_call_arguments(CheckerContext *c, Operand *op
|
||||
// in order to improve the type inference system
|
||||
|
||||
StringMap<Type *> type_hint_map = {}; // Key: String
|
||||
string_map_init(&type_hint_map, heap_allocator(), 2*args.count);
|
||||
string_map_init(&type_hint_map, 2*args.count);
|
||||
defer (string_map_destroy(&type_hint_map));
|
||||
|
||||
Type *ptype = nullptr;
|
||||
@@ -8283,7 +8283,6 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
|
||||
bool is_partial = cl->tag && (cl->tag->BasicDirective.name.string == "partial");
|
||||
|
||||
SeenMap seen = {}; // NOTE(bill): Multimap, Key: ExactValue
|
||||
map_init(&seen, heap_allocator());
|
||||
defer (map_destroy(&seen));
|
||||
|
||||
if (cl->elems.count > 0 && cl->elems[0]->kind == Ast_FieldValue) {
|
||||
|
||||
@@ -929,7 +929,6 @@ gb_internal void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags
|
||||
}
|
||||
|
||||
SeenMap seen = {}; // NOTE(bill): Multimap, Key: ExactValue
|
||||
map_init(&seen, heap_allocator());
|
||||
defer (map_destroy(&seen));
|
||||
|
||||
for_array(stmt_index, bs->stmts) {
|
||||
|
||||
@@ -221,7 +221,7 @@ gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) {
|
||||
gb_internal Scope *create_scope(CheckerInfo *info, Scope *parent, isize init_elements_capacity=DEFAULT_SCOPE_CAPACITY) {
|
||||
Scope *s = gb_alloc_item(permanent_allocator(), Scope);
|
||||
s->parent = parent;
|
||||
string_map_init(&s->elements, heap_allocator(), init_elements_capacity);
|
||||
string_map_init(&s->elements, init_elements_capacity);
|
||||
ptr_set_init(&s->imported, 0);
|
||||
|
||||
if (parent != nullptr && parent != builtin_pkg->scope) {
|
||||
@@ -1135,14 +1135,14 @@ gb_internal void init_checker_info(CheckerInfo *i) {
|
||||
|
||||
array_init(&i->definitions, a);
|
||||
array_init(&i->entities, a);
|
||||
map_init(&i->global_untyped, a);
|
||||
string_map_init(&i->foreigns, a);
|
||||
map_init(&i->gen_procs, a);
|
||||
map_init(&i->gen_types, a);
|
||||
map_init(&i->global_untyped);
|
||||
string_map_init(&i->foreigns);
|
||||
map_init(&i->gen_procs);
|
||||
map_init(&i->gen_types);
|
||||
array_init(&i->type_info_types, a);
|
||||
map_init(&i->type_info_map, a);
|
||||
string_map_init(&i->files, a);
|
||||
string_map_init(&i->packages, a);
|
||||
map_init(&i->type_info_map);
|
||||
string_map_init(&i->files);
|
||||
string_map_init(&i->packages);
|
||||
array_init(&i->variable_init_order, a);
|
||||
array_init(&i->testing_procedures, a, 0, 0);
|
||||
array_init(&i->init_procedures, a, 0, 0);
|
||||
@@ -1160,8 +1160,8 @@ gb_internal void init_checker_info(CheckerInfo *i) {
|
||||
|
||||
mpmc_init(&i->intrinsics_entry_point_usage, a, 1<<10); // just waste some memory here, even if it probably never used
|
||||
|
||||
map_init(&i->objc_msgSend_types, a);
|
||||
string_map_init(&i->load_file_cache, a);
|
||||
map_init(&i->objc_msgSend_types);
|
||||
string_map_init(&i->load_file_cache);
|
||||
|
||||
array_init(&i->all_procedures, heap_allocator());
|
||||
|
||||
@@ -2490,7 +2490,7 @@ gb_internal bool is_entity_a_dependency(Entity *e) {
|
||||
|
||||
gb_internal Array<EntityGraphNode *> generate_entity_dependency_graph(CheckerInfo *info, gbAllocator allocator) {
|
||||
PtrMap<Entity *, EntityGraphNode *> M = {};
|
||||
map_init(&M, allocator, info->entities.count);
|
||||
map_init(&M, info->entities.count);
|
||||
defer (map_destroy(&M));
|
||||
for_array(i, info->entities) {
|
||||
Entity *e = info->entities[i];
|
||||
@@ -4200,7 +4200,7 @@ gb_internal void add_import_dependency_node(Checker *c, Ast *decl, PtrMap<AstPac
|
||||
|
||||
gb_internal Array<ImportGraphNode *> generate_import_dependency_graph(Checker *c) {
|
||||
PtrMap<AstPackage *, ImportGraphNode *> M = {};
|
||||
map_init(&M, heap_allocator(), 2*c->parser->packages.count);
|
||||
map_init(&M, 2*c->parser->packages.count);
|
||||
defer (map_destroy(&M));
|
||||
|
||||
for_array(i, c->parser->packages) {
|
||||
@@ -4688,7 +4688,7 @@ gb_internal void check_collect_entities_all(Checker *c) {
|
||||
auto *wd = &collect_entity_worker_data[i];
|
||||
wd->c = c;
|
||||
wd->ctx = make_checker_context(c);
|
||||
map_init(&wd->untyped, heap_allocator());
|
||||
map_init(&wd->untyped);
|
||||
}
|
||||
|
||||
for (auto const &entry : c->info.files.entries) {
|
||||
@@ -4804,7 +4804,6 @@ gb_internal void check_import_entities(Checker *c) {
|
||||
CheckerContext ctx = make_checker_context(c);
|
||||
|
||||
UntypedExprInfoMap untyped = {};
|
||||
map_init(&untyped, heap_allocator());
|
||||
defer (map_destroy(&untyped));
|
||||
|
||||
isize min_pkg_index = 0;
|
||||
@@ -5159,7 +5158,6 @@ gb_internal void check_unchecked_bodies(Checker *c) {
|
||||
GB_ASSERT(c->procs_to_check.count == 0);
|
||||
|
||||
UntypedExprInfoMap untyped = {};
|
||||
map_init(&untyped, heap_allocator());
|
||||
defer (map_destroy(&untyped));
|
||||
|
||||
// use the `procs_to_check` array
|
||||
@@ -5212,7 +5210,6 @@ gb_internal void check_unchecked_bodies(Checker *c) {
|
||||
gb_internal void check_safety_all_procedures_for_unchecked(Checker *c) {
|
||||
GB_ASSERT(DEBUG_CHECK_ALL_PROCEDURES);
|
||||
UntypedExprInfoMap untyped = {};
|
||||
map_init(&untyped, heap_allocator());
|
||||
defer (map_destroy(&untyped));
|
||||
|
||||
|
||||
@@ -5345,7 +5342,7 @@ gb_internal void check_procedure_bodies(Checker *c) {
|
||||
|
||||
for (isize i = 0; i < thread_count; i++) {
|
||||
check_procedure_bodies_worker_data[i].c = c;
|
||||
map_init(&check_procedure_bodies_worker_data[i].untyped, heap_allocator());
|
||||
map_init(&check_procedure_bodies_worker_data[i].untyped);
|
||||
}
|
||||
|
||||
defer (for (isize i = 0; i < thread_count; i++) {
|
||||
@@ -5545,7 +5542,7 @@ gb_internal void check_deferred_procedures(Checker *c) {
|
||||
|
||||
gb_internal void check_unique_package_names(Checker *c) {
|
||||
StringMap<AstPackage *> pkgs = {}; // Key: package name
|
||||
string_map_init(&pkgs, heap_allocator(), 2*c->info.packages.entries.count);
|
||||
string_map_init(&pkgs, 2*c->info.packages.entries.count);
|
||||
defer (string_map_destroy(&pkgs));
|
||||
|
||||
for (auto const &entry : c->info.packages) {
|
||||
|
||||
@@ -373,7 +373,7 @@ gb_internal char const *string_intern(String const &string) {
|
||||
}
|
||||
|
||||
gb_internal void init_string_interner(void) {
|
||||
map_init(&string_intern_map, heap_allocator());
|
||||
map_init(&string_intern_map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,13 +53,12 @@ gb_internal void odin_doc_writer_item_tracker_init(OdinDocWriterItemTracker<T> *
|
||||
gb_internal void odin_doc_writer_prepare(OdinDocWriter *w) {
|
||||
w->state = OdinDocWriterState_Preparing;
|
||||
|
||||
gbAllocator a = heap_allocator();
|
||||
string_map_init(&w->string_cache, a);
|
||||
string_map_init(&w->string_cache);
|
||||
|
||||
map_init(&w->file_cache, a);
|
||||
map_init(&w->pkg_cache, a);
|
||||
map_init(&w->entity_cache, a);
|
||||
map_init(&w->type_cache, a);
|
||||
map_init(&w->file_cache);
|
||||
map_init(&w->pkg_cache);
|
||||
map_init(&w->entity_cache);
|
||||
map_init(&w->type_cache);
|
||||
|
||||
odin_doc_writer_item_tracker_init(&w->files, 1);
|
||||
odin_doc_writer_item_tracker_init(&w->pkgs, 1);
|
||||
|
||||
@@ -55,30 +55,30 @@ gb_internal void lb_init_module(lbModule *m, Checker *c) {
|
||||
}
|
||||
|
||||
gbAllocator a = heap_allocator();
|
||||
map_init(&m->types, a);
|
||||
map_init(&m->func_raw_types, a);
|
||||
map_init(&m->struct_field_remapping, a);
|
||||
map_init(&m->values, a);
|
||||
map_init(&m->soa_values, a);
|
||||
string_map_init(&m->members, a);
|
||||
map_init(&m->procedure_values, a);
|
||||
string_map_init(&m->procedures, a);
|
||||
string_map_init(&m->const_strings, a);
|
||||
map_init(&m->function_type_map, a);
|
||||
map_init(&m->equal_procs, a);
|
||||
map_init(&m->hasher_procs, a);
|
||||
map_init(&m->map_get_procs, a);
|
||||
map_init(&m->map_set_procs, a);
|
||||
map_init(&m->types);
|
||||
map_init(&m->func_raw_types);
|
||||
map_init(&m->struct_field_remapping);
|
||||
map_init(&m->values);
|
||||
map_init(&m->soa_values);
|
||||
string_map_init(&m->members);
|
||||
map_init(&m->procedure_values);
|
||||
string_map_init(&m->procedures);
|
||||
string_map_init(&m->const_strings);
|
||||
map_init(&m->function_type_map);
|
||||
map_init(&m->equal_procs);
|
||||
map_init(&m->hasher_procs);
|
||||
map_init(&m->map_get_procs);
|
||||
map_init(&m->map_set_procs);
|
||||
array_init(&m->procedures_to_generate, a, 0, 1024);
|
||||
array_init(&m->missing_procedures_to_check, a, 0, 16);
|
||||
map_init(&m->debug_values, a);
|
||||
map_init(&m->debug_values);
|
||||
array_init(&m->debug_incomplete_types, a, 0, 1024);
|
||||
|
||||
string_map_init(&m->objc_classes, a);
|
||||
string_map_init(&m->objc_selectors, a);
|
||||
string_map_init(&m->objc_classes);
|
||||
string_map_init(&m->objc_selectors);
|
||||
|
||||
map_init(&m->map_info_map, a, 0);
|
||||
map_init(&m->map_cell_info_map, a, 0);
|
||||
map_init(&m->map_info_map, 0);
|
||||
map_init(&m->map_cell_info_map, 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -127,9 +127,9 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
|
||||
|
||||
gen->info = &c->info;
|
||||
|
||||
map_init(&gen->modules, permanent_allocator(), gen->info->packages.entries.count*2);
|
||||
map_init(&gen->modules_through_ctx, permanent_allocator(), gen->info->packages.entries.count*2);
|
||||
map_init(&gen->anonymous_proc_lits, heap_allocator(), 1024);
|
||||
map_init(&gen->modules, gen->info->packages.entries.count*2);
|
||||
map_init(&gen->modules_through_ctx, gen->info->packages.entries.count*2);
|
||||
map_init(&gen->anonymous_proc_lits, 1024);
|
||||
|
||||
|
||||
array_init(&gen->foreign_libraries, heap_allocator(), 0, 1024);
|
||||
|
||||
@@ -119,9 +119,9 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
|
||||
p->branch_blocks.allocator = a;
|
||||
p->context_stack.allocator = a;
|
||||
p->scope_stack.allocator = a;
|
||||
map_init(&p->selector_values, a, 0);
|
||||
map_init(&p->selector_addr, a, 0);
|
||||
map_init(&p->tuple_fix_map, a, 0);
|
||||
map_init(&p->selector_values, 0);
|
||||
map_init(&p->selector_addr, 0);
|
||||
map_init(&p->tuple_fix_map, 0);
|
||||
|
||||
if (p->is_foreign) {
|
||||
lb_add_foreign_library_path(p->module, entity->Procedure.foreign_library);
|
||||
@@ -345,7 +345,7 @@ gb_internal lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name
|
||||
p->blocks.allocator = a;
|
||||
p->branch_blocks.allocator = a;
|
||||
p->context_stack.allocator = a;
|
||||
map_init(&p->tuple_fix_map, a, 0);
|
||||
map_init(&p->tuple_fix_map, 0);
|
||||
|
||||
|
||||
char *c_link_name = alloc_cstring(permanent_allocator(), p->name);
|
||||
@@ -486,7 +486,7 @@ gb_internal void lb_begin_procedure_body(lbProcedure *p) {
|
||||
p->entry_block = lb_create_block(p, "entry", true);
|
||||
lb_start_block(p, p->entry_block);
|
||||
|
||||
map_init(&p->direct_parameters, heap_allocator());
|
||||
map_init(&p->direct_parameters);
|
||||
|
||||
GB_ASSERT(p->type != nullptr);
|
||||
|
||||
|
||||
@@ -2516,7 +2516,7 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
add_library_collection(str_lit("core"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("core")));
|
||||
add_library_collection(str_lit("vendor"), get_fullpath_relative(heap_allocator(), odin_root_dir(), str_lit("vendor")));
|
||||
|
||||
map_init(&build_context.defined_values, heap_allocator());
|
||||
map_init(&build_context.defined_values);
|
||||
build_context.extra_packages.allocator = heap_allocator();
|
||||
string_set_init(&build_context.test_names);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ gb_internal gb_inline u32 ptr_map_hash_key(void const *key) {
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename V> gb_internal void map_init (PtrMap<K, V> *h, gbAllocator a, isize capacity = 16);
|
||||
template <typename K, typename V> gb_internal void map_init (PtrMap<K, V> *h, isize capacity = 16);
|
||||
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);
|
||||
@@ -68,11 +68,15 @@ template <typename K, typename V> gb_internal void multi_map_remove (PtrMap<
|
||||
template <typename K, typename V> gb_internal void multi_map_remove_all(PtrMap<K, V> *h, K key);
|
||||
#endif
|
||||
|
||||
gb_internal gbAllocator map_allocator(void) {
|
||||
return heap_allocator();
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
gb_internal gb_inline void map_init(PtrMap<K, V> *h, gbAllocator a, isize capacity) {
|
||||
gb_internal gb_inline void map_init(PtrMap<K, V> *h, isize capacity) {
|
||||
capacity = next_pow2_isize(capacity);
|
||||
slice_init(&h->hashes, a, capacity);
|
||||
array_init(&h->entries, a, 0, capacity);
|
||||
slice_init(&h->hashes, map_allocator(), capacity);
|
||||
array_init(&h->entries, map_allocator(), 0, capacity);
|
||||
for (isize i = 0; i < capacity; i++) {
|
||||
h->hashes.data[i] = MAP_SENTINEL;
|
||||
}
|
||||
@@ -80,6 +84,9 @@ gb_internal gb_inline void map_init(PtrMap<K, V> *h, gbAllocator a, isize capaci
|
||||
|
||||
template <typename K, typename V>
|
||||
gb_internal gb_inline void map_destroy(PtrMap<K, V> *h) {
|
||||
if (h->entries.allocator.proc == nullptr) {
|
||||
h->entries.allocator = map_allocator();
|
||||
}
|
||||
slice_free(&h->hashes, h->entries.allocator);
|
||||
array_free(&h->entries);
|
||||
}
|
||||
@@ -162,6 +169,9 @@ gb_internal void map_reset_entries(PtrMap<K, V> *h) {
|
||||
|
||||
template <typename K, typename V>
|
||||
gb_internal void map_reserve(PtrMap<K, V> *h, isize cap) {
|
||||
if (h->entries.allocator.proc == nullptr) {
|
||||
h->entries.allocator = map_allocator();
|
||||
}
|
||||
array_reserve(&h->entries, cap);
|
||||
if (h->entries.count*2 < h->hashes.count) {
|
||||
return;
|
||||
|
||||
@@ -35,7 +35,7 @@ struct StringMap {
|
||||
};
|
||||
|
||||
|
||||
template <typename T> gb_internal void string_map_init (StringMap<T> *h, gbAllocator a, isize capacity = 16);
|
||||
template <typename T> gb_internal void string_map_init (StringMap<T> *h, isize capacity = 16);
|
||||
template <typename T> gb_internal void string_map_destroy (StringMap<T> *h);
|
||||
|
||||
template <typename T> gb_internal T * string_map_get (StringMap<T> *h, char const *key);
|
||||
@@ -56,11 +56,15 @@ template <typename T> gb_internal void string_map_grow (StringMap<T>
|
||||
template <typename T> gb_internal void string_map_rehash (StringMap<T> *h, isize new_count);
|
||||
template <typename T> gb_internal void string_map_reserve (StringMap<T> *h, isize cap);
|
||||
|
||||
gb_internal gbAllocator string_map_allocator(void) {
|
||||
return heap_allocator();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
gb_internal gb_inline void string_map_init(StringMap<T> *h, gbAllocator a, isize capacity) {
|
||||
gb_internal gb_inline void string_map_init(StringMap<T> *h, isize capacity) {
|
||||
capacity = next_pow2_isize(capacity);
|
||||
slice_init(&h->hashes, a, capacity);
|
||||
array_init(&h->entries, a, 0, capacity);
|
||||
slice_init(&h->hashes, string_map_allocator(), capacity);
|
||||
array_init(&h->entries, string_map_allocator(), 0, capacity);
|
||||
for (isize i = 0; i < capacity; i++) {
|
||||
h->hashes.data[i] = MAP_SENTINEL;
|
||||
}
|
||||
@@ -68,6 +72,9 @@ gb_internal gb_inline void string_map_init(StringMap<T> *h, gbAllocator a, isize
|
||||
|
||||
template <typename T>
|
||||
gb_internal gb_inline void string_map_destroy(StringMap<T> *h) {
|
||||
if (h->entries.allocator.proc == nullptr) {
|
||||
h->entries.allocator = string_map_allocator();
|
||||
}
|
||||
slice_free(&h->hashes, h->entries.allocator);
|
||||
array_free(&h->entries);
|
||||
}
|
||||
@@ -147,6 +154,9 @@ gb_internal void string_map_reset_entries(StringMap<T> *h) {
|
||||
|
||||
template <typename T>
|
||||
gb_internal void string_map_reserve(StringMap<T> *h, isize cap) {
|
||||
if (h->entries.allocator.proc == nullptr) {
|
||||
h->entries.allocator = string_map_allocator();
|
||||
}
|
||||
array_reserve(&h->entries, cap);
|
||||
if (h->entries.count*2 < h->hashes.count) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user