aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-09-10 19:47:29 +0100
committergingerBill <gingerBill@users.noreply.github.com>2025-09-10 19:47:29 +0100
commit1c648126c73d01e6bce368bd8a55dbb89f0f2369 (patch)
tree025641d460d434d146666bad0e870aa884a64e3d
parent01258d4817bb8d04ab287d847c93d36952f11f22 (diff)
Move more from `heap_allocator()` to `temporary_allocator()`
-rw-r--r--src/check_expr.cpp25
-rw-r--r--src/checker.cpp61
2 files changed, 40 insertions, 46 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index bdbccb4f8..dad9e8348 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -6986,10 +6986,10 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
isize lhs_count = -1;
i32 variadic_index = -1;
- auto positional_operands = array_make<Operand>(heap_allocator(), 0, 0);
- auto named_operands = array_make<Operand>(heap_allocator(), 0, 0);
- defer (array_free(&positional_operands));
- defer (array_free(&named_operands));
+ TEMPORARY_ALLOCATOR_GUARD();
+
+ auto positional_operands = array_make<Operand>(temporary_allocator(), 0, 0);
+ auto named_operands = array_make<Operand>(temporary_allocator(), 0, 0);
if (procs.count == 1) {
Entity *e = procs[0];
@@ -7030,7 +7030,7 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
if (proc_arg_count >= 0) {
lhs_count = proc_arg_count;
if (lhs_count > 0) {
- lhs = gb_alloc_array(heap_allocator(), Entity *, lhs_count);
+ lhs = gb_alloc_array(temporary_allocator(), Entity *, lhs_count);
for (isize param_index = 0; param_index < lhs_count; param_index++) {
Entity *e = nullptr;
for (Entity *p : procs) {
@@ -7116,13 +7116,9 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
array_add(&named_operands, o);
}
- gb_free(heap_allocator(), lhs);
-
- auto valids = array_make<ValidIndexAndScore>(heap_allocator(), 0, procs.count);
- defer (array_free(&valids));
+ auto valids = array_make<ValidIndexAndScore>(temporary_allocator(), 0, procs.count);
- auto proc_entities = array_make<Entity *>(heap_allocator(), 0, procs.count*2 + 1);
- defer (array_free(&proc_entities));
+ auto proc_entities = array_make<Entity *>(temporary_allocator(), 0, procs.count*2 + 1);
for (Entity *proc : procs) {
array_add(&proc_entities, proc);
}
@@ -7606,6 +7602,8 @@ gb_internal isize lookup_polymorphic_record_parameter(Type *t, String parameter_
gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *operand, Ast *call) {
+ TEMPORARY_ALLOCATOR_GUARD();
+
ast_node(ce, CallExpr, call);
Type *original_type = operand->type;
@@ -7614,7 +7612,6 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
bool show_error = true;
Array<Operand> operands = {};
- defer (array_free(&operands));
CallArgumentError err = CallArgumentError_None;
@@ -7629,7 +7626,7 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
if (is_call_expr_field_value(ce)) {
named_fields = true;
- operands = array_make<Operand>(heap_allocator(), ce->args.count);
+ operands = array_make<Operand>(temporary_allocator(), ce->args.count);
for_array(i, ce->args) {
Ast *arg = ce->args[i];
ast_node(fv, FieldValue, arg);
@@ -7661,7 +7658,7 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
}
} else {
- operands = array_make<Operand>(heap_allocator(), 0, 2*ce->args.count);
+ operands = array_make<Operand>(temporary_allocator(), 0, 2*ce->args.count);
Entity **lhs = nullptr;
isize lhs_count = -1;
diff --git a/src/checker.cpp b/src/checker.cpp
index 1fca3dfe5..87dd775ca 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -722,9 +722,10 @@ gb_internal bool check_vet_unused(Checker *c, Entity *e, VettedEntity *ve) {
gb_internal void check_scope_usage_internal(Checker *c, Scope *scope, u64 vet_flags, bool per_entity) {
u64 original_vet_flags = vet_flags;
+
+ TEMPORARY_ALLOCATOR_GUARD();
Array<VettedEntity> vetted_entities = {};
- array_init(&vetted_entities, heap_allocator());
- defer (array_free(&vetted_entities));
+ array_init(&vetted_entities, temporary_allocator());
rw_mutex_shared_lock(&scope->mutex);
for (auto const &entry : scope->elements) {
@@ -5123,14 +5124,14 @@ gb_internal void add_import_dependency_node(Checker *c, Ast *decl, PtrMap<AstPac
}
}
-gb_internal Array<ImportGraphNode *> generate_import_dependency_graph(Checker *c) {
+gb_internal Array<ImportGraphNode *> generate_import_dependency_graph(Checker *c, gbAllocator allocator) {
PtrMap<AstPackage *, ImportGraphNode *> M = {};
map_init(&M, 2*c->parser->packages.count);
defer (map_destroy(&M));
for_array(i, c->parser->packages) {
AstPackage *pkg = c->parser->packages[i];
- ImportGraphNode *n = import_graph_node_create(heap_allocator(), pkg);
+ ImportGraphNode *n = import_graph_node_create(allocator, pkg);
map_set(&M, pkg, n);
}
@@ -5147,7 +5148,7 @@ gb_internal Array<ImportGraphNode *> generate_import_dependency_graph(Checker *c
}
Array<ImportGraphNode *> G = {};
- array_init(&G, heap_allocator(), 0, M.count);
+ array_init(&G, allocator, 0, M.count);
isize i = 0;
for (auto const &entry : M) {
@@ -5166,7 +5167,7 @@ struct ImportPathItem {
Ast * decl;
};
-gb_internal Array<ImportPathItem> find_import_path(Checker *c, AstPackage *start, AstPackage *end, PtrSet<AstPackage *> *visited) {
+gb_internal Array<ImportPathItem> find_import_path(Checker *c, AstPackage *start, AstPackage *end, PtrSet<AstPackage *> *visited, gbAllocator allocator) {
Array<ImportPathItem> empty_path = {};
if (ptr_set_update(visited, start)) {
@@ -5200,11 +5201,11 @@ gb_internal Array<ImportPathItem> find_import_path(Checker *c, AstPackage *start
ImportPathItem item = {pkg, decl};
if (pkg == end) {
- auto path = array_make<ImportPathItem>(heap_allocator());
+ auto path = array_make<ImportPathItem>(allocator);
array_add(&path, item);
return path;
}
- auto next_path = find_import_path(c, pkg, end, visited);
+ auto next_path = find_import_path(c, pkg, end, visited, allocator);
if (next_path.count > 0) {
array_add(&next_path, item);
return next_path;
@@ -5809,14 +5810,9 @@ gb_internal void check_export_entities(Checker *c) {
}
gb_internal void check_import_entities(Checker *c) {
- Array<ImportGraphNode *> dep_graph = generate_import_dependency_graph(c);
- defer ({
- for_array(i, dep_graph) {
- import_graph_node_destroy(dep_graph[i], heap_allocator());
- }
- array_free(&dep_graph);
- });
+ TEMPORARY_ALLOCATOR_GUARD();
+ Array<ImportGraphNode *> dep_graph = generate_import_dependency_graph(c, temporary_allocator());
TIME_SECTION("check_import_entities - sort packages");
// NOTE(bill): Priority queue
@@ -5826,8 +5822,7 @@ gb_internal void check_import_entities(Checker *c) {
defer (ptr_set_destroy(&emitted));
Array<ImportGraphNode *> package_order = {};
- array_init(&package_order, heap_allocator(), 0, c->parser->packages.count);
- defer (array_free(&package_order));
+ array_init(&package_order, temporary_allocator(), 0, c->parser->packages.count);
while (pq.queue.count > 0) {
ImportGraphNode *n = priority_queue_pop(&pq);
@@ -5835,11 +5830,12 @@ gb_internal void check_import_entities(Checker *c) {
AstPackage *pkg = n->pkg;
if (n->dep_count > 0) {
+ TEMPORARY_ALLOCATOR_GUARD();
+
PtrSet<AstPackage *> visited = {};
defer (ptr_set_destroy(&visited));
- auto path = find_import_path(c, pkg, pkg, &visited);
- defer (array_free(&path));
+ auto path = find_import_path(c, pkg, pkg, &visited, temporary_allocator());
if (path.count > 1) {
ImportPathItem item = path[path.count-1];
@@ -5957,9 +5953,9 @@ gb_internal void check_import_entities(Checker *c) {
}
-gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, PtrSet<Entity *> *visited = nullptr);
+gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, gbAllocator allocator, PtrSet<Entity *> *visited = nullptr);
-gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet<Entity *> *visited, Array<Entity *> *path_) {
+gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, gbAllocator allocator, PtrSet<Entity *> *visited, Array<Entity *> *path_) {
GB_ASSERT(path_ != nullptr);
if (tuple == nullptr) {
return false;
@@ -5973,12 +5969,12 @@ gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet<Entity
}
for (Entity *dep : var_decl->deps) {
if (dep == end) {
- auto path = array_make<Entity *>(heap_allocator());
+ auto path = array_make<Entity *>(allocator);
array_add(&path, dep);
*path_ = path;
return true;
}
- auto next_path = find_entity_path(dep, end, visited);
+ auto next_path = find_entity_path(dep, end, allocator, visited);
if (next_path.count > 0) {
array_add(&next_path, dep);
*path_ = next_path;
@@ -5990,7 +5986,7 @@ gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet<Entity
return false;
}
-gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, PtrSet<Entity *> *visited) {
+gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, gbAllocator allocator, PtrSet<Entity *> *visited) {
PtrSet<Entity *> visited_ = {};
bool made_visited = false;
if (visited == nullptr) {
@@ -6014,20 +6010,20 @@ gb_internal Array<Entity *> find_entity_path(Entity *start, Entity *end, PtrSet<
GB_ASSERT(t->kind == Type_Proc);
Array<Entity *> path = {};
- if (find_entity_path_tuple(t->Proc.params, end, visited, &path)) {
+ if (find_entity_path_tuple(t->Proc.params, end, allocator, visited, &path)) {
return path;
}
- if (find_entity_path_tuple(t->Proc.results, end, visited, &path)) {
+ if (find_entity_path_tuple(t->Proc.results, end, allocator, visited, &path)) {
return path;
}
} else {
for (Entity *dep : decl->deps) {
if (dep == end) {
- auto path = array_make<Entity *>(heap_allocator());
+ auto path = array_make<Entity *>(allocator);
array_add(&path, dep);
return path;
}
- auto next_path = find_entity_path(dep, end, visited);
+ auto next_path = find_entity_path(dep, end, allocator, visited);
if (next_path.count > 0) {
array_add(&next_path, dep);
return next_path;
@@ -6061,8 +6057,8 @@ gb_internal void calculate_global_init_order(Checker *c) {
Entity *e = n->entity;
if (n->dep_count > 0) {
- auto path = find_entity_path(e, e);
- defer (array_free(&path));
+ TEMPORARY_ALLOCATOR_GUARD();
+ auto path = find_entity_path(e, e, temporary_allocator());
if (path.count > 0) {
Entity *e = path[0];
@@ -7450,9 +7446,10 @@ gb_internal void check_parsed_files(Checker *c) {
TIME_SECTION("initialize and check for collisions in type info array");
{
+ TEMPORARY_ALLOCATOR_GUARD();
+
Array<TypeInfoPair> type_info_types; // sorted after filled
- array_init(&type_info_types, heap_allocator());
- defer (array_free(&type_info_types));
+ array_init(&type_info_types, temporary_allocator());
for (auto const &tt : c->info.min_dep_type_info_set) {
array_add(&type_info_types, tt);