diff options
| author | Takeshi Yoneda <takeshi@tetrate.io> | 2021-08-09 14:39:26 +0900 |
|---|---|---|
| committer | Takeshi Yoneda <takeshi@tetrate.io> | 2021-08-09 14:39:26 +0900 |
| commit | 97560cd915008f04addc2c30af087aa89c162b02 (patch) | |
| tree | 8aed12c207ff84cc256a0c78955c23b61129ba22 /src/Compilation.zig | |
| parent | 7814a2bd4a3ec22cd9548c622f7dc837dba968f7 (diff) | |
| parent | 799fedf612aa8742c446b015c12d21707a1dbec0 (diff) | |
| download | zig-97560cd915008f04addc2c30af087aa89c162b02.tar.gz zig-97560cd915008f04addc2c30af087aa89c162b02.zip | |
Merge remote-tracking branch 'origin' into libc-wasi-test
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index a34d0cd198..24e2d9e67f 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -944,8 +944,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { if (options.sysroot) |sysroot| { break :blk sysroot; } else if (darwin_can_use_system_sdk) { - // TODO Revisit this targeting versions lower than macOS 11 when LLVM 12 is out. - // See https://github.com/ziglang/zig/issues/6996 const at_least_big_sur = options.target.os.getVersionRange().semver.min.major >= 11; break :blk if (at_least_big_sur) try std.zig.system.getSDKPath(arena) else null; } else { @@ -1029,7 +1027,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { options.target, options.is_native_abi, link_libc, - options.system_libs.len != 0, + options.system_libs.len != 0 or options.frameworks.len != 0, options.libc_installation, ); @@ -1229,6 +1227,12 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { } else main_pkg; errdefer if (options.is_test) root_pkg.destroy(gpa); + var other_pkg_iter = main_pkg.table.valueIterator(); + while (other_pkg_iter.next()) |pkg| { + try pkg.*.add(gpa, "builtin", builtin_pkg); + try pkg.*.add(gpa, "std", std_pkg); + } + try main_pkg.addAndAdopt(gpa, "builtin", builtin_pkg); try main_pkg.add(gpa, "root", root_pkg); try main_pkg.addAndAdopt(gpa, "std", std_pkg); @@ -1709,7 +1713,9 @@ pub fn update(self: *Compilation) !void { // in the start code, but when using the stage1 backend that won't happen, // so in order to run AstGen on the root source file we put it into the // import_table here. - if (use_stage1) { + // Likewise, in the case of `zig test`, the test runner is the root source file, + // and so there is nothing to import the main file. + if (use_stage1 or self.bin_file.options.is_test) { _ = try module.importPkg(module.main_pkg); } @@ -1725,6 +1731,9 @@ pub fn update(self: *Compilation) !void { if (!use_stage1) { try self.work_queue.writeItem(.{ .analyze_pkg = std_pkg }); + if (self.bin_file.options.is_test) { + try self.work_queue.writeItem(.{ .analyze_pkg = module.main_pkg }); + } } } @@ -1732,6 +1741,13 @@ pub fn update(self: *Compilation) !void { if (!use_stage1) { if (self.bin_file.options.module) |module| { + if (self.bin_file.options.is_test and self.totalErrorCount() == 0) { + // The `test_functions` decl has been intentionally postponed until now, + // at which point we must populate it with the list of test functions that + // have been discovered and not filtered out. + try module.populateTestFunctions(); + } + // Process the deletion set. We use a while loop here because the // deletion set may grow as we call `clearDecl` within this loop, // and more unreferenced Decls are revealed. @@ -2049,28 +2065,19 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor .complete, .codegen_failure_retryable => { if (build_options.omit_stage2) @panic("sadly stage2 is omitted from this build to save memory on the CI server"); + const module = self.bin_file.options.module.?; assert(decl.has_tv); assert(decl.ty.hasCodeGenBits()); - self.bin_file.updateDecl(module, decl) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.AnalysisFail => { - decl.analysis = .codegen_failure; - continue; - }, - else => { - try module.failed_decls.ensureUnusedCapacity(gpa, 1); - module.failed_decls.putAssumeCapacityNoClobber(decl, try Module.ErrorMsg.create( - gpa, - decl.srcLoc(), - "unable to codegen: {s}", - .{@errorName(err)}, - )); - decl.analysis = .codegen_failure_retryable; - continue; - }, - }; + if (decl.alive) { + try module.linkerUpdateDecl(decl); + continue; + } + + // Instead of sending this decl to the linker, we actually will delete it + // because we found out that it in fact was never referenced. + module.deleteUnusedDecl(decl); }, }, .codegen_func => |func| switch (func.owner_decl.analysis) { @@ -2115,7 +2122,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor if (builtin.mode == .Debug and self.verbose_air) { std.debug.print("# Begin Function AIR: {s}:\n", .{decl.name}); @import("print_air.zig").dump(gpa, air, decl.namespace.file_scope.zir, liveness); - std.debug.print("# End Function AIR: {s}:\n", .{decl.name}); + std.debug.print("# End Function AIR: {s}\n\n", .{decl.name}); } self.bin_file.updateFunc(module, func, air, liveness) catch |err| switch (err) { @@ -3340,7 +3347,7 @@ pub fn hasSharedLibraryExt(filename: []const u8) bool { return true; } // Look for .so.X, .so.X.Y, .so.X.Y.Z - var it = mem.split(filename, "."); + var it = mem.split(u8, filename, "."); _ = it.next().?; var so_txt = it.next() orelse return false; while (!mem.eql(u8, so_txt, "so")) { @@ -4085,7 +4092,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node }; if (directory.handle.readFileAlloc(comp.gpa, libs_txt_basename, 10 * 1024 * 1024)) |libs_txt| { - var it = mem.tokenize(libs_txt, "\n"); + var it = mem.tokenize(u8, libs_txt, "\n"); while (it.next()) |lib_name| { try comp.stage1AddLinkLib(lib_name); } |
