diff --git a/src-self-hosted/stage1.zig b/src-self-hosted/stage1.zig index 5a0294fa7..619fd32dc 100644 --- a/src-self-hosted/stage1.zig +++ b/src-self-hosted/stage1.zig @@ -517,3 +517,11 @@ export fn stage2_progress_end(node: *std.Progress.Node) void { export fn stage2_progress_complete_one(node: *std.Progress.Node) void { node.completeOne(); } + +// ABI warning +export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usize, total_count: usize) void { + node.completed_items = done_count; + node.estimated_total_items = total_count; + node.activate(); + node.context.maybeRefresh(); +} diff --git a/src/all_types.hpp b/src/all_types.hpp index 267c5479b..7ea15dc76 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -2008,7 +2008,8 @@ struct CodeGen { ZigFn *largest_frame_fn; - Stage2ProgressNode *progress_node; + Stage2ProgressNode *main_progress_node; + Stage2ProgressNode *sub_progress_node; WantPIC want_pic; WantStackCheck want_stack_check; diff --git a/src/analyze.cpp b/src/analyze.cpp index ed4547957..44223b58b 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -120,6 +120,12 @@ static ScopeExpr *find_expr_scope(Scope *scope) { } } +static void update_progress_display(CodeGen *g) { + stage2_progress_update_node(g->sub_progress_node, + g->resolve_queue_index + g->fn_defs_index, + g->resolve_queue.length + g->fn_defs.length); +} + ScopeDecls *get_container_scope(ZigType *type_entry) { return *get_container_scope_ptr(type_entry); } @@ -3939,6 +3945,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool all return; tld->resolution = TldResolutionResolving; + update_progress_display(g); switch (tld->id) { case TldIdVar: { @@ -4592,6 +4599,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { return; fn_table_entry->anal_state = FnAnalStateProbing; + update_progress_display(g); AstNode *return_type_node = (fn_table_entry->proto_node != nullptr) ? fn_table_entry->proto_node->data.fn_proto.return_type : fn_table_entry->fndef_scope->base.source_node; diff --git a/src/codegen.cpp b/src/codegen.cpp index 82d2480eb..37715716e 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7303,8 +7303,12 @@ static void do_code_gen(CodeGen *g) { } // Generate function definitions. + stage2_progress_update_node(g->sub_progress_node, 0, g->fn_defs.length); for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) { ZigFn *fn_table_entry = g->fn_defs.at(fn_i); + Stage2ProgressNode *fn_prog_node = stage2_progress_start(g->sub_progress_node, + buf_ptr(&fn_table_entry->symbol_name), buf_len(&fn_table_entry->symbol_name), 0); + FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id; CallingConvention cc = fn_type_id->cc; bool is_c_abi = cc == CallingConventionC; @@ -7568,6 +7572,7 @@ static void do_code_gen(CodeGen *g) { ir_render(g, fn_table_entry); + stage2_progress_end(fn_prog_node); } assert(!g->errors.length); @@ -7615,7 +7620,7 @@ static void zig_llvm_emit_output(CodeGen *g) { if (g->bundle_compiler_rt && (g->out_type == OutTypeObj || (g->out_type == OutTypeLib && !g->is_dynamic))) { - zig_link_add_compiler_rt(g, g->progress_node); + zig_link_add_compiler_rt(g, g->sub_progress_node); } break; @@ -9458,7 +9463,7 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose } // returns true if it was a cache miss -static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file, Stage2ProgressNode *parent_prog_node) { +static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { Error err; Buf *artifact_dir; @@ -9470,7 +9475,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file, Stage2Pr Buf *c_source_basename = buf_alloc(); os_path_split(c_source_file, nullptr, c_source_basename); - Stage2ProgressNode *child_prog_node = stage2_progress_start(parent_prog_node, buf_ptr(c_source_basename), + Stage2ProgressNode *child_prog_node = stage2_progress_start(g->sub_progress_node, buf_ptr(c_source_basename), buf_len(c_source_basename), 0); Buf *final_o_basename = buf_alloc(); @@ -9606,17 +9611,15 @@ static void gen_c_objects(CodeGen *g) { exit(1); } - codegen_add_time_event(g, "Compile C Code"); - const char *c_prog_name = "compiling C objects"; - Stage2ProgressNode *c_prog_node = stage2_progress_start(g->progress_node, c_prog_name, strlen(c_prog_name), - g->c_source_files.length); + codegen_add_time_event(g, "Compile C Objects"); + const char *c_prog_name = "Compile C Objects"; + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, c_prog_name, strlen(c_prog_name), + g->c_source_files.length)); for (size_t c_file_i = 0; c_file_i < g->c_source_files.length; c_file_i += 1) { CFile *c_file = g->c_source_files.at(c_file_i); - gen_c_object(g, self_exe_path, c_file, c_prog_node); + gen_c_object(g, self_exe_path, c_file); } - - stage2_progress_end(c_prog_node); } void codegen_add_object(CodeGen *g, Buf *object_path) { @@ -10337,9 +10340,8 @@ void codegen_build_and_link(CodeGen *g) { codegen_add_time_event(g, "Semantic Analysis"); const char *progress_name = "Semantic Analysis"; - Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node, - progress_name, strlen(progress_name), 0); - (void)child_progress_node; + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, + progress_name, strlen(progress_name), 0)); gen_root_source(g); @@ -10365,18 +10367,16 @@ void codegen_build_and_link(CodeGen *g) { codegen_add_time_event(g, "Code Generation"); { const char *progress_name = "Code Generation"; - Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node, - progress_name, strlen(progress_name), 0); - (void)child_progress_node; + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, + progress_name, strlen(progress_name), 0)); } do_code_gen(g); codegen_add_time_event(g, "LLVM Emit Output"); { const char *progress_name = "LLVM Emit Output"; - Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node, - progress_name, strlen(progress_name), 0); - (void)child_progress_node; + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, + progress_name, strlen(progress_name), 0)); } zig_llvm_emit_output(g); @@ -10384,9 +10384,8 @@ void codegen_build_and_link(CodeGen *g) { codegen_add_time_event(g, "Generate .h"); { const char *progress_name = "Generate .h"; - Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node, - progress_name, strlen(progress_name), 0); - (void)child_progress_node; + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, + progress_name, strlen(progress_name), 0)); } gen_h_file(g); } @@ -10458,6 +10457,7 @@ void codegen_build_and_link(CodeGen *g) { codegen_release_caches(g); codegen_add_time_event(g, "Done"); + codegen_switch_sub_prog_node(g, nullptr); } void codegen_release_caches(CodeGen *g) { @@ -10487,7 +10487,7 @@ CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType o ZigLibCInstallation *libc, const char *name, Stage2ProgressNode *parent_progress_node) { Stage2ProgressNode *child_progress_node = stage2_progress_start( - parent_progress_node ? parent_progress_node : parent_gen->progress_node, + parent_progress_node ? parent_progress_node : parent_gen->sub_progress_node, name, strlen(name), 0); CodeGen *child_gen = codegen_create(nullptr, root_src_path, parent_gen->zig_target, out_type, @@ -10524,9 +10524,14 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget ZigLibCInstallation *libc, Buf *cache_dir, bool is_test_build, Stage2ProgressNode *progress_node) { CodeGen *g = allocate(1); - g->progress_node = progress_node; + g->main_progress_node = progress_node; codegen_add_time_event(g, "Initialize"); + { + const char *progress_name = "Initialize"; + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, + progress_name, strlen(progress_name), 0)); + } g->subsystem = TargetSubsystemAuto; g->libc = libc; @@ -10651,3 +10656,11 @@ bool codegen_fn_has_err_ret_tracing_stack(CodeGen *g, ZigFn *fn, bool is_async) !codegen_fn_has_err_ret_tracing_arg(g, fn->type_entry->data.fn.fn_type_id.return_type); } } + +void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) { + if (g->sub_progress_node != nullptr) { + stage2_progress_end(g->sub_progress_node); + } + g->sub_progress_node = node; +} + diff --git a/src/codegen.hpp b/src/codegen.hpp index 31771cd16..6dd914f9a 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -67,4 +67,6 @@ bool codegen_fn_has_err_ret_tracing_stack(CodeGen *g, ZigFn *fn, bool is_async); ATTRIBUTE_NORETURN void codegen_report_errors_and_exit(CodeGen *g); +void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node); + #endif diff --git a/src/link.cpp b/src/link.cpp index c6286722a..664e83e8b 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -2630,8 +2630,9 @@ void codegen_link(CodeGen *g) { { const char *progress_name = "Build Dependencies"; - lj.build_dep_prog_node = stage2_progress_start(g->progress_node, - progress_name, strlen(progress_name), 0); + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, + progress_name, strlen(progress_name), 0)); + lj.build_dep_prog_node = g->sub_progress_node; } @@ -2661,10 +2662,9 @@ void codegen_link(CodeGen *g) { ZigLLVM_OSType os_type = get_llvm_os_type(g->zig_target->os); codegen_add_time_event(g, "LLVM Link"); { - const char *progress_name = "linking"; - Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node, - progress_name, strlen(progress_name), 0); - (void)child_progress_node; + const char *progress_name = "Link"; + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, + progress_name, strlen(progress_name), 0)); } if (g->verbose_link) { fprintf(stderr, "ar rcs %s", buf_ptr(&g->output_file_path)); @@ -2696,6 +2696,11 @@ void codegen_link(CodeGen *g) { Buf diag = BUF_INIT; codegen_add_time_event(g, "LLVM Link"); + { + const char *progress_name = "Link"; + codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, + progress_name, strlen(progress_name), 0)); + } if (g->system_linker_hack && g->zig_target->os == OsMacOSX) { Termination term; ZigList args = {}; diff --git a/src/main.cpp b/src/main.cpp index 470903585..69f0abac6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1333,6 +1333,10 @@ int main(int argc, char **argv) { g->enable_cache = get_cache_opt(enable_cache, output_dir == nullptr); codegen_build_and_link(g); + if (root_progress_node != nullptr) { + stage2_progress_end(root_progress_node); + root_progress_node = nullptr; + } if (timing_info) { codegen_print_timing_report(g, stdout); diff --git a/src/userland.cpp b/src/userland.cpp index ec7f6b2de..a36dfa69a 100644 --- a/src/userland.cpp +++ b/src/userland.cpp @@ -88,3 +88,4 @@ Stage2ProgressNode *stage2_progress_start(Stage2ProgressNode *node, void stage2_progress_end(Stage2ProgressNode *node) {} void stage2_progress_complete_one(Stage2ProgressNode *node) {} void stage2_progress_disable_tty(Stage2Progress *progress) {} +void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items){} diff --git a/src/userland.h b/src/userland.h index eb419c166..58d5cc719 100644 --- a/src/userland.h +++ b/src/userland.h @@ -176,5 +176,8 @@ ZIG_EXTERN_C Stage2ProgressNode *stage2_progress_start(Stage2ProgressNode *node, ZIG_EXTERN_C void stage2_progress_end(Stage2ProgressNode *node); // ABI warning ZIG_EXTERN_C void stage2_progress_complete_one(Stage2ProgressNode *node); +// ABI warning +ZIG_EXTERN_C void stage2_progress_update_node(Stage2ProgressNode *node, + size_t completed_count, size_t estimated_total_items); #endif