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