| author | |
| committer | |
| log | ca02266157ee72e41068672c8ca6f928fcbf6fdf |
| tree | d827ad6e5d0d311c4fca7fa83a32a98d3d201ac4 |
| parent | 525f341f33af9b8aad53931fd5511f00a82cb090 |
22 files changed, 1025 insertions(+), 963 deletions(-)
src/Compilation.zig+44-45| ... | @@ -29,8 +29,6 @@ const wasi_libc = @import("wasi_libc.zig"); | ... | @@ -29,8 +29,6 @@ const wasi_libc = @import("wasi_libc.zig"); |
| 29 | const fatal = @import("main.zig").fatal; | 29 | const fatal = @import("main.zig").fatal; |
| 30 | const clangMain = @import("main.zig").clangMain; | 30 | const clangMain = @import("main.zig").clangMain; |
| 31 | const Zcu = @import("Zcu.zig"); | 31 | const Zcu = @import("Zcu.zig"); |
| 32 | /// Deprecated; use `Zcu`. | ||
| 33 | const Module = Zcu; | ||
| 34 | const Sema = @import("Sema.zig"); | 32 | const Sema = @import("Sema.zig"); |
| 35 | const InternPool = @import("InternPool.zig"); | 33 | const InternPool = @import("InternPool.zig"); |
| 36 | const Cache = std.Build.Cache; | 34 | const Cache = std.Build.Cache; |
| ... | @@ -50,7 +48,7 @@ gpa: Allocator, | ... | @@ -50,7 +48,7 @@ gpa: Allocator, |
| 50 | arena: Allocator, | 48 | arena: Allocator, |
| 51 | /// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`. | 49 | /// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`. |
| 52 | /// TODO: rename to zcu: ?*Zcu | 50 | /// TODO: rename to zcu: ?*Zcu |
| 53 | module: ?*Module, | 51 | module: ?*Zcu, |
| 54 | /// Contains different state depending on whether the Compilation uses | 52 | /// Contains different state depending on whether the Compilation uses |
| 55 | /// incremental or whole cache mode. | 53 | /// incremental or whole cache mode. |
| 56 | cache_use: CacheUse, | 54 | cache_use: CacheUse, |
| ... | @@ -120,7 +118,7 @@ astgen_work_queue: std.fifo.LinearFifo(Zcu.File.Index, .Dynamic), | ... | @@ -120,7 +118,7 @@ astgen_work_queue: std.fifo.LinearFifo(Zcu.File.Index, .Dynamic), |
| 120 | /// These jobs are to inspect the file system stat() and if the embedded file has changed | 118 | /// These jobs are to inspect the file system stat() and if the embedded file has changed |
| 121 | /// on disk, mark the corresponding Decl outdated and queue up an `analyze_decl` | 119 | /// on disk, mark the corresponding Decl outdated and queue up an `analyze_decl` |
| 122 | /// task for it. | 120 | /// task for it. |
| 123 | embed_file_work_queue: std.fifo.LinearFifo(*Module.EmbedFile, .Dynamic), | 121 | embed_file_work_queue: std.fifo.LinearFifo(*Zcu.EmbedFile, .Dynamic), |
| 124 | 122 | ||
| 125 | /// The ErrorMsg memory is owned by the `CObject`, using Compilation's general purpose allocator. | 123 | /// The ErrorMsg memory is owned by the `CObject`, using Compilation's general purpose allocator. |
| 126 | /// This data is accessed by multiple threads and is protected by `mutex`. | 124 | /// This data is accessed by multiple threads and is protected by `mutex`. |
| ... | @@ -252,7 +250,7 @@ pub const Emit = struct { | ... | @@ -252,7 +250,7 @@ pub const Emit = struct { |
| 252 | }; | 250 | }; |
| 253 | 251 | ||
| 254 | pub const default_stack_protector_buffer_size = target_util.default_stack_protector_buffer_size; | 252 | pub const default_stack_protector_buffer_size = target_util.default_stack_protector_buffer_size; |
| 255 | pub const SemaError = Module.SemaError; | 253 | pub const SemaError = Zcu.SemaError; |
| 256 | 254 | ||
| 257 | pub const CRTFile = struct { | 255 | pub const CRTFile = struct { |
| 258 | lock: Cache.Lock, | 256 | lock: Cache.Lock, |
| ... | @@ -1138,7 +1136,7 @@ pub const CreateOptions = struct { | ... | @@ -1138,7 +1136,7 @@ pub const CreateOptions = struct { |
| 1138 | pdb_source_path: ?[]const u8 = null, | 1136 | pdb_source_path: ?[]const u8 = null, |
| 1139 | /// (Windows) PDB output path | 1137 | /// (Windows) PDB output path |
| 1140 | pdb_out_path: ?[]const u8 = null, | 1138 | pdb_out_path: ?[]const u8 = null, |
| 1141 | error_limit: ?Compilation.Module.ErrorInt = null, | 1139 | error_limit: ?Zcu.ErrorInt = null, |
| 1142 | global_cc_argv: []const []const u8 = &.{}, | 1140 | global_cc_argv: []const []const u8 = &.{}, |
| 1143 | 1141 | ||
| 1144 | pub const Entry = link.File.OpenOptions.Entry; | 1142 | pub const Entry = link.File.OpenOptions.Entry; |
| ... | @@ -1344,7 +1342,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil | ... | @@ -1344,7 +1342,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1344 | 1342 | ||
| 1345 | const main_mod = options.main_mod orelse options.root_mod; | 1343 | const main_mod = options.main_mod orelse options.root_mod; |
| 1346 | const comp = try arena.create(Compilation); | 1344 | const comp = try arena.create(Compilation); |
| 1347 | const opt_zcu: ?*Module = if (have_zcu) blk: { | 1345 | const opt_zcu: ?*Zcu = if (have_zcu) blk: { |
| 1348 | // Pre-open the directory handles for cached ZIR code so that it does not need | 1346 | // Pre-open the directory handles for cached ZIR code so that it does not need |
| 1349 | // to redundantly happen for each AstGen operation. | 1347 | // to redundantly happen for each AstGen operation. |
| 1350 | const zir_sub_dir = "z"; | 1348 | const zir_sub_dir = "z"; |
| ... | @@ -1362,8 +1360,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil | ... | @@ -1362,8 +1360,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1362 | .path = try options.global_cache_directory.join(arena, &[_][]const u8{zir_sub_dir}), | 1360 | .path = try options.global_cache_directory.join(arena, &[_][]const u8{zir_sub_dir}), |
| 1363 | }; | 1361 | }; |
| 1364 | 1362 | ||
| 1365 | const emit_h: ?*Module.GlobalEmitH = if (options.emit_h) |loc| eh: { | 1363 | const emit_h: ?*Zcu.GlobalEmitH = if (options.emit_h) |loc| eh: { |
| 1366 | const eh = try arena.create(Module.GlobalEmitH); | 1364 | const eh = try arena.create(Zcu.GlobalEmitH); |
| 1367 | eh.* = .{ .loc = loc }; | 1365 | eh.* = .{ .loc = loc }; |
| 1368 | break :eh eh; | 1366 | break :eh eh; |
| 1369 | } else null; | 1367 | } else null; |
| ... | @@ -1386,7 +1384,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil | ... | @@ -1386,7 +1384,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1386 | .builtin_modules = null, // `builtin_mod` is set | 1384 | .builtin_modules = null, // `builtin_mod` is set |
| 1387 | }); | 1385 | }); |
| 1388 | 1386 | ||
| 1389 | const zcu = try arena.create(Module); | 1387 | const zcu = try arena.create(Zcu); |
| 1390 | zcu.* = .{ | 1388 | zcu.* = .{ |
| 1391 | .gpa = gpa, | 1389 | .gpa = gpa, |
| 1392 | .comp = comp, | 1390 | .comp = comp, |
| ... | @@ -1434,7 +1432,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil | ... | @@ -1434,7 +1432,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1434 | .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa), | 1432 | .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa), |
| 1435 | .win32_resource_work_queue = if (build_options.only_core_functionality) {} else std.fifo.LinearFifo(*Win32Resource, .Dynamic).init(gpa), | 1433 | .win32_resource_work_queue = if (build_options.only_core_functionality) {} else std.fifo.LinearFifo(*Win32Resource, .Dynamic).init(gpa), |
| 1436 | .astgen_work_queue = std.fifo.LinearFifo(Zcu.File.Index, .Dynamic).init(gpa), | 1434 | .astgen_work_queue = std.fifo.LinearFifo(Zcu.File.Index, .Dynamic).init(gpa), |
| 1437 | .embed_file_work_queue = std.fifo.LinearFifo(*Module.EmbedFile, .Dynamic).init(gpa), | 1435 | .embed_file_work_queue = std.fifo.LinearFifo(*Zcu.EmbedFile, .Dynamic).init(gpa), |
| 1438 | .c_source_files = options.c_source_files, | 1436 | .c_source_files = options.c_source_files, |
| 1439 | .rc_source_files = options.rc_source_files, | 1437 | .rc_source_files = options.rc_source_files, |
| 1440 | .cache_parent = cache, | 1438 | .cache_parent = cache, |
| ... | @@ -2626,7 +2624,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { | ... | @@ -2626,7 +2624,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { |
| 2626 | var num_errors: u32 = 0; | 2624 | var num_errors: u32 = 0; |
| 2627 | const max_errors = 5; | 2625 | const max_errors = 5; |
| 2628 | // Attach the "some omitted" note to the final error message | 2626 | // Attach the "some omitted" note to the final error message |
| 2629 | var last_err: ?*Module.ErrorMsg = null; | 2627 | var last_err: ?*Zcu.ErrorMsg = null; |
| 2630 | 2628 | ||
| 2631 | for (zcu.import_table.values(), 0..) |file, file_index_usize| { | 2629 | for (zcu.import_table.values(), 0..) |file, file_index_usize| { |
| 2632 | if (!file.multi_pkg) continue; | 2630 | if (!file.multi_pkg) continue; |
| ... | @@ -2642,13 +2640,13 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { | ... | @@ -2642,13 +2640,13 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { |
| 2642 | const omitted = file.references.items.len -| max_notes; | 2640 | const omitted = file.references.items.len -| max_notes; |
| 2643 | const num_notes = file.references.items.len - omitted; | 2641 | const num_notes = file.references.items.len - omitted; |
| 2644 | 2642 | ||
| 2645 | const notes = try gpa.alloc(Module.ErrorMsg, if (omitted > 0) num_notes + 1 else num_notes); | 2643 | const notes = try gpa.alloc(Zcu.ErrorMsg, if (omitted > 0) num_notes + 1 else num_notes); |
| 2646 | errdefer gpa.free(notes); | 2644 | errdefer gpa.free(notes); |
| 2647 | 2645 | ||
| 2648 | for (notes[0..num_notes], file.references.items[0..num_notes], 0..) |*note, ref, i| { | 2646 | for (notes[0..num_notes], file.references.items[0..num_notes], 0..) |*note, ref, i| { |
| 2649 | errdefer for (notes[0..i]) |*n| n.deinit(gpa); | 2647 | errdefer for (notes[0..i]) |*n| n.deinit(gpa); |
| 2650 | note.* = switch (ref) { | 2648 | note.* = switch (ref) { |
| 2651 | .import => |import| try Module.ErrorMsg.init( | 2649 | .import => |import| try Zcu.ErrorMsg.init( |
| 2652 | gpa, | 2650 | gpa, |
| 2653 | .{ | 2651 | .{ |
| 2654 | .base_node_inst = try ip.trackZir(gpa, import.file, .main_struct_inst), | 2652 | .base_node_inst = try ip.trackZir(gpa, import.file, .main_struct_inst), |
| ... | @@ -2657,7 +2655,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { | ... | @@ -2657,7 +2655,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { |
| 2657 | "imported from module {s}", | 2655 | "imported from module {s}", |
| 2658 | .{zcu.fileByIndex(import.file).mod.fully_qualified_name}, | 2656 | .{zcu.fileByIndex(import.file).mod.fully_qualified_name}, |
| 2659 | ), | 2657 | ), |
| 2660 | .root => |pkg| try Module.ErrorMsg.init( | 2658 | .root => |pkg| try Zcu.ErrorMsg.init( |
| 2661 | gpa, | 2659 | gpa, |
| 2662 | .{ | 2660 | .{ |
| 2663 | .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst), | 2661 | .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst), |
| ... | @@ -2671,7 +2669,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { | ... | @@ -2671,7 +2669,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { |
| 2671 | errdefer for (notes[0..num_notes]) |*n| n.deinit(gpa); | 2669 | errdefer for (notes[0..num_notes]) |*n| n.deinit(gpa); |
| 2672 | 2670 | ||
| 2673 | if (omitted > 0) { | 2671 | if (omitted > 0) { |
| 2674 | notes[num_notes] = try Module.ErrorMsg.init( | 2672 | notes[num_notes] = try Zcu.ErrorMsg.init( |
| 2675 | gpa, | 2673 | gpa, |
| 2676 | .{ | 2674 | .{ |
| 2677 | .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst), | 2675 | .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst), |
| ... | @@ -2683,7 +2681,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { | ... | @@ -2683,7 +2681,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { |
| 2683 | } | 2681 | } |
| 2684 | errdefer if (omitted > 0) notes[num_notes].deinit(gpa); | 2682 | errdefer if (omitted > 0) notes[num_notes].deinit(gpa); |
| 2685 | 2683 | ||
| 2686 | const err = try Module.ErrorMsg.create( | 2684 | const err = try Zcu.ErrorMsg.create( |
| 2687 | gpa, | 2685 | gpa, |
| 2688 | .{ | 2686 | .{ |
| 2689 | .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst), | 2687 | .base_node_inst = try ip.trackZir(gpa, file_index, .main_struct_inst), |
| ... | @@ -2706,7 +2704,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { | ... | @@ -2706,7 +2704,7 @@ fn reportMultiModuleErrors(zcu: *Zcu) !void { |
| 2706 | 2704 | ||
| 2707 | // There isn't really any meaningful place to put this note, so just attach it to the | 2705 | // There isn't really any meaningful place to put this note, so just attach it to the |
| 2708 | // last failed file | 2706 | // last failed file |
| 2709 | var note = try Module.ErrorMsg.init( | 2707 | var note = try Zcu.ErrorMsg.init( |
| 2710 | gpa, | 2708 | gpa, |
| 2711 | err.src_loc, | 2709 | err.src_loc, |
| 2712 | "{} more errors omitted", | 2710 | "{} more errors omitted", |
| ... | @@ -3095,10 +3093,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { | ... | @@ -3095,10 +3093,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3095 | const values = zcu.compile_log_sources.values(); | 3093 | const values = zcu.compile_log_sources.values(); |
| 3096 | // First one will be the error; subsequent ones will be notes. | 3094 | // First one will be the error; subsequent ones will be notes. |
| 3097 | const src_loc = values[0].src(); | 3095 | const src_loc = values[0].src(); |
| 3098 | const err_msg: Module.ErrorMsg = .{ | 3096 | const err_msg: Zcu.ErrorMsg = .{ |
| 3099 | .src_loc = src_loc, | 3097 | .src_loc = src_loc, |
| 3100 | .msg = "found compile log statement", | 3098 | .msg = "found compile log statement", |
| 3101 | .notes = try gpa.alloc(Module.ErrorMsg, zcu.compile_log_sources.count() - 1), | 3099 | .notes = try gpa.alloc(Zcu.ErrorMsg, zcu.compile_log_sources.count() - 1), |
| 3102 | }; | 3100 | }; |
| 3103 | defer gpa.free(err_msg.notes); | 3101 | defer gpa.free(err_msg.notes); |
| 3104 | 3102 | ||
| ... | @@ -3166,9 +3164,9 @@ pub const ErrorNoteHashContext = struct { | ... | @@ -3166,9 +3164,9 @@ pub const ErrorNoteHashContext = struct { |
| 3166 | }; | 3164 | }; |
| 3167 | 3165 | ||
| 3168 | pub fn addModuleErrorMsg( | 3166 | pub fn addModuleErrorMsg( |
| 3169 | mod: *Module, | 3167 | mod: *Zcu, |
| 3170 | eb: *ErrorBundle.Wip, | 3168 | eb: *ErrorBundle.Wip, |
| 3171 | module_err_msg: Module.ErrorMsg, | 3169 | module_err_msg: Zcu.ErrorMsg, |
| 3172 | all_references: *const std.AutoHashMapUnmanaged(InternPool.AnalUnit, Zcu.ResolvedReference), | 3170 | all_references: *const std.AutoHashMapUnmanaged(InternPool.AnalUnit, Zcu.ResolvedReference), |
| 3173 | ) !void { | 3171 | ) !void { |
| 3174 | const gpa = eb.gpa; | 3172 | const gpa = eb.gpa; |
| ... | @@ -3299,7 +3297,7 @@ pub fn addModuleErrorMsg( | ... | @@ -3299,7 +3297,7 @@ pub fn addModuleErrorMsg( |
| 3299 | } | 3297 | } |
| 3300 | } | 3298 | } |
| 3301 | 3299 | ||
| 3302 | pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void { | 3300 | pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Zcu.File) !void { |
| 3303 | assert(file.zir_loaded); | 3301 | assert(file.zir_loaded); |
| 3304 | assert(file.tree_loaded); | 3302 | assert(file.tree_loaded); |
| 3305 | assert(file.source_loaded); | 3303 | assert(file.source_loaded); |
| ... | @@ -3378,7 +3376,7 @@ pub fn performAllTheWork( | ... | @@ -3378,7 +3376,7 @@ pub fn performAllTheWork( |
| 3378 | const path_digest = zcu.filePathDigest(file_index); | 3376 | const path_digest = zcu.filePathDigest(file_index); |
| 3379 | const root_decl = zcu.fileRootDecl(file_index); | 3377 | const root_decl = zcu.fileRootDecl(file_index); |
| 3380 | const file = zcu.fileByIndex(file_index); | 3378 | const file = zcu.fileByIndex(file_index); |
| 3381 | comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerAstGenFile, .{ | 3379 | comp.thread_pool.spawnWgId(&comp.astgen_wait_group, workerAstGenFile, .{ |
| 3382 | comp, file, file_index, path_digest, root_decl, zir_prog_node, &comp.astgen_wait_group, .root, | 3380 | comp, file, file_index, path_digest, root_decl, zir_prog_node, &comp.astgen_wait_group, .root, |
| 3383 | }); | 3381 | }); |
| 3384 | } | 3382 | } |
| ... | @@ -3587,22 +3585,22 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre | ... | @@ -3587,22 +3585,22 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre |
| 3587 | defer named_frame.end(); | 3585 | defer named_frame.end(); |
| 3588 | 3586 | ||
| 3589 | const gpa = comp.gpa; | 3587 | const gpa = comp.gpa; |
| 3590 | const zcu = comp.module.?; | 3588 | const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) }; |
| 3591 | const decl = zcu.declPtr(decl_index); | 3589 | const decl = pt.zcu.declPtr(decl_index); |
| 3592 | const lf = comp.bin_file.?; | 3590 | const lf = comp.bin_file.?; |
| 3593 | lf.updateDeclLineNumber(zcu, decl_index) catch |err| { | 3591 | lf.updateDeclLineNumber(pt, decl_index) catch |err| { |
| 3594 | try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1); | 3592 | try pt.zcu.failed_analysis.ensureUnusedCapacity(gpa, 1); |
| 3595 | zcu.failed_analysis.putAssumeCapacityNoClobber( | 3593 | pt.zcu.failed_analysis.putAssumeCapacityNoClobber( |
| 3596 | InternPool.AnalUnit.wrap(.{ .decl = decl_index }), | 3594 | InternPool.AnalUnit.wrap(.{ .decl = decl_index }), |
| 3597 | try Zcu.ErrorMsg.create( | 3595 | try Zcu.ErrorMsg.create( |
| 3598 | gpa, | 3596 | gpa, |
| 3599 | decl.navSrcLoc(zcu), | 3597 | decl.navSrcLoc(pt.zcu), |
| 3600 | "unable to update line number: {s}", | 3598 | "unable to update line number: {s}", |
| 3601 | .{@errorName(err)}, | 3599 | .{@errorName(err)}, |
| 3602 | ), | 3600 | ), |
| 3603 | ); | 3601 | ); |
| 3604 | decl.analysis = .codegen_failure; | 3602 | decl.analysis = .codegen_failure; |
| 3605 | try zcu.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index })); | 3603 | try pt.zcu.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index })); |
| 3606 | }; | 3604 | }; |
| 3607 | }, | 3605 | }, |
| 3608 | .analyze_mod => |mod| { | 3606 | .analyze_mod => |mod| { |
| ... | @@ -4049,6 +4047,7 @@ const AstGenSrc = union(enum) { | ... | @@ -4049,6 +4047,7 @@ const AstGenSrc = union(enum) { |
| 4049 | }; | 4047 | }; |
| 4050 | 4048 | ||
| 4051 | fn workerAstGenFile( | 4049 | fn workerAstGenFile( |
| 4050 | tid: usize, | ||
| 4052 | comp: *Compilation, | 4051 | comp: *Compilation, |
| 4053 | file: *Zcu.File, | 4052 | file: *Zcu.File, |
| 4054 | file_index: Zcu.File.Index, | 4053 | file_index: Zcu.File.Index, |
| ... | @@ -4061,8 +4060,8 @@ fn workerAstGenFile( | ... | @@ -4061,8 +4060,8 @@ fn workerAstGenFile( |
| 4061 | const child_prog_node = prog_node.start(file.sub_file_path, 0); | 4060 | const child_prog_node = prog_node.start(file.sub_file_path, 0); |
| 4062 | defer child_prog_node.end(); | 4061 | defer child_prog_node.end(); |
| 4063 | 4062 | ||
| 4064 | const zcu = comp.module.?; | 4063 | const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) }; |
| 4065 | zcu.astGenFile(file, file_index, path_digest, root_decl) catch |err| switch (err) { | 4064 | pt.astGenFile(file, file_index, path_digest, root_decl) catch |err| switch (err) { |
| 4066 | error.AnalysisFail => return, | 4065 | error.AnalysisFail => return, |
| 4067 | else => { | 4066 | else => { |
| 4068 | file.status = .retryable_failure; | 4067 | file.status = .retryable_failure; |
| ... | @@ -4097,15 +4096,15 @@ fn workerAstGenFile( | ... | @@ -4097,15 +4096,15 @@ fn workerAstGenFile( |
| 4097 | comp.mutex.lock(); | 4096 | comp.mutex.lock(); |
| 4098 | defer comp.mutex.unlock(); | 4097 | defer comp.mutex.unlock(); |
| 4099 | 4098 | ||
| 4100 | const res = zcu.importFile(file, import_path) catch continue; | 4099 | const res = pt.zcu.importFile(file, import_path) catch continue; |
| 4101 | if (!res.is_pkg) { | 4100 | if (!res.is_pkg) { |
| 4102 | res.file.addReference(zcu.*, .{ .import = .{ | 4101 | res.file.addReference(pt.zcu.*, .{ .import = .{ |
| 4103 | .file = file_index, | 4102 | .file = file_index, |
| 4104 | .token = item.data.token, | 4103 | .token = item.data.token, |
| 4105 | } }) catch continue; | 4104 | } }) catch continue; |
| 4106 | } | 4105 | } |
| 4107 | const imported_path_digest = zcu.filePathDigest(res.file_index); | 4106 | const imported_path_digest = pt.zcu.filePathDigest(res.file_index); |
| 4108 | const imported_root_decl = zcu.fileRootDecl(res.file_index); | 4107 | const imported_root_decl = pt.zcu.fileRootDecl(res.file_index); |
| 4109 | break :blk .{ res, imported_path_digest, imported_root_decl }; | 4108 | break :blk .{ res, imported_path_digest, imported_root_decl }; |
| 4110 | }; | 4109 | }; |
| 4111 | if (import_result.is_new) { | 4110 | if (import_result.is_new) { |
| ... | @@ -4116,7 +4115,7 @@ fn workerAstGenFile( | ... | @@ -4116,7 +4115,7 @@ fn workerAstGenFile( |
| 4116 | .importing_file = file_index, | 4115 | .importing_file = file_index, |
| 4117 | .import_tok = item.data.token, | 4116 | .import_tok = item.data.token, |
| 4118 | } }; | 4117 | } }; |
| 4119 | comp.thread_pool.spawnWg(wg, workerAstGenFile, .{ | 4118 | comp.thread_pool.spawnWgId(wg, workerAstGenFile, .{ |
| 4120 | comp, import_result.file, import_result.file_index, imported_path_digest, imported_root_decl, prog_node, wg, sub_src, | 4119 | comp, import_result.file, import_result.file_index, imported_path_digest, imported_root_decl, prog_node, wg, sub_src, |
| 4121 | }); | 4120 | }); |
| 4122 | } | 4121 | } |
| ... | @@ -4127,7 +4126,7 @@ fn workerAstGenFile( | ... | @@ -4127,7 +4126,7 @@ fn workerAstGenFile( |
| 4127 | fn workerUpdateBuiltinZigFile( | 4126 | fn workerUpdateBuiltinZigFile( |
| 4128 | comp: *Compilation, | 4127 | comp: *Compilation, |
| 4129 | mod: *Package.Module, | 4128 | mod: *Package.Module, |
| 4130 | file: *Module.File, | 4129 | file: *Zcu.File, |
| 4131 | ) void { | 4130 | ) void { |
| 4132 | Builtin.populateFile(comp, mod, file) catch |err| { | 4131 | Builtin.populateFile(comp, mod, file) catch |err| { |
| 4133 | comp.mutex.lock(); | 4132 | comp.mutex.lock(); |
| ... | @@ -4139,7 +4138,7 @@ fn workerUpdateBuiltinZigFile( | ... | @@ -4139,7 +4138,7 @@ fn workerUpdateBuiltinZigFile( |
| 4139 | }; | 4138 | }; |
| 4140 | } | 4139 | } |
| 4141 | 4140 | ||
| 4142 | fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Module.EmbedFile) void { | 4141 | fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Zcu.EmbedFile) void { |
| 4143 | comp.detectEmbedFileUpdate(embed_file) catch |err| { | 4142 | comp.detectEmbedFileUpdate(embed_file) catch |err| { |
| 4144 | comp.reportRetryableEmbedFileError(embed_file, err) catch |oom| switch (oom) { | 4143 | comp.reportRetryableEmbedFileError(embed_file, err) catch |oom| switch (oom) { |
| 4145 | // Swallowing this error is OK because it's implied to be OOM when | 4144 | // Swallowing this error is OK because it's implied to be OOM when |
| ... | @@ -4150,7 +4149,7 @@ fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Module.EmbedFile) void | ... | @@ -4150,7 +4149,7 @@ fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Module.EmbedFile) void |
| 4150 | }; | 4149 | }; |
| 4151 | } | 4150 | } |
| 4152 | 4151 | ||
| 4153 | fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Module.EmbedFile) !void { | 4152 | fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Zcu.EmbedFile) !void { |
| 4154 | const mod = comp.module.?; | 4153 | const mod = comp.module.?; |
| 4155 | const ip = &mod.intern_pool; | 4154 | const ip = &mod.intern_pool; |
| 4156 | var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{}); | 4155 | var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{}); |
| ... | @@ -4477,7 +4476,7 @@ fn reportRetryableAstGenError( | ... | @@ -4477,7 +4476,7 @@ fn reportRetryableAstGenError( |
| 4477 | const file = zcu.fileByIndex(file_index); | 4476 | const file = zcu.fileByIndex(file_index); |
| 4478 | file.status = .retryable_failure; | 4477 | file.status = .retryable_failure; |
| 4479 | 4478 | ||
| 4480 | const src_loc: Module.LazySrcLoc = switch (src) { | 4479 | const src_loc: Zcu.LazySrcLoc = switch (src) { |
| 4481 | .root => .{ | 4480 | .root => .{ |
| 4482 | .base_node_inst = try zcu.intern_pool.trackZir(gpa, file_index, .main_struct_inst), | 4481 | .base_node_inst = try zcu.intern_pool.trackZir(gpa, file_index, .main_struct_inst), |
| 4483 | .offset = .entire_file, | 4482 | .offset = .entire_file, |
| ... | @@ -4488,7 +4487,7 @@ fn reportRetryableAstGenError( | ... | @@ -4488,7 +4487,7 @@ fn reportRetryableAstGenError( |
| 4488 | }, | 4487 | }, |
| 4489 | }; | 4488 | }; |
| 4490 | 4489 | ||
| 4491 | const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{ | 4490 | const err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{ |
| 4492 | file.mod.root, file.sub_file_path, @errorName(err), | 4491 | file.mod.root, file.sub_file_path, @errorName(err), |
| 4493 | }); | 4492 | }); |
| 4494 | errdefer err_msg.destroy(gpa); | 4493 | errdefer err_msg.destroy(gpa); |
| ... | @@ -4502,14 +4501,14 @@ fn reportRetryableAstGenError( | ... | @@ -4502,14 +4501,14 @@ fn reportRetryableAstGenError( |
| 4502 | 4501 | ||
| 4503 | fn reportRetryableEmbedFileError( | 4502 | fn reportRetryableEmbedFileError( |
| 4504 | comp: *Compilation, | 4503 | comp: *Compilation, |
| 4505 | embed_file: *Module.EmbedFile, | 4504 | embed_file: *Zcu.EmbedFile, |
| 4506 | err: anyerror, | 4505 | err: anyerror, |
| 4507 | ) error{OutOfMemory}!void { | 4506 | ) error{OutOfMemory}!void { |
| 4508 | const mod = comp.module.?; | 4507 | const mod = comp.module.?; |
| 4509 | const gpa = mod.gpa; | 4508 | const gpa = mod.gpa; |
| 4510 | const src_loc = embed_file.src_loc; | 4509 | const src_loc = embed_file.src_loc; |
| 4511 | const ip = &mod.intern_pool; | 4510 | const ip = &mod.intern_pool; |
| 4512 | const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{ | 4511 | const err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{ |
| 4513 | embed_file.owner.root, | 4512 | embed_file.owner.root, |
| 4514 | embed_file.sub_file_path.toSlice(ip), | 4513 | embed_file.sub_file_path.toSlice(ip), |
| 4515 | @errorName(err), | 4514 | @errorName(err), |
src/InternPool.zig+15-6| ... | @@ -4539,7 +4539,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void { | ... | @@ -4539,7 +4539,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void { |
| 4539 | assert(ip.items.len == 0); | 4539 | assert(ip.items.len == 0); |
| 4540 | 4540 | ||
| 4541 | // Reserve string index 0 for an empty string. | 4541 | // Reserve string index 0 for an empty string. |
| 4542 | assert((try ip.getOrPutString(gpa, "", .no_embedded_nulls)) == .empty); | 4542 | assert((try ip.getOrPutString(gpa, .main, "", .no_embedded_nulls)) == .empty); |
| 4543 | 4543 | ||
| 4544 | // So that we can use `catch unreachable` below. | 4544 | // So that we can use `catch unreachable` below. |
| 4545 | try ip.items.ensureUnusedCapacity(gpa, static_keys.len); | 4545 | try ip.items.ensureUnusedCapacity(gpa, static_keys.len); |
| ... | @@ -5986,6 +5986,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All | ... | @@ -5986,6 +5986,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5986 | ); | 5986 | ); |
| 5987 | const string = try ip.getOrPutTrailingString( | 5987 | const string = try ip.getOrPutTrailingString( |
| 5988 | gpa, | 5988 | gpa, |
| 5989 | tid, | ||
| 5989 | @intCast(len_including_sentinel), | 5990 | @intCast(len_including_sentinel), |
| 5990 | .maybe_embedded_nulls, | 5991 | .maybe_embedded_nulls, |
| 5991 | ); | 5992 | ); |
| ... | @@ -6865,6 +6866,7 @@ pub fn getFuncInstance( | ... | @@ -6865,6 +6866,7 @@ pub fn getFuncInstance( |
| 6865 | return finishFuncInstance( | 6866 | return finishFuncInstance( |
| 6866 | ip, | 6867 | ip, |
| 6867 | gpa, | 6868 | gpa, |
| 6869 | tid, | ||
| 6868 | generic_owner, | 6870 | generic_owner, |
| 6869 | func_index, | 6871 | func_index, |
| 6870 | func_extra_index, | 6872 | func_extra_index, |
| ... | @@ -6879,7 +6881,7 @@ pub fn getFuncInstance( | ... | @@ -6879,7 +6881,7 @@ pub fn getFuncInstance( |
| 6879 | pub fn getFuncInstanceIes( | 6881 | pub fn getFuncInstanceIes( |
| 6880 | ip: *InternPool, | 6882 | ip: *InternPool, |
| 6881 | gpa: Allocator, | 6883 | gpa: Allocator, |
| 6882 | _: Zcu.PerThread.Id, | 6884 | tid: Zcu.PerThread.Id, |
| 6883 | arg: GetFuncInstanceKey, | 6885 | arg: GetFuncInstanceKey, |
| 6884 | ) Allocator.Error!Index { | 6886 | ) Allocator.Error!Index { |
| 6885 | // Validate input parameters. | 6887 | // Validate input parameters. |
| ... | @@ -6994,6 +6996,7 @@ pub fn getFuncInstanceIes( | ... | @@ -6994,6 +6996,7 @@ pub fn getFuncInstanceIes( |
| 6994 | return finishFuncInstance( | 6996 | return finishFuncInstance( |
| 6995 | ip, | 6997 | ip, |
| 6996 | gpa, | 6998 | gpa, |
| 6999 | tid, | ||
| 6997 | generic_owner, | 7000 | generic_owner, |
| 6998 | func_index, | 7001 | func_index, |
| 6999 | func_extra_index, | 7002 | func_extra_index, |
| ... | @@ -7005,6 +7008,7 @@ pub fn getFuncInstanceIes( | ... | @@ -7005,6 +7008,7 @@ pub fn getFuncInstanceIes( |
| 7005 | fn finishFuncInstance( | 7008 | fn finishFuncInstance( |
| 7006 | ip: *InternPool, | 7009 | ip: *InternPool, |
| 7007 | gpa: Allocator, | 7010 | gpa: Allocator, |
| 7011 | tid: Zcu.PerThread.Id, | ||
| 7008 | generic_owner: Index, | 7012 | generic_owner: Index, |
| 7009 | func_index: Index, | 7013 | func_index: Index, |
| 7010 | func_extra_index: u32, | 7014 | func_extra_index: u32, |
| ... | @@ -7036,7 +7040,7 @@ fn finishFuncInstance( | ... | @@ -7036,7 +7040,7 @@ fn finishFuncInstance( |
| 7036 | 7040 | ||
| 7037 | // TODO: improve this name | 7041 | // TODO: improve this name |
| 7038 | const decl = ip.declPtr(decl_index); | 7042 | const decl = ip.declPtr(decl_index); |
| 7039 | decl.name = try ip.getOrPutStringFmt(gpa, "{}__anon_{d}", .{ | 7043 | decl.name = try ip.getOrPutStringFmt(gpa, tid, "{}__anon_{d}", .{ |
| 7040 | fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index), | 7044 | fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index), |
| 7041 | }, .no_embedded_nulls); | 7045 | }, .no_embedded_nulls); |
| 7042 | 7046 | ||
| ... | @@ -8782,18 +8786,20 @@ const EmbeddedNulls = enum { | ... | @@ -8782,18 +8786,20 @@ const EmbeddedNulls = enum { |
| 8782 | pub fn getOrPutString( | 8786 | pub fn getOrPutString( |
| 8783 | ip: *InternPool, | 8787 | ip: *InternPool, |
| 8784 | gpa: Allocator, | 8788 | gpa: Allocator, |
| 8789 | tid: Zcu.PerThread.Id, | ||
| 8785 | slice: []const u8, | 8790 | slice: []const u8, |
| 8786 | comptime embedded_nulls: EmbeddedNulls, | 8791 | comptime embedded_nulls: EmbeddedNulls, |
| 8787 | ) Allocator.Error!embedded_nulls.StringType() { | 8792 | ) Allocator.Error!embedded_nulls.StringType() { |
| 8788 | try ip.string_bytes.ensureUnusedCapacity(gpa, slice.len + 1); | 8793 | try ip.string_bytes.ensureUnusedCapacity(gpa, slice.len + 1); |
| 8789 | ip.string_bytes.appendSliceAssumeCapacity(slice); | 8794 | ip.string_bytes.appendSliceAssumeCapacity(slice); |
| 8790 | ip.string_bytes.appendAssumeCapacity(0); | 8795 | ip.string_bytes.appendAssumeCapacity(0); |
| 8791 | return ip.getOrPutTrailingString(gpa, slice.len + 1, embedded_nulls); | 8796 | return ip.getOrPutTrailingString(gpa, tid, slice.len + 1, embedded_nulls); |
| 8792 | } | 8797 | } |
| 8793 | 8798 | ||
| 8794 | pub fn getOrPutStringFmt( | 8799 | pub fn getOrPutStringFmt( |
| 8795 | ip: *InternPool, | 8800 | ip: *InternPool, |
| 8796 | gpa: Allocator, | 8801 | gpa: Allocator, |
| 8802 | tid: Zcu.PerThread.Id, | ||
| 8797 | comptime format: []const u8, | 8803 | comptime format: []const u8, |
| 8798 | args: anytype, | 8804 | args: anytype, |
| 8799 | comptime embedded_nulls: EmbeddedNulls, | 8805 | comptime embedded_nulls: EmbeddedNulls, |
| ... | @@ -8803,16 +8809,17 @@ pub fn getOrPutStringFmt( | ... | @@ -8803,16 +8809,17 @@ pub fn getOrPutStringFmt( |
| 8803 | try ip.string_bytes.ensureUnusedCapacity(gpa, len); | 8809 | try ip.string_bytes.ensureUnusedCapacity(gpa, len); |
| 8804 | ip.string_bytes.writer(undefined).print(format, args) catch unreachable; | 8810 | ip.string_bytes.writer(undefined).print(format, args) catch unreachable; |
| 8805 | ip.string_bytes.appendAssumeCapacity(0); | 8811 | ip.string_bytes.appendAssumeCapacity(0); |
| 8806 | return ip.getOrPutTrailingString(gpa, len, embedded_nulls); | 8812 | return ip.getOrPutTrailingString(gpa, tid, len, embedded_nulls); |
| 8807 | } | 8813 | } |
| 8808 | 8814 | ||
| 8809 | pub fn getOrPutStringOpt( | 8815 | pub fn getOrPutStringOpt( |
| 8810 | ip: *InternPool, | 8816 | ip: *InternPool, |
| 8811 | gpa: Allocator, | 8817 | gpa: Allocator, |
| 8818 | tid: Zcu.PerThread.Id, | ||
| 8812 | slice: ?[]const u8, | 8819 | slice: ?[]const u8, |
| 8813 | comptime embedded_nulls: EmbeddedNulls, | 8820 | comptime embedded_nulls: EmbeddedNulls, |
| 8814 | ) Allocator.Error!embedded_nulls.OptionalStringType() { | 8821 | ) Allocator.Error!embedded_nulls.OptionalStringType() { |
| 8815 | const string = try getOrPutString(ip, gpa, slice orelse return .none, embedded_nulls); | 8822 | const string = try getOrPutString(ip, gpa, tid, slice orelse return .none, embedded_nulls); |
| 8816 | return string.toOptional(); | 8823 | return string.toOptional(); |
| 8817 | } | 8824 | } |
| 8818 | 8825 | ||
| ... | @@ -8820,9 +8827,11 @@ pub fn getOrPutStringOpt( | ... | @@ -8820,9 +8827,11 @@ pub fn getOrPutStringOpt( |
| 8820 | pub fn getOrPutTrailingString( | 8827 | pub fn getOrPutTrailingString( |
| 8821 | ip: *InternPool, | 8828 | ip: *InternPool, |
| 8822 | gpa: Allocator, | 8829 | gpa: Allocator, |
| 8830 | tid: Zcu.PerThread.Id, | ||
| 8823 | len: usize, | 8831 | len: usize, |
| 8824 | comptime embedded_nulls: EmbeddedNulls, | 8832 | comptime embedded_nulls: EmbeddedNulls, |
| 8825 | ) Allocator.Error!embedded_nulls.StringType() { | 8833 | ) Allocator.Error!embedded_nulls.StringType() { |
| 8834 | _ = tid; | ||
| 8826 | const string_bytes = &ip.string_bytes; | 8835 | const string_bytes = &ip.string_bytes; |
| 8827 | const str_index: u32 = @intCast(string_bytes.items.len - len); | 8836 | const str_index: u32 = @intCast(string_bytes.items.len - len); |
| 8828 | if (len > 0 and string_bytes.getLast() == 0) { | 8837 | if (len > 0 and string_bytes.getLast() == 0) { |
src/Sema.zig+141-121| ... | @@ -2093,12 +2093,12 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) | ... | @@ -2093,12 +2093,12 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2093 | const st_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(stack_trace_ty)); | 2093 | const st_ptr = try err_trace_block.addTy(.alloc, try pt.singleMutPtrType(stack_trace_ty)); |
| 2094 | 2094 | ||
| 2095 | // st.instruction_addresses = &addrs; | 2095 | // st.instruction_addresses = &addrs; |
| 2096 | const instruction_addresses_field_name = try ip.getOrPutString(gpa, "instruction_addresses", .no_embedded_nulls); | 2096 | const instruction_addresses_field_name = try ip.getOrPutString(gpa, pt.tid, "instruction_addresses", .no_embedded_nulls); |
| 2097 | const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, instruction_addresses_field_name, src, true); | 2097 | const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, instruction_addresses_field_name, src, true); |
| 2098 | try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store); | 2098 | try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store); |
| 2099 | 2099 | ||
| 2100 | // st.index = 0; | 2100 | // st.index = 0; |
| 2101 | const index_field_name = try ip.getOrPutString(gpa, "index", .no_embedded_nulls); | 2101 | const index_field_name = try ip.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls); |
| 2102 | const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, index_field_name, src, true); | 2102 | const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, index_field_name, src, true); |
| 2103 | try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store); | 2103 | try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store); |
| 2104 | 2104 | ||
| ... | @@ -2691,6 +2691,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us | ... | @@ -2691,6 +2691,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2691 | .decl_val => |str| capture: { | 2691 | .decl_val => |str| capture: { |
| 2692 | const decl_name = try ip.getOrPutString( | 2692 | const decl_name = try ip.getOrPutString( |
| 2693 | sema.gpa, | 2693 | sema.gpa, |
| 2694 | pt.tid, | ||
| 2694 | sema.code.nullTerminatedString(str), | 2695 | sema.code.nullTerminatedString(str), |
| 2695 | .no_embedded_nulls, | 2696 | .no_embedded_nulls, |
| 2696 | ); | 2697 | ); |
| ... | @@ -2700,6 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us | ... | @@ -2700,6 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2700 | .decl_ref => |str| capture: { | 2701 | .decl_ref => |str| capture: { |
| 2701 | const decl_name = try ip.getOrPutString( | 2702 | const decl_name = try ip.getOrPutString( |
| 2702 | sema.gpa, | 2703 | sema.gpa, |
| 2704 | pt.tid, | ||
| 2703 | sema.code.nullTerminatedString(str), | 2705 | sema.code.nullTerminatedString(str), |
| 2704 | .no_embedded_nulls, | 2706 | .no_embedded_nulls, |
| 2705 | ); | 2707 | ); |
| ... | @@ -2847,7 +2849,7 @@ fn zirStructDecl( | ... | @@ -2847,7 +2849,7 @@ fn zirStructDecl( |
| 2847 | 2849 | ||
| 2848 | if (new_namespace_index.unwrap()) |ns| { | 2850 | if (new_namespace_index.unwrap()) |ns| { |
| 2849 | const decls = sema.code.bodySlice(extra_index, decls_len); | 2851 | const decls = sema.code.bodySlice(extra_index, decls_len); |
| 2850 | try mod.scanNamespace(ns, decls, mod.declPtr(new_decl_index)); | 2852 | try pt.scanNamespace(ns, decls, mod.declPtr(new_decl_index)); |
| 2851 | } | 2853 | } |
| 2852 | 2854 | ||
| 2853 | try pt.finalizeAnonDecl(new_decl_index); | 2855 | try pt.finalizeAnonDecl(new_decl_index); |
| ... | @@ -2919,7 +2921,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2919,7 +2921,7 @@ fn createAnonymousDeclTypeNamed( |
| 2919 | }; | 2921 | }; |
| 2920 | 2922 | ||
| 2921 | try writer.writeByte(')'); | 2923 | try writer.writeByte(')'); |
| 2922 | const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls); | 2924 | const name = try ip.getOrPutString(gpa, pt.tid, buf.items, .no_embedded_nulls); |
| 2923 | try zcu.initNewAnonDecl(new_decl_index, val, name); | 2925 | try zcu.initNewAnonDecl(new_decl_index, val, name); |
| 2924 | return new_decl_index; | 2926 | return new_decl_index; |
| 2925 | }, | 2927 | }, |
| ... | @@ -2931,7 +2933,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2931,7 +2933,7 @@ fn createAnonymousDeclTypeNamed( |
| 2931 | .dbg_var_ptr, .dbg_var_val => { | 2933 | .dbg_var_ptr, .dbg_var_val => { |
| 2932 | if (zir_data[i].str_op.operand != ref) continue; | 2934 | if (zir_data[i].str_op.operand != ref) continue; |
| 2933 | 2935 | ||
| 2934 | const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{ | 2936 | const name = try ip.getOrPutStringFmt(gpa, pt.tid, "{}.{s}", .{ |
| 2935 | block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code), | 2937 | block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code), |
| 2936 | }, .no_embedded_nulls); | 2938 | }, .no_embedded_nulls); |
| 2937 | try zcu.initNewAnonDecl(new_decl_index, val, name); | 2939 | try zcu.initNewAnonDecl(new_decl_index, val, name); |
| ... | @@ -2952,7 +2954,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2952,7 +2954,7 @@ fn createAnonymousDeclTypeNamed( |
| 2952 | // This name is also used as the key in the parent namespace so it cannot be | 2954 | // This name is also used as the key in the parent namespace so it cannot be |
| 2953 | // renamed. | 2955 | // renamed. |
| 2954 | 2956 | ||
| 2955 | const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{ | 2957 | const name = ip.getOrPutStringFmt(gpa, pt.tid, "{}__{s}_{d}", .{ |
| 2956 | block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index), | 2958 | block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index), |
| 2957 | }, .no_embedded_nulls) catch unreachable; | 2959 | }, .no_embedded_nulls) catch unreachable; |
| 2958 | try zcu.initNewAnonDecl(new_decl_index, val, name); | 2960 | try zcu.initNewAnonDecl(new_decl_index, val, name); |
| ... | @@ -3084,7 +3086,7 @@ fn zirEnumDecl( | ... | @@ -3084,7 +3086,7 @@ fn zirEnumDecl( |
| 3084 | errdefer if (!done) if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); | 3086 | errdefer if (!done) if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); |
| 3085 | 3087 | ||
| 3086 | if (new_namespace_index.unwrap()) |ns| { | 3088 | if (new_namespace_index.unwrap()) |ns| { |
| 3087 | try mod.scanNamespace(ns, decls, new_decl); | 3089 | try pt.scanNamespace(ns, decls, new_decl); |
| 3088 | } | 3090 | } |
| 3089 | 3091 | ||
| 3090 | // We've finished the initial construction of this type, and are about to perform analysis. | 3092 | // We've finished the initial construction of this type, and are about to perform analysis. |
| ... | @@ -3169,7 +3171,7 @@ fn zirEnumDecl( | ... | @@ -3169,7 +3171,7 @@ fn zirEnumDecl( |
| 3169 | const field_name_zir = sema.code.nullTerminatedString(field_name_index); | 3171 | const field_name_zir = sema.code.nullTerminatedString(field_name_index); |
| 3170 | extra_index += 2; // field name, doc comment | 3172 | extra_index += 2; // field name, doc comment |
| 3171 | 3173 | ||
| 3172 | const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); | 3174 | const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls); |
| 3173 | 3175 | ||
| 3174 | const value_src: LazySrcLoc = .{ | 3176 | const value_src: LazySrcLoc = .{ |
| 3175 | .base_node_inst = tracked_inst, | 3177 | .base_node_inst = tracked_inst, |
| ... | @@ -3352,7 +3354,7 @@ fn zirUnionDecl( | ... | @@ -3352,7 +3354,7 @@ fn zirUnionDecl( |
| 3352 | 3354 | ||
| 3353 | if (new_namespace_index.unwrap()) |ns| { | 3355 | if (new_namespace_index.unwrap()) |ns| { |
| 3354 | const decls = sema.code.bodySlice(extra_index, decls_len); | 3356 | const decls = sema.code.bodySlice(extra_index, decls_len); |
| 3355 | try mod.scanNamespace(ns, decls, mod.declPtr(new_decl_index)); | 3357 | try pt.scanNamespace(ns, decls, mod.declPtr(new_decl_index)); |
| 3356 | } | 3358 | } |
| 3357 | 3359 | ||
| 3358 | try pt.finalizeAnonDecl(new_decl_index); | 3360 | try pt.finalizeAnonDecl(new_decl_index); |
| ... | @@ -3441,7 +3443,7 @@ fn zirOpaqueDecl( | ... | @@ -3441,7 +3443,7 @@ fn zirOpaqueDecl( |
| 3441 | 3443 | ||
| 3442 | if (new_namespace_index.unwrap()) |ns| { | 3444 | if (new_namespace_index.unwrap()) |ns| { |
| 3443 | const decls = sema.code.bodySlice(extra_index, decls_len); | 3445 | const decls = sema.code.bodySlice(extra_index, decls_len); |
| 3444 | try mod.scanNamespace(ns, decls, mod.declPtr(new_decl_index)); | 3446 | try pt.scanNamespace(ns, decls, mod.declPtr(new_decl_index)); |
| 3445 | } | 3447 | } |
| 3446 | 3448 | ||
| 3447 | try pt.finalizeAnonDecl(new_decl_index); | 3449 | try pt.finalizeAnonDecl(new_decl_index); |
| ... | @@ -3470,7 +3472,7 @@ fn zirErrorSetDecl( | ... | @@ -3470,7 +3472,7 @@ fn zirErrorSetDecl( |
| 3470 | while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string | 3472 | while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string |
| 3471 | const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]); | 3473 | const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]); |
| 3472 | const name = sema.code.nullTerminatedString(name_index); | 3474 | const name = sema.code.nullTerminatedString(name_index); |
| 3473 | const name_ip = try mod.intern_pool.getOrPutString(gpa, name, .no_embedded_nulls); | 3475 | const name_ip = try mod.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls); |
| 3474 | _ = try mod.getErrorValue(name_ip); | 3476 | _ = try mod.getErrorValue(name_ip); |
| 3475 | const result = names.getOrPutAssumeCapacity(name_ip); | 3477 | const result = names.getOrPutAssumeCapacity(name_ip); |
| 3476 | assert(!result.found_existing); // verified in AstGen | 3478 | assert(!result.found_existing); // verified in AstGen |
| ... | @@ -3634,7 +3636,7 @@ fn indexablePtrLen( | ... | @@ -3634,7 +3636,7 @@ fn indexablePtrLen( |
| 3634 | const is_pointer_to = object_ty.isSinglePointer(mod); | 3636 | const is_pointer_to = object_ty.isSinglePointer(mod); |
| 3635 | const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty; | 3637 | const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty; |
| 3636 | try checkIndexable(sema, block, src, indexable_ty); | 3638 | try checkIndexable(sema, block, src, indexable_ty); |
| 3637 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len", .no_embedded_nulls); | 3639 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls); |
| 3638 | return sema.fieldVal(block, src, object, field_name, src); | 3640 | return sema.fieldVal(block, src, object, field_name, src); |
| 3639 | } | 3641 | } |
| 3640 | 3642 | ||
| ... | @@ -3649,7 +3651,7 @@ fn indexablePtrLenOrNone( | ... | @@ -3649,7 +3651,7 @@ fn indexablePtrLenOrNone( |
| 3649 | const operand_ty = sema.typeOf(operand); | 3651 | const operand_ty = sema.typeOf(operand); |
| 3650 | try checkMemOperand(sema, block, src, operand_ty); | 3652 | try checkMemOperand(sema, block, src, operand_ty); |
| 3651 | if (operand_ty.ptrSize(mod) == .Many) return .none; | 3653 | if (operand_ty.ptrSize(mod) == .Many) return .none; |
| 3652 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len", .no_embedded_nulls); | 3654 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls); |
| 3653 | return sema.fieldVal(block, src, operand, field_name, src); | 3655 | return sema.fieldVal(block, src, operand, field_name, src); |
| 3654 | } | 3656 | } |
| 3655 | 3657 | ||
| ... | @@ -4405,7 +4407,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4405,7 +4407,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4405 | } | 4407 | } |
| 4406 | if (!object_ty.indexableHasLen(mod)) continue; | 4408 | if (!object_ty.indexableHasLen(mod)) continue; |
| 4407 | 4409 | ||
| 4408 | break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, "len", .no_embedded_nulls), arg_src); | 4410 | break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), arg_src); |
| 4409 | }; | 4411 | }; |
| 4410 | const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src); | 4412 | const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src); |
| 4411 | if (len == .none) { | 4413 | if (len == .none) { |
| ... | @@ -4797,6 +4799,7 @@ fn validateUnionInit( | ... | @@ -4797,6 +4799,7 @@ fn validateUnionInit( |
| 4797 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4799 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4798 | const field_name = try mod.intern_pool.getOrPutString( | 4800 | const field_name = try mod.intern_pool.getOrPutString( |
| 4799 | gpa, | 4801 | gpa, |
| 4802 | pt.tid, | ||
| 4800 | sema.code.nullTerminatedString(field_ptr_extra.field_name_start), | 4803 | sema.code.nullTerminatedString(field_ptr_extra.field_name_start), |
| 4801 | .no_embedded_nulls, | 4804 | .no_embedded_nulls, |
| 4802 | ); | 4805 | ); |
| ... | @@ -4942,6 +4945,7 @@ fn validateStructInit( | ... | @@ -4942,6 +4945,7 @@ fn validateStructInit( |
| 4942 | struct_ptr_zir_ref = field_ptr_extra.lhs; | 4945 | struct_ptr_zir_ref = field_ptr_extra.lhs; |
| 4943 | const field_name = try ip.getOrPutString( | 4946 | const field_name = try ip.getOrPutString( |
| 4944 | gpa, | 4947 | gpa, |
| 4948 | pt.tid, | ||
| 4945 | sema.code.nullTerminatedString(field_ptr_extra.field_name_start), | 4949 | sema.code.nullTerminatedString(field_ptr_extra.field_name_start), |
| 4946 | .no_embedded_nulls, | 4950 | .no_embedded_nulls, |
| 4947 | ); | 4951 | ); |
| ... | @@ -5518,10 +5522,11 @@ fn failWithBadStructFieldAccess( | ... | @@ -5518,10 +5522,11 @@ fn failWithBadStructFieldAccess( |
| 5518 | field_src: LazySrcLoc, | 5522 | field_src: LazySrcLoc, |
| 5519 | field_name: InternPool.NullTerminatedString, | 5523 | field_name: InternPool.NullTerminatedString, |
| 5520 | ) CompileError { | 5524 | ) CompileError { |
| 5521 | const zcu = sema.pt.zcu; | 5525 | const pt = sema.pt; |
| 5526 | const zcu = pt.zcu; | ||
| 5522 | const ip = &zcu.intern_pool; | 5527 | const ip = &zcu.intern_pool; |
| 5523 | const decl = zcu.declPtr(struct_type.decl.unwrap().?); | 5528 | const decl = zcu.declPtr(struct_type.decl.unwrap().?); |
| 5524 | const fqn = try decl.fullyQualifiedName(zcu); | 5529 | const fqn = try decl.fullyQualifiedName(pt); |
| 5525 | 5530 | ||
| 5526 | const msg = msg: { | 5531 | const msg = msg: { |
| 5527 | const msg = try sema.errMsg( | 5532 | const msg = try sema.errMsg( |
| ... | @@ -5544,12 +5549,13 @@ fn failWithBadUnionFieldAccess( | ... | @@ -5544,12 +5549,13 @@ fn failWithBadUnionFieldAccess( |
| 5544 | field_src: LazySrcLoc, | 5549 | field_src: LazySrcLoc, |
| 5545 | field_name: InternPool.NullTerminatedString, | 5550 | field_name: InternPool.NullTerminatedString, |
| 5546 | ) CompileError { | 5551 | ) CompileError { |
| 5547 | const zcu = sema.pt.zcu; | 5552 | const pt = sema.pt; |
| 5553 | const zcu = pt.zcu; | ||
| 5548 | const ip = &zcu.intern_pool; | 5554 | const ip = &zcu.intern_pool; |
| 5549 | const gpa = sema.gpa; | 5555 | const gpa = sema.gpa; |
| 5550 | 5556 | ||
| 5551 | const decl = zcu.declPtr(union_obj.decl); | 5557 | const decl = zcu.declPtr(union_obj.decl); |
| 5552 | const fqn = try decl.fullyQualifiedName(zcu); | 5558 | const fqn = try decl.fullyQualifiedName(pt); |
| 5553 | 5559 | ||
| 5554 | const msg = msg: { | 5560 | const msg = msg: { |
| 5555 | const msg = try sema.errMsg( | 5561 | const msg = try sema.errMsg( |
| ... | @@ -5715,7 +5721,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v | ... | @@ -5715,7 +5721,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5715 | fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 5721 | fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5716 | const bytes = sema.code.instructions.items(.data)[@intFromEnum(inst)].str.get(sema.code); | 5722 | const bytes = sema.code.instructions.items(.data)[@intFromEnum(inst)].str.get(sema.code); |
| 5717 | return sema.addStrLit( | 5723 | return sema.addStrLit( |
| 5718 | try sema.pt.zcu.intern_pool.getOrPutString(sema.gpa, bytes, .maybe_embedded_nulls), | 5724 | try sema.pt.zcu.intern_pool.getOrPutString(sema.gpa, sema.pt.tid, bytes, .maybe_embedded_nulls), |
| 5719 | bytes.len, | 5725 | bytes.len, |
| 5720 | ); | 5726 | ); |
| 5721 | } | 5727 | } |
| ... | @@ -6057,7 +6063,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6057,7 +6063,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 6057 | 6063 | ||
| 6058 | const path_digest = zcu.filePathDigest(result.file_index); | 6064 | const path_digest = zcu.filePathDigest(result.file_index); |
| 6059 | const root_decl = zcu.fileRootDecl(result.file_index); | 6065 | const root_decl = zcu.fileRootDecl(result.file_index); |
| 6060 | zcu.astGenFile(result.file, result.file_index, path_digest, root_decl) catch |err| | 6066 | pt.astGenFile(result.file, result.file_index, path_digest, root_decl) catch |err| |
| 6061 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); | 6067 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 6062 | 6068 | ||
| 6063 | try pt.ensureFileAnalyzed(result.file_index); | 6069 | try pt.ensureFileAnalyzed(result.file_index); |
| ... | @@ -6418,6 +6424,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -6418,6 +6424,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6418 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 6424 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 6419 | const decl_name = try mod.intern_pool.getOrPutString( | 6425 | const decl_name = try mod.intern_pool.getOrPutString( |
| 6420 | mod.gpa, | 6426 | mod.gpa, |
| 6427 | pt.tid, | ||
| 6421 | sema.code.nullTerminatedString(extra.decl_name), | 6428 | sema.code.nullTerminatedString(extra.decl_name), |
| 6422 | .no_embedded_nulls, | 6429 | .no_embedded_nulls, |
| 6423 | ); | 6430 | ); |
| ... | @@ -6737,6 +6744,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -6737,6 +6744,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 6737 | const src = block.tokenOffset(inst_data.src_tok); | 6744 | const src = block.tokenOffset(inst_data.src_tok); |
| 6738 | const decl_name = try mod.intern_pool.getOrPutString( | 6745 | const decl_name = try mod.intern_pool.getOrPutString( |
| 6739 | sema.gpa, | 6746 | sema.gpa, |
| 6747 | pt.tid, | ||
| 6740 | inst_data.get(sema.code), | 6748 | inst_data.get(sema.code), |
| 6741 | .no_embedded_nulls, | 6749 | .no_embedded_nulls, |
| 6742 | ); | 6750 | ); |
| ... | @@ -6751,6 +6759,7 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -6751,6 +6759,7 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 6751 | const src = block.tokenOffset(inst_data.src_tok); | 6759 | const src = block.tokenOffset(inst_data.src_tok); |
| 6752 | const decl_name = try mod.intern_pool.getOrPutString( | 6760 | const decl_name = try mod.intern_pool.getOrPutString( |
| 6753 | sema.gpa, | 6761 | sema.gpa, |
| 6762 | pt.tid, | ||
| 6754 | inst_data.get(sema.code), | 6763 | inst_data.get(sema.code), |
| 6755 | .no_embedded_nulls, | 6764 | .no_embedded_nulls, |
| 6756 | ); | 6765 | ); |
| ... | @@ -6907,7 +6916,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref | ... | @@ -6907,7 +6916,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6907 | 6916 | ||
| 6908 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 6917 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); |
| 6909 | try stack_trace_ty.resolveFields(pt); | 6918 | try stack_trace_ty.resolveFields(pt); |
| 6910 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); | 6919 | const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls); |
| 6911 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { | 6920 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { |
| 6912 | error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"), | 6921 | error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"), |
| 6913 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6922 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| ... | @@ -6951,7 +6960,7 @@ fn popErrorReturnTrace( | ... | @@ -6951,7 +6960,7 @@ fn popErrorReturnTrace( |
| 6951 | try stack_trace_ty.resolveFields(pt); | 6960 | try stack_trace_ty.resolveFields(pt); |
| 6952 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); | 6961 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 6953 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); | 6962 | const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 6954 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); | 6963 | const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls); |
| 6955 | const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true); | 6964 | const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true); |
| 6956 | try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store); | 6965 | try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6957 | } else if (is_non_error == null) { | 6966 | } else if (is_non_error == null) { |
| ... | @@ -6977,7 +6986,7 @@ fn popErrorReturnTrace( | ... | @@ -6977,7 +6986,7 @@ fn popErrorReturnTrace( |
| 6977 | try stack_trace_ty.resolveFields(pt); | 6986 | try stack_trace_ty.resolveFields(pt); |
| 6978 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); | 6987 | const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty); |
| 6979 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); | 6988 | const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty); |
| 6980 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); | 6989 | const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls); |
| 6981 | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true); | 6990 | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true); |
| 6982 | try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store); | 6991 | try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6983 | _ = try then_block.addBr(cond_block_inst, .void_value); | 6992 | _ = try then_block.addBr(cond_block_inst, .void_value); |
| ... | @@ -7038,6 +7047,7 @@ fn zirCall( | ... | @@ -7038,6 +7047,7 @@ fn zirCall( |
| 7038 | const object_ptr = try sema.resolveInst(extra.data.obj_ptr); | 7047 | const object_ptr = try sema.resolveInst(extra.data.obj_ptr); |
| 7039 | const field_name = try mod.intern_pool.getOrPutString( | 7048 | const field_name = try mod.intern_pool.getOrPutString( |
| 7040 | sema.gpa, | 7049 | sema.gpa, |
| 7050 | pt.tid, | ||
| 7041 | sema.code.nullTerminatedString(extra.data.field_name_start), | 7051 | sema.code.nullTerminatedString(extra.data.field_name_start), |
| 7042 | .no_embedded_nulls, | 7052 | .no_embedded_nulls, |
| 7043 | ); | 7053 | ); |
| ... | @@ -7103,7 +7113,7 @@ fn zirCall( | ... | @@ -7103,7 +7113,7 @@ fn zirCall( |
| 7103 | if (input_is_error or (pop_error_return_trace and return_ty.isError(mod))) { | 7113 | if (input_is_error or (pop_error_return_trace and return_ty.isError(mod))) { |
| 7104 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); | 7114 | const stack_trace_ty = try pt.getBuiltinType("StackTrace"); |
| 7105 | try stack_trace_ty.resolveFields(pt); | 7115 | try stack_trace_ty.resolveFields(pt); |
| 7106 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "index", .no_embedded_nulls); | 7116 | const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "index", .no_embedded_nulls); |
| 7107 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src); | 7117 | const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src); |
| 7108 | 7118 | ||
| 7109 | // Insert a save instruction before the arg resolution + call instructions we just generated | 7119 | // Insert a save instruction before the arg resolution + call instructions we just generated |
| ... | @@ -8687,6 +8697,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -8687,6 +8697,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8687 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | 8697 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 8688 | const name = try pt.zcu.intern_pool.getOrPutString( | 8698 | const name = try pt.zcu.intern_pool.getOrPutString( |
| 8689 | sema.gpa, | 8699 | sema.gpa, |
| 8700 | pt.tid, | ||
| 8690 | inst_data.get(sema.code), | 8701 | inst_data.get(sema.code), |
| 8691 | .no_embedded_nulls, | 8702 | .no_embedded_nulls, |
| 8692 | ); | 8703 | ); |
| ... | @@ -8849,7 +8860,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8849,7 +8860,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8849 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | 8860 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 8850 | const name = inst_data.get(sema.code); | 8861 | const name = inst_data.get(sema.code); |
| 8851 | return Air.internedToRef((try pt.intern(.{ | 8862 | return Air.internedToRef((try pt.intern(.{ |
| 8852 | .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name, .no_embedded_nulls), | 8863 | .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, name, .no_embedded_nulls), |
| 8853 | }))); | 8864 | }))); |
| 8854 | } | 8865 | } |
| 8855 | 8866 | ||
| ... | @@ -9820,7 +9831,7 @@ fn funcCommon( | ... | @@ -9820,7 +9831,7 @@ fn funcCommon( |
| 9820 | const func_index = try ip.getExternFunc(gpa, pt.tid, .{ | 9831 | const func_index = try ip.getExternFunc(gpa, pt.tid, .{ |
| 9821 | .ty = func_ty, | 9832 | .ty = func_ty, |
| 9822 | .decl = sema.owner_decl_index, | 9833 | .decl = sema.owner_decl_index, |
| 9823 | .lib_name = try mod.intern_pool.getOrPutStringOpt(gpa, opt_lib_name, .no_embedded_nulls), | 9834 | .lib_name = try mod.intern_pool.getOrPutStringOpt(gpa, pt.tid, opt_lib_name, .no_embedded_nulls), |
| 9824 | }); | 9835 | }); |
| 9825 | return finishFunc( | 9836 | return finishFunc( |
| 9826 | sema, | 9837 | sema, |
| ... | @@ -10281,6 +10292,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10281,6 +10292,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10281 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10292 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10282 | const field_name = try mod.intern_pool.getOrPutString( | 10293 | const field_name = try mod.intern_pool.getOrPutString( |
| 10283 | sema.gpa, | 10294 | sema.gpa, |
| 10295 | pt.tid, | ||
| 10284 | sema.code.nullTerminatedString(extra.field_name_start), | 10296 | sema.code.nullTerminatedString(extra.field_name_start), |
| 10285 | .no_embedded_nulls, | 10297 | .no_embedded_nulls, |
| 10286 | ); | 10298 | ); |
| ... | @@ -10300,6 +10312,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10300,6 +10312,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10300 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10312 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10301 | const field_name = try mod.intern_pool.getOrPutString( | 10313 | const field_name = try mod.intern_pool.getOrPutString( |
| 10302 | sema.gpa, | 10314 | sema.gpa, |
| 10315 | pt.tid, | ||
| 10303 | sema.code.nullTerminatedString(extra.field_name_start), | 10316 | sema.code.nullTerminatedString(extra.field_name_start), |
| 10304 | .no_embedded_nulls, | 10317 | .no_embedded_nulls, |
| 10305 | ); | 10318 | ); |
| ... | @@ -10319,6 +10332,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi | ... | @@ -10319,6 +10332,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 10319 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10332 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10320 | const field_name = try mod.intern_pool.getOrPutString( | 10333 | const field_name = try mod.intern_pool.getOrPutString( |
| 10321 | sema.gpa, | 10334 | sema.gpa, |
| 10335 | pt.tid, | ||
| 10322 | sema.code.nullTerminatedString(extra.field_name_start), | 10336 | sema.code.nullTerminatedString(extra.field_name_start), |
| 10323 | .no_embedded_nulls, | 10337 | .no_embedded_nulls, |
| 10324 | ); | 10338 | ); |
| ... | @@ -13983,6 +13997,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R | ... | @@ -13983,6 +13997,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R |
| 13983 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | 13997 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 13984 | const name = try mod.intern_pool.getOrPutString( | 13998 | const name = try mod.intern_pool.getOrPutString( |
| 13985 | sema.gpa, | 13999 | sema.gpa, |
| 14000 | pt.tid, | ||
| 13986 | inst_data.get(sema.code), | 14001 | inst_data.get(sema.code), |
| 13987 | .no_embedded_nulls, | 14002 | .no_embedded_nulls, |
| 13988 | ); | 14003 | ); |
| ... | @@ -17716,7 +17731,7 @@ fn zirBuiltinSrc( | ... | @@ -17716,7 +17731,7 @@ fn zirBuiltinSrc( |
| 17716 | .val = try pt.intern(.{ .aggregate = .{ | 17731 | .val = try pt.intern(.{ .aggregate = .{ |
| 17717 | .ty = array_ty, | 17732 | .ty = array_ty, |
| 17718 | .storage = .{ | 17733 | .storage = .{ |
| 17719 | .bytes = try ip.getOrPutString(gpa, file_name, .maybe_embedded_nulls), | 17734 | .bytes = try ip.getOrPutString(gpa, pt.tid, file_name, .maybe_embedded_nulls), |
| 17720 | }, | 17735 | }, |
| 17721 | } }), | 17736 | } }), |
| 17722 | } }, | 17737 | } }, |
| ... | @@ -17778,7 +17793,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17778,7 +17793,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17778 | block, | 17793 | block, |
| 17779 | src, | 17794 | src, |
| 17780 | type_info_ty.getNamespaceIndex(mod), | 17795 | type_info_ty.getNamespaceIndex(mod), |
| 17781 | try ip.getOrPutString(gpa, "Fn", .no_embedded_nulls), | 17796 | try ip.getOrPutString(gpa, pt.tid, "Fn", .no_embedded_nulls), |
| 17782 | )).?; | 17797 | )).?; |
| 17783 | try sema.ensureDeclAnalyzed(fn_info_decl_index); | 17798 | try sema.ensureDeclAnalyzed(fn_info_decl_index); |
| 17784 | const fn_info_decl = mod.declPtr(fn_info_decl_index); | 17799 | const fn_info_decl = mod.declPtr(fn_info_decl_index); |
| ... | @@ -17788,7 +17803,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17788,7 +17803,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17788 | block, | 17803 | block, |
| 17789 | src, | 17804 | src, |
| 17790 | fn_info_ty.getNamespaceIndex(mod), | 17805 | fn_info_ty.getNamespaceIndex(mod), |
| 17791 | try ip.getOrPutString(gpa, "Param", .no_embedded_nulls), | 17806 | try ip.getOrPutString(gpa, pt.tid, "Param", .no_embedded_nulls), |
| 17792 | )).?; | 17807 | )).?; |
| 17793 | try sema.ensureDeclAnalyzed(param_info_decl_index); | 17808 | try sema.ensureDeclAnalyzed(param_info_decl_index); |
| 17794 | const param_info_decl = mod.declPtr(param_info_decl_index); | 17809 | const param_info_decl = mod.declPtr(param_info_decl_index); |
| ... | @@ -17890,7 +17905,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17890,7 +17905,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17890 | block, | 17905 | block, |
| 17891 | src, | 17906 | src, |
| 17892 | type_info_ty.getNamespaceIndex(mod), | 17907 | type_info_ty.getNamespaceIndex(mod), |
| 17893 | try ip.getOrPutString(gpa, "Int", .no_embedded_nulls), | 17908 | try ip.getOrPutString(gpa, pt.tid, "Int", .no_embedded_nulls), |
| 17894 | )).?; | 17909 | )).?; |
| 17895 | try sema.ensureDeclAnalyzed(int_info_decl_index); | 17910 | try sema.ensureDeclAnalyzed(int_info_decl_index); |
| 17896 | const int_info_decl = mod.declPtr(int_info_decl_index); | 17911 | const int_info_decl = mod.declPtr(int_info_decl_index); |
| ... | @@ -17918,7 +17933,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17918,7 +17933,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17918 | block, | 17933 | block, |
| 17919 | src, | 17934 | src, |
| 17920 | type_info_ty.getNamespaceIndex(mod), | 17935 | type_info_ty.getNamespaceIndex(mod), |
| 17921 | try ip.getOrPutString(gpa, "Float", .no_embedded_nulls), | 17936 | try ip.getOrPutString(gpa, pt.tid, "Float", .no_embedded_nulls), |
| 17922 | )).?; | 17937 | )).?; |
| 17923 | try sema.ensureDeclAnalyzed(float_info_decl_index); | 17938 | try sema.ensureDeclAnalyzed(float_info_decl_index); |
| 17924 | const float_info_decl = mod.declPtr(float_info_decl_index); | 17939 | const float_info_decl = mod.declPtr(float_info_decl_index); |
| ... | @@ -17950,7 +17965,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17950,7 +17965,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17950 | block, | 17965 | block, |
| 17951 | src, | 17966 | src, |
| 17952 | (try pt.getBuiltinType("Type")).getNamespaceIndex(mod), | 17967 | (try pt.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 17953 | try ip.getOrPutString(gpa, "Pointer", .no_embedded_nulls), | 17968 | try ip.getOrPutString(gpa, pt.tid, "Pointer", .no_embedded_nulls), |
| 17954 | )).?; | 17969 | )).?; |
| 17955 | try sema.ensureDeclAnalyzed(decl_index); | 17970 | try sema.ensureDeclAnalyzed(decl_index); |
| 17956 | const decl = mod.declPtr(decl_index); | 17971 | const decl = mod.declPtr(decl_index); |
| ... | @@ -17961,7 +17976,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17961,7 +17976,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17961 | block, | 17976 | block, |
| 17962 | src, | 17977 | src, |
| 17963 | pointer_ty.getNamespaceIndex(mod), | 17978 | pointer_ty.getNamespaceIndex(mod), |
| 17964 | try ip.getOrPutString(gpa, "Size", .no_embedded_nulls), | 17979 | try ip.getOrPutString(gpa, pt.tid, "Size", .no_embedded_nulls), |
| 17965 | )).?; | 17980 | )).?; |
| 17966 | try sema.ensureDeclAnalyzed(decl_index); | 17981 | try sema.ensureDeclAnalyzed(decl_index); |
| 17967 | const decl = mod.declPtr(decl_index); | 17982 | const decl = mod.declPtr(decl_index); |
| ... | @@ -18004,7 +18019,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18004,7 +18019,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18004 | block, | 18019 | block, |
| 18005 | src, | 18020 | src, |
| 18006 | type_info_ty.getNamespaceIndex(mod), | 18021 | type_info_ty.getNamespaceIndex(mod), |
| 18007 | try ip.getOrPutString(gpa, "Array", .no_embedded_nulls), | 18022 | try ip.getOrPutString(gpa, pt.tid, "Array", .no_embedded_nulls), |
| 18008 | )).?; | 18023 | )).?; |
| 18009 | try sema.ensureDeclAnalyzed(array_field_ty_decl_index); | 18024 | try sema.ensureDeclAnalyzed(array_field_ty_decl_index); |
| 18010 | const array_field_ty_decl = mod.declPtr(array_field_ty_decl_index); | 18025 | const array_field_ty_decl = mod.declPtr(array_field_ty_decl_index); |
| ... | @@ -18035,7 +18050,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18035,7 +18050,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18035 | block, | 18050 | block, |
| 18036 | src, | 18051 | src, |
| 18037 | type_info_ty.getNamespaceIndex(mod), | 18052 | type_info_ty.getNamespaceIndex(mod), |
| 18038 | try ip.getOrPutString(gpa, "Vector", .no_embedded_nulls), | 18053 | try ip.getOrPutString(gpa, pt.tid, "Vector", .no_embedded_nulls), |
| 18039 | )).?; | 18054 | )).?; |
| 18040 | try sema.ensureDeclAnalyzed(vector_field_ty_decl_index); | 18055 | try sema.ensureDeclAnalyzed(vector_field_ty_decl_index); |
| 18041 | const vector_field_ty_decl = mod.declPtr(vector_field_ty_decl_index); | 18056 | const vector_field_ty_decl = mod.declPtr(vector_field_ty_decl_index); |
| ... | @@ -18064,7 +18079,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18064,7 +18079,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18064 | block, | 18079 | block, |
| 18065 | src, | 18080 | src, |
| 18066 | type_info_ty.getNamespaceIndex(mod), | 18081 | type_info_ty.getNamespaceIndex(mod), |
| 18067 | try ip.getOrPutString(gpa, "Optional", .no_embedded_nulls), | 18082 | try ip.getOrPutString(gpa, pt.tid, "Optional", .no_embedded_nulls), |
| 18068 | )).?; | 18083 | )).?; |
| 18069 | try sema.ensureDeclAnalyzed(optional_field_ty_decl_index); | 18084 | try sema.ensureDeclAnalyzed(optional_field_ty_decl_index); |
| 18070 | const optional_field_ty_decl = mod.declPtr(optional_field_ty_decl_index); | 18085 | const optional_field_ty_decl = mod.declPtr(optional_field_ty_decl_index); |
| ... | @@ -18091,7 +18106,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18091,7 +18106,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18091 | block, | 18106 | block, |
| 18092 | src, | 18107 | src, |
| 18093 | type_info_ty.getNamespaceIndex(mod), | 18108 | type_info_ty.getNamespaceIndex(mod), |
| 18094 | try ip.getOrPutString(gpa, "Error", .no_embedded_nulls), | 18109 | try ip.getOrPutString(gpa, pt.tid, "Error", .no_embedded_nulls), |
| 18095 | )).?; | 18110 | )).?; |
| 18096 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); | 18111 | try sema.ensureDeclAnalyzed(set_field_ty_decl_index); |
| 18097 | const set_field_ty_decl = mod.declPtr(set_field_ty_decl_index); | 18112 | const set_field_ty_decl = mod.declPtr(set_field_ty_decl_index); |
| ... | @@ -18197,7 +18212,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18197,7 +18212,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18197 | block, | 18212 | block, |
| 18198 | src, | 18213 | src, |
| 18199 | type_info_ty.getNamespaceIndex(mod), | 18214 | type_info_ty.getNamespaceIndex(mod), |
| 18200 | try ip.getOrPutString(gpa, "ErrorUnion", .no_embedded_nulls), | 18215 | try ip.getOrPutString(gpa, pt.tid, "ErrorUnion", .no_embedded_nulls), |
| 18201 | )).?; | 18216 | )).?; |
| 18202 | try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index); | 18217 | try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index); |
| 18203 | const error_union_field_ty_decl = mod.declPtr(error_union_field_ty_decl_index); | 18218 | const error_union_field_ty_decl = mod.declPtr(error_union_field_ty_decl_index); |
| ... | @@ -18227,7 +18242,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18227,7 +18242,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18227 | block, | 18242 | block, |
| 18228 | src, | 18243 | src, |
| 18229 | type_info_ty.getNamespaceIndex(mod), | 18244 | type_info_ty.getNamespaceIndex(mod), |
| 18230 | try ip.getOrPutString(gpa, "EnumField", .no_embedded_nulls), | 18245 | try ip.getOrPutString(gpa, pt.tid, "EnumField", .no_embedded_nulls), |
| 18231 | )).?; | 18246 | )).?; |
| 18232 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); | 18247 | try sema.ensureDeclAnalyzed(enum_field_ty_decl_index); |
| 18233 | const enum_field_ty_decl = mod.declPtr(enum_field_ty_decl_index); | 18248 | const enum_field_ty_decl = mod.declPtr(enum_field_ty_decl_index); |
| ... | @@ -18324,7 +18339,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18324,7 +18339,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18324 | block, | 18339 | block, |
| 18325 | src, | 18340 | src, |
| 18326 | type_info_ty.getNamespaceIndex(mod), | 18341 | type_info_ty.getNamespaceIndex(mod), |
| 18327 | try ip.getOrPutString(gpa, "Enum", .no_embedded_nulls), | 18342 | try ip.getOrPutString(gpa, pt.tid, "Enum", .no_embedded_nulls), |
| 18328 | )).?; | 18343 | )).?; |
| 18329 | try sema.ensureDeclAnalyzed(type_enum_ty_decl_index); | 18344 | try sema.ensureDeclAnalyzed(type_enum_ty_decl_index); |
| 18330 | const type_enum_ty_decl = mod.declPtr(type_enum_ty_decl_index); | 18345 | const type_enum_ty_decl = mod.declPtr(type_enum_ty_decl_index); |
| ... | @@ -18356,7 +18371,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18356,7 +18371,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18356 | block, | 18371 | block, |
| 18357 | src, | 18372 | src, |
| 18358 | type_info_ty.getNamespaceIndex(mod), | 18373 | type_info_ty.getNamespaceIndex(mod), |
| 18359 | try ip.getOrPutString(gpa, "Union", .no_embedded_nulls), | 18374 | try ip.getOrPutString(gpa, pt.tid, "Union", .no_embedded_nulls), |
| 18360 | )).?; | 18375 | )).?; |
| 18361 | try sema.ensureDeclAnalyzed(type_union_ty_decl_index); | 18376 | try sema.ensureDeclAnalyzed(type_union_ty_decl_index); |
| 18362 | const type_union_ty_decl = mod.declPtr(type_union_ty_decl_index); | 18377 | const type_union_ty_decl = mod.declPtr(type_union_ty_decl_index); |
| ... | @@ -18368,7 +18383,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18368,7 +18383,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18368 | block, | 18383 | block, |
| 18369 | src, | 18384 | src, |
| 18370 | type_info_ty.getNamespaceIndex(mod), | 18385 | type_info_ty.getNamespaceIndex(mod), |
| 18371 | try ip.getOrPutString(gpa, "UnionField", .no_embedded_nulls), | 18386 | try ip.getOrPutString(gpa, pt.tid, "UnionField", .no_embedded_nulls), |
| 18372 | )).?; | 18387 | )).?; |
| 18373 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); | 18388 | try sema.ensureDeclAnalyzed(union_field_ty_decl_index); |
| 18374 | const union_field_ty_decl = mod.declPtr(union_field_ty_decl_index); | 18389 | const union_field_ty_decl = mod.declPtr(union_field_ty_decl_index); |
| ... | @@ -18473,7 +18488,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18473,7 +18488,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18473 | block, | 18488 | block, |
| 18474 | src, | 18489 | src, |
| 18475 | (try pt.getBuiltinType("Type")).getNamespaceIndex(mod), | 18490 | (try pt.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 18476 | try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls), | 18491 | try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls), |
| 18477 | )).?; | 18492 | )).?; |
| 18478 | try sema.ensureDeclAnalyzed(decl_index); | 18493 | try sema.ensureDeclAnalyzed(decl_index); |
| 18479 | const decl = mod.declPtr(decl_index); | 18494 | const decl = mod.declPtr(decl_index); |
| ... | @@ -18506,7 +18521,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18506,7 +18521,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18506 | block, | 18521 | block, |
| 18507 | src, | 18522 | src, |
| 18508 | type_info_ty.getNamespaceIndex(mod), | 18523 | type_info_ty.getNamespaceIndex(mod), |
| 18509 | try ip.getOrPutString(gpa, "Struct", .no_embedded_nulls), | 18524 | try ip.getOrPutString(gpa, pt.tid, "Struct", .no_embedded_nulls), |
| 18510 | )).?; | 18525 | )).?; |
| 18511 | try sema.ensureDeclAnalyzed(type_struct_ty_decl_index); | 18526 | try sema.ensureDeclAnalyzed(type_struct_ty_decl_index); |
| 18512 | const type_struct_ty_decl = mod.declPtr(type_struct_ty_decl_index); | 18527 | const type_struct_ty_decl = mod.declPtr(type_struct_ty_decl_index); |
| ... | @@ -18518,7 +18533,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18518,7 +18533,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18518 | block, | 18533 | block, |
| 18519 | src, | 18534 | src, |
| 18520 | type_info_ty.getNamespaceIndex(mod), | 18535 | type_info_ty.getNamespaceIndex(mod), |
| 18521 | try ip.getOrPutString(gpa, "StructField", .no_embedded_nulls), | 18536 | try ip.getOrPutString(gpa, pt.tid, "StructField", .no_embedded_nulls), |
| 18522 | )).?; | 18537 | )).?; |
| 18523 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); | 18538 | try sema.ensureDeclAnalyzed(struct_field_ty_decl_index); |
| 18524 | const struct_field_ty_decl = mod.declPtr(struct_field_ty_decl_index); | 18539 | const struct_field_ty_decl = mod.declPtr(struct_field_ty_decl_index); |
| ... | @@ -18540,7 +18555,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18540,7 +18555,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18540 | const field_name = if (anon_struct_type.names.len != 0) | 18555 | const field_name = if (anon_struct_type.names.len != 0) |
| 18541 | anon_struct_type.names.get(ip)[field_index] | 18556 | anon_struct_type.names.get(ip)[field_index] |
| 18542 | else | 18557 | else |
| 18543 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls); | 18558 | try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 18544 | const field_name_len = field_name.length(ip); | 18559 | const field_name_len = field_name.length(ip); |
| 18545 | const new_decl_ty = try pt.arrayType(.{ | 18560 | const new_decl_ty = try pt.arrayType(.{ |
| 18546 | .len = field_name_len, | 18561 | .len = field_name_len, |
| ... | @@ -18600,7 +18615,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18600,7 +18615,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18600 | const field_name = if (struct_type.fieldName(ip, field_index).unwrap()) |field_name| | 18615 | const field_name = if (struct_type.fieldName(ip, field_index).unwrap()) |field_name| |
| 18601 | field_name | 18616 | field_name |
| 18602 | else | 18617 | else |
| 18603 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls); | 18618 | try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 18604 | const field_name_len = field_name.length(ip); | 18619 | const field_name_len = field_name.length(ip); |
| 18605 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); | 18620 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); |
| 18606 | const field_init = struct_type.fieldInit(ip, field_index); | 18621 | const field_init = struct_type.fieldInit(ip, field_index); |
| ... | @@ -18706,7 +18721,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18706,7 +18721,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18706 | block, | 18721 | block, |
| 18707 | src, | 18722 | src, |
| 18708 | (try pt.getBuiltinType("Type")).getNamespaceIndex(mod), | 18723 | (try pt.getBuiltinType("Type")).getNamespaceIndex(mod), |
| 18709 | try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls), | 18724 | try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls), |
| 18710 | )).?; | 18725 | )).?; |
| 18711 | try sema.ensureDeclAnalyzed(decl_index); | 18726 | try sema.ensureDeclAnalyzed(decl_index); |
| 18712 | const decl = mod.declPtr(decl_index); | 18727 | const decl = mod.declPtr(decl_index); |
| ... | @@ -18742,7 +18757,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18742,7 +18757,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18742 | block, | 18757 | block, |
| 18743 | src, | 18758 | src, |
| 18744 | type_info_ty.getNamespaceIndex(mod), | 18759 | type_info_ty.getNamespaceIndex(mod), |
| 18745 | try ip.getOrPutString(gpa, "Opaque", .no_embedded_nulls), | 18760 | try ip.getOrPutString(gpa, pt.tid, "Opaque", .no_embedded_nulls), |
| 18746 | )).?; | 18761 | )).?; |
| 18747 | try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index); | 18762 | try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index); |
| 18748 | const type_opaque_ty_decl = mod.declPtr(type_opaque_ty_decl_index); | 18763 | const type_opaque_ty_decl = mod.declPtr(type_opaque_ty_decl_index); |
| ... | @@ -18786,7 +18801,7 @@ fn typeInfoDecls( | ... | @@ -18786,7 +18801,7 @@ fn typeInfoDecls( |
| 18786 | block, | 18801 | block, |
| 18787 | src, | 18802 | src, |
| 18788 | type_info_ty.getNamespaceIndex(mod), | 18803 | type_info_ty.getNamespaceIndex(mod), |
| 18789 | try mod.intern_pool.getOrPutString(gpa, "Declaration", .no_embedded_nulls), | 18804 | try mod.intern_pool.getOrPutString(gpa, pt.tid, "Declaration", .no_embedded_nulls), |
| 18790 | )).?; | 18805 | )).?; |
| 18791 | try sema.ensureDeclAnalyzed(declaration_ty_decl_index); | 18806 | try sema.ensureDeclAnalyzed(declaration_ty_decl_index); |
| 18792 | const declaration_ty_decl = mod.declPtr(declaration_ty_decl_index); | 18807 | const declaration_ty_decl = mod.declPtr(declaration_ty_decl_index); |
| ... | @@ -19541,6 +19556,7 @@ fn zirRetErrValue( | ... | @@ -19541,6 +19556,7 @@ fn zirRetErrValue( |
| 19541 | const src = block.tokenOffset(inst_data.src_tok); | 19556 | const src = block.tokenOffset(inst_data.src_tok); |
| 19542 | const err_name = try mod.intern_pool.getOrPutString( | 19557 | const err_name = try mod.intern_pool.getOrPutString( |
| 19543 | sema.gpa, | 19558 | sema.gpa, |
| 19559 | pt.tid, | ||
| 19544 | inst_data.get(sema.code), | 19560 | inst_data.get(sema.code), |
| 19545 | .no_embedded_nulls, | 19561 | .no_embedded_nulls, |
| 19546 | ); | 19562 | ); |
| ... | @@ -20251,6 +20267,7 @@ fn zirStructInit( | ... | @@ -20251,6 +20267,7 @@ fn zirStructInit( |
| 20251 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 20267 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20252 | const field_name = try ip.getOrPutString( | 20268 | const field_name = try ip.getOrPutString( |
| 20253 | gpa, | 20269 | gpa, |
| 20270 | pt.tid, | ||
| 20254 | sema.code.nullTerminatedString(field_type_extra.name_start), | 20271 | sema.code.nullTerminatedString(field_type_extra.name_start), |
| 20255 | .no_embedded_nulls, | 20272 | .no_embedded_nulls, |
| 20256 | ); | 20273 | ); |
| ... | @@ -20292,6 +20309,7 @@ fn zirStructInit( | ... | @@ -20292,6 +20309,7 @@ fn zirStructInit( |
| 20292 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 20309 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20293 | const field_name = try ip.getOrPutString( | 20310 | const field_name = try ip.getOrPutString( |
| 20294 | gpa, | 20311 | gpa, |
| 20312 | pt.tid, | ||
| 20295 | sema.code.nullTerminatedString(field_type_extra.name_start), | 20313 | sema.code.nullTerminatedString(field_type_extra.name_start), |
| 20296 | .no_embedded_nulls, | 20314 | .no_embedded_nulls, |
| 20297 | ); | 20315 | ); |
| ... | @@ -20581,7 +20599,7 @@ fn structInitAnon( | ... | @@ -20581,7 +20599,7 @@ fn structInitAnon( |
| 20581 | }, | 20599 | }, |
| 20582 | }; | 20600 | }; |
| 20583 | 20601 | ||
| 20584 | field_name.* = try mod.intern_pool.getOrPutString(gpa, name, .no_embedded_nulls); | 20602 | field_name.* = try mod.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls); |
| 20585 | 20603 | ||
| 20586 | const init = try sema.resolveInst(item.data.init); | 20604 | const init = try sema.resolveInst(item.data.init); |
| 20587 | field_ty.* = sema.typeOf(init).toIntern(); | 20605 | field_ty.* = sema.typeOf(init).toIntern(); |
| ... | @@ -20958,7 +20976,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -20958,7 +20976,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 20958 | }; | 20976 | }; |
| 20959 | const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod); | 20977 | const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod); |
| 20960 | const zir_field_name = sema.code.nullTerminatedString(extra.name_start); | 20978 | const zir_field_name = sema.code.nullTerminatedString(extra.name_start); |
| 20961 | const field_name = try ip.getOrPutString(sema.gpa, zir_field_name, .no_embedded_nulls); | 20979 | const field_name = try ip.getOrPutString(sema.gpa, pt.tid, zir_field_name, .no_embedded_nulls); |
| 20962 | return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src); | 20980 | return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src); |
| 20963 | } | 20981 | } |
| 20964 | 20982 | ||
| ... | @@ -21344,11 +21362,11 @@ fn zirReify( | ... | @@ -21344,11 +21362,11 @@ fn zirReify( |
| 21344 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21362 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21345 | const signedness_val = try Value.fromInterned(union_val.val).fieldValue( | 21363 | const signedness_val = try Value.fromInterned(union_val.val).fieldValue( |
| 21346 | pt, | 21364 | pt, |
| 21347 | struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness", .no_embedded_nulls)).?, | 21365 | struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "signedness", .no_embedded_nulls)).?, |
| 21348 | ); | 21366 | ); |
| 21349 | const bits_val = try Value.fromInterned(union_val.val).fieldValue( | 21367 | const bits_val = try Value.fromInterned(union_val.val).fieldValue( |
| 21350 | pt, | 21368 | pt, |
| 21351 | struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits", .no_embedded_nulls)).?, | 21369 | struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls)).?, |
| 21352 | ); | 21370 | ); |
| 21353 | 21371 | ||
| 21354 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); | 21372 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); |
| ... | @@ -21360,11 +21378,11 @@ fn zirReify( | ... | @@ -21360,11 +21378,11 @@ fn zirReify( |
| 21360 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21378 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21361 | const len_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21379 | const len_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21362 | ip, | 21380 | ip, |
| 21363 | try ip.getOrPutString(gpa, "len", .no_embedded_nulls), | 21381 | try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), |
| 21364 | ).?); | 21382 | ).?); |
| 21365 | const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21383 | const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21366 | ip, | 21384 | ip, |
| 21367 | try ip.getOrPutString(gpa, "child", .no_embedded_nulls), | 21385 | try ip.getOrPutString(gpa, pt.tid, "child", .no_embedded_nulls), |
| 21368 | ).?); | 21386 | ).?); |
| 21369 | 21387 | ||
| 21370 | const len: u32 = @intCast(try len_val.toUnsignedIntSema(pt)); | 21388 | const len: u32 = @intCast(try len_val.toUnsignedIntSema(pt)); |
| ... | @@ -21382,7 +21400,7 @@ fn zirReify( | ... | @@ -21382,7 +21400,7 @@ fn zirReify( |
| 21382 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21400 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21383 | const bits_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21401 | const bits_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21384 | ip, | 21402 | ip, |
| 21385 | try ip.getOrPutString(gpa, "bits", .no_embedded_nulls), | 21403 | try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls), |
| 21386 | ).?); | 21404 | ).?); |
| 21387 | 21405 | ||
| 21388 | const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt)); | 21406 | const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt)); |
| ... | @@ -21400,35 +21418,35 @@ fn zirReify( | ... | @@ -21400,35 +21418,35 @@ fn zirReify( |
| 21400 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21418 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21401 | const size_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21419 | const size_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21402 | ip, | 21420 | ip, |
| 21403 | try ip.getOrPutString(gpa, "size", .no_embedded_nulls), | 21421 | try ip.getOrPutString(gpa, pt.tid, "size", .no_embedded_nulls), |
| 21404 | ).?); | 21422 | ).?); |
| 21405 | const is_const_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21423 | const is_const_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21406 | ip, | 21424 | ip, |
| 21407 | try ip.getOrPutString(gpa, "is_const", .no_embedded_nulls), | 21425 | try ip.getOrPutString(gpa, pt.tid, "is_const", .no_embedded_nulls), |
| 21408 | ).?); | 21426 | ).?); |
| 21409 | const is_volatile_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21427 | const is_volatile_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21410 | ip, | 21428 | ip, |
| 21411 | try ip.getOrPutString(gpa, "is_volatile", .no_embedded_nulls), | 21429 | try ip.getOrPutString(gpa, pt.tid, "is_volatile", .no_embedded_nulls), |
| 21412 | ).?); | 21430 | ).?); |
| 21413 | const alignment_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21431 | const alignment_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21414 | ip, | 21432 | ip, |
| 21415 | try ip.getOrPutString(gpa, "alignment", .no_embedded_nulls), | 21433 | try ip.getOrPutString(gpa, pt.tid, "alignment", .no_embedded_nulls), |
| 21416 | ).?); | 21434 | ).?); |
| 21417 | const address_space_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21435 | const address_space_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21418 | ip, | 21436 | ip, |
| 21419 | try ip.getOrPutString(gpa, "address_space", .no_embedded_nulls), | 21437 | try ip.getOrPutString(gpa, pt.tid, "address_space", .no_embedded_nulls), |
| 21420 | ).?); | 21438 | ).?); |
| 21421 | const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21439 | const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21422 | ip, | 21440 | ip, |
| 21423 | try ip.getOrPutString(gpa, "child", .no_embedded_nulls), | 21441 | try ip.getOrPutString(gpa, pt.tid, "child", .no_embedded_nulls), |
| 21424 | ).?); | 21442 | ).?); |
| 21425 | const is_allowzero_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21443 | const is_allowzero_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21426 | ip, | 21444 | ip, |
| 21427 | try ip.getOrPutString(gpa, "is_allowzero", .no_embedded_nulls), | 21445 | try ip.getOrPutString(gpa, pt.tid, "is_allowzero", .no_embedded_nulls), |
| 21428 | ).?); | 21446 | ).?); |
| 21429 | const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21447 | const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21430 | ip, | 21448 | ip, |
| 21431 | try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls), | 21449 | try ip.getOrPutString(gpa, pt.tid, "sentinel", .no_embedded_nulls), |
| 21432 | ).?); | 21450 | ).?); |
| 21433 | 21451 | ||
| 21434 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { | 21452 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| ... | @@ -21505,15 +21523,15 @@ fn zirReify( | ... | @@ -21505,15 +21523,15 @@ fn zirReify( |
| 21505 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21523 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21506 | const len_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21524 | const len_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21507 | ip, | 21525 | ip, |
| 21508 | try ip.getOrPutString(gpa, "len", .no_embedded_nulls), | 21526 | try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), |
| 21509 | ).?); | 21527 | ).?); |
| 21510 | const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21528 | const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21511 | ip, | 21529 | ip, |
| 21512 | try ip.getOrPutString(gpa, "child", .no_embedded_nulls), | 21530 | try ip.getOrPutString(gpa, pt.tid, "child", .no_embedded_nulls), |
| 21513 | ).?); | 21531 | ).?); |
| 21514 | const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21532 | const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21515 | ip, | 21533 | ip, |
| 21516 | try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls), | 21534 | try ip.getOrPutString(gpa, pt.tid, "sentinel", .no_embedded_nulls), |
| 21517 | ).?); | 21535 | ).?); |
| 21518 | 21536 | ||
| 21519 | const len = try len_val.toUnsignedIntSema(pt); | 21537 | const len = try len_val.toUnsignedIntSema(pt); |
| ... | @@ -21534,7 +21552,7 @@ fn zirReify( | ... | @@ -21534,7 +21552,7 @@ fn zirReify( |
| 21534 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21552 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21535 | const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21553 | const child_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21536 | ip, | 21554 | ip, |
| 21537 | try ip.getOrPutString(gpa, "child", .no_embedded_nulls), | 21555 | try ip.getOrPutString(gpa, pt.tid, "child", .no_embedded_nulls), |
| 21538 | ).?); | 21556 | ).?); |
| 21539 | 21557 | ||
| 21540 | const child_ty = child_val.toType(); | 21558 | const child_ty = child_val.toType(); |
| ... | @@ -21546,11 +21564,11 @@ fn zirReify( | ... | @@ -21546,11 +21564,11 @@ fn zirReify( |
| 21546 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21564 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21547 | const error_set_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21565 | const error_set_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21548 | ip, | 21566 | ip, |
| 21549 | try ip.getOrPutString(gpa, "error_set", .no_embedded_nulls), | 21567 | try ip.getOrPutString(gpa, pt.tid, "error_set", .no_embedded_nulls), |
| 21550 | ).?); | 21568 | ).?); |
| 21551 | const payload_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21569 | const payload_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21552 | ip, | 21570 | ip, |
| 21553 | try ip.getOrPutString(gpa, "payload", .no_embedded_nulls), | 21571 | try ip.getOrPutString(gpa, pt.tid, "payload", .no_embedded_nulls), |
| 21554 | ).?); | 21572 | ).?); |
| 21555 | 21573 | ||
| 21556 | const error_set_ty = error_set_val.toType(); | 21574 | const error_set_ty = error_set_val.toType(); |
| ... | @@ -21579,7 +21597,7 @@ fn zirReify( | ... | @@ -21579,7 +21597,7 @@ fn zirReify( |
| 21579 | const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern())); | 21597 | const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern())); |
| 21580 | const name_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex( | 21598 | const name_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex( |
| 21581 | ip, | 21599 | ip, |
| 21582 | try ip.getOrPutString(gpa, "name", .no_embedded_nulls), | 21600 | try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), |
| 21583 | ).?); | 21601 | ).?); |
| 21584 | 21602 | ||
| 21585 | const name = try sema.sliceToIpString(block, src, name_val, .{ | 21603 | const name = try sema.sliceToIpString(block, src, name_val, .{ |
| ... | @@ -21601,23 +21619,23 @@ fn zirReify( | ... | @@ -21601,23 +21619,23 @@ fn zirReify( |
| 21601 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21619 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21602 | const layout_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21620 | const layout_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21603 | ip, | 21621 | ip, |
| 21604 | try ip.getOrPutString(gpa, "layout", .no_embedded_nulls), | 21622 | try ip.getOrPutString(gpa, pt.tid, "layout", .no_embedded_nulls), |
| 21605 | ).?); | 21623 | ).?); |
| 21606 | const backing_integer_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21624 | const backing_integer_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21607 | ip, | 21625 | ip, |
| 21608 | try ip.getOrPutString(gpa, "backing_integer", .no_embedded_nulls), | 21626 | try ip.getOrPutString(gpa, pt.tid, "backing_integer", .no_embedded_nulls), |
| 21609 | ).?); | 21627 | ).?); |
| 21610 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21628 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21611 | ip, | 21629 | ip, |
| 21612 | try ip.getOrPutString(gpa, "fields", .no_embedded_nulls), | 21630 | try ip.getOrPutString(gpa, pt.tid, "fields", .no_embedded_nulls), |
| 21613 | ).?); | 21631 | ).?); |
| 21614 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21632 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21615 | ip, | 21633 | ip, |
| 21616 | try ip.getOrPutString(gpa, "decls", .no_embedded_nulls), | 21634 | try ip.getOrPutString(gpa, pt.tid, "decls", .no_embedded_nulls), |
| 21617 | ).?); | 21635 | ).?); |
| 21618 | const is_tuple_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21636 | const is_tuple_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21619 | ip, | 21637 | ip, |
| 21620 | try ip.getOrPutString(gpa, "is_tuple", .no_embedded_nulls), | 21638 | try ip.getOrPutString(gpa, pt.tid, "is_tuple", .no_embedded_nulls), |
| 21621 | ).?); | 21639 | ).?); |
| 21622 | 21640 | ||
| 21623 | const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val); | 21641 | const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val); |
| ... | @@ -21641,19 +21659,19 @@ fn zirReify( | ... | @@ -21641,19 +21659,19 @@ fn zirReify( |
| 21641 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21659 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21642 | const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21660 | const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21643 | ip, | 21661 | ip, |
| 21644 | try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls), | 21662 | try ip.getOrPutString(gpa, pt.tid, "tag_type", .no_embedded_nulls), |
| 21645 | ).?); | 21663 | ).?); |
| 21646 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21664 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21647 | ip, | 21665 | ip, |
| 21648 | try ip.getOrPutString(gpa, "fields", .no_embedded_nulls), | 21666 | try ip.getOrPutString(gpa, pt.tid, "fields", .no_embedded_nulls), |
| 21649 | ).?); | 21667 | ).?); |
| 21650 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21668 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21651 | ip, | 21669 | ip, |
| 21652 | try ip.getOrPutString(gpa, "decls", .no_embedded_nulls), | 21670 | try ip.getOrPutString(gpa, pt.tid, "decls", .no_embedded_nulls), |
| 21653 | ).?); | 21671 | ).?); |
| 21654 | const is_exhaustive_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21672 | const is_exhaustive_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21655 | ip, | 21673 | ip, |
| 21656 | try ip.getOrPutString(gpa, "is_exhaustive", .no_embedded_nulls), | 21674 | try ip.getOrPutString(gpa, pt.tid, "is_exhaustive", .no_embedded_nulls), |
| 21657 | ).?); | 21675 | ).?); |
| 21658 | 21676 | ||
| 21659 | if (try decls_val.sliceLen(pt) > 0) { | 21677 | if (try decls_val.sliceLen(pt) > 0) { |
| ... | @@ -21670,7 +21688,7 @@ fn zirReify( | ... | @@ -21670,7 +21688,7 @@ fn zirReify( |
| 21670 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21688 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21671 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21689 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21672 | ip, | 21690 | ip, |
| 21673 | try ip.getOrPutString(gpa, "decls", .no_embedded_nulls), | 21691 | try ip.getOrPutString(gpa, pt.tid, "decls", .no_embedded_nulls), |
| 21674 | ).?); | 21692 | ).?); |
| 21675 | 21693 | ||
| 21676 | // Decls | 21694 | // Decls |
| ... | @@ -21707,19 +21725,19 @@ fn zirReify( | ... | @@ -21707,19 +21725,19 @@ fn zirReify( |
| 21707 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21725 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21708 | const layout_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21726 | const layout_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21709 | ip, | 21727 | ip, |
| 21710 | try ip.getOrPutString(gpa, "layout", .no_embedded_nulls), | 21728 | try ip.getOrPutString(gpa, pt.tid, "layout", .no_embedded_nulls), |
| 21711 | ).?); | 21729 | ).?); |
| 21712 | const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21730 | const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21713 | ip, | 21731 | ip, |
| 21714 | try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls), | 21732 | try ip.getOrPutString(gpa, pt.tid, "tag_type", .no_embedded_nulls), |
| 21715 | ).?); | 21733 | ).?); |
| 21716 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21734 | const fields_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21717 | ip, | 21735 | ip, |
| 21718 | try ip.getOrPutString(gpa, "fields", .no_embedded_nulls), | 21736 | try ip.getOrPutString(gpa, pt.tid, "fields", .no_embedded_nulls), |
| 21719 | ).?); | 21737 | ).?); |
| 21720 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21738 | const decls_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21721 | ip, | 21739 | ip, |
| 21722 | try ip.getOrPutString(gpa, "decls", .no_embedded_nulls), | 21740 | try ip.getOrPutString(gpa, pt.tid, "decls", .no_embedded_nulls), |
| 21723 | ).?); | 21741 | ).?); |
| 21724 | 21742 | ||
| 21725 | if (try decls_val.sliceLen(pt) > 0) { | 21743 | if (try decls_val.sliceLen(pt) > 0) { |
| ... | @@ -21737,23 +21755,23 @@ fn zirReify( | ... | @@ -21737,23 +21755,23 @@ fn zirReify( |
| 21737 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21755 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| 21738 | const calling_convention_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21756 | const calling_convention_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21739 | ip, | 21757 | ip, |
| 21740 | try ip.getOrPutString(gpa, "calling_convention", .no_embedded_nulls), | 21758 | try ip.getOrPutString(gpa, pt.tid, "calling_convention", .no_embedded_nulls), |
| 21741 | ).?); | 21759 | ).?); |
| 21742 | const is_generic_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21760 | const is_generic_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21743 | ip, | 21761 | ip, |
| 21744 | try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls), | 21762 | try ip.getOrPutString(gpa, pt.tid, "is_generic", .no_embedded_nulls), |
| 21745 | ).?); | 21763 | ).?); |
| 21746 | const is_var_args_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21764 | const is_var_args_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21747 | ip, | 21765 | ip, |
| 21748 | try ip.getOrPutString(gpa, "is_var_args", .no_embedded_nulls), | 21766 | try ip.getOrPutString(gpa, pt.tid, "is_var_args", .no_embedded_nulls), |
| 21749 | ).?); | 21767 | ).?); |
| 21750 | const return_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21768 | const return_type_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21751 | ip, | 21769 | ip, |
| 21752 | try ip.getOrPutString(gpa, "return_type", .no_embedded_nulls), | 21770 | try ip.getOrPutString(gpa, pt.tid, "return_type", .no_embedded_nulls), |
| 21753 | ).?); | 21771 | ).?); |
| 21754 | const params_slice_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( | 21772 | const params_slice_val = try Value.fromInterned(union_val.val).fieldValue(pt, struct_type.nameIndex( |
| 21755 | ip, | 21773 | ip, |
| 21756 | try ip.getOrPutString(gpa, "params", .no_embedded_nulls), | 21774 | try ip.getOrPutString(gpa, pt.tid, "params", .no_embedded_nulls), |
| 21757 | ).?); | 21775 | ).?); |
| 21758 | 21776 | ||
| 21759 | const is_generic = is_generic_val.toBool(); | 21777 | const is_generic = is_generic_val.toBool(); |
| ... | @@ -21783,15 +21801,15 @@ fn zirReify( | ... | @@ -21783,15 +21801,15 @@ fn zirReify( |
| 21783 | const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern())); | 21801 | const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern())); |
| 21784 | const param_is_generic_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex( | 21802 | const param_is_generic_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex( |
| 21785 | ip, | 21803 | ip, |
| 21786 | try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls), | 21804 | try ip.getOrPutString(gpa, pt.tid, "is_generic", .no_embedded_nulls), |
| 21787 | ).?); | 21805 | ).?); |
| 21788 | const param_is_noalias_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex( | 21806 | const param_is_noalias_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex( |
| 21789 | ip, | 21807 | ip, |
| 21790 | try ip.getOrPutString(gpa, "is_noalias", .no_embedded_nulls), | 21808 | try ip.getOrPutString(gpa, pt.tid, "is_noalias", .no_embedded_nulls), |
| 21791 | ).?); | 21809 | ).?); |
| 21792 | const opt_param_type_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex( | 21810 | const opt_param_type_val = try elem_val.fieldValue(pt, elem_struct_type.nameIndex( |
| 21793 | ip, | 21811 | ip, |
| 21794 | try ip.getOrPutString(gpa, "type", .no_embedded_nulls), | 21812 | try ip.getOrPutString(gpa, pt.tid, "type", .no_embedded_nulls), |
| 21795 | ).?); | 21813 | ).?); |
| 21796 | 21814 | ||
| 21797 | if (param_is_generic_val.toBool()) { | 21815 | if (param_is_generic_val.toBool()) { |
| ... | @@ -22535,7 +22553,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -22535,7 +22553,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22535 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 22553 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22536 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); | 22554 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 22537 | 22555 | ||
| 22538 | const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(pt)}, .no_embedded_nulls); | 22556 | const type_name = try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{}", .{ty.fmt(pt)}, .no_embedded_nulls); |
| 22539 | return sema.addNullTerminatedStrLit(type_name); | 22557 | return sema.addNullTerminatedStrLit(type_name); |
| 22540 | } | 22558 | } |
| 22541 | 22559 | ||
| ... | @@ -24143,18 +24161,18 @@ fn resolveExportOptions( | ... | @@ -24143,18 +24161,18 @@ fn resolveExportOptions( |
| 24143 | const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 24161 | const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24144 | const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 24162 | const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24145 | 24163 | ||
| 24146 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); | 24164 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src); |
| 24147 | const name = try sema.toConstString(block, name_src, name_operand, .{ | 24165 | const name = try sema.toConstString(block, name_src, name_operand, .{ |
| 24148 | .needed_comptime_reason = "name of exported value must be comptime-known", | 24166 | .needed_comptime_reason = "name of exported value must be comptime-known", |
| 24149 | }); | 24167 | }); |
| 24150 | 24168 | ||
| 24151 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage", .no_embedded_nulls), linkage_src); | 24169 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src); |
| 24152 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{ | 24170 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{ |
| 24153 | .needed_comptime_reason = "linkage of exported value must be comptime-known", | 24171 | .needed_comptime_reason = "linkage of exported value must be comptime-known", |
| 24154 | }); | 24172 | }); |
| 24155 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); | 24173 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 24156 | 24174 | ||
| 24157 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section", .no_embedded_nulls), section_src); | 24175 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src); |
| 24158 | const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{ | 24176 | const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{ |
| 24159 | .needed_comptime_reason = "linksection of exported value must be comptime-known", | 24177 | .needed_comptime_reason = "linksection of exported value must be comptime-known", |
| 24160 | }); | 24178 | }); |
| ... | @@ -24165,7 +24183,7 @@ fn resolveExportOptions( | ... | @@ -24165,7 +24183,7 @@ fn resolveExportOptions( |
| 24165 | else | 24183 | else |
| 24166 | null; | 24184 | null; |
| 24167 | 24185 | ||
| 24168 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility", .no_embedded_nulls), visibility_src); | 24186 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "visibility", .no_embedded_nulls), visibility_src); |
| 24169 | const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{ | 24187 | const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{ |
| 24170 | .needed_comptime_reason = "visibility of exported value must be comptime-known", | 24188 | .needed_comptime_reason = "visibility of exported value must be comptime-known", |
| 24171 | }); | 24189 | }); |
| ... | @@ -24182,9 +24200,9 @@ fn resolveExportOptions( | ... | @@ -24182,9 +24200,9 @@ fn resolveExportOptions( |
| 24182 | } | 24200 | } |
| 24183 | 24201 | ||
| 24184 | return .{ | 24202 | return .{ |
| 24185 | .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls), | 24203 | .name = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls), |
| 24186 | .linkage = linkage, | 24204 | .linkage = linkage, |
| 24187 | .section = try ip.getOrPutStringOpt(gpa, section, .no_embedded_nulls), | 24205 | .section = try ip.getOrPutStringOpt(gpa, pt.tid, section, .no_embedded_nulls), |
| 24188 | .visibility = visibility, | 24206 | .visibility = visibility, |
| 24189 | }; | 24207 | }; |
| 24190 | } | 24208 | } |
| ... | @@ -25821,7 +25839,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25821,7 +25839,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25821 | 25839 | ||
| 25822 | const runtime_src = rs: { | 25840 | const runtime_src = rs: { |
| 25823 | const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src; | 25841 | const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src; |
| 25824 | const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, "len", .no_embedded_nulls), dest_src); | 25842 | const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), dest_src); |
| 25825 | const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src; | 25843 | const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src; |
| 25826 | const len_u64 = (try len_val.getUnsignedIntAdvanced(pt, .sema)).?; | 25844 | const len_u64 = (try len_val.getUnsignedIntAdvanced(pt, .sema)).?; |
| 25827 | const len = try sema.usizeCast(block, dest_src, len_u64); | 25845 | const len = try sema.usizeCast(block, dest_src, len_u64); |
| ... | @@ -25952,7 +25970,7 @@ fn zirVarExtended( | ... | @@ -25952,7 +25970,7 @@ fn zirVarExtended( |
| 25952 | .ty = var_ty.toIntern(), | 25970 | .ty = var_ty.toIntern(), |
| 25953 | .init = init_val, | 25971 | .init = init_val, |
| 25954 | .decl = sema.owner_decl_index, | 25972 | .decl = sema.owner_decl_index, |
| 25955 | .lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, lib_name, .no_embedded_nulls), | 25973 | .lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, pt.tid, lib_name, .no_embedded_nulls), |
| 25956 | .is_extern = small.is_extern, | 25974 | .is_extern = small.is_extern, |
| 25957 | .is_const = small.is_const, | 25975 | .is_const = small.is_const, |
| 25958 | .is_threadlocal = small.is_threadlocal, | 25976 | .is_threadlocal = small.is_threadlocal, |
| ... | @@ -26323,17 +26341,17 @@ fn resolvePrefetchOptions( | ... | @@ -26323,17 +26341,17 @@ fn resolvePrefetchOptions( |
| 26323 | const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 26341 | const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26324 | const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 26342 | const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26325 | 26343 | ||
| 26326 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src); | 26344 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "rw", .no_embedded_nulls), rw_src); |
| 26327 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ | 26345 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ |
| 26328 | .needed_comptime_reason = "prefetch read/write must be comptime-known", | 26346 | .needed_comptime_reason = "prefetch read/write must be comptime-known", |
| 26329 | }); | 26347 | }); |
| 26330 | 26348 | ||
| 26331 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality", .no_embedded_nulls), locality_src); | 26349 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "locality", .no_embedded_nulls), locality_src); |
| 26332 | const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{ | 26350 | const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{ |
| 26333 | .needed_comptime_reason = "prefetch locality must be comptime-known", | 26351 | .needed_comptime_reason = "prefetch locality must be comptime-known", |
| 26334 | }); | 26352 | }); |
| 26335 | 26353 | ||
| 26336 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache", .no_embedded_nulls), cache_src); | 26354 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "cache", .no_embedded_nulls), cache_src); |
| 26337 | const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{ | 26355 | const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{ |
| 26338 | .needed_comptime_reason = "prefetch cache must be comptime-known", | 26356 | .needed_comptime_reason = "prefetch cache must be comptime-known", |
| 26339 | }); | 26357 | }); |
| ... | @@ -26397,23 +26415,23 @@ fn resolveExternOptions( | ... | @@ -26397,23 +26415,23 @@ fn resolveExternOptions( |
| 26397 | const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 26415 | const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26398 | const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 26416 | const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26399 | 26417 | ||
| 26400 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); | 26418 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src); |
| 26401 | const name = try sema.toConstString(block, name_src, name_ref, .{ | 26419 | const name = try sema.toConstString(block, name_src, name_ref, .{ |
| 26402 | .needed_comptime_reason = "name of the extern symbol must be comptime-known", | 26420 | .needed_comptime_reason = "name of the extern symbol must be comptime-known", |
| 26403 | }); | 26421 | }); |
| 26404 | 26422 | ||
| 26405 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name", .no_embedded_nulls), library_src); | 26423 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "library_name", .no_embedded_nulls), library_src); |
| 26406 | const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{ | 26424 | const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{ |
| 26407 | .needed_comptime_reason = "library in which extern symbol is must be comptime-known", | 26425 | .needed_comptime_reason = "library in which extern symbol is must be comptime-known", |
| 26408 | }); | 26426 | }); |
| 26409 | 26427 | ||
| 26410 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage", .no_embedded_nulls), linkage_src); | 26428 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src); |
| 26411 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{ | 26429 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{ |
| 26412 | .needed_comptime_reason = "linkage of the extern symbol must be comptime-known", | 26430 | .needed_comptime_reason = "linkage of the extern symbol must be comptime-known", |
| 26413 | }); | 26431 | }); |
| 26414 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); | 26432 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 26415 | 26433 | ||
| 26416 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local", .no_embedded_nulls), thread_local_src); | 26434 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_thread_local", .no_embedded_nulls), thread_local_src); |
| 26417 | const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{ | 26435 | const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{ |
| 26418 | .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known", | 26436 | .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known", |
| 26419 | }); | 26437 | }); |
| ... | @@ -26438,8 +26456,8 @@ fn resolveExternOptions( | ... | @@ -26438,8 +26456,8 @@ fn resolveExternOptions( |
| 26438 | } | 26456 | } |
| 26439 | 26457 | ||
| 26440 | return .{ | 26458 | return .{ |
| 26441 | .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls), | 26459 | .name = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls), |
| 26442 | .library_name = try ip.getOrPutStringOpt(gpa, library_name, .no_embedded_nulls), | 26460 | .library_name = try ip.getOrPutStringOpt(gpa, pt.tid, library_name, .no_embedded_nulls), |
| 26443 | .linkage = linkage, | 26461 | .linkage = linkage, |
| 26444 | .is_thread_local = is_thread_local_val.toBool(), | 26462 | .is_thread_local = is_thread_local_val.toBool(), |
| 26445 | }; | 26463 | }; |
| ... | @@ -27052,7 +27070,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP | ... | @@ -27052,7 +27070,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP |
| 27052 | block, | 27070 | block, |
| 27053 | LazySrcLoc.unneeded, | 27071 | LazySrcLoc.unneeded, |
| 27054 | panic_messages_ty.getNamespaceIndex(mod), | 27072 | panic_messages_ty.getNamespaceIndex(mod), |
| 27055 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls), | 27073 | try mod.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls), |
| 27056 | ) catch |err| switch (err) { | 27074 | ) catch |err| switch (err) { |
| 27057 | error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"), | 27075 | error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"), |
| 27058 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 27076 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| ... | @@ -31745,7 +31763,7 @@ fn coerceTupleToStruct( | ... | @@ -31745,7 +31763,7 @@ fn coerceTupleToStruct( |
| 31745 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) | 31763 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) |
| 31746 | anon_struct_type.names.get(ip)[tuple_field_index] | 31764 | anon_struct_type.names.get(ip)[tuple_field_index] |
| 31747 | else | 31765 | else |
| 31748 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{tuple_field_index}, .no_embedded_nulls), | 31766 | try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{tuple_field_index}, .no_embedded_nulls), |
| 31749 | .struct_type => ip.loadStructType(inst_ty.toIntern()).field_names.get(ip)[tuple_field_index], | 31767 | .struct_type => ip.loadStructType(inst_ty.toIntern()).field_names.get(ip)[tuple_field_index], |
| 31750 | else => unreachable, | 31768 | else => unreachable, |
| 31751 | }; | 31769 | }; |
| ... | @@ -31858,13 +31876,13 @@ fn coerceTupleToTuple( | ... | @@ -31858,13 +31876,13 @@ fn coerceTupleToTuple( |
| 31858 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) | 31876 | .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0) |
| 31859 | anon_struct_type.names.get(ip)[field_i] | 31877 | anon_struct_type.names.get(ip)[field_i] |
| 31860 | else | 31878 | else |
| 31861 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls), | 31879 | try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_i}, .no_embedded_nulls), |
| 31862 | .struct_type => s: { | 31880 | .struct_type => s: { |
| 31863 | const struct_type = ip.loadStructType(inst_ty.toIntern()); | 31881 | const struct_type = ip.loadStructType(inst_ty.toIntern()); |
| 31864 | if (struct_type.field_names.len > 0) { | 31882 | if (struct_type.field_names.len > 0) { |
| 31865 | break :s struct_type.field_names.get(ip)[field_i]; | 31883 | break :s struct_type.field_names.get(ip)[field_i]; |
| 31866 | } else { | 31884 | } else { |
| 31867 | break :s try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls); | 31885 | break :s try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_i}, .no_embedded_nulls); |
| 31868 | } | 31886 | } |
| 31869 | }, | 31887 | }, |
| 31870 | else => unreachable, | 31888 | else => unreachable, |
| ... | @@ -34849,7 +34867,7 @@ fn resolvePeerTypesInner( | ... | @@ -34849,7 +34867,7 @@ fn resolvePeerTypesInner( |
| 34849 | const result_buf = try sema.arena.create(PeerResolveResult); | 34867 | const result_buf = try sema.arena.create(PeerResolveResult); |
| 34850 | result_buf.* = result; | 34868 | result_buf.* = result; |
| 34851 | const field_name = if (is_tuple) | 34869 | const field_name = if (is_tuple) |
| 34852 | try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_index}, .no_embedded_nulls) | 34870 | try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls) |
| 34853 | else | 34871 | else |
| 34854 | field_names[field_index]; | 34872 | field_names[field_index]; |
| 34855 | 34873 | ||
| ... | @@ -36066,7 +36084,7 @@ fn semaStructFields( | ... | @@ -36066,7 +36084,7 @@ fn semaStructFields( |
| 36066 | 36084 | ||
| 36067 | // This string needs to outlive the ZIR code. | 36085 | // This string needs to outlive the ZIR code. |
| 36068 | if (opt_field_name_zir) |field_name_zir| { | 36086 | if (opt_field_name_zir) |field_name_zir| { |
| 36069 | const field_name = try ip.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); | 36087 | const field_name = try ip.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls); |
| 36070 | assert(struct_type.addFieldName(ip, field_name) == null); | 36088 | assert(struct_type.addFieldName(ip, field_name) == null); |
| 36071 | } | 36089 | } |
| 36072 | 36090 | ||
| ... | @@ -36567,7 +36585,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L | ... | @@ -36567,7 +36585,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L |
| 36567 | } | 36585 | } |
| 36568 | 36586 | ||
| 36569 | // This string needs to outlive the ZIR code. | 36587 | // This string needs to outlive the ZIR code. |
| 36570 | const field_name = try ip.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); | 36588 | const field_name = try ip.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls); |
| 36571 | if (enum_field_names.len != 0) { | 36589 | if (enum_field_names.len != 0) { |
| 36572 | enum_field_names[field_i] = field_name; | 36590 | enum_field_names[field_i] = field_name; |
| 36573 | } | 36591 | } |
| ... | @@ -36716,9 +36734,10 @@ fn generateUnionTagTypeNumbered( | ... | @@ -36716,9 +36734,10 @@ fn generateUnionTagTypeNumbered( |
| 36716 | 36734 | ||
| 36717 | const new_decl_index = try mod.allocateNewDecl(block.namespace); | 36735 | const new_decl_index = try mod.allocateNewDecl(block.namespace); |
| 36718 | errdefer mod.destroyDecl(new_decl_index); | 36736 | errdefer mod.destroyDecl(new_decl_index); |
| 36719 | const fqn = try union_owner_decl.fullyQualifiedName(mod); | 36737 | const fqn = try union_owner_decl.fullyQualifiedName(pt); |
| 36720 | const name = try ip.getOrPutStringFmt( | 36738 | const name = try ip.getOrPutStringFmt( |
| 36721 | gpa, | 36739 | gpa, |
| 36740 | pt.tid, | ||
| 36722 | "@typeInfo({}).Union.tag_type.?", | 36741 | "@typeInfo({}).Union.tag_type.?", |
| 36723 | .{fqn.fmt(ip)}, | 36742 | .{fqn.fmt(ip)}, |
| 36724 | .no_embedded_nulls, | 36743 | .no_embedded_nulls, |
| ... | @@ -36764,11 +36783,12 @@ fn generateUnionTagTypeSimple( | ... | @@ -36764,11 +36783,12 @@ fn generateUnionTagTypeSimple( |
| 36764 | const gpa = sema.gpa; | 36783 | const gpa = sema.gpa; |
| 36765 | 36784 | ||
| 36766 | const new_decl_index = new_decl_index: { | 36785 | const new_decl_index = new_decl_index: { |
| 36767 | const fqn = try union_owner_decl.fullyQualifiedName(mod); | 36786 | const fqn = try union_owner_decl.fullyQualifiedName(pt); |
| 36768 | const new_decl_index = try mod.allocateNewDecl(block.namespace); | 36787 | const new_decl_index = try mod.allocateNewDecl(block.namespace); |
| 36769 | errdefer mod.destroyDecl(new_decl_index); | 36788 | errdefer mod.destroyDecl(new_decl_index); |
| 36770 | const name = try ip.getOrPutStringFmt( | 36789 | const name = try ip.getOrPutStringFmt( |
| 36771 | gpa, | 36790 | gpa, |
| 36791 | pt.tid, | ||
| 36772 | "@typeInfo({}).Union.tag_type.?", | 36792 | "@typeInfo({}).Union.tag_type.?", |
| 36773 | .{fqn.fmt(ip)}, | 36793 | .{fqn.fmt(ip)}, |
| 36774 | .no_embedded_nulls, | 36794 | .no_embedded_nulls, |
src/Value.zig+2-2| ... | @@ -67,7 +67,7 @@ pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTermi | ... | @@ -67,7 +67,7 @@ pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTermi |
| 67 | const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(pt)); | 67 | const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(pt)); |
| 68 | const len: usize = @intCast(ty.arrayLen(mod)); | 68 | const len: usize = @intCast(ty.arrayLen(mod)); |
| 69 | try ip.string_bytes.appendNTimes(mod.gpa, byte, len); | 69 | try ip.string_bytes.appendNTimes(mod.gpa, byte, len); |
| 70 | return ip.getOrPutTrailingString(mod.gpa, len, .no_embedded_nulls); | 70 | return ip.getOrPutTrailingString(mod.gpa, pt.tid, len, .no_embedded_nulls); |
| 71 | }, | 71 | }, |
| 72 | } | 72 | } |
| 73 | } | 73 | } |
| ... | @@ -118,7 +118,7 @@ fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.Null | ... | @@ -118,7 +118,7 @@ fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.Null |
| 118 | const byte: u8 = @intCast(elem_val.toUnsignedInt(pt)); | 118 | const byte: u8 = @intCast(elem_val.toUnsignedInt(pt)); |
| 119 | ip.string_bytes.appendAssumeCapacity(byte); | 119 | ip.string_bytes.appendAssumeCapacity(byte); |
| 120 | } | 120 | } |
| 121 | return ip.getOrPutTrailingString(gpa, len, .no_embedded_nulls); | 121 | return ip.getOrPutTrailingString(gpa, pt.tid, len, .no_embedded_nulls); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | pub fn fromInterned(i: InternPool.Index) Value { | 124 | pub fn fromInterned(i: InternPool.Index) Value { |
src/Zcu.zig+13-674| ... | @@ -420,11 +420,11 @@ pub const Decl = struct { | ... | @@ -420,11 +420,11 @@ pub const Decl = struct { |
| 420 | return zcu.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(zcu, decl.name, writer); | 420 | return zcu.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(zcu, decl.name, writer); |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | pub fn fullyQualifiedName(decl: Decl, zcu: *Zcu) !InternPool.NullTerminatedString { | 423 | pub fn fullyQualifiedName(decl: Decl, pt: Zcu.PerThread) !InternPool.NullTerminatedString { |
| 424 | return if (decl.name_fully_qualified) | 424 | return if (decl.name_fully_qualified) |
| 425 | decl.name | 425 | decl.name |
| 426 | else | 426 | else |
| 427 | zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(zcu, decl.name); | 427 | pt.zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(pt, decl.name); |
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | pub fn typeOf(decl: Decl, zcu: *const Zcu) Type { | 430 | pub fn typeOf(decl: Decl, zcu: *const Zcu) Type { |
| ... | @@ -688,9 +688,10 @@ pub const Namespace = struct { | ... | @@ -688,9 +688,10 @@ pub const Namespace = struct { |
| 688 | 688 | ||
| 689 | pub fn fullyQualifiedName( | 689 | pub fn fullyQualifiedName( |
| 690 | ns: Namespace, | 690 | ns: Namespace, |
| 691 | zcu: *Zcu, | 691 | pt: Zcu.PerThread, |
| 692 | name: InternPool.NullTerminatedString, | 692 | name: InternPool.NullTerminatedString, |
| 693 | ) !InternPool.NullTerminatedString { | 693 | ) !InternPool.NullTerminatedString { |
| 694 | const zcu = pt.zcu; | ||
| 694 | const ip = &zcu.intern_pool; | 695 | const ip = &zcu.intern_pool; |
| 695 | const count = count: { | 696 | const count = count: { |
| 696 | var count: usize = name.length(ip) + 1; | 697 | var count: usize = name.length(ip) + 1; |
| ... | @@ -723,7 +724,7 @@ pub const Namespace = struct { | ... | @@ -723,7 +724,7 @@ pub const Namespace = struct { |
| 723 | }; | 724 | }; |
| 724 | } | 725 | } |
| 725 | 726 | ||
| 726 | return ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start, .no_embedded_nulls); | 727 | return ip.getOrPutTrailingString(gpa, pt.tid, ip.string_bytes.items.len - start, .no_embedded_nulls); |
| 727 | } | 728 | } |
| 728 | 729 | ||
| 729 | pub fn getType(ns: Namespace, zcu: *Zcu) Type { | 730 | pub fn getType(ns: Namespace, zcu: *Zcu) Type { |
| ... | @@ -875,11 +876,12 @@ pub const File = struct { | ... | @@ -875,11 +876,12 @@ pub const File = struct { |
| 875 | }; | 876 | }; |
| 876 | } | 877 | } |
| 877 | 878 | ||
| 878 | pub fn fullyQualifiedName(file: File, mod: *Module) !InternPool.NullTerminatedString { | 879 | pub fn fullyQualifiedName(file: File, pt: Zcu.PerThread) !InternPool.NullTerminatedString { |
| 879 | const ip = &mod.intern_pool; | 880 | const gpa = pt.zcu.gpa; |
| 881 | const ip = &pt.zcu.intern_pool; | ||
| 880 | const start = ip.string_bytes.items.len; | 882 | const start = ip.string_bytes.items.len; |
| 881 | try file.renderFullyQualifiedName(ip.string_bytes.writer(mod.gpa)); | 883 | try file.renderFullyQualifiedName(ip.string_bytes.writer(gpa)); |
| 882 | return ip.getOrPutTrailingString(mod.gpa, ip.string_bytes.items.len - start, .no_embedded_nulls); | 884 | return ip.getOrPutTrailingString(gpa, pt.tid, ip.string_bytes.items.len - start, .no_embedded_nulls); |
| 883 | } | 885 | } |
| 884 | 886 | ||
| 885 | pub fn fullPath(file: File, ally: Allocator) ![]u8 { | 887 | pub fn fullPath(file: File, ally: Allocator) ![]u8 { |
| ... | @@ -2569,8 +2571,8 @@ pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool { | ... | @@ -2569,8 +2571,8 @@ pub fn declIsRoot(mod: *Module, decl_index: Decl.Index) bool { |
| 2569 | } | 2571 | } |
| 2570 | 2572 | ||
| 2571 | // TODO https://github.com/ziglang/zig/issues/8643 | 2573 | // TODO https://github.com/ziglang/zig/issues/8643 |
| 2572 | const data_has_safety_tag = @sizeOf(Zir.Inst.Data) != 8; | 2574 | pub const data_has_safety_tag = @sizeOf(Zir.Inst.Data) != 8; |
| 2573 | const HackDataLayout = extern struct { | 2575 | pub const HackDataLayout = extern struct { |
| 2574 | data: [8]u8 align(@alignOf(Zir.Inst.Data)), | 2576 | data: [8]u8 align(@alignOf(Zir.Inst.Data)), |
| 2575 | safety_tag: u8, | 2577 | safety_tag: u8, |
| 2576 | }; | 2578 | }; |
| ... | @@ -2580,291 +2582,11 @@ comptime { | ... | @@ -2580,291 +2582,11 @@ comptime { |
| 2580 | } | 2582 | } |
| 2581 | } | 2583 | } |
| 2582 | 2584 | ||
| 2583 | pub fn astGenFile( | ||
| 2584 | zcu: *Zcu, | ||
| 2585 | file: *File, | ||
| 2586 | /// This parameter is provided separately from `file` because it is not | ||
| 2587 | /// safe to access `import_table` without a lock, and this index is needed | ||
| 2588 | /// in the call to `updateZirRefs`. | ||
| 2589 | file_index: File.Index, | ||
| 2590 | path_digest: Cache.BinDigest, | ||
| 2591 | opt_root_decl: Zcu.Decl.OptionalIndex, | ||
| 2592 | ) !void { | ||
| 2593 | assert(!file.mod.isBuiltin()); | ||
| 2594 | |||
| 2595 | const tracy = trace(@src()); | ||
| 2596 | defer tracy.end(); | ||
| 2597 | |||
| 2598 | const comp = zcu.comp; | ||
| 2599 | const gpa = zcu.gpa; | ||
| 2600 | |||
| 2601 | // In any case we need to examine the stat of the file to determine the course of action. | ||
| 2602 | var source_file = try file.mod.root.openFile(file.sub_file_path, .{}); | ||
| 2603 | defer source_file.close(); | ||
| 2604 | |||
| 2605 | const stat = try source_file.stat(); | ||
| 2606 | |||
| 2607 | const want_local_cache = file.mod == zcu.main_mod; | ||
| 2608 | const hex_digest = Cache.binToHex(path_digest); | ||
| 2609 | const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache; | ||
| 2610 | const zir_dir = cache_directory.handle; | ||
| 2611 | |||
| 2612 | // Determine whether we need to reload the file from disk and redo parsing and AstGen. | ||
| 2613 | var lock: std.fs.File.Lock = switch (file.status) { | ||
| 2614 | .never_loaded, .retryable_failure => lock: { | ||
| 2615 | // First, load the cached ZIR code, if any. | ||
| 2616 | log.debug("AstGen checking cache: {s} (local={}, digest={s})", .{ | ||
| 2617 | file.sub_file_path, want_local_cache, &hex_digest, | ||
| 2618 | }); | ||
| 2619 | |||
| 2620 | break :lock .shared; | ||
| 2621 | }, | ||
| 2622 | .parse_failure, .astgen_failure, .success_zir => lock: { | ||
| 2623 | const unchanged_metadata = | ||
| 2624 | stat.size == file.stat.size and | ||
| 2625 | stat.mtime == file.stat.mtime and | ||
| 2626 | stat.inode == file.stat.inode; | ||
| 2627 | |||
| 2628 | if (unchanged_metadata) { | ||
| 2629 | log.debug("unmodified metadata of file: {s}", .{file.sub_file_path}); | ||
| 2630 | return; | ||
| 2631 | } | ||
| 2632 | |||
| 2633 | log.debug("metadata changed: {s}", .{file.sub_file_path}); | ||
| 2634 | |||
| 2635 | break :lock .exclusive; | ||
| 2636 | }, | ||
| 2637 | }; | ||
| 2638 | |||
| 2639 | // We ask for a lock in order to coordinate with other zig processes. | ||
| 2640 | // If another process is already working on this file, we will get the cached | ||
| 2641 | // version. Likewise if we're working on AstGen and another process asks for | ||
| 2642 | // the cached file, they'll get it. | ||
| 2643 | const cache_file = while (true) { | ||
| 2644 | break zir_dir.createFile(&hex_digest, .{ | ||
| 2645 | .read = true, | ||
| 2646 | .truncate = false, | ||
| 2647 | .lock = lock, | ||
| 2648 | }) catch |err| switch (err) { | ||
| 2649 | error.NotDir => unreachable, // no dir components | ||
| 2650 | error.InvalidUtf8 => unreachable, // it's a hex encoded name | ||
| 2651 | error.InvalidWtf8 => unreachable, // it's a hex encoded name | ||
| 2652 | error.BadPathName => unreachable, // it's a hex encoded name | ||
| 2653 | error.NameTooLong => unreachable, // it's a fixed size name | ||
| 2654 | error.PipeBusy => unreachable, // it's not a pipe | ||
| 2655 | error.WouldBlock => unreachable, // not asking for non-blocking I/O | ||
| 2656 | // There are no dir components, so you would think that this was | ||
| 2657 | // unreachable, however we have observed on macOS two processes racing | ||
| 2658 | // to do openat() with O_CREAT manifest in ENOENT. | ||
| 2659 | error.FileNotFound => continue, | ||
| 2660 | |||
| 2661 | else => |e| return e, // Retryable errors are handled at callsite. | ||
| 2662 | }; | ||
| 2663 | }; | ||
| 2664 | defer cache_file.close(); | ||
| 2665 | |||
| 2666 | while (true) { | ||
| 2667 | update: { | ||
| 2668 | // First we read the header to determine the lengths of arrays. | ||
| 2669 | const header = cache_file.reader().readStruct(Zir.Header) catch |err| switch (err) { | ||
| 2670 | // This can happen if Zig bails out of this function between creating | ||
| 2671 | // the cached file and writing it. | ||
| 2672 | error.EndOfStream => break :update, | ||
| 2673 | else => |e| return e, | ||
| 2674 | }; | ||
| 2675 | const unchanged_metadata = | ||
| 2676 | stat.size == header.stat_size and | ||
| 2677 | stat.mtime == header.stat_mtime and | ||
| 2678 | stat.inode == header.stat_inode; | ||
| 2679 | |||
| 2680 | if (!unchanged_metadata) { | ||
| 2681 | log.debug("AstGen cache stale: {s}", .{file.sub_file_path}); | ||
| 2682 | break :update; | ||
| 2683 | } | ||
| 2684 | log.debug("AstGen cache hit: {s} instructions_len={d}", .{ | ||
| 2685 | file.sub_file_path, header.instructions_len, | ||
| 2686 | }); | ||
| 2687 | |||
| 2688 | file.zir = loadZirCacheBody(gpa, header, cache_file) catch |err| switch (err) { | ||
| 2689 | error.UnexpectedFileSize => { | ||
| 2690 | log.warn("unexpected EOF reading cached ZIR for {s}", .{file.sub_file_path}); | ||
| 2691 | break :update; | ||
| 2692 | }, | ||
| 2693 | else => |e| return e, | ||
| 2694 | }; | ||
| 2695 | file.zir_loaded = true; | ||
| 2696 | file.stat = .{ | ||
| 2697 | .size = header.stat_size, | ||
| 2698 | .inode = header.stat_inode, | ||
| 2699 | .mtime = header.stat_mtime, | ||
| 2700 | }; | ||
| 2701 | file.status = .success_zir; | ||
| 2702 | log.debug("AstGen cached success: {s}", .{file.sub_file_path}); | ||
| 2703 | |||
| 2704 | // TODO don't report compile errors until Sema @importFile | ||
| 2705 | if (file.zir.hasCompileErrors()) { | ||
| 2706 | { | ||
| 2707 | comp.mutex.lock(); | ||
| 2708 | defer comp.mutex.unlock(); | ||
| 2709 | try zcu.failed_files.putNoClobber(gpa, file, null); | ||
| 2710 | } | ||
| 2711 | file.status = .astgen_failure; | ||
| 2712 | return error.AnalysisFail; | ||
| 2713 | } | ||
| 2714 | return; | ||
| 2715 | } | ||
| 2716 | |||
| 2717 | // If we already have the exclusive lock then it is our job to update. | ||
| 2718 | if (builtin.os.tag == .wasi or lock == .exclusive) break; | ||
| 2719 | // Otherwise, unlock to give someone a chance to get the exclusive lock | ||
| 2720 | // and then upgrade to an exclusive lock. | ||
| 2721 | cache_file.unlock(); | ||
| 2722 | lock = .exclusive; | ||
| 2723 | try cache_file.lock(lock); | ||
| 2724 | } | ||
| 2725 | |||
| 2726 | // The cache is definitely stale so delete the contents to avoid an underwrite later. | ||
| 2727 | cache_file.setEndPos(0) catch |err| switch (err) { | ||
| 2728 | error.FileTooBig => unreachable, // 0 is not too big | ||
| 2729 | |||
| 2730 | else => |e| return e, | ||
| 2731 | }; | ||
| 2732 | |||
| 2733 | zcu.lockAndClearFileCompileError(file); | ||
| 2734 | |||
| 2735 | // If the previous ZIR does not have compile errors, keep it around | ||
| 2736 | // in case parsing or new ZIR fails. In case of successful ZIR update | ||
| 2737 | // at the end of this function we will free it. | ||
| 2738 | // We keep the previous ZIR loaded so that we can use it | ||
| 2739 | // for the update next time it does not have any compile errors. This avoids | ||
| 2740 | // needlessly tossing out semantic analysis work when an error is | ||
| 2741 | // temporarily introduced. | ||
| 2742 | if (file.zir_loaded and !file.zir.hasCompileErrors()) { | ||
| 2743 | assert(file.prev_zir == null); | ||
| 2744 | const prev_zir_ptr = try gpa.create(Zir); | ||
| 2745 | file.prev_zir = prev_zir_ptr; | ||
| 2746 | prev_zir_ptr.* = file.zir; | ||
| 2747 | file.zir = undefined; | ||
| 2748 | file.zir_loaded = false; | ||
| 2749 | } | ||
| 2750 | file.unload(gpa); | ||
| 2751 | |||
| 2752 | if (stat.size > std.math.maxInt(u32)) | ||
| 2753 | return error.FileTooBig; | ||
| 2754 | |||
| 2755 | const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0); | ||
| 2756 | defer if (!file.source_loaded) gpa.free(source); | ||
| 2757 | const amt = try source_file.readAll(source); | ||
| 2758 | if (amt != stat.size) | ||
| 2759 | return error.UnexpectedEndOfFile; | ||
| 2760 | |||
| 2761 | file.stat = .{ | ||
| 2762 | .size = stat.size, | ||
| 2763 | .inode = stat.inode, | ||
| 2764 | .mtime = stat.mtime, | ||
| 2765 | }; | ||
| 2766 | file.source = source; | ||
| 2767 | file.source_loaded = true; | ||
| 2768 | |||
| 2769 | file.tree = try Ast.parse(gpa, source, .zig); | ||
| 2770 | file.tree_loaded = true; | ||
| 2771 | |||
| 2772 | // Any potential AST errors are converted to ZIR errors here. | ||
| 2773 | file.zir = try AstGen.generate(gpa, file.tree); | ||
| 2774 | file.zir_loaded = true; | ||
| 2775 | file.status = .success_zir; | ||
| 2776 | log.debug("AstGen fresh success: {s}", .{file.sub_file_path}); | ||
| 2777 | |||
| 2778 | const safety_buffer = if (data_has_safety_tag) | ||
| 2779 | try gpa.alloc([8]u8, file.zir.instructions.len) | ||
| 2780 | else | ||
| 2781 | undefined; | ||
| 2782 | defer if (data_has_safety_tag) gpa.free(safety_buffer); | ||
| 2783 | const data_ptr = if (data_has_safety_tag) | ||
| 2784 | if (file.zir.instructions.len == 0) | ||
| 2785 | @as([*]const u8, undefined) | ||
| 2786 | else | ||
| 2787 | @as([*]const u8, @ptrCast(safety_buffer.ptr)) | ||
| 2788 | else | ||
| 2789 | @as([*]const u8, @ptrCast(file.zir.instructions.items(.data).ptr)); | ||
| 2790 | if (data_has_safety_tag) { | ||
| 2791 | // The `Data` union has a safety tag but in the file format we store it without. | ||
| 2792 | for (file.zir.instructions.items(.data), 0..) |*data, i| { | ||
| 2793 | const as_struct = @as(*const HackDataLayout, @ptrCast(data)); | ||
| 2794 | safety_buffer[i] = as_struct.data; | ||
| 2795 | } | ||
| 2796 | } | ||
| 2797 | |||
| 2798 | const header: Zir.Header = .{ | ||
| 2799 | .instructions_len = @as(u32, @intCast(file.zir.instructions.len)), | ||
| 2800 | .string_bytes_len = @as(u32, @intCast(file.zir.string_bytes.len)), | ||
| 2801 | .extra_len = @as(u32, @intCast(file.zir.extra.len)), | ||
| 2802 | |||
| 2803 | .stat_size = stat.size, | ||
| 2804 | .stat_inode = stat.inode, | ||
| 2805 | .stat_mtime = stat.mtime, | ||
| 2806 | }; | ||
| 2807 | var iovecs = [_]std.posix.iovec_const{ | ||
| 2808 | .{ | ||
| 2809 | .base = @as([*]const u8, @ptrCast(&header)), | ||
| 2810 | .len = @sizeOf(Zir.Header), | ||
| 2811 | }, | ||
| 2812 | .{ | ||
| 2813 | .base = @as([*]const u8, @ptrCast(file.zir.instructions.items(.tag).ptr)), | ||
| 2814 | .len = file.zir.instructions.len, | ||
| 2815 | }, | ||
| 2816 | .{ | ||
| 2817 | .base = data_ptr, | ||
| 2818 | .len = file.zir.instructions.len * 8, | ||
| 2819 | }, | ||
| 2820 | .{ | ||
| 2821 | .base = file.zir.string_bytes.ptr, | ||
| 2822 | .len = file.zir.string_bytes.len, | ||
| 2823 | }, | ||
| 2824 | .{ | ||
| 2825 | .base = @as([*]const u8, @ptrCast(file.zir.extra.ptr)), | ||
| 2826 | .len = file.zir.extra.len * 4, | ||
| 2827 | }, | ||
| 2828 | }; | ||
| 2829 | cache_file.writevAll(&iovecs) catch |err| { | ||
| 2830 | log.warn("unable to write cached ZIR code for {}{s} to {}{s}: {s}", .{ | ||
| 2831 | file.mod.root, file.sub_file_path, cache_directory, &hex_digest, @errorName(err), | ||
| 2832 | }); | ||
| 2833 | }; | ||
| 2834 | |||
| 2835 | if (file.zir.hasCompileErrors()) { | ||
| 2836 | { | ||
| 2837 | comp.mutex.lock(); | ||
| 2838 | defer comp.mutex.unlock(); | ||
| 2839 | try zcu.failed_files.putNoClobber(gpa, file, null); | ||
| 2840 | } | ||
| 2841 | file.status = .astgen_failure; | ||
| 2842 | return error.AnalysisFail; | ||
| 2843 | } | ||
| 2844 | |||
| 2845 | if (file.prev_zir) |prev_zir| { | ||
| 2846 | try updateZirRefs(zcu, file, file_index, prev_zir.*); | ||
| 2847 | // No need to keep previous ZIR. | ||
| 2848 | prev_zir.deinit(gpa); | ||
| 2849 | gpa.destroy(prev_zir); | ||
| 2850 | file.prev_zir = null; | ||
| 2851 | } | ||
| 2852 | |||
| 2853 | if (opt_root_decl.unwrap()) |root_decl| { | ||
| 2854 | // The root of this file must be re-analyzed, since the file has changed. | ||
| 2855 | comp.mutex.lock(); | ||
| 2856 | defer comp.mutex.unlock(); | ||
| 2857 | |||
| 2858 | log.debug("outdated root Decl: {}", .{root_decl}); | ||
| 2859 | try zcu.outdated_file_root.put(gpa, root_decl, {}); | ||
| 2860 | } | ||
| 2861 | } | ||
| 2862 | |||
| 2863 | pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir { | 2585 | pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir { |
| 2864 | return loadZirCacheBody(gpa, try cache_file.reader().readStruct(Zir.Header), cache_file); | 2586 | return loadZirCacheBody(gpa, try cache_file.reader().readStruct(Zir.Header), cache_file); |
| 2865 | } | 2587 | } |
| 2866 | 2588 | ||
| 2867 | fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) !Zir { | 2589 | pub fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) !Zir { |
| 2868 | var instructions: std.MultiArrayList(Zir.Inst) = .{}; | 2590 | var instructions: std.MultiArrayList(Zir.Inst) = .{}; |
| 2869 | errdefer instructions.deinit(gpa); | 2591 | errdefer instructions.deinit(gpa); |
| 2870 | 2592 | ||
| ... | @@ -2930,127 +2652,6 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) | ... | @@ -2930,127 +2652,6 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) |
| 2930 | return zir; | 2652 | return zir; |
| 2931 | } | 2653 | } |
| 2932 | 2654 | ||
| 2933 | /// This is called from the AstGen thread pool, so must acquire | ||
| 2934 | /// the Compilation mutex when acting on shared state. | ||
| 2935 | fn updateZirRefs(zcu: *Module, file: *File, file_index: File.Index, old_zir: Zir) !void { | ||
| 2936 | const gpa = zcu.gpa; | ||
| 2937 | const new_zir = file.zir; | ||
| 2938 | |||
| 2939 | var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{}; | ||
| 2940 | defer inst_map.deinit(gpa); | ||
| 2941 | |||
| 2942 | try mapOldZirToNew(gpa, old_zir, new_zir, &inst_map); | ||
| 2943 | |||
| 2944 | const old_tag = old_zir.instructions.items(.tag); | ||
| 2945 | const old_data = old_zir.instructions.items(.data); | ||
| 2946 | |||
| 2947 | // TODO: this should be done after all AstGen workers complete, to avoid | ||
| 2948 | // iterating over this full set for every updated file. | ||
| 2949 | for (zcu.intern_pool.tracked_insts.keys(), 0..) |*ti, idx_raw| { | ||
| 2950 | const ti_idx: InternPool.TrackedInst.Index = @enumFromInt(idx_raw); | ||
| 2951 | if (ti.file != file_index) continue; | ||
| 2952 | const old_inst = ti.inst; | ||
| 2953 | ti.inst = inst_map.get(ti.inst) orelse { | ||
| 2954 | // Tracking failed for this instruction. Invalidate associated `src_hash` deps. | ||
| 2955 | zcu.comp.mutex.lock(); | ||
| 2956 | defer zcu.comp.mutex.unlock(); | ||
| 2957 | log.debug("tracking failed for %{d}", .{old_inst}); | ||
| 2958 | try zcu.markDependeeOutdated(.{ .src_hash = ti_idx }); | ||
| 2959 | continue; | ||
| 2960 | }; | ||
| 2961 | |||
| 2962 | if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: { | ||
| 2963 | if (new_zir.getAssociatedSrcHash(ti.inst)) |new_hash| { | ||
| 2964 | if (std.zig.srcHashEql(old_hash, new_hash)) { | ||
| 2965 | break :hash_changed; | ||
| 2966 | } | ||
| 2967 | log.debug("hash for (%{d} -> %{d}) changed: {} -> {}", .{ | ||
| 2968 | old_inst, | ||
| 2969 | ti.inst, | ||
| 2970 | std.fmt.fmtSliceHexLower(&old_hash), | ||
| 2971 | std.fmt.fmtSliceHexLower(&new_hash), | ||
| 2972 | }); | ||
| 2973 | } | ||
| 2974 | // The source hash associated with this instruction changed - invalidate relevant dependencies. | ||
| 2975 | zcu.comp.mutex.lock(); | ||
| 2976 | defer zcu.comp.mutex.unlock(); | ||
| 2977 | try zcu.markDependeeOutdated(.{ .src_hash = ti_idx }); | ||
| 2978 | } | ||
| 2979 | |||
| 2980 | // If this is a `struct_decl` etc, we must invalidate any outdated namespace dependencies. | ||
| 2981 | const has_namespace = switch (old_tag[@intFromEnum(old_inst)]) { | ||
| 2982 | .extended => switch (old_data[@intFromEnum(old_inst)].extended.opcode) { | ||
| 2983 | .struct_decl, .union_decl, .opaque_decl, .enum_decl => true, | ||
| 2984 | else => false, | ||
| 2985 | }, | ||
| 2986 | else => false, | ||
| 2987 | }; | ||
| 2988 | if (!has_namespace) continue; | ||
| 2989 | |||
| 2990 | var old_names: std.AutoArrayHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{}; | ||
| 2991 | defer old_names.deinit(zcu.gpa); | ||
| 2992 | { | ||
| 2993 | var it = old_zir.declIterator(old_inst); | ||
| 2994 | while (it.next()) |decl_inst| { | ||
| 2995 | const decl_name = old_zir.getDeclaration(decl_inst)[0].name; | ||
| 2996 | switch (decl_name) { | ||
| 2997 | .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue, | ||
| 2998 | _ => if (decl_name.isNamedTest(old_zir)) continue, | ||
| 2999 | } | ||
| 3000 | const name_zir = decl_name.toString(old_zir).?; | ||
| 3001 | const name_ip = try zcu.intern_pool.getOrPutString( | ||
| 3002 | zcu.gpa, | ||
| 3003 | old_zir.nullTerminatedString(name_zir), | ||
| 3004 | .no_embedded_nulls, | ||
| 3005 | ); | ||
| 3006 | try old_names.put(zcu.gpa, name_ip, {}); | ||
| 3007 | } | ||
| 3008 | } | ||
| 3009 | var any_change = false; | ||
| 3010 | { | ||
| 3011 | var it = new_zir.declIterator(ti.inst); | ||
| 3012 | while (it.next()) |decl_inst| { | ||
| 3013 | const decl_name = old_zir.getDeclaration(decl_inst)[0].name; | ||
| 3014 | switch (decl_name) { | ||
| 3015 | .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue, | ||
| 3016 | _ => if (decl_name.isNamedTest(old_zir)) continue, | ||
| 3017 | } | ||
| 3018 | const name_zir = decl_name.toString(old_zir).?; | ||
| 3019 | const name_ip = try zcu.intern_pool.getOrPutString( | ||
| 3020 | zcu.gpa, | ||
| 3021 | old_zir.nullTerminatedString(name_zir), | ||
| 3022 | .no_embedded_nulls, | ||
| 3023 | ); | ||
| 3024 | if (!old_names.swapRemove(name_ip)) continue; | ||
| 3025 | // Name added | ||
| 3026 | any_change = true; | ||
| 3027 | zcu.comp.mutex.lock(); | ||
| 3028 | defer zcu.comp.mutex.unlock(); | ||
| 3029 | try zcu.markDependeeOutdated(.{ .namespace_name = .{ | ||
| 3030 | .namespace = ti_idx, | ||
| 3031 | .name = name_ip, | ||
| 3032 | } }); | ||
| 3033 | } | ||
| 3034 | } | ||
| 3035 | // The only elements remaining in `old_names` now are any names which were removed. | ||
| 3036 | for (old_names.keys()) |name_ip| { | ||
| 3037 | any_change = true; | ||
| 3038 | zcu.comp.mutex.lock(); | ||
| 3039 | defer zcu.comp.mutex.unlock(); | ||
| 3040 | try zcu.markDependeeOutdated(.{ .namespace_name = .{ | ||
| 3041 | .namespace = ti_idx, | ||
| 3042 | .name = name_ip, | ||
| 3043 | } }); | ||
| 3044 | } | ||
| 3045 | |||
| 3046 | if (any_change) { | ||
| 3047 | zcu.comp.mutex.lock(); | ||
| 3048 | defer zcu.comp.mutex.unlock(); | ||
| 3049 | try zcu.markDependeeOutdated(.{ .namespace = ti_idx }); | ||
| 3050 | } | ||
| 3051 | } | ||
| 3052 | } | ||
| 3053 | |||
| 3054 | pub fn markDependeeOutdated(zcu: *Zcu, dependee: InternPool.Dependee) !void { | 2655 | pub fn markDependeeOutdated(zcu: *Zcu, dependee: InternPool.Dependee) !void { |
| 3055 | log.debug("outdated dependee: {}", .{dependee}); | 2656 | log.debug("outdated dependee: {}", .{dependee}); |
| 3056 | var it = zcu.intern_pool.dependencyIterator(dependee); | 2657 | var it = zcu.intern_pool.dependencyIterator(dependee); |
| ... | @@ -3695,268 +3296,6 @@ fn computePathDigest(zcu: *Zcu, mod: *Package.Module, sub_file_path: []const u8) | ... | @@ -3695,268 +3296,6 @@ fn computePathDigest(zcu: *Zcu, mod: *Package.Module, sub_file_path: []const u8) |
| 3695 | return bin; | 3296 | return bin; |
| 3696 | } | 3297 | } |
| 3697 | 3298 | ||
| 3698 | pub fn scanNamespace( | ||
| 3699 | zcu: *Zcu, | ||
| 3700 | namespace_index: Namespace.Index, | ||
| 3701 | decls: []const Zir.Inst.Index, | ||
| 3702 | parent_decl: *Decl, | ||
| 3703 | ) Allocator.Error!void { | ||
| 3704 | const tracy = trace(@src()); | ||
| 3705 | defer tracy.end(); | ||
| 3706 | |||
| 3707 | const gpa = zcu.gpa; | ||
| 3708 | const namespace = zcu.namespacePtr(namespace_index); | ||
| 3709 | |||
| 3710 | // For incremental updates, `scanDecl` wants to look up existing decls by their ZIR index rather | ||
| 3711 | // than their name. We'll build an efficient mapping now, then discard the current `decls`. | ||
| 3712 | var existing_by_inst: std.AutoHashMapUnmanaged(InternPool.TrackedInst.Index, Decl.Index) = .{}; | ||
| 3713 | defer existing_by_inst.deinit(gpa); | ||
| 3714 | |||
| 3715 | try existing_by_inst.ensureTotalCapacity(gpa, @intCast(namespace.decls.count())); | ||
| 3716 | |||
| 3717 | for (namespace.decls.keys()) |decl_index| { | ||
| 3718 | const decl = zcu.declPtr(decl_index); | ||
| 3719 | existing_by_inst.putAssumeCapacityNoClobber(decl.zir_decl_index.unwrap().?, decl_index); | ||
| 3720 | } | ||
| 3721 | |||
| 3722 | var seen_decls: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{}; | ||
| 3723 | defer seen_decls.deinit(gpa); | ||
| 3724 | |||
| 3725 | try zcu.comp.work_queue.ensureUnusedCapacity(decls.len); | ||
| 3726 | |||
| 3727 | namespace.decls.clearRetainingCapacity(); | ||
| 3728 | try namespace.decls.ensureTotalCapacity(gpa, decls.len); | ||
| 3729 | |||
| 3730 | namespace.usingnamespace_set.clearRetainingCapacity(); | ||
| 3731 | |||
| 3732 | var scan_decl_iter: ScanDeclIter = .{ | ||
| 3733 | .zcu = zcu, | ||
| 3734 | .namespace_index = namespace_index, | ||
| 3735 | .parent_decl = parent_decl, | ||
| 3736 | .seen_decls = &seen_decls, | ||
| 3737 | .existing_by_inst = &existing_by_inst, | ||
| 3738 | .pass = .named, | ||
| 3739 | }; | ||
| 3740 | for (decls) |decl_inst| { | ||
| 3741 | try scanDecl(&scan_decl_iter, decl_inst); | ||
| 3742 | } | ||
| 3743 | scan_decl_iter.pass = .unnamed; | ||
| 3744 | for (decls) |decl_inst| { | ||
| 3745 | try scanDecl(&scan_decl_iter, decl_inst); | ||
| 3746 | } | ||
| 3747 | |||
| 3748 | if (seen_decls.count() != namespace.decls.count()) { | ||
| 3749 | // Do a pass over the namespace contents and remove any decls from the last update | ||
| 3750 | // which were removed in this one. | ||
| 3751 | var i: usize = 0; | ||
| 3752 | while (i < namespace.decls.count()) { | ||
| 3753 | const decl_index = namespace.decls.keys()[i]; | ||
| 3754 | const decl = zcu.declPtr(decl_index); | ||
| 3755 | if (!seen_decls.contains(decl.name)) { | ||
| 3756 | // We must preserve namespace ordering for @typeInfo. | ||
| 3757 | namespace.decls.orderedRemoveAt(i); | ||
| 3758 | i -= 1; | ||
| 3759 | } | ||
| 3760 | } | ||
| 3761 | } | ||
| 3762 | } | ||
| 3763 | |||
| 3764 | const ScanDeclIter = struct { | ||
| 3765 | zcu: *Zcu, | ||
| 3766 | namespace_index: Namespace.Index, | ||
| 3767 | parent_decl: *Decl, | ||
| 3768 | seen_decls: *std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void), | ||
| 3769 | existing_by_inst: *const std.AutoHashMapUnmanaged(InternPool.TrackedInst.Index, Decl.Index), | ||
| 3770 | /// Decl scanning is run in two passes, so that we can detect when a generated | ||
| 3771 | /// name would clash with an explicit name and use a different one. | ||
| 3772 | pass: enum { named, unnamed }, | ||
| 3773 | usingnamespace_index: usize = 0, | ||
| 3774 | comptime_index: usize = 0, | ||
| 3775 | unnamed_test_index: usize = 0, | ||
| 3776 | |||
| 3777 | fn avoidNameConflict(iter: *ScanDeclIter, comptime fmt: []const u8, args: anytype) !InternPool.NullTerminatedString { | ||
| 3778 | const zcu = iter.zcu; | ||
| 3779 | const gpa = zcu.gpa; | ||
| 3780 | const ip = &zcu.intern_pool; | ||
| 3781 | var name = try ip.getOrPutStringFmt(gpa, fmt, args, .no_embedded_nulls); | ||
| 3782 | var gop = try iter.seen_decls.getOrPut(gpa, name); | ||
| 3783 | var next_suffix: u32 = 0; | ||
| 3784 | while (gop.found_existing) { | ||
| 3785 | name = try ip.getOrPutStringFmt(gpa, "{}_{d}", .{ name.fmt(ip), next_suffix }, .no_embedded_nulls); | ||
| 3786 | gop = try iter.seen_decls.getOrPut(gpa, name); | ||
| 3787 | next_suffix += 1; | ||
| 3788 | } | ||
| 3789 | return name; | ||
| 3790 | } | ||
| 3791 | }; | ||
| 3792 | |||
| 3793 | fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void { | ||
| 3794 | const tracy = trace(@src()); | ||
| 3795 | defer tracy.end(); | ||
| 3796 | |||
| 3797 | const zcu = iter.zcu; | ||
| 3798 | const namespace_index = iter.namespace_index; | ||
| 3799 | const namespace = zcu.namespacePtr(namespace_index); | ||
| 3800 | const gpa = zcu.gpa; | ||
| 3801 | const zir = namespace.fileScope(zcu).zir; | ||
| 3802 | const ip = &zcu.intern_pool; | ||
| 3803 | |||
| 3804 | const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration; | ||
| 3805 | const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index); | ||
| 3806 | const declaration = extra.data; | ||
| 3807 | |||
| 3808 | // Every Decl needs a name. | ||
| 3809 | const decl_name: InternPool.NullTerminatedString, const kind: Decl.Kind, const is_named_test: bool = switch (declaration.name) { | ||
| 3810 | .@"comptime" => info: { | ||
| 3811 | if (iter.pass != .unnamed) return; | ||
| 3812 | const i = iter.comptime_index; | ||
| 3813 | iter.comptime_index += 1; | ||
| 3814 | break :info .{ | ||
| 3815 | try iter.avoidNameConflict("comptime_{d}", .{i}), | ||
| 3816 | .@"comptime", | ||
| 3817 | false, | ||
| 3818 | }; | ||
| 3819 | }, | ||
| 3820 | .@"usingnamespace" => info: { | ||
| 3821 | // TODO: this isn't right! These should be considered unnamed. Name conflicts can happen here. | ||
| 3822 | // The problem is, we need to preserve the decl ordering for `@typeInfo`. | ||
| 3823 | // I'm not bothering to fix this now, since some upcoming changes will change this code significantly anyway. | ||
| 3824 | if (iter.pass != .named) return; | ||
| 3825 | const i = iter.usingnamespace_index; | ||
| 3826 | iter.usingnamespace_index += 1; | ||
| 3827 | break :info .{ | ||
| 3828 | try iter.avoidNameConflict("usingnamespace_{d}", .{i}), | ||
| 3829 | .@"usingnamespace", | ||
| 3830 | false, | ||
| 3831 | }; | ||
| 3832 | }, | ||
| 3833 | .unnamed_test => info: { | ||
| 3834 | if (iter.pass != .unnamed) return; | ||
| 3835 | const i = iter.unnamed_test_index; | ||
| 3836 | iter.unnamed_test_index += 1; | ||
| 3837 | break :info .{ | ||
| 3838 | try iter.avoidNameConflict("test_{d}", .{i}), | ||
| 3839 | .@"test", | ||
| 3840 | false, | ||
| 3841 | }; | ||
| 3842 | }, | ||
| 3843 | .decltest => info: { | ||
| 3844 | // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary. | ||
| 3845 | if (iter.pass != .unnamed) return; | ||
| 3846 | assert(declaration.flags.has_doc_comment); | ||
| 3847 | const name = zir.nullTerminatedString(@enumFromInt(zir.extra[extra.end])); | ||
| 3848 | break :info .{ | ||
| 3849 | try iter.avoidNameConflict("decltest.{s}", .{name}), | ||
| 3850 | .@"test", | ||
| 3851 | true, | ||
| 3852 | }; | ||
| 3853 | }, | ||
| 3854 | _ => if (declaration.name.isNamedTest(zir)) info: { | ||
| 3855 | // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary. | ||
| 3856 | if (iter.pass != .unnamed) return; | ||
| 3857 | break :info .{ | ||
| 3858 | try iter.avoidNameConflict("test.{s}", .{zir.nullTerminatedString(declaration.name.toString(zir).?)}), | ||
| 3859 | .@"test", | ||
| 3860 | true, | ||
| 3861 | }; | ||
| 3862 | } else info: { | ||
| 3863 | if (iter.pass != .named) return; | ||
| 3864 | const name = try ip.getOrPutString( | ||
| 3865 | gpa, | ||
| 3866 | zir.nullTerminatedString(declaration.name.toString(zir).?), | ||
| 3867 | .no_embedded_nulls, | ||
| 3868 | ); | ||
| 3869 | try iter.seen_decls.putNoClobber(gpa, name, {}); | ||
| 3870 | break :info .{ | ||
| 3871 | name, | ||
| 3872 | .named, | ||
| 3873 | false, | ||
| 3874 | }; | ||
| 3875 | }, | ||
| 3876 | }; | ||
| 3877 | |||
| 3878 | switch (kind) { | ||
| 3879 | .@"usingnamespace" => try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1), | ||
| 3880 | .@"test" => try zcu.test_functions.ensureUnusedCapacity(gpa, 1), | ||
| 3881 | else => {}, | ||
| 3882 | } | ||
| 3883 | |||
| 3884 | const parent_file_scope_index = iter.parent_decl.getFileScopeIndex(zcu); | ||
| 3885 | const tracked_inst = try ip.trackZir(gpa, parent_file_scope_index, decl_inst); | ||
| 3886 | |||
| 3887 | // We create a Decl for it regardless of analysis status. | ||
| 3888 | |||
| 3889 | const prev_exported, const decl_index = if (iter.existing_by_inst.get(tracked_inst)) |decl_index| decl_index: { | ||
| 3890 | // We need only update this existing Decl. | ||
| 3891 | const decl = zcu.declPtr(decl_index); | ||
| 3892 | const was_exported = decl.is_exported; | ||
| 3893 | assert(decl.kind == kind); // ZIR tracking should preserve this | ||
| 3894 | decl.name = decl_name; | ||
| 3895 | decl.is_pub = declaration.flags.is_pub; | ||
| 3896 | decl.is_exported = declaration.flags.is_export; | ||
| 3897 | break :decl_index .{ was_exported, decl_index }; | ||
| 3898 | } else decl_index: { | ||
| 3899 | // Create and set up a new Decl. | ||
| 3900 | const new_decl_index = try zcu.allocateNewDecl(namespace_index); | ||
| 3901 | const new_decl = zcu.declPtr(new_decl_index); | ||
| 3902 | new_decl.kind = kind; | ||
| 3903 | new_decl.name = decl_name; | ||
| 3904 | new_decl.is_pub = declaration.flags.is_pub; | ||
| 3905 | new_decl.is_exported = declaration.flags.is_export; | ||
| 3906 | new_decl.zir_decl_index = tracked_inst.toOptional(); | ||
| 3907 | break :decl_index .{ false, new_decl_index }; | ||
| 3908 | }; | ||
| 3909 | |||
| 3910 | const decl = zcu.declPtr(decl_index); | ||
| 3911 | |||
| 3912 | namespace.decls.putAssumeCapacityNoClobberContext(decl_index, {}, .{ .zcu = zcu }); | ||
| 3913 | |||
| 3914 | const comp = zcu.comp; | ||
| 3915 | const decl_mod = namespace.fileScope(zcu).mod; | ||
| 3916 | const want_analysis = declaration.flags.is_export or switch (kind) { | ||
| 3917 | .anon => unreachable, | ||
| 3918 | .@"comptime" => true, | ||
| 3919 | .@"usingnamespace" => a: { | ||
| 3920 | namespace.usingnamespace_set.putAssumeCapacityNoClobber(decl_index, declaration.flags.is_pub); | ||
| 3921 | break :a true; | ||
| 3922 | }, | ||
| 3923 | .named => false, | ||
| 3924 | .@"test" => a: { | ||
| 3925 | if (!comp.config.is_test) break :a false; | ||
| 3926 | if (decl_mod != zcu.main_mod) break :a false; | ||
| 3927 | if (is_named_test and comp.test_filters.len > 0) { | ||
| 3928 | const decl_fqn = try namespace.fullyQualifiedName(zcu, decl_name); | ||
| 3929 | const decl_fqn_slice = decl_fqn.toSlice(ip); | ||
| 3930 | for (comp.test_filters) |test_filter| { | ||
| 3931 | if (mem.indexOf(u8, decl_fqn_slice, test_filter)) |_| break; | ||
| 3932 | } else break :a false; | ||
| 3933 | } | ||
| 3934 | zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update | ||
| 3935 | break :a true; | ||
| 3936 | }, | ||
| 3937 | }; | ||
| 3938 | |||
| 3939 | if (want_analysis) { | ||
| 3940 | // We will not queue analysis if the decl has been analyzed on a previous update and | ||
| 3941 | // `is_export` is unchanged. In this case, the incremental update mechanism will handle | ||
| 3942 | // re-analysis for us if necessary. | ||
| 3943 | if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) { | ||
| 3944 | log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{ | ||
| 3945 | namespace.fileScope(zcu).sub_file_path, decl_name.fmt(ip), decl_index, | ||
| 3946 | }); | ||
| 3947 | comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index }); | ||
| 3948 | } | ||
| 3949 | } | ||
| 3950 | |||
| 3951 | if (decl.getOwnedFunction(zcu) != null) { | ||
| 3952 | // TODO this logic is insufficient; namespaces we don't re-scan may still require | ||
| 3953 | // updated line numbers. Look into this! | ||
| 3954 | // TODO Look into detecting when this would be unnecessary by storing enough state | ||
| 3955 | // in `Decl` to notice that the line number did not change. | ||
| 3956 | comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index }); | ||
| 3957 | } | ||
| 3958 | } | ||
| 3959 | |||
| 3960 | /// Cancel the creation of an anon decl and delete any references to it. | 3299 | /// Cancel the creation of an anon decl and delete any references to it. |
| 3961 | /// If other decls depend on this decl, they must be aborted first. | 3300 | /// If other decls depend on this decl, they must be aborted first. |
| 3962 | pub fn abortAnonDecl(mod: *Module, decl_index: Decl.Index) void { | 3301 | pub fn abortAnonDecl(mod: *Module, decl_index: Decl.Index) void { |
src/Zcu/PerThread.zig+705-20| ... | @@ -5,6 +5,411 @@ tid: Id, | ... | @@ -5,6 +5,411 @@ tid: Id, |
| 5 | 5 | ||
| 6 | pub const Id = if (builtin.single_threaded) enum { main } else enum(usize) { main, _ }; | 6 | pub const Id = if (builtin.single_threaded) enum { main } else enum(usize) { main, _ }; |
| 7 | 7 | ||
| 8 | pub fn astGenFile( | ||
| 9 | pt: Zcu.PerThread, | ||
| 10 | file: *Zcu.File, | ||
| 11 | /// This parameter is provided separately from `file` because it is not | ||
| 12 | /// safe to access `import_table` without a lock, and this index is needed | ||
| 13 | /// in the call to `updateZirRefs`. | ||
| 14 | file_index: Zcu.File.Index, | ||
| 15 | path_digest: Cache.BinDigest, | ||
| 16 | opt_root_decl: Zcu.Decl.OptionalIndex, | ||
| 17 | ) !void { | ||
| 18 | assert(!file.mod.isBuiltin()); | ||
| 19 | |||
| 20 | const tracy = trace(@src()); | ||
| 21 | defer tracy.end(); | ||
| 22 | |||
| 23 | const zcu = pt.zcu; | ||
| 24 | const comp = zcu.comp; | ||
| 25 | const gpa = zcu.gpa; | ||
| 26 | |||
| 27 | // In any case we need to examine the stat of the file to determine the course of action. | ||
| 28 | var source_file = try file.mod.root.openFile(file.sub_file_path, .{}); | ||
| 29 | defer source_file.close(); | ||
| 30 | |||
| 31 | const stat = try source_file.stat(); | ||
| 32 | |||
| 33 | const want_local_cache = file.mod == zcu.main_mod; | ||
| 34 | const hex_digest = Cache.binToHex(path_digest); | ||
| 35 | const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache; | ||
| 36 | const zir_dir = cache_directory.handle; | ||
| 37 | |||
| 38 | // Determine whether we need to reload the file from disk and redo parsing and AstGen. | ||
| 39 | var lock: std.fs.File.Lock = switch (file.status) { | ||
| 40 | .never_loaded, .retryable_failure => lock: { | ||
| 41 | // First, load the cached ZIR code, if any. | ||
| 42 | log.debug("AstGen checking cache: {s} (local={}, digest={s})", .{ | ||
| 43 | file.sub_file_path, want_local_cache, &hex_digest, | ||
| 44 | }); | ||
| 45 | |||
| 46 | break :lock .shared; | ||
| 47 | }, | ||
| 48 | .parse_failure, .astgen_failure, .success_zir => lock: { | ||
| 49 | const unchanged_metadata = | ||
| 50 | stat.size == file.stat.size and | ||
| 51 | stat.mtime == file.stat.mtime and | ||
| 52 | stat.inode == file.stat.inode; | ||
| 53 | |||
| 54 | if (unchanged_metadata) { | ||
| 55 | log.debug("unmodified metadata of file: {s}", .{file.sub_file_path}); | ||
| 56 | return; | ||
| 57 | } | ||
| 58 | |||
| 59 | log.debug("metadata changed: {s}", .{file.sub_file_path}); | ||
| 60 | |||
| 61 | break :lock .exclusive; | ||
| 62 | }, | ||
| 63 | }; | ||
| 64 | |||
| 65 | // We ask for a lock in order to coordinate with other zig processes. | ||
| 66 | // If another process is already working on this file, we will get the cached | ||
| 67 | // version. Likewise if we're working on AstGen and another process asks for | ||
| 68 | // the cached file, they'll get it. | ||
| 69 | const cache_file = while (true) { | ||
| 70 | break zir_dir.createFile(&hex_digest, .{ | ||
| 71 | .read = true, | ||
| 72 | .truncate = false, | ||
| 73 | .lock = lock, | ||
| 74 | }) catch |err| switch (err) { | ||
| 75 | error.NotDir => unreachable, // no dir components | ||
| 76 | error.InvalidUtf8 => unreachable, // it's a hex encoded name | ||
| 77 | error.InvalidWtf8 => unreachable, // it's a hex encoded name | ||
| 78 | error.BadPathName => unreachable, // it's a hex encoded name | ||
| 79 | error.NameTooLong => unreachable, // it's a fixed size name | ||
| 80 | error.PipeBusy => unreachable, // it's not a pipe | ||
| 81 | error.WouldBlock => unreachable, // not asking for non-blocking I/O | ||
| 82 | // There are no dir components, so you would think that this was | ||
| 83 | // unreachable, however we have observed on macOS two processes racing | ||
| 84 | // to do openat() with O_CREAT manifest in ENOENT. | ||
| 85 | error.FileNotFound => continue, | ||
| 86 | |||
| 87 | else => |e| return e, // Retryable errors are handled at callsite. | ||
| 88 | }; | ||
| 89 | }; | ||
| 90 | defer cache_file.close(); | ||
| 91 | |||
| 92 | while (true) { | ||
| 93 | update: { | ||
| 94 | // First we read the header to determine the lengths of arrays. | ||
| 95 | const header = cache_file.reader().readStruct(Zir.Header) catch |err| switch (err) { | ||
| 96 | // This can happen if Zig bails out of this function between creating | ||
| 97 | // the cached file and writing it. | ||
| 98 | error.EndOfStream => break :update, | ||
| 99 | else => |e| return e, | ||
| 100 | }; | ||
| 101 | const unchanged_metadata = | ||
| 102 | stat.size == header.stat_size and | ||
| 103 | stat.mtime == header.stat_mtime and | ||
| 104 | stat.inode == header.stat_inode; | ||
| 105 | |||
| 106 | if (!unchanged_metadata) { | ||
| 107 | log.debug("AstGen cache stale: {s}", .{file.sub_file_path}); | ||
| 108 | break :update; | ||
| 109 | } | ||
| 110 | log.debug("AstGen cache hit: {s} instructions_len={d}", .{ | ||
| 111 | file.sub_file_path, header.instructions_len, | ||
| 112 | }); | ||
| 113 | |||
| 114 | file.zir = Zcu.loadZirCacheBody(gpa, header, cache_file) catch |err| switch (err) { | ||
| 115 | error.UnexpectedFileSize => { | ||
| 116 | log.warn("unexpected EOF reading cached ZIR for {s}", .{file.sub_file_path}); | ||
| 117 | break :update; | ||
| 118 | }, | ||
| 119 | else => |e| return e, | ||
| 120 | }; | ||
| 121 | file.zir_loaded = true; | ||
| 122 | file.stat = .{ | ||
| 123 | .size = header.stat_size, | ||
| 124 | .inode = header.stat_inode, | ||
| 125 | .mtime = header.stat_mtime, | ||
| 126 | }; | ||
| 127 | file.status = .success_zir; | ||
| 128 | log.debug("AstGen cached success: {s}", .{file.sub_file_path}); | ||
| 129 | |||
| 130 | // TODO don't report compile errors until Sema @importFile | ||
| 131 | if (file.zir.hasCompileErrors()) { | ||
| 132 | { | ||
| 133 | comp.mutex.lock(); | ||
| 134 | defer comp.mutex.unlock(); | ||
| 135 | try zcu.failed_files.putNoClobber(gpa, file, null); | ||
| 136 | } | ||
| 137 | file.status = .astgen_failure; | ||
| 138 | return error.AnalysisFail; | ||
| 139 | } | ||
| 140 | return; | ||
| 141 | } | ||
| 142 | |||
| 143 | // If we already have the exclusive lock then it is our job to update. | ||
| 144 | if (builtin.os.tag == .wasi or lock == .exclusive) break; | ||
| 145 | // Otherwise, unlock to give someone a chance to get the exclusive lock | ||
| 146 | // and then upgrade to an exclusive lock. | ||
| 147 | cache_file.unlock(); | ||
| 148 | lock = .exclusive; | ||
| 149 | try cache_file.lock(lock); | ||
| 150 | } | ||
| 151 | |||
| 152 | // The cache is definitely stale so delete the contents to avoid an underwrite later. | ||
| 153 | cache_file.setEndPos(0) catch |err| switch (err) { | ||
| 154 | error.FileTooBig => unreachable, // 0 is not too big | ||
| 155 | |||
| 156 | else => |e| return e, | ||
| 157 | }; | ||
| 158 | |||
| 159 | pt.lockAndClearFileCompileError(file); | ||
| 160 | |||
| 161 | // If the previous ZIR does not have compile errors, keep it around | ||
| 162 | // in case parsing or new ZIR fails. In case of successful ZIR update | ||
| 163 | // at the end of this function we will free it. | ||
| 164 | // We keep the previous ZIR loaded so that we can use it | ||
| 165 | // for the update next time it does not have any compile errors. This avoids | ||
| 166 | // needlessly tossing out semantic analysis work when an error is | ||
| 167 | // temporarily introduced. | ||
| 168 | if (file.zir_loaded and !file.zir.hasCompileErrors()) { | ||
| 169 | assert(file.prev_zir == null); | ||
| 170 | const prev_zir_ptr = try gpa.create(Zir); | ||
| 171 | file.prev_zir = prev_zir_ptr; | ||
| 172 | prev_zir_ptr.* = file.zir; | ||
| 173 | file.zir = undefined; | ||
| 174 | file.zir_loaded = false; | ||
| 175 | } | ||
| 176 | file.unload(gpa); | ||
| 177 | |||
| 178 | if (stat.size > std.math.maxInt(u32)) | ||
| 179 | return error.FileTooBig; | ||
| 180 | |||
| 181 | const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0); | ||
| 182 | defer if (!file.source_loaded) gpa.free(source); | ||
| 183 | const amt = try source_file.readAll(source); | ||
| 184 | if (amt != stat.size) | ||
| 185 | return error.UnexpectedEndOfFile; | ||
| 186 | |||
| 187 | file.stat = .{ | ||
| 188 | .size = stat.size, | ||
| 189 | .inode = stat.inode, | ||
| 190 | .mtime = stat.mtime, | ||
| 191 | }; | ||
| 192 | file.source = source; | ||
| 193 | file.source_loaded = true; | ||
| 194 | |||
| 195 | file.tree = try Ast.parse(gpa, source, .zig); | ||
| 196 | file.tree_loaded = true; | ||
| 197 | |||
| 198 | // Any potential AST errors are converted to ZIR errors here. | ||
| 199 | file.zir = try AstGen.generate(gpa, file.tree); | ||
| 200 | file.zir_loaded = true; | ||
| 201 | file.status = .success_zir; | ||
| 202 | log.debug("AstGen fresh success: {s}", .{file.sub_file_path}); | ||
| 203 | |||
| 204 | const safety_buffer = if (Zcu.data_has_safety_tag) | ||
| 205 | try gpa.alloc([8]u8, file.zir.instructions.len) | ||
| 206 | else | ||
| 207 | undefined; | ||
| 208 | defer if (Zcu.data_has_safety_tag) gpa.free(safety_buffer); | ||
| 209 | const data_ptr = if (Zcu.data_has_safety_tag) | ||
| 210 | if (file.zir.instructions.len == 0) | ||
| 211 | @as([*]const u8, undefined) | ||
| 212 | else | ||
| 213 | @as([*]const u8, @ptrCast(safety_buffer.ptr)) | ||
| 214 | else | ||
| 215 | @as([*]const u8, @ptrCast(file.zir.instructions.items(.data).ptr)); | ||
| 216 | if (Zcu.data_has_safety_tag) { | ||
| 217 | // The `Data` union has a safety tag but in the file format we store it without. | ||
| 218 | for (file.zir.instructions.items(.data), 0..) |*data, i| { | ||
| 219 | const as_struct: *const Zcu.HackDataLayout = @ptrCast(data); | ||
| 220 | safety_buffer[i] = as_struct.data; | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | const header: Zir.Header = .{ | ||
| 225 | .instructions_len = @as(u32, @intCast(file.zir.instructions.len)), | ||
| 226 | .string_bytes_len = @as(u32, @intCast(file.zir.string_bytes.len)), | ||
| 227 | .extra_len = @as(u32, @intCast(file.zir.extra.len)), | ||
| 228 | |||
| 229 | .stat_size = stat.size, | ||
| 230 | .stat_inode = stat.inode, | ||
| 231 | .stat_mtime = stat.mtime, | ||
| 232 | }; | ||
| 233 | var iovecs = [_]std.posix.iovec_const{ | ||
| 234 | .{ | ||
| 235 | .base = @as([*]const u8, @ptrCast(&header)), | ||
| 236 | .len = @sizeOf(Zir.Header), | ||
| 237 | }, | ||
| 238 | .{ | ||
| 239 | .base = @as([*]const u8, @ptrCast(file.zir.instructions.items(.tag).ptr)), | ||
| 240 | .len = file.zir.instructions.len, | ||
| 241 | }, | ||
| 242 | .{ | ||
| 243 | .base = data_ptr, | ||
| 244 | .len = file.zir.instructions.len * 8, | ||
| 245 | }, | ||
| 246 | .{ | ||
| 247 | .base = file.zir.string_bytes.ptr, | ||
| 248 | .len = file.zir.string_bytes.len, | ||
| 249 | }, | ||
| 250 | .{ | ||
| 251 | .base = @as([*]const u8, @ptrCast(file.zir.extra.ptr)), | ||
| 252 | .len = file.zir.extra.len * 4, | ||
| 253 | }, | ||
| 254 | }; | ||
| 255 | cache_file.writevAll(&iovecs) catch |err| { | ||
| 256 | log.warn("unable to write cached ZIR code for {}{s} to {}{s}: {s}", .{ | ||
| 257 | file.mod.root, file.sub_file_path, cache_directory, &hex_digest, @errorName(err), | ||
| 258 | }); | ||
| 259 | }; | ||
| 260 | |||
| 261 | if (file.zir.hasCompileErrors()) { | ||
| 262 | { | ||
| 263 | comp.mutex.lock(); | ||
| 264 | defer comp.mutex.unlock(); | ||
| 265 | try zcu.failed_files.putNoClobber(gpa, file, null); | ||
| 266 | } | ||
| 267 | file.status = .astgen_failure; | ||
| 268 | return error.AnalysisFail; | ||
| 269 | } | ||
| 270 | |||
| 271 | if (file.prev_zir) |prev_zir| { | ||
| 272 | try pt.updateZirRefs(file, file_index, prev_zir.*); | ||
| 273 | // No need to keep previous ZIR. | ||
| 274 | prev_zir.deinit(gpa); | ||
| 275 | gpa.destroy(prev_zir); | ||
| 276 | file.prev_zir = null; | ||
| 277 | } | ||
| 278 | |||
| 279 | if (opt_root_decl.unwrap()) |root_decl| { | ||
| 280 | // The root of this file must be re-analyzed, since the file has changed. | ||
| 281 | comp.mutex.lock(); | ||
| 282 | defer comp.mutex.unlock(); | ||
| 283 | |||
| 284 | log.debug("outdated root Decl: {}", .{root_decl}); | ||
| 285 | try zcu.outdated_file_root.put(gpa, root_decl, {}); | ||
| 286 | } | ||
| 287 | } | ||
| 288 | |||
| 289 | /// This is called from the AstGen thread pool, so must acquire | ||
| 290 | /// the Compilation mutex when acting on shared state. | ||
| 291 | fn updateZirRefs(pt: Zcu.PerThread, file: *Zcu.File, file_index: Zcu.File.Index, old_zir: Zir) !void { | ||
| 292 | const zcu = pt.zcu; | ||
| 293 | const gpa = zcu.gpa; | ||
| 294 | const new_zir = file.zir; | ||
| 295 | |||
| 296 | var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{}; | ||
| 297 | defer inst_map.deinit(gpa); | ||
| 298 | |||
| 299 | try Zcu.mapOldZirToNew(gpa, old_zir, new_zir, &inst_map); | ||
| 300 | |||
| 301 | const old_tag = old_zir.instructions.items(.tag); | ||
| 302 | const old_data = old_zir.instructions.items(.data); | ||
| 303 | |||
| 304 | // TODO: this should be done after all AstGen workers complete, to avoid | ||
| 305 | // iterating over this full set for every updated file. | ||
| 306 | for (zcu.intern_pool.tracked_insts.keys(), 0..) |*ti, idx_raw| { | ||
| 307 | const ti_idx: InternPool.TrackedInst.Index = @enumFromInt(idx_raw); | ||
| 308 | if (ti.file != file_index) continue; | ||
| 309 | const old_inst = ti.inst; | ||
| 310 | ti.inst = inst_map.get(ti.inst) orelse { | ||
| 311 | // Tracking failed for this instruction. Invalidate associated `src_hash` deps. | ||
| 312 | zcu.comp.mutex.lock(); | ||
| 313 | defer zcu.comp.mutex.unlock(); | ||
| 314 | log.debug("tracking failed for %{d}", .{old_inst}); | ||
| 315 | try zcu.markDependeeOutdated(.{ .src_hash = ti_idx }); | ||
| 316 | continue; | ||
| 317 | }; | ||
| 318 | |||
| 319 | if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: { | ||
| 320 | if (new_zir.getAssociatedSrcHash(ti.inst)) |new_hash| { | ||
| 321 | if (std.zig.srcHashEql(old_hash, new_hash)) { | ||
| 322 | break :hash_changed; | ||
| 323 | } | ||
| 324 | log.debug("hash for (%{d} -> %{d}) changed: {} -> {}", .{ | ||
| 325 | old_inst, | ||
| 326 | ti.inst, | ||
| 327 | std.fmt.fmtSliceHexLower(&old_hash), | ||
| 328 | std.fmt.fmtSliceHexLower(&new_hash), | ||
| 329 | }); | ||
| 330 | } | ||
| 331 | // The source hash associated with this instruction changed - invalidate relevant dependencies. | ||
| 332 | zcu.comp.mutex.lock(); | ||
| 333 | defer zcu.comp.mutex.unlock(); | ||
| 334 | try zcu.markDependeeOutdated(.{ .src_hash = ti_idx }); | ||
| 335 | } | ||
| 336 | |||
| 337 | // If this is a `struct_decl` etc, we must invalidate any outdated namespace dependencies. | ||
| 338 | const has_namespace = switch (old_tag[@intFromEnum(old_inst)]) { | ||
| 339 | .extended => switch (old_data[@intFromEnum(old_inst)].extended.opcode) { | ||
| 340 | .struct_decl, .union_decl, .opaque_decl, .enum_decl => true, | ||
| 341 | else => false, | ||
| 342 | }, | ||
| 343 | else => false, | ||
| 344 | }; | ||
| 345 | if (!has_namespace) continue; | ||
| 346 | |||
| 347 | var old_names: std.AutoArrayHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{}; | ||
| 348 | defer old_names.deinit(zcu.gpa); | ||
| 349 | { | ||
| 350 | var it = old_zir.declIterator(old_inst); | ||
| 351 | while (it.next()) |decl_inst| { | ||
| 352 | const decl_name = old_zir.getDeclaration(decl_inst)[0].name; | ||
| 353 | switch (decl_name) { | ||
| 354 | .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue, | ||
| 355 | _ => if (decl_name.isNamedTest(old_zir)) continue, | ||
| 356 | } | ||
| 357 | const name_zir = decl_name.toString(old_zir).?; | ||
| 358 | const name_ip = try zcu.intern_pool.getOrPutString( | ||
| 359 | zcu.gpa, | ||
| 360 | pt.tid, | ||
| 361 | old_zir.nullTerminatedString(name_zir), | ||
| 362 | .no_embedded_nulls, | ||
| 363 | ); | ||
| 364 | try old_names.put(zcu.gpa, name_ip, {}); | ||
| 365 | } | ||
| 366 | } | ||
| 367 | var any_change = false; | ||
| 368 | { | ||
| 369 | var it = new_zir.declIterator(ti.inst); | ||
| 370 | while (it.next()) |decl_inst| { | ||
| 371 | const decl_name = old_zir.getDeclaration(decl_inst)[0].name; | ||
| 372 | switch (decl_name) { | ||
| 373 | .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue, | ||
| 374 | _ => if (decl_name.isNamedTest(old_zir)) continue, | ||
| 375 | } | ||
| 376 | const name_zir = decl_name.toString(old_zir).?; | ||
| 377 | const name_ip = try zcu.intern_pool.getOrPutString( | ||
| 378 | zcu.gpa, | ||
| 379 | pt.tid, | ||
| 380 | old_zir.nullTerminatedString(name_zir), | ||
| 381 | .no_embedded_nulls, | ||
| 382 | ); | ||
| 383 | if (!old_names.swapRemove(name_ip)) continue; | ||
| 384 | // Name added | ||
| 385 | any_change = true; | ||
| 386 | zcu.comp.mutex.lock(); | ||
| 387 | defer zcu.comp.mutex.unlock(); | ||
| 388 | try zcu.markDependeeOutdated(.{ .namespace_name = .{ | ||
| 389 | .namespace = ti_idx, | ||
| 390 | .name = name_ip, | ||
| 391 | } }); | ||
| 392 | } | ||
| 393 | } | ||
| 394 | // The only elements remaining in `old_names` now are any names which were removed. | ||
| 395 | for (old_names.keys()) |name_ip| { | ||
| 396 | any_change = true; | ||
| 397 | zcu.comp.mutex.lock(); | ||
| 398 | defer zcu.comp.mutex.unlock(); | ||
| 399 | try zcu.markDependeeOutdated(.{ .namespace_name = .{ | ||
| 400 | .namespace = ti_idx, | ||
| 401 | .name = name_ip, | ||
| 402 | } }); | ||
| 403 | } | ||
| 404 | |||
| 405 | if (any_change) { | ||
| 406 | zcu.comp.mutex.lock(); | ||
| 407 | defer zcu.comp.mutex.unlock(); | ||
| 408 | try zcu.markDependeeOutdated(.{ .namespace = ti_idx }); | ||
| 409 | } | ||
| 410 | } | ||
| 411 | } | ||
| 412 | |||
| 8 | /// Like `ensureDeclAnalyzed`, but the Decl is a file's root Decl. | 413 | /// Like `ensureDeclAnalyzed`, but the Decl is a file's root Decl. |
| 9 | pub fn ensureFileAnalyzed(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void { | 414 | pub fn ensureFileAnalyzed(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void { |
| 10 | if (pt.zcu.fileRootDecl(file_index).unwrap()) |existing_root| { | 415 | if (pt.zcu.fileRootDecl(file_index).unwrap()) |existing_root| { |
| ... | @@ -91,7 +496,7 @@ pub fn ensureDeclAnalyzed(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Zcu.Sem | ... | @@ -91,7 +496,7 @@ pub fn ensureDeclAnalyzed(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Zcu.Sem |
| 91 | }; | 496 | }; |
| 92 | } | 497 | } |
| 93 | 498 | ||
| 94 | const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(mod)).toSlice(ip), 0); | 499 | const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0); |
| 95 | defer decl_prog_node.end(); | 500 | defer decl_prog_node.end(); |
| 96 | 501 | ||
| 97 | break :blk pt.semaDecl(decl_index) catch |err| switch (err) { | 502 | break :blk pt.semaDecl(decl_index) catch |err| switch (err) { |
| ... | @@ -290,7 +695,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai | ... | @@ -290,7 +695,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai |
| 290 | defer liveness.deinit(gpa); | 695 | defer liveness.deinit(gpa); |
| 291 | 696 | ||
| 292 | if (build_options.enable_debug_extensions and comp.verbose_air) { | 697 | if (build_options.enable_debug_extensions and comp.verbose_air) { |
| 293 | const fqn = try decl.fullyQualifiedName(zcu); | 698 | const fqn = try decl.fullyQualifiedName(pt); |
| 294 | std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(ip)}); | 699 | std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(ip)}); |
| 295 | @import("../print_air.zig").dump(pt, air, liveness); | 700 | @import("../print_air.zig").dump(pt, air, liveness); |
| 296 | std.debug.print("# End Function AIR: {}\n\n", .{fqn.fmt(ip)}); | 701 | std.debug.print("# End Function AIR: {}\n\n", .{fqn.fmt(ip)}); |
| ... | @@ -324,7 +729,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai | ... | @@ -324,7 +729,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai |
| 324 | }; | 729 | }; |
| 325 | } | 730 | } |
| 326 | 731 | ||
| 327 | const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(zcu)).toSlice(ip), 0); | 732 | const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0); |
| 328 | defer codegen_prog_node.end(); | 733 | defer codegen_prog_node.end(); |
| 329 | 734 | ||
| 330 | if (!air.typesFullyResolved(zcu)) { | 735 | if (!air.typesFullyResolved(zcu)) { |
| ... | @@ -434,7 +839,7 @@ fn getFileRootStruct( | ... | @@ -434,7 +839,7 @@ fn getFileRootStruct( |
| 434 | decl.owns_tv = true; | 839 | decl.owns_tv = true; |
| 435 | decl.analysis = .complete; | 840 | decl.analysis = .complete; |
| 436 | 841 | ||
| 437 | try zcu.scanNamespace(namespace_index, decls, decl); | 842 | try pt.scanNamespace(namespace_index, decls, decl); |
| 438 | try zcu.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index }); | 843 | try zcu.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index }); |
| 439 | return wip_ty.finish(ip, decl_index, namespace_index.toOptional()); | 844 | return wip_ty.finish(ip, decl_index, namespace_index.toOptional()); |
| 440 | } | 845 | } |
| ... | @@ -502,7 +907,7 @@ fn semaFileUpdate(pt: Zcu.PerThread, file_index: Zcu.File.Index, type_outdated: | ... | @@ -502,7 +907,7 @@ fn semaFileUpdate(pt: Zcu.PerThread, file_index: Zcu.File.Index, type_outdated: |
| 502 | const decls = file.zir.bodySlice(extra_index, decls_len); | 907 | const decls = file.zir.bodySlice(extra_index, decls_len); |
| 503 | 908 | ||
| 504 | if (!type_outdated) { | 909 | if (!type_outdated) { |
| 505 | try zcu.scanNamespace(decl.src_namespace, decls, decl); | 910 | try pt.scanNamespace(decl.src_namespace, decls, decl); |
| 506 | } | 911 | } |
| 507 | 912 | ||
| 508 | return false; | 913 | return false; |
| ... | @@ -539,7 +944,7 @@ fn semaFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void { | ... | @@ -539,7 +944,7 @@ fn semaFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void { |
| 539 | zcu.setFileRootDecl(file_index, new_decl_index.toOptional()); | 944 | zcu.setFileRootDecl(file_index, new_decl_index.toOptional()); |
| 540 | zcu.namespacePtr(new_namespace_index).decl_index = new_decl_index; | 945 | zcu.namespacePtr(new_namespace_index).decl_index = new_decl_index; |
| 541 | 946 | ||
| 542 | new_decl.name = try file.fullyQualifiedName(zcu); | 947 | new_decl.name = try file.fullyQualifiedName(pt); |
| 543 | new_decl.name_fully_qualified = true; | 948 | new_decl.name_fully_qualified = true; |
| 544 | new_decl.is_pub = true; | 949 | new_decl.is_pub = true; |
| 545 | new_decl.is_exported = false; | 950 | new_decl.is_exported = false; |
| ... | @@ -601,9 +1006,9 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult { | ... | @@ -601,9 +1006,9 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult { |
| 601 | } | 1006 | } |
| 602 | 1007 | ||
| 603 | log.debug("semaDecl '{d}'", .{@intFromEnum(decl_index)}); | 1008 | log.debug("semaDecl '{d}'", .{@intFromEnum(decl_index)}); |
| 604 | log.debug("decl name '{}'", .{(try decl.fullyQualifiedName(zcu)).fmt(ip)}); | 1009 | log.debug("decl name '{}'", .{(try decl.fullyQualifiedName(pt)).fmt(ip)}); |
| 605 | defer blk: { | 1010 | defer blk: { |
| 606 | log.debug("finish decl name '{}'", .{(decl.fullyQualifiedName(zcu) catch break :blk).fmt(ip)}); | 1011 | log.debug("finish decl name '{}'", .{(decl.fullyQualifiedName(pt) catch break :blk).fmt(ip)}); |
| 607 | } | 1012 | } |
| 608 | 1013 | ||
| 609 | const old_has_tv = decl.has_tv; | 1014 | const old_has_tv = decl.has_tv; |
| ... | @@ -631,7 +1036,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult { | ... | @@ -631,7 +1036,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult { |
| 631 | const std_file_root_decl_index = zcu.fileRootDecl(std_file_imported.file_index); | 1036 | const std_file_root_decl_index = zcu.fileRootDecl(std_file_imported.file_index); |
| 632 | const std_decl = zcu.declPtr(std_file_root_decl_index.unwrap().?); | 1037 | const std_decl = zcu.declPtr(std_file_root_decl_index.unwrap().?); |
| 633 | const std_namespace = std_decl.getInnerNamespace(zcu).?; | 1038 | const std_namespace = std_decl.getInnerNamespace(zcu).?; |
| 634 | const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls); | 1039 | const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls); |
| 635 | const builtin_decl = zcu.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse break :ip_index .none); | 1040 | const builtin_decl = zcu.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse break :ip_index .none); |
| 636 | const builtin_namespace = builtin_decl.getInnerNamespaceIndex(zcu).unwrap() orelse break :ip_index .none; | 1041 | const builtin_namespace = builtin_decl.getInnerNamespaceIndex(zcu).unwrap() orelse break :ip_index .none; |
| 637 | if (decl.src_namespace != builtin_namespace) break :ip_index .none; | 1042 | if (decl.src_namespace != builtin_namespace) break :ip_index .none; |
| ... | @@ -802,7 +1207,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult { | ... | @@ -802,7 +1207,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult { |
| 802 | } else if (bytes.len == 0) { | 1207 | } else if (bytes.len == 0) { |
| 803 | return sema.fail(&block_scope, section_src, "linksection cannot be empty", .{}); | 1208 | return sema.fail(&block_scope, section_src, "linksection cannot be empty", .{}); |
| 804 | } | 1209 | } |
| 805 | break :blk try ip.getOrPutStringOpt(gpa, bytes, .no_embedded_nulls); | 1210 | break :blk try ip.getOrPutStringOpt(gpa, pt.tid, bytes, .no_embedded_nulls); |
| 806 | }; | 1211 | }; |
| 807 | decl.@"addrspace" = blk: { | 1212 | decl.@"addrspace" = blk: { |
| 808 | const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_val.toIntern())) { | 1213 | const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_val.toIntern())) { |
| ... | @@ -996,7 +1401,7 @@ fn newEmbedFile( | ... | @@ -996,7 +1401,7 @@ fn newEmbedFile( |
| 996 | } }); | 1401 | } }); |
| 997 | const array_val = try pt.intern(.{ .aggregate = .{ | 1402 | const array_val = try pt.intern(.{ .aggregate = .{ |
| 998 | .ty = array_ty, | 1403 | .ty = array_ty, |
| 999 | .storage = .{ .bytes = try ip.getOrPutTrailingString(gpa, bytes.len, .maybe_embedded_nulls) }, | 1404 | .storage = .{ .bytes = try ip.getOrPutTrailingString(gpa, pt.tid, bytes.len, .maybe_embedded_nulls) }, |
| 1000 | } }); | 1405 | } }); |
| 1001 | 1406 | ||
| 1002 | const ptr_ty = (try pt.ptrType(.{ | 1407 | const ptr_ty = (try pt.ptrType(.{ |
| ... | @@ -1018,7 +1423,7 @@ fn newEmbedFile( | ... | @@ -1018,7 +1423,7 @@ fn newEmbedFile( |
| 1018 | 1423 | ||
| 1019 | result.* = new_file; | 1424 | result.* = new_file; |
| 1020 | new_file.* = .{ | 1425 | new_file.* = .{ |
| 1021 | .sub_file_path = try ip.getOrPutString(gpa, sub_file_path, .no_embedded_nulls), | 1426 | .sub_file_path = try ip.getOrPutString(gpa, pt.tid, sub_file_path, .no_embedded_nulls), |
| 1022 | .owner = pkg, | 1427 | .owner = pkg, |
| 1023 | .stat = stat, | 1428 | .stat = stat, |
| 1024 | .val = ptr_val, | 1429 | .val = ptr_val, |
| ... | @@ -1027,6 +1432,271 @@ fn newEmbedFile( | ... | @@ -1027,6 +1432,271 @@ fn newEmbedFile( |
| 1027 | return ptr_val; | 1432 | return ptr_val; |
| 1028 | } | 1433 | } |
| 1029 | 1434 | ||
| 1435 | pub fn scanNamespace( | ||
| 1436 | pt: Zcu.PerThread, | ||
| 1437 | namespace_index: Zcu.Namespace.Index, | ||
| 1438 | decls: []const Zir.Inst.Index, | ||
| 1439 | parent_decl: *Zcu.Decl, | ||
| 1440 | ) Allocator.Error!void { | ||
| 1441 | const tracy = trace(@src()); | ||
| 1442 | defer tracy.end(); | ||
| 1443 | |||
| 1444 | const zcu = pt.zcu; | ||
| 1445 | const gpa = zcu.gpa; | ||
| 1446 | const namespace = zcu.namespacePtr(namespace_index); | ||
| 1447 | |||
| 1448 | // For incremental updates, `scanDecl` wants to look up existing decls by their ZIR index rather | ||
| 1449 | // than their name. We'll build an efficient mapping now, then discard the current `decls`. | ||
| 1450 | var existing_by_inst: std.AutoHashMapUnmanaged(InternPool.TrackedInst.Index, Zcu.Decl.Index) = .{}; | ||
| 1451 | defer existing_by_inst.deinit(gpa); | ||
| 1452 | |||
| 1453 | try existing_by_inst.ensureTotalCapacity(gpa, @intCast(namespace.decls.count())); | ||
| 1454 | |||
| 1455 | for (namespace.decls.keys()) |decl_index| { | ||
| 1456 | const decl = zcu.declPtr(decl_index); | ||
| 1457 | existing_by_inst.putAssumeCapacityNoClobber(decl.zir_decl_index.unwrap().?, decl_index); | ||
| 1458 | } | ||
| 1459 | |||
| 1460 | var seen_decls: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{}; | ||
| 1461 | defer seen_decls.deinit(gpa); | ||
| 1462 | |||
| 1463 | try zcu.comp.work_queue.ensureUnusedCapacity(decls.len); | ||
| 1464 | |||
| 1465 | namespace.decls.clearRetainingCapacity(); | ||
| 1466 | try namespace.decls.ensureTotalCapacity(gpa, decls.len); | ||
| 1467 | |||
| 1468 | namespace.usingnamespace_set.clearRetainingCapacity(); | ||
| 1469 | |||
| 1470 | var scan_decl_iter: ScanDeclIter = .{ | ||
| 1471 | .pt = pt, | ||
| 1472 | .namespace_index = namespace_index, | ||
| 1473 | .parent_decl = parent_decl, | ||
| 1474 | .seen_decls = &seen_decls, | ||
| 1475 | .existing_by_inst = &existing_by_inst, | ||
| 1476 | .pass = .named, | ||
| 1477 | }; | ||
| 1478 | for (decls) |decl_inst| { | ||
| 1479 | try scan_decl_iter.scanDecl(decl_inst); | ||
| 1480 | } | ||
| 1481 | scan_decl_iter.pass = .unnamed; | ||
| 1482 | for (decls) |decl_inst| { | ||
| 1483 | try scan_decl_iter.scanDecl(decl_inst); | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | if (seen_decls.count() != namespace.decls.count()) { | ||
| 1487 | // Do a pass over the namespace contents and remove any decls from the last update | ||
| 1488 | // which were removed in this one. | ||
| 1489 | var i: usize = 0; | ||
| 1490 | while (i < namespace.decls.count()) { | ||
| 1491 | const decl_index = namespace.decls.keys()[i]; | ||
| 1492 | const decl = zcu.declPtr(decl_index); | ||
| 1493 | if (!seen_decls.contains(decl.name)) { | ||
| 1494 | // We must preserve namespace ordering for @typeInfo. | ||
| 1495 | namespace.decls.orderedRemoveAt(i); | ||
| 1496 | i -= 1; | ||
| 1497 | } | ||
| 1498 | } | ||
| 1499 | } | ||
| 1500 | } | ||
| 1501 | |||
| 1502 | const ScanDeclIter = struct { | ||
| 1503 | pt: Zcu.PerThread, | ||
| 1504 | namespace_index: Zcu.Namespace.Index, | ||
| 1505 | parent_decl: *Zcu.Decl, | ||
| 1506 | seen_decls: *std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void), | ||
| 1507 | existing_by_inst: *const std.AutoHashMapUnmanaged(InternPool.TrackedInst.Index, Zcu.Decl.Index), | ||
| 1508 | /// Decl scanning is run in two passes, so that we can detect when a generated | ||
| 1509 | /// name would clash with an explicit name and use a different one. | ||
| 1510 | pass: enum { named, unnamed }, | ||
| 1511 | usingnamespace_index: usize = 0, | ||
| 1512 | comptime_index: usize = 0, | ||
| 1513 | unnamed_test_index: usize = 0, | ||
| 1514 | |||
| 1515 | fn avoidNameConflict(iter: *ScanDeclIter, comptime fmt: []const u8, args: anytype) !InternPool.NullTerminatedString { | ||
| 1516 | const pt = iter.pt; | ||
| 1517 | const gpa = pt.zcu.gpa; | ||
| 1518 | const ip = &pt.zcu.intern_pool; | ||
| 1519 | var name = try ip.getOrPutStringFmt(gpa, pt.tid, fmt, args, .no_embedded_nulls); | ||
| 1520 | var gop = try iter.seen_decls.getOrPut(gpa, name); | ||
| 1521 | var next_suffix: u32 = 0; | ||
| 1522 | while (gop.found_existing) { | ||
| 1523 | name = try ip.getOrPutStringFmt(gpa, pt.tid, "{}_{d}", .{ name.fmt(ip), next_suffix }, .no_embedded_nulls); | ||
| 1524 | gop = try iter.seen_decls.getOrPut(gpa, name); | ||
| 1525 | next_suffix += 1; | ||
| 1526 | } | ||
| 1527 | return name; | ||
| 1528 | } | ||
| 1529 | |||
| 1530 | fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void { | ||
| 1531 | const tracy = trace(@src()); | ||
| 1532 | defer tracy.end(); | ||
| 1533 | |||
| 1534 | const pt = iter.pt; | ||
| 1535 | const zcu = pt.zcu; | ||
| 1536 | const namespace_index = iter.namespace_index; | ||
| 1537 | const namespace = zcu.namespacePtr(namespace_index); | ||
| 1538 | const gpa = zcu.gpa; | ||
| 1539 | const zir = namespace.fileScope(zcu).zir; | ||
| 1540 | const ip = &zcu.intern_pool; | ||
| 1541 | |||
| 1542 | const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration; | ||
| 1543 | const extra = zir.extraData(Zir.Inst.Declaration, inst_data.payload_index); | ||
| 1544 | const declaration = extra.data; | ||
| 1545 | |||
| 1546 | // Every Decl needs a name. | ||
| 1547 | const decl_name: InternPool.NullTerminatedString, const kind: Zcu.Decl.Kind, const is_named_test: bool = switch (declaration.name) { | ||
| 1548 | .@"comptime" => info: { | ||
| 1549 | if (iter.pass != .unnamed) return; | ||
| 1550 | const i = iter.comptime_index; | ||
| 1551 | iter.comptime_index += 1; | ||
| 1552 | break :info .{ | ||
| 1553 | try iter.avoidNameConflict("comptime_{d}", .{i}), | ||
| 1554 | .@"comptime", | ||
| 1555 | false, | ||
| 1556 | }; | ||
| 1557 | }, | ||
| 1558 | .@"usingnamespace" => info: { | ||
| 1559 | // TODO: this isn't right! These should be considered unnamed. Name conflicts can happen here. | ||
| 1560 | // The problem is, we need to preserve the decl ordering for `@typeInfo`. | ||
| 1561 | // I'm not bothering to fix this now, since some upcoming changes will change this code significantly anyway. | ||
| 1562 | if (iter.pass != .named) return; | ||
| 1563 | const i = iter.usingnamespace_index; | ||
| 1564 | iter.usingnamespace_index += 1; | ||
| 1565 | break :info .{ | ||
| 1566 | try iter.avoidNameConflict("usingnamespace_{d}", .{i}), | ||
| 1567 | .@"usingnamespace", | ||
| 1568 | false, | ||
| 1569 | }; | ||
| 1570 | }, | ||
| 1571 | .unnamed_test => info: { | ||
| 1572 | if (iter.pass != .unnamed) return; | ||
| 1573 | const i = iter.unnamed_test_index; | ||
| 1574 | iter.unnamed_test_index += 1; | ||
| 1575 | break :info .{ | ||
| 1576 | try iter.avoidNameConflict("test_{d}", .{i}), | ||
| 1577 | .@"test", | ||
| 1578 | false, | ||
| 1579 | }; | ||
| 1580 | }, | ||
| 1581 | .decltest => info: { | ||
| 1582 | // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary. | ||
| 1583 | if (iter.pass != .unnamed) return; | ||
| 1584 | assert(declaration.flags.has_doc_comment); | ||
| 1585 | const name = zir.nullTerminatedString(@enumFromInt(zir.extra[extra.end])); | ||
| 1586 | break :info .{ | ||
| 1587 | try iter.avoidNameConflict("decltest.{s}", .{name}), | ||
| 1588 | .@"test", | ||
| 1589 | true, | ||
| 1590 | }; | ||
| 1591 | }, | ||
| 1592 | _ => if (declaration.name.isNamedTest(zir)) info: { | ||
| 1593 | // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary. | ||
| 1594 | if (iter.pass != .unnamed) return; | ||
| 1595 | break :info .{ | ||
| 1596 | try iter.avoidNameConflict("test.{s}", .{zir.nullTerminatedString(declaration.name.toString(zir).?)}), | ||
| 1597 | .@"test", | ||
| 1598 | true, | ||
| 1599 | }; | ||
| 1600 | } else info: { | ||
| 1601 | if (iter.pass != .named) return; | ||
| 1602 | const name = try ip.getOrPutString( | ||
| 1603 | gpa, | ||
| 1604 | pt.tid, | ||
| 1605 | zir.nullTerminatedString(declaration.name.toString(zir).?), | ||
| 1606 | .no_embedded_nulls, | ||
| 1607 | ); | ||
| 1608 | try iter.seen_decls.putNoClobber(gpa, name, {}); | ||
| 1609 | break :info .{ | ||
| 1610 | name, | ||
| 1611 | .named, | ||
| 1612 | false, | ||
| 1613 | }; | ||
| 1614 | }, | ||
| 1615 | }; | ||
| 1616 | |||
| 1617 | switch (kind) { | ||
| 1618 | .@"usingnamespace" => try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1), | ||
| 1619 | .@"test" => try zcu.test_functions.ensureUnusedCapacity(gpa, 1), | ||
| 1620 | else => {}, | ||
| 1621 | } | ||
| 1622 | |||
| 1623 | const parent_file_scope_index = iter.parent_decl.getFileScopeIndex(zcu); | ||
| 1624 | const tracked_inst = try ip.trackZir(gpa, parent_file_scope_index, decl_inst); | ||
| 1625 | |||
| 1626 | // We create a Decl for it regardless of analysis status. | ||
| 1627 | |||
| 1628 | const prev_exported, const decl_index = if (iter.existing_by_inst.get(tracked_inst)) |decl_index| decl_index: { | ||
| 1629 | // We need only update this existing Decl. | ||
| 1630 | const decl = zcu.declPtr(decl_index); | ||
| 1631 | const was_exported = decl.is_exported; | ||
| 1632 | assert(decl.kind == kind); // ZIR tracking should preserve this | ||
| 1633 | decl.name = decl_name; | ||
| 1634 | decl.is_pub = declaration.flags.is_pub; | ||
| 1635 | decl.is_exported = declaration.flags.is_export; | ||
| 1636 | break :decl_index .{ was_exported, decl_index }; | ||
| 1637 | } else decl_index: { | ||
| 1638 | // Create and set up a new Decl. | ||
| 1639 | const new_decl_index = try zcu.allocateNewDecl(namespace_index); | ||
| 1640 | const new_decl = zcu.declPtr(new_decl_index); | ||
| 1641 | new_decl.kind = kind; | ||
| 1642 | new_decl.name = decl_name; | ||
| 1643 | new_decl.is_pub = declaration.flags.is_pub; | ||
| 1644 | new_decl.is_exported = declaration.flags.is_export; | ||
| 1645 | new_decl.zir_decl_index = tracked_inst.toOptional(); | ||
| 1646 | break :decl_index .{ false, new_decl_index }; | ||
| 1647 | }; | ||
| 1648 | |||
| 1649 | const decl = zcu.declPtr(decl_index); | ||
| 1650 | |||
| 1651 | namespace.decls.putAssumeCapacityNoClobberContext(decl_index, {}, .{ .zcu = zcu }); | ||
| 1652 | |||
| 1653 | const comp = zcu.comp; | ||
| 1654 | const decl_mod = namespace.fileScope(zcu).mod; | ||
| 1655 | const want_analysis = declaration.flags.is_export or switch (kind) { | ||
| 1656 | .anon => unreachable, | ||
| 1657 | .@"comptime" => true, | ||
| 1658 | .@"usingnamespace" => a: { | ||
| 1659 | namespace.usingnamespace_set.putAssumeCapacityNoClobber(decl_index, declaration.flags.is_pub); | ||
| 1660 | break :a true; | ||
| 1661 | }, | ||
| 1662 | .named => false, | ||
| 1663 | .@"test" => a: { | ||
| 1664 | if (!comp.config.is_test) break :a false; | ||
| 1665 | if (decl_mod != zcu.main_mod) break :a false; | ||
| 1666 | if (is_named_test and comp.test_filters.len > 0) { | ||
| 1667 | const decl_fqn = try namespace.fullyQualifiedName(pt, decl_name); | ||
| 1668 | const decl_fqn_slice = decl_fqn.toSlice(ip); | ||
| 1669 | for (comp.test_filters) |test_filter| { | ||
| 1670 | if (std.mem.indexOf(u8, decl_fqn_slice, test_filter)) |_| break; | ||
| 1671 | } else break :a false; | ||
| 1672 | } | ||
| 1673 | zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update | ||
| 1674 | break :a true; | ||
| 1675 | }, | ||
| 1676 | }; | ||
| 1677 | |||
| 1678 | if (want_analysis) { | ||
| 1679 | // We will not queue analysis if the decl has been analyzed on a previous update and | ||
| 1680 | // `is_export` is unchanged. In this case, the incremental update mechanism will handle | ||
| 1681 | // re-analysis for us if necessary. | ||
| 1682 | if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) { | ||
| 1683 | log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{ | ||
| 1684 | namespace.fileScope(zcu).sub_file_path, decl_name.fmt(ip), decl_index, | ||
| 1685 | }); | ||
| 1686 | comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index }); | ||
| 1687 | } | ||
| 1688 | } | ||
| 1689 | |||
| 1690 | if (decl.getOwnedFunction(zcu) != null) { | ||
| 1691 | // TODO this logic is insufficient; namespaces we don't re-scan may still require | ||
| 1692 | // updated line numbers. Look into this! | ||
| 1693 | // TODO Look into detecting when this would be unnecessary by storing enough state | ||
| 1694 | // in `Decl` to notice that the line number did not change. | ||
| 1695 | comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index }); | ||
| 1696 | } | ||
| 1697 | } | ||
| 1698 | }; | ||
| 1699 | |||
| 1030 | pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: Allocator) Zcu.SemaError!Air { | 1700 | pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: Allocator) Zcu.SemaError!Air { |
| 1031 | const tracy = trace(@src()); | 1701 | const tracy = trace(@src()); |
| 1032 | defer tracy.end(); | 1702 | defer tracy.end(); |
| ... | @@ -1038,12 +1708,12 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All | ... | @@ -1038,12 +1708,12 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All |
| 1038 | const decl_index = func.owner_decl; | 1708 | const decl_index = func.owner_decl; |
| 1039 | const decl = mod.declPtr(decl_index); | 1709 | const decl = mod.declPtr(decl_index); |
| 1040 | 1710 | ||
| 1041 | log.debug("func name '{}'", .{(try decl.fullyQualifiedName(mod)).fmt(ip)}); | 1711 | log.debug("func name '{}'", .{(try decl.fullyQualifiedName(pt)).fmt(ip)}); |
| 1042 | defer blk: { | 1712 | defer blk: { |
| 1043 | log.debug("finish func name '{}'", .{(decl.fullyQualifiedName(mod) catch break :blk).fmt(ip)}); | 1713 | log.debug("finish func name '{}'", .{(decl.fullyQualifiedName(pt) catch break :blk).fmt(ip)}); |
| 1044 | } | 1714 | } |
| 1045 | 1715 | ||
| 1046 | const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(mod)).toSlice(ip), 0); | 1716 | const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(ip), 0); |
| 1047 | defer decl_prog_node.end(); | 1717 | defer decl_prog_node.end(); |
| 1048 | 1718 | ||
| 1049 | mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalUnit.wrap(.{ .func = func_index })); | 1719 | mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalUnit.wrap(.{ .func = func_index })); |
| ... | @@ -1273,6 +1943,19 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All | ... | @@ -1273,6 +1943,19 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All |
| 1273 | }; | 1943 | }; |
| 1274 | } | 1944 | } |
| 1275 | 1945 | ||
| 1946 | fn lockAndClearFileCompileError(pt: Zcu.PerThread, file: *Zcu.File) void { | ||
| 1947 | switch (file.status) { | ||
| 1948 | .success_zir, .retryable_failure => {}, | ||
| 1949 | .never_loaded, .parse_failure, .astgen_failure => { | ||
| 1950 | pt.zcu.comp.mutex.lock(); | ||
| 1951 | defer pt.zcu.comp.mutex.unlock(); | ||
| 1952 | if (pt.zcu.failed_files.fetchSwapRemove(file)) |kv| { | ||
| 1953 | if (kv.value) |msg| msg.destroy(pt.zcu.gpa); // Delete previous error message. | ||
| 1954 | } | ||
| 1955 | }, | ||
| 1956 | } | ||
| 1957 | } | ||
| 1958 | |||
| 1276 | /// Called from `Compilation.update`, after everything is done, just before | 1959 | /// Called from `Compilation.update`, after everything is done, just before |
| 1277 | /// reporting compile errors. In this function we emit exported symbol collision | 1960 | /// reporting compile errors. In this function we emit exported symbol collision |
| 1278 | /// errors and communicate exported symbols to the linker backend. | 1961 | /// errors and communicate exported symbols to the linker backend. |
| ... | @@ -1397,7 +2080,7 @@ pub fn populateTestFunctions( | ... | @@ -1397,7 +2080,7 @@ pub fn populateTestFunctions( |
| 1397 | const root_decl_index = zcu.fileRootDecl(builtin_file_index); | 2080 | const root_decl_index = zcu.fileRootDecl(builtin_file_index); |
| 1398 | const root_decl = zcu.declPtr(root_decl_index.unwrap().?); | 2081 | const root_decl = zcu.declPtr(root_decl_index.unwrap().?); |
| 1399 | const builtin_namespace = zcu.namespacePtr(root_decl.src_namespace); | 2082 | const builtin_namespace = zcu.namespacePtr(root_decl.src_namespace); |
| 1400 | const test_functions_str = try ip.getOrPutString(gpa, "test_functions", .no_embedded_nulls); | 2083 | const test_functions_str = try ip.getOrPutString(gpa, pt.tid, "test_functions", .no_embedded_nulls); |
| 1401 | const decl_index = builtin_namespace.decls.getKeyAdapted( | 2084 | const decl_index = builtin_namespace.decls.getKeyAdapted( |
| 1402 | test_functions_str, | 2085 | test_functions_str, |
| 1403 | Zcu.DeclAdapter{ .zcu = zcu }, | 2086 | Zcu.DeclAdapter{ .zcu = zcu }, |
| ... | @@ -1424,7 +2107,7 @@ pub fn populateTestFunctions( | ... | @@ -1424,7 +2107,7 @@ pub fn populateTestFunctions( |
| 1424 | 2107 | ||
| 1425 | for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_decl_index| { | 2108 | for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_decl_index| { |
| 1426 | const test_decl = zcu.declPtr(test_decl_index); | 2109 | const test_decl = zcu.declPtr(test_decl_index); |
| 1427 | const test_decl_name = try test_decl.fullyQualifiedName(zcu); | 2110 | const test_decl_name = try test_decl.fullyQualifiedName(pt); |
| 1428 | const test_decl_name_len = test_decl_name.length(ip); | 2111 | const test_decl_name_len = test_decl_name.length(ip); |
| 1429 | const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = n: { | 2112 | const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = n: { |
| 1430 | const test_name_ty = try pt.arrayType(.{ | 2113 | const test_name_ty = try pt.arrayType(.{ |
| ... | @@ -1530,7 +2213,7 @@ pub fn linkerUpdateDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !void { | ... | @@ -1530,7 +2213,7 @@ pub fn linkerUpdateDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !void { |
| 1530 | 2213 | ||
| 1531 | const decl = zcu.declPtr(decl_index); | 2214 | const decl = zcu.declPtr(decl_index); |
| 1532 | 2215 | ||
| 1533 | const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(zcu)).toSlice(&zcu.intern_pool), 0); | 2216 | const codegen_prog_node = zcu.codegen_prog_node.start((try decl.fullyQualifiedName(pt)).toSlice(&zcu.intern_pool), 0); |
| 1534 | defer codegen_prog_node.end(); | 2217 | defer codegen_prog_node.end(); |
| 1535 | 2218 | ||
| 1536 | if (comp.bin_file) |lf| { | 2219 | if (comp.bin_file) |lf| { |
| ... | @@ -2064,11 +2747,11 @@ pub fn getBuiltinDecl(pt: Zcu.PerThread, name: []const u8) Allocator.Error!Inter | ... | @@ -2064,11 +2747,11 @@ pub fn getBuiltinDecl(pt: Zcu.PerThread, name: []const u8) Allocator.Error!Inter |
| 2064 | const std_file_imported = zcu.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig"); | 2747 | const std_file_imported = zcu.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig"); |
| 2065 | const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index).unwrap().?; | 2748 | const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index).unwrap().?; |
| 2066 | const std_namespace = zcu.declPtr(std_file_root_decl).getOwnedInnerNamespace(zcu).?; | 2749 | const std_namespace = zcu.declPtr(std_file_root_decl).getOwnedInnerNamespace(zcu).?; |
| 2067 | const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls); | 2750 | const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls); |
| 2068 | const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); | 2751 | const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 2069 | pt.ensureDeclAnalyzed(builtin_decl) catch @panic("std.builtin is corrupt"); | 2752 | pt.ensureDeclAnalyzed(builtin_decl) catch @panic("std.builtin is corrupt"); |
| 2070 | const builtin_namespace = zcu.declPtr(builtin_decl).getInnerNamespace(zcu) orelse @panic("std.builtin is corrupt"); | 2753 | const builtin_namespace = zcu.declPtr(builtin_decl).getInnerNamespace(zcu) orelse @panic("std.builtin is corrupt"); |
| 2071 | const name_str = try ip.getOrPutString(gpa, name, .no_embedded_nulls); | 2754 | const name_str = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls); |
| 2072 | return builtin_namespace.decls.getKeyAdapted(name_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std/builtin.zig is corrupt"); | 2755 | return builtin_namespace.decls.getKeyAdapted(name_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std/builtin.zig is corrupt"); |
| 2073 | } | 2756 | } |
| 2074 | 2757 | ||
| ... | @@ -2082,6 +2765,8 @@ pub fn getBuiltinType(pt: Zcu.PerThread, name: []const u8) Allocator.Error!Type | ... | @@ -2082,6 +2765,8 @@ pub fn getBuiltinType(pt: Zcu.PerThread, name: []const u8) Allocator.Error!Type |
| 2082 | const Air = @import("../Air.zig"); | 2765 | const Air = @import("../Air.zig"); |
| 2083 | const Allocator = std.mem.Allocator; | 2766 | const Allocator = std.mem.Allocator; |
| 2084 | const assert = std.debug.assert; | 2767 | const assert = std.debug.assert; |
| 2768 | const Ast = std.zig.Ast; | ||
| 2769 | const AstGen = std.zig.AstGen; | ||
| 2085 | const BigIntConst = std.math.big.int.Const; | 2770 | const BigIntConst = std.math.big.int.Const; |
| 2086 | const BigIntMutable = std.math.big.int.Mutable; | 2771 | const BigIntMutable = std.math.big.int.Mutable; |
| 2087 | const build_options = @import("build_options"); | 2772 | const build_options = @import("build_options"); |
src/arch/wasm/CodeGen.zig+5-5| ... | @@ -2204,14 +2204,14 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif | ... | @@ -2204,14 +2204,14 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 2204 | const func_val = (try func.air.value(pl_op.operand, pt)) orelse break :blk null; | 2204 | const func_val = (try func.air.value(pl_op.operand, pt)) orelse break :blk null; |
| 2205 | 2205 | ||
| 2206 | if (func_val.getFunction(mod)) |function| { | 2206 | if (func_val.getFunction(mod)) |function| { |
| 2207 | _ = try func.bin_file.getOrCreateAtomForDecl(function.owner_decl); | 2207 | _ = try func.bin_file.getOrCreateAtomForDecl(pt, function.owner_decl); |
| 2208 | break :blk function.owner_decl; | 2208 | break :blk function.owner_decl; |
| 2209 | } else if (func_val.getExternFunc(mod)) |extern_func| { | 2209 | } else if (func_val.getExternFunc(mod)) |extern_func| { |
| 2210 | const ext_decl = mod.declPtr(extern_func.decl); | 2210 | const ext_decl = mod.declPtr(extern_func.decl); |
| 2211 | const ext_info = mod.typeToFunc(ext_decl.typeOf(mod)).?; | 2211 | const ext_info = mod.typeToFunc(ext_decl.typeOf(mod)).?; |
| 2212 | var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), Type.fromInterned(ext_info.return_type), pt); | 2212 | var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), Type.fromInterned(ext_info.return_type), pt); |
| 2213 | defer func_type.deinit(func.gpa); | 2213 | defer func_type.deinit(func.gpa); |
| 2214 | const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_func.decl); | 2214 | const atom_index = try func.bin_file.getOrCreateAtomForDecl(pt, extern_func.decl); |
| 2215 | const atom = func.bin_file.getAtomPtr(atom_index); | 2215 | const atom = func.bin_file.getAtomPtr(atom_index); |
| 2216 | const type_index = try func.bin_file.storeDeclType(extern_func.decl, func_type); | 2216 | const type_index = try func.bin_file.storeDeclType(extern_func.decl, func_type); |
| 2217 | try func.bin_file.addOrUpdateImport( | 2217 | try func.bin_file.addOrUpdateImport( |
| ... | @@ -2224,7 +2224,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif | ... | @@ -2224,7 +2224,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif |
| 2224 | } else switch (mod.intern_pool.indexToKey(func_val.ip_index)) { | 2224 | } else switch (mod.intern_pool.indexToKey(func_val.ip_index)) { |
| 2225 | .ptr => |ptr| if (ptr.byte_offset == 0) switch (ptr.base_addr) { | 2225 | .ptr => |ptr| if (ptr.byte_offset == 0) switch (ptr.base_addr) { |
| 2226 | .decl => |decl| { | 2226 | .decl => |decl| { |
| 2227 | _ = try func.bin_file.getOrCreateAtomForDecl(decl); | 2227 | _ = try func.bin_file.getOrCreateAtomForDecl(pt, decl); |
| 2228 | break :blk decl; | 2228 | break :blk decl; |
| 2229 | }, | 2229 | }, |
| 2230 | else => {}, | 2230 | else => {}, |
| ... | @@ -3227,7 +3227,7 @@ fn lowerDeclRefValue(func: *CodeGen, decl_index: InternPool.DeclIndex, offset: u | ... | @@ -3227,7 +3227,7 @@ fn lowerDeclRefValue(func: *CodeGen, decl_index: InternPool.DeclIndex, offset: u |
| 3227 | return WValue{ .imm32 = 0xaaaaaaaa }; | 3227 | return WValue{ .imm32 = 0xaaaaaaaa }; |
| 3228 | } | 3228 | } |
| 3229 | 3229 | ||
| 3230 | const atom_index = try func.bin_file.getOrCreateAtomForDecl(decl_index); | 3230 | const atom_index = try func.bin_file.getOrCreateAtomForDecl(pt, decl_index); |
| 3231 | const atom = func.bin_file.getAtom(atom_index); | 3231 | const atom = func.bin_file.getAtom(atom_index); |
| 3232 | 3232 | ||
| 3233 | const target_sym_index = @intFromEnum(atom.sym_index); | 3233 | const target_sym_index = @intFromEnum(atom.sym_index); |
| ... | @@ -7284,7 +7284,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { | ... | @@ -7284,7 +7284,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 { |
| 7284 | defer arena_allocator.deinit(); | 7284 | defer arena_allocator.deinit(); |
| 7285 | const arena = arena_allocator.allocator(); | 7285 | const arena = arena_allocator.allocator(); |
| 7286 | 7286 | ||
| 7287 | const fqn = try mod.declPtr(enum_decl_index).fullyQualifiedName(mod); | 7287 | const fqn = try mod.declPtr(enum_decl_index).fullyQualifiedName(pt); |
| 7288 | const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(ip)}); | 7288 | const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(ip)}); |
| 7289 | 7289 | ||
| 7290 | // check if we already generated code for this. | 7290 | // check if we already generated code for this. |
src/codegen.zig+1-1| ... | @@ -756,7 +756,7 @@ fn lowerDeclRef( | ... | @@ -756,7 +756,7 @@ fn lowerDeclRef( |
| 756 | return Result.ok; | 756 | return Result.ok; |
| 757 | } | 757 | } |
| 758 | 758 | ||
| 759 | const vaddr = try lf.getDeclVAddr(decl_index, .{ | 759 | const vaddr = try lf.getDeclVAddr(pt, decl_index, .{ |
| 760 | .parent_atom_index = reloc_info.parent_atom_index, | 760 | .parent_atom_index = reloc_info.parent_atom_index, |
| 761 | .offset = code.items.len, | 761 | .offset = code.items.len, |
| 762 | .addend = @intCast(offset), | 762 | .addend = @intCast(offset), |
src/codegen/llvm.zig+16-14| ... | @@ -1744,7 +1744,7 @@ pub const Object = struct { | ... | @@ -1744,7 +1744,7 @@ pub const Object = struct { |
| 1744 | if (export_indices.len != 0) { | 1744 | if (export_indices.len != 0) { |
| 1745 | return updateExportedGlobal(self, zcu, global_index, export_indices); | 1745 | return updateExportedGlobal(self, zcu, global_index, export_indices); |
| 1746 | } else { | 1746 | } else { |
| 1747 | const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(zcu)).toSlice(ip)); | 1747 | const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(pt)).toSlice(ip)); |
| 1748 | try global_index.rename(fqn, &self.builder); | 1748 | try global_index.rename(fqn, &self.builder); |
| 1749 | global_index.setLinkage(.internal, &self.builder); | 1749 | global_index.setLinkage(.internal, &self.builder); |
| 1750 | if (comp.config.dll_export_fns) | 1750 | if (comp.config.dll_export_fns) |
| ... | @@ -2520,7 +2520,7 @@ pub const Object = struct { | ... | @@ -2520,7 +2520,7 @@ pub const Object = struct { |
| 2520 | const field_offset = ty.structFieldOffset(field_index, pt); | 2520 | const field_offset = ty.structFieldOffset(field_index, pt); |
| 2521 | 2521 | ||
| 2522 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse | 2522 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 2523 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls); | 2523 | try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 2524 | 2524 | ||
| 2525 | fields.appendAssumeCapacity(try o.builder.debugMemberType( | 2525 | fields.appendAssumeCapacity(try o.builder.debugMemberType( |
| 2526 | try o.builder.metadataString(field_name.toSlice(ip)), | 2526 | try o.builder.metadataString(field_name.toSlice(ip)), |
| ... | @@ -2807,17 +2807,18 @@ pub const Object = struct { | ... | @@ -2807,17 +2807,18 @@ pub const Object = struct { |
| 2807 | } | 2807 | } |
| 2808 | 2808 | ||
| 2809 | fn getStackTraceType(o: *Object) Allocator.Error!Type { | 2809 | fn getStackTraceType(o: *Object) Allocator.Error!Type { |
| 2810 | const zcu = o.pt.zcu; | 2810 | const pt = o.pt; |
| 2811 | const zcu = pt.zcu; | ||
| 2811 | 2812 | ||
| 2812 | const std_mod = zcu.std_mod; | 2813 | const std_mod = zcu.std_mod; |
| 2813 | const std_file_imported = zcu.importPkg(std_mod) catch unreachable; | 2814 | const std_file_imported = zcu.importPkg(std_mod) catch unreachable; |
| 2814 | 2815 | ||
| 2815 | const builtin_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "builtin", .no_embedded_nulls); | 2816 | const builtin_str = try zcu.intern_pool.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls); |
| 2816 | const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index); | 2817 | const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index); |
| 2817 | const std_namespace = zcu.namespacePtr(zcu.declPtr(std_file_root_decl.unwrap().?).src_namespace); | 2818 | const std_namespace = zcu.namespacePtr(zcu.declPtr(std_file_root_decl.unwrap().?).src_namespace); |
| 2818 | const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }).?; | 2819 | const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }).?; |
| 2819 | 2820 | ||
| 2820 | const stack_trace_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "StackTrace", .no_embedded_nulls); | 2821 | const stack_trace_str = try zcu.intern_pool.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls); |
| 2821 | // buffer is only used for int_type, `builtin` is a struct. | 2822 | // buffer is only used for int_type, `builtin` is a struct. |
| 2822 | const builtin_ty = zcu.declPtr(builtin_decl).val.toType(); | 2823 | const builtin_ty = zcu.declPtr(builtin_decl).val.toType(); |
| 2823 | const builtin_namespace = zcu.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(zcu)).?; | 2824 | const builtin_namespace = zcu.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(zcu)).?; |
| ... | @@ -2865,7 +2866,7 @@ pub const Object = struct { | ... | @@ -2865,7 +2866,7 @@ pub const Object = struct { |
| 2865 | try o.builder.strtabString((if (is_extern) | 2866 | try o.builder.strtabString((if (is_extern) |
| 2866 | decl.name | 2867 | decl.name |
| 2867 | else | 2868 | else |
| 2868 | try decl.fullyQualifiedName(zcu)).toSlice(ip)), | 2869 | try decl.fullyQualifiedName(pt)).toSlice(ip)), |
| 2869 | toLlvmAddressSpace(decl.@"addrspace", target), | 2870 | toLlvmAddressSpace(decl.@"addrspace", target), |
| 2870 | ); | 2871 | ); |
| 2871 | gop.value_ptr.* = function_index.ptrConst(&o.builder).global; | 2872 | gop.value_ptr.* = function_index.ptrConst(&o.builder).global; |
| ... | @@ -3074,7 +3075,8 @@ pub const Object = struct { | ... | @@ -3074,7 +3075,8 @@ pub const Object = struct { |
| 3074 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable; | 3075 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable; |
| 3075 | errdefer assert(o.decl_map.remove(decl_index)); | 3076 | errdefer assert(o.decl_map.remove(decl_index)); |
| 3076 | 3077 | ||
| 3077 | const zcu = o.pt.zcu; | 3078 | const pt = o.pt; |
| 3079 | const zcu = pt.zcu; | ||
| 3078 | const decl = zcu.declPtr(decl_index); | 3080 | const decl = zcu.declPtr(decl_index); |
| 3079 | const is_extern = decl.isExtern(zcu); | 3081 | const is_extern = decl.isExtern(zcu); |
| 3080 | 3082 | ||
| ... | @@ -3082,7 +3084,7 @@ pub const Object = struct { | ... | @@ -3082,7 +3084,7 @@ pub const Object = struct { |
| 3082 | try o.builder.strtabString((if (is_extern) | 3084 | try o.builder.strtabString((if (is_extern) |
| 3083 | decl.name | 3085 | decl.name |
| 3084 | else | 3086 | else |
| 3085 | try decl.fullyQualifiedName(zcu)).toSlice(&zcu.intern_pool)), | 3087 | try decl.fullyQualifiedName(pt)).toSlice(&zcu.intern_pool)), |
| 3086 | try o.lowerType(decl.typeOf(zcu)), | 3088 | try o.lowerType(decl.typeOf(zcu)), |
| 3087 | toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()), | 3089 | toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()), |
| 3088 | ); | 3090 | ); |
| ... | @@ -3310,7 +3312,7 @@ pub const Object = struct { | ... | @@ -3310,7 +3312,7 @@ pub const Object = struct { |
| 3310 | return int_ty; | 3312 | return int_ty; |
| 3311 | } | 3313 | } |
| 3312 | 3314 | ||
| 3313 | const fqn = try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(mod); | 3315 | const fqn = try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(pt); |
| 3314 | 3316 | ||
| 3315 | var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){}; | 3317 | var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){}; |
| 3316 | defer llvm_field_types.deinit(o.gpa); | 3318 | defer llvm_field_types.deinit(o.gpa); |
| ... | @@ -3464,7 +3466,7 @@ pub const Object = struct { | ... | @@ -3464,7 +3466,7 @@ pub const Object = struct { |
| 3464 | return enum_tag_ty; | 3466 | return enum_tag_ty; |
| 3465 | } | 3467 | } |
| 3466 | 3468 | ||
| 3467 | const fqn = try mod.declPtr(union_obj.decl).fullyQualifiedName(mod); | 3469 | const fqn = try mod.declPtr(union_obj.decl).fullyQualifiedName(pt); |
| 3468 | 3470 | ||
| 3469 | const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]); | 3471 | const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]); |
| 3470 | const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty); | 3472 | const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty); |
| ... | @@ -3525,7 +3527,7 @@ pub const Object = struct { | ... | @@ -3525,7 +3527,7 @@ pub const Object = struct { |
| 3525 | const gop = try o.type_map.getOrPut(o.gpa, t.toIntern()); | 3527 | const gop = try o.type_map.getOrPut(o.gpa, t.toIntern()); |
| 3526 | if (!gop.found_existing) { | 3528 | if (!gop.found_existing) { |
| 3527 | const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl); | 3529 | const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl); |
| 3528 | const fqn = try decl.fullyQualifiedName(mod); | 3530 | const fqn = try decl.fullyQualifiedName(pt); |
| 3529 | gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip))); | 3531 | gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip))); |
| 3530 | } | 3532 | } |
| 3531 | return gop.value_ptr.*; | 3533 | return gop.value_ptr.*; |
| ... | @@ -4585,7 +4587,7 @@ pub const Object = struct { | ... | @@ -4585,7 +4587,7 @@ pub const Object = struct { |
| 4585 | 4587 | ||
| 4586 | const usize_ty = try o.lowerType(Type.usize); | 4588 | const usize_ty = try o.lowerType(Type.usize); |
| 4587 | const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0); | 4589 | const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0); |
| 4588 | const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(zcu); | 4590 | const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(pt); |
| 4589 | const target = zcu.root_mod.resolved_target.result; | 4591 | const target = zcu.root_mod.resolved_target.result; |
| 4590 | const function_index = try o.builder.addFunction( | 4592 | const function_index = try o.builder.addFunction( |
| 4591 | try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal), | 4593 | try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal), |
| ... | @@ -5173,7 +5175,7 @@ pub const FuncGen = struct { | ... | @@ -5173,7 +5175,7 @@ pub const FuncGen = struct { |
| 5173 | const line_number = decl.navSrcLine(zcu) + 1; | 5175 | const line_number = decl.navSrcLine(zcu) + 1; |
| 5174 | self.inlined = self.wip.debug_location; | 5176 | self.inlined = self.wip.debug_location; |
| 5175 | 5177 | ||
| 5176 | const fqn = try decl.fullyQualifiedName(zcu); | 5178 | const fqn = try decl.fullyQualifiedName(pt); |
| 5177 | 5179 | ||
| 5178 | const fn_ty = try pt.funcType(.{ | 5180 | const fn_ty = try pt.funcType(.{ |
| 5179 | .param_types = &.{}, | 5181 | .param_types = &.{}, |
| ... | @@ -9707,7 +9709,7 @@ pub const FuncGen = struct { | ... | @@ -9707,7 +9709,7 @@ pub const FuncGen = struct { |
| 9707 | if (gop.found_existing) return gop.value_ptr.*; | 9709 | if (gop.found_existing) return gop.value_ptr.*; |
| 9708 | errdefer assert(o.named_enum_map.remove(enum_type.decl)); | 9710 | errdefer assert(o.named_enum_map.remove(enum_type.decl)); |
| 9709 | 9711 | ||
| 9710 | const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(zcu); | 9712 | const fqn = try zcu.declPtr(enum_type.decl).fullyQualifiedName(pt); |
| 9711 | const target = zcu.root_mod.resolved_target.result; | 9713 | const target = zcu.root_mod.resolved_target.result; |
| 9712 | const function_index = try o.builder.addFunction( | 9714 | const function_index = try o.builder.addFunction( |
| 9713 | try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal), | 9715 | try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal), |
src/codegen/spirv.zig+4-4| ... | @@ -1753,7 +1753,7 @@ const DeclGen = struct { | ... | @@ -1753,7 +1753,7 @@ const DeclGen = struct { |
| 1753 | } | 1753 | } |
| 1754 | 1754 | ||
| 1755 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse | 1755 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 1756 | try ip.getOrPutStringFmt(mod.gpa, "{d}", .{field_index}, .no_embedded_nulls); | 1756 | try ip.getOrPutStringFmt(mod.gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| 1757 | try member_types.append(try self.resolveType(field_ty, .indirect)); | 1757 | try member_types.append(try self.resolveType(field_ty, .indirect)); |
| 1758 | try member_names.append(field_name.toSlice(ip)); | 1758 | try member_names.append(field_name.toSlice(ip)); |
| 1759 | } | 1759 | } |
| ... | @@ -3012,7 +3012,7 @@ const DeclGen = struct { | ... | @@ -3012,7 +3012,7 @@ const DeclGen = struct { |
| 3012 | // Append the actual code into the functions section. | 3012 | // Append the actual code into the functions section. |
| 3013 | try self.spv.addFunction(spv_decl_index, self.func); | 3013 | try self.spv.addFunction(spv_decl_index, self.func); |
| 3014 | 3014 | ||
| 3015 | const fqn = try decl.fullyQualifiedName(self.pt.zcu); | 3015 | const fqn = try decl.fullyQualifiedName(self.pt); |
| 3016 | try self.spv.debugName(result_id, fqn.toSlice(ip)); | 3016 | try self.spv.debugName(result_id, fqn.toSlice(ip)); |
| 3017 | 3017 | ||
| 3018 | // Temporarily generate a test kernel declaration if this is a test function. | 3018 | // Temporarily generate a test kernel declaration if this is a test function. |
| ... | @@ -3041,7 +3041,7 @@ const DeclGen = struct { | ... | @@ -3041,7 +3041,7 @@ const DeclGen = struct { |
| 3041 | .storage_class = final_storage_class, | 3041 | .storage_class = final_storage_class, |
| 3042 | }); | 3042 | }); |
| 3043 | 3043 | ||
| 3044 | const fqn = try decl.fullyQualifiedName(self.pt.zcu); | 3044 | const fqn = try decl.fullyQualifiedName(self.pt); |
| 3045 | try self.spv.debugName(result_id, fqn.toSlice(ip)); | 3045 | try self.spv.debugName(result_id, fqn.toSlice(ip)); |
| 3046 | try self.spv.declareDeclDeps(spv_decl_index, &.{}); | 3046 | try self.spv.declareDeclDeps(spv_decl_index, &.{}); |
| 3047 | }, | 3047 | }, |
| ... | @@ -3086,7 +3086,7 @@ const DeclGen = struct { | ... | @@ -3086,7 +3086,7 @@ const DeclGen = struct { |
| 3086 | try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {}); | 3086 | try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {}); |
| 3087 | try self.spv.addFunction(spv_decl_index, self.func); | 3087 | try self.spv.addFunction(spv_decl_index, self.func); |
| 3088 | 3088 | ||
| 3089 | const fqn = try decl.fullyQualifiedName(self.pt.zcu); | 3089 | const fqn = try decl.fullyQualifiedName(self.pt); |
| 3090 | try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{fqn.fmt(ip)}); | 3090 | try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{fqn.fmt(ip)}); |
| 3091 | 3091 | ||
| 3092 | try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{ | 3092 | try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{ |
src/link.zig+5-5| ... | @@ -424,14 +424,14 @@ pub const File = struct { | ... | @@ -424,14 +424,14 @@ pub const File = struct { |
| 424 | } | 424 | } |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | pub fn updateDeclLineNumber(base: *File, module: *Zcu, decl_index: InternPool.DeclIndex) UpdateDeclError!void { | 427 | pub fn updateDeclLineNumber(base: *File, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) UpdateDeclError!void { |
| 428 | const decl = module.declPtr(decl_index); | 428 | const decl = pt.zcu.declPtr(decl_index); |
| 429 | assert(decl.has_tv); | 429 | assert(decl.has_tv); |
| 430 | switch (base.tag) { | 430 | switch (base.tag) { |
| 431 | .spirv, .nvptx => {}, | 431 | .spirv, .nvptx => {}, |
| 432 | inline else => |tag| { | 432 | inline else => |tag| { |
| 433 | if (tag != .c and build_options.only_c) unreachable; | 433 | if (tag != .c and build_options.only_c) unreachable; |
| 434 | return @as(*tag.Type(), @fieldParentPtr("base", base)).updateDeclLineNumber(module, decl_index); | 434 | return @as(*tag.Type(), @fieldParentPtr("base", base)).updateDeclLineNumber(pt, decl_index); |
| 435 | }, | 435 | }, |
| 436 | } | 436 | } |
| 437 | } | 437 | } |
| ... | @@ -626,14 +626,14 @@ pub const File = struct { | ... | @@ -626,14 +626,14 @@ pub const File = struct { |
| 626 | /// `Decl`'s address was not yet resolved, or the containing atom gets moved in virtual memory. | 626 | /// `Decl`'s address was not yet resolved, or the containing atom gets moved in virtual memory. |
| 627 | /// May be called before or after updateFunc/updateDecl therefore it is up to the linker to allocate | 627 | /// May be called before or after updateFunc/updateDecl therefore it is up to the linker to allocate |
| 628 | /// the block/atom. | 628 | /// the block/atom. |
| 629 | pub fn getDeclVAddr(base: *File, decl_index: InternPool.DeclIndex, reloc_info: RelocInfo) !u64 { | 629 | pub fn getDeclVAddr(base: *File, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: RelocInfo) !u64 { |
| 630 | if (build_options.only_c) @compileError("unreachable"); | 630 | if (build_options.only_c) @compileError("unreachable"); |
| 631 | switch (base.tag) { | 631 | switch (base.tag) { |
| 632 | .c => unreachable, | 632 | .c => unreachable, |
| 633 | .spirv => unreachable, | 633 | .spirv => unreachable, |
| 634 | .nvptx => unreachable, | 634 | .nvptx => unreachable, |
| 635 | inline else => |tag| { | 635 | inline else => |tag| { |
| 636 | return @as(*tag.Type(), @fieldParentPtr("base", base)).getDeclVAddr(decl_index, reloc_info); | 636 | return @as(*tag.Type(), @fieldParentPtr("base", base)).getDeclVAddr(pt, decl_index, reloc_info); |
| 637 | }, | 637 | }, |
| 638 | } | 638 | } |
| 639 | } | 639 | } |
src/link/C.zig+2-2| ... | @@ -383,11 +383,11 @@ pub fn updateDecl(self: *C, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) | ... | @@ -383,11 +383,11 @@ pub fn updateDecl(self: *C, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) |
| 383 | gop.value_ptr.fwd_decl = try self.addString(object.dg.fwd_decl.items); | 383 | gop.value_ptr.fwd_decl = try self.addString(object.dg.fwd_decl.items); |
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | pub fn updateDeclLineNumber(self: *C, zcu: *Zcu, decl_index: InternPool.DeclIndex) !void { | 386 | pub fn updateDeclLineNumber(self: *C, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void { |
| 387 | // The C backend does not have the ability to fix line numbers without re-generating | 387 | // The C backend does not have the ability to fix line numbers without re-generating |
| 388 | // the entire Decl. | 388 | // the entire Decl. |
| 389 | _ = self; | 389 | _ = self; |
| 390 | _ = zcu; | 390 | _ = pt; |
| 391 | _ = decl_index; | 391 | _ = decl_index; |
| 392 | } | 392 | } |
| 393 | 393 |
src/link/Coff.zig+5-5| ... | @@ -1176,7 +1176,7 @@ pub fn lowerUnnamedConst(self: *Coff, pt: Zcu.PerThread, val: Value, decl_index: | ... | @@ -1176,7 +1176,7 @@ pub fn lowerUnnamedConst(self: *Coff, pt: Zcu.PerThread, val: Value, decl_index: |
| 1176 | gop.value_ptr.* = .{}; | 1176 | gop.value_ptr.* = .{}; |
| 1177 | } | 1177 | } |
| 1178 | const unnamed_consts = gop.value_ptr; | 1178 | const unnamed_consts = gop.value_ptr; |
| 1179 | const decl_name = try decl.fullyQualifiedName(mod); | 1179 | const decl_name = try decl.fullyQualifiedName(pt); |
| 1180 | const index = unnamed_consts.items.len; | 1180 | const index = unnamed_consts.items.len; |
| 1181 | const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); | 1181 | const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); |
| 1182 | defer gpa.free(sym_name); | 1182 | defer gpa.free(sym_name); |
| ... | @@ -1427,7 +1427,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd | ... | @@ -1427,7 +1427,7 @@ fn updateDeclCode(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclInd |
| 1427 | const mod = pt.zcu; | 1427 | const mod = pt.zcu; |
| 1428 | const decl = mod.declPtr(decl_index); | 1428 | const decl = mod.declPtr(decl_index); |
| 1429 | 1429 | ||
| 1430 | const decl_name = try decl.fullyQualifiedName(mod); | 1430 | const decl_name = try decl.fullyQualifiedName(pt); |
| 1431 | 1431 | ||
| 1432 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | 1432 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); |
| 1433 | const required_alignment: u32 = @intCast(decl.getAlignment(pt).toByteUnits() orelse 0); | 1433 | const required_alignment: u32 = @intCast(decl.getAlignment(pt).toByteUnits() orelse 0); |
| ... | @@ -1855,7 +1855,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no | ... | @@ -1855,7 +1855,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no |
| 1855 | assert(!self.imports_count_dirty); | 1855 | assert(!self.imports_count_dirty); |
| 1856 | } | 1856 | } |
| 1857 | 1857 | ||
| 1858 | pub fn getDeclVAddr(self: *Coff, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 { | 1858 | pub fn getDeclVAddr(self: *Coff, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 { |
| 1859 | assert(self.llvm_object == null); | 1859 | assert(self.llvm_object == null); |
| 1860 | 1860 | ||
| 1861 | const this_atom_index = try self.getOrCreateAtomForDecl(decl_index); | 1861 | const this_atom_index = try self.getOrCreateAtomForDecl(decl_index); |
| ... | @@ -1972,9 +1972,9 @@ pub fn getGlobalSymbol(self: *Coff, name: []const u8, lib_name_name: ?[]const u8 | ... | @@ -1972,9 +1972,9 @@ pub fn getGlobalSymbol(self: *Coff, name: []const u8, lib_name_name: ?[]const u8 |
| 1972 | return global_index; | 1972 | return global_index; |
| 1973 | } | 1973 | } |
| 1974 | 1974 | ||
| 1975 | pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl_index: InternPool.DeclIndex) !void { | 1975 | pub fn updateDeclLineNumber(self: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void { |
| 1976 | _ = self; | 1976 | _ = self; |
| 1977 | _ = module; | 1977 | _ = pt; |
| 1978 | _ = decl_index; | 1978 | _ = decl_index; |
| 1979 | log.debug("TODO implement updateDeclLineNumber", .{}); | 1979 | log.debug("TODO implement updateDeclLineNumber", .{}); |
| 1980 | } | 1980 | } |
src/link/Dwarf.zig+1-1| ... | @@ -1082,7 +1082,7 @@ pub fn initDeclState(self: *Dwarf, pt: Zcu.PerThread, decl_index: InternPool.Dec | ... | @@ -1082,7 +1082,7 @@ pub fn initDeclState(self: *Dwarf, pt: Zcu.PerThread, decl_index: InternPool.Dec |
| 1082 | defer tracy.end(); | 1082 | defer tracy.end(); |
| 1083 | 1083 | ||
| 1084 | const decl = pt.zcu.declPtr(decl_index); | 1084 | const decl = pt.zcu.declPtr(decl_index); |
| 1085 | const decl_linkage_name = try decl.fullyQualifiedName(pt.zcu); | 1085 | const decl_linkage_name = try decl.fullyQualifiedName(pt); |
| 1086 | 1086 | ||
| 1087 | log.debug("initDeclState {}{*}", .{ decl_linkage_name.fmt(&pt.zcu.intern_pool), decl }); | 1087 | log.debug("initDeclState {}{*}", .{ decl_linkage_name.fmt(&pt.zcu.intern_pool), decl }); |
| 1088 | 1088 |
src/link/Elf.zig+3-3| ... | @@ -543,7 +543,7 @@ pub fn deinit(self: *Elf) void { | ... | @@ -543,7 +543,7 @@ pub fn deinit(self: *Elf) void { |
| 543 | self.comdat_group_sections.deinit(gpa); | 543 | self.comdat_group_sections.deinit(gpa); |
| 544 | } | 544 | } |
| 545 | 545 | ||
| 546 | pub fn getDeclVAddr(self: *Elf, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 { | 546 | pub fn getDeclVAddr(self: *Elf, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 { |
| 547 | assert(self.llvm_object == null); | 547 | assert(self.llvm_object == null); |
| 548 | return self.zigObjectPtr().?.getDeclVAddr(self, decl_index, reloc_info); | 548 | return self.zigObjectPtr().?.getDeclVAddr(self, decl_index, reloc_info); |
| 549 | } | 549 | } |
| ... | @@ -3021,9 +3021,9 @@ pub fn updateExports( | ... | @@ -3021,9 +3021,9 @@ pub fn updateExports( |
| 3021 | return self.zigObjectPtr().?.updateExports(self, pt, exported, export_indices); | 3021 | return self.zigObjectPtr().?.updateExports(self, pt, exported, export_indices); |
| 3022 | } | 3022 | } |
| 3023 | 3023 | ||
| 3024 | pub fn updateDeclLineNumber(self: *Elf, mod: *Module, decl_index: InternPool.DeclIndex) !void { | 3024 | pub fn updateDeclLineNumber(self: *Elf, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void { |
| 3025 | if (self.llvm_object) |_| return; | 3025 | if (self.llvm_object) |_| return; |
| 3026 | return self.zigObjectPtr().?.updateDeclLineNumber(mod, decl_index); | 3026 | return self.zigObjectPtr().?.updateDeclLineNumber(pt, decl_index); |
| 3027 | } | 3027 | } |
| 3028 | 3028 | ||
| 3029 | pub fn deleteExport( | 3029 | pub fn deleteExport( |
src/link/Elf/ZigObject.zig+8-8| ... | @@ -908,7 +908,7 @@ fn updateDeclCode( | ... | @@ -908,7 +908,7 @@ fn updateDeclCode( |
| 908 | const gpa = elf_file.base.comp.gpa; | 908 | const gpa = elf_file.base.comp.gpa; |
| 909 | const mod = pt.zcu; | 909 | const mod = pt.zcu; |
| 910 | const decl = mod.declPtr(decl_index); | 910 | const decl = mod.declPtr(decl_index); |
| 911 | const decl_name = try decl.fullyQualifiedName(mod); | 911 | const decl_name = try decl.fullyQualifiedName(pt); |
| 912 | 912 | ||
| 913 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | 913 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); |
| 914 | 914 | ||
| ... | @@ -1009,7 +1009,7 @@ fn updateTlv( | ... | @@ -1009,7 +1009,7 @@ fn updateTlv( |
| 1009 | const mod = pt.zcu; | 1009 | const mod = pt.zcu; |
| 1010 | const gpa = mod.gpa; | 1010 | const gpa = mod.gpa; |
| 1011 | const decl = mod.declPtr(decl_index); | 1011 | const decl = mod.declPtr(decl_index); |
| 1012 | const decl_name = try decl.fullyQualifiedName(mod); | 1012 | const decl_name = try decl.fullyQualifiedName(pt); |
| 1013 | 1013 | ||
| 1014 | log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl }); | 1014 | log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl }); |
| 1015 | 1015 | ||
| ... | @@ -1286,7 +1286,7 @@ pub fn lowerUnnamedConst( | ... | @@ -1286,7 +1286,7 @@ pub fn lowerUnnamedConst( |
| 1286 | } | 1286 | } |
| 1287 | const unnamed_consts = gop.value_ptr; | 1287 | const unnamed_consts = gop.value_ptr; |
| 1288 | const decl = mod.declPtr(decl_index); | 1288 | const decl = mod.declPtr(decl_index); |
| 1289 | const decl_name = try decl.fullyQualifiedName(mod); | 1289 | const decl_name = try decl.fullyQualifiedName(pt); |
| 1290 | const index = unnamed_consts.items.len; | 1290 | const index = unnamed_consts.items.len; |
| 1291 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); | 1291 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); |
| 1292 | defer gpa.free(name); | 1292 | defer gpa.free(name); |
| ... | @@ -1466,19 +1466,19 @@ pub fn updateExports( | ... | @@ -1466,19 +1466,19 @@ pub fn updateExports( |
| 1466 | /// Must be called only after a successful call to `updateDecl`. | 1466 | /// Must be called only after a successful call to `updateDecl`. |
| 1467 | pub fn updateDeclLineNumber( | 1467 | pub fn updateDeclLineNumber( |
| 1468 | self: *ZigObject, | 1468 | self: *ZigObject, |
| 1469 | mod: *Module, | 1469 | pt: Zcu.PerThread, |
| 1470 | decl_index: InternPool.DeclIndex, | 1470 | decl_index: InternPool.DeclIndex, |
| 1471 | ) !void { | 1471 | ) !void { |
| 1472 | const tracy = trace(@src()); | 1472 | const tracy = trace(@src()); |
| 1473 | defer tracy.end(); | 1473 | defer tracy.end(); |
| 1474 | 1474 | ||
| 1475 | const decl = mod.declPtr(decl_index); | 1475 | const decl = pt.zcu.declPtr(decl_index); |
| 1476 | const decl_name = try decl.fullyQualifiedName(mod); | 1476 | const decl_name = try decl.fullyQualifiedName(pt); |
| 1477 | 1477 | ||
| 1478 | log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | 1478 | log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&pt.zcu.intern_pool), decl }); |
| 1479 | 1479 | ||
| 1480 | if (self.dwarf) |*dw| { | 1480 | if (self.dwarf) |*dw| { |
| 1481 | try dw.updateDeclLineNumber(mod, decl_index); | 1481 | try dw.updateDeclLineNumber(pt.zcu, decl_index); |
| 1482 | } | 1482 | } |
| 1483 | } | 1483 | } |
| 1484 | 1484 |
src/link/MachO.zig+3-3| ... | @@ -3198,9 +3198,9 @@ pub fn updateDecl(self: *MachO, pt: Zcu.PerThread, decl_index: InternPool.DeclIn | ... | @@ -3198,9 +3198,9 @@ pub fn updateDecl(self: *MachO, pt: Zcu.PerThread, decl_index: InternPool.DeclIn |
| 3198 | return self.getZigObject().?.updateDecl(self, pt, decl_index); | 3198 | return self.getZigObject().?.updateDecl(self, pt, decl_index); |
| 3199 | } | 3199 | } |
| 3200 | 3200 | ||
| 3201 | pub fn updateDeclLineNumber(self: *MachO, module: *Module, decl_index: InternPool.DeclIndex) !void { | 3201 | pub fn updateDeclLineNumber(self: *MachO, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void { |
| 3202 | if (self.llvm_object) |_| return; | 3202 | if (self.llvm_object) |_| return; |
| 3203 | return self.getZigObject().?.updateDeclLineNumber(module, decl_index); | 3203 | return self.getZigObject().?.updateDeclLineNumber(pt, decl_index); |
| 3204 | } | 3204 | } |
| 3205 | 3205 | ||
| 3206 | pub fn updateExports( | 3206 | pub fn updateExports( |
| ... | @@ -3230,7 +3230,7 @@ pub fn freeDecl(self: *MachO, decl_index: InternPool.DeclIndex) void { | ... | @@ -3230,7 +3230,7 @@ pub fn freeDecl(self: *MachO, decl_index: InternPool.DeclIndex) void { |
| 3230 | return self.getZigObject().?.freeDecl(decl_index); | 3230 | return self.getZigObject().?.freeDecl(decl_index); |
| 3231 | } | 3231 | } |
| 3232 | 3232 | ||
| 3233 | pub fn getDeclVAddr(self: *MachO, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 { | 3233 | pub fn getDeclVAddr(self: *MachO, _: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: link.File.RelocInfo) !u64 { |
| 3234 | assert(self.llvm_object == null); | 3234 | assert(self.llvm_object == null); |
| 3235 | return self.getZigObject().?.getDeclVAddr(self, decl_index, reloc_info); | 3235 | return self.getZigObject().?.getDeclVAddr(self, decl_index, reloc_info); |
| 3236 | } | 3236 | } |
src/link/MachO/ZigObject.zig+8-9| ... | @@ -810,7 +810,7 @@ fn updateDeclCode( | ... | @@ -810,7 +810,7 @@ fn updateDeclCode( |
| 810 | const gpa = macho_file.base.comp.gpa; | 810 | const gpa = macho_file.base.comp.gpa; |
| 811 | const mod = pt.zcu; | 811 | const mod = pt.zcu; |
| 812 | const decl = mod.declPtr(decl_index); | 812 | const decl = mod.declPtr(decl_index); |
| 813 | const decl_name = try decl.fullyQualifiedName(mod); | 813 | const decl_name = try decl.fullyQualifiedName(pt); |
| 814 | 814 | ||
| 815 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | 815 | log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); |
| 816 | 816 | ||
| ... | @@ -893,13 +893,12 @@ fn updateTlv( | ... | @@ -893,13 +893,12 @@ fn updateTlv( |
| 893 | sect_index: u8, | 893 | sect_index: u8, |
| 894 | code: []const u8, | 894 | code: []const u8, |
| 895 | ) !void { | 895 | ) !void { |
| 896 | const mod = pt.zcu; | 896 | const decl = pt.zcu.declPtr(decl_index); |
| 897 | const decl = mod.declPtr(decl_index); | 897 | const decl_name = try decl.fullyQualifiedName(pt); |
| 898 | const decl_name = try decl.fullyQualifiedName(mod); | ||
| 899 | 898 | ||
| 900 | log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl }); | 899 | log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&pt.zcu.intern_pool), decl }); |
| 901 | 900 | ||
| 902 | const decl_name_slice = decl_name.toSlice(&mod.intern_pool); | 901 | const decl_name_slice = decl_name.toSlice(&pt.zcu.intern_pool); |
| 903 | const required_alignment = decl.getAlignment(pt); | 902 | const required_alignment = decl.getAlignment(pt); |
| 904 | 903 | ||
| 905 | // 1. Lower TLV initializer | 904 | // 1. Lower TLV initializer |
| ... | @@ -1100,7 +1099,7 @@ pub fn lowerUnnamedConst( | ... | @@ -1100,7 +1099,7 @@ pub fn lowerUnnamedConst( |
| 1100 | } | 1099 | } |
| 1101 | const unnamed_consts = gop.value_ptr; | 1100 | const unnamed_consts = gop.value_ptr; |
| 1102 | const decl = mod.declPtr(decl_index); | 1101 | const decl = mod.declPtr(decl_index); |
| 1103 | const decl_name = try decl.fullyQualifiedName(mod); | 1102 | const decl_name = try decl.fullyQualifiedName(pt); |
| 1104 | const index = unnamed_consts.items.len; | 1103 | const index = unnamed_consts.items.len; |
| 1105 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); | 1104 | const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); |
| 1106 | defer gpa.free(name); | 1105 | defer gpa.free(name); |
| ... | @@ -1363,9 +1362,9 @@ fn updateLazySymbol( | ... | @@ -1363,9 +1362,9 @@ fn updateLazySymbol( |
| 1363 | } | 1362 | } |
| 1364 | 1363 | ||
| 1365 | /// Must be called only after a successful call to `updateDecl`. | 1364 | /// Must be called only after a successful call to `updateDecl`. |
| 1366 | pub fn updateDeclLineNumber(self: *ZigObject, mod: *Module, decl_index: InternPool.DeclIndex) !void { | 1365 | pub fn updateDeclLineNumber(self: *ZigObject, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void { |
| 1367 | if (self.dwarf) |*dw| { | 1366 | if (self.dwarf) |*dw| { |
| 1368 | try dw.updateDeclLineNumber(mod, decl_index); | 1367 | try dw.updateDeclLineNumber(pt.zcu, decl_index); |
| 1369 | } | 1368 | } |
| 1370 | } | 1369 | } |
| 1371 | 1370 |
src/link/Plan9.zig+7-7| ... | @@ -483,7 +483,7 @@ pub fn lowerUnnamedConst(self: *Plan9, pt: Zcu.PerThread, val: Value, decl_index | ... | @@ -483,7 +483,7 @@ pub fn lowerUnnamedConst(self: *Plan9, pt: Zcu.PerThread, val: Value, decl_index |
| 483 | } | 483 | } |
| 484 | const unnamed_consts = gop.value_ptr; | 484 | const unnamed_consts = gop.value_ptr; |
| 485 | 485 | ||
| 486 | const decl_name = try decl.fullyQualifiedName(mod); | 486 | const decl_name = try decl.fullyQualifiedName(pt); |
| 487 | 487 | ||
| 488 | const index = unnamed_consts.items.len; | 488 | const index = unnamed_consts.items.len; |
| 489 | // name is freed when the unnamed const is freed | 489 | // name is freed when the unnamed const is freed |
| ... | @@ -1496,22 +1496,22 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void { | ... | @@ -1496,22 +1496,22 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void { |
| 1496 | } | 1496 | } |
| 1497 | 1497 | ||
| 1498 | /// Must be called only after a successful call to `updateDecl`. | 1498 | /// Must be called only after a successful call to `updateDecl`. |
| 1499 | pub fn updateDeclLineNumber(self: *Plan9, mod: *Zcu, decl_index: InternPool.DeclIndex) !void { | 1499 | pub fn updateDeclLineNumber(self: *Plan9, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void { |
| 1500 | _ = self; | 1500 | _ = self; |
| 1501 | _ = mod; | 1501 | _ = pt; |
| 1502 | _ = decl_index; | 1502 | _ = decl_index; |
| 1503 | } | 1503 | } |
| 1504 | 1504 | ||
| 1505 | pub fn getDeclVAddr( | 1505 | pub fn getDeclVAddr( |
| 1506 | self: *Plan9, | 1506 | self: *Plan9, |
| 1507 | pt: Zcu.PerThread, | ||
| 1507 | decl_index: InternPool.DeclIndex, | 1508 | decl_index: InternPool.DeclIndex, |
| 1508 | reloc_info: link.File.RelocInfo, | 1509 | reloc_info: link.File.RelocInfo, |
| 1509 | ) !u64 { | 1510 | ) !u64 { |
| 1510 | const mod = self.base.comp.module.?; | 1511 | const ip = &pt.zcu.intern_pool; |
| 1511 | const ip = &mod.intern_pool; | 1512 | const decl = pt.zcu.declPtr(decl_index); |
| 1512 | const decl = mod.declPtr(decl_index); | ||
| 1513 | log.debug("getDeclVAddr for {}", .{decl.name.fmt(ip)}); | 1513 | log.debug("getDeclVAddr for {}", .{decl.name.fmt(ip)}); |
| 1514 | if (decl.isExtern(mod)) { | 1514 | if (decl.isExtern(pt.zcu)) { |
| 1515 | if (decl.name.eqlSlice("etext", ip)) { | 1515 | if (decl.name.eqlSlice("etext", ip)) { |
| 1516 | try self.addReloc(reloc_info.parent_atom_index, .{ | 1516 | try self.addReloc(reloc_info.parent_atom_index, .{ |
| 1517 | .target = undefined, | 1517 | .target = undefined, |
src/link/Wasm.zig+6-5| ... | @@ -1457,9 +1457,9 @@ pub fn updateDecl(wasm: *Wasm, pt: Zcu.PerThread, decl_index: InternPool.DeclInd | ... | @@ -1457,9 +1457,9 @@ pub fn updateDecl(wasm: *Wasm, pt: Zcu.PerThread, decl_index: InternPool.DeclInd |
| 1457 | try wasm.zigObjectPtr().?.updateDecl(wasm, pt, decl_index); | 1457 | try wasm.zigObjectPtr().?.updateDecl(wasm, pt, decl_index); |
| 1458 | } | 1458 | } |
| 1459 | 1459 | ||
| 1460 | pub fn updateDeclLineNumber(wasm: *Wasm, mod: *Zcu, decl_index: InternPool.DeclIndex) !void { | 1460 | pub fn updateDeclLineNumber(wasm: *Wasm, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void { |
| 1461 | if (wasm.llvm_object) |_| return; | 1461 | if (wasm.llvm_object) |_| return; |
| 1462 | try wasm.zigObjectPtr().?.updateDeclLineNumber(mod, decl_index); | 1462 | try wasm.zigObjectPtr().?.updateDeclLineNumber(pt, decl_index); |
| 1463 | } | 1463 | } |
| 1464 | 1464 | ||
| 1465 | /// From a given symbol location, returns its `wasm.GlobalType`. | 1465 | /// From a given symbol location, returns its `wasm.GlobalType`. |
| ... | @@ -1521,10 +1521,11 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !Sy | ... | @@ -1521,10 +1521,11 @@ pub fn getGlobalSymbol(wasm: *Wasm, name: []const u8, lib_name: ?[]const u8) !Sy |
| 1521 | /// Returns the given pointer address | 1521 | /// Returns the given pointer address |
| 1522 | pub fn getDeclVAddr( | 1522 | pub fn getDeclVAddr( |
| 1523 | wasm: *Wasm, | 1523 | wasm: *Wasm, |
| 1524 | pt: Zcu.PerThread, | ||
| 1524 | decl_index: InternPool.DeclIndex, | 1525 | decl_index: InternPool.DeclIndex, |
| 1525 | reloc_info: link.File.RelocInfo, | 1526 | reloc_info: link.File.RelocInfo, |
| 1526 | ) !u64 { | 1527 | ) !u64 { |
| 1527 | return wasm.zigObjectPtr().?.getDeclVAddr(wasm, decl_index, reloc_info); | 1528 | return wasm.zigObjectPtr().?.getDeclVAddr(wasm, pt, decl_index, reloc_info); |
| 1528 | } | 1529 | } |
| 1529 | 1530 | ||
| 1530 | pub fn lowerAnonDecl( | 1531 | pub fn lowerAnonDecl( |
| ... | @@ -4016,8 +4017,8 @@ pub fn getErrorTableSymbol(wasm_file: *Wasm, pt: Zcu.PerThread) !u32 { | ... | @@ -4016,8 +4017,8 @@ pub fn getErrorTableSymbol(wasm_file: *Wasm, pt: Zcu.PerThread) !u32 { |
| 4016 | /// For a given `InternPool.DeclIndex` returns its corresponding `Atom.Index`. | 4017 | /// For a given `InternPool.DeclIndex` returns its corresponding `Atom.Index`. |
| 4017 | /// When the index was not found, a new `Atom` will be created, and its index will be returned. | 4018 | /// When the index was not found, a new `Atom` will be created, and its index will be returned. |
| 4018 | /// The newly created Atom is empty with default fields as specified by `Atom.empty`. | 4019 | /// The newly created Atom is empty with default fields as specified by `Atom.empty`. |
| 4019 | pub fn getOrCreateAtomForDecl(wasm_file: *Wasm, decl_index: InternPool.DeclIndex) !Atom.Index { | 4020 | pub fn getOrCreateAtomForDecl(wasm_file: *Wasm, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !Atom.Index { |
| 4020 | return wasm_file.zigObjectPtr().?.getOrCreateAtomForDecl(wasm_file, decl_index); | 4021 | return wasm_file.zigObjectPtr().?.getOrCreateAtomForDecl(wasm_file, pt, decl_index); |
| 4021 | } | 4022 | } |
| 4022 | 4023 | ||
| 4023 | /// Verifies all resolved symbols and checks whether itself needs to be marked alive, | 4024 | /// Verifies all resolved symbols and checks whether itself needs to be marked alive, |
src/link/Wasm/ZigObject.zig+30-22| ... | @@ -253,7 +253,7 @@ pub fn updateDecl( | ... | @@ -253,7 +253,7 @@ pub fn updateDecl( |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | const gpa = wasm_file.base.comp.gpa; | 255 | const gpa = wasm_file.base.comp.gpa; |
| 256 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); | 256 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index); |
| 257 | const atom = wasm_file.getAtomPtr(atom_index); | 257 | const atom = wasm_file.getAtomPtr(atom_index); |
| 258 | atom.clear(); | 258 | atom.clear(); |
| 259 | 259 | ||
| ... | @@ -302,7 +302,7 @@ pub fn updateFunc( | ... | @@ -302,7 +302,7 @@ pub fn updateFunc( |
| 302 | const func = pt.zcu.funcInfo(func_index); | 302 | const func = pt.zcu.funcInfo(func_index); |
| 303 | const decl_index = func.owner_decl; | 303 | const decl_index = func.owner_decl; |
| 304 | const decl = pt.zcu.declPtr(decl_index); | 304 | const decl = pt.zcu.declPtr(decl_index); |
| 305 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); | 305 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index); |
| 306 | const atom = wasm_file.getAtomPtr(atom_index); | 306 | const atom = wasm_file.getAtomPtr(atom_index); |
| 307 | atom.clear(); | 307 | atom.clear(); |
| 308 | 308 | ||
| ... | @@ -346,7 +346,7 @@ fn finishUpdateDecl( | ... | @@ -346,7 +346,7 @@ fn finishUpdateDecl( |
| 346 | const atom_index = decl_info.atom; | 346 | const atom_index = decl_info.atom; |
| 347 | const atom = wasm_file.getAtomPtr(atom_index); | 347 | const atom = wasm_file.getAtomPtr(atom_index); |
| 348 | const sym = zig_object.symbol(atom.sym_index); | 348 | const sym = zig_object.symbol(atom.sym_index); |
| 349 | const full_name = try decl.fullyQualifiedName(zcu); | 349 | const full_name = try decl.fullyQualifiedName(pt); |
| 350 | sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(ip)); | 350 | sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(ip)); |
| 351 | try atom.code.appendSlice(gpa, code); | 351 | try atom.code.appendSlice(gpa, code); |
| 352 | atom.size = @intCast(code.len); | 352 | atom.size = @intCast(code.len); |
| ... | @@ -424,17 +424,21 @@ fn createDataSegment( | ... | @@ -424,17 +424,21 @@ fn createDataSegment( |
| 424 | /// For a given `InternPool.DeclIndex` returns its corresponding `Atom.Index`. | 424 | /// For a given `InternPool.DeclIndex` returns its corresponding `Atom.Index`. |
| 425 | /// When the index was not found, a new `Atom` will be created, and its index will be returned. | 425 | /// When the index was not found, a new `Atom` will be created, and its index will be returned. |
| 426 | /// The newly created Atom is empty with default fields as specified by `Atom.empty`. | 426 | /// The newly created Atom is empty with default fields as specified by `Atom.empty`. |
| 427 | pub fn getOrCreateAtomForDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_index: InternPool.DeclIndex) !Atom.Index { | 427 | pub fn getOrCreateAtomForDecl( |
| 428 | const gpa = wasm_file.base.comp.gpa; | 428 | zig_object: *ZigObject, |
| 429 | wasm_file: *Wasm, | ||
| 430 | pt: Zcu.PerThread, | ||
| 431 | decl_index: InternPool.DeclIndex, | ||
| 432 | ) !Atom.Index { | ||
| 433 | const gpa = pt.zcu.gpa; | ||
| 429 | const gop = try zig_object.decls_map.getOrPut(gpa, decl_index); | 434 | const gop = try zig_object.decls_map.getOrPut(gpa, decl_index); |
| 430 | if (!gop.found_existing) { | 435 | if (!gop.found_existing) { |
| 431 | const sym_index = try zig_object.allocateSymbol(gpa); | 436 | const sym_index = try zig_object.allocateSymbol(gpa); |
| 432 | gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) }; | 437 | gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) }; |
| 433 | const mod = wasm_file.base.comp.module.?; | 438 | const decl = pt.zcu.declPtr(decl_index); |
| 434 | const decl = mod.declPtr(decl_index); | 439 | const full_name = try decl.fullyQualifiedName(pt); |
| 435 | const full_name = try decl.fullyQualifiedName(mod); | ||
| 436 | const sym = zig_object.symbol(sym_index); | 440 | const sym = zig_object.symbol(sym_index); |
| 437 | sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&mod.intern_pool)); | 441 | sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&pt.zcu.intern_pool)); |
| 438 | } | 442 | } |
| 439 | return gop.value_ptr.atom; | 443 | return gop.value_ptr.atom; |
| 440 | } | 444 | } |
| ... | @@ -487,10 +491,10 @@ pub fn lowerUnnamedConst( | ... | @@ -487,10 +491,10 @@ pub fn lowerUnnamedConst( |
| 487 | std.debug.assert(val.typeOf(mod).zigTypeTag(mod) != .Fn); // cannot create local symbols for functions | 491 | std.debug.assert(val.typeOf(mod).zigTypeTag(mod) != .Fn); // cannot create local symbols for functions |
| 488 | const decl = mod.declPtr(decl_index); | 492 | const decl = mod.declPtr(decl_index); |
| 489 | 493 | ||
| 490 | const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); | 494 | const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index); |
| 491 | const parent_atom = wasm_file.getAtom(parent_atom_index); | 495 | const parent_atom = wasm_file.getAtom(parent_atom_index); |
| 492 | const local_index = parent_atom.locals.items.len; | 496 | const local_index = parent_atom.locals.items.len; |
| 493 | const fqn = try decl.fullyQualifiedName(mod); | 497 | const fqn = try decl.fullyQualifiedName(pt); |
| 494 | const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{}_{d}", .{ | 498 | const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{}_{d}", .{ |
| 495 | fqn.fmt(&mod.intern_pool), local_index, | 499 | fqn.fmt(&mod.intern_pool), local_index, |
| 496 | }); | 500 | }); |
| ... | @@ -775,22 +779,22 @@ pub fn getGlobalSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator, name: []c | ... | @@ -775,22 +779,22 @@ pub fn getGlobalSymbol(zig_object: *ZigObject, gpa: std.mem.Allocator, name: []c |
| 775 | pub fn getDeclVAddr( | 779 | pub fn getDeclVAddr( |
| 776 | zig_object: *ZigObject, | 780 | zig_object: *ZigObject, |
| 777 | wasm_file: *Wasm, | 781 | wasm_file: *Wasm, |
| 782 | pt: Zcu.PerThread, | ||
| 778 | decl_index: InternPool.DeclIndex, | 783 | decl_index: InternPool.DeclIndex, |
| 779 | reloc_info: link.File.RelocInfo, | 784 | reloc_info: link.File.RelocInfo, |
| 780 | ) !u64 { | 785 | ) !u64 { |
| 781 | const target = wasm_file.base.comp.root_mod.resolved_target.result; | 786 | const target = wasm_file.base.comp.root_mod.resolved_target.result; |
| 782 | const gpa = wasm_file.base.comp.gpa; | 787 | const gpa = pt.zcu.gpa; |
| 783 | const mod = wasm_file.base.comp.module.?; | 788 | const decl = pt.zcu.declPtr(decl_index); |
| 784 | const decl = mod.declPtr(decl_index); | ||
| 785 | 789 | ||
| 786 | const target_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); | 790 | const target_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index); |
| 787 | const target_symbol_index = @intFromEnum(wasm_file.getAtom(target_atom_index).sym_index); | 791 | const target_symbol_index = @intFromEnum(wasm_file.getAtom(target_atom_index).sym_index); |
| 788 | 792 | ||
| 789 | std.debug.assert(reloc_info.parent_atom_index != 0); | 793 | std.debug.assert(reloc_info.parent_atom_index != 0); |
| 790 | const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?; | 794 | const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?; |
| 791 | const atom = wasm_file.getAtomPtr(atom_index); | 795 | const atom = wasm_file.getAtomPtr(atom_index); |
| 792 | const is_wasm32 = target.cpu.arch == .wasm32; | 796 | const is_wasm32 = target.cpu.arch == .wasm32; |
| 793 | if (decl.typeOf(mod).zigTypeTag(mod) == .Fn) { | 797 | if (decl.typeOf(pt.zcu).zigTypeTag(pt.zcu) == .Fn) { |
| 794 | std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations | 798 | std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations |
| 795 | try atom.relocs.append(gpa, .{ | 799 | try atom.relocs.append(gpa, .{ |
| 796 | .index = target_symbol_index, | 800 | .index = target_symbol_index, |
| ... | @@ -890,7 +894,7 @@ pub fn updateExports( | ... | @@ -890,7 +894,7 @@ pub fn updateExports( |
| 890 | }, | 894 | }, |
| 891 | }; | 895 | }; |
| 892 | const decl = mod.declPtr(decl_index); | 896 | const decl = mod.declPtr(decl_index); |
| 893 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index); | 897 | const atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, pt, decl_index); |
| 894 | const decl_info = zig_object.decls_map.getPtr(decl_index).?; | 898 | const decl_info = zig_object.decls_map.getPtr(decl_index).?; |
| 895 | const atom = wasm_file.getAtom(atom_index); | 899 | const atom = wasm_file.getAtom(atom_index); |
| 896 | const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*; | 900 | const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*; |
| ... | @@ -1116,13 +1120,17 @@ pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm_file: *Wasm, inde | ... | @@ -1116,13 +1120,17 @@ pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm_file: *Wasm, inde |
| 1116 | return atom_index; | 1120 | return atom_index; |
| 1117 | } | 1121 | } |
| 1118 | 1122 | ||
| 1119 | pub fn updateDeclLineNumber(zig_object: *ZigObject, mod: *Zcu, decl_index: InternPool.DeclIndex) !void { | 1123 | pub fn updateDeclLineNumber( |
| 1124 | zig_object: *ZigObject, | ||
| 1125 | pt: Zcu.PerThread, | ||
| 1126 | decl_index: InternPool.DeclIndex, | ||
| 1127 | ) !void { | ||
| 1120 | if (zig_object.dwarf) |*dw| { | 1128 | if (zig_object.dwarf) |*dw| { |
| 1121 | const decl = mod.declPtr(decl_index); | 1129 | const decl = pt.zcu.declPtr(decl_index); |
| 1122 | const decl_name = try decl.fullyQualifiedName(mod); | 1130 | const decl_name = try decl.fullyQualifiedName(pt); |
| 1123 | 1131 | ||
| 1124 | log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl }); | 1132 | log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&pt.zcu.intern_pool), decl }); |
| 1125 | try dw.updateDeclLineNumber(mod, decl_index); | 1133 | try dw.updateDeclLineNumber(pt.zcu, decl_index); |
| 1126 | } | 1134 | } |
| 1127 | } | 1135 | } |
| 1128 | 1136 |
src/mutable_value.zig+1-1| ... | @@ -71,7 +71,7 @@ pub const MutableValue = union(enum) { | ... | @@ -71,7 +71,7 @@ pub const MutableValue = union(enum) { |
| 71 | } }), | 71 | } }), |
| 72 | .bytes => |b| try pt.intern(.{ .aggregate = .{ | 72 | .bytes => |b| try pt.intern(.{ .aggregate = .{ |
| 73 | .ty = b.ty, | 73 | .ty = b.ty, |
| 74 | .storage = .{ .bytes = try pt.zcu.intern_pool.getOrPutString(pt.zcu.gpa, b.data, .maybe_embedded_nulls) }, | 74 | .storage = .{ .bytes = try pt.zcu.intern_pool.getOrPutString(pt.zcu.gpa, pt.tid, b.data, .maybe_embedded_nulls) }, |
| 75 | } }), | 75 | } }), |
| 76 | .aggregate => |a| { | 76 | .aggregate => |a| { |
| 77 | const elems = try arena.alloc(InternPool.Index, a.elems.len); | 77 | const elems = try arena.alloc(InternPool.Index, a.elems.len); |