authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-22 17:52:12-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-22 17:52:12-04:00
logf65b1d46804bce716f16465b60c6daa2921e4519
treef22e5fac294a4f5f638f2005948c05fb1846e5b8
parentdc080573d160a444e2e7c1fb88fac27c8060269f
signaturelock-open Commit is signed but in an unrecognized format.

integrate stage1 progress display with semantic analysis


9 files changed, 76 insertions(+), 31 deletions(-)

src-self-hosted/stage1.zig+8
......@@ -517,3 +517,11 @@ export fn stage2_progress_end(node: *std.Progress.Node) void {
517517export fn stage2_progress_complete_one(node: *std.Progress.Node) void {
518518 node.completeOne();
519519}
520
521// ABI warning
522export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usize, total_count: usize) void {
523 node.completed_items = done_count;
524 node.estimated_total_items = total_count;
525 node.activate();
526 node.context.maybeRefresh();
527}
src/all_types.hpp+2-1
......@@ -2008,7 +2008,8 @@ struct CodeGen {
20082008
20092009 ZigFn *largest_frame_fn;
20102010
2011 Stage2ProgressNode *progress_node;
2011 Stage2ProgressNode *main_progress_node;
2012 Stage2ProgressNode *sub_progress_node;
20122013
20132014 WantPIC want_pic;
20142015 WantStackCheck want_stack_check;
src/analyze.cpp+8
......@@ -120,6 +120,12 @@ static ScopeExpr *find_expr_scope(Scope *scope) {
120120 }
121121}
122122
123static void update_progress_display(CodeGen *g) {
124 stage2_progress_update_node(g->sub_progress_node,
125 g->resolve_queue_index + g->fn_defs_index,
126 g->resolve_queue.length + g->fn_defs.length);
127}
128
123129ScopeDecls *get_container_scope(ZigType *type_entry) {
124130 return *get_container_scope_ptr(type_entry);
125131}
......@@ -3939,6 +3945,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool all
39393945 return;
39403946
39413947 tld->resolution = TldResolutionResolving;
3948 update_progress_display(g);
39423949
39433950 switch (tld->id) {
39443951 case TldIdVar: {
......@@ -4592,6 +4599,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
45924599 return;
45934600
45944601 fn_table_entry->anal_state = FnAnalStateProbing;
4602 update_progress_display(g);
45954603
45964604 AstNode *return_type_node = (fn_table_entry->proto_node != nullptr) ?
45974605 fn_table_entry->proto_node->data.fn_proto.return_type : fn_table_entry->fndef_scope->base.source_node;
src/codegen.cpp+37-24
......@@ -7303,8 +7303,12 @@ static void do_code_gen(CodeGen *g) {
73037303 }
73047304
73057305 // Generate function definitions.
7306 stage2_progress_update_node(g->sub_progress_node, 0, g->fn_defs.length);
73067307 for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) {
73077308 ZigFn *fn_table_entry = g->fn_defs.at(fn_i);
7309 Stage2ProgressNode *fn_prog_node = stage2_progress_start(g->sub_progress_node,
7310 buf_ptr(&fn_table_entry->symbol_name), buf_len(&fn_table_entry->symbol_name), 0);
7311
73087312 FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id;
73097313 CallingConvention cc = fn_type_id->cc;
73107314 bool is_c_abi = cc == CallingConventionC;
......@@ -7568,6 +7572,7 @@ static void do_code_gen(CodeGen *g) {
75687572
75697573 ir_render(g, fn_table_entry);
75707574
7575 stage2_progress_end(fn_prog_node);
75717576 }
75727577
75737578 assert(!g->errors.length);
......@@ -7615,7 +7620,7 @@ static void zig_llvm_emit_output(CodeGen *g) {
76157620 if (g->bundle_compiler_rt && (g->out_type == OutTypeObj ||
76167621 (g->out_type == OutTypeLib && !g->is_dynamic)))
76177622 {
7618 zig_link_add_compiler_rt(g, g->progress_node);
7623 zig_link_add_compiler_rt(g, g->sub_progress_node);
76197624 }
76207625 break;
76217626
......@@ -9458,7 +9463,7 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
94589463}
94599464
94609465// returns true if it was a cache miss
9461static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file, Stage2ProgressNode *parent_prog_node) {
9466static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
94629467 Error err;
94639468
94649469 Buf *artifact_dir;
......@@ -9470,7 +9475,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file, Stage2Pr
94709475 Buf *c_source_basename = buf_alloc();
94719476 os_path_split(c_source_file, nullptr, c_source_basename);
94729477
9473 Stage2ProgressNode *child_prog_node = stage2_progress_start(parent_prog_node, buf_ptr(c_source_basename),
9478 Stage2ProgressNode *child_prog_node = stage2_progress_start(g->sub_progress_node, buf_ptr(c_source_basename),
94749479 buf_len(c_source_basename), 0);
94759480
94769481 Buf *final_o_basename = buf_alloc();
......@@ -9606,17 +9611,15 @@ static void gen_c_objects(CodeGen *g) {
96069611 exit(1);
96079612 }
96089613
9609 codegen_add_time_event(g, "Compile C Code");
9610 const char *c_prog_name = "compiling C objects";
9611 Stage2ProgressNode *c_prog_node = stage2_progress_start(g->progress_node, c_prog_name, strlen(c_prog_name),
9612 g->c_source_files.length);
9614 codegen_add_time_event(g, "Compile C Objects");
9615 const char *c_prog_name = "Compile C Objects";
9616 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, c_prog_name, strlen(c_prog_name),
9617 g->c_source_files.length));
96139618
96149619 for (size_t c_file_i = 0; c_file_i < g->c_source_files.length; c_file_i += 1) {
96159620 CFile *c_file = g->c_source_files.at(c_file_i);
9616 gen_c_object(g, self_exe_path, c_file, c_prog_node);
9621 gen_c_object(g, self_exe_path, c_file);
96179622 }
9618
9619 stage2_progress_end(c_prog_node);
96209623}
96219624
96229625void codegen_add_object(CodeGen *g, Buf *object_path) {
......@@ -10337,9 +10340,8 @@ void codegen_build_and_link(CodeGen *g) {
1033710340
1033810341 codegen_add_time_event(g, "Semantic Analysis");
1033910342 const char *progress_name = "Semantic Analysis";
10340 Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node,
10341 progress_name, strlen(progress_name), 0);
10342 (void)child_progress_node;
10343 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
10344 progress_name, strlen(progress_name), 0));
1034310345
1034410346 gen_root_source(g);
1034510347
......@@ -10365,18 +10367,16 @@ void codegen_build_and_link(CodeGen *g) {
1036510367 codegen_add_time_event(g, "Code Generation");
1036610368 {
1036710369 const char *progress_name = "Code Generation";
10368 Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node,
10369 progress_name, strlen(progress_name), 0);
10370 (void)child_progress_node;
10370 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
10371 progress_name, strlen(progress_name), 0));
1037110372 }
1037210373
1037310374 do_code_gen(g);
1037410375 codegen_add_time_event(g, "LLVM Emit Output");
1037510376 {
1037610377 const char *progress_name = "LLVM Emit Output";
10377 Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node,
10378 progress_name, strlen(progress_name), 0);
10379 (void)child_progress_node;
10378 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
10379 progress_name, strlen(progress_name), 0));
1038010380 }
1038110381 zig_llvm_emit_output(g);
1038210382
......@@ -10384,9 +10384,8 @@ void codegen_build_and_link(CodeGen *g) {
1038410384 codegen_add_time_event(g, "Generate .h");
1038510385 {
1038610386 const char *progress_name = "Generate .h";
10387 Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node,
10388 progress_name, strlen(progress_name), 0);
10389 (void)child_progress_node;
10387 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
10388 progress_name, strlen(progress_name), 0));
1039010389 }
1039110390 gen_h_file(g);
1039210391 }
......@@ -10458,6 +10457,7 @@ void codegen_build_and_link(CodeGen *g) {
1045810457
1045910458 codegen_release_caches(g);
1046010459 codegen_add_time_event(g, "Done");
10460 codegen_switch_sub_prog_node(g, nullptr);
1046110461}
1046210462
1046310463void codegen_release_caches(CodeGen *g) {
......@@ -10487,7 +10487,7 @@ CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType o
1048710487 ZigLibCInstallation *libc, const char *name, Stage2ProgressNode *parent_progress_node)
1048810488{
1048910489 Stage2ProgressNode *child_progress_node = stage2_progress_start(
10490 parent_progress_node ? parent_progress_node : parent_gen->progress_node,
10490 parent_progress_node ? parent_progress_node : parent_gen->sub_progress_node,
1049110491 name, strlen(name), 0);
1049210492
1049310493 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
1052410524 ZigLibCInstallation *libc, Buf *cache_dir, bool is_test_build, Stage2ProgressNode *progress_node)
1052510525{
1052610526 CodeGen *g = allocate<CodeGen>(1);
10527 g->progress_node = progress_node;
10527 g->main_progress_node = progress_node;
1052810528
1052910529 codegen_add_time_event(g, "Initialize");
10530 {
10531 const char *progress_name = "Initialize";
10532 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
10533 progress_name, strlen(progress_name), 0));
10534 }
1053010535
1053110536 g->subsystem = TargetSubsystemAuto;
1053210537 g->libc = libc;
......@@ -10651,3 +10656,11 @@ bool codegen_fn_has_err_ret_tracing_stack(CodeGen *g, ZigFn *fn, bool is_async)
1065110656 !codegen_fn_has_err_ret_tracing_arg(g, fn->type_entry->data.fn.fn_type_id.return_type);
1065210657 }
1065310658}
10659
10660void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) {
10661 if (g->sub_progress_node != nullptr) {
10662 stage2_progress_end(g->sub_progress_node);
10663 }
10664 g->sub_progress_node = node;
10665}
10666
src/codegen.hpp+2
......@@ -67,4 +67,6 @@ bool codegen_fn_has_err_ret_tracing_stack(CodeGen *g, ZigFn *fn, bool is_async);
6767ATTRIBUTE_NORETURN
6868void codegen_report_errors_and_exit(CodeGen *g);
6969
70void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node);
71
7072#endif
src/link.cpp+11-6
......@@ -2630,8 +2630,9 @@ void codegen_link(CodeGen *g) {
26302630
26312631 {
26322632 const char *progress_name = "Build Dependencies";
2633 lj.build_dep_prog_node = stage2_progress_start(g->progress_node,
2634 progress_name, strlen(progress_name), 0);
2633 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
2634 progress_name, strlen(progress_name), 0));
2635 lj.build_dep_prog_node = g->sub_progress_node;
26352636 }
26362637
26372638
......@@ -2661,10 +2662,9 @@ void codegen_link(CodeGen *g) {
26612662 ZigLLVM_OSType os_type = get_llvm_os_type(g->zig_target->os);
26622663 codegen_add_time_event(g, "LLVM Link");
26632664 {
2664 const char *progress_name = "linking";
2665 Stage2ProgressNode *child_progress_node = stage2_progress_start(g->progress_node,
2666 progress_name, strlen(progress_name), 0);
2667 (void)child_progress_node;
2665 const char *progress_name = "Link";
2666 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
2667 progress_name, strlen(progress_name), 0));
26682668 }
26692669 if (g->verbose_link) {
26702670 fprintf(stderr, "ar rcs %s", buf_ptr(&g->output_file_path));
......@@ -2696,6 +2696,11 @@ void codegen_link(CodeGen *g) {
26962696 Buf diag = BUF_INIT;
26972697
26982698 codegen_add_time_event(g, "LLVM Link");
2699 {
2700 const char *progress_name = "Link";
2701 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
2702 progress_name, strlen(progress_name), 0));
2703 }
26992704 if (g->system_linker_hack && g->zig_target->os == OsMacOSX) {
27002705 Termination term;
27012706 ZigList<const char *> args = {};
src/main.cpp+4
......@@ -1333,6 +1333,10 @@ int main(int argc, char **argv) {
13331333
13341334 g->enable_cache = get_cache_opt(enable_cache, output_dir == nullptr);
13351335 codegen_build_and_link(g);
1336 if (root_progress_node != nullptr) {
1337 stage2_progress_end(root_progress_node);
1338 root_progress_node = nullptr;
1339 }
13361340
13371341 if (timing_info) {
13381342 codegen_print_timing_report(g, stdout);
src/userland.cpp+1
......@@ -88,3 +88,4 @@ Stage2ProgressNode *stage2_progress_start(Stage2ProgressNode *node,
8888void stage2_progress_end(Stage2ProgressNode *node) {}
8989void stage2_progress_complete_one(Stage2ProgressNode *node) {}
9090void stage2_progress_disable_tty(Stage2Progress *progress) {}
91void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items){}
src/userland.h+3
......@@ -176,5 +176,8 @@ ZIG_EXTERN_C Stage2ProgressNode *stage2_progress_start(Stage2ProgressNode *node,
176176ZIG_EXTERN_C void stage2_progress_end(Stage2ProgressNode *node);
177177// ABI warning
178178ZIG_EXTERN_C void stage2_progress_complete_one(Stage2ProgressNode *node);
179// ABI warning
180ZIG_EXTERN_C void stage2_progress_update_node(Stage2ProgressNode *node,
181 size_t completed_count, size_t estimated_total_items);
179182
180183#endif