| ... | ... | @@ -1391,6 +1391,7 @@ pub const Win32Resource = struct { |
| 1391 | 1391 | }; |
| 1392 | 1392 | |
| 1393 | 1393 | pub const MiscTask = enum { |
| 1394 | open_output, |
| 1394 | 1395 | write_builtin_zig, |
| 1395 | 1396 | rename_results, |
| 1396 | 1397 | check_whole_cache, |
| ... | ... | @@ -1874,7 +1875,49 @@ fn addModuleTableToCacheHash( |
| 1874 | 1875 | |
| 1875 | 1876 | const RtStrat = enum { none, lib, obj, zcu, dyn_lib }; |
| 1876 | 1877 | |
| 1877 | | pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compilation { |
| 1878 | pub const CreateDiagnostic = union(enum) { |
| 1879 | export_table_import_table_conflict, |
| 1880 | emit_h_without_zcu, |
| 1881 | illegal_zig_import, |
| 1882 | cross_libc_unavailable, |
| 1883 | find_native_libc: std.zig.LibCInstallation.FindError, |
| 1884 | libc_installation_missing_crt_dir, |
| 1885 | create_cache_path: CreateCachePath, |
| 1886 | open_output_bin: link.File.OpenError, |
| 1887 | pub const CreateCachePath = struct { |
| 1888 | which: enum { local, global }, |
| 1889 | sub: []const u8, |
| 1890 | err: (fs.Dir.MakeError || fs.Dir.OpenError || fs.Dir.StatFileError), |
| 1891 | }; |
| 1892 | pub fn format(diag: CreateDiagnostic, w: *std.Io.Writer) std.Io.Writer.Error!void { |
| 1893 | switch (diag) { |
| 1894 | .export_table_import_table_conflict => try w.writeAll("'--import-table' and '--export-table' cannot be used together"), |
| 1895 | .emit_h_without_zcu => try w.writeAll("cannot emit C header with no Zig source files"), |
| 1896 | .illegal_zig_import => try w.writeAll("this compiler implementation does not support importing the root source file of a provided module"), |
| 1897 | .cross_libc_unavailable => try w.writeAll("unable to provide libc for this target"), |
| 1898 | .find_native_libc => |err| try w.print("failed to find libc installation: {t}", .{err}), |
| 1899 | .libc_installation_missing_crt_dir => try w.writeAll("libc installation is missing crt directory"), |
| 1900 | .create_cache_path => |cache| try w.print("failed to create path '{s}' in {t} cache directory: {t}", .{ |
| 1901 | cache.sub, |
| 1902 | cache.which, |
| 1903 | cache.err, |
| 1904 | }), |
| 1905 | .open_output_bin => |err| try w.print("failed to open output binary: {t}", .{err}), |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | fn fail(out: *CreateDiagnostic, result: CreateDiagnostic) error{CreateFail} { |
| 1910 | out.* = result; |
| 1911 | return error.CreateFail; |
| 1912 | } |
| 1913 | }; |
| 1914 | pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options: CreateOptions) error{ |
| 1915 | OutOfMemory, |
| 1916 | Unexpected, |
| 1917 | CurrentWorkingDirectoryUnlinked, |
| 1918 | /// An error has been stored to `diag`. |
| 1919 | CreateFail, |
| 1920 | }!*Compilation { |
| 1878 | 1921 | const output_mode = options.config.output_mode; |
| 1879 | 1922 | const is_dyn_lib = switch (output_mode) { |
| 1880 | 1923 | .Obj, .Exe => false, |
| ... | ... | @@ -1887,7 +1930,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1887 | 1930 | }; |
| 1888 | 1931 | |
| 1889 | 1932 | if (options.linker_export_table and options.linker_import_table) { |
| 1890 | | return error.ExportTableAndImportTableConflict; |
| 1933 | return diag.fail(.export_table_import_table_conflict); |
| 1891 | 1934 | } |
| 1892 | 1935 | |
| 1893 | 1936 | const have_zcu = options.config.have_zcu; |
| ... | ... | @@ -1920,14 +1963,18 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1920 | 1963 | |
| 1921 | 1964 | const link_libc = options.config.link_libc; |
| 1922 | 1965 | |
| 1923 | | const libc_dirs = try std.zig.LibCDirs.detect( |
| 1966 | const libc_dirs = std.zig.LibCDirs.detect( |
| 1924 | 1967 | arena, |
| 1925 | 1968 | options.dirs.zig_lib.path.?, |
| 1926 | 1969 | target, |
| 1927 | 1970 | options.root_mod.resolved_target.is_native_abi, |
| 1928 | 1971 | link_libc, |
| 1929 | 1972 | options.libc_installation, |
| 1930 | | ); |
| 1973 | ) catch |err| switch (err) { |
| 1974 | error.OutOfMemory => |e| return e, |
| 1975 | // Every other error is specifically related to finding the native installation |
| 1976 | else => |e| return diag.fail(.{ .find_native_libc = e }), |
| 1977 | }; |
| 1931 | 1978 | |
| 1932 | 1979 | const sysroot = options.sysroot orelse libc_dirs.sysroot; |
| 1933 | 1980 | |
| ... | ... | @@ -1949,7 +1996,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1949 | 1996 | if (compiler_rt_strat == .zcu) { |
| 1950 | 1997 | // For objects, this mechanism relies on essentially `_ = @import("compiler-rt");` |
| 1951 | 1998 | // injected into the object. |
| 1952 | | const compiler_rt_mod = try Package.Module.create(arena, .{ |
| 1999 | const compiler_rt_mod = Package.Module.create(arena, .{ |
| 1953 | 2000 | .paths = .{ |
| 1954 | 2001 | .root = .zig_lib_root, |
| 1955 | 2002 | .root_src_path = "compiler_rt.zig", |
| ... | ... | @@ -1963,7 +2010,22 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1963 | 2010 | }, |
| 1964 | 2011 | .global = options.config, |
| 1965 | 2012 | .parent = options.root_mod, |
| 1966 | | }); |
| 2013 | }) catch |err| switch (err) { |
| 2014 | error.OutOfMemory => |e| return e, |
| 2015 | // None of these are possible because the configuration matches the root module |
| 2016 | // which already passed these checks. |
| 2017 | error.ValgrindUnsupportedOnTarget => unreachable, |
| 2018 | error.TargetRequiresSingleThreaded => unreachable, |
| 2019 | error.BackendRequiresSingleThreaded => unreachable, |
| 2020 | error.TargetRequiresPic => unreachable, |
| 2021 | error.PieRequiresPic => unreachable, |
| 2022 | error.DynamicLinkingRequiresPic => unreachable, |
| 2023 | error.TargetHasNoRedZone => unreachable, |
| 2024 | // These are not possible because are explicitly *not* requesting these things. |
| 2025 | error.StackCheckUnsupportedByTarget => unreachable, |
| 2026 | error.StackProtectorUnsupportedByTarget => unreachable, |
| 2027 | error.StackProtectorUnavailableWithoutLibC => unreachable, |
| 2028 | }; |
| 1967 | 2029 | try options.root_mod.deps.putNoClobber(arena, "compiler_rt", compiler_rt_mod); |
| 1968 | 2030 | } |
| 1969 | 2031 | |
| ... | ... | @@ -1981,7 +2043,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1981 | 2043 | }; |
| 1982 | 2044 | |
| 1983 | 2045 | if (ubsan_rt_strat == .zcu) { |
| 1984 | | const ubsan_rt_mod = try Package.Module.create(arena, .{ |
| 2046 | const ubsan_rt_mod = Package.Module.create(arena, .{ |
| 1985 | 2047 | .paths = .{ |
| 1986 | 2048 | .root = .zig_lib_root, |
| 1987 | 2049 | .root_src_path = "ubsan_rt.zig", |
| ... | ... | @@ -1991,7 +2053,21 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1991 | 2053 | .inherited = .{}, |
| 1992 | 2054 | .global = options.config, |
| 1993 | 2055 | .parent = options.root_mod, |
| 1994 | | }); |
| 2056 | }) catch |err| switch (err) { |
| 2057 | error.OutOfMemory => |e| return e, |
| 2058 | // None of these are possible because the configuration matches the root module |
| 2059 | // which already passed these checks. |
| 2060 | error.ValgrindUnsupportedOnTarget => unreachable, |
| 2061 | error.TargetRequiresSingleThreaded => unreachable, |
| 2062 | error.BackendRequiresSingleThreaded => unreachable, |
| 2063 | error.TargetRequiresPic => unreachable, |
| 2064 | error.PieRequiresPic => unreachable, |
| 2065 | error.DynamicLinkingRequiresPic => unreachable, |
| 2066 | error.TargetHasNoRedZone => unreachable, |
| 2067 | error.StackCheckUnsupportedByTarget => unreachable, |
| 2068 | error.StackProtectorUnsupportedByTarget => unreachable, |
| 2069 | error.StackProtectorUnavailableWithoutLibC => unreachable, |
| 2070 | }; |
| 1995 | 2071 | try options.root_mod.deps.putNoClobber(arena, "ubsan_rt", ubsan_rt_mod); |
| 1996 | 2072 | } |
| 1997 | 2073 | |
| ... | ... | @@ -2019,7 +2095,9 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2019 | 2095 | const cache = try arena.create(Cache); |
| 2020 | 2096 | cache.* = .{ |
| 2021 | 2097 | .gpa = gpa, |
| 2022 | | .manifest_dir = try options.dirs.local_cache.handle.makeOpenPath("h", .{}), |
| 2098 | .manifest_dir = options.dirs.local_cache.handle.makeOpenPath("h", .{}) catch |err| { |
| 2099 | return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = "h", .err = err } }); |
| 2100 | }, |
| 2023 | 2101 | }; |
| 2024 | 2102 | // These correspond to std.zig.Server.Message.PathPrefix. |
| 2025 | 2103 | cache.addPrefix(.{ .path = null, .handle = fs.cwd() }); |
| ... | ... | @@ -2067,20 +2145,24 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2067 | 2145 | // to redundantly happen for each AstGen operation. |
| 2068 | 2146 | const zir_sub_dir = "z"; |
| 2069 | 2147 | |
| 2070 | | var local_zir_dir = try options.dirs.local_cache.handle.makeOpenPath(zir_sub_dir, .{}); |
| 2148 | var local_zir_dir = options.dirs.local_cache.handle.makeOpenPath(zir_sub_dir, .{}) catch |err| { |
| 2149 | return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = zir_sub_dir, .err = err } }); |
| 2150 | }; |
| 2071 | 2151 | errdefer local_zir_dir.close(); |
| 2072 | 2152 | const local_zir_cache: Cache.Directory = .{ |
| 2073 | 2153 | .handle = local_zir_dir, |
| 2074 | 2154 | .path = try options.dirs.local_cache.join(arena, &.{zir_sub_dir}), |
| 2075 | 2155 | }; |
| 2076 | | var global_zir_dir = try options.dirs.global_cache.handle.makeOpenPath(zir_sub_dir, .{}); |
| 2156 | var global_zir_dir = options.dirs.global_cache.handle.makeOpenPath(zir_sub_dir, .{}) catch |err| { |
| 2157 | return diag.fail(.{ .create_cache_path = .{ .which = .global, .sub = zir_sub_dir, .err = err } }); |
| 2158 | }; |
| 2077 | 2159 | errdefer global_zir_dir.close(); |
| 2078 | 2160 | const global_zir_cache: Cache.Directory = .{ |
| 2079 | 2161 | .handle = global_zir_dir, |
| 2080 | 2162 | .path = try options.dirs.global_cache.join(arena, &.{zir_sub_dir}), |
| 2081 | 2163 | }; |
| 2082 | 2164 | |
| 2083 | | const std_mod = options.std_mod orelse try Package.Module.create(arena, .{ |
| 2165 | const std_mod = options.std_mod orelse Package.Module.create(arena, .{ |
| 2084 | 2166 | .paths = .{ |
| 2085 | 2167 | .root = try .fromRoot(arena, options.dirs, .zig_lib, "std"), |
| 2086 | 2168 | .root_src_path = "std.zig", |
| ... | ... | @@ -2090,7 +2172,21 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2090 | 2172 | .inherited = .{}, |
| 2091 | 2173 | .global = options.config, |
| 2092 | 2174 | .parent = options.root_mod, |
| 2093 | | }); |
| 2175 | }) catch |err| return switch (err) { |
| 2176 | error.OutOfMemory => |e| return e, |
| 2177 | // None of these are possible because the configuration matches the root module |
| 2178 | // which already passed these checks. |
| 2179 | error.ValgrindUnsupportedOnTarget => unreachable, |
| 2180 | error.TargetRequiresSingleThreaded => unreachable, |
| 2181 | error.BackendRequiresSingleThreaded => unreachable, |
| 2182 | error.TargetRequiresPic => unreachable, |
| 2183 | error.PieRequiresPic => unreachable, |
| 2184 | error.DynamicLinkingRequiresPic => unreachable, |
| 2185 | error.TargetHasNoRedZone => unreachable, |
| 2186 | error.StackCheckUnsupportedByTarget => unreachable, |
| 2187 | error.StackProtectorUnsupportedByTarget => unreachable, |
| 2188 | error.StackProtectorUnavailableWithoutLibC => unreachable, |
| 2189 | }; |
| 2094 | 2190 | |
| 2095 | 2191 | const zcu = try arena.create(Zcu); |
| 2096 | 2192 | zcu.* = .{ |
| ... | ... | @@ -2109,7 +2205,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2109 | 2205 | try zcu.init(options.thread_pool.getIdCount()); |
| 2110 | 2206 | break :blk zcu; |
| 2111 | 2207 | } else blk: { |
| 2112 | | if (options.emit_h != .no) return error.NoZigModuleForCHeader; |
| 2208 | if (options.emit_h != .no) return diag.fail(.emit_h_without_zcu); |
| 2113 | 2209 | break :blk null; |
| 2114 | 2210 | }; |
| 2115 | 2211 | errdefer if (opt_zcu) |zcu| zcu.deinit(); |
| ... | ... | @@ -2204,7 +2300,10 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2204 | 2300 | // Populate `zcu.module_roots`. |
| 2205 | 2301 | const pt: Zcu.PerThread = .activate(zcu, .main); |
| 2206 | 2302 | defer pt.deactivate(); |
| 2207 | | try pt.populateModuleRootTable(); |
| 2303 | pt.populateModuleRootTable() catch |err| switch (err) { |
| 2304 | error.OutOfMemory => |e| return e, |
| 2305 | error.IllegalZigImport => return diag.fail(.illegal_zig_import), |
| 2306 | }; |
| 2208 | 2307 | } |
| 2209 | 2308 | |
| 2210 | 2309 | const lf_open_opts: link.File.OpenOptions = .{ |
| ... | ... | @@ -2279,10 +2378,12 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2279 | 2378 | none.* = .{ .tmp_artifact_directory = null }; |
| 2280 | 2379 | comp.cache_use = .{ .none = none }; |
| 2281 | 2380 | if (comp.emit_bin) |path| { |
| 2282 | | comp.bin_file = try link.File.open(arena, comp, .{ |
| 2381 | comp.bin_file = link.File.open(arena, comp, .{ |
| 2283 | 2382 | .root_dir = .cwd(), |
| 2284 | 2383 | .sub_path = path, |
| 2285 | | }, lf_open_opts); |
| 2384 | }, lf_open_opts) catch |err| { |
| 2385 | return diag.fail(.{ .open_output_bin = err }); |
| 2386 | }; |
| 2286 | 2387 | } |
| 2287 | 2388 | }, |
| 2288 | 2389 | .incremental => { |
| ... | ... | @@ -2320,7 +2421,9 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2320 | 2421 | const digest = hash.final(); |
| 2321 | 2422 | |
| 2322 | 2423 | const artifact_sub_dir = "o" ++ fs.path.sep_str ++ digest; |
| 2323 | | var artifact_dir = try options.dirs.local_cache.handle.makeOpenPath(artifact_sub_dir, .{}); |
| 2424 | var artifact_dir = options.dirs.local_cache.handle.makeOpenPath(artifact_sub_dir, .{}) catch |err| { |
| 2425 | return diag.fail(.{ .create_cache_path = .{ .which = .local, .sub = artifact_sub_dir, .err = err } }); |
| 2426 | }; |
| 2324 | 2427 | errdefer artifact_dir.close(); |
| 2325 | 2428 | const artifact_directory: Cache.Directory = .{ |
| 2326 | 2429 | .handle = artifact_dir, |
| ... | ... | @@ -2338,7 +2441,9 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2338 | 2441 | .root_dir = artifact_directory, |
| 2339 | 2442 | .sub_path = cache_rel_path, |
| 2340 | 2443 | }; |
| 2341 | | comp.bin_file = try link.File.open(arena, comp, emit, lf_open_opts); |
| 2444 | comp.bin_file = link.File.open(arena, comp, emit, lf_open_opts) catch |err| { |
| 2445 | return diag.fail(.{ .open_output_bin = err }); |
| 2446 | }; |
| 2342 | 2447 | } |
| 2343 | 2448 | }, |
| 2344 | 2449 | .whole => { |
| ... | ... | @@ -2433,7 +2538,10 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2433 | 2538 | .link_mode = comp.config.link_mode, |
| 2434 | 2539 | .pie = comp.config.pie, |
| 2435 | 2540 | }); |
| 2436 | | const paths = try lci.resolveCrtPaths(arena, basenames, target); |
| 2541 | const paths = lci.resolveCrtPaths(arena, basenames, target) catch |err| switch (err) { |
| 2542 | error.OutOfMemory => |e| return e, |
| 2543 | error.LibCInstallationMissingCrtDir => return diag.fail(.libc_installation_missing_crt_dir), |
| 2544 | }; |
| 2437 | 2545 | |
| 2438 | 2546 | const fields = @typeInfo(@TypeOf(paths)).@"struct".fields; |
| 2439 | 2547 | try comp.link_task_queue.queued_prelink.ensureUnusedCapacity(gpa, fields.len + 1); |
| ... | ... | @@ -2445,7 +2553,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2445 | 2553 | // Loads the libraries provided by `target_util.libcFullLinkFlags(target)`. |
| 2446 | 2554 | comp.link_task_queue.queued_prelink.appendAssumeCapacity(.load_host_libc); |
| 2447 | 2555 | } else if (target.isMuslLibC()) { |
| 2448 | | if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; |
| 2556 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); |
| 2449 | 2557 | |
| 2450 | 2558 | if (musl.needsCrt0(comp.config.output_mode, comp.config.link_mode, comp.config.pie)) |f| { |
| 2451 | 2559 | comp.queued_jobs.musl_crt_file[@intFromEnum(f)] = true; |
| ... | ... | @@ -2455,7 +2563,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2455 | 2563 | .dynamic => comp.queued_jobs.musl_crt_file[@intFromEnum(musl.CrtFile.libc_so)] = true, |
| 2456 | 2564 | } |
| 2457 | 2565 | } else if (target.isGnuLibC()) { |
| 2458 | | if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; |
| 2566 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); |
| 2459 | 2567 | |
| 2460 | 2568 | if (glibc.needsCrt0(comp.config.output_mode)) |f| { |
| 2461 | 2569 | comp.queued_jobs.glibc_crt_file[@intFromEnum(f)] = true; |
| ... | ... | @@ -2464,7 +2572,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2464 | 2572 | |
| 2465 | 2573 | comp.queued_jobs.glibc_crt_file[@intFromEnum(glibc.CrtFile.libc_nonshared_a)] = true; |
| 2466 | 2574 | } else if (target.isFreeBSDLibC()) { |
| 2467 | | if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; |
| 2575 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); |
| 2468 | 2576 | |
| 2469 | 2577 | if (freebsd.needsCrt0(comp.config.output_mode)) |f| { |
| 2470 | 2578 | comp.queued_jobs.freebsd_crt_file[@intFromEnum(f)] = true; |
| ... | ... | @@ -2472,7 +2580,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2472 | 2580 | |
| 2473 | 2581 | comp.queued_jobs.freebsd_shared_objects = true; |
| 2474 | 2582 | } else if (target.isNetBSDLibC()) { |
| 2475 | | if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; |
| 2583 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); |
| 2476 | 2584 | |
| 2477 | 2585 | if (netbsd.needsCrt0(comp.config.output_mode)) |f| { |
| 2478 | 2586 | comp.queued_jobs.netbsd_crt_file[@intFromEnum(f)] = true; |
| ... | ... | @@ -2480,12 +2588,12 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2480 | 2588 | |
| 2481 | 2589 | comp.queued_jobs.netbsd_shared_objects = true; |
| 2482 | 2590 | } else if (target.isWasiLibC()) { |
| 2483 | | if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; |
| 2591 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); |
| 2484 | 2592 | |
| 2485 | 2593 | comp.queued_jobs.wasi_libc_crt_file[@intFromEnum(wasi_libc.execModelCrtFile(comp.config.wasi_exec_model))] = true; |
| 2486 | 2594 | comp.queued_jobs.wasi_libc_crt_file[@intFromEnum(wasi_libc.CrtFile.libc_a)] = true; |
| 2487 | 2595 | } else if (target.isMinGW()) { |
| 2488 | | if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable; |
| 2596 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); |
| 2489 | 2597 | |
| 2490 | 2598 | const main_crt_file: mingw.CrtFile = if (is_dyn_lib) .dllcrt2_o else .crt2_o; |
| 2491 | 2599 | comp.queued_jobs.mingw_crt_file[@intFromEnum(main_crt_file)] = true; |
| ... | ... | @@ -2495,7 +2603,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 2495 | 2603 | try comp.windows_libs.ensureUnusedCapacity(gpa, mingw.always_link_libs.len); |
| 2496 | 2604 | for (mingw.always_link_libs) |name| comp.windows_libs.putAssumeCapacity(try gpa.dupe(u8, name), {}); |
| 2497 | 2605 | } else { |
| 2498 | | return error.LibCUnavailable; |
| 2606 | return diag.fail(.cross_libc_unavailable); |
| 2499 | 2607 | } |
| 2500 | 2608 | |
| 2501 | 2609 | if ((target.isMuslLibC() and comp.config.link_mode == .static) or |
| ... | ... | @@ -2737,8 +2845,14 @@ fn cleanupAfterUpdate(comp: *Compilation, tmp_dir_rand_int: u64) void { |
| 2737 | 2845 | } |
| 2738 | 2846 | } |
| 2739 | 2847 | |
| 2848 | pub const UpdateError = error{ |
| 2849 | OutOfMemory, |
| 2850 | Unexpected, |
| 2851 | CurrentWorkingDirectoryUnlinked, |
| 2852 | }; |
| 2853 | |
| 2740 | 2854 | /// Detect changes to source files, perform semantic analysis, and update the output files. |
| 2741 | | pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 2855 | pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateError!void { |
| 2742 | 2856 | const tracy_trace = trace(@src()); |
| 2743 | 2857 | defer tracy_trace.end(); |
| 2744 | 2858 | |
| ... | ... | @@ -2769,10 +2883,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 2769 | 2883 | tmp_dir_rand_int = std.crypto.random.int(u64); |
| 2770 | 2884 | const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int); |
| 2771 | 2885 | const path = try comp.dirs.local_cache.join(arena, &.{tmp_dir_sub_path}); |
| 2772 | | break :d .{ |
| 2773 | | .path = path, |
| 2774 | | .handle = try comp.dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{}), |
| 2886 | const handle = comp.dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{}) catch |err| { |
| 2887 | return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err }); |
| 2775 | 2888 | }; |
| 2889 | break :d .{ .path = path, .handle = handle }; |
| 2776 | 2890 | }; |
| 2777 | 2891 | }, |
| 2778 | 2892 | .incremental => {}, |
| ... | ... | @@ -2849,17 +2963,19 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 2849 | 2963 | tmp_dir_rand_int = std.crypto.random.int(u64); |
| 2850 | 2964 | const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ std.fmt.hex(tmp_dir_rand_int); |
| 2851 | 2965 | const path = try comp.dirs.local_cache.join(arena, &.{tmp_dir_sub_path}); |
| 2852 | | break :d .{ |
| 2853 | | .path = path, |
| 2854 | | .handle = try comp.dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{}), |
| 2966 | const handle = comp.dirs.local_cache.handle.makeOpenPath(tmp_dir_sub_path, .{}) catch |err| { |
| 2967 | return comp.setMiscFailure(.open_output, "failed to create output directory '{s}': {t}", .{ path, err }); |
| 2855 | 2968 | }; |
| 2969 | break :d .{ .path = path, .handle = handle }; |
| 2856 | 2970 | }; |
| 2857 | 2971 | if (comp.emit_bin) |sub_path| { |
| 2858 | 2972 | const emit: Cache.Path = .{ |
| 2859 | 2973 | .root_dir = whole.tmp_artifact_directory.?, |
| 2860 | 2974 | .sub_path = sub_path, |
| 2861 | 2975 | }; |
| 2862 | | comp.bin_file = try link.File.createEmpty(arena, comp, emit, whole.lf_open_opts); |
| 2976 | comp.bin_file = link.File.createEmpty(arena, comp, emit, whole.lf_open_opts) catch |err| { |
| 2977 | return comp.setMiscFailure(.open_output, "failed to open output file '{f}': {t}", .{ emit, err }); |
| 2978 | }; |
| 2863 | 2979 | } |
| 2864 | 2980 | }, |
| 2865 | 2981 | } |
| ... | ... | @@ -3036,11 +3152,11 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 3036 | 3152 | renameTmpIntoCache(comp.dirs.local_cache, tmp_dir_sub_path, o_sub_path) catch |err| { |
| 3037 | 3153 | return comp.setMiscFailure( |
| 3038 | 3154 | .rename_results, |
| 3039 | | "failed to rename compilation results ('{f}{s}') into local cache ('{f}{s}'): {s}", |
| 3155 | "failed to rename compilation results ('{f}{s}') into local cache ('{f}{s}'): {t}", |
| 3040 | 3156 | .{ |
| 3041 | 3157 | comp.dirs.local_cache, tmp_dir_sub_path, |
| 3042 | 3158 | comp.dirs.local_cache, o_sub_path, |
| 3043 | | @errorName(err), |
| 3159 | err, |
| 3044 | 3160 | }, |
| 3045 | 3161 | ); |
| 3046 | 3162 | }; |
| ... | ... | @@ -3054,15 +3170,21 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 3054 | 3170 | .root_dir = comp.dirs.local_cache, |
| 3055 | 3171 | .sub_path = try fs.path.join(arena, &.{ o_sub_path, comp.emit_bin.? }), |
| 3056 | 3172 | }; |
| 3057 | | |
| 3058 | | switch (need_writable_dance) { |
| 3173 | const result: link.File.OpenError!void = switch (need_writable_dance) { |
| 3059 | 3174 | .no => {}, |
| 3060 | | .lf_only => try lf.makeWritable(), |
| 3061 | | .lf_and_debug => { |
| 3062 | | try lf.makeWritable(); |
| 3063 | | try lf.reopenDebugInfo(); |
| 3175 | .lf_only => lf.makeWritable(), |
| 3176 | .lf_and_debug => res: { |
| 3177 | lf.makeWritable() catch |err| break :res err; |
| 3178 | lf.reopenDebugInfo() catch |err| break :res err; |
| 3064 | 3179 | }, |
| 3065 | | } |
| 3180 | }; |
| 3181 | result catch |err| { |
| 3182 | return comp.setMiscFailure( |
| 3183 | .rename_results, |
| 3184 | "failed to re-open renamed compilation results ('{f}{s}'): {t}", |
| 3185 | .{ comp.dirs.local_cache, o_sub_path, err }, |
| 3186 | ); |
| 3187 | }; |
| 3066 | 3188 | } |
| 3067 | 3189 | |
| 3068 | 3190 | try flush(comp, arena, .main); |
| ... | ... | @@ -3155,7 +3277,7 @@ fn flush( |
| 3155 | 3277 | comp: *Compilation, |
| 3156 | 3278 | arena: Allocator, |
| 3157 | 3279 | tid: Zcu.PerThread.Id, |
| 3158 | | ) !void { |
| 3280 | ) Allocator.Error!void { |
| 3159 | 3281 | if (comp.zcu) |zcu| { |
| 3160 | 3282 | if (zcu.llvm_object) |llvm_object| { |
| 3161 | 3283 | const pt: Zcu.PerThread = .activate(zcu, tid); |
| ... | ... | @@ -3173,7 +3295,7 @@ fn flush( |
| 3173 | 3295 | comp.time_report.?.stats.real_ns_llvm_emit = ns; |
| 3174 | 3296 | }; |
| 3175 | 3297 | |
| 3176 | | try llvm_object.emit(pt, .{ |
| 3298 | llvm_object.emit(pt, .{ |
| 3177 | 3299 | .pre_ir_path = comp.verbose_llvm_ir, |
| 3178 | 3300 | .pre_bc_path = comp.verbose_llvm_bc, |
| 3179 | 3301 | |
| ... | ... | @@ -3204,7 +3326,10 @@ fn flush( |
| 3204 | 3326 | .sanitize_thread = comp.config.any_sanitize_thread, |
| 3205 | 3327 | .fuzz = comp.config.any_fuzz, |
| 3206 | 3328 | .lto = comp.config.lto, |
| 3207 | | }); |
| 3329 | }) catch |err| switch (err) { |
| 3330 | error.LinkFailure => {}, // Already reported. |
| 3331 | error.OutOfMemory => return error.OutOfMemory, |
| 3332 | }; |
| 3208 | 3333 | } |
| 3209 | 3334 | } |
| 3210 | 3335 | if (comp.bin_file) |lf| { |
| ... | ... | @@ -3746,7 +3871,7 @@ fn addBuf(list: *std.ArrayList([]const u8), buf: []const u8) void { |
| 3746 | 3871 | } |
| 3747 | 3872 | |
| 3748 | 3873 | /// This function is temporally single-threaded. |
| 3749 | | pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3874 | pub fn getAllErrorsAlloc(comp: *Compilation) error{OutOfMemory}!ErrorBundle { |
| 3750 | 3875 | const gpa = comp.gpa; |
| 3751 | 3876 | |
| 3752 | 3877 | var bundle: ErrorBundle.Wip = undefined; |
| ... | ... | @@ -3796,8 +3921,14 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3796 | 3921 | for (zcu.failed_imports.items) |failed| { |
| 3797 | 3922 | assert(zcu.alive_files.contains(failed.file_index)); // otherwise it wouldn't have been added |
| 3798 | 3923 | const file = zcu.fileByIndex(failed.file_index); |
| 3799 | | const source = try file.getSource(zcu); |
| 3800 | | const tree = try file.getTree(zcu); |
| 3924 | const source = file.getSource(zcu) catch |err| { |
| 3925 | try unableToLoadZcuFile(zcu, &bundle, file, err); |
| 3926 | continue; |
| 3927 | }; |
| 3928 | const tree = file.getTree(zcu) catch |err| { |
| 3929 | try unableToLoadZcuFile(zcu, &bundle, file, err); |
| 3930 | continue; |
| 3931 | }; |
| 3801 | 3932 | const start = tree.tokenStart(failed.import_token); |
| 3802 | 3933 | const end = start + tree.tokenSlice(failed.import_token).len; |
| 3803 | 3934 | const loc = std.zig.findLineColumn(source.bytes, start); |
| ... | ... | @@ -3853,7 +3984,11 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3853 | 3984 | } else { |
| 3854 | 3985 | assert(!is_retryable); |
| 3855 | 3986 | // AstGen/ZoirGen succeeded with errors. Note that this may include AST errors. |
| 3856 | | _ = try file.getTree(zcu); // Tree must be loaded. |
| 3987 | // Tree must be loaded. |
| 3988 | _ = file.getTree(zcu) catch |err| { |
| 3989 | try unableToLoadZcuFile(zcu, &bundle, file, err); |
| 3990 | continue; |
| 3991 | }; |
| 3857 | 3992 | const path = try std.fmt.allocPrint(gpa, "{f}", .{file.path.fmt(comp)}); |
| 3858 | 3993 | defer gpa.free(path); |
| 3859 | 3994 | if (file.zir != null) { |
| ... | ... | @@ -3871,16 +4006,19 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3871 | 4006 | const SortOrder = struct { |
| 3872 | 4007 | zcu: *Zcu, |
| 3873 | 4008 | errors: []const *Zcu.ErrorMsg, |
| 3874 | | err: *?Error, |
| 3875 | | |
| 3876 | | const Error = @typeInfo( |
| 3877 | | @typeInfo(@TypeOf(Zcu.LazySrcLoc.lessThan)).@"fn".return_type.?, |
| 3878 | | ).error_union.error_set; |
| 3879 | | |
| 4009 | read_err: *?ReadError, |
| 4010 | const ReadError = struct { |
| 4011 | file: *Zcu.File, |
| 4012 | err: Zcu.File.GetSourceError, |
| 4013 | }; |
| 3880 | 4014 | pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool { |
| 3881 | | if (ctx.err.* != null) return lhs_index < rhs_index; |
| 3882 | | return ctx.errors[lhs_index].src_loc.lessThan(ctx.errors[rhs_index].src_loc, ctx.zcu) catch |e| { |
| 3883 | | ctx.err.* = e; |
| 4015 | if (ctx.read_err.* != null) return lhs_index < rhs_index; |
| 4016 | var bad_file: *Zcu.File = undefined; |
| 4017 | return ctx.errors[lhs_index].src_loc.lessThan(ctx.errors[rhs_index].src_loc, ctx.zcu, &bad_file) catch |err| { |
| 4018 | ctx.read_err.* = .{ |
| 4019 | .file = bad_file, |
| 4020 | .err = err, |
| 4021 | }; |
| 3884 | 4022 | return lhs_index < rhs_index; |
| 3885 | 4023 | }; |
| 3886 | 4024 | } |
| ... | ... | @@ -3892,13 +4030,16 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3892 | 4030 | var entries = try zcu.failed_analysis.entries.clone(gpa); |
| 3893 | 4031 | errdefer entries.deinit(gpa); |
| 3894 | 4032 | |
| 3895 | | var err: ?SortOrder.Error = null; |
| 4033 | var read_err: ?SortOrder.ReadError = null; |
| 3896 | 4034 | entries.sort(SortOrder{ |
| 3897 | 4035 | .zcu = zcu, |
| 3898 | 4036 | .errors = entries.items(.value), |
| 3899 | | .err = &err, |
| 4037 | .read_err = &read_err, |
| 3900 | 4038 | }); |
| 3901 | | if (err) |e| return e; |
| 4039 | if (read_err) |e| { |
| 4040 | try unableToLoadZcuFile(zcu, &bundle, e.file, e.err); |
| 4041 | break :zcu_errors; |
| 4042 | } |
| 3902 | 4043 | break :s entries.slice(); |
| 3903 | 4044 | }; |
| 3904 | 4045 | defer sorted_failed_analysis.deinit(gpa); |
| ... | ... | @@ -4018,23 +4159,33 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 4018 | 4159 | |
| 4019 | 4160 | // Okay, there *are* referenced compile logs. Sort them into a consistent order. |
| 4020 | 4161 | |
| 4021 | | const SortContext = struct { |
| 4022 | | err: *?Error, |
| 4023 | | zcu: *Zcu, |
| 4024 | | const Error = @typeInfo( |
| 4025 | | @typeInfo(@TypeOf(Zcu.LazySrcLoc.lessThan)).@"fn".return_type.?, |
| 4026 | | ).error_union.error_set; |
| 4027 | | fn lessThan(ctx: @This(), lhs: Zcu.ErrorMsg, rhs: Zcu.ErrorMsg) bool { |
| 4028 | | if (ctx.err.* != null) return false; |
| 4029 | | return lhs.src_loc.lessThan(rhs.src_loc, ctx.zcu) catch |e| { |
| 4030 | | ctx.err.* = e; |
| 4031 | | return false; |
| 4162 | { |
| 4163 | const SortContext = struct { |
| 4164 | zcu: *Zcu, |
| 4165 | read_err: *?ReadError, |
| 4166 | const ReadError = struct { |
| 4167 | file: *Zcu.File, |
| 4168 | err: Zcu.File.GetSourceError, |
| 4032 | 4169 | }; |
| 4170 | fn lessThan(ctx: @This(), lhs: Zcu.ErrorMsg, rhs: Zcu.ErrorMsg) bool { |
| 4171 | if (ctx.read_err.* != null) return false; |
| 4172 | var bad_file: *Zcu.File = undefined; |
| 4173 | return lhs.src_loc.lessThan(rhs.src_loc, ctx.zcu, &bad_file) catch |err| { |
| 4174 | ctx.read_err.* = .{ |
| 4175 | .file = bad_file, |
| 4176 | .err = err, |
| 4177 | }; |
| 4178 | return false; |
| 4179 | }; |
| 4180 | } |
| 4181 | }; |
| 4182 | var read_err: ?SortContext.ReadError = null; |
| 4183 | std.mem.sort(Zcu.ErrorMsg, messages.items, @as(SortContext, .{ .read_err = &read_err, .zcu = zcu }), SortContext.lessThan); |
| 4184 | if (read_err) |e| { |
| 4185 | try unableToLoadZcuFile(zcu, &bundle, e.file, e.err); |
| 4186 | break :compile_log_text ""; |
| 4033 | 4187 | } |
| 4034 | | }; |
| 4035 | | var sort_err: ?SortContext.Error = null; |
| 4036 | | std.mem.sort(Zcu.ErrorMsg, messages.items, @as(SortContext, .{ .err = &sort_err, .zcu = zcu }), SortContext.lessThan); |
| 4037 | | if (sort_err) |e| return e; |
| 4188 | } |
| 4038 | 4189 | |
| 4039 | 4190 | var log_text: std.ArrayListUnmanaged(u8) = .empty; |
| 4040 | 4191 | defer log_text.deinit(gpa); |
| ... | ... | @@ -4068,18 +4219,19 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 4068 | 4219 | // This AU is referenced and has a transitive compile error, meaning it referenced something with a compile error. |
| 4069 | 4220 | // However, we haven't reported any such error. |
| 4070 | 4221 | // This is a compiler bug. |
| 4071 | | var stderr_w = std.debug.lockStderrWriter(&.{}); |
| 4072 | | defer std.debug.unlockStderrWriter(); |
| 4073 | | try stderr_w.writeAll("referenced transitive analysis errors, but none actually emitted\n"); |
| 4074 | | try stderr_w.print("{f} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)}); |
| 4075 | | while (ref) |r| { |
| 4076 | | try stderr_w.print("referenced by: {f}{s}\n", .{ |
| 4077 | | zcu.fmtAnalUnit(r.referencer), |
| 4078 | | if (zcu.transitive_failed_analysis.contains(r.referencer)) " [transitive failure]" else "", |
| 4079 | | }); |
| 4080 | | ref = refs.get(r.referencer).?; |
| 4222 | print_ctx: { |
| 4223 | var stderr_w = std.debug.lockStderrWriter(&.{}); |
| 4224 | defer std.debug.unlockStderrWriter(); |
| 4225 | stderr_w.writeAll("referenced transitive analysis errors, but none actually emitted\n") catch break :print_ctx; |
| 4226 | stderr_w.print("{f} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)}) catch break :print_ctx; |
| 4227 | while (ref) |r| { |
| 4228 | stderr_w.print("referenced by: {f}{s}\n", .{ |
| 4229 | zcu.fmtAnalUnit(r.referencer), |
| 4230 | if (zcu.transitive_failed_analysis.contains(r.referencer)) " [transitive failure]" else "", |
| 4231 | }) catch break :print_ctx; |
| 4232 | ref = refs.get(r.referencer).?; |
| 4233 | } |
| 4081 | 4234 | } |
| 4082 | | |
| 4083 | 4235 | @panic("referenced transitive analysis errors, but none actually emitted"); |
| 4084 | 4236 | } |
| 4085 | 4237 | }; |
| ... | ... | @@ -4166,19 +4318,16 @@ pub fn addModuleErrorMsg( |
| 4166 | 4318 | /// If `-freference-trace` is not specified, we only want to show the one reference trace. |
| 4167 | 4319 | /// So, this is whether we have already emitted an error with a reference trace. |
| 4168 | 4320 | already_added_error: bool, |
| 4169 | | ) !void { |
| 4321 | ) Allocator.Error!void { |
| 4170 | 4322 | const gpa = eb.gpa; |
| 4171 | 4323 | const ip = &zcu.intern_pool; |
| 4172 | 4324 | const err_src_loc = module_err_msg.src_loc.upgrade(zcu); |
| 4173 | 4325 | const err_source = err_src_loc.file_scope.getSource(zcu) catch |err| { |
| 4174 | | try eb.addRootErrorMessage(.{ |
| 4175 | | .msg = try eb.printString("unable to load '{f}': {s}", .{ |
| 4176 | | err_src_loc.file_scope.path.fmt(zcu.comp), @errorName(err), |
| 4177 | | }), |
| 4178 | | }); |
| 4179 | | return; |
| 4326 | return unableToLoadZcuFile(zcu, eb, err_src_loc.file_scope, err); |
| 4327 | }; |
| 4328 | const err_span = err_src_loc.span(zcu) catch |err| { |
| 4329 | return unableToLoadZcuFile(zcu, eb, err_src_loc.file_scope, err); |
| 4180 | 4330 | }; |
| 4181 | | const err_span = try err_src_loc.span(zcu); |
| 4182 | 4331 | const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main); |
| 4183 | 4332 | |
| 4184 | 4333 | var ref_traces: std.ArrayListUnmanaged(ErrorBundle.ReferenceTrace) = .empty; |
| ... | ... | @@ -4208,7 +4357,13 @@ pub fn addModuleErrorMsg( |
| 4208 | 4357 | const f = inline_frame.ptr(zcu).*; |
| 4209 | 4358 | const func_nav = ip.indexToKey(f.callee).func.owner_nav; |
| 4210 | 4359 | const func_name = ip.getNav(func_nav).name.toSlice(ip); |
| 4211 | | try addReferenceTraceFrame(zcu, eb, &ref_traces, func_name, last_call_src, true); |
| 4360 | addReferenceTraceFrame(zcu, eb, &ref_traces, func_name, last_call_src, true) catch |err| switch (err) { |
| 4361 | error.OutOfMemory => |e| return e, |
| 4362 | error.AlreadyReported => { |
| 4363 | // An incomplete reference trace isn't the end of the world; just cut it off. |
| 4364 | break :rt; |
| 4365 | }, |
| 4366 | }; |
| 4212 | 4367 | last_call_src = f.call_src; |
| 4213 | 4368 | opt_inline_frame = f.parent; |
| 4214 | 4369 | } |
| ... | ... | @@ -4220,7 +4375,13 @@ pub fn addModuleErrorMsg( |
| 4220 | 4375 | .memoized_state => null, |
| 4221 | 4376 | }; |
| 4222 | 4377 | if (root_name) |n| { |
| 4223 | | try addReferenceTraceFrame(zcu, eb, &ref_traces, n, last_call_src, false); |
| 4378 | addReferenceTraceFrame(zcu, eb, &ref_traces, n, last_call_src, false) catch |err| switch (err) { |
| 4379 | error.OutOfMemory => |e| return e, |
| 4380 | error.AlreadyReported => { |
| 4381 | // An incomplete reference trace isn't the end of the world; just cut it off. |
| 4382 | break :rt; |
| 4383 | }, |
| 4384 | }; |
| 4224 | 4385 | } |
| 4225 | 4386 | } |
| 4226 | 4387 | referenced_by = ref.referencer; |
| ... | ... | @@ -4257,8 +4418,12 @@ pub fn addModuleErrorMsg( |
| 4257 | 4418 | var last_note_loc: ?std.zig.Loc = null; |
| 4258 | 4419 | for (module_err_msg.notes) |module_note| { |
| 4259 | 4420 | const note_src_loc = module_note.src_loc.upgrade(zcu); |
| 4260 | | const source = try note_src_loc.file_scope.getSource(zcu); |
| 4261 | | const span = try note_src_loc.span(zcu); |
| 4421 | const source = note_src_loc.file_scope.getSource(zcu) catch |err| { |
| 4422 | return unableToLoadZcuFile(zcu, eb, note_src_loc.file_scope, err); |
| 4423 | }; |
| 4424 | const span = note_src_loc.span(zcu) catch |err| { |
| 4425 | return unableToLoadZcuFile(zcu, eb, note_src_loc.file_scope, err); |
| 4426 | }; |
| 4262 | 4427 | const loc = std.zig.findLineColumn(source.bytes, span.main); |
| 4263 | 4428 | |
| 4264 | 4429 | const omit_source_line = loc.eql(err_loc) or (last_note_loc != null and loc.eql(last_note_loc.?)); |
| ... | ... | @@ -4303,11 +4468,17 @@ fn addReferenceTraceFrame( |
| 4303 | 4468 | name: []const u8, |
| 4304 | 4469 | lazy_src: Zcu.LazySrcLoc, |
| 4305 | 4470 | inlined: bool, |
| 4306 | | ) !void { |
| 4471 | ) error{ OutOfMemory, AlreadyReported }!void { |
| 4307 | 4472 | const gpa = zcu.gpa; |
| 4308 | 4473 | const src = lazy_src.upgrade(zcu); |
| 4309 | | const source = try src.file_scope.getSource(zcu); |
| 4310 | | const span = try src.span(zcu); |
| 4474 | const source = src.file_scope.getSource(zcu) catch |err| { |
| 4475 | try unableToLoadZcuFile(zcu, eb, src.file_scope, err); |
| 4476 | return error.AlreadyReported; |
| 4477 | }; |
| 4478 | const span = src.span(zcu) catch |err| { |
| 4479 | try unableToLoadZcuFile(zcu, eb, src.file_scope, err); |
| 4480 | return error.AlreadyReported; |
| 4481 | }; |
| 4311 | 4482 | const loc = std.zig.findLineColumn(source.bytes, span.main); |
| 4312 | 4483 | try ref_traces.append(gpa, .{ |
| 4313 | 4484 | .decl_name = try eb.printString("{s}{s}", .{ name, if (inlined) " [inlined]" else "" }), |
| ... | ... | @@ -4323,19 +4494,26 @@ fn addReferenceTraceFrame( |
| 4323 | 4494 | }); |
| 4324 | 4495 | } |
| 4325 | 4496 | |
| 4326 | | pub fn addWholeFileError( |
| 4497 | fn addWholeFileError( |
| 4327 | 4498 | zcu: *Zcu, |
| 4328 | 4499 | eb: *ErrorBundle.Wip, |
| 4329 | 4500 | file_index: Zcu.File.Index, |
| 4330 | 4501 | msg: []const u8, |
| 4331 | | ) !void { |
| 4502 | ) Allocator.Error!void { |
| 4332 | 4503 | // note: "file imported here" on the import reference token |
| 4333 | 4504 | const imported_note: ?ErrorBundle.MessageIndex = switch (zcu.alive_files.get(file_index).?) { |
| 4334 | 4505 | .analysis_root => null, |
| 4335 | | .import => |import| try eb.addErrorMessage(.{ |
| 4336 | | .msg = try eb.addString("file imported here"), |
| 4337 | | .src_loc = try zcu.fileByIndex(import.importer).errorBundleTokenSrc(import.tok, zcu, eb), |
| 4338 | | }), |
| 4506 | .import => |import| note: { |
| 4507 | const file = zcu.fileByIndex(import.importer); |
| 4508 | // `errorBundleTokenSrc` expects the tree to be loaded |
| 4509 | _ = file.getTree(zcu) catch |err| { |
| 4510 | return unableToLoadZcuFile(zcu, eb, file, err); |
| 4511 | }; |
| 4512 | break :note try eb.addErrorMessage(.{ |
| 4513 | .msg = try eb.addString("file imported here"), |
| 4514 | .src_loc = try file.errorBundleTokenSrc(import.tok, zcu, eb), |
| 4515 | }); |
| 4516 | }, |
| 4339 | 4517 | }; |
| 4340 | 4518 | |
| 4341 | 4519 | try eb.addRootErrorMessage(.{ |
| ... | ... | @@ -4349,6 +4527,20 @@ pub fn addWholeFileError( |
| 4349 | 4527 | } |
| 4350 | 4528 | } |
| 4351 | 4529 | |
| 4530 | /// Adds an error to `eb` that the contents of `file` could not be loaded due to `err`. This is |
| 4531 | /// useful if `Zcu.File.getSource`/`Zcu.File.getTree` fails while lowering compile errors. |
| 4532 | pub fn unableToLoadZcuFile( |
| 4533 | zcu: *const Zcu, |
| 4534 | eb: *ErrorBundle.Wip, |
| 4535 | file: *Zcu.File, |
| 4536 | err: Zcu.File.GetSourceError, |
| 4537 | ) Allocator.Error!void { |
| 4538 | try eb.addRootErrorMessage(.{ |
| 4539 | .msg = try eb.printString("unable to load: {t}", .{err}), |
| 4540 | .src_loc = try file.errorBundleWholeFileSrc(zcu, eb), |
| 4541 | }); |
| 4542 | } |
| 4543 | |
| 4352 | 4544 | fn performAllTheWork( |
| 4353 | 4545 | comp: *Compilation, |
| 4354 | 4546 | main_progress_node: std.Progress.Node, |
| ... | ... | @@ -5002,18 +5194,15 @@ pub fn separateCodegenThreadOk(comp: *const Compilation) bool { |
| 5002 | 5194 | } |
| 5003 | 5195 | |
| 5004 | 5196 | fn workerDocsCopy(comp: *Compilation) void { |
| 5005 | | docsCopyFallible(comp) catch |err| { |
| 5006 | | return comp.lockAndSetMiscFailure( |
| 5007 | | .docs_copy, |
| 5008 | | "unable to copy autodocs artifacts: {s}", |
| 5009 | | .{@errorName(err)}, |
| 5010 | | ); |
| 5011 | | }; |
| 5197 | docsCopyFallible(comp) catch |err| return comp.lockAndSetMiscFailure( |
| 5198 | .docs_copy, |
| 5199 | "unable to copy autodocs artifacts: {s}", |
| 5200 | .{@errorName(err)}, |
| 5201 | ); |
| 5012 | 5202 | } |
| 5013 | 5203 | |
| 5014 | 5204 | fn docsCopyFallible(comp: *Compilation) anyerror!void { |
| 5015 | | const zcu = comp.zcu orelse |
| 5016 | | return comp.lockAndSetMiscFailure(.docs_copy, "no Zig code to document", .{}); |
| 5205 | const zcu = comp.zcu orelse return comp.lockAndSetMiscFailure(.docs_copy, "no Zig code to document", .{}); |
| 5017 | 5206 | |
| 5018 | 5207 | const docs_path = comp.resolveEmitPath(comp.emit_docs.?); |
| 5019 | 5208 | var out_dir = docs_path.root_dir.handle.makeOpenPath(docs_path.sub_path, .{}) catch |err| { |
| ... | ... | @@ -5127,12 +5316,12 @@ fn workerDocsWasm(comp: *Compilation, parent_prog_node: std.Progress.Node) void |
| 5127 | 5316 | defer prog_node.end(); |
| 5128 | 5317 | |
| 5129 | 5318 | workerDocsWasmFallible(comp, prog_node) catch |err| switch (err) { |
| 5130 | | error.SubCompilationFailed => return, // error reported already |
| 5319 | error.AlreadyReported => return, |
| 5131 | 5320 | else => comp.lockAndSetMiscFailure(.docs_wasm, "unable to build autodocs: {t}", .{err}), |
| 5132 | 5321 | }; |
| 5133 | 5322 | } |
| 5134 | 5323 | |
| 5135 | | fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anyerror!void { |
| 5324 | fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubUpdateError!void { |
| 5136 | 5325 | const gpa = comp.gpa; |
| 5137 | 5326 | |
| 5138 | 5327 | var arena_allocator = std.heap.ArenaAllocator.init(gpa); |
| ... | ... | @@ -5162,7 +5351,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 5162 | 5351 | .is_explicit_dynamic_linker = false, |
| 5163 | 5352 | }; |
| 5164 | 5353 | |
| 5165 | | const config = try Config.resolve(.{ |
| 5354 | const config = Config.resolve(.{ |
| 5166 | 5355 | .output_mode = output_mode, |
| 5167 | 5356 | .resolved_target = resolved_target, |
| 5168 | 5357 | .is_test = false, |
| ... | ... | @@ -5171,14 +5360,17 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 5171 | 5360 | .root_optimize_mode = optimize_mode, |
| 5172 | 5361 | .link_libc = false, |
| 5173 | 5362 | .rdynamic = true, |
| 5174 | | }); |
| 5363 | }) catch |err| { |
| 5364 | comp.lockAndSetMiscFailure(.docs_wasm, "sub-compilation of docs_wasm failed: failed to resolve compilation config: {t}", .{err}); |
| 5365 | return error.AlreadyReported; |
| 5366 | }; |
| 5175 | 5367 | |
| 5176 | 5368 | const src_basename = "main.zig"; |
| 5177 | 5369 | const root_name = fs.path.stem(src_basename); |
| 5178 | 5370 | |
| 5179 | 5371 | const dirs = comp.dirs.withoutLocalCache(); |
| 5180 | 5372 | |
| 5181 | | const root_mod = try Package.Module.create(arena, .{ |
| 5373 | const root_mod = Package.Module.create(arena, .{ |
| 5182 | 5374 | .paths = .{ |
| 5183 | 5375 | .root = try .fromRoot(arena, dirs, .zig_lib, "docs/wasm"), |
| 5184 | 5376 | .root_src_path = src_basename, |
| ... | ... | @@ -5191,8 +5383,11 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 5191 | 5383 | .global = config, |
| 5192 | 5384 | .cc_argv = &.{}, |
| 5193 | 5385 | .parent = null, |
| 5194 | | }); |
| 5195 | | const walk_mod = try Package.Module.create(arena, .{ |
| 5386 | }) catch |err| { |
| 5387 | comp.lockAndSetMiscFailure(.docs_wasm, "sub-compilation of docs_wasm failed: failed to create root module: {t}", .{err}); |
| 5388 | return error.AlreadyReported; |
| 5389 | }; |
| 5390 | const walk_mod = Package.Module.create(arena, .{ |
| 5196 | 5391 | .paths = .{ |
| 5197 | 5392 | .root = try .fromRoot(arena, dirs, .zig_lib, "docs/wasm"), |
| 5198 | 5393 | .root_src_path = "Walk.zig", |
| ... | ... | @@ -5205,10 +5400,14 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 5205 | 5400 | .global = config, |
| 5206 | 5401 | .cc_argv = &.{}, |
| 5207 | 5402 | .parent = root_mod, |
| 5208 | | }); |
| 5403 | }) catch |err| { |
| 5404 | comp.lockAndSetMiscFailure(.docs_wasm, "sub-compilation of docs_wasm failed: failed to create 'Walk' module: {t}", .{err}); |
| 5405 | return error.AlreadyReported; |
| 5406 | }; |
| 5209 | 5407 | try root_mod.deps.put(arena, "Walk", walk_mod); |
| 5210 | 5408 | |
| 5211 | | const sub_compilation = try Compilation.create(gpa, arena, .{ |
| 5409 | var sub_create_diag: CreateDiagnostic = undefined; |
| 5410 | const sub_compilation = Compilation.create(gpa, arena, &sub_create_diag, .{ |
| 5212 | 5411 | .dirs = dirs, |
| 5213 | 5412 | .self_exe_path = comp.self_exe_path, |
| 5214 | 5413 | .config = config, |
| ... | ... | @@ -5228,7 +5427,13 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 5228 | 5427 | .verbose_llvm_bc = comp.verbose_llvm_bc, |
| 5229 | 5428 | .verbose_cimport = comp.verbose_cimport, |
| 5230 | 5429 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 5231 | | }); |
| 5430 | }) catch |err| switch (err) { |
| 5431 | error.CreateFail => { |
| 5432 | comp.lockAndSetMiscFailure(.docs_wasm, "sub-compilation of docs_wasm failed: {f}", .{sub_create_diag}); |
| 5433 | return error.AlreadyReported; |
| 5434 | }, |
| 5435 | else => |e| return e, |
| 5436 | }; |
| 5232 | 5437 | defer sub_compilation.destroy(); |
| 5233 | 5438 | |
| 5234 | 5439 | try comp.updateSubCompilation(sub_compilation, .docs_wasm, prog_node); |
| ... | ... | @@ -5241,11 +5446,12 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 5241 | 5446 | |
| 5242 | 5447 | const docs_path = comp.resolveEmitPath(comp.emit_docs.?); |
| 5243 | 5448 | var out_dir = docs_path.root_dir.handle.makeOpenPath(docs_path.sub_path, .{}) catch |err| { |
| 5244 | | return comp.lockAndSetMiscFailure( |
| 5449 | comp.lockAndSetMiscFailure( |
| 5245 | 5450 | .docs_copy, |
| 5246 | | "unable to create output directory '{f}': {s}", |
| 5247 | | .{ docs_path, @errorName(err) }, |
| 5451 | "unable to create output directory '{f}': {t}", |
| 5452 | .{ docs_path, err }, |
| 5248 | 5453 | ); |
| 5454 | return error.AlreadyReported; |
| 5249 | 5455 | }; |
| 5250 | 5456 | defer out_dir.close(); |
| 5251 | 5457 | |
| ... | ... | @@ -5255,9 +5461,10 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 5255 | 5461 | "main.wasm", |
| 5256 | 5462 | .{}, |
| 5257 | 5463 | ) catch |err| { |
| 5258 | | return comp.lockAndSetMiscFailure(.docs_copy, "unable to copy '{f}' to '{f}': {s}", .{ |
| 5259 | | crt_file.full_object_path, docs_path, @errorName(err), |
| 5464 | comp.lockAndSetMiscFailure(.docs_copy, "unable to copy '{f}' to '{f}': {t}", .{ |
| 5465 | crt_file.full_object_path, docs_path, err, |
| 5260 | 5466 | }); |
| 5467 | return error.AlreadyReported; |
| 5261 | 5468 | }; |
| 5262 | 5469 | } |
| 5263 | 5470 | |
| ... | ... | @@ -5324,15 +5531,11 @@ fn workerUpdateFile( |
| 5324 | 5531 | } |
| 5325 | 5532 | |
| 5326 | 5533 | fn workerUpdateBuiltinFile(comp: *Compilation, file: *Zcu.File) void { |
| 5327 | | Builtin.updateFileOnDisk(file, comp) catch |err| { |
| 5328 | | comp.mutex.lock(); |
| 5329 | | defer comp.mutex.unlock(); |
| 5330 | | comp.setMiscFailure( |
| 5331 | | .write_builtin_zig, |
| 5332 | | "unable to write '{f}': {s}", |
| 5333 | | .{ file.path.fmt(comp), @errorName(err) }, |
| 5334 | | ); |
| 5335 | | }; |
| 5534 | Builtin.updateFileOnDisk(file, comp) catch |err| comp.lockAndSetMiscFailure( |
| 5535 | .write_builtin_zig, |
| 5536 | "unable to write '{f}': {s}", |
| 5537 | .{ file.path.fmt(comp), @errorName(err) }, |
| 5538 | ); |
| 5336 | 5539 | } |
| 5337 | 5540 | |
| 5338 | 5541 | fn workerUpdateEmbedFile(tid: usize, comp: *Compilation, ef_index: Zcu.EmbedFile.Index, ef: *Zcu.EmbedFile) void { |
| ... | ... | @@ -5632,7 +5835,7 @@ fn buildRt( |
| 5632 | 5835 | options, |
| 5633 | 5836 | out, |
| 5634 | 5837 | ) catch |err| switch (err) { |
| 5635 | | error.SubCompilationFailed => return, // error reported already |
| 5838 | error.AlreadyReported => return, |
| 5636 | 5839 | else => comp.lockAndSetMiscFailure(misc_task, "unable to build {s}: {s}", .{ |
| 5637 | 5840 | @tagName(misc_task), @errorName(err), |
| 5638 | 5841 | }), |
| ... | ... | @@ -5644,7 +5847,7 @@ fn buildMuslCrtFile(comp: *Compilation, crt_file: musl.CrtFile, prog_node: std.P |
| 5644 | 5847 | if (musl.buildCrtFile(comp, crt_file, prog_node)) |_| { |
| 5645 | 5848 | comp.queued_jobs.musl_crt_file[@intFromEnum(crt_file)] = false; |
| 5646 | 5849 | } else |err| switch (err) { |
| 5647 | | error.SubCompilationFailed => return, // error reported already |
| 5850 | error.AlreadyReported => return, |
| 5648 | 5851 | else => comp.lockAndSetMiscFailure(.musl_crt_file, "unable to build musl {s}: {s}", .{ |
| 5649 | 5852 | @tagName(crt_file), @errorName(err), |
| 5650 | 5853 | }), |
| ... | ... | @@ -5656,7 +5859,7 @@ fn buildGlibcCrtFile(comp: *Compilation, crt_file: glibc.CrtFile, prog_node: std |
| 5656 | 5859 | if (glibc.buildCrtFile(comp, crt_file, prog_node)) |_| { |
| 5657 | 5860 | comp.queued_jobs.glibc_crt_file[@intFromEnum(crt_file)] = false; |
| 5658 | 5861 | } else |err| switch (err) { |
| 5659 | | error.SubCompilationFailed => return, // error reported already |
| 5862 | error.AlreadyReported => return, |
| 5660 | 5863 | else => comp.lockAndSetMiscFailure(.glibc_crt_file, "unable to build glibc {s}: {s}", .{ |
| 5661 | 5864 | @tagName(crt_file), @errorName(err), |
| 5662 | 5865 | }), |
| ... | ... | @@ -5669,7 +5872,7 @@ fn buildGlibcSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) voi |
| 5669 | 5872 | // The job should no longer be queued up since it succeeded. |
| 5670 | 5873 | comp.queued_jobs.glibc_shared_objects = false; |
| 5671 | 5874 | } else |err| switch (err) { |
| 5672 | | error.SubCompilationFailed => return, // error reported already |
| 5875 | error.AlreadyReported => return, |
| 5673 | 5876 | else => comp.lockAndSetMiscFailure(.glibc_shared_objects, "unable to build glibc shared objects: {s}", .{ |
| 5674 | 5877 | @errorName(err), |
| 5675 | 5878 | }), |
| ... | ... | @@ -5681,7 +5884,7 @@ fn buildFreeBSDCrtFile(comp: *Compilation, crt_file: freebsd.CrtFile, prog_node: |
| 5681 | 5884 | if (freebsd.buildCrtFile(comp, crt_file, prog_node)) |_| { |
| 5682 | 5885 | comp.queued_jobs.freebsd_crt_file[@intFromEnum(crt_file)] = false; |
| 5683 | 5886 | } else |err| switch (err) { |
| 5684 | | error.SubCompilationFailed => return, // error reported already |
| 5887 | error.AlreadyReported => return, |
| 5685 | 5888 | else => comp.lockAndSetMiscFailure(.freebsd_crt_file, "unable to build FreeBSD {s}: {s}", .{ |
| 5686 | 5889 | @tagName(crt_file), @errorName(err), |
| 5687 | 5890 | }), |
| ... | ... | @@ -5694,7 +5897,7 @@ fn buildFreeBSDSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) v |
| 5694 | 5897 | // The job should no longer be queued up since it succeeded. |
| 5695 | 5898 | comp.queued_jobs.freebsd_shared_objects = false; |
| 5696 | 5899 | } else |err| switch (err) { |
| 5697 | | error.SubCompilationFailed => return, // error reported already |
| 5900 | error.AlreadyReported => return, |
| 5698 | 5901 | else => comp.lockAndSetMiscFailure(.freebsd_shared_objects, "unable to build FreeBSD libc shared objects: {s}", .{ |
| 5699 | 5902 | @errorName(err), |
| 5700 | 5903 | }), |
| ... | ... | @@ -5706,7 +5909,7 @@ fn buildNetBSDCrtFile(comp: *Compilation, crt_file: netbsd.CrtFile, prog_node: s |
| 5706 | 5909 | if (netbsd.buildCrtFile(comp, crt_file, prog_node)) |_| { |
| 5707 | 5910 | comp.queued_jobs.netbsd_crt_file[@intFromEnum(crt_file)] = false; |
| 5708 | 5911 | } else |err| switch (err) { |
| 5709 | | error.SubCompilationFailed => return, // error reported already |
| 5912 | error.AlreadyReported => return, |
| 5710 | 5913 | else => comp.lockAndSetMiscFailure(.netbsd_crt_file, "unable to build NetBSD {s}: {s}", .{ |
| 5711 | 5914 | @tagName(crt_file), @errorName(err), |
| 5712 | 5915 | }), |
| ... | ... | @@ -5719,7 +5922,7 @@ fn buildNetBSDSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) vo |
| 5719 | 5922 | // The job should no longer be queued up since it succeeded. |
| 5720 | 5923 | comp.queued_jobs.netbsd_shared_objects = false; |
| 5721 | 5924 | } else |err| switch (err) { |
| 5722 | | error.SubCompilationFailed => return, // error reported already |
| 5925 | error.AlreadyReported => return, |
| 5723 | 5926 | else => comp.lockAndSetMiscFailure(.netbsd_shared_objects, "unable to build NetBSD libc shared objects: {s}", .{ |
| 5724 | 5927 | @errorName(err), |
| 5725 | 5928 | }), |
| ... | ... | @@ -5731,7 +5934,7 @@ fn buildMingwCrtFile(comp: *Compilation, crt_file: mingw.CrtFile, prog_node: std |
| 5731 | 5934 | if (mingw.buildCrtFile(comp, crt_file, prog_node)) |_| { |
| 5732 | 5935 | comp.queued_jobs.mingw_crt_file[@intFromEnum(crt_file)] = false; |
| 5733 | 5936 | } else |err| switch (err) { |
| 5734 | | error.SubCompilationFailed => return, // error reported already |
| 5937 | error.AlreadyReported => return, |
| 5735 | 5938 | else => comp.lockAndSetMiscFailure(.mingw_crt_file, "unable to build mingw-w64 {s}: {s}", .{ |
| 5736 | 5939 | @tagName(crt_file), @errorName(err), |
| 5737 | 5940 | }), |
| ... | ... | @@ -5743,7 +5946,7 @@ fn buildWasiLibcCrtFile(comp: *Compilation, crt_file: wasi_libc.CrtFile, prog_no |
| 5743 | 5946 | if (wasi_libc.buildCrtFile(comp, crt_file, prog_node)) |_| { |
| 5744 | 5947 | comp.queued_jobs.wasi_libc_crt_file[@intFromEnum(crt_file)] = false; |
| 5745 | 5948 | } else |err| switch (err) { |
| 5746 | | error.SubCompilationFailed => return, // error reported already |
| 5949 | error.AlreadyReported => return, |
| 5747 | 5950 | else => comp.lockAndSetMiscFailure(.wasi_libc_crt_file, "unable to build WASI libc {s}: {s}", .{ |
| 5748 | 5951 | @tagName(crt_file), @errorName(err), |
| 5749 | 5952 | }), |
| ... | ... | @@ -5755,7 +5958,7 @@ fn buildLibUnwind(comp: *Compilation, prog_node: std.Progress.Node) void { |
| 5755 | 5958 | if (libunwind.buildStaticLib(comp, prog_node)) |_| { |
| 5756 | 5959 | comp.queued_jobs.libunwind = false; |
| 5757 | 5960 | } else |err| switch (err) { |
| 5758 | | error.SubCompilationFailed => return, // error reported already |
| 5961 | error.AlreadyReported => return, |
| 5759 | 5962 | else => comp.lockAndSetMiscFailure(.libunwind, "unable to build libunwind: {s}", .{@errorName(err)}), |
| 5760 | 5963 | } |
| 5761 | 5964 | } |
| ... | ... | @@ -5765,7 +5968,7 @@ fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) void { |
| 5765 | 5968 | if (libcxx.buildLibCxx(comp, prog_node)) |_| { |
| 5766 | 5969 | comp.queued_jobs.libcxx = false; |
| 5767 | 5970 | } else |err| switch (err) { |
| 5768 | | error.SubCompilationFailed => return, // error reported already |
| 5971 | error.AlreadyReported => return, |
| 5769 | 5972 | else => comp.lockAndSetMiscFailure(.libcxx, "unable to build libcxx: {s}", .{@errorName(err)}), |
| 5770 | 5973 | } |
| 5771 | 5974 | } |
| ... | ... | @@ -5775,7 +5978,7 @@ fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) void { |
| 5775 | 5978 | if (libcxx.buildLibCxxAbi(comp, prog_node)) |_| { |
| 5776 | 5979 | comp.queued_jobs.libcxxabi = false; |
| 5777 | 5980 | } else |err| switch (err) { |
| 5778 | | error.SubCompilationFailed => return, // error reported already |
| 5981 | error.AlreadyReported => return, |
| 5779 | 5982 | else => comp.lockAndSetMiscFailure(.libcxxabi, "unable to build libcxxabi: {s}", .{@errorName(err)}), |
| 5780 | 5983 | } |
| 5781 | 5984 | } |
| ... | ... | @@ -5785,7 +5988,7 @@ fn buildLibTsan(comp: *Compilation, prog_node: std.Progress.Node) void { |
| 5785 | 5988 | if (libtsan.buildTsan(comp, prog_node)) |_| { |
| 5786 | 5989 | comp.queued_jobs.libtsan = false; |
| 5787 | 5990 | } else |err| switch (err) { |
| 5788 | | error.SubCompilationFailed => return, // error reported already |
| 5991 | error.AlreadyReported => return, |
| 5789 | 5992 | else => comp.lockAndSetMiscFailure(.libtsan, "unable to build TSAN library: {s}", .{@errorName(err)}), |
| 5790 | 5993 | } |
| 5791 | 5994 | } |
| ... | ... | @@ -5802,7 +6005,7 @@ fn buildLibZigC(comp: *Compilation, prog_node: std.Progress.Node) void { |
| 5802 | 6005 | .{}, |
| 5803 | 6006 | &comp.zigc_static_lib, |
| 5804 | 6007 | ) catch |err| switch (err) { |
| 5805 | | error.SubCompilationFailed => return, // error reported already |
| 6008 | error.AlreadyReported => return, |
| 5806 | 6009 | else => comp.lockAndSetMiscFailure(.libzigc, "unable to build libzigc: {s}", .{@errorName(err)}), |
| 5807 | 6010 | }; |
| 5808 | 6011 | } |
| ... | ... | @@ -7439,12 +7642,13 @@ pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend { |
| 7439 | 7642 | return target_util.zigBackend(target, comp.config.use_llvm); |
| 7440 | 7643 | } |
| 7441 | 7644 | |
| 7645 | pub const SubUpdateError = UpdateError || error{AlreadyReported}; |
| 7442 | 7646 | pub fn updateSubCompilation( |
| 7443 | 7647 | parent_comp: *Compilation, |
| 7444 | 7648 | sub_comp: *Compilation, |
| 7445 | 7649 | misc_task: MiscTask, |
| 7446 | 7650 | prog_node: std.Progress.Node, |
| 7447 | | ) !void { |
| 7651 | ) SubUpdateError!void { |
| 7448 | 7652 | { |
| 7449 | 7653 | const sub_node = prog_node.start(@tagName(misc_task), 0); |
| 7450 | 7654 | defer sub_node.end(); |
| ... | ... | @@ -7454,20 +7658,20 @@ pub fn updateSubCompilation( |
| 7454 | 7658 | |
| 7455 | 7659 | // Look for compilation errors in this sub compilation |
| 7456 | 7660 | const gpa = parent_comp.gpa; |
| 7457 | | var keep_errors = false; |
| 7661 | |
| 7458 | 7662 | var errors = try sub_comp.getAllErrorsAlloc(); |
| 7459 | | defer if (!keep_errors) errors.deinit(gpa); |
| 7663 | defer errors.deinit(gpa); |
| 7460 | 7664 | |
| 7461 | 7665 | if (errors.errorMessageCount() > 0) { |
| 7666 | parent_comp.mutex.lock(); |
| 7667 | defer parent_comp.mutex.unlock(); |
| 7462 | 7668 | try parent_comp.misc_failures.ensureUnusedCapacity(gpa, 1); |
| 7463 | 7669 | parent_comp.misc_failures.putAssumeCapacityNoClobber(misc_task, .{ |
| 7464 | | .msg = try std.fmt.allocPrint(gpa, "sub-compilation of {s} failed", .{ |
| 7465 | | @tagName(misc_task), |
| 7466 | | }), |
| 7670 | .msg = try std.fmt.allocPrint(gpa, "sub-compilation of {t} failed", .{misc_task}), |
| 7467 | 7671 | .children = errors, |
| 7468 | 7672 | }); |
| 7469 | | keep_errors = true; |
| 7470 | | return error.SubCompilationFailed; |
| 7673 | errors = .empty; // ownership moved to the failures map |
| 7674 | return error.AlreadyReported; |
| 7471 | 7675 | } |
| 7472 | 7676 | } |
| 7473 | 7677 | |
| ... | ... | @@ -7481,7 +7685,7 @@ fn buildOutputFromZig( |
| 7481 | 7685 | prog_node: std.Progress.Node, |
| 7482 | 7686 | options: RtOptions, |
| 7483 | 7687 | out: *?CrtFile, |
| 7484 | | ) !void { |
| 7688 | ) SubUpdateError!void { |
| 7485 | 7689 | const tracy_trace = trace(@src()); |
| 7486 | 7690 | defer tracy_trace.end(); |
| 7487 | 7691 | |
| ... | ... | @@ -7495,7 +7699,7 @@ fn buildOutputFromZig( |
| 7495 | 7699 | const strip = comp.compilerRtStrip(); |
| 7496 | 7700 | const optimize_mode = comp.compilerRtOptMode(); |
| 7497 | 7701 | |
| 7498 | | const config = try Config.resolve(.{ |
| 7702 | const config = Config.resolve(.{ |
| 7499 | 7703 | .output_mode = output_mode, |
| 7500 | 7704 | .link_mode = link_mode, |
| 7501 | 7705 | .resolved_target = comp.root_mod.resolved_target, |
| ... | ... | @@ -7509,9 +7713,12 @@ fn buildOutputFromZig( |
| 7509 | 7713 | .any_error_tracing = false, |
| 7510 | 7714 | .root_error_tracing = false, |
| 7511 | 7715 | .lto = if (options.allow_lto) comp.config.lto else .none, |
| 7512 | | }); |
| 7716 | }) catch |err| { |
| 7717 | comp.lockAndSetMiscFailure(misc_task_tag, "sub-compilation of {t} failed: failed to resolve compilation config: {t}", .{ misc_task_tag, err }); |
| 7718 | return error.AlreadyReported; |
| 7719 | }; |
| 7513 | 7720 | |
| 7514 | | const root_mod = try Package.Module.create(arena, .{ |
| 7721 | const root_mod = Package.Module.create(arena, .{ |
| 7515 | 7722 | .paths = .{ |
| 7516 | 7723 | .root = .zig_lib_root, |
| 7517 | 7724 | .root_src_path = src_basename, |
| ... | ... | @@ -7536,7 +7743,10 @@ fn buildOutputFromZig( |
| 7536 | 7743 | .global = config, |
| 7537 | 7744 | .cc_argv = &.{}, |
| 7538 | 7745 | .parent = null, |
| 7539 | | }); |
| 7746 | }) catch |err| { |
| 7747 | comp.lockAndSetMiscFailure(misc_task_tag, "sub-compilation of {t} failed: failed to create module: {t}", .{ misc_task_tag, err }); |
| 7748 | return error.AlreadyReported; |
| 7749 | }; |
| 7540 | 7750 | |
| 7541 | 7751 | const parent_whole_cache: ?ParentWholeCache = switch (comp.cache_use) { |
| 7542 | 7752 | .whole => |whole| .{ |
| ... | ... | @@ -7552,7 +7762,8 @@ fn buildOutputFromZig( |
| 7552 | 7762 | .incremental, .none => null, |
| 7553 | 7763 | }; |
| 7554 | 7764 | |
| 7555 | | const sub_compilation = try Compilation.create(gpa, arena, .{ |
| 7765 | var sub_create_diag: CreateDiagnostic = undefined; |
| 7766 | const sub_compilation = Compilation.create(gpa, arena, &sub_create_diag, .{ |
| 7556 | 7767 | .dirs = comp.dirs.withoutLocalCache(), |
| 7557 | 7768 | .cache_mode = .whole, |
| 7558 | 7769 | .parent_whole_cache = parent_whole_cache, |
| ... | ... | @@ -7576,7 +7787,13 @@ fn buildOutputFromZig( |
| 7576 | 7787 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 7577 | 7788 | .clang_passthrough_mode = comp.clang_passthrough_mode, |
| 7578 | 7789 | .skip_linker_dependencies = true, |
| 7579 | | }); |
| 7790 | }) catch |err| switch (err) { |
| 7791 | error.CreateFail => { |
| 7792 | comp.lockAndSetMiscFailure(misc_task_tag, "sub-compilation of {t} failed: {f}", .{ misc_task_tag, sub_create_diag }); |
| 7793 | return error.AlreadyReported; |
| 7794 | }, |
| 7795 | else => |e| return e, |
| 7796 | }; |
| 7580 | 7797 | defer sub_compilation.destroy(); |
| 7581 | 7798 | |
| 7582 | 7799 | try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node); |
| ... | ... | @@ -7609,7 +7826,7 @@ pub fn build_crt_file( |
| 7609 | 7826 | /// created within this function. |
| 7610 | 7827 | c_source_files: []CSourceFile, |
| 7611 | 7828 | options: CrtFileOptions, |
| 7612 | | ) !void { |
| 7829 | ) SubUpdateError!void { |
| 7613 | 7830 | const tracy_trace = trace(@src()); |
| 7614 | 7831 | defer tracy_trace.end(); |
| 7615 | 7832 | |
| ... | ... | @@ -7624,7 +7841,7 @@ pub fn build_crt_file( |
| 7624 | 7841 | .output_mode = output_mode, |
| 7625 | 7842 | }); |
| 7626 | 7843 | |
| 7627 | | const config = try Config.resolve(.{ |
| 7844 | const config = Config.resolve(.{ |
| 7628 | 7845 | .output_mode = output_mode, |
| 7629 | 7846 | .resolved_target = comp.root_mod.resolved_target, |
| 7630 | 7847 | .is_test = false, |
| ... | ... | @@ -7638,8 +7855,11 @@ pub fn build_crt_file( |
| 7638 | 7855 | .Lib => if (options.allow_lto) comp.config.lto else .none, |
| 7639 | 7856 | .Obj, .Exe => .none, |
| 7640 | 7857 | }, |
| 7641 | | }); |
| 7642 | | const root_mod = try Package.Module.create(arena, .{ |
| 7858 | }) catch |err| { |
| 7859 | comp.lockAndSetMiscFailure(misc_task_tag, "sub-compilation of {t} failed: failed to resolve compilation config: {t}", .{ misc_task_tag, err }); |
| 7860 | return error.AlreadyReported; |
| 7861 | }; |
| 7862 | const root_mod = Package.Module.create(arena, .{ |
| 7643 | 7863 | .paths = .{ |
| 7644 | 7864 | .root = .zig_lib_root, |
| 7645 | 7865 | .root_src_path = "", |
| ... | ... | @@ -7669,13 +7889,17 @@ pub fn build_crt_file( |
| 7669 | 7889 | .global = config, |
| 7670 | 7890 | .cc_argv = &.{}, |
| 7671 | 7891 | .parent = null, |
| 7672 | | }); |
| 7892 | }) catch |err| { |
| 7893 | comp.lockAndSetMiscFailure(misc_task_tag, "sub-compilation of {t} failed: failed to create module: {t}", .{ misc_task_tag, err }); |
| 7894 | return error.AlreadyReported; |
| 7895 | }; |
| 7673 | 7896 | |
| 7674 | 7897 | for (c_source_files) |*item| { |
| 7675 | 7898 | item.owner = root_mod; |
| 7676 | 7899 | } |
| 7677 | 7900 | |
| 7678 | | const sub_compilation = try Compilation.create(gpa, arena, .{ |
| 7901 | var sub_create_diag: CreateDiagnostic = undefined; |
| 7902 | const sub_compilation = Compilation.create(gpa, arena, &sub_create_diag, .{ |
| 7679 | 7903 | .dirs = comp.dirs.withoutLocalCache(), |
| 7680 | 7904 | .self_exe_path = comp.self_exe_path, |
| 7681 | 7905 | .cache_mode = .whole, |
| ... | ... | @@ -7699,7 +7923,13 @@ pub fn build_crt_file( |
| 7699 | 7923 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| 7700 | 7924 | .clang_passthrough_mode = comp.clang_passthrough_mode, |
| 7701 | 7925 | .skip_linker_dependencies = true, |
| 7702 | | }); |
| 7926 | }) catch |err| switch (err) { |
| 7927 | error.CreateFail => { |
| 7928 | comp.lockAndSetMiscFailure(misc_task_tag, "sub-compilation of {t} failed: {f}", .{ misc_task_tag, sub_create_diag }); |
| 7929 | return error.AlreadyReported; |
| 7930 | }, |
| 7931 | else => |e| return e, |
| 7932 | }; |
| 7703 | 7933 | defer sub_compilation.destroy(); |
| 7704 | 7934 | |
| 7705 | 7935 | try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node); |