| ... | @@ -37,6 +37,7 @@ const clang = @import("clang.zig"); | ... | @@ -37,6 +37,7 @@ const clang = @import("clang.zig"); |
| 37 | const InternPool = @import("InternPool.zig"); | 37 | const InternPool = @import("InternPool.zig"); |
| 38 | const Alignment = InternPool.Alignment; | 38 | const Alignment = InternPool.Alignment; |
| 39 | const BuiltinFn = std.zig.BuiltinFn; | 39 | const BuiltinFn = std.zig.BuiltinFn; |
| | 40 | const LlvmObject = @import("codegen/llvm.zig").Object; |
| 40 | | 41 | |
| 41 | comptime { | 42 | comptime { |
| 42 | @setEvalBranchQuota(4000); | 43 | @setEvalBranchQuota(4000); |
| ... | @@ -53,6 +54,10 @@ comptime { | ... | @@ -53,6 +54,10 @@ comptime { |
| 53 | /// General-purpose allocator. Used for both temporary and long-term storage. | 54 | /// General-purpose allocator. Used for both temporary and long-term storage. |
| 54 | gpa: Allocator, | 55 | gpa: Allocator, |
| 55 | comp: *Compilation, | 56 | comp: *Compilation, |
| | 57 | /// Usually, the LlvmObject is managed by linker code, however, in the case |
| | 58 | /// that -fno-emit-bin is specified, the linker code never executes, so we |
| | 59 | /// store the LlvmObject here. |
| | 60 | llvm_object: ?*LlvmObject, |
| 56 | | 61 | |
| 57 | /// Pointer to externally managed resource. | 62 | /// Pointer to externally managed resource. |
| 58 | root_mod: *Package.Module, | 63 | root_mod: *Package.Module, |
| ... | @@ -2476,36 +2481,41 @@ pub fn init(mod: *Module) !void { | ... | @@ -2476,36 +2481,41 @@ pub fn init(mod: *Module) !void { |
| 2476 | try mod.global_error_set.put(gpa, .empty, {}); | 2481 | try mod.global_error_set.put(gpa, .empty, {}); |
| 2477 | } | 2482 | } |
| 2478 | | 2483 | |
| 2479 | pub fn deinit(mod: *Module) void { | 2484 | pub fn deinit(zcu: *Zcu) void { |
| 2480 | const gpa = mod.gpa; | 2485 | const gpa = zcu.gpa; |
| | 2486 | |
| | 2487 | if (zcu.llvm_object) |llvm_object| { |
| | 2488 | if (build_options.only_c) unreachable; |
| | 2489 | llvm_object.deinit(); |
| | 2490 | } |
| 2481 | | 2491 | |
| 2482 | for (mod.import_table.keys()) |key| { | 2492 | for (zcu.import_table.keys()) |key| { |
| 2483 | gpa.free(key); | 2493 | gpa.free(key); |
| 2484 | } | 2494 | } |
| 2485 | var failed_decls = mod.failed_decls; | 2495 | var failed_decls = zcu.failed_decls; |
| 2486 | mod.failed_decls = .{}; | 2496 | zcu.failed_decls = .{}; |
| 2487 | for (mod.import_table.values()) |value| { | 2497 | for (zcu.import_table.values()) |value| { |
| 2488 | value.destroy(mod); | 2498 | value.destroy(zcu); |
| 2489 | } | 2499 | } |
| 2490 | mod.import_table.deinit(gpa); | 2500 | zcu.import_table.deinit(gpa); |
| 2491 | | 2501 | |
| 2492 | for (mod.embed_table.keys(), mod.embed_table.values()) |path, embed_file| { | 2502 | for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| { |
| 2493 | gpa.free(path); | 2503 | gpa.free(path); |
| 2494 | gpa.destroy(embed_file); | 2504 | gpa.destroy(embed_file); |
| 2495 | } | 2505 | } |
| 2496 | mod.embed_table.deinit(gpa); | 2506 | zcu.embed_table.deinit(gpa); |
| 2497 | | 2507 | |
| 2498 | mod.compile_log_text.deinit(gpa); | 2508 | zcu.compile_log_text.deinit(gpa); |
| 2499 | | 2509 | |
| 2500 | mod.local_zir_cache.handle.close(); | 2510 | zcu.local_zir_cache.handle.close(); |
| 2501 | mod.global_zir_cache.handle.close(); | 2511 | zcu.global_zir_cache.handle.close(); |
| 2502 | | 2512 | |
| 2503 | for (failed_decls.values()) |value| { | 2513 | for (failed_decls.values()) |value| { |
| 2504 | value.destroy(gpa); | 2514 | value.destroy(gpa); |
| 2505 | } | 2515 | } |
| 2506 | failed_decls.deinit(gpa); | 2516 | failed_decls.deinit(gpa); |
| 2507 | | 2517 | |
| 2508 | if (mod.emit_h) |emit_h| { | 2518 | if (zcu.emit_h) |emit_h| { |
| 2509 | for (emit_h.failed_decls.values()) |value| { | 2519 | for (emit_h.failed_decls.values()) |value| { |
| 2510 | value.destroy(gpa); | 2520 | value.destroy(gpa); |
| 2511 | } | 2521 | } |
| ... | @@ -2514,68 +2524,68 @@ pub fn deinit(mod: *Module) void { | ... | @@ -2514,68 +2524,68 @@ pub fn deinit(mod: *Module) void { |
| 2514 | emit_h.allocated_emit_h.deinit(gpa); | 2524 | emit_h.allocated_emit_h.deinit(gpa); |
| 2515 | } | 2525 | } |
| 2516 | | 2526 | |
| 2517 | for (mod.failed_files.values()) |value| { | 2527 | for (zcu.failed_files.values()) |value| { |
| 2518 | if (value) |msg| msg.destroy(gpa); | 2528 | if (value) |msg| msg.destroy(gpa); |
| 2519 | } | 2529 | } |
| 2520 | mod.failed_files.deinit(gpa); | 2530 | zcu.failed_files.deinit(gpa); |
| 2521 | | 2531 | |
| 2522 | for (mod.failed_embed_files.values()) |msg| { | 2532 | for (zcu.failed_embed_files.values()) |msg| { |
| 2523 | msg.destroy(gpa); | 2533 | msg.destroy(gpa); |
| 2524 | } | 2534 | } |
| 2525 | mod.failed_embed_files.deinit(gpa); | 2535 | zcu.failed_embed_files.deinit(gpa); |
| 2526 | | 2536 | |
| 2527 | for (mod.failed_exports.values()) |value| { | 2537 | for (zcu.failed_exports.values()) |value| { |
| 2528 | value.destroy(gpa); | 2538 | value.destroy(gpa); |
| 2529 | } | 2539 | } |
| 2530 | mod.failed_exports.deinit(gpa); | 2540 | zcu.failed_exports.deinit(gpa); |
| 2531 | | 2541 | |
| 2532 | for (mod.cimport_errors.values()) |*errs| { | 2542 | for (zcu.cimport_errors.values()) |*errs| { |
| 2533 | errs.deinit(gpa); | 2543 | errs.deinit(gpa); |
| 2534 | } | 2544 | } |
| 2535 | mod.cimport_errors.deinit(gpa); | 2545 | zcu.cimport_errors.deinit(gpa); |
| 2536 | | 2546 | |
| 2537 | mod.compile_log_decls.deinit(gpa); | 2547 | zcu.compile_log_decls.deinit(gpa); |
| 2538 | | 2548 | |
| 2539 | for (mod.decl_exports.values()) |*export_list| { | 2549 | for (zcu.decl_exports.values()) |*export_list| { |
| 2540 | export_list.deinit(gpa); | 2550 | export_list.deinit(gpa); |
| 2541 | } | 2551 | } |
| 2542 | mod.decl_exports.deinit(gpa); | 2552 | zcu.decl_exports.deinit(gpa); |
| 2543 | | 2553 | |
| 2544 | for (mod.value_exports.values()) |*export_list| { | 2554 | for (zcu.value_exports.values()) |*export_list| { |
| 2545 | export_list.deinit(gpa); | 2555 | export_list.deinit(gpa); |
| 2546 | } | 2556 | } |
| 2547 | mod.value_exports.deinit(gpa); | 2557 | zcu.value_exports.deinit(gpa); |
| 2548 | | 2558 | |
| 2549 | for (mod.export_owners.values()) |*value| { | 2559 | for (zcu.export_owners.values()) |*value| { |
| 2550 | freeExportList(gpa, value); | 2560 | freeExportList(gpa, value); |
| 2551 | } | 2561 | } |
| 2552 | mod.export_owners.deinit(gpa); | 2562 | zcu.export_owners.deinit(gpa); |
| 2553 | | 2563 | |
| 2554 | mod.global_error_set.deinit(gpa); | 2564 | zcu.global_error_set.deinit(gpa); |
| 2555 | | 2565 | |
| 2556 | mod.test_functions.deinit(gpa); | 2566 | zcu.test_functions.deinit(gpa); |
| 2557 | | 2567 | |
| 2558 | for (mod.global_assembly.values()) |s| { | 2568 | for (zcu.global_assembly.values()) |s| { |
| 2559 | gpa.free(s); | 2569 | gpa.free(s); |
| 2560 | } | 2570 | } |
| 2561 | mod.global_assembly.deinit(gpa); | 2571 | zcu.global_assembly.deinit(gpa); |
| 2562 | | 2572 | |
| 2563 | mod.reference_table.deinit(gpa); | 2573 | zcu.reference_table.deinit(gpa); |
| 2564 | | 2574 | |
| 2565 | { | 2575 | { |
| 2566 | var it = mod.intern_pool.allocated_namespaces.iterator(0); | 2576 | var it = zcu.intern_pool.allocated_namespaces.iterator(0); |
| 2567 | while (it.next()) |namespace| { | 2577 | while (it.next()) |namespace| { |
| 2568 | namespace.decls.deinit(gpa); | 2578 | namespace.decls.deinit(gpa); |
| 2569 | namespace.usingnamespace_set.deinit(gpa); | 2579 | namespace.usingnamespace_set.deinit(gpa); |
| 2570 | } | 2580 | } |
| 2571 | } | 2581 | } |
| 2572 | | 2582 | |
| 2573 | mod.intern_pool.deinit(gpa); | 2583 | zcu.intern_pool.deinit(gpa); |
| 2574 | mod.tmp_hack_arena.deinit(); | 2584 | zcu.tmp_hack_arena.deinit(); |
| 2575 | | 2585 | |
| 2576 | mod.capture_scope_parents.deinit(gpa); | 2586 | zcu.capture_scope_parents.deinit(gpa); |
| 2577 | mod.runtime_capture_scopes.deinit(gpa); | 2587 | zcu.runtime_capture_scopes.deinit(gpa); |
| 2578 | mod.comptime_capture_scopes.deinit(gpa); | 2588 | zcu.comptime_capture_scopes.deinit(gpa); |
| 2579 | } | 2589 | } |
| 2580 | | 2590 | |
| 2581 | pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { | 2591 | pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { |
| ... | @@ -3222,14 +3232,14 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { | ... | @@ -3222,14 +3232,14 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { |
| 3222 | } | 3232 | } |
| 3223 | } | 3233 | } |
| 3224 | | 3234 | |
| 3225 | pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaError!void { | 3235 | pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, func_index: InternPool.Index) SemaError!void { |
| 3226 | const tracy = trace(@src()); | 3236 | const tracy = trace(@src()); |
| 3227 | defer tracy.end(); | 3237 | defer tracy.end(); |
| 3228 | | 3238 | |
| 3229 | const ip = &mod.intern_pool; | 3239 | const ip = &zcu.intern_pool; |
| 3230 | const func = mod.funcInfo(func_index); | 3240 | const func = zcu.funcInfo(func_index); |
| 3231 | const decl_index = func.owner_decl; | 3241 | const decl_index = func.owner_decl; |
| 3232 | const decl = mod.declPtr(decl_index); | 3242 | const decl = zcu.declPtr(decl_index); |
| 3233 | | 3243 | |
| 3234 | switch (decl.analysis) { | 3244 | switch (decl.analysis) { |
| 3235 | .unreferenced => unreachable, | 3245 | .unreferenced => unreachable, |
| ... | @@ -3253,13 +3263,13 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr | ... | @@ -3253,13 +3263,13 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr |
| 3253 | .success => return, | 3263 | .success => return, |
| 3254 | } | 3264 | } |
| 3255 | | 3265 | |
| 3256 | const gpa = mod.gpa; | 3266 | const gpa = zcu.gpa; |
| 3257 | | 3267 | |
| 3258 | var tmp_arena = std.heap.ArenaAllocator.init(gpa); | 3268 | var tmp_arena = std.heap.ArenaAllocator.init(gpa); |
| 3259 | defer tmp_arena.deinit(); | 3269 | defer tmp_arena.deinit(); |
| 3260 | const sema_arena = tmp_arena.allocator(); | 3270 | const sema_arena = tmp_arena.allocator(); |
| 3261 | | 3271 | |
| 3262 | var air = mod.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) { | 3272 | var air = zcu.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) { |
| 3263 | error.AnalysisFail => { | 3273 | error.AnalysisFail => { |
| 3264 | if (func.analysis(ip).state == .in_progress) { | 3274 | if (func.analysis(ip).state == .in_progress) { |
| 3265 | // If this decl caused the compile error, the analysis field would | 3275 | // If this decl caused the compile error, the analysis field would |
| ... | @@ -3273,25 +3283,22 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr | ... | @@ -3273,25 +3283,22 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr |
| 3273 | }; | 3283 | }; |
| 3274 | defer air.deinit(gpa); | 3284 | defer air.deinit(gpa); |
| 3275 | | 3285 | |
| 3276 | const comp = mod.comp; | 3286 | const comp = zcu.comp; |
| 3277 | | | |
| 3278 | const no_bin_file = (comp.bin_file == null and | | |
| 3279 | comp.emit_asm == null and | | |
| 3280 | comp.emit_llvm_ir == null and | | |
| 3281 | comp.emit_llvm_bc == null); | | |
| 3282 | | 3287 | |
| 3283 | const dump_air = builtin.mode == .Debug and comp.verbose_air; | 3288 | const dump_air = builtin.mode == .Debug and comp.verbose_air; |
| 3284 | const dump_llvm_ir = builtin.mode == .Debug and (comp.verbose_llvm_ir != null or comp.verbose_llvm_bc != null); | 3289 | const dump_llvm_ir = builtin.mode == .Debug and (comp.verbose_llvm_ir != null or comp.verbose_llvm_bc != null); |
| 3285 | | 3290 | |
| 3286 | if (no_bin_file and !dump_air and !dump_llvm_ir) return; | 3291 | if (comp.bin_file == null and zcu.llvm_object == null and !dump_air and !dump_llvm_ir) { |
| | 3292 | return; |
| | 3293 | } |
| 3287 | | 3294 | |
| 3288 | var liveness = try Liveness.analyze(gpa, air, ip); | 3295 | var liveness = try Liveness.analyze(gpa, air, ip); |
| 3289 | defer liveness.deinit(gpa); | 3296 | defer liveness.deinit(gpa); |
| 3290 | | 3297 | |
| 3291 | if (dump_air) { | 3298 | if (dump_air) { |
| 3292 | const fqn = try decl.getFullyQualifiedName(mod); | 3299 | const fqn = try decl.getFullyQualifiedName(zcu); |
| 3293 | std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(ip)}); | 3300 | std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(ip)}); |
| 3294 | @import("print_air.zig").dump(mod, air, liveness); | 3301 | @import("print_air.zig").dump(zcu, air, liveness); |
| 3295 | std.debug.print("# End Function AIR: {}\n\n", .{fqn.fmt(ip)}); | 3302 | std.debug.print("# End Function AIR: {}\n\n", .{fqn.fmt(ip)}); |
| 3296 | } | 3303 | } |
| 3297 | | 3304 | |
| ... | @@ -3307,12 +3314,12 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr | ... | @@ -3307,12 +3314,12 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr |
| 3307 | verify.verify() catch |err| switch (err) { | 3314 | verify.verify() catch |err| switch (err) { |
| 3308 | error.OutOfMemory => return error.OutOfMemory, | 3315 | error.OutOfMemory => return error.OutOfMemory, |
| 3309 | else => { | 3316 | else => { |
| 3310 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); | 3317 | try zcu.failed_decls.ensureUnusedCapacity(gpa, 1); |
| 3311 | mod.failed_decls.putAssumeCapacityNoClobber( | 3318 | zcu.failed_decls.putAssumeCapacityNoClobber( |
| 3312 | decl_index, | 3319 | decl_index, |
| 3313 | try Module.ErrorMsg.create( | 3320 | try Module.ErrorMsg.create( |
| 3314 | gpa, | 3321 | gpa, |
| 3315 | decl.srcLoc(mod), | 3322 | decl.srcLoc(zcu), |
| 3316 | "invalid liveness: {s}", | 3323 | "invalid liveness: {s}", |
| 3317 | .{@errorName(err)}, | 3324 | .{@errorName(err)}, |
| 3318 | ), | 3325 | ), |
| ... | @@ -3323,28 +3330,32 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr | ... | @@ -3323,28 +3330,32 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: InternPool.Index) SemaEr |
| 3323 | }; | 3330 | }; |
| 3324 | } | 3331 | } |
| 3325 | | 3332 | |
| 3326 | if (no_bin_file and !dump_llvm_ir) return; | 3333 | if (comp.bin_file) |lf| { |
| 3327 | | 3334 | lf.updateFunc(zcu, func_index, air, liveness) catch |err| switch (err) { |
| 3328 | const lf = comp.bin_file.?; | 3335 | error.OutOfMemory => return error.OutOfMemory, |
| 3329 | lf.updateFunc(mod, func_index, air, liveness) catch |err| switch (err) { | 3336 | error.AnalysisFail => { |
| 3330 | error.OutOfMemory => return error.OutOfMemory, | 3337 | decl.analysis = .codegen_failure; |
| 3331 | error.AnalysisFail => { | 3338 | }, |
| 3332 | decl.analysis = .codegen_failure; | 3339 | else => { |
| 3333 | return; | 3340 | try zcu.failed_decls.ensureUnusedCapacity(gpa, 1); |
| 3334 | }, | 3341 | zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create( |
| 3335 | else => { | 3342 | gpa, |
| 3336 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); | 3343 | decl.srcLoc(zcu), |
| 3337 | mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create( | 3344 | "unable to codegen: {s}", |
| 3338 | gpa, | 3345 | .{@errorName(err)}, |
| 3339 | decl.srcLoc(mod), | 3346 | )); |
| 3340 | "unable to codegen: {s}", | 3347 | decl.analysis = .codegen_failure_retryable; |
| 3341 | .{@errorName(err)}, | 3348 | }, |
| 3342 | )); | 3349 | }; |
| 3343 | decl.analysis = .codegen_failure_retryable; | 3350 | } else if (zcu.llvm_object) |llvm_object| { |
| 3344 | return; | 3351 | if (build_options.only_c) unreachable; |
| 3345 | }, | 3352 | llvm_object.updateFunc(zcu, func_index, air, liveness) catch |err| switch (err) { |
| 3346 | }; | 3353 | error.OutOfMemory => return error.OutOfMemory, |
| 3347 | return; | 3354 | error.AnalysisFail => { |
| | 3355 | decl.analysis = .codegen_failure; |
| | 3356 | }, |
| | 3357 | }; |
| | 3358 | } |
| 3348 | }, | 3359 | }, |
| 3349 | } | 3360 | } |
| 3350 | } | 3361 | } |
| ... | @@ -5235,44 +5246,57 @@ pub fn processExports(mod: *Module) !void { | ... | @@ -5235,44 +5246,57 @@ pub fn processExports(mod: *Module) !void { |
| 5235 | const SymbolExports = std.AutoArrayHashMapUnmanaged(InternPool.NullTerminatedString, *Export); | 5246 | const SymbolExports = std.AutoArrayHashMapUnmanaged(InternPool.NullTerminatedString, *Export); |
| 5236 | | 5247 | |
| 5237 | fn processExportsInner( | 5248 | fn processExportsInner( |
| 5238 | mod: *Module, | 5249 | zcu: *Zcu, |
| 5239 | symbol_exports: *SymbolExports, | 5250 | symbol_exports: *SymbolExports, |
| 5240 | exported: Exported, | 5251 | exported: Exported, |
| 5241 | exports: []const *Export, | 5252 | exports: []const *Export, |
| 5242 | ) error{OutOfMemory}!void { | 5253 | ) error{OutOfMemory}!void { |
| 5243 | const gpa = mod.gpa; | 5254 | const gpa = zcu.gpa; |
| 5244 | | 5255 | |
| 5245 | for (exports) |new_export| { | 5256 | for (exports) |new_export| { |
| 5246 | const gop = try symbol_exports.getOrPut(gpa, new_export.opts.name); | 5257 | const gop = try symbol_exports.getOrPut(gpa, new_export.opts.name); |
| 5247 | if (gop.found_existing) { | 5258 | if (gop.found_existing) { |
| 5248 | new_export.status = .failed_retryable; | 5259 | new_export.status = .failed_retryable; |
| 5249 | try mod.failed_exports.ensureUnusedCapacity(gpa, 1); | 5260 | try zcu.failed_exports.ensureUnusedCapacity(gpa, 1); |
| 5250 | const src_loc = new_export.getSrcLoc(mod); | 5261 | const src_loc = new_export.getSrcLoc(zcu); |
| 5251 | const msg = try ErrorMsg.create(gpa, src_loc, "exported symbol collision: {}", .{ | 5262 | const msg = try ErrorMsg.create(gpa, src_loc, "exported symbol collision: {}", .{ |
| 5252 | new_export.opts.name.fmt(&mod.intern_pool), | 5263 | new_export.opts.name.fmt(&zcu.intern_pool), |
| 5253 | }); | 5264 | }); |
| 5254 | errdefer msg.destroy(gpa); | 5265 | errdefer msg.destroy(gpa); |
| 5255 | const other_export = gop.value_ptr.*; | 5266 | const other_export = gop.value_ptr.*; |
| 5256 | const other_src_loc = other_export.getSrcLoc(mod); | 5267 | const other_src_loc = other_export.getSrcLoc(zcu); |
| 5257 | try mod.errNoteNonLazy(other_src_loc, msg, "other symbol here", .{}); | 5268 | try zcu.errNoteNonLazy(other_src_loc, msg, "other symbol here", .{}); |
| 5258 | mod.failed_exports.putAssumeCapacityNoClobber(new_export, msg); | 5269 | zcu.failed_exports.putAssumeCapacityNoClobber(new_export, msg); |
| 5259 | new_export.status = .failed; | 5270 | new_export.status = .failed; |
| 5260 | } else { | 5271 | } else { |
| 5261 | gop.value_ptr.* = new_export; | 5272 | gop.value_ptr.* = new_export; |
| 5262 | } | 5273 | } |
| 5263 | } | 5274 | } |
| 5264 | const lf = mod.comp.bin_file orelse return; | 5275 | if (zcu.comp.bin_file) |lf| { |
| 5265 | lf.updateExports(mod, exported, exports) catch |err| switch (err) { | 5276 | try handleUpdateExports(zcu, exports, lf.updateExports(zcu, exported, exports)); |
| | 5277 | } else if (zcu.llvm_object) |llvm_object| { |
| | 5278 | if (build_options.only_c) unreachable; |
| | 5279 | try handleUpdateExports(zcu, exports, llvm_object.updateExports(zcu, exported, exports)); |
| | 5280 | } |
| | 5281 | } |
| | 5282 | |
| | 5283 | fn handleUpdateExports( |
| | 5284 | zcu: *Zcu, |
| | 5285 | exports: []const *Export, |
| | 5286 | result: link.File.UpdateExportsError!void, |
| | 5287 | ) Allocator.Error!void { |
| | 5288 | const gpa = zcu.gpa; |
| | 5289 | result catch |err| switch (err) { |
| 5266 | error.OutOfMemory => return error.OutOfMemory, | 5290 | error.OutOfMemory => return error.OutOfMemory, |
| 5267 | else => { | 5291 | error.AnalysisFail => { |
| 5268 | const new_export = exports[0]; | 5292 | const new_export = exports[0]; |
| 5269 | new_export.status = .failed_retryable; | 5293 | new_export.status = .failed_retryable; |
| 5270 | try mod.failed_exports.ensureUnusedCapacity(gpa, 1); | 5294 | try zcu.failed_exports.ensureUnusedCapacity(gpa, 1); |
| 5271 | const src_loc = new_export.getSrcLoc(mod); | 5295 | const src_loc = new_export.getSrcLoc(zcu); |
| 5272 | const msg = try ErrorMsg.create(gpa, src_loc, "unable to export: {s}", .{ | 5296 | const msg = try ErrorMsg.create(gpa, src_loc, "unable to export: {s}", .{ |
| 5273 | @errorName(err), | 5297 | @errorName(err), |
| 5274 | }); | 5298 | }); |
| 5275 | mod.failed_exports.putAssumeCapacityNoClobber(new_export, msg); | 5299 | zcu.failed_exports.putAssumeCapacityNoClobber(new_export, msg); |
| 5276 | }, | 5300 | }, |
| 5277 | }; | 5301 | }; |
| 5278 | } | 5302 | } |
| ... | @@ -5415,41 +5439,38 @@ pub fn populateTestFunctions( | ... | @@ -5415,41 +5439,38 @@ pub fn populateTestFunctions( |
| 5415 | try mod.linkerUpdateDecl(decl_index); | 5439 | try mod.linkerUpdateDecl(decl_index); |
| 5416 | } | 5440 | } |
| 5417 | | 5441 | |
| 5418 | pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void { | 5442 | pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void { |
| 5419 | const comp = mod.comp; | 5443 | const comp = zcu.comp; |
| 5420 | | 5444 | |
| 5421 | if (comp.bin_file) |lf| { | 5445 | if (comp.bin_file) |lf| { |
| 5422 | const decl = mod.declPtr(decl_index); | 5446 | lf.updateDecl(zcu, decl_index) catch |err| switch (err) { |
| 5423 | lf.updateDecl(mod, decl_index) catch |err| switch (err) { | | |
| 5424 | error.OutOfMemory => return error.OutOfMemory, | 5447 | error.OutOfMemory => return error.OutOfMemory, |
| 5425 | error.AnalysisFail => { | 5448 | error.AnalysisFail => { |
| | 5449 | const decl = zcu.declPtr(decl_index); |
| 5426 | decl.analysis = .codegen_failure; | 5450 | decl.analysis = .codegen_failure; |
| 5427 | return; | | |
| 5428 | }, | 5451 | }, |
| 5429 | else => { | 5452 | else => { |
| 5430 | const gpa = mod.gpa; | 5453 | const decl = zcu.declPtr(decl_index); |
| 5431 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); | 5454 | const gpa = zcu.gpa; |
| 5432 | mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create( | 5455 | try zcu.failed_decls.ensureUnusedCapacity(gpa, 1); |
| | 5456 | zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create( |
| 5433 | gpa, | 5457 | gpa, |
| 5434 | decl.srcLoc(mod), | 5458 | decl.srcLoc(zcu), |
| 5435 | "unable to codegen: {s}", | 5459 | "unable to codegen: {s}", |
| 5436 | .{@errorName(err)}, | 5460 | .{@errorName(err)}, |
| 5437 | )); | 5461 | )); |
| 5438 | decl.analysis = .codegen_failure_retryable; | 5462 | decl.analysis = .codegen_failure_retryable; |
| 5439 | return; | | |
| 5440 | }, | 5463 | }, |
| 5441 | }; | 5464 | }; |
| 5442 | } else { | 5465 | } else if (zcu.llvm_object) |llvm_object| { |
| 5443 | const dump_llvm_ir = builtin.mode == .Debug and | 5466 | if (build_options.only_c) unreachable; |
| 5444 | (comp.verbose_llvm_ir != null or comp.verbose_llvm_bc != null); | 5467 | llvm_object.updateDecl(zcu, decl_index) catch |err| switch (err) { |
| 5445 | | 5468 | error.OutOfMemory => return error.OutOfMemory, |
| 5446 | if (comp.emit_asm != null or | 5469 | error.AnalysisFail => { |
| 5447 | comp.emit_llvm_ir != null or | 5470 | const decl = zcu.declPtr(decl_index); |
| 5448 | comp.emit_llvm_bc != null or | 5471 | decl.analysis = .codegen_failure; |
| 5449 | dump_llvm_ir) | 5472 | }, |
| 5450 | { | 5473 | }; |
| 5451 | @panic("TODO handle emit_asm, emit_llvm_ir, and emit_llvm_bc along with -fno-emit-bin"); | | |
| 5452 | } | | |
| 5453 | } | 5474 | } |
| 5454 | } | 5475 | } |
| 5455 | | 5476 | |