| author | |
| committer | |
| log | d3ca10d5d8bc92280a14f9e40dc41d6accc1b4c2 |
| tree | 20306667045b1136e12399d5fe13612925f0677c |
| parent | 3a4bb47fedbb890dc149622e31c75101b14c3b16 |
| signature |
Instead, `source`, `tree`, and `zir` should all be optional. This is
precisely what we're actually trying to model here; and `File` isn't
optimized for memory consumption or serializability anyway, so it's fine
to use a couple of extra bytes on actual optionals here.11 files changed, 191 insertions(+), 240 deletions(-)
src/Builtin.zig+9-13| ... | ... | @@ -264,14 +264,12 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void { |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | pub fn populateFile(comp: *Compilation, mod: *Module, file: *File) !void { |
| 267 | assert(file.source_loaded == true); | |
| 268 | ||
| 269 | 267 | if (mod.root.statFile(mod.root_src_path)) |stat| { |
| 270 | if (stat.size != file.source.len) { | |
| 268 | if (stat.size != file.source.?.len) { | |
| 271 | 269 | std.log.warn( |
| 272 | 270 | "the cached file '{}{s}' had the wrong size. Expected {d}, found {d}. " ++ |
| 273 | 271 | "Overwriting with correct file contents now", |
| 274 | .{ mod.root, mod.root_src_path, file.source.len, stat.size }, | |
| 272 | .{ mod.root, mod.root_src_path, file.source.?.len, stat.size }, | |
| 275 | 273 | ); |
| 276 | 274 | |
| 277 | 275 | try writeFile(file, mod); |
| ... | ... | @@ -296,15 +294,13 @@ pub fn populateFile(comp: *Compilation, mod: *Module, file: *File) !void { |
| 296 | 294 | |
| 297 | 295 | log.debug("parsing and generating '{s}'", .{mod.root_src_path}); |
| 298 | 296 | |
| 299 | file.tree = try std.zig.Ast.parse(comp.gpa, file.source, .zig); | |
| 300 | assert(file.tree.errors.len == 0); // builtin.zig must parse | |
| 301 | file.tree_loaded = true; | |
| 297 | file.tree = try std.zig.Ast.parse(comp.gpa, file.source.?, .zig); | |
| 298 | assert(file.tree.?.errors.len == 0); // builtin.zig must parse | |
| 302 | 299 | |
| 303 | file.zir = try AstGen.generate(comp.gpa, file.tree); | |
| 304 | assert(!file.zir.hasCompileErrors()); // builtin.zig must not have astgen errors | |
| 305 | file.zir_loaded = true; | |
| 300 | file.zir = try AstGen.generate(comp.gpa, file.tree.?); | |
| 301 | assert(!file.zir.?.hasCompileErrors()); // builtin.zig must not have astgen errors | |
| 306 | 302 | file.status = .success_zir; |
| 307 | // Note that whilst we set `zir_loaded` here, we populated `path_digest` | |
| 303 | // Note that whilst we set `zir` here, we populated `path_digest` | |
| 308 | 304 | // all the way back in `Package.Module.create`. |
| 309 | 305 | } |
| 310 | 306 | |
| ... | ... | @@ -312,7 +308,7 @@ fn writeFile(file: *File, mod: *Module) !void { |
| 312 | 308 | var buf: [std.fs.max_path_bytes]u8 = undefined; |
| 313 | 309 | var af = try mod.root.atomicFile(mod.root_src_path, .{ .make_path = true }, &buf); |
| 314 | 310 | defer af.deinit(); |
| 315 | try af.file.writeAll(file.source); | |
| 311 | try af.file.writeAll(file.source.?); | |
| 316 | 312 | af.finish() catch |err| switch (err) { |
| 317 | 313 | error.AccessDenied => switch (builtin.os.tag) { |
| 318 | 314 | .windows => { |
| ... | ... | @@ -326,7 +322,7 @@ fn writeFile(file: *File, mod: *Module) !void { |
| 326 | 322 | }; |
| 327 | 323 | |
| 328 | 324 | file.stat = .{ |
| 329 | .size = file.source.len, | |
| 325 | .size = file.source.?.len, | |
| 330 | 326 | .inode = 0, // dummy value |
| 331 | 327 | .mtime = 0, // dummy value |
| 332 | 328 | }; |
src/Compilation.zig+7-13| ... | ... | @@ -3211,7 +3211,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { |
| 3211 | 3211 | } else { |
| 3212 | 3212 | // Must be ZIR or Zoir errors. Note that this may include AST errors. |
| 3213 | 3213 | _ = try file.getTree(gpa); // Tree must be loaded. |
| 3214 | if (file.zir_loaded) { | |
| 3214 | if (file.zir != null) { | |
| 3215 | 3215 | try addZirErrorMessages(&bundle, file); |
| 3216 | 3216 | } else if (file.zoir != null) { |
| 3217 | 3217 | try addZoirErrorMessages(&bundle, file); |
| ... | ... | @@ -3623,22 +3623,17 @@ pub fn addModuleErrorMsg( |
| 3623 | 3623 | } |
| 3624 | 3624 | |
| 3625 | 3625 | pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Zcu.File) !void { |
| 3626 | assert(file.zir_loaded); | |
| 3627 | assert(file.tree_loaded); | |
| 3628 | assert(file.source_loaded); | |
| 3629 | 3626 | const gpa = eb.gpa; |
| 3630 | 3627 | const src_path = try file.fullPath(gpa); |
| 3631 | 3628 | defer gpa.free(src_path); |
| 3632 | return eb.addZirErrorMessages(file.zir, file.tree, file.source, src_path); | |
| 3629 | return eb.addZirErrorMessages(file.zir.?, file.tree.?, file.source.?, src_path); | |
| 3633 | 3630 | } |
| 3634 | 3631 | |
| 3635 | 3632 | pub fn addZoirErrorMessages(eb: *ErrorBundle.Wip, file: *Zcu.File) !void { |
| 3636 | assert(file.source_loaded); | |
| 3637 | assert(file.tree_loaded); | |
| 3638 | 3633 | const gpa = eb.gpa; |
| 3639 | 3634 | const src_path = try file.fullPath(gpa); |
| 3640 | 3635 | defer gpa.free(src_path); |
| 3641 | return eb.addZoirErrorMessages(file.zoir.?, file.tree, file.source, src_path); | |
| 3636 | return eb.addZoirErrorMessages(file.zoir.?, file.tree.?, file.source.?, src_path); | |
| 3642 | 3637 | } |
| 3643 | 3638 | |
| 3644 | 3639 | pub fn performAllTheWork( |
| ... | ... | @@ -4312,18 +4307,17 @@ fn workerAstGenFile( |
| 4312 | 4307 | // Pre-emptively look for `@import` paths and queue them up. |
| 4313 | 4308 | // If we experience an error preemptively fetching the |
| 4314 | 4309 | // file, just ignore it and let it happen again later during Sema. |
| 4315 | assert(file.zir_loaded); | |
| 4316 | const imports_index = file.zir.extra[@intFromEnum(Zir.ExtraIndex.imports)]; | |
| 4310 | const imports_index = file.zir.?.extra[@intFromEnum(Zir.ExtraIndex.imports)]; | |
| 4317 | 4311 | if (imports_index != 0) { |
| 4318 | const extra = file.zir.extraData(Zir.Inst.Imports, imports_index); | |
| 4312 | const extra = file.zir.?.extraData(Zir.Inst.Imports, imports_index); | |
| 4319 | 4313 | var import_i: u32 = 0; |
| 4320 | 4314 | var extra_index = extra.end; |
| 4321 | 4315 | |
| 4322 | 4316 | while (import_i < extra.data.imports_len) : (import_i += 1) { |
| 4323 | const item = file.zir.extraData(Zir.Inst.Imports.Item, extra_index); | |
| 4317 | const item = file.zir.?.extraData(Zir.Inst.Imports.Item, extra_index); | |
| 4324 | 4318 | extra_index = item.end; |
| 4325 | 4319 | |
| 4326 | const import_path = file.zir.nullTerminatedString(item.data.name); | |
| 4320 | const import_path = file.zir.?.nullTerminatedString(item.data.name); | |
| 4327 | 4321 | // `@import("builtin")` is handled specially. |
| 4328 | 4322 | if (mem.eql(u8, import_path, "builtin")) continue; |
| 4329 | 4323 |
src/Package/Module.zig+4-6| ... | ... | @@ -482,13 +482,11 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { |
| 482 | 482 | }; |
| 483 | 483 | new_file.* = .{ |
| 484 | 484 | .sub_file_path = "builtin.zig", |
| 485 | .source = generated_builtin_source, | |
| 486 | .source_loaded = true, | |
| 487 | .tree_loaded = false, | |
| 488 | .zir_loaded = false, | |
| 489 | 485 | .stat = undefined, |
| 490 | .tree = undefined, | |
| 491 | .zir = undefined, | |
| 486 | .source = generated_builtin_source, | |
| 487 | .tree = null, | |
| 488 | .zir = null, | |
| 489 | .zoir = null, | |
| 492 | 490 | .status = .never_loaded, |
| 493 | 491 | .prev_status = .never_loaded, |
| 494 | 492 | .mod = new, |
src/Sema.zig+6-7| ... | ... | @@ -7649,9 +7649,8 @@ fn analyzeCall( |
| 7649 | 7649 | const nav = ip.getNav(info.owner_nav); |
| 7650 | 7650 | const resolved_func_inst = info.zir_body_inst.resolveFull(ip) orelse return error.AnalysisFail; |
| 7651 | 7651 | const file = zcu.fileByIndex(resolved_func_inst.file); |
| 7652 | assert(file.zir_loaded); | |
| 7653 | const zir_info = file.zir.getFnInfo(resolved_func_inst.inst); | |
| 7654 | break :b .{ nav, file.zir, info.zir_body_inst, resolved_func_inst.inst, zir_info }; | |
| 7652 | const zir_info = file.zir.?.getFnInfo(resolved_func_inst.inst); | |
| 7653 | break :b .{ nav, file.zir.?, info.zir_body_inst, resolved_func_inst.inst, zir_info }; | |
| 7655 | 7654 | } else .{ undefined, undefined, undefined, undefined, undefined }; |
| 7656 | 7655 | |
| 7657 | 7656 | // This is the `inst_map` used when evaluating generic parameters and return types. |
| ... | ... | @@ -35328,7 +35327,7 @@ fn backingIntType( |
| 35328 | 35327 | break :blk accumulator; |
| 35329 | 35328 | }; |
| 35330 | 35329 | |
| 35331 | const zir = zcu.namespacePtr(struct_type.namespace).fileScope(zcu).zir; | |
| 35330 | const zir = zcu.namespacePtr(struct_type.namespace).fileScope(zcu).zir.?; | |
| 35332 | 35331 | const zir_index = struct_type.zir_index.resolve(ip) orelse return error.AnalysisFail; |
| 35333 | 35332 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; |
| 35334 | 35333 | assert(extended.opcode == .struct_decl); |
| ... | ... | @@ -35948,7 +35947,7 @@ fn structFields( |
| 35948 | 35947 | const gpa = zcu.gpa; |
| 35949 | 35948 | const ip = &zcu.intern_pool; |
| 35950 | 35949 | const namespace_index = struct_type.namespace; |
| 35951 | const zir = zcu.namespacePtr(namespace_index).fileScope(zcu).zir; | |
| 35950 | const zir = zcu.namespacePtr(namespace_index).fileScope(zcu).zir.?; | |
| 35952 | 35951 | const zir_index = struct_type.zir_index.resolve(ip) orelse return error.AnalysisFail; |
| 35953 | 35952 | |
| 35954 | 35953 | const fields_len, _, var extra_index = structZirInfo(zir, zir_index); |
| ... | ... | @@ -36149,7 +36148,7 @@ fn structFieldInits( |
| 36149 | 36148 | assert(!struct_type.haveFieldInits(ip)); |
| 36150 | 36149 | |
| 36151 | 36150 | const namespace_index = struct_type.namespace; |
| 36152 | const zir = zcu.namespacePtr(namespace_index).fileScope(zcu).zir; | |
| 36151 | const zir = zcu.namespacePtr(namespace_index).fileScope(zcu).zir.?; | |
| 36153 | 36152 | const zir_index = struct_type.zir_index.resolve(ip) orelse return error.AnalysisFail; |
| 36154 | 36153 | const fields_len, _, var extra_index = structZirInfo(zir, zir_index); |
| 36155 | 36154 | |
| ... | ... | @@ -36268,7 +36267,7 @@ fn unionFields( |
| 36268 | 36267 | const zcu = pt.zcu; |
| 36269 | 36268 | const gpa = zcu.gpa; |
| 36270 | 36269 | const ip = &zcu.intern_pool; |
| 36271 | const zir = zcu.namespacePtr(union_type.namespace).fileScope(zcu).zir; | |
| 36270 | const zir = zcu.namespacePtr(union_type.namespace).fileScope(zcu).zir.?; | |
| 36272 | 36271 | const zir_index = union_type.zir_index.resolve(ip) orelse return error.AnalysisFail; |
| 36273 | 36272 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; |
| 36274 | 36273 | assert(extended.opcode == .union_decl); |
src/Type.zig+3-4| ... | ... | @@ -3587,8 +3587,7 @@ pub fn typeDeclSrcLine(ty: Type, zcu: *Zcu) ?u32 { |
| 3587 | 3587 | }; |
| 3588 | 3588 | const info = tracked.resolveFull(&zcu.intern_pool) orelse return null; |
| 3589 | 3589 | const file = zcu.fileByIndex(info.file); |
| 3590 | assert(file.zir_loaded); | |
| 3591 | const zir = file.zir; | |
| 3590 | const zir = file.zir.?; | |
| 3592 | 3591 | const inst = zir.instructions.get(@intFromEnum(info.inst)); |
| 3593 | 3592 | return switch (inst.tag) { |
| 3594 | 3593 | .struct_init, .struct_init_ref => zir.extraData(Zir.Inst.StructInit, inst.data.pl_node.payload_index).data.abs_line, |
| ... | ... | @@ -3905,7 +3904,7 @@ fn resolveStructInner( |
| 3905 | 3904 | var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa); |
| 3906 | 3905 | defer comptime_err_ret_trace.deinit(); |
| 3907 | 3906 | |
| 3908 | const zir = zcu.namespacePtr(struct_obj.namespace).fileScope(zcu).zir; | |
| 3907 | const zir = zcu.namespacePtr(struct_obj.namespace).fileScope(zcu).zir.?; | |
| 3909 | 3908 | var sema: Sema = .{ |
| 3910 | 3909 | .pt = pt, |
| 3911 | 3910 | .gpa = gpa, |
| ... | ... | @@ -3959,7 +3958,7 @@ fn resolveUnionInner( |
| 3959 | 3958 | var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa); |
| 3960 | 3959 | defer comptime_err_ret_trace.deinit(); |
| 3961 | 3960 | |
| 3962 | const zir = zcu.namespacePtr(union_obj.namespace).fileScope(zcu).zir; | |
| 3961 | const zir = zcu.namespacePtr(union_obj.namespace).fileScope(zcu).zir.?; | |
| 3963 | 3962 | var sema: Sema = .{ |
| 3964 | 3963 | .pt = pt, |
| 3965 | 3964 | .gpa = gpa, |
src/Zcu.zig+39-46| ... | ... | @@ -660,22 +660,17 @@ pub const Namespace = struct { |
| 660 | 660 | pub const File = struct { |
| 661 | 661 | status: Status, |
| 662 | 662 | prev_status: Status, |
| 663 | source_loaded: bool, | |
| 664 | tree_loaded: bool, | |
| 665 | zir_loaded: bool, | |
| 666 | 663 | /// Relative to the owning package's root source directory. |
| 667 | 664 | /// Memory is stored in gpa, owned by File. |
| 668 | 665 | sub_file_path: []const u8, |
| 669 | /// Whether this is populated depends on `source_loaded`. | |
| 670 | source: [:0]const u8, | |
| 671 | 666 | /// Whether this is populated depends on `status`. |
| 672 | 667 | stat: Cache.File.Stat, |
| 673 | /// Whether this is populated or not depends on `tree_loaded`. | |
| 674 | tree: Ast, | |
| 675 | /// Whether this is populated or not depends on `zir_loaded`. | |
| 676 | zir: Zir, | |
| 677 | /// Cached Zoir, generated lazily. | |
| 678 | zoir: ?Zoir = null, | |
| 668 | ||
| 669 | source: ?[:0]const u8, | |
| 670 | tree: ?Ast, | |
| 671 | zir: ?Zir, | |
| 672 | zoir: ?Zoir, | |
| 673 | ||
| 679 | 674 | /// Module that this file is a part of, managed externally. |
| 680 | 675 | mod: *Package.Module, |
| 681 | 676 | /// Whether this file is a part of multiple packages. This is an error condition which will be reported after AstGen. |
| ... | ... | @@ -727,23 +722,23 @@ pub const File = struct { |
| 727 | 722 | } |
| 728 | 723 | |
| 729 | 724 | pub fn unloadTree(file: *File, gpa: Allocator) void { |
| 730 | if (file.tree_loaded) { | |
| 731 | file.tree_loaded = false; | |
| 732 | file.tree.deinit(gpa); | |
| 725 | if (file.tree) |*tree| { | |
| 726 | tree.deinit(gpa); | |
| 727 | file.tree = null; | |
| 733 | 728 | } |
| 734 | 729 | } |
| 735 | 730 | |
| 736 | 731 | pub fn unloadSource(file: *File, gpa: Allocator) void { |
| 737 | if (file.source_loaded) { | |
| 738 | file.source_loaded = false; | |
| 739 | gpa.free(file.source); | |
| 732 | if (file.source) |source| { | |
| 733 | gpa.free(source); | |
| 734 | file.source = null; | |
| 740 | 735 | } |
| 741 | 736 | } |
| 742 | 737 | |
| 743 | 738 | pub fn unloadZir(file: *File, gpa: Allocator) void { |
| 744 | if (file.zir_loaded) { | |
| 745 | file.zir_loaded = false; | |
| 746 | file.zir.deinit(gpa); | |
| 739 | if (file.zir) |*zir| { | |
| 740 | zir.deinit(gpa); | |
| 741 | file.zir = null; | |
| 747 | 742 | } |
| 748 | 743 | } |
| 749 | 744 | |
| ... | ... | @@ -753,8 +748,8 @@ pub const File = struct { |
| 753 | 748 | }; |
| 754 | 749 | |
| 755 | 750 | pub fn getSource(file: *File, gpa: Allocator) !Source { |
| 756 | if (file.source_loaded) return Source{ | |
| 757 | .bytes = file.source, | |
| 751 | if (file.source) |source| return .{ | |
| 752 | .bytes = source, | |
| 758 | 753 | .stat = file.stat, |
| 759 | 754 | }; |
| 760 | 755 | |
| ... | ... | @@ -769,7 +764,8 @@ pub const File = struct { |
| 769 | 764 | return error.FileTooBig; |
| 770 | 765 | |
| 771 | 766 | const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0); |
| 772 | defer if (!file.source_loaded) gpa.free(source); | |
| 767 | defer gpa.free(source); | |
| 768 | ||
| 773 | 769 | const amt = try f.readAll(source); |
| 774 | 770 | if (amt != stat.size) |
| 775 | 771 | return error.UnexpectedEndOfFile; |
| ... | ... | @@ -778,9 +774,9 @@ pub const File = struct { |
| 778 | 774 | // used for error reporting. We need to keep the stat fields stale so that |
| 779 | 775 | // astGenFile can know to regenerate ZIR. |
| 780 | 776 | |
| 777 | errdefer comptime unreachable; // don't error after populating `source` | |
| 781 | 778 | file.source = source; |
| 782 | file.source_loaded = true; | |
| 783 | return Source{ | |
| 779 | return .{ | |
| 784 | 780 | .bytes = source, |
| 785 | 781 | .stat = .{ |
| 786 | 782 | .size = stat.size, |
| ... | ... | @@ -791,20 +787,20 @@ pub const File = struct { |
| 791 | 787 | } |
| 792 | 788 | |
| 793 | 789 | pub fn getTree(file: *File, gpa: Allocator) !*const Ast { |
| 794 | if (file.tree_loaded) return &file.tree; | |
| 790 | if (file.tree) |*tree| return tree; | |
| 795 | 791 | |
| 796 | 792 | const source = try file.getSource(gpa); |
| 797 | file.tree = try Ast.parse(gpa, source.bytes, file.getMode()); | |
| 798 | file.tree_loaded = true; | |
| 799 | return &file.tree; | |
| 793 | file.tree = try .parse(gpa, source.bytes, file.getMode()); | |
| 794 | return &file.tree.?; | |
| 800 | 795 | } |
| 801 | 796 | |
| 802 | 797 | pub fn getZoir(file: *File, zcu: *Zcu) !*const Zoir { |
| 803 | 798 | if (file.zoir) |*zoir| return zoir; |
| 804 | 799 | |
| 805 | assert(file.tree_loaded); | |
| 806 | assert(file.tree.mode == .zon); | |
| 807 | file.zoir = try ZonGen.generate(zcu.gpa, file.tree, .{}); | |
| 800 | const tree = file.tree.?; | |
| 801 | assert(tree.mode == .zon); | |
| 802 | ||
| 803 | file.zoir = try ZonGen.generate(zcu.gpa, tree, .{}); | |
| 808 | 804 | if (file.zoir.?.hasCompileErrors()) { |
| 809 | 805 | try zcu.failed_files.putNoClobber(zcu.gpa, file, null); |
| 810 | 806 | return error.AnalysisFail; |
| ... | ... | @@ -900,18 +896,18 @@ pub const File = struct { |
| 900 | 896 | |
| 901 | 897 | // We can only mark children as failed if the ZIR is loaded, which may not |
| 902 | 898 | // be the case if there were other astgen failures in this file |
| 903 | if (!file.zir_loaded) return; | |
| 899 | if (file.zir == null) return; | |
| 904 | 900 | |
| 905 | const imports_index = file.zir.extra[@intFromEnum(Zir.ExtraIndex.imports)]; | |
| 901 | const imports_index = file.zir.?.extra[@intFromEnum(Zir.ExtraIndex.imports)]; | |
| 906 | 902 | if (imports_index == 0) return; |
| 907 | const extra = file.zir.extraData(Zir.Inst.Imports, imports_index); | |
| 903 | const extra = file.zir.?.extraData(Zir.Inst.Imports, imports_index); | |
| 908 | 904 | |
| 909 | 905 | var extra_index = extra.end; |
| 910 | 906 | for (0..extra.data.imports_len) |_| { |
| 911 | const item = file.zir.extraData(Zir.Inst.Imports.Item, extra_index); | |
| 907 | const item = file.zir.?.extraData(Zir.Inst.Imports.Item, extra_index); | |
| 912 | 908 | extra_index = item.end; |
| 913 | 909 | |
| 914 | const import_path = file.zir.nullTerminatedString(item.data.name); | |
| 910 | const import_path = file.zir.?.nullTerminatedString(item.data.name); | |
| 915 | 911 | if (mem.eql(u8, import_path, "builtin")) continue; |
| 916 | 912 | |
| 917 | 913 | const res = pt.importFile(file, import_path) catch continue; |
| ... | ... | @@ -1012,7 +1008,7 @@ pub const SrcLoc = struct { |
| 1012 | 1008 | lazy: LazySrcLoc.Offset, |
| 1013 | 1009 | |
| 1014 | 1010 | pub fn baseSrcToken(src_loc: SrcLoc) Ast.TokenIndex { |
| 1015 | const tree = src_loc.file_scope.tree; | |
| 1011 | const tree = src_loc.file_scope.tree.?; | |
| 1016 | 1012 | return tree.firstToken(src_loc.base_node); |
| 1017 | 1013 | } |
| 1018 | 1014 | |
| ... | ... | @@ -1057,7 +1053,6 @@ pub const SrcLoc = struct { |
| 1057 | 1053 | const node_off = traced_off.x; |
| 1058 | 1054 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1059 | 1055 | const node = src_loc.relativeToNodeIndex(node_off); |
| 1060 | assert(src_loc.file_scope.tree_loaded); | |
| 1061 | 1056 | return tree.nodeToSpan(node); |
| 1062 | 1057 | }, |
| 1063 | 1058 | .node_offset_main_token => |node_off| { |
| ... | ... | @@ -1069,7 +1064,6 @@ pub const SrcLoc = struct { |
| 1069 | 1064 | .node_offset_bin_op => |node_off| { |
| 1070 | 1065 | const tree = try src_loc.file_scope.getTree(gpa); |
| 1071 | 1066 | const node = src_loc.relativeToNodeIndex(node_off); |
| 1072 | assert(src_loc.file_scope.tree_loaded); | |
| 1073 | 1067 | return tree.nodeToSpan(node); |
| 1074 | 1068 | }, |
| 1075 | 1069 | .node_offset_initializer => |node_off| { |
| ... | ... | @@ -2408,9 +2402,8 @@ pub const LazySrcLoc = struct { |
| 2408 | 2402 | if (zir_inst == .main_struct_inst) return .{ file, 0 }; |
| 2409 | 2403 | |
| 2410 | 2404 | // Otherwise, make sure ZIR is loaded. |
| 2411 | assert(file.zir_loaded); | |
| 2405 | const zir = file.zir.?; | |
| 2412 | 2406 | |
| 2413 | const zir = file.zir; | |
| 2414 | 2407 | const inst = zir.instructions.get(@intFromEnum(zir_inst)); |
| 2415 | 2408 | const base_node: Ast.Node.Index = switch (inst.tag) { |
| 2416 | 2409 | .declaration => inst.data.declaration.src_node, |
| ... | ... | @@ -3671,7 +3664,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv |
| 3671 | 3664 | const inst_info = nav.analysis.?.zir_index.resolveFull(ip) orelse continue; |
| 3672 | 3665 | const file = zcu.fileByIndex(inst_info.file); |
| 3673 | 3666 | // If the file failed AstGen, the TrackedInst refers to the old ZIR. |
| 3674 | const zir = if (file.status == .success_zir) file.zir else file.prev_zir.?.*; | |
| 3667 | const zir = if (file.status == .success_zir) file.zir.? else file.prev_zir.?.*; | |
| 3675 | 3668 | const decl = zir.getDeclaration(inst_info.inst); |
| 3676 | 3669 | |
| 3677 | 3670 | if (!comp.config.is_test or file.mod != zcu.main_mod) continue; |
| ... | ... | @@ -3703,7 +3696,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv |
| 3703 | 3696 | const inst_info = ip.getNav(nav).analysis.?.zir_index.resolveFull(ip) orelse continue; |
| 3704 | 3697 | const file = zcu.fileByIndex(inst_info.file); |
| 3705 | 3698 | // If the file failed AstGen, the TrackedInst refers to the old ZIR. |
| 3706 | const zir = if (file.status == .success_zir) file.zir else file.prev_zir.?.*; | |
| 3699 | const zir = if (file.status == .success_zir) file.zir.? else file.prev_zir.?.*; | |
| 3707 | 3700 | const decl = zir.getDeclaration(inst_info.inst); |
| 3708 | 3701 | if (decl.linkage == .@"export") { |
| 3709 | 3702 | const unit: AnalUnit = .wrap(.{ .nav_val = nav }); |
| ... | ... | @@ -3721,7 +3714,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv |
| 3721 | 3714 | const inst_info = ip.getNav(nav).analysis.?.zir_index.resolveFull(ip) orelse continue; |
| 3722 | 3715 | const file = zcu.fileByIndex(inst_info.file); |
| 3723 | 3716 | // If the file failed AstGen, the TrackedInst refers to the old ZIR. |
| 3724 | const zir = if (file.status == .success_zir) file.zir else file.prev_zir.?.*; | |
| 3717 | const zir = if (file.status == .success_zir) file.zir.? else file.prev_zir.?.*; | |
| 3725 | 3718 | const decl = zir.getDeclaration(inst_info.inst); |
| 3726 | 3719 | if (decl.linkage == .@"export") { |
| 3727 | 3720 | const unit: AnalUnit = .wrap(.{ .nav_val = nav }); |
| ... | ... | @@ -3858,7 +3851,7 @@ pub fn navSrcLine(zcu: *Zcu, nav_index: InternPool.Nav.Index) u32 { |
| 3858 | 3851 | const ip = &zcu.intern_pool; |
| 3859 | 3852 | const inst_info = ip.getNav(nav_index).srcInst(ip).resolveFull(ip).?; |
| 3860 | 3853 | const zir = zcu.fileByIndex(inst_info.file).zir; |
| 3861 | return zir.getDeclaration(inst_info.inst).src_line; | |
| 3854 | return zir.?.getDeclaration(inst_info.inst).src_line; | |
| 3862 | 3855 | } |
| 3863 | 3856 | |
| 3864 | 3857 | pub fn navValue(zcu: *const Zcu, nav_index: InternPool.Nav.Index) Value { |
src/Zcu/PerThread.zig+56-63| ... | ... | @@ -209,7 +209,6 @@ pub fn astGenFile( |
| 209 | 209 | }, |
| 210 | 210 | else => |e| return e, |
| 211 | 211 | }; |
| 212 | file.zir_loaded = true; | |
| 213 | 212 | file.stat = .{ |
| 214 | 213 | .size = header.stat_size, |
| 215 | 214 | .inode = header.stat_inode, |
| ... | ... | @@ -219,12 +218,12 @@ pub fn astGenFile( |
| 219 | 218 | file.status = .success_zir; |
| 220 | 219 | log.debug("AstGen cached success: {s}", .{file.sub_file_path}); |
| 221 | 220 | |
| 222 | if (file.zir.hasCompileErrors()) { | |
| 221 | if (file.zir.?.hasCompileErrors()) { | |
| 223 | 222 | comp.mutex.lock(); |
| 224 | 223 | defer comp.mutex.unlock(); |
| 225 | 224 | try zcu.failed_files.putNoClobber(gpa, file, null); |
| 226 | 225 | } |
| 227 | if (file.zir.loweringFailed()) { | |
| 226 | if (file.zir.?.loweringFailed()) { | |
| 228 | 227 | file.status = .astgen_failure; |
| 229 | 228 | return error.AnalysisFail; |
| 230 | 229 | } |
| ... | ... | @@ -261,13 +260,12 @@ pub fn astGenFile( |
| 261 | 260 | // single-threaded context, so we need to keep both versions around |
| 262 | 261 | // until that point in the pipeline. Previous ZIR data is freed after |
| 263 | 262 | // that. |
| 264 | if (file.zir_loaded and !file.zir.loweringFailed()) { | |
| 263 | if (file.zir != null and !file.zir.?.loweringFailed()) { | |
| 265 | 264 | assert(file.prev_zir == null); |
| 266 | 265 | const prev_zir_ptr = try gpa.create(Zir); |
| 267 | 266 | file.prev_zir = prev_zir_ptr; |
| 268 | prev_zir_ptr.* = file.zir; | |
| 269 | file.zir = undefined; | |
| 270 | file.zir_loaded = false; | |
| 267 | prev_zir_ptr.* = file.zir.?; | |
| 268 | file.zir = null; | |
| 271 | 269 | } |
| 272 | 270 | file.unload(gpa); |
| 273 | 271 | |
| ... | ... | @@ -275,7 +273,7 @@ pub fn astGenFile( |
| 275 | 273 | return error.FileTooBig; |
| 276 | 274 | |
| 277 | 275 | const source = try gpa.allocSentinel(u8, @as(usize, @intCast(stat.size)), 0); |
| 278 | defer if (!file.source_loaded) gpa.free(source); | |
| 276 | defer if (file.source == null) gpa.free(source); | |
| 279 | 277 | const amt = try source_file.readAll(source); |
| 280 | 278 | if (amt != stat.size) |
| 281 | 279 | return error.UnexpectedEndOfFile; |
| ... | ... | @@ -286,42 +284,39 @@ pub fn astGenFile( |
| 286 | 284 | .mtime = stat.mtime, |
| 287 | 285 | }; |
| 288 | 286 | file.source = source; |
| 289 | file.source_loaded = true; | |
| 290 | 287 | |
| 291 | 288 | file.tree = try Ast.parse(gpa, source, .zig); |
| 292 | file.tree_loaded = true; | |
| 293 | 289 | |
| 294 | 290 | // Any potential AST errors are converted to ZIR errors here. |
| 295 | file.zir = try AstGen.generate(gpa, file.tree); | |
| 296 | file.zir_loaded = true; | |
| 291 | file.zir = try AstGen.generate(gpa, file.tree.?); | |
| 297 | 292 | file.prev_status = file.status; |
| 298 | 293 | file.status = .success_zir; |
| 299 | 294 | log.debug("AstGen fresh success: {s}", .{file.sub_file_path}); |
| 300 | 295 | |
| 301 | 296 | const safety_buffer = if (Zcu.data_has_safety_tag) |
| 302 | try gpa.alloc([8]u8, file.zir.instructions.len) | |
| 297 | try gpa.alloc([8]u8, file.zir.?.instructions.len) | |
| 303 | 298 | else |
| 304 | 299 | undefined; |
| 305 | 300 | defer if (Zcu.data_has_safety_tag) gpa.free(safety_buffer); |
| 306 | 301 | const data_ptr = if (Zcu.data_has_safety_tag) |
| 307 | if (file.zir.instructions.len == 0) | |
| 302 | if (file.zir.?.instructions.len == 0) | |
| 308 | 303 | @as([*]const u8, undefined) |
| 309 | 304 | else |
| 310 | 305 | @as([*]const u8, @ptrCast(safety_buffer.ptr)) |
| 311 | 306 | else |
| 312 | @as([*]const u8, @ptrCast(file.zir.instructions.items(.data).ptr)); | |
| 307 | @as([*]const u8, @ptrCast(file.zir.?.instructions.items(.data).ptr)); | |
| 313 | 308 | if (Zcu.data_has_safety_tag) { |
| 314 | 309 | // The `Data` union has a safety tag but in the file format we store it without. |
| 315 | for (file.zir.instructions.items(.data), 0..) |*data, i| { | |
| 310 | for (file.zir.?.instructions.items(.data), 0..) |*data, i| { | |
| 316 | 311 | const as_struct: *const Zcu.HackDataLayout = @ptrCast(data); |
| 317 | 312 | safety_buffer[i] = as_struct.data; |
| 318 | 313 | } |
| 319 | 314 | } |
| 320 | 315 | |
| 321 | 316 | const header: Zir.Header = .{ |
| 322 | .instructions_len = @as(u32, @intCast(file.zir.instructions.len)), | |
| 323 | .string_bytes_len = @as(u32, @intCast(file.zir.string_bytes.len)), | |
| 324 | .extra_len = @as(u32, @intCast(file.zir.extra.len)), | |
| 317 | .instructions_len = @as(u32, @intCast(file.zir.?.instructions.len)), | |
| 318 | .string_bytes_len = @as(u32, @intCast(file.zir.?.string_bytes.len)), | |
| 319 | .extra_len = @as(u32, @intCast(file.zir.?.extra.len)), | |
| 325 | 320 | |
| 326 | 321 | .stat_size = stat.size, |
| 327 | 322 | .stat_inode = stat.inode, |
| ... | ... | @@ -333,20 +328,20 @@ pub fn astGenFile( |
| 333 | 328 | .len = @sizeOf(Zir.Header), |
| 334 | 329 | }, |
| 335 | 330 | .{ |
| 336 | .base = @as([*]const u8, @ptrCast(file.zir.instructions.items(.tag).ptr)), | |
| 337 | .len = file.zir.instructions.len, | |
| 331 | .base = @as([*]const u8, @ptrCast(file.zir.?.instructions.items(.tag).ptr)), | |
| 332 | .len = file.zir.?.instructions.len, | |
| 338 | 333 | }, |
| 339 | 334 | .{ |
| 340 | 335 | .base = data_ptr, |
| 341 | .len = file.zir.instructions.len * 8, | |
| 336 | .len = file.zir.?.instructions.len * 8, | |
| 342 | 337 | }, |
| 343 | 338 | .{ |
| 344 | .base = file.zir.string_bytes.ptr, | |
| 345 | .len = file.zir.string_bytes.len, | |
| 339 | .base = file.zir.?.string_bytes.ptr, | |
| 340 | .len = file.zir.?.string_bytes.len, | |
| 346 | 341 | }, |
| 347 | 342 | .{ |
| 348 | .base = @as([*]const u8, @ptrCast(file.zir.extra.ptr)), | |
| 349 | .len = file.zir.extra.len * 4, | |
| 343 | .base = @as([*]const u8, @ptrCast(file.zir.?.extra.ptr)), | |
| 344 | .len = file.zir.?.extra.len * 4, | |
| 350 | 345 | }, |
| 351 | 346 | }; |
| 352 | 347 | cache_file.writevAll(&iovecs) catch |err| { |
| ... | ... | @@ -355,12 +350,12 @@ pub fn astGenFile( |
| 355 | 350 | }); |
| 356 | 351 | }; |
| 357 | 352 | |
| 358 | if (file.zir.hasCompileErrors()) { | |
| 353 | if (file.zir.?.hasCompileErrors()) { | |
| 359 | 354 | comp.mutex.lock(); |
| 360 | 355 | defer comp.mutex.unlock(); |
| 361 | 356 | try zcu.failed_files.putNoClobber(gpa, file, null); |
| 362 | 357 | } |
| 363 | if (file.zir.loweringFailed()) { | |
| 358 | if (file.zir.?.loweringFailed()) { | |
| 364 | 359 | file.status = .astgen_failure; |
| 365 | 360 | return error.AnalysisFail; |
| 366 | 361 | } |
| ... | ... | @@ -392,7 +387,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void { |
| 392 | 387 | try zcu.markDependeeOutdated(.not_marked_po, .{ .file = file_index }); |
| 393 | 388 | } |
| 394 | 389 | const old_zir = file.prev_zir orelse continue; |
| 395 | const new_zir = file.zir; | |
| 390 | const new_zir = file.zir.?; | |
| 396 | 391 | const gop = try updated_files.getOrPut(gpa, file_index); |
| 397 | 392 | assert(!gop.found_existing); |
| 398 | 393 | gop.value_ptr.* = .{ |
| ... | ... | @@ -400,7 +395,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void { |
| 400 | 395 | .inst_map = .{}, |
| 401 | 396 | }; |
| 402 | 397 | if (!new_zir.loweringFailed()) { |
| 403 | try Zcu.mapOldZirToNew(gpa, old_zir.*, file.zir, &gop.value_ptr.inst_map); | |
| 398 | try Zcu.mapOldZirToNew(gpa, old_zir.*, new_zir, &gop.value_ptr.inst_map); | |
| 404 | 399 | } |
| 405 | 400 | } |
| 406 | 401 | |
| ... | ... | @@ -426,7 +421,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void { |
| 426 | 421 | // Either way, invalidate associated `src_hash` deps. |
| 427 | 422 | log.debug("tracking failed for %{d}{s}", .{ |
| 428 | 423 | old_inst, |
| 429 | if (file.zir.loweringFailed()) " due to AstGen failure" else "", | |
| 424 | if (file.zir.?.loweringFailed()) " due to AstGen failure" else "", | |
| 430 | 425 | }); |
| 431 | 426 | tracked_inst.inst = .lost; |
| 432 | 427 | try zcu.markDependeeOutdated(.not_marked_po, .{ .src_hash = tracked_inst_index }); |
| ... | ... | @@ -435,7 +430,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void { |
| 435 | 430 | tracked_inst.inst = InternPool.TrackedInst.MaybeLost.ZirIndex.wrap(new_inst); |
| 436 | 431 | |
| 437 | 432 | const old_zir = file.prev_zir.?.*; |
| 438 | const new_zir = file.zir; | |
| 433 | const new_zir = file.zir.?; | |
| 439 | 434 | const old_tag = old_zir.instructions.items(.tag)[@intFromEnum(old_inst)]; |
| 440 | 435 | const old_data = old_zir.instructions.items(.data)[@intFromEnum(old_inst)]; |
| 441 | 436 | |
| ... | ... | @@ -532,7 +527,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void { |
| 532 | 527 | |
| 533 | 528 | for (updated_files.keys(), updated_files.values()) |file_index, updated_file| { |
| 534 | 529 | const file = updated_file.file; |
| 535 | if (file.zir.loweringFailed()) { | |
| 530 | if (file.zir.?.loweringFailed()) { | |
| 536 | 531 | // Keep `prev_zir` around: it's the last usable ZIR. |
| 537 | 532 | // Don't update the namespace, as we have no new data to update *to*. |
| 538 | 533 | } else { |
| ... | ... | @@ -805,7 +800,7 @@ fn analyzeComptimeUnit(pt: Zcu.PerThread, cu_id: InternPool.ComptimeUnit.Id) Zcu |
| 805 | 800 | // unnecessary, and we can move the below `removeDependenciesForDepender` call up with its friends |
| 806 | 801 | // in `ensureComptimeUnitUpToDate`. |
| 807 | 802 | if (file.status != .success_zir) return error.AnalysisFail; |
| 808 | const zir = file.zir; | |
| 803 | const zir = file.zir.?; | |
| 809 | 804 | |
| 810 | 805 | // We are about to re-analyze this unit; drop its depenndencies. |
| 811 | 806 | zcu.intern_pool.removeDependenciesForDepender(gpa, anal_unit); |
| ... | ... | @@ -1002,7 +997,7 @@ fn analyzeNavVal(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileErr |
| 1002 | 997 | // unnecessary, and we can move the below `removeDependenciesForDepender` call up with its friends |
| 1003 | 998 | // in `ensureComptimeUnitUpToDate`. |
| 1004 | 999 | if (file.status != .success_zir) return error.AnalysisFail; |
| 1005 | const zir = file.zir; | |
| 1000 | const zir = file.zir.?; | |
| 1006 | 1001 | |
| 1007 | 1002 | // We are about to re-analyze this unit; drop its depenndencies. |
| 1008 | 1003 | zcu.intern_pool.removeDependenciesForDepender(gpa, anal_unit); |
| ... | ... | @@ -1380,7 +1375,7 @@ fn analyzeNavType(pt: Zcu.PerThread, nav_id: InternPool.Nav.Index) Zcu.CompileEr |
| 1380 | 1375 | // unnecessary, and we can move the below `removeDependenciesForDepender` call up with its friends |
| 1381 | 1376 | // in `ensureComptimeUnitUpToDate`. |
| 1382 | 1377 | if (file.status != .success_zir) return error.AnalysisFail; |
| 1383 | const zir = file.zir; | |
| 1378 | const zir = file.zir.?; | |
| 1384 | 1379 | |
| 1385 | 1380 | // We are about to re-analyze this unit; drop its depenndencies. |
| 1386 | 1381 | zcu.intern_pool.removeDependenciesForDepender(gpa, anal_unit); |
| ... | ... | @@ -1758,7 +1753,7 @@ fn createFileRootStruct( |
| 1758 | 1753 | const gpa = zcu.gpa; |
| 1759 | 1754 | const ip = &zcu.intern_pool; |
| 1760 | 1755 | const file = zcu.fileByIndex(file_index); |
| 1761 | const extended = file.zir.instructions.items(.data)[@intFromEnum(Zir.Inst.Index.main_struct_inst)].extended; | |
| 1756 | const extended = file.zir.?.instructions.items(.data)[@intFromEnum(Zir.Inst.Index.main_struct_inst)].extended; | |
| 1762 | 1757 | assert(extended.opcode == .struct_decl); |
| 1763 | 1758 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 1764 | 1759 | assert(!small.has_captures_len); |
| ... | ... | @@ -1766,16 +1761,16 @@ fn createFileRootStruct( |
| 1766 | 1761 | assert(small.layout == .auto); |
| 1767 | 1762 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).@"struct".fields.len; |
| 1768 | 1763 | const fields_len = if (small.has_fields_len) blk: { |
| 1769 | const fields_len = file.zir.extra[extra_index]; | |
| 1764 | const fields_len = file.zir.?.extra[extra_index]; | |
| 1770 | 1765 | extra_index += 1; |
| 1771 | 1766 | break :blk fields_len; |
| 1772 | 1767 | } else 0; |
| 1773 | 1768 | const decls_len = if (small.has_decls_len) blk: { |
| 1774 | const decls_len = file.zir.extra[extra_index]; | |
| 1769 | const decls_len = file.zir.?.extra[extra_index]; | |
| 1775 | 1770 | extra_index += 1; |
| 1776 | 1771 | break :blk decls_len; |
| 1777 | 1772 | } else 0; |
| 1778 | const decls = file.zir.bodySlice(extra_index, decls_len); | |
| 1773 | const decls = file.zir.?.bodySlice(extra_index, decls_len); | |
| 1779 | 1774 | extra_index += decls_len; |
| 1780 | 1775 | |
| 1781 | 1776 | const tracked_inst = try ip.trackZir(gpa, pt.tid, .{ |
| ... | ... | @@ -1844,17 +1839,17 @@ fn updateFileNamespace(pt: Zcu.PerThread, file_index: Zcu.File.Index) Allocator. |
| 1844 | 1839 | |
| 1845 | 1840 | const namespace_index = Type.fromInterned(file_root_type).getNamespaceIndex(zcu); |
| 1846 | 1841 | const decls = decls: { |
| 1847 | const extended = file.zir.instructions.items(.data)[@intFromEnum(Zir.Inst.Index.main_struct_inst)].extended; | |
| 1842 | const extended = file.zir.?.instructions.items(.data)[@intFromEnum(Zir.Inst.Index.main_struct_inst)].extended; | |
| 1848 | 1843 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 1849 | 1844 | |
| 1850 | 1845 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).@"struct".fields.len; |
| 1851 | 1846 | extra_index += @intFromBool(small.has_fields_len); |
| 1852 | 1847 | const decls_len = if (small.has_decls_len) blk: { |
| 1853 | const decls_len = file.zir.extra[extra_index]; | |
| 1848 | const decls_len = file.zir.?.extra[extra_index]; | |
| 1854 | 1849 | extra_index += 1; |
| 1855 | 1850 | break :blk decls_len; |
| 1856 | 1851 | } else 0; |
| 1857 | break :decls file.zir.bodySlice(extra_index, decls_len); | |
| 1852 | break :decls file.zir.?.bodySlice(extra_index, decls_len); | |
| 1858 | 1853 | }; |
| 1859 | 1854 | try pt.scanNamespace(namespace_index, decls); |
| 1860 | 1855 | zcu.namespacePtr(namespace_index).generation = zcu.generation; |
| ... | ... | @@ -1873,7 +1868,7 @@ fn semaFile(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.SemaError!void { |
| 1873 | 1868 | if (file.status != .success_zir) { |
| 1874 | 1869 | return error.AnalysisFail; |
| 1875 | 1870 | } |
| 1876 | assert(file.zir_loaded); | |
| 1871 | assert(file.zir != null); | |
| 1877 | 1872 | |
| 1878 | 1873 | const new_namespace_index = try pt.createNamespace(.{ |
| 1879 | 1874 | .parent = .none, |
| ... | ... | @@ -1983,13 +1978,11 @@ pub fn importPkg(pt: Zcu.PerThread, mod: *Module) !Zcu.ImportFileResult { |
| 1983 | 1978 | gop.value_ptr.* = new_file_index; |
| 1984 | 1979 | new_file.* = .{ |
| 1985 | 1980 | .sub_file_path = sub_file_path, |
| 1986 | .source = undefined, | |
| 1987 | .source_loaded = false, | |
| 1988 | .tree_loaded = false, | |
| 1989 | .zir_loaded = false, | |
| 1990 | 1981 | .stat = undefined, |
| 1991 | .tree = undefined, | |
| 1992 | .zir = undefined, | |
| 1982 | .source = null, | |
| 1983 | .tree = null, | |
| 1984 | .zir = null, | |
| 1985 | .zoir = null, | |
| 1993 | 1986 | .status = .never_loaded, |
| 1994 | 1987 | .prev_status = .never_loaded, |
| 1995 | 1988 | .mod = mod, |
| ... | ... | @@ -2096,13 +2089,11 @@ pub fn importFile( |
| 2096 | 2089 | gop.value_ptr.* = new_file_index; |
| 2097 | 2090 | new_file.* = .{ |
| 2098 | 2091 | .sub_file_path = sub_file_path, |
| 2099 | .source = undefined, | |
| 2100 | .source_loaded = false, | |
| 2101 | .tree_loaded = false, | |
| 2102 | .zir_loaded = false, | |
| 2103 | 2092 | .stat = undefined, |
| 2104 | .tree = undefined, | |
| 2105 | .zir = undefined, | |
| 2093 | .source = null, | |
| 2094 | .tree = null, | |
| 2095 | .zir = null, | |
| 2096 | .zoir = null, | |
| 2106 | 2097 | .status = .never_loaded, |
| 2107 | 2098 | .prev_status = .never_loaded, |
| 2108 | 2099 | .mod = mod, |
| ... | ... | @@ -2441,7 +2432,7 @@ const ScanDeclIter = struct { |
| 2441 | 2432 | const namespace = zcu.namespacePtr(namespace_index); |
| 2442 | 2433 | const gpa = zcu.gpa; |
| 2443 | 2434 | const file = namespace.fileScope(zcu); |
| 2444 | const zir = file.zir; | |
| 2435 | const zir = file.zir.?; | |
| 2445 | 2436 | const ip = &zcu.intern_pool; |
| 2446 | 2437 | |
| 2447 | 2438 | const decl = zir.getDeclaration(decl_inst); |
| ... | ... | @@ -2591,7 +2582,7 @@ fn analyzeFnBodyInner(pt: Zcu.PerThread, func_index: InternPool.Index) Zcu.SemaE |
| 2591 | 2582 | const func = zcu.funcInfo(func_index); |
| 2592 | 2583 | const inst_info = func.zir_body_inst.resolveFull(ip) orelse return error.AnalysisFail; |
| 2593 | 2584 | const file = zcu.fileByIndex(inst_info.file); |
| 2594 | const zir = file.zir; | |
| 2585 | const zir = file.zir.?; | |
| 2595 | 2586 | |
| 2596 | 2587 | try zcu.analysis_in_progress.put(gpa, anal_unit, {}); |
| 2597 | 2588 | errdefer _ = zcu.analysis_in_progress.swapRemove(anal_unit); |
| ... | ... | @@ -2843,7 +2834,9 @@ pub fn getErrorValueFromSlice(pt: Zcu.PerThread, name: []const u8) Allocator.Err |
| 2843 | 2834 | /// Removes any entry from `Zcu.failed_files` associated with `file`. Acquires `Compilation.mutex` as needed. |
| 2844 | 2835 | /// `file.zir` must be unchanged from the last update, as it is used to determine if there is such an entry. |
| 2845 | 2836 | fn lockAndClearFileCompileError(pt: Zcu.PerThread, file: *Zcu.File) void { |
| 2846 | if (!file.zir_loaded or !file.zir.hasCompileErrors()) return; | |
| 2837 | const zir = file.zir orelse return; | |
| 2838 | if (zir.hasCompileErrors()) return; | |
| 2839 | ||
| 2847 | 2840 | pt.zcu.comp.mutex.lock(); |
| 2848 | 2841 | defer pt.zcu.comp.mutex.unlock(); |
| 2849 | 2842 | if (pt.zcu.failed_files.fetchSwapRemove(file)) |kv| { |
| ... | ... | @@ -3779,7 +3772,7 @@ fn recreateStructType( |
| 3779 | 3772 | const inst_info = key.zir_index.resolveFull(ip).?; |
| 3780 | 3773 | const file = zcu.fileByIndex(inst_info.file); |
| 3781 | 3774 | assert(file.status == .success_zir); // otherwise inst tracking failed |
| 3782 | const zir = file.zir; | |
| 3775 | const zir = file.zir.?; | |
| 3783 | 3776 | |
| 3784 | 3777 | assert(zir.instructions.items(.tag)[@intFromEnum(inst_info.inst)] == .extended); |
| 3785 | 3778 | const extended = zir.instructions.items(.data)[@intFromEnum(inst_info.inst)].extended; |
| ... | ... | @@ -3852,7 +3845,7 @@ fn recreateUnionType( |
| 3852 | 3845 | const inst_info = key.zir_index.resolveFull(ip).?; |
| 3853 | 3846 | const file = zcu.fileByIndex(inst_info.file); |
| 3854 | 3847 | assert(file.status == .success_zir); // otherwise inst tracking failed |
| 3855 | const zir = file.zir; | |
| 3848 | const zir = file.zir.?; | |
| 3856 | 3849 | |
| 3857 | 3850 | assert(zir.instructions.items(.tag)[@intFromEnum(inst_info.inst)] == .extended); |
| 3858 | 3851 | const extended = zir.instructions.items(.data)[@intFromEnum(inst_info.inst)].extended; |
| ... | ... | @@ -3939,7 +3932,7 @@ fn recreateEnumType( |
| 3939 | 3932 | const inst_info = key.zir_index.resolveFull(ip).?; |
| 3940 | 3933 | const file = zcu.fileByIndex(inst_info.file); |
| 3941 | 3934 | assert(file.status == .success_zir); // otherwise inst tracking failed |
| 3942 | const zir = file.zir; | |
| 3935 | const zir = file.zir.?; | |
| 3943 | 3936 | |
| 3944 | 3937 | assert(zir.instructions.items(.tag)[@intFromEnum(inst_info.inst)] == .extended); |
| 3945 | 3938 | const extended = zir.instructions.items(.data)[@intFromEnum(inst_info.inst)].extended; |
| ... | ... | @@ -4083,7 +4076,7 @@ pub fn ensureNamespaceUpToDate(pt: Zcu.PerThread, namespace_index: Zcu.Namespace |
| 4083 | 4076 | const inst_info = key.zir_index.resolveFull(ip) orelse return error.AnalysisFail; |
| 4084 | 4077 | const file = zcu.fileByIndex(inst_info.file); |
| 4085 | 4078 | if (file.status != .success_zir) return error.AnalysisFail; |
| 4086 | const zir = file.zir; | |
| 4079 | const zir = file.zir.?; | |
| 4087 | 4080 | |
| 4088 | 4081 | assert(zir.instructions.items(.tag)[@intFromEnum(inst_info.inst)] == .extended); |
| 4089 | 4082 | const extended = zir.instructions.items(.data)[@intFromEnum(inst_info.inst)].extended; |
src/link.zig+1-2| ... | ... | @@ -750,8 +750,7 @@ pub const File = struct { |
| 750 | 750 | { |
| 751 | 751 | const ti = ti_id.resolveFull(&pt.zcu.intern_pool).?; |
| 752 | 752 | const file = pt.zcu.fileByIndex(ti.file); |
| 753 | assert(file.zir_loaded); | |
| 754 | const inst = file.zir.instructions.get(@intFromEnum(ti.inst)); | |
| 753 | const inst = file.zir.?.instructions.get(@intFromEnum(ti.inst)); | |
| 755 | 754 | assert(inst.tag == .declaration); |
| 756 | 755 | } |
| 757 | 756 |
src/link/Dwarf.zig+7-10| ... | ... | @@ -2358,8 +2358,7 @@ fn initWipNavInner( |
| 2358 | 2358 | const nav = ip.getNav(nav_index); |
| 2359 | 2359 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 2360 | 2360 | const file = zcu.fileByIndex(inst_info.file); |
| 2361 | assert(file.zir_loaded); | |
| 2362 | const decl = file.zir.getDeclaration(inst_info.inst); | |
| 2361 | const decl = file.zir.?.getDeclaration(inst_info.inst); | |
| 2363 | 2362 | log.debug("initWipNav({s}:{d}:{d} %{d} = {})", .{ |
| 2364 | 2363 | file.sub_file_path, |
| 2365 | 2364 | decl.src_line + 1, |
| ... | ... | @@ -2373,7 +2372,7 @@ fn initWipNavInner( |
| 2373 | 2372 | switch (nav_key) { |
| 2374 | 2373 | // Ignore @extern |
| 2375 | 2374 | .@"extern" => |@"extern"| if (decl.linkage != .@"extern" or |
| 2376 | !@"extern".name.eqlSlice(file.zir.nullTerminatedString(decl.name), ip)) return null, | |
| 2375 | !@"extern".name.eqlSlice(file.zir.?.nullTerminatedString(decl.name), ip)) return null, | |
| 2377 | 2376 | else => {}, |
| 2378 | 2377 | } |
| 2379 | 2378 | |
| ... | ... | @@ -2696,8 +2695,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo |
| 2696 | 2695 | const nav = ip.getNav(nav_index); |
| 2697 | 2696 | const inst_info = nav.srcInst(ip).resolveFull(ip).?; |
| 2698 | 2697 | const file = zcu.fileByIndex(inst_info.file); |
| 2699 | assert(file.zir_loaded); | |
| 2700 | const decl = file.zir.getDeclaration(inst_info.inst); | |
| 2698 | const decl = file.zir.?.getDeclaration(inst_info.inst); | |
| 2701 | 2699 | log.debug("updateComptimeNav({s}:{d}:{d} %{d} = {})", .{ |
| 2702 | 2700 | file.sub_file_path, |
| 2703 | 2701 | decl.src_line + 1, |
| ... | ... | @@ -4097,7 +4095,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP |
| 4097 | 4095 | // if a newly-tracked instruction can be a type's owner `zir_index`. |
| 4098 | 4096 | comptime assert(Zir.inst_tracking_version == 0); |
| 4099 | 4097 | |
| 4100 | const decl_inst = file.zir.instructions.get(@intFromEnum(inst_info.inst)); | |
| 4098 | const decl_inst = file.zir.?.instructions.get(@intFromEnum(inst_info.inst)); | |
| 4101 | 4099 | const name_strat: Zir.Inst.NameStrategy = switch (decl_inst.tag) { |
| 4102 | 4100 | .struct_init, .struct_init_ref, .struct_init_anon => .anon, |
| 4103 | 4101 | .extended => switch (decl_inst.data.extended.opcode) { |
| ... | ... | @@ -4301,14 +4299,13 @@ pub fn updateLineNumber(dwarf: *Dwarf, zcu: *Zcu, zir_index: InternPool.TrackedI |
| 4301 | 4299 | const inst_info = zir_index.resolveFull(ip).?; |
| 4302 | 4300 | assert(inst_info.inst != .main_struct_inst); |
| 4303 | 4301 | const file = zcu.fileByIndex(inst_info.file); |
| 4304 | assert(file.zir_loaded); | |
| 4305 | const decl = file.zir.getDeclaration(inst_info.inst); | |
| 4302 | const decl = file.zir.?.getDeclaration(inst_info.inst); | |
| 4306 | 4303 | log.debug("updateLineNumber({s}:{d}:{d} %{d} = {s})", .{ |
| 4307 | 4304 | file.sub_file_path, |
| 4308 | 4305 | decl.src_line + 1, |
| 4309 | 4306 | decl.src_column + 1, |
| 4310 | 4307 | @intFromEnum(inst_info.inst), |
| 4311 | file.zir.nullTerminatedString(decl.name), | |
| 4308 | file.zir.?.nullTerminatedString(decl.name), | |
| 4312 | 4309 | }); |
| 4313 | 4310 | |
| 4314 | 4311 | var line_buf: [4]u8 = undefined; |
| ... | ... | @@ -4661,7 +4658,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 4661 | 4658 | .target_unit = StringSection.unit, |
| 4662 | 4659 | .target_entry = (try dwarf.debug_line_str.addString( |
| 4663 | 4660 | dwarf, |
| 4664 | if (file.mod.builtin_file == file) file.source else "", | |
| 4661 | if (file.mod.builtin_file == file) file.source.? else "", | |
| 4665 | 4662 | )).toOptional(), |
| 4666 | 4663 | }); |
| 4667 | 4664 | header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes()); |
src/main.zig+49-63| ... | ... | @@ -3636,7 +3636,7 @@ fn buildOutputType( |
| 3636 | 3636 | |
| 3637 | 3637 | if (show_builtin) { |
| 3638 | 3638 | const builtin_mod = comp.root_mod.getBuiltinDependency(); |
| 3639 | const source = builtin_mod.builtin_file.?.source; | |
| 3639 | const source = builtin_mod.builtin_file.?.source.?; | |
| 3640 | 3640 | return std.io.getStdOut().writeAll(source); |
| 3641 | 3641 | } |
| 3642 | 3642 | switch (listen) { |
| ... | ... | @@ -6135,14 +6135,12 @@ fn cmdAstCheck( |
| 6135 | 6135 | var file: Zcu.File = .{ |
| 6136 | 6136 | .status = .never_loaded, |
| 6137 | 6137 | .prev_status = .never_loaded, |
| 6138 | .source_loaded = false, | |
| 6139 | .tree_loaded = false, | |
| 6140 | .zir_loaded = false, | |
| 6141 | 6138 | .sub_file_path = undefined, |
| 6142 | .source = undefined, | |
| 6143 | 6139 | .stat = undefined, |
| 6144 | .tree = undefined, | |
| 6145 | .zir = undefined, | |
| 6140 | .source = null, | |
| 6141 | .tree = null, | |
| 6142 | .zir = null, | |
| 6143 | .zoir = null, | |
| 6146 | 6144 | .mod = undefined, |
| 6147 | 6145 | }; |
| 6148 | 6146 | if (zig_source_file) |file_name| { |
| ... | ... | @@ -6163,7 +6161,6 @@ fn cmdAstCheck( |
| 6163 | 6161 | |
| 6164 | 6162 | file.sub_file_path = file_name; |
| 6165 | 6163 | file.source = source; |
| 6166 | file.source_loaded = true; | |
| 6167 | 6164 | file.stat = .{ |
| 6168 | 6165 | .size = stat.size, |
| 6169 | 6166 | .inode = stat.inode, |
| ... | ... | @@ -6176,7 +6173,6 @@ fn cmdAstCheck( |
| 6176 | 6173 | }; |
| 6177 | 6174 | file.sub_file_path = "<stdin>"; |
| 6178 | 6175 | file.source = source; |
| 6179 | file.source_loaded = true; | |
| 6180 | 6176 | file.stat.size = source.len; |
| 6181 | 6177 | } |
| 6182 | 6178 | |
| ... | ... | @@ -6196,17 +6192,15 @@ fn cmdAstCheck( |
| 6196 | 6192 | .fully_qualified_name = "root", |
| 6197 | 6193 | }); |
| 6198 | 6194 | |
| 6199 | file.tree = try Ast.parse(gpa, file.source, mode); | |
| 6200 | file.tree_loaded = true; | |
| 6201 | defer file.tree.deinit(gpa); | |
| 6195 | file.tree = try Ast.parse(gpa, file.source.?, mode); | |
| 6196 | defer file.tree.?.deinit(gpa); | |
| 6202 | 6197 | |
| 6203 | 6198 | switch (mode) { |
| 6204 | 6199 | .zig => { |
| 6205 | file.zir = try AstGen.generate(gpa, file.tree); | |
| 6206 | file.zir_loaded = true; | |
| 6207 | defer file.zir.deinit(gpa); | |
| 6200 | file.zir = try AstGen.generate(gpa, file.tree.?); | |
| 6201 | defer file.zir.?.deinit(gpa); | |
| 6208 | 6202 | |
| 6209 | if (file.zir.hasCompileErrors()) { | |
| 6203 | if (file.zir.?.hasCompileErrors()) { | |
| 6210 | 6204 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 6211 | 6205 | try wip_errors.init(gpa); |
| 6212 | 6206 | defer wip_errors.deinit(); |
| ... | ... | @@ -6215,13 +6209,13 @@ fn cmdAstCheck( |
| 6215 | 6209 | defer error_bundle.deinit(gpa); |
| 6216 | 6210 | error_bundle.renderToStdErr(color.renderOptions()); |
| 6217 | 6211 | |
| 6218 | if (file.zir.loweringFailed()) { | |
| 6212 | if (file.zir.?.loweringFailed()) { | |
| 6219 | 6213 | process.exit(1); |
| 6220 | 6214 | } |
| 6221 | 6215 | } |
| 6222 | 6216 | |
| 6223 | 6217 | if (!want_output_text) { |
| 6224 | if (file.zir.hasCompileErrors()) { | |
| 6218 | if (file.zir.?.hasCompileErrors()) { | |
| 6225 | 6219 | process.exit(1); |
| 6226 | 6220 | } else { |
| 6227 | 6221 | return cleanExit(); |
| ... | ... | @@ -6233,18 +6227,18 @@ fn cmdAstCheck( |
| 6233 | 6227 | |
| 6234 | 6228 | { |
| 6235 | 6229 | const token_bytes = @sizeOf(Ast.TokenList) + |
| 6236 | file.tree.tokens.len * (@sizeOf(std.zig.Token.Tag) + @sizeOf(Ast.ByteOffset)); | |
| 6237 | const tree_bytes = @sizeOf(Ast) + file.tree.nodes.len * | |
| 6230 | file.tree.?.tokens.len * (@sizeOf(std.zig.Token.Tag) + @sizeOf(Ast.ByteOffset)); | |
| 6231 | const tree_bytes = @sizeOf(Ast) + file.tree.?.nodes.len * | |
| 6238 | 6232 | (@sizeOf(Ast.Node.Tag) + |
| 6239 | 6233 | @sizeOf(Ast.Node.Data) + |
| 6240 | 6234 | @sizeOf(Ast.TokenIndex)); |
| 6241 | const instruction_bytes = file.zir.instructions.len * | |
| 6235 | const instruction_bytes = file.zir.?.instructions.len * | |
| 6242 | 6236 | // Here we don't use @sizeOf(Zir.Inst.Data) because it would include |
| 6243 | 6237 | // the debug safety tag but we want to measure release size. |
| 6244 | 6238 | (@sizeOf(Zir.Inst.Tag) + 8); |
| 6245 | const extra_bytes = file.zir.extra.len * @sizeOf(u32); | |
| 6239 | const extra_bytes = file.zir.?.extra.len * @sizeOf(u32); | |
| 6246 | 6240 | const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes + |
| 6247 | file.zir.string_bytes.len * @sizeOf(u8); | |
| 6241 | file.zir.?.string_bytes.len * @sizeOf(u8); | |
| 6248 | 6242 | const stdout = io.getStdOut(); |
| 6249 | 6243 | const fmtIntSizeBin = std.fmt.fmtIntSizeBin; |
| 6250 | 6244 | // zig fmt: off |
| ... | ... | @@ -6258,27 +6252,27 @@ fn cmdAstCheck( |
| 6258 | 6252 | \\# Extra Data Items: {d} ({}) |
| 6259 | 6253 | \\ |
| 6260 | 6254 | , .{ |
| 6261 | fmtIntSizeBin(file.source.len), | |
| 6262 | file.tree.tokens.len, fmtIntSizeBin(token_bytes), | |
| 6263 | file.tree.nodes.len, fmtIntSizeBin(tree_bytes), | |
| 6255 | fmtIntSizeBin(file.source.?.len), | |
| 6256 | file.tree.?.tokens.len, fmtIntSizeBin(token_bytes), | |
| 6257 | file.tree.?.nodes.len, fmtIntSizeBin(tree_bytes), | |
| 6264 | 6258 | fmtIntSizeBin(total_bytes), |
| 6265 | file.zir.instructions.len, fmtIntSizeBin(instruction_bytes), | |
| 6266 | fmtIntSizeBin(file.zir.string_bytes.len), | |
| 6267 | file.zir.extra.len, fmtIntSizeBin(extra_bytes), | |
| 6259 | file.zir.?.instructions.len, fmtIntSizeBin(instruction_bytes), | |
| 6260 | fmtIntSizeBin(file.zir.?.string_bytes.len), | |
| 6261 | file.zir.?.extra.len, fmtIntSizeBin(extra_bytes), | |
| 6268 | 6262 | }); |
| 6269 | 6263 | // zig fmt: on |
| 6270 | 6264 | } |
| 6271 | 6265 | |
| 6272 | 6266 | try @import("print_zir.zig").renderAsTextToFile(gpa, &file, io.getStdOut()); |
| 6273 | 6267 | |
| 6274 | if (file.zir.hasCompileErrors()) { | |
| 6268 | if (file.zir.?.hasCompileErrors()) { | |
| 6275 | 6269 | process.exit(1); |
| 6276 | 6270 | } else { |
| 6277 | 6271 | return cleanExit(); |
| 6278 | 6272 | } |
| 6279 | 6273 | }, |
| 6280 | 6274 | .zon => { |
| 6281 | const zoir = try ZonGen.generate(gpa, file.tree, .{}); | |
| 6275 | const zoir = try ZonGen.generate(gpa, file.tree.?, .{}); | |
| 6282 | 6276 | defer zoir.deinit(gpa); |
| 6283 | 6277 | |
| 6284 | 6278 | if (zoir.hasCompileErrors()) { |
| ... | ... | @@ -6289,7 +6283,7 @@ fn cmdAstCheck( |
| 6289 | 6283 | { |
| 6290 | 6284 | const src_path = try file.fullPath(gpa); |
| 6291 | 6285 | defer gpa.free(src_path); |
| 6292 | try wip_errors.addZoirErrorMessages(zoir, file.tree, file.source, src_path); | |
| 6286 | try wip_errors.addZoirErrorMessages(zoir, file.tree.?, file.source.?, src_path); | |
| 6293 | 6287 | } |
| 6294 | 6288 | |
| 6295 | 6289 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| ... | ... | @@ -6519,26 +6513,24 @@ fn cmdDumpZir( |
| 6519 | 6513 | var file: Zcu.File = .{ |
| 6520 | 6514 | .status = .never_loaded, |
| 6521 | 6515 | .prev_status = .never_loaded, |
| 6522 | .source_loaded = false, | |
| 6523 | .tree_loaded = false, | |
| 6524 | .zir_loaded = true, | |
| 6525 | 6516 | .sub_file_path = undefined, |
| 6526 | .source = undefined, | |
| 6527 | 6517 | .stat = undefined, |
| 6528 | .tree = undefined, | |
| 6518 | .source = null, | |
| 6519 | .tree = null, | |
| 6529 | 6520 | .zir = try Zcu.loadZirCache(gpa, f), |
| 6521 | .zoir = null, | |
| 6530 | 6522 | .mod = undefined, |
| 6531 | 6523 | }; |
| 6532 | defer file.zir.deinit(gpa); | |
| 6524 | defer file.zir.?.deinit(gpa); | |
| 6533 | 6525 | |
| 6534 | 6526 | { |
| 6535 | const instruction_bytes = file.zir.instructions.len * | |
| 6527 | const instruction_bytes = file.zir.?.instructions.len * | |
| 6536 | 6528 | // Here we don't use @sizeOf(Zir.Inst.Data) because it would include |
| 6537 | 6529 | // the debug safety tag but we want to measure release size. |
| 6538 | 6530 | (@sizeOf(Zir.Inst.Tag) + 8); |
| 6539 | const extra_bytes = file.zir.extra.len * @sizeOf(u32); | |
| 6531 | const extra_bytes = file.zir.?.extra.len * @sizeOf(u32); | |
| 6540 | 6532 | const total_bytes = @sizeOf(Zir) + instruction_bytes + extra_bytes + |
| 6541 | file.zir.string_bytes.len * @sizeOf(u8); | |
| 6533 | file.zir.?.string_bytes.len * @sizeOf(u8); | |
| 6542 | 6534 | const stdout = io.getStdOut(); |
| 6543 | 6535 | const fmtIntSizeBin = std.fmt.fmtIntSizeBin; |
| 6544 | 6536 | // zig fmt: off |
| ... | ... | @@ -6550,9 +6542,9 @@ fn cmdDumpZir( |
| 6550 | 6542 | \\ |
| 6551 | 6543 | , .{ |
| 6552 | 6544 | fmtIntSizeBin(total_bytes), |
| 6553 | file.zir.instructions.len, fmtIntSizeBin(instruction_bytes), | |
| 6554 | fmtIntSizeBin(file.zir.string_bytes.len), | |
| 6555 | file.zir.extra.len, fmtIntSizeBin(extra_bytes), | |
| 6545 | file.zir.?.instructions.len, fmtIntSizeBin(instruction_bytes), | |
| 6546 | fmtIntSizeBin(file.zir.?.string_bytes.len), | |
| 6547 | file.zir.?.extra.len, fmtIntSizeBin(extra_bytes), | |
| 6556 | 6548 | }); |
| 6557 | 6549 | // zig fmt: on |
| 6558 | 6550 | } |
| ... | ... | @@ -6587,18 +6579,16 @@ fn cmdChangelist( |
| 6587 | 6579 | var file: Zcu.File = .{ |
| 6588 | 6580 | .status = .never_loaded, |
| 6589 | 6581 | .prev_status = .never_loaded, |
| 6590 | .source_loaded = false, | |
| 6591 | .tree_loaded = false, | |
| 6592 | .zir_loaded = false, | |
| 6593 | 6582 | .sub_file_path = old_source_file, |
| 6594 | .source = undefined, | |
| 6595 | 6583 | .stat = .{ |
| 6596 | 6584 | .size = stat.size, |
| 6597 | 6585 | .inode = stat.inode, |
| 6598 | 6586 | .mtime = stat.mtime, |
| 6599 | 6587 | }, |
| 6600 | .tree = undefined, | |
| 6601 | .zir = undefined, | |
| 6588 | .source = null, | |
| 6589 | .tree = null, | |
| 6590 | .zir = null, | |
| 6591 | .zoir = null, | |
| 6602 | 6592 | .mod = undefined, |
| 6603 | 6593 | }; |
| 6604 | 6594 | |
| ... | ... | @@ -6613,17 +6603,14 @@ fn cmdChangelist( |
| 6613 | 6603 | if (amt != stat.size) |
| 6614 | 6604 | return error.UnexpectedEndOfFile; |
| 6615 | 6605 | file.source = source; |
| 6616 | file.source_loaded = true; | |
| 6617 | 6606 | |
| 6618 | file.tree = try Ast.parse(gpa, file.source, .zig); | |
| 6619 | file.tree_loaded = true; | |
| 6620 | defer file.tree.deinit(gpa); | |
| 6607 | file.tree = try Ast.parse(gpa, file.source.?, .zig); | |
| 6608 | defer file.tree.?.deinit(gpa); | |
| 6621 | 6609 | |
| 6622 | file.zir = try AstGen.generate(gpa, file.tree); | |
| 6623 | file.zir_loaded = true; | |
| 6624 | defer file.zir.deinit(gpa); | |
| 6610 | file.zir = try AstGen.generate(gpa, file.tree.?); | |
| 6611 | defer file.zir.?.deinit(gpa); | |
| 6625 | 6612 | |
| 6626 | if (file.zir.loweringFailed()) { | |
| 6613 | if (file.zir.?.loweringFailed()) { | |
| 6627 | 6614 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 6628 | 6615 | try wip_errors.init(gpa); |
| 6629 | 6616 | defer wip_errors.deinit(); |
| ... | ... | @@ -6652,13 +6639,12 @@ fn cmdChangelist( |
| 6652 | 6639 | var new_tree = try Ast.parse(gpa, new_source, .zig); |
| 6653 | 6640 | defer new_tree.deinit(gpa); |
| 6654 | 6641 | |
| 6655 | var old_zir = file.zir; | |
| 6642 | var old_zir = file.zir.?; | |
| 6656 | 6643 | defer old_zir.deinit(gpa); |
| 6657 | file.zir_loaded = false; | |
| 6644 | file.zir = null; | |
| 6658 | 6645 | file.zir = try AstGen.generate(gpa, new_tree); |
| 6659 | file.zir_loaded = true; | |
| 6660 | 6646 | |
| 6661 | if (file.zir.loweringFailed()) { | |
| 6647 | if (file.zir.?.loweringFailed()) { | |
| 6662 | 6648 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| 6663 | 6649 | try wip_errors.init(gpa); |
| 6664 | 6650 | defer wip_errors.deinit(); |
| ... | ... | @@ -6672,7 +6658,7 @@ fn cmdChangelist( |
| 6672 | 6658 | var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty; |
| 6673 | 6659 | defer inst_map.deinit(gpa); |
| 6674 | 6660 | |
| 6675 | try Zcu.mapOldZirToNew(gpa, old_zir, file.zir, &inst_map); | |
| 6661 | try Zcu.mapOldZirToNew(gpa, old_zir, file.zir.?, &inst_map); | |
| 6676 | 6662 | |
| 6677 | 6663 | var bw = io.bufferedWriter(io.getStdOut().writer()); |
| 6678 | 6664 | const stdout = bw.writer(); |
src/print_zir.zig+10-13| ... | ... | @@ -22,7 +22,7 @@ pub fn renderAsTextToFile( |
| 22 | 22 | .gpa = gpa, |
| 23 | 23 | .arena = arena.allocator(), |
| 24 | 24 | .file = scope_file, |
| 25 | .code = scope_file.zir, | |
| 25 | .code = scope_file.zir.?, | |
| 26 | 26 | .indent = 0, |
| 27 | 27 | .parent_decl_node = 0, |
| 28 | 28 | .recurse_decls = true, |
| ... | ... | @@ -36,18 +36,18 @@ pub fn renderAsTextToFile( |
| 36 | 36 | try stream.print("%{d} ", .{@intFromEnum(main_struct_inst)}); |
| 37 | 37 | try writer.writeInstToStream(stream, main_struct_inst); |
| 38 | 38 | try stream.writeAll("\n"); |
| 39 | const imports_index = scope_file.zir.extra[@intFromEnum(Zir.ExtraIndex.imports)]; | |
| 39 | const imports_index = scope_file.zir.?.extra[@intFromEnum(Zir.ExtraIndex.imports)]; | |
| 40 | 40 | if (imports_index != 0) { |
| 41 | 41 | try stream.writeAll("Imports:\n"); |
| 42 | 42 | |
| 43 | const extra = scope_file.zir.extraData(Zir.Inst.Imports, imports_index); | |
| 43 | const extra = scope_file.zir.?.extraData(Zir.Inst.Imports, imports_index); | |
| 44 | 44 | var extra_index = extra.end; |
| 45 | 45 | |
| 46 | 46 | for (0..extra.data.imports_len) |_| { |
| 47 | const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index); | |
| 47 | const item = scope_file.zir.?.extraData(Zir.Inst.Imports.Item, extra_index); | |
| 48 | 48 | extra_index = item.end; |
| 49 | 49 | |
| 50 | const import_path = scope_file.zir.nullTerminatedString(item.data.name); | |
| 50 | const import_path = scope_file.zir.?.nullTerminatedString(item.data.name); | |
| 51 | 51 | try stream.print(" @import(\"{}\") ", .{ |
| 52 | 52 | std.zig.fmtEscapes(import_path), |
| 53 | 53 | }); |
| ... | ... | @@ -75,7 +75,7 @@ pub fn renderInstructionContext( |
| 75 | 75 | .gpa = gpa, |
| 76 | 76 | .arena = arena.allocator(), |
| 77 | 77 | .file = scope_file, |
| 78 | .code = scope_file.zir, | |
| 78 | .code = scope_file.zir.?, | |
| 79 | 79 | .indent = if (indent < 2) 2 else indent, |
| 80 | 80 | .parent_decl_node = parent_decl_node, |
| 81 | 81 | .recurse_decls = false, |
| ... | ... | @@ -107,7 +107,7 @@ pub fn renderSingleInstruction( |
| 107 | 107 | .gpa = gpa, |
| 108 | 108 | .arena = arena.allocator(), |
| 109 | 109 | .file = scope_file, |
| 110 | .code = scope_file.zir, | |
| 110 | .code = scope_file.zir.?, | |
| 111 | 111 | .indent = indent, |
| 112 | 112 | .parent_decl_node = parent_decl_node, |
| 113 | 113 | .recurse_decls = false, |
| ... | ... | @@ -2759,8 +2759,7 @@ const Writer = struct { |
| 2759 | 2759 | } |
| 2760 | 2760 | |
| 2761 | 2761 | fn writeSrcNode(self: *Writer, stream: anytype, src_node: i32) !void { |
| 2762 | if (!self.file.tree_loaded) return; | |
| 2763 | const tree = self.file.tree; | |
| 2762 | const tree = self.file.tree orelse return; | |
| 2764 | 2763 | const abs_node = self.relativeToNodeIndex(src_node); |
| 2765 | 2764 | const src_span = tree.nodeToSpan(abs_node); |
| 2766 | 2765 | const start = self.line_col_cursor.find(tree.source, src_span.start); |
| ... | ... | @@ -2772,8 +2771,7 @@ const Writer = struct { |
| 2772 | 2771 | } |
| 2773 | 2772 | |
| 2774 | 2773 | fn writeSrcTok(self: *Writer, stream: anytype, src_tok: u32) !void { |
| 2775 | if (!self.file.tree_loaded) return; | |
| 2776 | const tree = self.file.tree; | |
| 2774 | const tree = self.file.tree orelse return; | |
| 2777 | 2775 | const abs_tok = tree.firstToken(self.parent_decl_node) + src_tok; |
| 2778 | 2776 | const span_start = tree.tokens.items(.start)[abs_tok]; |
| 2779 | 2777 | const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(abs_tok).len)); |
| ... | ... | @@ -2786,8 +2784,7 @@ const Writer = struct { |
| 2786 | 2784 | } |
| 2787 | 2785 | |
| 2788 | 2786 | fn writeSrcTokAbs(self: *Writer, stream: anytype, src_tok: u32) !void { |
| 2789 | if (!self.file.tree_loaded) return; | |
| 2790 | const tree = self.file.tree; | |
| 2787 | const tree = self.file.tree orelse return; | |
| 2791 | 2788 | const span_start = tree.tokens.items(.start)[src_tok]; |
| 2792 | 2789 | const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len)); |
| 2793 | 2790 | const start = self.line_col_cursor.find(tree.source, span_start); |