| ... | ... | @@ -410,22 +410,15 @@ pub const CObject = struct { |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | pub const Bundle = struct { |
| 413 | | file_names: std.AutoHashMapUnmanaged(u32, []const u8) = .{}, |
| 414 | | category_names: std.AutoHashMapUnmanaged(u32, []const u8) = .{}, |
| 413 | file_names: std.AutoArrayHashMapUnmanaged(u32, []const u8) = .{}, |
| 414 | category_names: std.AutoArrayHashMapUnmanaged(u32, []const u8) = .{}, |
| 415 | 415 | diags: []Diag = &.{}, |
| 416 | 416 | |
| 417 | 417 | pub fn destroy(bundle: *Bundle, gpa: Allocator) void { |
| 418 | | var file_name_it = bundle.file_names.valueIterator(); |
| 419 | | while (file_name_it.next()) |file_name| gpa.free(file_name.*); |
| 420 | | bundle.file_names.deinit(gpa); |
| 421 | | |
| 422 | | var category_name_it = bundle.category_names.valueIterator(); |
| 423 | | while (category_name_it.next()) |category_name| gpa.free(category_name.*); |
| 424 | | bundle.category_names.deinit(gpa); |
| 425 | | |
| 418 | for (bundle.file_names.values()) |file_name| gpa.free(file_name); |
| 419 | for (bundle.category_names.values()) |category_name| gpa.free(category_name); |
| 426 | 420 | for (bundle.diags) |*diag| diag.deinit(gpa); |
| 427 | 421 | gpa.free(bundle.diags); |
| 428 | | |
| 429 | 422 | gpa.destroy(bundle); |
| 430 | 423 | } |
| 431 | 424 | |
| ... | ... | @@ -470,17 +463,15 @@ pub const CObject = struct { |
| 470 | 463 | var bc = BitcodeReader.init(gpa, .{ .reader = reader.any() }); |
| 471 | 464 | defer bc.deinit(); |
| 472 | 465 | |
| 473 | | var file_names: std.AutoHashMapUnmanaged(u32, []const u8) = .{}; |
| 466 | var file_names: std.AutoArrayHashMapUnmanaged(u32, []const u8) = .{}; |
| 474 | 467 | errdefer { |
| 475 | | var file_name_it = file_names.valueIterator(); |
| 476 | | while (file_name_it.next()) |file_name| gpa.free(file_name.*); |
| 468 | for (file_names.values()) |file_name| gpa.free(file_name); |
| 477 | 469 | file_names.deinit(gpa); |
| 478 | 470 | } |
| 479 | 471 | |
| 480 | | var category_names: std.AutoHashMapUnmanaged(u32, []const u8) = .{}; |
| 472 | var category_names: std.AutoArrayHashMapUnmanaged(u32, []const u8) = .{}; |
| 481 | 473 | errdefer { |
| 482 | | var category_name_it = category_names.valueIterator(); |
| 483 | | while (category_name_it.next()) |category_name| gpa.free(category_name.*); |
| 474 | for (category_names.values()) |category_name| gpa.free(category_name); |
| 484 | 475 | category_names.deinit(gpa); |
| 485 | 476 | } |
| 486 | 477 | |
| ... | ... | @@ -1014,46 +1005,39 @@ fn addModuleTableToCacheHash( |
| 1014 | 1005 | ) (error{OutOfMemory} || std.os.GetCwdError)!void { |
| 1015 | 1006 | const allocator = arena.allocator(); |
| 1016 | 1007 | |
| 1017 | | const modules = try allocator.alloc(Package.Module.Deps.KV, mod_table.count()); |
| 1018 | | { |
| 1019 | | // Copy over the hashmap entries to our slice |
| 1020 | | var table_it = mod_table.iterator(); |
| 1021 | | var idx: usize = 0; |
| 1022 | | while (table_it.next()) |entry| : (idx += 1) { |
| 1023 | | modules[idx] = .{ |
| 1024 | | .key = entry.key_ptr.*, |
| 1025 | | .value = entry.value_ptr.*, |
| 1026 | | }; |
| 1027 | | } |
| 1028 | | } |
| 1008 | const module_indices = try allocator.alloc(u32, mod_table.count()); |
| 1009 | // Copy over the hashmap entries to our slice |
| 1010 | for (module_indices, 0..) |*module_index, index| module_index.* = @intCast(index); |
| 1029 | 1011 | // Sort the slice by package name |
| 1030 | | mem.sortUnstable(Package.Module.Deps.KV, modules, {}, struct { |
| 1031 | | fn lessThan(_: void, lhs: Package.Module.Deps.KV, rhs: Package.Module.Deps.KV) bool { |
| 1032 | | return std.mem.lessThan(u8, lhs.key, rhs.key); |
| 1012 | mem.sortUnstable(u32, module_indices, &mod_table, struct { |
| 1013 | fn lessThan(deps: *const Package.Module.Deps, lhs: u32, rhs: u32) bool { |
| 1014 | const keys = deps.keys(); |
| 1015 | return std.mem.lessThan(u8, keys[lhs], keys[rhs]); |
| 1033 | 1016 | } |
| 1034 | 1017 | }.lessThan); |
| 1035 | 1018 | |
| 1036 | | for (modules) |mod| { |
| 1037 | | if ((try seen_table.getOrPut(mod.value)).found_existing) continue; |
| 1019 | for (module_indices) |module_index| { |
| 1020 | const module = mod_table.values()[module_index]; |
| 1021 | if ((try seen_table.getOrPut(module)).found_existing) continue; |
| 1038 | 1022 | |
| 1039 | 1023 | // Finally insert the package name and path to the cache hash. |
| 1040 | | hash.addBytes(mod.key); |
| 1024 | hash.addBytes(mod_table.keys()[module_index]); |
| 1041 | 1025 | switch (hash_type) { |
| 1042 | 1026 | .path_bytes => { |
| 1043 | | hash.addBytes(mod.value.root_src_path); |
| 1044 | | hash.addOptionalBytes(mod.value.root.root_dir.path); |
| 1045 | | hash.addBytes(mod.value.root.sub_path); |
| 1027 | hash.addBytes(module.root_src_path); |
| 1028 | hash.addOptionalBytes(module.root.root_dir.path); |
| 1029 | hash.addBytes(module.root.sub_path); |
| 1046 | 1030 | }, |
| 1047 | 1031 | .files => |man| { |
| 1048 | | const pkg_zig_file = try mod.value.root.joinString( |
| 1032 | const pkg_zig_file = try module.root.joinString( |
| 1049 | 1033 | allocator, |
| 1050 | | mod.value.root_src_path, |
| 1034 | module.root_src_path, |
| 1051 | 1035 | ); |
| 1052 | 1036 | _ = try man.addFile(pkg_zig_file, null); |
| 1053 | 1037 | }, |
| 1054 | 1038 | } |
| 1055 | 1039 | // Recurse to handle the module's dependencies |
| 1056 | | try addModuleTableToCacheHash(hash, arena, mod.value.deps, seen_table, hash_type); |
| 1040 | try addModuleTableToCacheHash(hash, arena, module.deps, seen_table, hash_type); |
| 1057 | 1041 | } |
| 1058 | 1042 | } |
| 1059 | 1043 | |
| ... | ... | @@ -2260,8 +2244,8 @@ pub fn destroy(self: *Compilation) void { |
| 2260 | 2244 | } |
| 2261 | 2245 | self.c_object_table.deinit(gpa); |
| 2262 | 2246 | |
| 2263 | | for (self.failed_c_objects.values()) |value| { |
| 2264 | | value.destroy(gpa); |
| 2247 | for (self.failed_c_objects.values()) |bundle| { |
| 2248 | bundle.destroy(gpa); |
| 2265 | 2249 | } |
| 2266 | 2250 | self.failed_c_objects.deinit(gpa); |
| 2267 | 2251 | |
| ... | ... | @@ -2483,13 +2467,9 @@ pub fn update(comp: *Compilation, main_progress_node: *std.Progress.Node) !void |
| 2483 | 2467 | } |
| 2484 | 2468 | |
| 2485 | 2469 | // Put a work item in for checking if any files used with `@embedFile` changed. |
| 2486 | | { |
| 2487 | | try comp.embed_file_work_queue.ensureUnusedCapacity(module.embed_table.count()); |
| 2488 | | var it = module.embed_table.iterator(); |
| 2489 | | while (it.next()) |entry| { |
| 2490 | | const embed_file = entry.value_ptr.*; |
| 2491 | | comp.embed_file_work_queue.writeItemAssumeCapacity(embed_file); |
| 2492 | | } |
| 2470 | try comp.embed_file_work_queue.ensureUnusedCapacity(module.embed_table.count()); |
| 2471 | for (module.embed_table.values()) |embed_file| { |
| 2472 | comp.embed_file_work_queue.writeItemAssumeCapacity(embed_file); |
| 2493 | 2473 | } |
| 2494 | 2474 | |
| 2495 | 2475 | try comp.work_queue.writeItem(.{ .analyze_mod = std_mod }); |
| ... | ... | @@ -3083,9 +3063,8 @@ pub fn totalErrorCount(self: *Compilation) u32 { |
| 3083 | 3063 | @intFromBool(self.alloc_failure_occurred) + |
| 3084 | 3064 | self.lld_errors.items.len; |
| 3085 | 3065 | |
| 3086 | | { |
| 3087 | | var it = self.failed_c_objects.iterator(); |
| 3088 | | while (it.next()) |entry| total += entry.value_ptr.*.diags.len; |
| 3066 | for (self.failed_c_objects.values()) |bundle| { |
| 3067 | total += bundle.diags.len; |
| 3089 | 3068 | } |
| 3090 | 3069 | |
| 3091 | 3070 | if (!build_options.only_core_functionality) { |
| ... | ... | @@ -3098,19 +3077,15 @@ pub fn totalErrorCount(self: *Compilation) u32 { |
| 3098 | 3077 | total += module.failed_exports.count(); |
| 3099 | 3078 | total += module.failed_embed_files.count(); |
| 3100 | 3079 | |
| 3101 | | { |
| 3102 | | var it = module.failed_files.iterator(); |
| 3103 | | while (it.next()) |entry| { |
| 3104 | | if (entry.value_ptr.*) |_| { |
| 3105 | | total += 1; |
| 3106 | | } else { |
| 3107 | | const file = entry.key_ptr.*; |
| 3108 | | assert(file.zir_loaded); |
| 3109 | | const payload_index = file.zir.extra[@intFromEnum(Zir.ExtraIndex.compile_errors)]; |
| 3110 | | assert(payload_index != 0); |
| 3111 | | const header = file.zir.extraData(Zir.Inst.CompileErrors, payload_index); |
| 3112 | | total += header.data.items_len; |
| 3113 | | } |
| 3080 | for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| { |
| 3081 | if (error_msg) |_| { |
| 3082 | total += 1; |
| 3083 | } else { |
| 3084 | assert(file.zir_loaded); |
| 3085 | const payload_index = file.zir.extra[@intFromEnum(Zir.ExtraIndex.compile_errors)]; |
| 3086 | assert(payload_index != 0); |
| 3087 | const header = file.zir.extraData(Zir.Inst.CompileErrors, payload_index); |
| 3088 | total += header.data.items_len; |
| 3114 | 3089 | } |
| 3115 | 3090 | } |
| 3116 | 3091 | |
| ... | ... | @@ -3166,15 +3141,13 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 3166 | 3141 | try bundle.init(gpa); |
| 3167 | 3142 | defer bundle.deinit(); |
| 3168 | 3143 | |
| 3169 | | { |
| 3170 | | var it = self.failed_c_objects.iterator(); |
| 3171 | | while (it.next()) |entry| try entry.value_ptr.*.addToErrorBundle(&bundle); |
| 3144 | for (self.failed_c_objects.values()) |diag_bundle| { |
| 3145 | try diag_bundle.addToErrorBundle(&bundle); |
| 3172 | 3146 | } |
| 3173 | 3147 | |
| 3174 | 3148 | if (!build_options.only_core_functionality) { |
| 3175 | | var it = self.failed_win32_resources.iterator(); |
| 3176 | | while (it.next()) |entry| { |
| 3177 | | try bundle.addBundleAsRoots(entry.value_ptr.*); |
| 3149 | for (self.failed_win32_resources.values()) |error_bundle| { |
| 3150 | try bundle.addBundleAsRoots(error_bundle); |
| 3178 | 3151 | } |
| 3179 | 3152 | } |
| 3180 | 3153 | |
| ... | ... | @@ -3205,65 +3178,52 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 3205 | 3178 | }); |
| 3206 | 3179 | } |
| 3207 | 3180 | if (self.bin_file.options.module) |module| { |
| 3208 | | { |
| 3209 | | var it = module.failed_files.iterator(); |
| 3210 | | while (it.next()) |entry| { |
| 3211 | | if (entry.value_ptr.*) |msg| { |
| 3212 | | try addModuleErrorMsg(module, &bundle, msg.*); |
| 3213 | | } else { |
| 3214 | | // Must be ZIR errors. Note that this may include AST errors. |
| 3215 | | // addZirErrorMessages asserts that the tree is loaded. |
| 3216 | | _ = try entry.key_ptr.*.getTree(gpa); |
| 3217 | | try addZirErrorMessages(&bundle, entry.key_ptr.*); |
| 3218 | | } |
| 3219 | | } |
| 3220 | | } |
| 3221 | | { |
| 3222 | | var it = module.failed_embed_files.iterator(); |
| 3223 | | while (it.next()) |entry| { |
| 3224 | | const msg = entry.value_ptr.*; |
| 3181 | for (module.failed_files.keys(), module.failed_files.values()) |file, error_msg| { |
| 3182 | if (error_msg) |msg| { |
| 3225 | 3183 | try addModuleErrorMsg(module, &bundle, msg.*); |
| 3184 | } else { |
| 3185 | // Must be ZIR errors. Note that this may include AST errors. |
| 3186 | // addZirErrorMessages asserts that the tree is loaded. |
| 3187 | _ = try file.getTree(gpa); |
| 3188 | try addZirErrorMessages(&bundle, file); |
| 3226 | 3189 | } |
| 3227 | 3190 | } |
| 3228 | | { |
| 3229 | | var it = module.failed_decls.iterator(); |
| 3230 | | while (it.next()) |entry| { |
| 3231 | | const decl_index = entry.key_ptr.*; |
| 3232 | | // Skip errors for Decls within files that had a parse failure. |
| 3233 | | // We'll try again once parsing succeeds. |
| 3234 | | if (module.declFileScope(decl_index).okToReportErrors()) { |
| 3235 | | try addModuleErrorMsg(module, &bundle, entry.value_ptr.*.*); |
| 3236 | | if (module.cimport_errors.get(entry.key_ptr.*)) |errors| { |
| 3237 | | for (errors.getMessages()) |err_msg_index| { |
| 3238 | | const err_msg = errors.getErrorMessage(err_msg_index); |
| 3239 | | try bundle.addRootErrorMessage(.{ |
| 3240 | | .msg = try bundle.addString(errors.nullTerminatedString(err_msg.msg)), |
| 3241 | | .src_loc = if (err_msg.src_loc != .none) blk: { |
| 3242 | | const src_loc = errors.getSourceLocation(err_msg.src_loc); |
| 3243 | | break :blk try bundle.addSourceLocation(.{ |
| 3244 | | .src_path = try bundle.addString(errors.nullTerminatedString(src_loc.src_path)), |
| 3245 | | .span_start = src_loc.span_start, |
| 3246 | | .span_main = src_loc.span_main, |
| 3247 | | .span_end = src_loc.span_end, |
| 3248 | | .line = src_loc.line, |
| 3249 | | .column = src_loc.column, |
| 3250 | | .source_line = if (src_loc.source_line != 0) try bundle.addString(errors.nullTerminatedString(src_loc.source_line)) else 0, |
| 3251 | | }); |
| 3252 | | } else .none, |
| 3253 | | }); |
| 3254 | | } |
| 3191 | for (module.failed_embed_files.values()) |error_msg| { |
| 3192 | try addModuleErrorMsg(module, &bundle, error_msg.*); |
| 3193 | } |
| 3194 | for (module.failed_decls.keys(), module.failed_decls.values()) |decl_index, error_msg| { |
| 3195 | // Skip errors for Decls within files that had a parse failure. |
| 3196 | // We'll try again once parsing succeeds. |
| 3197 | if (module.declFileScope(decl_index).okToReportErrors()) { |
| 3198 | try addModuleErrorMsg(module, &bundle, error_msg.*); |
| 3199 | if (module.cimport_errors.get(decl_index)) |errors| { |
| 3200 | for (errors.getMessages()) |err_msg_index| { |
| 3201 | const err_msg = errors.getErrorMessage(err_msg_index); |
| 3202 | try bundle.addRootErrorMessage(.{ |
| 3203 | .msg = try bundle.addString(errors.nullTerminatedString(err_msg.msg)), |
| 3204 | .src_loc = if (err_msg.src_loc != .none) blk: { |
| 3205 | const src_loc = errors.getSourceLocation(err_msg.src_loc); |
| 3206 | break :blk try bundle.addSourceLocation(.{ |
| 3207 | .src_path = try bundle.addString(errors.nullTerminatedString(src_loc.src_path)), |
| 3208 | .span_start = src_loc.span_start, |
| 3209 | .span_main = src_loc.span_main, |
| 3210 | .span_end = src_loc.span_end, |
| 3211 | .line = src_loc.line, |
| 3212 | .column = src_loc.column, |
| 3213 | .source_line = if (src_loc.source_line != 0) try bundle.addString(errors.nullTerminatedString(src_loc.source_line)) else 0, |
| 3214 | }); |
| 3215 | } else .none, |
| 3216 | }); |
| 3255 | 3217 | } |
| 3256 | 3218 | } |
| 3257 | 3219 | } |
| 3258 | 3220 | } |
| 3259 | 3221 | if (module.emit_h) |emit_h| { |
| 3260 | | var it = emit_h.failed_decls.iterator(); |
| 3261 | | while (it.next()) |entry| { |
| 3262 | | const decl_index = entry.key_ptr.*; |
| 3222 | for (emit_h.failed_decls.keys(), emit_h.failed_decls.values()) |decl_index, error_msg| { |
| 3263 | 3223 | // Skip errors for Decls within files that had a parse failure. |
| 3264 | 3224 | // We'll try again once parsing succeeds. |
| 3265 | 3225 | if (module.declFileScope(decl_index).okToReportErrors()) { |
| 3266 | | try addModuleErrorMsg(module, &bundle, entry.value_ptr.*.*); |
| 3226 | try addModuleErrorMsg(module, &bundle, error_msg.*); |
| 3267 | 3227 | } |
| 3268 | 3228 | } |
| 3269 | 3229 | } |