| ... | @@ -1047,9 +1047,9 @@ pub const File = struct { | ... | @@ -1047,9 +1047,9 @@ pub const File = struct { |
| 1047 | const source = try gpa.allocSentinel(u8, @intCast(stat.size), 0); | 1047 | const source = try gpa.allocSentinel(u8, @intCast(stat.size), 0); |
| 1048 | errdefer gpa.free(source); | 1048 | errdefer gpa.free(source); |
| 1049 | | 1049 | |
| 1050 | var fr = f.reader(); | 1050 | var file_reader = f.reader(&.{}); |
| 1051 | var br = fr.interface().unbuffered(); | 1051 | file_reader.size = stat.size; |
| 1052 | try br.readSlice(source); | 1052 | try file_reader.interface.readSliceAll(source); |
| 1053 | | 1053 | |
| 1054 | // Here we do not modify stat fields because this function is the one | 1054 | // Here we do not modify stat fields because this function is the one |
| 1055 | // used for error reporting. We need to keep the stat fields stale so that | 1055 | // used for error reporting. We need to keep the stat fields stale so that |
| ... | @@ -1102,10 +1102,10 @@ pub const File = struct { | ... | @@ -1102,10 +1102,10 @@ pub const File = struct { |
| 1102 | const gpa = pt.zcu.gpa; | 1102 | const gpa = pt.zcu.gpa; |
| 1103 | const ip = &pt.zcu.intern_pool; | 1103 | const ip = &pt.zcu.intern_pool; |
| 1104 | const strings = ip.getLocal(pt.tid).getMutableStrings(gpa); | 1104 | const strings = ip.getLocal(pt.tid).getMutableStrings(gpa); |
| 1105 | var bw: Writer = .fixed((try strings.addManyAsSlice(file.fullyQualifiedNameLen()))[0]); | 1105 | var w: Writer = .fixed((try strings.addManyAsSlice(file.fullyQualifiedNameLen()))[0]); |
| 1106 | file.renderFullyQualifiedName(&bw) catch unreachable; | 1106 | file.renderFullyQualifiedName(&w) catch unreachable; |
| 1107 | assert(bw.end == bw.buffer.len); | 1107 | assert(w.end == w.buffer.len); |
| 1108 | return ip.getOrPutTrailingString(gpa, pt.tid, @intCast(bw.end), .no_embedded_nulls); | 1108 | return ip.getOrPutTrailingString(gpa, pt.tid, @intCast(w.end), .no_embedded_nulls); |
| 1109 | } | 1109 | } |
| 1110 | | 1110 | |
| 1111 | pub const Index = InternPool.FileIndex; | 1111 | pub const Index = InternPool.FileIndex; |
| ... | @@ -2817,13 +2817,13 @@ comptime { | ... | @@ -2817,13 +2817,13 @@ comptime { |
| 2817 | } | 2817 | } |
| 2818 | | 2818 | |
| 2819 | pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir { | 2819 | pub fn loadZirCache(gpa: Allocator, cache_file: std.fs.File) !Zir { |
| 2820 | var cache_fr = cache_file.reader(); | 2820 | var buffer: [2000]u8 = undefined; |
| 2821 | var cache_br = cache_fr.interface().unbuffered(); | 2821 | var file_reader = cache_file.reader(&buffer); |
| 2822 | return result: { | 2822 | return result: { |
| 2823 | const header = cache_br.takeStruct(Zir.Header) catch |err| break :result err; | 2823 | const header = file_reader.interface.takeStruct(Zir.Header) catch |err| break :result err; |
| 2824 | break :result loadZirCacheBody(gpa, header.*, &cache_br); | 2824 | break :result loadZirCacheBody(gpa, header.*, &file_reader.interface); |
| 2825 | } catch |err| switch (err) { | 2825 | } catch |err| switch (err) { |
| 2826 | error.ReadFailed => return cache_fr.err.?, | 2826 | error.ReadFailed => return file_reader.err.?, |
| 2827 | else => |e| return e, | 2827 | else => |e| return e, |
| 2828 | }; | 2828 | }; |
| 2829 | } | 2829 | } |
| ... | @@ -2909,9 +2909,8 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S | ... | @@ -2909,9 +2909,8 @@ pub fn saveZirCache(gpa: Allocator, cache_file: std.fs.File, stat: std.fs.File.S |
| 2909 | zir.string_bytes, | 2909 | zir.string_bytes, |
| 2910 | @ptrCast(zir.extra), | 2910 | @ptrCast(zir.extra), |
| 2911 | }; | 2911 | }; |
| 2912 | var cache_fw = cache_file.writer(); | 2912 | var cache_fw = cache_file.writer(&.{}); |
| 2913 | var cache_bw = cache_fw.interface().unbuffered(); | 2913 | cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) { |
| 2914 | cache_bw.writeVecAll(&vecs) catch |err| switch (err) { | | |
| 2915 | error.WriteFailed => return cache_fw.err.?, | 2914 | error.WriteFailed => return cache_fw.err.?, |
| 2916 | }; | 2915 | }; |
| 2917 | } | 2916 | } |
| ... | @@ -2940,9 +2939,8 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir | ... | @@ -2940,9 +2939,8 @@ pub fn saveZoirCache(cache_file: std.fs.File, stat: std.fs.File.Stat, zoir: Zoir |
| 2940 | @ptrCast(zoir.compile_errors), | 2939 | @ptrCast(zoir.compile_errors), |
| 2941 | @ptrCast(zoir.error_notes), | 2940 | @ptrCast(zoir.error_notes), |
| 2942 | }; | 2941 | }; |
| 2943 | var cache_fw = cache_file.writer(); | 2942 | var cache_fw = cache_file.writer(&.{}); |
| 2944 | var cache_bw = cache_fw.interface().unbuffered(); | 2943 | cache_fw.interface.writeVecAll(&vecs) catch |err| switch (err) { |
| 2945 | cache_bw.writeVecAll(&vecs) catch |err| switch (err) { | | |
| 2946 | error.WriteFailed => return cache_fw.err.?, | 2944 | error.WriteFailed => return cache_fw.err.?, |
| 2947 | }; | 2945 | }; |
| 2948 | } | 2946 | } |
| ... | @@ -4253,15 +4251,19 @@ pub fn navFileScope(zcu: *Zcu, nav: InternPool.Nav.Index) *File { | ... | @@ -4253,15 +4251,19 @@ pub fn navFileScope(zcu: *Zcu, nav: InternPool.Nav.Index) *File { |
| 4253 | return zcu.fileByIndex(zcu.navFileScopeIndex(nav)); | 4251 | return zcu.fileByIndex(zcu.navFileScopeIndex(nav)); |
| 4254 | } | 4252 | } |
| 4255 | | 4253 | |
| 4256 | pub fn fmtAnalUnit(zcu: *Zcu, unit: AnalUnit) std.fmt.Formatter(formatAnalUnit) { | 4254 | pub fn fmtAnalUnit(zcu: *Zcu, unit: AnalUnit) std.fmt.Formatter(FormatAnalUnit, formatAnalUnit) { |
| 4257 | return .{ .data = .{ .unit = unit, .zcu = zcu } }; | 4255 | return .{ .data = .{ .unit = unit, .zcu = zcu } }; |
| 4258 | } | 4256 | } |
| 4259 | pub fn fmtDependee(zcu: *Zcu, d: InternPool.Dependee) std.fmt.Formatter(formatDependee) { | 4257 | pub fn fmtDependee(zcu: *Zcu, d: InternPool.Dependee) std.fmt.Formatter(FormatDependee, formatDependee) { |
| 4260 | return .{ .data = .{ .dependee = d, .zcu = zcu } }; | 4258 | return .{ .data = .{ .dependee = d, .zcu = zcu } }; |
| 4261 | } | 4259 | } |
| 4262 | | 4260 | |
| 4263 | fn formatAnalUnit(data: struct { unit: AnalUnit, zcu: *Zcu }, bw: *Writer, comptime fmt: []const u8) !void { | 4261 | const FormatAnalUnit = struct { |
| 4264 | _ = fmt; | 4262 | unit: AnalUnit, |
| | 4263 | zcu: *Zcu, |
| | 4264 | }; |
| | 4265 | |
| | 4266 | fn formatAnalUnit(data: FormatAnalUnit, writer: *std.io.Writer) std.io.Writer.Error!void { |
| 4265 | const zcu = data.zcu; | 4267 | const zcu = data.zcu; |
| 4266 | const ip = &zcu.intern_pool; | 4268 | const ip = &zcu.intern_pool; |
| 4267 | switch (data.unit.unwrap()) { | 4269 | switch (data.unit.unwrap()) { |
| ... | @@ -4269,69 +4271,71 @@ fn formatAnalUnit(data: struct { unit: AnalUnit, zcu: *Zcu }, bw: *Writer, compt | ... | @@ -4269,69 +4271,71 @@ fn formatAnalUnit(data: struct { unit: AnalUnit, zcu: *Zcu }, bw: *Writer, compt |
| 4269 | const cu = ip.getComptimeUnit(cu_id); | 4271 | const cu = ip.getComptimeUnit(cu_id); |
| 4270 | if (cu.zir_index.resolveFull(ip)) |resolved| { | 4272 | if (cu.zir_index.resolveFull(ip)) |resolved| { |
| 4271 | const file_path = zcu.fileByIndex(resolved.file).path; | 4273 | const file_path = zcu.fileByIndex(resolved.file).path; |
| 4272 | return bw.print("comptime(inst=('{f}', %{}) [{}])", .{ file_path.fmt(zcu.comp), @intFromEnum(resolved.inst), @intFromEnum(cu_id) }); | 4274 | return writer.print("comptime(inst=('{}', %{}) [{}])", .{ file_path.fmt(zcu.comp), @intFromEnum(resolved.inst), @intFromEnum(cu_id) }); |
| 4273 | } else { | 4275 | } else { |
| 4274 | return bw.print("comptime(inst=<lost> [{}])", .{@intFromEnum(cu_id)}); | 4276 | return writer.print("comptime(inst=<lost> [{}])", .{@intFromEnum(cu_id)}); |
| 4275 | } | 4277 | } |
| 4276 | }, | 4278 | }, |
| 4277 | .nav_val => |nav| return bw.print("nav_val('{f}' [{}])", .{ ip.getNav(nav).fqn.fmt(ip), @intFromEnum(nav) }), | 4279 | .nav_val => |nav| return writer.print("nav_val('{}' [{}])", .{ ip.getNav(nav).fqn.fmt(ip), @intFromEnum(nav) }), |
| 4278 | .nav_ty => |nav| return bw.print("nav_ty('{f}' [{}])", .{ ip.getNav(nav).fqn.fmt(ip), @intFromEnum(nav) }), | 4280 | .nav_ty => |nav| return writer.print("nav_ty('{}' [{}])", .{ ip.getNav(nav).fqn.fmt(ip), @intFromEnum(nav) }), |
| 4279 | .type => |ty| return bw.print("ty('{f}' [{}])", .{ Type.fromInterned(ty).containerTypeName(ip).fmt(ip), @intFromEnum(ty) }), | 4281 | .type => |ty| return writer.print("ty('{}' [{}])", .{ Type.fromInterned(ty).containerTypeName(ip).fmt(ip), @intFromEnum(ty) }), |
| 4280 | .func => |func| { | 4282 | .func => |func| { |
| 4281 | const nav = zcu.funcInfo(func).owner_nav; | 4283 | const nav = zcu.funcInfo(func).owner_nav; |
| 4282 | return bw.print("func('{f}' [{}])", .{ ip.getNav(nav).fqn.fmt(ip), @intFromEnum(func) }); | 4284 | return writer.print("func('{}' [{}])", .{ ip.getNav(nav).fqn.fmt(ip), @intFromEnum(func) }); |
| 4283 | }, | 4285 | }, |
| 4284 | .memoized_state => return bw.writeAll("memoized_state"), | 4286 | .memoized_state => return writer.writeAll("memoized_state"), |
| 4285 | } | 4287 | } |
| 4286 | } | 4288 | } |
| 4287 | fn formatDependee(data: struct { dependee: InternPool.Dependee, zcu: *Zcu }, bw: *Writer, comptime fmt: []const u8) !void { | 4289 | |
| 4288 | _ = fmt; | 4290 | const FormatDependee = struct { dependee: InternPool.Dependee, zcu: *Zcu }; |
| | 4291 | |
| | 4292 | fn formatDependee(data: FormatDependee, writer: *std.io.Writer) std.io.Writer.Error!void { |
| 4289 | const zcu = data.zcu; | 4293 | const zcu = data.zcu; |
| 4290 | const ip = &zcu.intern_pool; | 4294 | const ip = &zcu.intern_pool; |
| 4291 | switch (data.dependee) { | 4295 | switch (data.dependee) { |
| 4292 | .src_hash => |ti| { | 4296 | .src_hash => |ti| { |
| 4293 | const info = ti.resolveFull(ip) orelse { | 4297 | const info = ti.resolveFull(ip) orelse { |
| 4294 | return bw.writeAll("inst(<lost>)"); | 4298 | return writer.writeAll("inst(<lost>)"); |
| 4295 | }; | 4299 | }; |
| 4296 | const file_path = zcu.fileByIndex(info.file).path; | 4300 | const file_path = zcu.fileByIndex(info.file).path; |
| 4297 | return bw.print("inst('{f}', %{d})", .{ file_path.fmt(zcu.comp), @intFromEnum(info.inst) }); | 4301 | return writer.print("inst('{}', %{d})", .{ file_path.fmt(zcu.comp), @intFromEnum(info.inst) }); |
| 4298 | }, | 4302 | }, |
| 4299 | .nav_val => |nav| { | 4303 | .nav_val => |nav| { |
| 4300 | const fqn = ip.getNav(nav).fqn; | 4304 | const fqn = ip.getNav(nav).fqn; |
| 4301 | return bw.print("nav_val('{f}')", .{fqn.fmt(ip)}); | 4305 | return writer.print("nav_val('{}')", .{fqn.fmt(ip)}); |
| 4302 | }, | 4306 | }, |
| 4303 | .nav_ty => |nav| { | 4307 | .nav_ty => |nav| { |
| 4304 | const fqn = ip.getNav(nav).fqn; | 4308 | const fqn = ip.getNav(nav).fqn; |
| 4305 | return bw.print("nav_ty('{f}')", .{fqn.fmt(ip)}); | 4309 | return writer.print("nav_ty('{}')", .{fqn.fmt(ip)}); |
| 4306 | }, | 4310 | }, |
| 4307 | .interned => |ip_index| switch (ip.indexToKey(ip_index)) { | 4311 | .interned => |ip_index| switch (ip.indexToKey(ip_index)) { |
| 4308 | .struct_type, .union_type, .enum_type => return bw.print("type('{f}')", .{Type.fromInterned(ip_index).containerTypeName(ip).fmt(ip)}), | 4312 | .struct_type, .union_type, .enum_type => return writer.print("type('{}')", .{Type.fromInterned(ip_index).containerTypeName(ip).fmt(ip)}), |
| 4309 | .func => |f| return bw.print("ies('{f}')", .{ip.getNav(f.owner_nav).fqn.fmt(ip)}), | 4313 | .func => |f| return writer.print("ies('{}')", .{ip.getNav(f.owner_nav).fqn.fmt(ip)}), |
| 4310 | else => unreachable, | 4314 | else => unreachable, |
| 4311 | }, | 4315 | }, |
| 4312 | .zon_file => |file| { | 4316 | .zon_file => |file| { |
| 4313 | const file_path = zcu.fileByIndex(file).path; | 4317 | const file_path = zcu.fileByIndex(file).path; |
| 4314 | return bw.print("zon_file('{f}')", .{file_path.fmt(zcu.comp)}); | 4318 | return writer.print("zon_file('{}')", .{file_path.fmt(zcu.comp)}); |
| 4315 | }, | 4319 | }, |
| 4316 | .embed_file => |ef_idx| { | 4320 | .embed_file => |ef_idx| { |
| 4317 | const ef = ef_idx.get(zcu); | 4321 | const ef = ef_idx.get(zcu); |
| 4318 | return bw.print("embed_file('{f}')", .{ef.path.fmt(zcu.comp)}); | 4322 | return writer.print("embed_file('{}')", .{ef.path.fmt(zcu.comp)}); |
| 4319 | }, | 4323 | }, |
| 4320 | .namespace => |ti| { | 4324 | .namespace => |ti| { |
| 4321 | const info = ti.resolveFull(ip) orelse { | 4325 | const info = ti.resolveFull(ip) orelse { |
| 4322 | return bw.writeAll("namespace(<lost>)"); | 4326 | return writer.writeAll("namespace(<lost>)"); |
| 4323 | }; | 4327 | }; |
| 4324 | const file_path = zcu.fileByIndex(info.file).path; | 4328 | const file_path = zcu.fileByIndex(info.file).path; |
| 4325 | return bw.print("namespace('{f}', %{d})", .{ file_path.fmt(zcu.comp), @intFromEnum(info.inst) }); | 4329 | return writer.print("namespace('{}', %{d})", .{ file_path.fmt(zcu.comp), @intFromEnum(info.inst) }); |
| 4326 | }, | 4330 | }, |
| 4327 | .namespace_name => |k| { | 4331 | .namespace_name => |k| { |
| 4328 | const info = k.namespace.resolveFull(ip) orelse { | 4332 | const info = k.namespace.resolveFull(ip) orelse { |
| 4329 | return bw.print("namespace(<lost>, '{f}')", .{k.name.fmt(ip)}); | 4333 | return writer.print("namespace(<lost>, '{}')", .{k.name.fmt(ip)}); |
| 4330 | }; | 4334 | }; |
| 4331 | const file_path = zcu.fileByIndex(info.file).path; | 4335 | const file_path = zcu.fileByIndex(info.file).path; |
| 4332 | return bw.print("namespace('{f}', %{d}, '{f}')", .{ file_path.fmt(zcu.comp), @intFromEnum(info.inst), k.name.fmt(ip) }); | 4336 | return writer.print("namespace('{}', %{d}, '{}')", .{ file_path.fmt(zcu.comp), @intFromEnum(info.inst), k.name.fmt(ip) }); |
| 4333 | }, | 4337 | }, |
| 4334 | .memoized_state => return bw.writeAll("memoized_state"), | 4338 | .memoized_state => return writer.writeAll("memoized_state"), |
| 4335 | } | 4339 | } |
| 4336 | } | 4340 | } |
| 4337 | | 4341 | |