mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Move more from heap_allocator() to temporary_allocator()
This commit is contained in:
+11
-14
@@ -6986,10 +6986,10 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
|
|||||||
isize lhs_count = -1;
|
isize lhs_count = -1;
|
||||||
i32 variadic_index = -1;
|
i32 variadic_index = -1;
|
||||||
|
|
||||||
auto positional_operands = array_make<Operand>(heap_allocator(), 0, 0);
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
auto named_operands = array_make<Operand>(heap_allocator(), 0, 0);
|
|
||||||
defer (array_free(&positional_operands));
|
auto positional_operands = array_make<Operand>(temporary_allocator(), 0, 0);
|
||||||
defer (array_free(&named_operands));
|
auto named_operands = array_make<Operand>(temporary_allocator(), 0, 0);
|
||||||
|
|
||||||
if (procs.count == 1) {
|
if (procs.count == 1) {
|
||||||
Entity *e = procs[0];
|
Entity *e = procs[0];
|
||||||
@@ -7030,7 +7030,7 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
|
|||||||
if (proc_arg_count >= 0) {
|
if (proc_arg_count >= 0) {
|
||||||
lhs_count = proc_arg_count;
|
lhs_count = proc_arg_count;
|
||||||
if (lhs_count > 0) {
|
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++) {
|
for (isize param_index = 0; param_index < lhs_count; param_index++) {
|
||||||
Entity *e = nullptr;
|
Entity *e = nullptr;
|
||||||
for (Entity *p : procs) {
|
for (Entity *p : procs) {
|
||||||
@@ -7116,13 +7116,9 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
|
|||||||
array_add(&named_operands, o);
|
array_add(&named_operands, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_free(heap_allocator(), lhs);
|
auto valids = array_make<ValidIndexAndScore>(temporary_allocator(), 0, procs.count);
|
||||||
|
|
||||||
auto valids = array_make<ValidIndexAndScore>(heap_allocator(), 0, procs.count);
|
auto proc_entities = array_make<Entity *>(temporary_allocator(), 0, procs.count*2 + 1);
|
||||||
defer (array_free(&valids));
|
|
||||||
|
|
||||||
auto proc_entities = array_make<Entity *>(heap_allocator(), 0, procs.count*2 + 1);
|
|
||||||
defer (array_free(&proc_entities));
|
|
||||||
for (Entity *proc : procs) {
|
for (Entity *proc : procs) {
|
||||||
array_add(&proc_entities, proc);
|
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) {
|
gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *operand, Ast *call) {
|
||||||
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
|
|
||||||
ast_node(ce, CallExpr, call);
|
ast_node(ce, CallExpr, call);
|
||||||
|
|
||||||
Type *original_type = operand->type;
|
Type *original_type = operand->type;
|
||||||
@@ -7614,7 +7612,6 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
|
|||||||
bool show_error = true;
|
bool show_error = true;
|
||||||
|
|
||||||
Array<Operand> operands = {};
|
Array<Operand> operands = {};
|
||||||
defer (array_free(&operands));
|
|
||||||
|
|
||||||
CallArgumentError err = CallArgumentError_None;
|
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)) {
|
if (is_call_expr_field_value(ce)) {
|
||||||
named_fields = true;
|
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) {
|
for_array(i, ce->args) {
|
||||||
Ast *arg = ce->args[i];
|
Ast *arg = ce->args[i];
|
||||||
ast_node(fv, FieldValue, arg);
|
ast_node(fv, FieldValue, arg);
|
||||||
@@ -7661,7 +7658,7 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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;
|
Entity **lhs = nullptr;
|
||||||
isize lhs_count = -1;
|
isize lhs_count = -1;
|
||||||
|
|||||||
+29
-32
@@ -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) {
|
gb_internal void check_scope_usage_internal(Checker *c, Scope *scope, u64 vet_flags, bool per_entity) {
|
||||||
u64 original_vet_flags = vet_flags;
|
u64 original_vet_flags = vet_flags;
|
||||||
|
|
||||||
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
Array<VettedEntity> vetted_entities = {};
|
Array<VettedEntity> vetted_entities = {};
|
||||||
array_init(&vetted_entities, heap_allocator());
|
array_init(&vetted_entities, temporary_allocator());
|
||||||
defer (array_free(&vetted_entities));
|
|
||||||
|
|
||||||
rw_mutex_shared_lock(&scope->mutex);
|
rw_mutex_shared_lock(&scope->mutex);
|
||||||
for (auto const &entry : scope->elements) {
|
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 = {};
|
PtrMap<AstPackage *, ImportGraphNode *> M = {};
|
||||||
map_init(&M, 2*c->parser->packages.count);
|
map_init(&M, 2*c->parser->packages.count);
|
||||||
defer (map_destroy(&M));
|
defer (map_destroy(&M));
|
||||||
|
|
||||||
for_array(i, c->parser->packages) {
|
for_array(i, c->parser->packages) {
|
||||||
AstPackage *pkg = c->parser->packages[i];
|
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);
|
map_set(&M, pkg, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5147,7 +5148,7 @@ gb_internal Array<ImportGraphNode *> generate_import_dependency_graph(Checker *c
|
|||||||
}
|
}
|
||||||
|
|
||||||
Array<ImportGraphNode *> G = {};
|
Array<ImportGraphNode *> G = {};
|
||||||
array_init(&G, heap_allocator(), 0, M.count);
|
array_init(&G, allocator, 0, M.count);
|
||||||
|
|
||||||
isize i = 0;
|
isize i = 0;
|
||||||
for (auto const &entry : M) {
|
for (auto const &entry : M) {
|
||||||
@@ -5166,7 +5167,7 @@ struct ImportPathItem {
|
|||||||
Ast * decl;
|
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 = {};
|
Array<ImportPathItem> empty_path = {};
|
||||||
|
|
||||||
if (ptr_set_update(visited, start)) {
|
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};
|
ImportPathItem item = {pkg, decl};
|
||||||
if (pkg == end) {
|
if (pkg == end) {
|
||||||
auto path = array_make<ImportPathItem>(heap_allocator());
|
auto path = array_make<ImportPathItem>(allocator);
|
||||||
array_add(&path, item);
|
array_add(&path, item);
|
||||||
return path;
|
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) {
|
if (next_path.count > 0) {
|
||||||
array_add(&next_path, item);
|
array_add(&next_path, item);
|
||||||
return next_path;
|
return next_path;
|
||||||
@@ -5809,14 +5810,9 @@ gb_internal void check_export_entities(Checker *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gb_internal void check_import_entities(Checker *c) {
|
gb_internal void check_import_entities(Checker *c) {
|
||||||
Array<ImportGraphNode *> dep_graph = generate_import_dependency_graph(c);
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
defer ({
|
|
||||||
for_array(i, dep_graph) {
|
|
||||||
import_graph_node_destroy(dep_graph[i], heap_allocator());
|
|
||||||
}
|
|
||||||
array_free(&dep_graph);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
Array<ImportGraphNode *> dep_graph = generate_import_dependency_graph(c, temporary_allocator());
|
||||||
|
|
||||||
TIME_SECTION("check_import_entities - sort packages");
|
TIME_SECTION("check_import_entities - sort packages");
|
||||||
// NOTE(bill): Priority queue
|
// NOTE(bill): Priority queue
|
||||||
@@ -5826,8 +5822,7 @@ gb_internal void check_import_entities(Checker *c) {
|
|||||||
defer (ptr_set_destroy(&emitted));
|
defer (ptr_set_destroy(&emitted));
|
||||||
|
|
||||||
Array<ImportGraphNode *> package_order = {};
|
Array<ImportGraphNode *> package_order = {};
|
||||||
array_init(&package_order, heap_allocator(), 0, c->parser->packages.count);
|
array_init(&package_order, temporary_allocator(), 0, c->parser->packages.count);
|
||||||
defer (array_free(&package_order));
|
|
||||||
|
|
||||||
while (pq.queue.count > 0) {
|
while (pq.queue.count > 0) {
|
||||||
ImportGraphNode *n = priority_queue_pop(&pq);
|
ImportGraphNode *n = priority_queue_pop(&pq);
|
||||||
@@ -5835,11 +5830,12 @@ gb_internal void check_import_entities(Checker *c) {
|
|||||||
AstPackage *pkg = n->pkg;
|
AstPackage *pkg = n->pkg;
|
||||||
|
|
||||||
if (n->dep_count > 0) {
|
if (n->dep_count > 0) {
|
||||||
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
|
|
||||||
PtrSet<AstPackage *> visited = {};
|
PtrSet<AstPackage *> visited = {};
|
||||||
defer (ptr_set_destroy(&visited));
|
defer (ptr_set_destroy(&visited));
|
||||||
|
|
||||||
auto path = find_import_path(c, pkg, pkg, &visited);
|
auto path = find_import_path(c, pkg, pkg, &visited, temporary_allocator());
|
||||||
defer (array_free(&path));
|
|
||||||
|
|
||||||
if (path.count > 1) {
|
if (path.count > 1) {
|
||||||
ImportPathItem item = path[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);
|
GB_ASSERT(path_ != nullptr);
|
||||||
if (tuple == nullptr) {
|
if (tuple == nullptr) {
|
||||||
return false;
|
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) {
|
for (Entity *dep : var_decl->deps) {
|
||||||
if (dep == end) {
|
if (dep == end) {
|
||||||
auto path = array_make<Entity *>(heap_allocator());
|
auto path = array_make<Entity *>(allocator);
|
||||||
array_add(&path, dep);
|
array_add(&path, dep);
|
||||||
*path_ = path;
|
*path_ = path;
|
||||||
return true;
|
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) {
|
if (next_path.count > 0) {
|
||||||
array_add(&next_path, dep);
|
array_add(&next_path, dep);
|
||||||
*path_ = next_path;
|
*path_ = next_path;
|
||||||
@@ -5990,7 +5986,7 @@ gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet<Entity
|
|||||||
return false;
|
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_ = {};
|
PtrSet<Entity *> visited_ = {};
|
||||||
bool made_visited = false;
|
bool made_visited = false;
|
||||||
if (visited == nullptr) {
|
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);
|
GB_ASSERT(t->kind == Type_Proc);
|
||||||
|
|
||||||
Array<Entity *> path = {};
|
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;
|
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;
|
return path;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Entity *dep : decl->deps) {
|
for (Entity *dep : decl->deps) {
|
||||||
if (dep == end) {
|
if (dep == end) {
|
||||||
auto path = array_make<Entity *>(heap_allocator());
|
auto path = array_make<Entity *>(allocator);
|
||||||
array_add(&path, dep);
|
array_add(&path, dep);
|
||||||
return path;
|
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) {
|
if (next_path.count > 0) {
|
||||||
array_add(&next_path, dep);
|
array_add(&next_path, dep);
|
||||||
return next_path;
|
return next_path;
|
||||||
@@ -6061,8 +6057,8 @@ gb_internal void calculate_global_init_order(Checker *c) {
|
|||||||
Entity *e = n->entity;
|
Entity *e = n->entity;
|
||||||
|
|
||||||
if (n->dep_count > 0) {
|
if (n->dep_count > 0) {
|
||||||
auto path = find_entity_path(e, e);
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
defer (array_free(&path));
|
auto path = find_entity_path(e, e, temporary_allocator());
|
||||||
|
|
||||||
if (path.count > 0) {
|
if (path.count > 0) {
|
||||||
Entity *e = path[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");
|
TIME_SECTION("initialize and check for collisions in type info array");
|
||||||
{
|
{
|
||||||
|
TEMPORARY_ALLOCATOR_GUARD();
|
||||||
|
|
||||||
Array<TypeInfoPair> type_info_types; // sorted after filled
|
Array<TypeInfoPair> type_info_types; // sorted after filled
|
||||||
array_init(&type_info_types, heap_allocator());
|
array_init(&type_info_types, temporary_allocator());
|
||||||
defer (array_free(&type_info_types));
|
|
||||||
|
|
||||||
for (auto const &tt : c->info.min_dep_type_info_set) {
|
for (auto const &tt : c->info.min_dep_type_info_set) {
|
||||||
array_add(&type_info_types, tt);
|
array_add(&type_info_types, tt);
|
||||||
|
|||||||
Reference in New Issue
Block a user