authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 19:15:33-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 19:15:33-04:00
log69c7c5de09e16e96a6ea5207ef8b3a21e9d119f9
tree8b3edf357fa9b73d824753ba9ebebee158e9e8b2
parentfe2d89007b2013bed4a12446fa74a124a9721dbb
signature Commit is signed but in an unrecognized format.

fixups

* better detection for already seen packages * "root" instead of "@root"

3 files changed, 18 insertions(+), 19 deletions(-)

src/all_types.hpp+2
...@@ -1110,6 +1110,8 @@ struct ZigPackage {...@@ -1110,6 +1110,8 @@ struct ZigPackage {
11101110
1111 // reminder: hash tables must be initialized before use1111 // reminder: hash tables must be initialized before use
1112 HashMap<Buf *, ZigPackage *, buf_hash, buf_eql_buf> package_table;1112 HashMap<Buf *, ZigPackage *, buf_hash, buf_eql_buf> package_table;
1113
1114 bool added_to_cache;
1113};1115};
11141116
1115// Stuff that only applies to a struct which is the implicit root struct of a file1117// Stuff that only applies to a struct which is the implicit root struct of a file
src/codegen.cpp+14-16
...@@ -180,7 +180,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget...@@ -180,7 +180,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
180 g->root_package = new_package(".", "", "");180 g->root_package = new_package(".", "", "");
181 }181 }
182182
183 g->root_package->package_table.put(buf_create_from_str("@root"), g->root_package);183 g->root_package->package_table.put(buf_create_from_str("root"), g->root_package);
184184
185 g->zig_std_special_dir = buf_alloc();185 g->zig_std_special_dir = buf_alloc();
186 os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir);186 os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir);
...@@ -8055,6 +8055,8 @@ static Error define_builtin_compile_vars(CodeGen *g) {...@@ -8055,6 +8055,8 @@ static Error define_builtin_compile_vars(CodeGen *g) {
8055 g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);8055 g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
8056 g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);8056 g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
8057 g->std_package->package_table.put(buf_create_from_str("std"), g->std_package);8057 g->std_package->package_table.put(buf_create_from_str("std"), g->std_package);
8058 g->std_package->package_table.put(buf_create_from_str("root"),
8059 g->is_test_build ? g->test_runner_package : g->root_package);
8058 g->compile_var_import = add_source_file(g, g->compile_var_package, builtin_zig_path, contents,8060 g->compile_var_import = add_source_file(g, g->compile_var_package, builtin_zig_path, contents,
8059 SourceKindPkgMain);8061 SourceKindPkgMain);
80608062
...@@ -8522,8 +8524,10 @@ static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *ba...@@ -8522,8 +8524,10 @@ static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *ba
8522 return add_source_file(g, package, resolved_path, import_code, SourceKindPkgMain);8524 return add_source_file(g, package, resolved_path, import_code, SourceKindPkgMain);
8523}8525}
85248526
8525static ZigPackage *create_bootstrap_pkg(CodeGen *g) {8527static ZigPackage *create_bootstrap_pkg(CodeGen *g, ZigPackage *pkg_with_main) {
8526 return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig", "std.special");8528 ZigPackage *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig", "std.special");
8529 package->package_table.put(buf_create_from_str("root"), pkg_with_main);
8530 return package;
8527}8531}
85288532
8529static ZigPackage *create_test_runner_pkg(CodeGen *g) {8533static ZigPackage *create_test_runner_pkg(CodeGen *g) {
...@@ -8647,12 +8651,12 @@ static void gen_root_source(CodeGen *g) {...@@ -8647,12 +8651,12 @@ static void gen_root_source(CodeGen *g) {
8647 !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&8651 !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&
8648 ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))8652 ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))
8649 {8653 {
8650 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g), "bootstrap.zig");8654 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap.zig");
8651 }8655 }
8652 if (g->zig_target->os == OsWindows && !g->have_dllmain_crt_startup &&8656 if (g->zig_target->os == OsWindows && !g->have_dllmain_crt_startup &&
8653 g->out_type == OutTypeLib && g->is_dynamic)8657 g->out_type == OutTypeLib && g->is_dynamic)
8654 {8658 {
8655 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g), "bootstrap_lib.zig");8659 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap_lib.zig");
8656 }8660 }
86578661
8658 if (!g->error_during_imports) {8662 if (!g->error_during_imports) {
...@@ -8660,7 +8664,7 @@ static void gen_root_source(CodeGen *g) {...@@ -8660,7 +8664,7 @@ static void gen_root_source(CodeGen *g) {
8660 }8664 }
8661 if (g->is_test_build) {8665 if (g->is_test_build) {
8662 create_test_compile_var_and_add_test_runner(g);8666 create_test_compile_var_and_add_test_runner(g);
8663 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g), "bootstrap.zig");8667 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->test_runner_package), "bootstrap.zig");
86648668
8665 if (!g->error_during_imports) {8669 if (!g->error_during_imports) {
8666 semantic_analyze(g);8670 semantic_analyze(g);
...@@ -9375,6 +9379,7 @@ void codegen_add_time_event(CodeGen *g, const char *name) {...@@ -9375,6 +9379,7 @@ void codegen_add_time_event(CodeGen *g, const char *name) {
9375static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {9379static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
9376 if (buf_len(&pkg->root_src_path) == 0)9380 if (buf_len(&pkg->root_src_path) == 0)
9377 return;9381 return;
9382 pkg->added_to_cache = true;
93789383
9379 Buf *rel_full_path = buf_alloc();9384 Buf *rel_full_path = buf_alloc();
9380 os_path_join(&pkg->root_src_dir, &pkg->root_src_path, rel_full_path);9385 os_path_join(&pkg->root_src_dir, &pkg->root_src_path, rel_full_path);
...@@ -9386,11 +9391,7 @@ static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {...@@ -9386,11 +9391,7 @@ static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
9386 if (!entry)9391 if (!entry)
9387 break;9392 break;
93889393
9389 // TODO: I think we need a more sophisticated detection of9394 if (!pkg->added_to_cache) {
9390 // packages we have already seen
9391 if (entry->value != pkg) {
9392 auto root = pkg->package_table.maybe_get(buf_create_from_str("@root"));
9393 if (root != nullptr && entry->value == root->value) continue;
9394 cache_buf(ch, entry->key);9395 cache_buf(ch, entry->key);
9395 add_cache_pkg(g, ch, entry->value);9396 add_cache_pkg(g, ch, entry->value);
9396 }9397 }
...@@ -9648,11 +9649,8 @@ ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const c...@@ -9648,11 +9649,8 @@ ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const c
9648 assert(g->compile_var_package != nullptr);9649 assert(g->compile_var_package != nullptr);
9649 pkg->package_table.put(buf_create_from_str("std"), g->std_package);9650 pkg->package_table.put(buf_create_from_str("std"), g->std_package);
96509651
9651 if (g->is_test_build) {9652 ZigPackage *main_pkg = g->is_test_build ? g->test_runner_package : g->root_package;
9652 pkg->package_table.put(buf_create_from_str("@root"), g->test_runner_package);9653 pkg->package_table.put(buf_create_from_str("root"), main_pkg);
9653 } else {
9654 pkg->package_table.put(buf_create_from_str("@root"), g->root_package);
9655 }
96569654
9657 pkg->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);9655 pkg->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
9658 }9656 }
std/special/bootstrap.zig+2-3
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1// This file is in a package which has the root source file exposed as "@root".1// This file is included in the compilation unit when exporting an executable.
2// It is included in the compilation unit when exporting an executable.
32
4const root = @import("@root");3const root = @import("root");
5const std = @import("std");4const std = @import("std");
6const builtin = @import("builtin");5const builtin = @import("builtin");
7const assert = std.debug.assert;6const assert = std.debug.assert;