From 5c519f0e8dada6b15166a257d22a07f2316a394f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 1 Jan 2023 16:19:21 +0000 Subject: Remove the synchronization primitive init/destroy calls --- src/parser.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index e07f26004..344dcb20d 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4858,10 +4858,6 @@ gb_internal bool init_parser(Parser *p) { GB_ASSERT(p != nullptr); string_set_init(&p->imported_files, heap_allocator()); array_init(&p->packages, heap_allocator()); - mutex_init(&p->imported_files_mutex); - mutex_init(&p->file_decl_mutex); - mutex_init(&p->packages_mutex); - mutex_init(&p->file_error_mutex); return true; } @@ -4878,10 +4874,6 @@ gb_internal void destroy_parser(Parser *p) { } array_free(&p->packages); string_set_destroy(&p->imported_files); - mutex_destroy(&p->imported_files_mutex); - mutex_destroy(&p->file_decl_mutex); - mutex_destroy(&p->packages_mutex); - mutex_destroy(&p->file_error_mutex); } @@ -4978,9 +4970,6 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin pkg->fullpath = path; array_init(&pkg->files, heap_allocator()); pkg->foreign_files.allocator = heap_allocator(); - mutex_init(&pkg->files_mutex); - mutex_init(&pkg->foreign_files_mutex); - // NOTE(bill): Single file initial package if (kind == Package_Init && string_ends_with(path, FILE_EXT)) { -- cgit v1.2.3 From d16ddf7926935e66057239194bbcb699409fafdf Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 1 Jan 2023 16:32:51 +0000 Subject: Use C++ style `for` loop over `for_array` macro in parser.cpp where posible --- src/parser.cpp | 95 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 45 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 344dcb20d..4a5ba78a9 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1905,13 +1905,11 @@ gb_internal void check_polymorphic_params_for_type(AstFile *f, Ast *polymorphic_ return; } ast_node(fl, FieldList, polymorphic_params); - for_array(fi, fl->list) { - Ast *field = fl->list[fi]; + for (Ast *field : fl->list) { if (field->kind != Ast_Field) { continue; } - for_array(i, field->Field.names) { - Ast *name = field->Field.names[i]; + for (Ast *name : field->Field.names) { if (name->kind != field->Field.names[0]->kind) { syntax_error(name, "Mixture of polymorphic names using both $ and not for %.*s parameters", LIT(token.string)); return; @@ -3473,16 +3471,14 @@ gb_internal Ast *parse_proc_type(AstFile *f, Token proc_token) { u64 tags = 0; bool is_generic = false; - for_array(i, params->FieldList.list) { - Ast *param = params->FieldList.list[i]; + for (Ast *param : params->FieldList.list) { ast_node(field, Field, param); if (field->type != nullptr) { if (field->type->kind == Ast_PolyType) { is_generic = true; goto end; } - for_array(j, field->names) { - Ast *name = field->names[j]; + for (Ast *name : field->names) { if (name->kind == Ast_PolyType) { is_generic = true; goto end; @@ -3646,8 +3642,9 @@ struct AstAndFlags { gb_internal Array convert_to_ident_list(AstFile *f, Array list, bool ignore_flags, bool allow_poly_names) { auto idents = array_make(heap_allocator(), 0, list.count); // Convert to ident list - for_array(i, list) { - Ast *ident = list[i].node; + isize i = 0; + for (AstAndFlags const &item : list) { + Ast *ident = item.node; if (!ignore_flags) { if (i != 0) { @@ -3678,6 +3675,7 @@ gb_internal Array convert_to_ident_list(AstFile *f, Array li break; } array_add(&idents, ident); + i += 1; } return idents; } @@ -3919,8 +3917,8 @@ gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_fl return ast_field_list(f, start_token, params); } - for_array(i, list) { - Ast *type = list[i].node; + for (AstAndFlags const &item : list) { + Ast *type = item.node; Token token = blank_token; if (allowed_flags&FieldFlag_Results) { // NOTE(bill): Make this nothing and not `_` @@ -3930,9 +3928,9 @@ gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_fl auto names = array_make(heap_allocator(), 1); token.pos = ast_token(type).pos; names[0] = ast_ident(f, token); - u32 flags = check_field_prefixes(f, list.count, allowed_flags, list[i].flags); + u32 flags = check_field_prefixes(f, list.count, allowed_flags, item.flags); Token tag = {}; - Ast *param = ast_field(f, names, list[i].node, nullptr, flags, tag, docs, f->line_comment); + Ast *param = ast_field(f, names, item.node, nullptr, flags, tag, docs, f->line_comment); array_add(¶ms, param); } @@ -4864,10 +4862,9 @@ gb_internal bool init_parser(Parser *p) { gb_internal void destroy_parser(Parser *p) { GB_ASSERT(p != nullptr); // TODO(bill): Fix memory leak - for_array(i, p->packages) { - AstPackage *pkg = p->packages[i]; - for_array(j, pkg->files) { - destroy_ast_file(pkg->files[j]); + for (AstPackage *pkg : p->packages) { + for (AstFile *file : pkg->files) { + destroy_ast_file(file); } array_free(&pkg->files); array_free(&pkg->foreign_files); @@ -4878,10 +4875,10 @@ gb_internal void destroy_parser(Parser *p) { gb_internal void parser_add_package(Parser *p, AstPackage *pkg) { - mutex_lock(&p->packages_mutex); - pkg->id = p->packages.count+1; - array_add(&p->packages, pkg); - mutex_unlock(&p->packages_mutex); + MUTEX_GUARD_BLOCK(&p->packages_mutex) { + pkg->id = p->packages.count+1; + array_add(&p->packages, pkg); + } } gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile imported_file); @@ -4893,15 +4890,15 @@ gb_internal WORKER_TASK_PROC(parser_worker_proc) { auto *node = gb_alloc_item(permanent_allocator(), ParseFileErrorNode); node->err = err; - mutex_lock(&wd->parser->file_error_mutex); - if (wd->parser->file_error_tail != nullptr) { - wd->parser->file_error_tail->next = node; - } - wd->parser->file_error_tail = node; - if (wd->parser->file_error_head == nullptr) { - wd->parser->file_error_head = node; + MUTEX_GUARD_BLOCK(&wd->parser->file_error_mutex) { + if (wd->parser->file_error_tail != nullptr) { + wd->parser->file_error_tail->next = node; + } + wd->parser->file_error_tail = node; + if (wd->parser->file_error_head == nullptr) { + wd->parser->file_error_head = node; + } } - mutex_unlock(&wd->parser->file_error_mutex); } return cast(isize)err; } @@ -4937,9 +4934,9 @@ gb_internal WORKER_TASK_PROC(foreign_file_worker_proc) { // TODO(bill): Actually do something with it break; } - mutex_lock(&pkg->foreign_files_mutex); - array_add(&pkg->foreign_files, foreign_file); - mutex_unlock(&pkg->foreign_files_mutex); + MUTEX_GUARD_BLOCK(&pkg->foreign_files_mutex) { + array_add(&pkg->foreign_files, foreign_file); + } return 0; } @@ -4973,13 +4970,13 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin // NOTE(bill): Single file initial package if (kind == Package_Init && string_ends_with(path, FILE_EXT)) { - FileInfo fi = {}; fi.name = filename_from_path(path); fi.fullpath = path; fi.size = get_file_size(path); fi.is_dir = false; + array_reserve(&pkg->files, 1); pkg->is_single_file = true; parser_add_package(p, pkg); parser_add_file_to_process(p, pkg, fi, pos); @@ -5017,8 +5014,17 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin return nullptr; } - for_array(list_index, list) { - FileInfo fi = list[list_index]; + isize files_to_reserve = 1; // always reserve 1 + for (FileInfo fi : list) { + String name = fi.name; + String ext = path_extension(name); + if (ext == FILE_EXT && !is_excluded_target_filename(name)) { + files_to_reserve += 1; + } + } + + array_reserve(&pkg->files, files_to_reserve); + for (FileInfo fi : list) { String name = fi.name; String ext = path_extension(name); if (ext == FILE_EXT) { @@ -5311,14 +5317,14 @@ gb_internal void parse_setup_file_decls(Parser *p, AstFile *f, String const &bas auto fullpaths = array_make(permanent_allocator(), 0, fl->filepaths.count); - for_array(fp_idx, fl->filepaths) { - String file_str = string_trim_whitespace(string_value_from_token(f, fl->filepaths[fp_idx])); + for (Token const &fp : fl->filepaths) { + String file_str = string_trim_whitespace(string_value_from_token(f, fp)); String fullpath = file_str; if (allow_check_foreign_filepath()) { String foreign_path = {}; bool ok = determine_path_from_string(&p->file_decl_mutex, node, base_dir, file_str, &foreign_path); if (!ok) { - decls[i] = ast_bad_decl(f, fl->filepaths[fp_idx], fl->filepaths[fl->filepaths.count-1]); + decls[i] = ast_bad_decl(f, fp, fl->filepaths[fl->filepaths.count-1]); goto end; } fullpath = foreign_path; @@ -5443,8 +5449,8 @@ gb_internal 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]); + for (Ast *stmt : decl->BlockStmt.stmts) { + count += calc_decl_count(stmt); } break; case Ast_WhenStmt: @@ -5564,8 +5570,8 @@ gb_internal bool parse_file(Parser *p, AstFile *f) { f->package_name = package_name.string; if (!f->pkg->is_single_file && docs != nullptr && docs->list.count > 0) { - for_array(i, docs->list) { - Token tok = docs->list[i]; GB_ASSERT(tok.kind == Token_Comment); + for (Token const &tok : docs->list) { + GB_ASSERT(tok.kind == Token_Comment); String str = tok.string; if (string_starts_with(str, str_lit("//"))) { String lc = string_trim_whitespace(substring(str, 2, str.len)); @@ -5776,8 +5782,7 @@ gb_internal ParseFileError parse_packages(Parser *p, String init_filename) { } - for_array(i, build_context.extra_packages) { - String path = build_context.extra_packages[i]; + for (String const &path : build_context.extra_packages) { String fullpath = path_to_full_path(heap_allocator(), path); // LEAK? if (!path_is_directory(fullpath)) { String const ext = str_lit(".odin"); -- cgit v1.2.3 From bfdcf900ef25566e57e46ec46683f8b6f2a9515a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 2 Jan 2023 00:56:06 +0000 Subject: Remove `global_` prefix from `global_thread_pool_*` procedures --- src/checker.cpp | 12 ++++++------ src/llvm_backend.cpp | 2 +- src/main.cpp | 4 ++-- src/parser.cpp | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index e70643940..a25d78d3d 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -4654,9 +4654,9 @@ gb_internal void check_with_workers(Checker *c, WorkerTaskProc *proc, isize tota for (isize i = 0; i < thread_count; i++) { - global_thread_pool_add_task(proc, thread_data+i); + thread_pool_add_task(proc, thread_data+i); } - global_thread_pool_wait(); + thread_pool_wait(); semaphore_wait(&c->info.collect_semaphore); } @@ -4704,9 +4704,9 @@ gb_internal void check_collect_entities_all(Checker *c) { if (build_context.threaded_checker) { for (auto const &entry : c->info.files.entries) { AstFile *f = entry.value; - global_thread_pool_add_task(check_collect_entities_all_worker_proc, f); + thread_pool_add_task(check_collect_entities_all_worker_proc, f); } - global_thread_pool_wait(); + thread_pool_wait(); } else { for (auto const &entry : c->info.files.entries) { AstFile *f = entry.value; @@ -5350,9 +5350,9 @@ gb_internal void check_procedure_bodies(Checker *c) { semaphore_post(&c->procs_to_check_semaphore, cast(i32)thread_count); for (isize i = 0; i < thread_count; i++) { - global_thread_pool_add_task(thread_proc_body, thread_data+i); + thread_pool_add_task(thread_proc_body, thread_data+i); } - global_thread_pool_wait(); + thread_pool_wait(); semaphore_wait(&c->procs_to_check_semaphore); isize global_remaining = c->procs_to_check_queue.count.load(std::memory_order_relaxed); diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 146cb2944..1c401552e 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2272,7 +2272,7 @@ gb_internal void lb_generate_code(lbGenerator *gen) { wd->code_gen_file_type = code_gen_file_type; wd->filepath_obj = filepath_obj; wd->m = m; - global_thread_pool_add_task(lb_llvm_emit_worker_proc, wd); + thread_pool_add_task(lb_llvm_emit_worker_proc, wd); } thread_pool_wait(&global_thread_pool); diff --git a/src/main.cpp b/src/main.cpp index 184ab471e..3ad0e160f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,10 +20,10 @@ gb_internal void init_global_thread_pool(void) { isize worker_count = thread_count-1; // NOTE(bill): The main thread will also be used for work thread_pool_init(&global_thread_pool, permanent_allocator(), worker_count, "ThreadPoolWorker"); } -gb_internal bool global_thread_pool_add_task(WorkerTaskProc *proc, void *data) { +gb_internal bool thread_pool_add_task(WorkerTaskProc *proc, void *data) { return thread_pool_add_task(&global_thread_pool, proc, data); } -gb_internal void global_thread_pool_wait(void) { +gb_internal void thread_pool_wait(void) { thread_pool_wait(&global_thread_pool); } diff --git a/src/parser.cpp b/src/parser.cpp index 4a5ba78a9..4d2a8ecf4 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4910,7 +4910,7 @@ gb_internal void parser_add_file_to_process(Parser *p, AstPackage *pkg, FileInfo auto wd = gb_alloc_item(permanent_allocator(), ParserWorkerData); wd->parser = p; wd->imported_file = f; - global_thread_pool_add_task(parser_worker_proc, wd); + thread_pool_add_task(parser_worker_proc, wd); } gb_internal WORKER_TASK_PROC(foreign_file_worker_proc) { @@ -4948,7 +4948,7 @@ gb_internal void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, wd->parser = p; wd->imported_file = f; wd->foreign_kind = kind; - global_thread_pool_add_task(foreign_file_worker_proc, wd); + thread_pool_add_task(foreign_file_worker_proc, wd); } @@ -5798,7 +5798,7 @@ gb_internal ParseFileError parse_packages(Parser *p, String init_filename) { } } - global_thread_pool_wait(); + thread_pool_wait(); for (ParseFileErrorNode *node = p->file_error_head; node != nullptr; node = node->next) { if (node->err != ParseFile_None) { -- cgit v1.2.3 From 600f2b7284b8974a18827242c18e790dab0cf06a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 3 Jan 2023 11:53:59 +0000 Subject: Use heap_allocator for all hash set types --- src/build_settings.cpp | 2 +- src/check_builtin.cpp | 2 +- src/check_decl.cpp | 2 +- src/check_expr.cpp | 1 - src/check_stmt.cpp | 1 - src/checker.cpp | 24 +++++++----------------- src/llvm_backend_general.cpp | 2 +- src/llvm_backend_type.cpp | 2 +- src/main.cpp | 8 ++++---- src/parser.cpp | 2 +- src/ptr_set.cpp | 21 +++++++++++++++------ src/string_set.cpp | 18 +++++++++++++----- 12 files changed, 45 insertions(+), 40 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 04d1ada93..75615a901 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -1369,7 +1369,7 @@ gb_internal bool init_build_paths(String init_filename) { // NOTE(Jeroen): We're pre-allocating BuildPathCOUNT slots so that certain paths are always at the same enumerated index. array_init(&bc->build_paths, permanent_allocator(), BuildPathCOUNT); - string_set_init(&bc->target_features_set, heap_allocator(), 1024); + string_set_init(&bc->target_features_set, 1024); // [BuildPathMainPackage] Turn given init path into a `Path`, which includes normalizing it into a full path. bc->build_paths[BuildPath_Main_Package] = path_from_string(ha, init_filename); diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 99d956f5e..36dc9b7a1 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -3086,7 +3086,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As } } StringSet name_set = {}; - string_set_init(&name_set, heap_allocator(), 2*ce->args.count); + string_set_init(&name_set, 2*ce->args.count); for_array(i, ce->args) { String name = {}; diff --git a/src/check_decl.cpp b/src/check_decl.cpp index e3486924c..0c1a7c325 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -1235,7 +1235,7 @@ gb_internal void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity, pg_entity->type = t_invalid; PtrSet entity_set = {}; - ptr_set_init(&entity_set, heap_allocator(), 2*pg->args.count); + ptr_set_init(&entity_set, 2*pg->args.count); for_array(i, pg->args) { Ast *arg = pg->args[i]; diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 3c998fc44..7a00b5353 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -196,7 +196,6 @@ gb_internal void check_did_you_mean_objc_entity(String const &name, Entity *e, b MUTEX_GUARD(objc_metadata->mutex); StringSet set = {}; - string_set_init(&set, heap_allocator()); defer (string_set_destroy(&set)); populate_check_did_you_mean_objc_entity(&set, e, is_type); diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index cf111e84c..945ba8f02 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1185,7 +1185,6 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ } PtrSet seen = {}; - ptr_set_init(&seen, heap_allocator()); defer (ptr_set_destroy(&seen)); for_array(i, bs->stmts) { diff --git a/src/checker.cpp b/src/checker.cpp index ccd0f3627..8da659461 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -72,7 +72,7 @@ gb_internal void entity_graph_node_set_destroy(EntityGraphNodeSet *s) { gb_internal void entity_graph_node_set_add(EntityGraphNodeSet *s, EntityGraphNode *n) { if (s->hashes.data == nullptr) { - ptr_set_init(s, heap_allocator()); + ptr_set_init(s); } ptr_set_add(s, n); } @@ -118,15 +118,10 @@ gb_internal void entity_graph_node_swap(EntityGraphNode **data, isize i, isize j gb_internal void import_graph_node_set_destroy(ImportGraphNodeSet *s) { - if (s->hashes.data != nullptr) { - ptr_set_destroy(s); - } + ptr_set_destroy(s); } gb_internal void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNode *n) { - if (s->hashes.data == nullptr) { - ptr_set_init(s, heap_allocator()); - } ptr_set_add(s, n); } @@ -185,8 +180,8 @@ gb_internal void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { gb_zero_item(d); d->parent = parent; d->scope = scope; - ptr_set_init(&d->deps, heap_allocator()); - ptr_set_init(&d->type_info_deps, heap_allocator()); + ptr_set_init(&d->deps); + ptr_set_init(&d->type_info_deps); array_init (&d->labels, heap_allocator()); } @@ -227,7 +222,7 @@ gb_internal Scope *create_scope(CheckerInfo *info, Scope *parent, isize init_ele Scope *s = gb_alloc_item(permanent_allocator(), Scope); s->parent = parent; string_map_init(&s->elements, heap_allocator(), init_elements_capacity); - ptr_set_init(&s->imported, heap_allocator(), 0); + ptr_set_init(&s->imported, 0); if (parent != nullptr && parent != builtin_pkg->scope) { Scope *prev_head_child = parent->head_child.exchange(s, std::memory_order_acq_rel); @@ -2270,8 +2265,8 @@ gb_internal void generate_minimum_dependency_set(Checker *c, Entity *start) { isize entity_count = c->info.entities.count; isize min_dep_set_cap = next_pow2_isize(entity_count*4); // empirically determined factor - ptr_set_init(&c->info.minimum_dependency_set, heap_allocator(), min_dep_set_cap); - ptr_set_init(&c->info.minimum_dependency_type_info_set, heap_allocator()); + ptr_set_init(&c->info.minimum_dependency_set, min_dep_set_cap); + ptr_set_init(&c->info.minimum_dependency_type_info_set); #define FORCE_ADD_RUNTIME_ENTITIES(condition, ...) do { \ if (condition) { \ @@ -3388,7 +3383,6 @@ gb_internal void check_decl_attributes(CheckerContext *c, Array const &at } StringSet set = {}; - string_set_init(&set, heap_allocator()); defer (string_set_destroy(&set)); for_array(i, attributes) { @@ -4759,7 +4753,6 @@ gb_internal void check_import_entities(Checker *c) { auto pq = priority_queue_create(dep_graph, import_graph_node_cmp, import_graph_node_swap); PtrSet emitted = {}; - ptr_set_init(&emitted, heap_allocator()); defer (ptr_set_destroy(&emitted)); Array package_order = {}; @@ -4773,7 +4766,6 @@ gb_internal void check_import_entities(Checker *c) { if (n->dep_count > 0) { PtrSet visited = {}; - ptr_set_init(&visited, heap_allocator()); defer (ptr_set_destroy(&visited)); auto path = find_import_path(c, pkg, pkg, &visited); @@ -4927,7 +4919,6 @@ gb_internal Array find_entity_path(Entity *start, Entity *end, PtrSet< bool made_visited = false; if (visited == nullptr) { made_visited = true; - ptr_set_init(&visited_, heap_allocator()); visited = &visited_; } defer (if (made_visited) { @@ -4990,7 +4981,6 @@ gb_internal void calculate_global_init_order(Checker *c) { auto pq = priority_queue_create(dep_graph, entity_graph_node_cmp, entity_graph_node_swap); PtrSet emitted = {}; - ptr_set_init(&emitted, heap_allocator()); defer (ptr_set_destroy(&emitted)); TIME_SECTION("calculate_global_init_order: queue sort"); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 22628e895..75675474a 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -133,7 +133,7 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { array_init(&gen->foreign_libraries, heap_allocator(), 0, 1024); - ptr_set_init(&gen->foreign_libraries_set, heap_allocator(), 1024); + ptr_set_init(&gen->foreign_libraries_set, 1024); if (USE_SEPARATE_MODULES) { for (auto const &entry : gen->info->packages) { diff --git a/src/llvm_backend_type.cpp b/src/llvm_backend_type.cpp index 26bb614e6..c306cdead 100644 --- a/src/llvm_backend_type.cpp +++ b/src/llvm_backend_type.cpp @@ -2,7 +2,7 @@ gb_internal isize lb_type_info_index(CheckerInfo *info, Type *type, bool err_on_ auto *set = &info->minimum_dependency_type_info_set; isize index = type_info_index(info, type, err_on_not_found); if (index >= 0) { - isize i = ptr_entry_index(set, index); + isize i = ptr_set_entry_index(set, index); if (i >= 0) { return i+1; } diff --git a/src/main.cpp b/src/main.cpp index ad9d6b0ef..91dcbdb01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -212,11 +212,11 @@ gb_internal i32 linker_stage(lbGenerator *gen) { StringSet libs = {}; - string_set_init(&libs, heap_allocator(), 64); + string_set_init(&libs, 64); defer (string_set_destroy(&libs)); StringSet asm_files = {}; - string_set_init(&asm_files, heap_allocator(), 64); + string_set_init(&asm_files, 64); defer (string_set_destroy(&asm_files)); for_array(j, gen->foreign_libraries) { @@ -371,7 +371,7 @@ gb_internal i32 linker_stage(lbGenerator *gen) { defer (gb_string_free(lib_str)); StringSet libs = {}; - string_set_init(&libs, heap_allocator(), 64); + string_set_init(&libs, 64); defer (string_set_destroy(&libs)); for_array(j, gen->foreign_libraries) { @@ -2518,7 +2518,7 @@ int main(int arg_count, char const **arg_ptr) { map_init(&build_context.defined_values, heap_allocator()); build_context.extra_packages.allocator = heap_allocator(); - string_set_init(&build_context.test_names, heap_allocator()); + string_set_init(&build_context.test_names); Array args = setup_args(arg_count, arg_ptr); diff --git a/src/parser.cpp b/src/parser.cpp index 4d2a8ecf4..046469c16 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4854,7 +4854,7 @@ gb_internal void destroy_ast_file(AstFile *f) { gb_internal bool init_parser(Parser *p) { GB_ASSERT(p != nullptr); - string_set_init(&p->imported_files, heap_allocator()); + string_set_init(&p->imported_files); array_init(&p->packages, heap_allocator()); return true; } diff --git a/src/ptr_set.cpp b/src/ptr_set.cpp index 9ecf1043e..affde5c2f 100644 --- a/src/ptr_set.cpp +++ b/src/ptr_set.cpp @@ -6,11 +6,11 @@ struct PtrSetEntry { template struct PtrSet { - Slice hashes; + Slice hashes; Array> entries; }; -template gb_internal void ptr_set_init (PtrSet *s, gbAllocator a, isize capacity = 16); +template gb_internal void ptr_set_init (PtrSet *s, isize capacity = 16); template gb_internal void ptr_set_destroy(PtrSet *s); template gb_internal T ptr_set_add (PtrSet *s, T ptr); template gb_internal bool ptr_set_update (PtrSet *s, T ptr); // returns true if it previously existed @@ -21,15 +21,18 @@ template gb_internal void ptr_set_grow (PtrSet *s); template gb_internal void ptr_set_rehash (PtrSet *s, isize new_count); template gb_internal void ptr_set_reserve(PtrSet *h, isize cap); +gb_internal gbAllocator ptr_set_allocator(void) { + return heap_allocator(); +} template -gb_internal void ptr_set_init(PtrSet *s, gbAllocator a, isize capacity) { +gb_internal void ptr_set_init(PtrSet *s, isize capacity) { if (capacity != 0) { capacity = next_pow2_isize(gb_max(16, capacity)); } - slice_init(&s->hashes, a, capacity); - array_init(&s->entries, a, 0, capacity); + slice_init(&s->hashes, ptr_set_allocator(), capacity); + array_init(&s->entries, ptr_set_allocator(), 0, capacity); for (isize i = 0; i < capacity; i++) { s->hashes.data[i] = MAP_SENTINEL; } @@ -37,6 +40,9 @@ gb_internal void ptr_set_init(PtrSet *s, gbAllocator a, isize capacity) { template gb_internal void ptr_set_destroy(PtrSet *s) { + if (s->entries.allocator.proc == nullptr) { + s->entries.allocator = ptr_set_allocator(); + } slice_free(&s->hashes, s->entries.allocator); array_free(&s->entries); } @@ -118,6 +124,9 @@ gb_internal void ptr_set_reset_entries(PtrSet *s) { template gb_internal void ptr_set_reserve(PtrSet *s, isize cap) { + if (s->entries.allocator.proc == nullptr) { + s->entries.allocator = ptr_set_allocator(); + } array_reserve(&s->entries, cap); if (s->entries.count*2 < s->hashes.count) { return; @@ -139,7 +148,7 @@ gb_internal gb_inline bool ptr_set_exists(PtrSet *s, T ptr) { } template -gb_internal gb_inline isize ptr_entry_index(PtrSet *s, T ptr) { +gb_internal gb_inline isize ptr_set_entry_index(PtrSet *s, T ptr) { isize index = ptr_set__find(s, ptr).entry_index; if (index != MAP_SENTINEL) { return index; diff --git a/src/string_set.cpp b/src/string_set.cpp index 1c97d253e..753afa9bf 100644 --- a/src/string_set.cpp +++ b/src/string_set.cpp @@ -10,7 +10,7 @@ struct StringSet { }; -gb_internal void string_set_init (StringSet *s, gbAllocator a, isize capacity = 16); +gb_internal void string_set_init (StringSet *s, isize capacity = 16); gb_internal void string_set_destroy(StringSet *s); gb_internal void string_set_add (StringSet *s, String const &str); gb_internal bool string_set_update (StringSet *s, String const &str); // returns true if it previously existed @@ -20,18 +20,24 @@ gb_internal void string_set_clear (StringSet *s); gb_internal void string_set_grow (StringSet *s); gb_internal void string_set_rehash (StringSet *s, isize new_count); +gb_internal gbAllocator string_set_allocator(void) { + return heap_allocator(); +} -gb_internal gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) { +gb_internal gb_inline void string_set_init(StringSet *s, isize capacity) { capacity = next_pow2_isize(gb_max(16, capacity)); - slice_init(&s->hashes, a, capacity); - array_init(&s->entries, a, 0, capacity); + slice_init(&s->hashes, string_set_allocator(), capacity); + array_init(&s->entries, string_set_allocator(), 0, capacity); for (isize i = 0; i < capacity; i++) { s->hashes.data[i] = MAP_SENTINEL; } } gb_internal gb_inline void string_set_destroy(StringSet *s) { + if (s->entries.allocator.proc == nullptr) { + s->entries.allocator = string_set_allocator(); + } slice_free(&s->hashes, s->entries.allocator); array_free(&s->entries); } @@ -106,6 +112,9 @@ gb_internal void string_set_reset_entries(StringSet *s) { } gb_internal void string_set_reserve(StringSet *s, isize cap) { + if (s->entries.allocator.proc == nullptr) { + s->entries.allocator = string_set_allocator(); + } array_reserve(&s->entries, cap); if (s->entries.count*2 < s->hashes.count) { return; @@ -217,7 +226,6 @@ gb_internal gb_inline void string_set_clear(StringSet *s) { } - gb_internal StringSetEntry *begin(StringSet &m) { return m.entries.data; } -- cgit v1.2.3 From 0fb3032b731b640a2d0d1d62b9f8dd548e224b0e Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 3 Jan 2023 14:45:09 +0000 Subject: General improves to `alloc_ast_node` and other unnecessary checks --- src/common.cpp | 2 +- src/main.cpp | 4 ++-- src/parser.cpp | 4 +--- src/parser.hpp | 5 ++--- src/ptr_map.cpp | 6 ++++-- src/thread_pool.cpp | 6 +++--- src/threading.cpp | 1 + src/types.cpp | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/common.cpp b/src/common.cpp index 199a263a1..988a992d0 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -43,9 +43,9 @@ gb_internal void debugf(char const *fmt, ...); #error Odin on Windows requires a 64-bit build-system. The 'Developer Command Prompt' for VS still defaults to 32-bit shell. The 64-bit shell can be found under the name 'x64 Native Tools Command Prompt' for VS. For more information, please see https://odin-lang.org/docs/install/#for-windows #endif -#include "threading.cpp" #include "unicode.cpp" #include "array.cpp" +#include "threading.cpp" #include "queue.cpp" #include "common_memory.cpp" #include "string.cpp" diff --git a/src/main.cpp b/src/main.cpp index 7ac78241e..c07d2c400 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,11 +13,11 @@ #endif #include "exact_value.cpp" #include "build_settings.cpp" - gb_global ThreadPool global_thread_pool; gb_internal void init_global_thread_pool(void) { isize thread_count = gb_max(build_context.thread_count, 1); - thread_pool_init(&global_thread_pool, permanent_allocator(), thread_count, "ThreadPoolWorker"); + isize worker_count = thread_count-1; + thread_pool_init(&global_thread_pool, permanent_allocator(), worker_count, "ThreadPoolWorker"); } gb_internal bool thread_pool_add_task(WorkerTaskProc *proc, void *data) { return thread_pool_add_task(&global_thread_pool, proc, data); diff --git a/src/parser.cpp b/src/parser.cpp index 046469c16..c6f35d326 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -64,11 +64,9 @@ gb_global std::atomic global_total_node_memory_allocated; // NOTE(bill): And this below is why is I/we need a new language! Discriminated unions are a pain in C/C++ gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) { - gbAllocator a = ast_allocator(f); - isize size = ast_node_size(kind); - Ast *node = cast(Ast *)gb_alloc(a, size); + Ast *node = cast(Ast *)arena_alloc(&global_thread_local_ast_arena, size, 16); node->kind = kind; node->file_id = f ? f->id : 0; diff --git a/src/parser.hpp b/src/parser.hpp index b492cfa85..d81194831 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -821,9 +821,8 @@ gb_internal gb_inline bool is_ast_when_stmt(Ast *node) { gb_global gb_thread_local Arena global_thread_local_ast_arena = {}; -gb_internal gbAllocator ast_allocator(AstFile *f) { - Arena *arena = &global_thread_local_ast_arena; - return arena_allocator(arena); +gb_internal gb_inline gbAllocator ast_allocator(AstFile *f) { + return arena_allocator(&global_thread_local_ast_arena); } gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind); diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp index 083cd6697..264136881 100644 --- a/src/ptr_map.cpp +++ b/src/ptr_map.cpp @@ -27,6 +27,7 @@ struct PtrMap { gb_internal gb_inline u32 ptr_map_hash_key(uintptr key) { + u32 res; #if defined(GB_ARCH_64_BIT) key = (~key) + (key << 21); key = key ^ (key >> 24); @@ -34,12 +35,13 @@ gb_internal gb_inline u32 ptr_map_hash_key(uintptr key) { key = key ^ (key >> 14); key = (key + (key << 2)) + (key << 4); key = key ^ (key << 28); - return cast(u32)key; + res = cast(u32)key; #elif defined(GB_ARCH_32_BIT) u32 state = ((u32)key) * 747796405u + 2891336453u; u32 word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u; - return (word >> 22u) ^ word; + res = (word >> 22u) ^ word; #endif + return res ^ (res == MAP_SENTINEL); } gb_internal gb_inline u32 ptr_map_hash_key(void const *key) { return ptr_map_hash_key((uintptr)key); diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 07ab3d323..276e93dff 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -5,7 +5,7 @@ struct ThreadPool; gb_thread_local Thread *current_thread; -gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name); +gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize worker_count, char const *worker_name); gb_internal void thread_pool_destroy(ThreadPool *pool); gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data); gb_internal void thread_pool_wait(ThreadPool *pool); @@ -25,9 +25,9 @@ gb_internal isize current_thread_index(void) { return current_thread ? current_thread->idx : 0; } -gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name) { +gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize worker_count, char const *worker_name) { pool->allocator = a; - slice_init(&pool->threads, a, thread_count + 1); + slice_init(&pool->threads, a, worker_count + 1); // NOTE: this needs to be initialized before any thread starts pool->running.store(true, std::memory_order_seq_cst); diff --git a/src/threading.cpp b/src/threading.cpp index aca77cd8f..78943150e 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -398,6 +398,7 @@ gb_internal void thread_init(ThreadPool *pool, Thread *t, isize idx) { t->idx = idx; } + gb_internal void thread_init_and_start(ThreadPool *pool, Thread *t, isize idx) { thread_init(pool, t, idx); isize stack_size = 0; diff --git a/src/types.cpp b/src/types.cpp index d33c36e94..fa7c1d7f7 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -2535,13 +2535,13 @@ gb_internal bool are_types_identical_internal(Type *x, Type *y, bool check_tuple if (x->kind == Type_Named) { Entity *e = x->Named.type_name; - if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) { + if (e->TypeName.is_type_alias) { x = x->Named.base; } } if (y->kind == Type_Named) { Entity *e = y->Named.type_name; - if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) { + if (e->TypeName.is_type_alias) { y = y->Named.base; } } -- cgit v1.2.3 From 85e390deba48437eb8268e2a1067e2c377613352 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 3 Jan 2023 15:55:22 +0000 Subject: Minimize calling of `Ast::thread_safe_file()` when cloning --- src/parser.cpp | 284 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 143 insertions(+), 141 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index c6f35d326..bc0fcf6be 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -75,33 +75,35 @@ gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) { return node; } -gb_internal Ast *clone_ast(Ast *node); -gb_internal Array clone_ast_array(Array const &array) { +gb_internal Ast *clone_ast(Ast *node, AstFile *f = nullptr); +gb_internal Array clone_ast_array(Array const &array, AstFile *f) { Array result = {}; if (array.count > 0) { result = array_make(ast_allocator(nullptr), array.count); for_array(i, array) { - result[i] = clone_ast(array[i]); + result[i] = clone_ast(array[i], f); } } return result; } -gb_internal Slice clone_ast_array(Slice const &array) { +gb_internal Slice clone_ast_array(Slice const &array, AstFile *f) { Slice result = {}; if (array.count > 0) { result = slice_clone(permanent_allocator(), array); for_array(i, array) { - result[i] = clone_ast(array[i]); + result[i] = clone_ast(array[i], f); } } return result; } -gb_internal Ast *clone_ast(Ast *node) { +gb_internal Ast *clone_ast(Ast *node, AstFile *f) { if (node == nullptr) { return nullptr; } - AstFile *f = node->thread_safe_file(); + if (f == nullptr) { + f = node->thread_safe_file(); + } Ast *n = alloc_ast_node(f, node->kind); gb_memmove(n, node, ast_node_size(node->kind)); @@ -118,279 +120,279 @@ gb_internal Ast *clone_ast(Ast *node) { case Ast_BasicDirective: break; case Ast_PolyType: - n->PolyType.type = clone_ast(n->PolyType.type); - n->PolyType.specialization = clone_ast(n->PolyType.specialization); + n->PolyType.type = clone_ast(n->PolyType.type, f); + n->PolyType.specialization = clone_ast(n->PolyType.specialization, f); break; case Ast_Ellipsis: - n->Ellipsis.expr = clone_ast(n->Ellipsis.expr); + n->Ellipsis.expr = clone_ast(n->Ellipsis.expr, f); break; case Ast_ProcGroup: - n->ProcGroup.args = clone_ast_array(n->ProcGroup.args); + n->ProcGroup.args = clone_ast_array(n->ProcGroup.args, f); break; case Ast_ProcLit: - n->ProcLit.type = clone_ast(n->ProcLit.type); - n->ProcLit.body = clone_ast(n->ProcLit.body); - n->ProcLit.where_clauses = clone_ast_array(n->ProcLit.where_clauses); + n->ProcLit.type = clone_ast(n->ProcLit.type, f); + n->ProcLit.body = clone_ast(n->ProcLit.body, f); + n->ProcLit.where_clauses = clone_ast_array(n->ProcLit.where_clauses, f); break; case Ast_CompoundLit: - n->CompoundLit.type = clone_ast(n->CompoundLit.type); - n->CompoundLit.elems = clone_ast_array(n->CompoundLit.elems); + n->CompoundLit.type = clone_ast(n->CompoundLit.type, f); + n->CompoundLit.elems = clone_ast_array(n->CompoundLit.elems, f); break; case Ast_BadExpr: break; case Ast_TagExpr: - n->TagExpr.expr = clone_ast(n->TagExpr.expr); + n->TagExpr.expr = clone_ast(n->TagExpr.expr, f); break; case Ast_UnaryExpr: - n->UnaryExpr.expr = clone_ast(n->UnaryExpr.expr); + n->UnaryExpr.expr = clone_ast(n->UnaryExpr.expr, f); break; case Ast_BinaryExpr: - n->BinaryExpr.left = clone_ast(n->BinaryExpr.left); - n->BinaryExpr.right = clone_ast(n->BinaryExpr.right); + n->BinaryExpr.left = clone_ast(n->BinaryExpr.left, f); + n->BinaryExpr.right = clone_ast(n->BinaryExpr.right, f); break; case Ast_ParenExpr: - n->ParenExpr.expr = clone_ast(n->ParenExpr.expr); + n->ParenExpr.expr = clone_ast(n->ParenExpr.expr, f); break; case Ast_SelectorExpr: - n->SelectorExpr.expr = clone_ast(n->SelectorExpr.expr); - n->SelectorExpr.selector = clone_ast(n->SelectorExpr.selector); + n->SelectorExpr.expr = clone_ast(n->SelectorExpr.expr, f); + n->SelectorExpr.selector = clone_ast(n->SelectorExpr.selector, f); break; case Ast_ImplicitSelectorExpr: - n->ImplicitSelectorExpr.selector = clone_ast(n->ImplicitSelectorExpr.selector); + n->ImplicitSelectorExpr.selector = clone_ast(n->ImplicitSelectorExpr.selector, f); break; case Ast_SelectorCallExpr: - n->SelectorCallExpr.expr = clone_ast(n->SelectorCallExpr.expr); - n->SelectorCallExpr.call = clone_ast(n->SelectorCallExpr.call); + n->SelectorCallExpr.expr = clone_ast(n->SelectorCallExpr.expr, f); + n->SelectorCallExpr.call = clone_ast(n->SelectorCallExpr.call, f); break; case Ast_IndexExpr: - n->IndexExpr.expr = clone_ast(n->IndexExpr.expr); - n->IndexExpr.index = clone_ast(n->IndexExpr.index); + n->IndexExpr.expr = clone_ast(n->IndexExpr.expr, f); + n->IndexExpr.index = clone_ast(n->IndexExpr.index, f); break; case Ast_MatrixIndexExpr: - n->MatrixIndexExpr.expr = clone_ast(n->MatrixIndexExpr.expr); - n->MatrixIndexExpr.row_index = clone_ast(n->MatrixIndexExpr.row_index); - n->MatrixIndexExpr.column_index = clone_ast(n->MatrixIndexExpr.column_index); + n->MatrixIndexExpr.expr = clone_ast(n->MatrixIndexExpr.expr, f); + n->MatrixIndexExpr.row_index = clone_ast(n->MatrixIndexExpr.row_index, f); + n->MatrixIndexExpr.column_index = clone_ast(n->MatrixIndexExpr.column_index, f); break; case Ast_DerefExpr: - n->DerefExpr.expr = clone_ast(n->DerefExpr.expr); + n->DerefExpr.expr = clone_ast(n->DerefExpr.expr, f); break; case Ast_SliceExpr: - n->SliceExpr.expr = clone_ast(n->SliceExpr.expr); - n->SliceExpr.low = clone_ast(n->SliceExpr.low); - n->SliceExpr.high = clone_ast(n->SliceExpr.high); + n->SliceExpr.expr = clone_ast(n->SliceExpr.expr, f); + n->SliceExpr.low = clone_ast(n->SliceExpr.low, f); + n->SliceExpr.high = clone_ast(n->SliceExpr.high, f); break; case Ast_CallExpr: - n->CallExpr.proc = clone_ast(n->CallExpr.proc); - n->CallExpr.args = clone_ast_array(n->CallExpr.args); + n->CallExpr.proc = clone_ast(n->CallExpr.proc, f); + n->CallExpr.args = clone_ast_array(n->CallExpr.args, f); break; case Ast_FieldValue: - n->FieldValue.field = clone_ast(n->FieldValue.field); - n->FieldValue.value = clone_ast(n->FieldValue.value); + n->FieldValue.field = clone_ast(n->FieldValue.field, f); + n->FieldValue.value = clone_ast(n->FieldValue.value, f); break; case Ast_EnumFieldValue: - n->EnumFieldValue.name = clone_ast(n->EnumFieldValue.name); - n->EnumFieldValue.value = clone_ast(n->EnumFieldValue.value); + n->EnumFieldValue.name = clone_ast(n->EnumFieldValue.name, f); + n->EnumFieldValue.value = clone_ast(n->EnumFieldValue.value, f); break; case Ast_TernaryIfExpr: - n->TernaryIfExpr.x = clone_ast(n->TernaryIfExpr.x); - n->TernaryIfExpr.cond = clone_ast(n->TernaryIfExpr.cond); - n->TernaryIfExpr.y = clone_ast(n->TernaryIfExpr.y); + n->TernaryIfExpr.x = clone_ast(n->TernaryIfExpr.x, f); + n->TernaryIfExpr.cond = clone_ast(n->TernaryIfExpr.cond, f); + n->TernaryIfExpr.y = clone_ast(n->TernaryIfExpr.y, f); break; case Ast_TernaryWhenExpr: - n->TernaryWhenExpr.x = clone_ast(n->TernaryWhenExpr.x); - n->TernaryWhenExpr.cond = clone_ast(n->TernaryWhenExpr.cond); - n->TernaryWhenExpr.y = clone_ast(n->TernaryWhenExpr.y); + n->TernaryWhenExpr.x = clone_ast(n->TernaryWhenExpr.x, f); + n->TernaryWhenExpr.cond = clone_ast(n->TernaryWhenExpr.cond, f); + n->TernaryWhenExpr.y = clone_ast(n->TernaryWhenExpr.y, f); break; case Ast_OrElseExpr: - n->OrElseExpr.x = clone_ast(n->OrElseExpr.x); - n->OrElseExpr.y = clone_ast(n->OrElseExpr.y); + n->OrElseExpr.x = clone_ast(n->OrElseExpr.x, f); + n->OrElseExpr.y = clone_ast(n->OrElseExpr.y, f); break; case Ast_OrReturnExpr: - n->OrReturnExpr.expr = clone_ast(n->OrReturnExpr.expr); + n->OrReturnExpr.expr = clone_ast(n->OrReturnExpr.expr, f); break; case Ast_TypeAssertion: - n->TypeAssertion.expr = clone_ast(n->TypeAssertion.expr); - n->TypeAssertion.type = clone_ast(n->TypeAssertion.type); + n->TypeAssertion.expr = clone_ast(n->TypeAssertion.expr, f); + n->TypeAssertion.type = clone_ast(n->TypeAssertion.type, f); break; case Ast_TypeCast: - n->TypeCast.type = clone_ast(n->TypeCast.type); - n->TypeCast.expr = clone_ast(n->TypeCast.expr); + n->TypeCast.type = clone_ast(n->TypeCast.type, f); + n->TypeCast.expr = clone_ast(n->TypeCast.expr, f); break; case Ast_AutoCast: - n->AutoCast.expr = clone_ast(n->AutoCast.expr); + n->AutoCast.expr = clone_ast(n->AutoCast.expr, f); break; case Ast_InlineAsmExpr: - n->InlineAsmExpr.param_types = clone_ast_array(n->InlineAsmExpr.param_types); - n->InlineAsmExpr.return_type = clone_ast(n->InlineAsmExpr.return_type); - n->InlineAsmExpr.asm_string = clone_ast(n->InlineAsmExpr.asm_string); - n->InlineAsmExpr.constraints_string = clone_ast(n->InlineAsmExpr.constraints_string); + n->InlineAsmExpr.param_types = clone_ast_array(n->InlineAsmExpr.param_types, f); + n->InlineAsmExpr.return_type = clone_ast(n->InlineAsmExpr.return_type, f); + n->InlineAsmExpr.asm_string = clone_ast(n->InlineAsmExpr.asm_string, f); + n->InlineAsmExpr.constraints_string = clone_ast(n->InlineAsmExpr.constraints_string, f); break; case Ast_BadStmt: break; case Ast_EmptyStmt: break; case Ast_ExprStmt: - n->ExprStmt.expr = clone_ast(n->ExprStmt.expr); + n->ExprStmt.expr = clone_ast(n->ExprStmt.expr, f); break; case Ast_AssignStmt: - n->AssignStmt.lhs = clone_ast_array(n->AssignStmt.lhs); - n->AssignStmt.rhs = clone_ast_array(n->AssignStmt.rhs); + n->AssignStmt.lhs = clone_ast_array(n->AssignStmt.lhs, f); + n->AssignStmt.rhs = clone_ast_array(n->AssignStmt.rhs, f); break; case Ast_BlockStmt: - n->BlockStmt.label = clone_ast(n->BlockStmt.label); - n->BlockStmt.stmts = clone_ast_array(n->BlockStmt.stmts); + n->BlockStmt.label = clone_ast(n->BlockStmt.label, f); + n->BlockStmt.stmts = clone_ast_array(n->BlockStmt.stmts, f); break; case Ast_IfStmt: - n->IfStmt.label = clone_ast(n->IfStmt.label); - n->IfStmt.init = clone_ast(n->IfStmt.init); - n->IfStmt.cond = clone_ast(n->IfStmt.cond); - n->IfStmt.body = clone_ast(n->IfStmt.body); - n->IfStmt.else_stmt = clone_ast(n->IfStmt.else_stmt); + n->IfStmt.label = clone_ast(n->IfStmt.label, f); + n->IfStmt.init = clone_ast(n->IfStmt.init, f); + n->IfStmt.cond = clone_ast(n->IfStmt.cond, f); + n->IfStmt.body = clone_ast(n->IfStmt.body, f); + n->IfStmt.else_stmt = clone_ast(n->IfStmt.else_stmt, f); break; case Ast_WhenStmt: - n->WhenStmt.cond = clone_ast(n->WhenStmt.cond); - n->WhenStmt.body = clone_ast(n->WhenStmt.body); - n->WhenStmt.else_stmt = clone_ast(n->WhenStmt.else_stmt); + n->WhenStmt.cond = clone_ast(n->WhenStmt.cond, f); + n->WhenStmt.body = clone_ast(n->WhenStmt.body, f); + n->WhenStmt.else_stmt = clone_ast(n->WhenStmt.else_stmt, f); break; case Ast_ReturnStmt: - n->ReturnStmt.results = clone_ast_array(n->ReturnStmt.results); + n->ReturnStmt.results = clone_ast_array(n->ReturnStmt.results, f); break; case Ast_ForStmt: - n->ForStmt.label = clone_ast(n->ForStmt.label); - n->ForStmt.init = clone_ast(n->ForStmt.init); - n->ForStmt.cond = clone_ast(n->ForStmt.cond); - n->ForStmt.post = clone_ast(n->ForStmt.post); - n->ForStmt.body = clone_ast(n->ForStmt.body); + n->ForStmt.label = clone_ast(n->ForStmt.label, f); + n->ForStmt.init = clone_ast(n->ForStmt.init, f); + n->ForStmt.cond = clone_ast(n->ForStmt.cond, f); + n->ForStmt.post = clone_ast(n->ForStmt.post, f); + n->ForStmt.body = clone_ast(n->ForStmt.body, f); break; case Ast_RangeStmt: - n->RangeStmt.label = clone_ast(n->RangeStmt.label); - n->RangeStmt.vals = clone_ast_array(n->RangeStmt.vals); - n->RangeStmt.expr = clone_ast(n->RangeStmt.expr); - n->RangeStmt.body = clone_ast(n->RangeStmt.body); + n->RangeStmt.label = clone_ast(n->RangeStmt.label, f); + n->RangeStmt.vals = clone_ast_array(n->RangeStmt.vals, f); + n->RangeStmt.expr = clone_ast(n->RangeStmt.expr, f); + n->RangeStmt.body = clone_ast(n->RangeStmt.body, f); break; case Ast_UnrollRangeStmt: - n->UnrollRangeStmt.val0 = clone_ast(n->UnrollRangeStmt.val0); - n->UnrollRangeStmt.val1 = clone_ast(n->UnrollRangeStmt.val1); - n->UnrollRangeStmt.expr = clone_ast(n->UnrollRangeStmt.expr); - n->UnrollRangeStmt.body = clone_ast(n->UnrollRangeStmt.body); + n->UnrollRangeStmt.val0 = clone_ast(n->UnrollRangeStmt.val0, f); + n->UnrollRangeStmt.val1 = clone_ast(n->UnrollRangeStmt.val1, f); + n->UnrollRangeStmt.expr = clone_ast(n->UnrollRangeStmt.expr, f); + n->UnrollRangeStmt.body = clone_ast(n->UnrollRangeStmt.body, f); break; case Ast_CaseClause: - n->CaseClause.list = clone_ast_array(n->CaseClause.list); - n->CaseClause.stmts = clone_ast_array(n->CaseClause.stmts); + n->CaseClause.list = clone_ast_array(n->CaseClause.list, f); + n->CaseClause.stmts = clone_ast_array(n->CaseClause.stmts, f); n->CaseClause.implicit_entity = nullptr; break; case Ast_SwitchStmt: - n->SwitchStmt.label = clone_ast(n->SwitchStmt.label); - n->SwitchStmt.init = clone_ast(n->SwitchStmt.init); - n->SwitchStmt.tag = clone_ast(n->SwitchStmt.tag); - n->SwitchStmt.body = clone_ast(n->SwitchStmt.body); + n->SwitchStmt.label = clone_ast(n->SwitchStmt.label, f); + n->SwitchStmt.init = clone_ast(n->SwitchStmt.init, f); + n->SwitchStmt.tag = clone_ast(n->SwitchStmt.tag, f); + n->SwitchStmt.body = clone_ast(n->SwitchStmt.body, f); break; case Ast_TypeSwitchStmt: - n->TypeSwitchStmt.label = clone_ast(n->TypeSwitchStmt.label); - n->TypeSwitchStmt.tag = clone_ast(n->TypeSwitchStmt.tag); - n->TypeSwitchStmt.body = clone_ast(n->TypeSwitchStmt.body); + n->TypeSwitchStmt.label = clone_ast(n->TypeSwitchStmt.label, f); + n->TypeSwitchStmt.tag = clone_ast(n->TypeSwitchStmt.tag, f); + n->TypeSwitchStmt.body = clone_ast(n->TypeSwitchStmt.body, f); break; case Ast_DeferStmt: - n->DeferStmt.stmt = clone_ast(n->DeferStmt.stmt); + n->DeferStmt.stmt = clone_ast(n->DeferStmt.stmt, f); break; case Ast_BranchStmt: - n->BranchStmt.label = clone_ast(n->BranchStmt.label); + n->BranchStmt.label = clone_ast(n->BranchStmt.label, f); break; case Ast_UsingStmt: - n->UsingStmt.list = clone_ast_array(n->UsingStmt.list); + n->UsingStmt.list = clone_ast_array(n->UsingStmt.list, f); break; case Ast_BadDecl: break; case Ast_ForeignBlockDecl: - n->ForeignBlockDecl.foreign_library = clone_ast(n->ForeignBlockDecl.foreign_library); - n->ForeignBlockDecl.body = clone_ast(n->ForeignBlockDecl.body); - n->ForeignBlockDecl.attributes = clone_ast_array(n->ForeignBlockDecl.attributes); + n->ForeignBlockDecl.foreign_library = clone_ast(n->ForeignBlockDecl.foreign_library, f); + n->ForeignBlockDecl.body = clone_ast(n->ForeignBlockDecl.body, f); + n->ForeignBlockDecl.attributes = clone_ast_array(n->ForeignBlockDecl.attributes, f); break; case Ast_Label: - n->Label.name = clone_ast(n->Label.name); + n->Label.name = clone_ast(n->Label.name, f); break; case Ast_ValueDecl: - n->ValueDecl.names = clone_ast_array(n->ValueDecl.names); - n->ValueDecl.type = clone_ast(n->ValueDecl.type); - n->ValueDecl.values = clone_ast_array(n->ValueDecl.values); - n->ValueDecl.attributes = clone_ast_array(n->ValueDecl.attributes); + n->ValueDecl.names = clone_ast_array(n->ValueDecl.names, f); + n->ValueDecl.type = clone_ast(n->ValueDecl.type, f); + n->ValueDecl.values = clone_ast_array(n->ValueDecl.values, f); + n->ValueDecl.attributes = clone_ast_array(n->ValueDecl.attributes, f); break; case Ast_Attribute: - n->Attribute.elems = clone_ast_array(n->Attribute.elems); + n->Attribute.elems = clone_ast_array(n->Attribute.elems, f); break; case Ast_Field: - n->Field.names = clone_ast_array(n->Field.names); - n->Field.type = clone_ast(n->Field.type); + n->Field.names = clone_ast_array(n->Field.names, f); + n->Field.type = clone_ast(n->Field.type, f); break; case Ast_FieldList: - n->FieldList.list = clone_ast_array(n->FieldList.list); + n->FieldList.list = clone_ast_array(n->FieldList.list, f); break; case Ast_TypeidType: - n->TypeidType.specialization = clone_ast(n->TypeidType.specialization); + n->TypeidType.specialization = clone_ast(n->TypeidType.specialization, f); break; case Ast_HelperType: - n->HelperType.type = clone_ast(n->HelperType.type); + n->HelperType.type = clone_ast(n->HelperType.type, f); break; case Ast_DistinctType: - n->DistinctType.type = clone_ast(n->DistinctType.type); + n->DistinctType.type = clone_ast(n->DistinctType.type, f); break; case Ast_ProcType: - n->ProcType.params = clone_ast(n->ProcType.params); - n->ProcType.results = clone_ast(n->ProcType.results); + n->ProcType.params = clone_ast(n->ProcType.params, f); + n->ProcType.results = clone_ast(n->ProcType.results, f); break; case Ast_RelativeType: - n->RelativeType.tag = clone_ast(n->RelativeType.tag); - n->RelativeType.type = clone_ast(n->RelativeType.type); + n->RelativeType.tag = clone_ast(n->RelativeType.tag, f); + n->RelativeType.type = clone_ast(n->RelativeType.type, f); break; case Ast_PointerType: - n->PointerType.type = clone_ast(n->PointerType.type); - n->PointerType.tag = clone_ast(n->PointerType.tag); + n->PointerType.type = clone_ast(n->PointerType.type, f); + n->PointerType.tag = clone_ast(n->PointerType.tag, f); break; case Ast_MultiPointerType: - n->MultiPointerType.type = clone_ast(n->MultiPointerType.type); + n->MultiPointerType.type = clone_ast(n->MultiPointerType.type, f); break; case Ast_ArrayType: - n->ArrayType.count = clone_ast(n->ArrayType.count); - n->ArrayType.elem = clone_ast(n->ArrayType.elem); - n->ArrayType.tag = clone_ast(n->ArrayType.tag); + n->ArrayType.count = clone_ast(n->ArrayType.count, f); + n->ArrayType.elem = clone_ast(n->ArrayType.elem, f); + n->ArrayType.tag = clone_ast(n->ArrayType.tag, f); break; case Ast_DynamicArrayType: - n->DynamicArrayType.elem = clone_ast(n->DynamicArrayType.elem); + n->DynamicArrayType.elem = clone_ast(n->DynamicArrayType.elem, f); break; case Ast_StructType: - n->StructType.fields = clone_ast_array(n->StructType.fields); - n->StructType.polymorphic_params = clone_ast(n->StructType.polymorphic_params); - n->StructType.align = clone_ast(n->StructType.align); - n->StructType.where_clauses = clone_ast_array(n->StructType.where_clauses); + n->StructType.fields = clone_ast_array(n->StructType.fields, f); + n->StructType.polymorphic_params = clone_ast(n->StructType.polymorphic_params, f); + n->StructType.align = clone_ast(n->StructType.align, f); + n->StructType.where_clauses = clone_ast_array(n->StructType.where_clauses, f); break; case Ast_UnionType: - n->UnionType.variants = clone_ast_array(n->UnionType.variants); - n->UnionType.polymorphic_params = clone_ast(n->UnionType.polymorphic_params); - n->UnionType.where_clauses = clone_ast_array(n->UnionType.where_clauses); + n->UnionType.variants = clone_ast_array(n->UnionType.variants, f); + n->UnionType.polymorphic_params = clone_ast(n->UnionType.polymorphic_params, f); + n->UnionType.where_clauses = clone_ast_array(n->UnionType.where_clauses, f); break; case Ast_EnumType: - n->EnumType.base_type = clone_ast(n->EnumType.base_type); - n->EnumType.fields = clone_ast_array(n->EnumType.fields); + n->EnumType.base_type = clone_ast(n->EnumType.base_type, f); + n->EnumType.fields = clone_ast_array(n->EnumType.fields, f); break; case Ast_BitSetType: - n->BitSetType.elem = clone_ast(n->BitSetType.elem); - n->BitSetType.underlying = clone_ast(n->BitSetType.underlying); + n->BitSetType.elem = clone_ast(n->BitSetType.elem, f); + n->BitSetType.underlying = clone_ast(n->BitSetType.underlying, f); break; case Ast_MapType: - n->MapType.count = clone_ast(n->MapType.count); - n->MapType.key = clone_ast(n->MapType.key); - n->MapType.value = clone_ast(n->MapType.value); + n->MapType.count = clone_ast(n->MapType.count, f); + n->MapType.key = clone_ast(n->MapType.key, f); + n->MapType.value = clone_ast(n->MapType.value, f); break; case Ast_MatrixType: - n->MatrixType.row_count = clone_ast(n->MatrixType.row_count); - n->MatrixType.column_count = clone_ast(n->MatrixType.column_count); - n->MatrixType.elem = clone_ast(n->MatrixType.elem); + n->MatrixType.row_count = clone_ast(n->MatrixType.row_count, f); + n->MatrixType.column_count = clone_ast(n->MatrixType.column_count, f); + n->MatrixType.elem = clone_ast(n->MatrixType.elem, f); break; } -- cgit v1.2.3 From 2720e9812778c8cf28ead9c41c46b0d578f6a7b3 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 3 Jan 2023 17:25:51 +0000 Subject: Add `+ignore` along with `+build ignore` --- src/parser.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index bc0fcf6be..0eb7e5fc1 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5584,6 +5584,8 @@ gb_internal bool parse_file(Parser *p, AstFile *f) { if (!parse_build_tag(tok, lc)) { return false; } + } else if (string_starts_with(lc, str_lit("+ignore"))) { + return false; } else if (string_starts_with(lc, str_lit("+private"))) { f->flags |= AstFile_IsPrivatePkg; String command = string_trim_starts_with(lc, str_lit("+private ")); -- cgit v1.2.3