diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 73aa14c49..03ee6eb14 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1638,7 +1638,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 } } StringSet name_set = {}; - string_set_init(&name_set, temporary_allocator(), 2*ce->args.count); + string_set_init(&name_set, heap_allocator(), 2*ce->args.count); for_array(i, ce->args) { String name = {}; diff --git a/src/check_type.cpp b/src/check_type.cpp index bf84dbcce..f65768277 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2228,7 +2228,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el soa_struct->Struct.soa_elem = elem; soa_struct->Struct.soa_count = count; - scope = create_scope(ctx->info, ctx->scope); + scope = create_scope(ctx->info, ctx->scope, 8); soa_struct->Struct.scope = scope; String params_xyzw[4] = { diff --git a/src/checker.cpp b/src/checker.cpp index 610ec02eb..b97cc5ee1 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -250,7 +250,8 @@ Scope *create_scope_from_file(CheckerInfo *info, AstFile *f) { GB_ASSERT(f->pkg != nullptr); GB_ASSERT(f->pkg->scope != nullptr); - Scope *s = create_scope(info, f->pkg->scope); + isize init_elements_capacity = gb_max(DEFAULT_SCOPE_CAPACITY, 2*f->total_file_decl_count); + Scope *s = create_scope(info, f->pkg->scope, init_elements_capacity); array_reserve(&s->delayed_imports, f->imports.count); array_reserve(&s->delayed_directives, f->directive_count); @@ -265,11 +266,12 @@ Scope *create_scope_from_file(CheckerInfo *info, AstFile *f) { Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { GB_ASSERT(pkg != nullptr); - isize decl_count = 0; - for_array(i, pkg->files) { - decl_count += pkg->files[i]->decls.count; + isize total_pkg_decl_count = 0; + for_array(j, pkg->files) { + total_pkg_decl_count += pkg->files.data[j]->total_file_decl_count; } - isize init_elements_capacity = 2*decl_count; + + isize init_elements_capacity = gb_max(DEFAULT_SCOPE_CAPACITY, 2*total_pkg_decl_count); Scope *s = create_scope(c->info, builtin_pkg->scope, init_elements_capacity); s->flags |= ScopeFlag_Pkg; @@ -3993,6 +3995,10 @@ bool collect_file_decls(CheckerContext *ctx, Slice const &decls) { for_array(i, decls) { Ast *decl = decls[i]; + if (decl->state_flags & StateFlag_BeenHandled) { + continue; + } + switch (decl->kind) { case_ast_node(vd, ValueDecl, decl); check_collect_value_decl(ctx, decl); @@ -4051,6 +4057,7 @@ bool collect_file_decls(CheckerContext *ctx, Slice const &decls) { void check_create_file_scopes(Checker *c) { for_array(i, c->parser->packages) { AstPackage *pkg = c->parser->packages[i]; + isize total_pkg_decl_count = 0; for_array(j, pkg->files) { AstFile *f = pkg->files[j]; @@ -4149,6 +4156,8 @@ void check_collect_entities_all(Checker *c) { } void check_import_entities(Checker *c) { +#define TIME_SECTION(str) do { debugf("[Section] %s\n", str); if (build_context.show_more_timings) timings_start_section(&global_timings, str_lit(str)); } while (0) + Array dep_graph = generate_import_dependency_graph(c); defer ({ for_array(i, dep_graph) { @@ -4157,6 +4166,8 @@ void check_import_entities(Checker *c) { array_free(&dep_graph); }); + + TIME_SECTION("check_import_entities - cycles"); // NOTE(bill): Priority queue auto pq = priority_queue_create(dep_graph, import_graph_node_cmp, import_graph_node_swap); @@ -4210,6 +4221,7 @@ void check_import_entities(Checker *c) { array_add(&package_order, n); } + TIME_SECTION("check_import_entities - used"); for_array(i, c->parser->packages) { AstPackage *pkg = c->parser->packages[i]; switch (pkg->kind) { @@ -4220,6 +4232,7 @@ void check_import_entities(Checker *c) { } } + TIME_SECTION("check_import_entities - collect checked packages from decl list"); CheckerContext ctx = make_checker_context(c); for (isize loop_count = 0; ; loop_count++) { @@ -4244,6 +4257,7 @@ void check_import_entities(Checker *c) { } } + TIME_SECTION("check_import_entities - collect file decls"); for (isize pkg_index = 0; pkg_index < package_order.count; pkg_index++) { ImportGraphNode *node = package_order[pkg_index]; AstPackage *pkg = node->pkg; @@ -4272,6 +4286,7 @@ void check_import_entities(Checker *c) { } } + TIME_SECTION("check_import_entities - check delayed entities"); for_array(i, package_order) { ImportGraphNode *node = package_order[i]; GB_ASSERT(node->scope->flags&ScopeFlag_Pkg); @@ -4297,6 +4312,8 @@ void check_import_entities(Checker *c) { } } } + +#undef TIME_SECTION } diff --git a/src/common.cpp b/src/common.cpp index 018afd803..0e11ed5a6 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -605,7 +605,8 @@ GB_ALLOCATOR_PROC(temp_allocator_proc) { gbAllocator temporary_allocator() { - return {temp_allocator_proc, &temporary_allocator_data}; + return permanent_allocator(); + // return {temp_allocator_proc, &temporary_allocator_data}; } diff --git a/src/parser.cpp b/src/parser.cpp index fcc8078f7..f1f348ff4 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5261,6 +5261,28 @@ String dir_from_path(String path) { return base_dir; } +isize calc_decl_count(Ast *decl) { + isize count = 0; + switch (decl->kind) { + case Ast_BlockStmt: + for_array(i, decl->BlockStmt.stmts) { + count += calc_decl_count(decl->BlockStmt.stmts.data[i]); + } + break; + case Ast_ValueDecl: + count = decl->ValueDecl.names.count; + break; + case Ast_ForeignBlockDecl: + count = calc_decl_count(decl->ForeignBlockDecl.body); + break; + case Ast_ImportDecl: + case Ast_ForeignImportDecl: + count = 1; + break; + } + return count; +} + bool parse_file(Parser *p, AstFile *f) { if (f->tokens.count == 0) { return true; @@ -5346,6 +5368,8 @@ bool parse_file(Parser *p, AstFile *f) { stmt->ExprStmt.expr->kind == Ast_ProcLit) { syntax_error(stmt, "Procedure literal evaluated but not used"); } + + f->total_file_decl_count += calc_decl_count(stmt); } } diff --git a/src/parser.hpp b/src/parser.hpp index 9fc4c95a3..b3bdfd15d 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -112,6 +112,7 @@ struct AstFile { bool in_foreign_block; bool allow_type; + isize total_file_decl_count; Slice decls; Array imports; // 'import' isize directive_count;