authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-04-08 12:44:42-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-04-08 13:24:08-04:00
log7611d90ba011fb030523e669e85acfb6faae5d19
treef1b48f3ac73681c402dce10b5857ecc0f84dd7a4
parent4cd92567e7392b0fe390562d7ea52f68357bb45a

InternPool: remove slice from byte aggregate keys

This deletes a ton of lookups and avoids many UAF bugs. Closes #19485

24 files changed, 1038 insertions(+), 952 deletions(-)

lib/std/zig/Zir.zig+2-6
...@@ -106,12 +106,8 @@ pub const NullTerminatedString = enum(u32) {...@@ -106,12 +106,8 @@ pub const NullTerminatedString = enum(u32) {
106106
107/// Given an index into `string_bytes` returns the null-terminated string found there.107/// Given an index into `string_bytes` returns the null-terminated string found there.
108pub fn nullTerminatedString(code: Zir, index: NullTerminatedString) [:0]const u8 {108pub fn nullTerminatedString(code: Zir, index: NullTerminatedString) [:0]const u8 {
109 const start = @intFromEnum(index);109 const slice = code.string_bytes[@intFromEnum(index)..];
110 var end: u32 = start;110 return slice[0..std.mem.indexOfScalar(u8, slice, 0).? :0];
111 while (code.string_bytes[end] != 0) {
112 end += 1;
113 }
114 return code.string_bytes[start..end :0];
115}111}
116112
117pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {113pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
src/Compilation.zig+3-4
...@@ -3159,7 +3159,7 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod...@@ -3159,7 +3159,7 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
3159 const rt_file_path = try module_reference.src_loc.file_scope.fullPath(gpa);3159 const rt_file_path = try module_reference.src_loc.file_scope.fullPath(gpa);
3160 defer gpa.free(rt_file_path);3160 defer gpa.free(rt_file_path);
3161 ref_traces.appendAssumeCapacity(.{3161 ref_traces.appendAssumeCapacity(.{
3162 .decl_name = try eb.addString(ip.stringToSlice(module_reference.decl)),3162 .decl_name = try eb.addString(module_reference.decl.toSlice(ip)),
3163 .src_loc = try eb.addSourceLocation(.{3163 .src_loc = try eb.addSourceLocation(.{
3164 .src_path = try eb.addString(rt_file_path),3164 .src_path = try eb.addString(rt_file_path),
3165 .span_start = span.start,3165 .span_start = span.start,
...@@ -4074,8 +4074,7 @@ fn workerCheckEmbedFile(...@@ -4074,8 +4074,7 @@ fn workerCheckEmbedFile(
4074fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Module.EmbedFile) !void {4074fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Module.EmbedFile) !void {
4075 const mod = comp.module.?;4075 const mod = comp.module.?;
4076 const ip = &mod.intern_pool;4076 const ip = &mod.intern_pool;
4077 const sub_file_path = ip.stringToSlice(embed_file.sub_file_path);4077 var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{});
4078 var file = try embed_file.owner.root.openFile(sub_file_path, .{});
4079 defer file.close();4078 defer file.close();
40804079
4081 const stat = try file.stat();4080 const stat = try file.stat();
...@@ -4444,7 +4443,7 @@ fn reportRetryableEmbedFileError(...@@ -4444,7 +4443,7 @@ fn reportRetryableEmbedFileError(
4444 const ip = &mod.intern_pool;4443 const ip = &mod.intern_pool;
4445 const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{4444 const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{
4446 embed_file.owner.root,4445 embed_file.owner.root,
4447 ip.stringToSlice(embed_file.sub_file_path),4446 embed_file.sub_file_path.toSlice(ip),
4448 @errorName(err),4447 @errorName(err),
4449 });4448 });
44504449
src/InternPool.zig+190-164
...@@ -351,7 +351,7 @@ const KeyAdapter = struct {...@@ -351,7 +351,7 @@ const KeyAdapter = struct {
351 pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: usize) bool {351 pub fn eql(ctx: @This(), a: Key, b_void: void, b_map_index: usize) bool {
352 _ = b_void;352 _ = b_void;
353 if (ctx.intern_pool.items.items(.tag)[b_map_index] == .removed) return false;353 if (ctx.intern_pool.items.items(.tag)[b_map_index] == .removed) return false;
354 return ctx.intern_pool.indexToKey(@as(Index, @enumFromInt(b_map_index))).eql(a, ctx.intern_pool);354 return ctx.intern_pool.indexToKey(@enumFromInt(b_map_index)).eql(a, ctx.intern_pool);
355 }355 }
356356
357 pub fn hash(ctx: @This(), a: Key) u32 {357 pub fn hash(ctx: @This(), a: Key) u32 {
...@@ -385,7 +385,7 @@ pub const RuntimeIndex = enum(u32) {...@@ -385,7 +385,7 @@ pub const RuntimeIndex = enum(u32) {
385 _,385 _,
386386
387 pub fn increment(ri: *RuntimeIndex) void {387 pub fn increment(ri: *RuntimeIndex) void {
388 ri.* = @as(RuntimeIndex, @enumFromInt(@intFromEnum(ri.*) + 1));388 ri.* = @enumFromInt(@intFromEnum(ri.*) + 1);
389 }389 }
390};390};
391391
...@@ -418,12 +418,44 @@ pub const OptionalNamespaceIndex = enum(u32) {...@@ -418,12 +418,44 @@ pub const OptionalNamespaceIndex = enum(u32) {
418418
419/// An index into `string_bytes`.419/// An index into `string_bytes`.
420pub const String = enum(u32) {420pub const String = enum(u32) {
421 /// An empty string.
422 empty = 0,
423 _,
424
425 pub fn toSlice(string: String, len: u64, ip: *const InternPool) []const u8 {
426 return ip.string_bytes.items[@intFromEnum(string)..][0..@intCast(len)];
427 }
428
429 pub fn at(string: String, index: u64, ip: *const InternPool) u8 {
430 return ip.string_bytes.items[@intCast(@intFromEnum(string) + index)];
431 }
432
433 pub fn toNullTerminatedString(string: String, len: u64, ip: *const InternPool) NullTerminatedString {
434 assert(std.mem.indexOfScalar(u8, string.toSlice(len, ip), 0) == null);
435 assert(string.at(len, ip) == 0);
436 return @enumFromInt(@intFromEnum(string));
437 }
438};
439
440/// An index into `string_bytes` which might be `none`.
441pub const OptionalString = enum(u32) {
442 /// This is distinct from `none` - it is a valid index that represents empty string.
443 empty = 0,
444 none = std.math.maxInt(u32),
421 _,445 _,
446
447 pub fn unwrap(string: OptionalString) ?String {
448 return if (string != .none) @enumFromInt(@intFromEnum(string)) else null;
449 }
450
451 pub fn toSlice(string: OptionalString, len: u64, ip: *const InternPool) ?[]const u8 {
452 return (string.unwrap() orelse return null).toSlice(len, ip);
453 }
422};454};
423455
424/// An index into `string_bytes`.456/// An index into `string_bytes`.
425pub const NullTerminatedString = enum(u32) {457pub const NullTerminatedString = enum(u32) {
426 /// This is distinct from `none` - it is a valid index that represents empty string.458 /// An empty string.
427 empty = 0,459 empty = 0,
428 _,460 _,
429461
...@@ -447,6 +479,19 @@ pub const NullTerminatedString = enum(u32) {...@@ -447,6 +479,19 @@ pub const NullTerminatedString = enum(u32) {
447 return @enumFromInt(@intFromEnum(self));479 return @enumFromInt(@intFromEnum(self));
448 }480 }
449481
482 pub fn toSlice(string: NullTerminatedString, ip: *const InternPool) [:0]const u8 {
483 const slice = ip.string_bytes.items[@intFromEnum(string)..];
484 return slice[0..std.mem.indexOfScalar(u8, slice, 0).? :0];
485 }
486
487 pub fn length(string: NullTerminatedString, ip: *const InternPool) u32 {
488 return @intCast(string.toSlice(ip).len);
489 }
490
491 pub fn eqlSlice(string: NullTerminatedString, slice: []const u8, ip: *const InternPool) bool {
492 return std.mem.eql(u8, string.toSlice(ip), slice);
493 }
494
450 const Adapter = struct {495 const Adapter = struct {
451 strings: []const NullTerminatedString,496 strings: []const NullTerminatedString,
452497
...@@ -467,11 +512,11 @@ pub const NullTerminatedString = enum(u32) {...@@ -467,11 +512,11 @@ pub const NullTerminatedString = enum(u32) {
467 return @intFromEnum(a) < @intFromEnum(b);512 return @intFromEnum(a) < @intFromEnum(b);
468 }513 }
469514
470 pub fn toUnsigned(self: NullTerminatedString, ip: *const InternPool) ?u32 {515 pub fn toUnsigned(string: NullTerminatedString, ip: *const InternPool) ?u32 {
471 const s = ip.stringToSlice(self);516 const slice = string.toSlice(ip);
472 if (s.len > 1 and s[0] == '0') return null;517 if (slice.len > 1 and slice[0] == '0') return null;
473 if (std.mem.indexOfScalar(u8, s, '_')) |_| return null;518 if (std.mem.indexOfScalar(u8, slice, '_')) |_| return null;
474 return std.fmt.parseUnsigned(u32, s, 10) catch null;519 return std.fmt.parseUnsigned(u32, slice, 10) catch null;
475 }520 }
476521
477 const FormatData = struct {522 const FormatData = struct {
...@@ -484,11 +529,11 @@ pub const NullTerminatedString = enum(u32) {...@@ -484,11 +529,11 @@ pub const NullTerminatedString = enum(u32) {
484 _: std.fmt.FormatOptions,529 _: std.fmt.FormatOptions,
485 writer: anytype,530 writer: anytype,
486 ) @TypeOf(writer).Error!void {531 ) @TypeOf(writer).Error!void {
487 const s = data.ip.stringToSlice(data.string);532 const slice = data.string.toSlice(data.ip);
488 if (comptime std.mem.eql(u8, specifier, "")) {533 if (comptime std.mem.eql(u8, specifier, "")) {
489 try writer.writeAll(s);534 try writer.writeAll(slice);
490 } else if (comptime std.mem.eql(u8, specifier, "i")) {535 } else if (comptime std.mem.eql(u8, specifier, "i")) {
491 try writer.print("{p}", .{std.zig.fmtId(s)});536 try writer.print("{p}", .{std.zig.fmtId(slice)});
492 } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'");537 } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'");
493 }538 }
494539
...@@ -504,9 +549,12 @@ pub const OptionalNullTerminatedString = enum(u32) {...@@ -504,9 +549,12 @@ pub const OptionalNullTerminatedString = enum(u32) {
504 none = std.math.maxInt(u32),549 none = std.math.maxInt(u32),
505 _,550 _,
506551
507 pub fn unwrap(oi: OptionalNullTerminatedString) ?NullTerminatedString {552 pub fn unwrap(string: OptionalNullTerminatedString) ?NullTerminatedString {
508 if (oi == .none) return null;553 return if (string != .none) @enumFromInt(@intFromEnum(string)) else null;
509 return @enumFromInt(@intFromEnum(oi));554 }
555
556 pub fn toSlice(string: OptionalNullTerminatedString, ip: *const InternPool) ?[:0]const u8 {
557 return (string.unwrap() orelse return null).toSlice(ip);
510 }558 }
511};559};
512560
...@@ -690,6 +738,10 @@ pub const Key = union(enum) {...@@ -690,6 +738,10 @@ pub const Key = union(enum) {
690 len: u64,738 len: u64,
691 child: Index,739 child: Index,
692 sentinel: Index = .none,740 sentinel: Index = .none,
741
742 pub fn lenIncludingSentinel(array_type: ArrayType) u64 {
743 return array_type.len + @intFromBool(array_type.sentinel != .none);
744 }
693 };745 };
694746
695 /// Extern so that hashing can be done via memory reinterpreting.747 /// Extern so that hashing can be done via memory reinterpreting.
...@@ -1043,7 +1095,7 @@ pub const Key = union(enum) {...@@ -1043,7 +1095,7 @@ pub const Key = union(enum) {
1043 storage: Storage,1095 storage: Storage,
10441096
1045 pub const Storage = union(enum) {1097 pub const Storage = union(enum) {
1046 bytes: []const u8,1098 bytes: String,
1047 elems: []const Index,1099 elems: []const Index,
1048 repeated_elem: Index,1100 repeated_elem: Index,
10491101
...@@ -1203,7 +1255,7 @@ pub const Key = union(enum) {...@@ -1203,7 +1255,7 @@ pub const Key = union(enum) {
12031255
1204 if (child == .u8_type) {1256 if (child == .u8_type) {
1205 switch (aggregate.storage) {1257 switch (aggregate.storage) {
1206 .bytes => |bytes| for (bytes[0..@intCast(len)]) |byte| {1258 .bytes => |bytes| for (bytes.toSlice(len, ip)) |byte| {
1207 std.hash.autoHash(&hasher, KeyTag.int);1259 std.hash.autoHash(&hasher, KeyTag.int);
1208 std.hash.autoHash(&hasher, byte);1260 std.hash.autoHash(&hasher, byte);
1209 },1261 },
...@@ -1240,7 +1292,7 @@ pub const Key = union(enum) {...@@ -1240,7 +1292,7 @@ pub const Key = union(enum) {
12401292
1241 switch (aggregate.storage) {1293 switch (aggregate.storage) {
1242 .bytes => unreachable,1294 .bytes => unreachable,
1243 .elems => |elems| for (elems[0..@as(usize, @intCast(len))]) |elem|1295 .elems => |elems| for (elems[0..@intCast(len)]) |elem|
1244 std.hash.autoHash(&hasher, elem),1296 std.hash.autoHash(&hasher, elem),
1245 .repeated_elem => |elem| {1297 .repeated_elem => |elem| {
1246 var remaining = len;1298 var remaining = len;
...@@ -1505,11 +1557,11 @@ pub const Key = union(enum) {...@@ -1505,11 +1557,11 @@ pub const Key = union(enum) {
1505 if (a_info.ty == .c_longdouble_type and a_info.storage != .f80) {1557 if (a_info.ty == .c_longdouble_type and a_info.storage != .f80) {
1506 // These are strange: we'll sometimes represent them as f128, even if the1558 // These are strange: we'll sometimes represent them as f128, even if the
1507 // underlying type is smaller. f80 is an exception: see float_c_longdouble_f80.1559 // underlying type is smaller. f80 is an exception: see float_c_longdouble_f80.
1508 const a_val = switch (a_info.storage) {1560 const a_val: u128 = switch (a_info.storage) {
1509 inline else => |val| @as(u128, @bitCast(@as(f128, @floatCast(val)))),1561 inline else => |val| @bitCast(@as(f128, @floatCast(val))),
1510 };1562 };
1511 const b_val = switch (b_info.storage) {1563 const b_val: u128 = switch (b_info.storage) {
1512 inline else => |val| @as(u128, @bitCast(@as(f128, @floatCast(val)))),1564 inline else => |val| @bitCast(@as(f128, @floatCast(val))),
1513 };1565 };
1514 return a_val == b_val;1566 return a_val == b_val;
1515 }1567 }
...@@ -1560,11 +1612,11 @@ pub const Key = union(enum) {...@@ -1560,11 +1612,11 @@ pub const Key = union(enum) {
1560 const len = ip.aggregateTypeLen(a_info.ty);1612 const len = ip.aggregateTypeLen(a_info.ty);
1561 const StorageTag = @typeInfo(Key.Aggregate.Storage).Union.tag_type.?;1613 const StorageTag = @typeInfo(Key.Aggregate.Storage).Union.tag_type.?;
1562 if (@as(StorageTag, a_info.storage) != @as(StorageTag, b_info.storage)) {1614 if (@as(StorageTag, a_info.storage) != @as(StorageTag, b_info.storage)) {
1563 for (0..@as(usize, @intCast(len))) |elem_index| {1615 for (0..@intCast(len)) |elem_index| {
1564 const a_elem = switch (a_info.storage) {1616 const a_elem = switch (a_info.storage) {
1565 .bytes => |bytes| ip.getIfExists(.{ .int = .{1617 .bytes => |bytes| ip.getIfExists(.{ .int = .{
1566 .ty = .u8_type,1618 .ty = .u8_type,
1567 .storage = .{ .u64 = bytes[elem_index] },1619 .storage = .{ .u64 = bytes.at(elem_index, ip) },
1568 } }) orelse return false,1620 } }) orelse return false,
1569 .elems => |elems| elems[elem_index],1621 .elems => |elems| elems[elem_index],
1570 .repeated_elem => |elem| elem,1622 .repeated_elem => |elem| elem,
...@@ -1572,7 +1624,7 @@ pub const Key = union(enum) {...@@ -1572,7 +1624,7 @@ pub const Key = union(enum) {
1572 const b_elem = switch (b_info.storage) {1624 const b_elem = switch (b_info.storage) {
1573 .bytes => |bytes| ip.getIfExists(.{ .int = .{1625 .bytes => |bytes| ip.getIfExists(.{ .int = .{
1574 .ty = .u8_type,1626 .ty = .u8_type,
1575 .storage = .{ .u64 = bytes[elem_index] },1627 .storage = .{ .u64 = bytes.at(elem_index, ip) },
1576 } }) orelse return false,1628 } }) orelse return false,
1577 .elems => |elems| elems[elem_index],1629 .elems => |elems| elems[elem_index],
1578 .repeated_elem => |elem| elem,1630 .repeated_elem => |elem| elem,
...@@ -1585,18 +1637,15 @@ pub const Key = union(enum) {...@@ -1585,18 +1637,15 @@ pub const Key = union(enum) {
1585 switch (a_info.storage) {1637 switch (a_info.storage) {
1586 .bytes => |a_bytes| {1638 .bytes => |a_bytes| {
1587 const b_bytes = b_info.storage.bytes;1639 const b_bytes = b_info.storage.bytes;
1588 return std.mem.eql(1640 return a_bytes == b_bytes or
1589 u8,1641 std.mem.eql(u8, a_bytes.toSlice(len, ip), b_bytes.toSlice(len, ip));
1590 a_bytes[0..@as(usize, @intCast(len))],
1591 b_bytes[0..@as(usize, @intCast(len))],
1592 );
1593 },1642 },
1594 .elems => |a_elems| {1643 .elems => |a_elems| {
1595 const b_elems = b_info.storage.elems;1644 const b_elems = b_info.storage.elems;
1596 return std.mem.eql(1645 return std.mem.eql(
1597 Index,1646 Index,
1598 a_elems[0..@as(usize, @intCast(len))],1647 a_elems[0..@intCast(len)],
1599 b_elems[0..@as(usize, @intCast(len))],1648 b_elems[0..@intCast(len)],
1600 );1649 );
1601 },1650 },
1602 .repeated_elem => |a_elem| {1651 .repeated_elem => |a_elem| {
...@@ -4175,10 +4224,10 @@ pub const Float64 = struct {...@@ -4175,10 +4224,10 @@ pub const Float64 = struct {
4175 }4224 }
41764225
4177 fn pack(val: f64) Float64 {4226 fn pack(val: f64) Float64 {
4178 const bits = @as(u64, @bitCast(val));4227 const bits: u64 = @bitCast(val);
4179 return .{4228 return .{
4180 .piece0 = @as(u32, @truncate(bits)),4229 .piece0 = @truncate(bits),
4181 .piece1 = @as(u32, @truncate(bits >> 32)),4230 .piece1 = @truncate(bits >> 32),
4182 };4231 };
4183 }4232 }
4184};4233};
...@@ -4197,11 +4246,11 @@ pub const Float80 = struct {...@@ -4197,11 +4246,11 @@ pub const Float80 = struct {
4197 }4246 }
41984247
4199 fn pack(val: f80) Float80 {4248 fn pack(val: f80) Float80 {
4200 const bits = @as(u80, @bitCast(val));4249 const bits: u80 = @bitCast(val);
4201 return .{4250 return .{
4202 .piece0 = @as(u32, @truncate(bits)),4251 .piece0 = @truncate(bits),
4203 .piece1 = @as(u32, @truncate(bits >> 32)),4252 .piece1 = @truncate(bits >> 32),
4204 .piece2 = @as(u16, @truncate(bits >> 64)),4253 .piece2 = @truncate(bits >> 64),
4205 };4254 };
4206 }4255 }
4207};4256};
...@@ -4222,12 +4271,12 @@ pub const Float128 = struct {...@@ -4222,12 +4271,12 @@ pub const Float128 = struct {
4222 }4271 }
42234272
4224 fn pack(val: f128) Float128 {4273 fn pack(val: f128) Float128 {
4225 const bits = @as(u128, @bitCast(val));4274 const bits: u128 = @bitCast(val);
4226 return .{4275 return .{
4227 .piece0 = @as(u32, @truncate(bits)),4276 .piece0 = @truncate(bits),
4228 .piece1 = @as(u32, @truncate(bits >> 32)),4277 .piece1 = @truncate(bits >> 32),
4229 .piece2 = @as(u32, @truncate(bits >> 64)),4278 .piece2 = @truncate(bits >> 64),
4230 .piece3 = @as(u32, @truncate(bits >> 96)),4279 .piece3 = @truncate(bits >> 96),
4231 };4280 };
4232 }4281 }
4233};4282};
...@@ -4244,7 +4293,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void {...@@ -4244,7 +4293,7 @@ pub fn init(ip: *InternPool, gpa: Allocator) !void {
4244 assert(ip.items.len == 0);4293 assert(ip.items.len == 0);
42454294
4246 // Reserve string index 0 for an empty string.4295 // Reserve string index 0 for an empty string.
4247 assert((try ip.getOrPutString(gpa, "")) == .empty);4296 assert((try ip.getOrPutString(gpa, "", .no_embedded_nulls)) == .empty);
42484297
4249 // So that we can use `catch unreachable` below.4298 // So that we can use `catch unreachable` below.
4250 try ip.items.ensureUnusedCapacity(gpa, static_keys.len);4299 try ip.items.ensureUnusedCapacity(gpa, static_keys.len);
...@@ -4329,13 +4378,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -4329,13 +4378,13 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
4329 .type_int_signed => .{4378 .type_int_signed => .{
4330 .int_type = .{4379 .int_type = .{
4331 .signedness = .signed,4380 .signedness = .signed,
4332 .bits = @as(u16, @intCast(data)),4381 .bits = @intCast(data),
4333 },4382 },
4334 },4383 },
4335 .type_int_unsigned => .{4384 .type_int_unsigned => .{
4336 .int_type = .{4385 .int_type = .{
4337 .signedness = .unsigned,4386 .signedness = .unsigned,
4338 .bits = @as(u16, @intCast(data)),4387 .bits = @intCast(data),
4339 },4388 },
4340 },4389 },
4341 .type_array_big => {4390 .type_array_big => {
...@@ -4354,8 +4403,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -4354,8 +4403,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
4354 .sentinel = .none,4403 .sentinel = .none,
4355 } };4404 } };
4356 },4405 },
4357 .simple_type => .{ .simple_type = @as(SimpleType, @enumFromInt(data)) },4406 .simple_type => .{ .simple_type = @enumFromInt(data) },
4358 .simple_value => .{ .simple_value = @as(SimpleValue, @enumFromInt(data)) },4407 .simple_value => .{ .simple_value = @enumFromInt(data) },
43594408
4360 .type_vector => {4409 .type_vector => {
4361 const vector_info = ip.extraData(Vector, data);4410 const vector_info = ip.extraData(Vector, data);
...@@ -4506,9 +4555,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -4506,9 +4555,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
4506 } },4555 } },
4507 .type_function => .{ .func_type = ip.extraFuncType(data) },4556 .type_function => .{ .func_type = ip.extraFuncType(data) },
45084557
4509 .undef => .{ .undef = @as(Index, @enumFromInt(data)) },4558 .undef => .{ .undef = @enumFromInt(data) },
4510 .opt_null => .{ .opt = .{4559 .opt_null => .{ .opt = .{
4511 .ty = @as(Index, @enumFromInt(data)),4560 .ty = @enumFromInt(data),
4512 .val = .none,4561 .val = .none,
4513 } },4562 } },
4514 .opt_payload => {4563 .opt_payload => {
...@@ -4670,11 +4719,11 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -4670,11 +4719,11 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
4670 },4719 },
4671 .float_f16 => .{ .float = .{4720 .float_f16 => .{ .float = .{
4672 .ty = .f16_type,4721 .ty = .f16_type,
4673 .storage = .{ .f16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },4722 .storage = .{ .f16 = @bitCast(@as(u16, @intCast(data))) },
4674 } },4723 } },
4675 .float_f32 => .{ .float = .{4724 .float_f32 => .{ .float = .{
4676 .ty = .f32_type,4725 .ty = .f32_type,
4677 .storage = .{ .f32 = @as(f32, @bitCast(data)) },4726 .storage = .{ .f32 = @bitCast(data) },
4678 } },4727 } },
4679 .float_f64 => .{ .float = .{4728 .float_f64 => .{ .float = .{
4680 .ty = .f64_type,4729 .ty = .f64_type,
...@@ -4771,10 +4820,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -4771,10 +4820,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
4771 },4820 },
4772 .bytes => {4821 .bytes => {
4773 const extra = ip.extraData(Bytes, data);4822 const extra = ip.extraData(Bytes, data);
4774 const len: u32 = @intCast(ip.aggregateTypeLenIncludingSentinel(extra.ty));
4775 return .{ .aggregate = .{4823 return .{ .aggregate = .{
4776 .ty = extra.ty,4824 .ty = extra.ty,
4777 .storage = .{ .bytes = ip.string_bytes.items[@intFromEnum(extra.bytes)..][0..len] },4825 .storage = .{ .bytes = extra.bytes },
4778 } };4826 } };
4779 },4827 },
4780 .aggregate => {4828 .aggregate => {
...@@ -4809,14 +4857,14 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -4809,14 +4857,14 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
4809 .val = .{ .payload = extra.val },4857 .val = .{ .payload = extra.val },
4810 } };4858 } };
4811 },4859 },
4812 .enum_literal => .{ .enum_literal = @as(NullTerminatedString, @enumFromInt(data)) },4860 .enum_literal => .{ .enum_literal = @enumFromInt(data) },
4813 .enum_tag => .{ .enum_tag = ip.extraData(Tag.EnumTag, data) },4861 .enum_tag => .{ .enum_tag = ip.extraData(Tag.EnumTag, data) },
48144862
4815 .memoized_call => {4863 .memoized_call => {
4816 const extra = ip.extraDataTrail(MemoizedCall, data);4864 const extra = ip.extraDataTrail(MemoizedCall, data);
4817 return .{ .memoized_call = .{4865 return .{ .memoized_call = .{
4818 .func = extra.data.func,4866 .func = extra.data.func,
4819 .arg_values = @as([]const Index, @ptrCast(ip.extra.items[extra.end..][0..extra.data.args_len])),4867 .arg_values = @ptrCast(ip.extra.items[extra.end..][0..extra.data.args_len]),
4820 .result = extra.data.result,4868 .result = extra.data.result,
4821 } };4869 } };
4822 },4870 },
...@@ -5596,9 +5644,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -5596,9 +5644,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
5596 switch (aggregate.storage) {5644 switch (aggregate.storage) {
5597 .bytes => |bytes| {5645 .bytes => |bytes| {
5598 assert(child == .u8_type);5646 assert(child == .u8_type);
5599 if (bytes.len != len) {5647 if (sentinel != .none) {
5600 assert(bytes.len == len_including_sentinel);5648 assert(bytes.at(@intCast(len), ip) == ip.indexToKey(sentinel).int.storage.u64);
5601 assert(bytes[@intCast(len)] == ip.indexToKey(sentinel).int.storage.u64);
5602 }5649 }
5603 },5650 },
5604 .elems => |elems| {5651 .elems => |elems| {
...@@ -5641,11 +5688,16 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -5641,11 +5688,16 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
5641 switch (ty_key) {5688 switch (ty_key) {
5642 .anon_struct_type => |anon_struct_type| opv: {5689 .anon_struct_type => |anon_struct_type| opv: {
5643 switch (aggregate.storage) {5690 switch (aggregate.storage) {
5644 .bytes => |bytes| for (anon_struct_type.values.get(ip), bytes) |value, byte| {5691 .bytes => |bytes| for (anon_struct_type.values.get(ip), bytes.at(0, ip)..) |value, byte| {
5645 if (value != ip.getIfExists(.{ .int = .{5692 if (value == .none) break :opv;
5646 .ty = .u8_type,5693 switch (ip.indexToKey(value)) {
5647 .storage = .{ .u64 = byte },5694 .undef => break :opv,
5648 } })) break :opv;5695 .int => |int| switch (int.storage) {
5696 .u64 => |x| if (x != byte) break :opv,
5697 else => break :opv,
5698 },
5699 else => unreachable,
5700 }
5649 },5701 },
5650 .elems => |elems| if (!std.mem.eql(5702 .elems => |elems| if (!std.mem.eql(
5651 Index,5703 Index,
...@@ -5670,9 +5722,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -5670,9 +5722,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
56705722
5671 repeated: {5723 repeated: {
5672 switch (aggregate.storage) {5724 switch (aggregate.storage) {
5673 .bytes => |bytes| for (bytes[1..@as(usize, @intCast(len))]) |byte|5725 .bytes => |bytes| for (bytes.toSlice(len, ip)[1..]) |byte|
5674 if (byte != bytes[0]) break :repeated,5726 if (byte != bytes.at(0, ip)) break :repeated,
5675 .elems => |elems| for (elems[1..@as(usize, @intCast(len))]) |elem|5727 .elems => |elems| for (elems[1..@intCast(len)]) |elem|
5676 if (elem != elems[0]) break :repeated,5728 if (elem != elems[0]) break :repeated,
5677 .repeated_elem => {},5729 .repeated_elem => {},
5678 }5730 }
...@@ -5681,7 +5733,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -5681,7 +5733,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
5681 _ = ip.map.pop();5733 _ = ip.map.pop();
5682 const elem = try ip.get(gpa, .{ .int = .{5734 const elem = try ip.get(gpa, .{ .int = .{
5683 .ty = .u8_type,5735 .ty = .u8_type,
5684 .storage = .{ .u64 = bytes[0] },5736 .storage = .{ .u64 = bytes.at(0, ip) },
5685 } });5737 } });
5686 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);5738 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);
5687 try ip.items.ensureUnusedCapacity(gpa, 1);5739 try ip.items.ensureUnusedCapacity(gpa, 1);
...@@ -5710,7 +5762,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -5710,7 +5762,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
5710 try ip.string_bytes.ensureUnusedCapacity(gpa, @intCast(len_including_sentinel + 1));5762 try ip.string_bytes.ensureUnusedCapacity(gpa, @intCast(len_including_sentinel + 1));
5711 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len);5763 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len);
5712 switch (aggregate.storage) {5764 switch (aggregate.storage) {
5713 .bytes => |bytes| ip.string_bytes.appendSliceAssumeCapacity(bytes[0..@intCast(len)]),5765 .bytes => |bytes| ip.string_bytes.appendSliceAssumeCapacity(bytes.toSlice(len, ip)),
5714 .elems => |elems| for (elems[0..@intCast(len)]) |elem| switch (ip.indexToKey(elem)) {5766 .elems => |elems| for (elems[0..@intCast(len)]) |elem| switch (ip.indexToKey(elem)) {
5715 .undef => {5767 .undef => {
5716 ip.string_bytes.shrinkRetainingCapacity(string_bytes_index);5768 ip.string_bytes.shrinkRetainingCapacity(string_bytes_index);
...@@ -5730,15 +5782,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -5730,15 +5782,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
5730 else => unreachable,5782 else => unreachable,
5731 },5783 },
5732 }5784 }
5733 const has_internal_null =
5734 std.mem.indexOfScalar(u8, ip.string_bytes.items[string_bytes_index..], 0) != null;
5735 if (sentinel != .none) ip.string_bytes.appendAssumeCapacity(5785 if (sentinel != .none) ip.string_bytes.appendAssumeCapacity(
5736 @intCast(ip.indexToKey(sentinel).int.storage.u64),5786 @intCast(ip.indexToKey(sentinel).int.storage.u64),
5737 );5787 );
5738 const string: String = if (has_internal_null)5788 const string = try ip.getOrPutTrailingString(
5739 @enumFromInt(string_bytes_index)5789 gpa,
5740 else5790 @intCast(len_including_sentinel),
5741 (try ip.getOrPutTrailingString(gpa, @intCast(len_including_sentinel))).toString();5791 .maybe_embedded_nulls,
5792 );
5742 ip.items.appendAssumeCapacity(.{5793 ip.items.appendAssumeCapacity(.{
5743 .tag = .bytes,5794 .tag = .bytes,
5744 .data = ip.addExtraAssumeCapacity(Bytes{5795 .data = ip.addExtraAssumeCapacity(Bytes{
...@@ -5780,7 +5831,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -5780,7 +5831,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
5780 .tag = .memoized_call,5831 .tag = .memoized_call,
5781 .data = ip.addExtraAssumeCapacity(MemoizedCall{5832 .data = ip.addExtraAssumeCapacity(MemoizedCall{
5782 .func = memoized_call.func,5833 .func = memoized_call.func,
5783 .args_len = @as(u32, @intCast(memoized_call.arg_values.len)),5834 .args_len = @intCast(memoized_call.arg_values.len),
5784 .result = memoized_call.result,5835 .result = memoized_call.result,
5785 }),5836 }),
5786 });5837 });
...@@ -6753,7 +6804,7 @@ fn finishFuncInstance(...@@ -6753,7 +6804,7 @@ fn finishFuncInstance(
6753 const decl = ip.declPtr(decl_index);6804 const decl = ip.declPtr(decl_index);
6754 decl.name = try ip.getOrPutStringFmt(gpa, "{}__anon_{d}", .{6805 decl.name = try ip.getOrPutStringFmt(gpa, "{}__anon_{d}", .{
6755 fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index),6806 fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index),
6756 });6807 }, .no_embedded_nulls);
67576808
6758 return func_index;6809 return func_index;
6759}6810}
...@@ -7216,7 +7267,7 @@ pub fn remove(ip: *InternPool, index: Index) void {...@@ -7216,7 +7267,7 @@ pub fn remove(ip: *InternPool, index: Index) void {
7216}7267}
72177268
7218fn addInt(ip: *InternPool, gpa: Allocator, ty: Index, tag: Tag, limbs: []const Limb) !void {7269fn addInt(ip: *InternPool, gpa: Allocator, ty: Index, tag: Tag, limbs: []const Limb) !void {
7219 const limbs_len = @as(u32, @intCast(limbs.len));7270 const limbs_len: u32 = @intCast(limbs.len);
7220 try ip.reserveLimbs(gpa, @typeInfo(Int).Struct.fields.len + limbs_len);7271 try ip.reserveLimbs(gpa, @typeInfo(Int).Struct.fields.len + limbs_len);
7221 ip.items.appendAssumeCapacity(.{7272 ip.items.appendAssumeCapacity(.{
7222 .tag = tag,7273 .tag = tag,
...@@ -7235,7 +7286,7 @@ fn addExtra(ip: *InternPool, gpa: Allocator, extra: anytype) Allocator.Error!u32...@@ -7235,7 +7286,7 @@ fn addExtra(ip: *InternPool, gpa: Allocator, extra: anytype) Allocator.Error!u32
7235}7286}
72367287
7237fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {7288fn addExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
7238 const result = @as(u32, @intCast(ip.extra.items.len));7289 const result: u32 = @intCast(ip.extra.items.len);
7239 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {7290 inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
7240 ip.extra.appendAssumeCapacity(switch (field.type) {7291 ip.extra.appendAssumeCapacity(switch (field.type) {
7241 Index,7292 Index,
...@@ -7286,7 +7337,7 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {...@@ -7286,7 +7337,7 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
7286 @sizeOf(u64) => {},7337 @sizeOf(u64) => {},
7287 else => @compileError("unsupported host"),7338 else => @compileError("unsupported host"),
7288 }7339 }
7289 const result = @as(u32, @intCast(ip.limbs.items.len));7340 const result: u32 = @intCast(ip.limbs.items.len);
7290 inline for (@typeInfo(@TypeOf(extra)).Struct.fields, 0..) |field, i| {7341 inline for (@typeInfo(@TypeOf(extra)).Struct.fields, 0..) |field, i| {
7291 const new: u32 = switch (field.type) {7342 const new: u32 = switch (field.type) {
7292 u32 => @field(extra, field.name),7343 u32 => @field(extra, field.name),
...@@ -7374,7 +7425,7 @@ fn limbData(ip: *const InternPool, comptime T: type, index: usize) T {...@@ -7374,7 +7425,7 @@ fn limbData(ip: *const InternPool, comptime T: type, index: usize) T {
73747425
7375 @field(result, field.name) = switch (field.type) {7426 @field(result, field.name) = switch (field.type) {
7376 u32 => int32,7427 u32 => int32,
7377 Index => @as(Index, @enumFromInt(int32)),7428 Index => @enumFromInt(int32),
7378 else => @compileError("bad field type: " ++ @typeName(field.type)),7429 else => @compileError("bad field type: " ++ @typeName(field.type)),
7379 };7430 };
7380 }7431 }
...@@ -7410,8 +7461,8 @@ fn limbsSliceToIndex(ip: *const InternPool, limbs: []const Limb) LimbsAsIndexes...@@ -7410,8 +7461,8 @@ fn limbsSliceToIndex(ip: *const InternPool, limbs: []const Limb) LimbsAsIndexes
7410 };7461 };
7411 // TODO: https://github.com/ziglang/zig/issues/17387462 // TODO: https://github.com/ziglang/zig/issues/1738
7412 return .{7463 return .{
7413 .start = @as(u32, @intCast(@divExact(@intFromPtr(limbs.ptr) - @intFromPtr(host_slice.ptr), @sizeOf(Limb)))),7464 .start = @intCast(@divExact(@intFromPtr(limbs.ptr) - @intFromPtr(host_slice.ptr), @sizeOf(Limb))),
7414 .len = @as(u32, @intCast(limbs.len)),7465 .len = @intCast(limbs.len),
7415 };7466 };
7416}7467}
74177468
...@@ -7683,7 +7734,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al...@@ -7683,7 +7734,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
7683 .val = error_union.val,7734 .val = error_union.val,
7684 } }),7735 } }),
7685 .aggregate => |aggregate| {7736 .aggregate => |aggregate| {
7686 const new_len = @as(usize, @intCast(ip.aggregateTypeLen(new_ty)));7737 const new_len: usize = @intCast(ip.aggregateTypeLen(new_ty));
7687 direct: {7738 direct: {
7688 const old_ty_child = switch (ip.indexToKey(old_ty)) {7739 const old_ty_child = switch (ip.indexToKey(old_ty)) {
7689 inline .array_type, .vector_type => |seq_type| seq_type.child,7740 inline .array_type, .vector_type => |seq_type| seq_type.child,
...@@ -7696,16 +7747,11 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al...@@ -7696,16 +7747,11 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
7696 else => unreachable,7747 else => unreachable,
7697 };7748 };
7698 if (old_ty_child != new_ty_child) break :direct;7749 if (old_ty_child != new_ty_child) break :direct;
7699 // TODO: write something like getCoercedInts to avoid needing to dupe here
7700 switch (aggregate.storage) {7750 switch (aggregate.storage) {
7701 .bytes => |bytes| {7751 .bytes => |bytes| return ip.get(gpa, .{ .aggregate = .{
7702 const bytes_copy = try gpa.dupe(u8, bytes[0..new_len]);7752 .ty = new_ty,
7703 defer gpa.free(bytes_copy);7753 .storage = .{ .bytes = bytes },
7704 return ip.get(gpa, .{ .aggregate = .{7754 } }),
7705 .ty = new_ty,
7706 .storage = .{ .bytes = bytes_copy },
7707 } });
7708 },
7709 .elems => |elems| {7755 .elems => |elems| {
7710 const elems_copy = try gpa.dupe(Index, elems[0..new_len]);7756 const elems_copy = try gpa.dupe(Index, elems[0..new_len]);
7711 defer gpa.free(elems_copy);7757 defer gpa.free(elems_copy);
...@@ -7729,14 +7775,13 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al...@@ -7729,14 +7775,13 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
7729 // lifetime issues, since it'll allow us to avoid referencing `aggregate` after we7775 // lifetime issues, since it'll allow us to avoid referencing `aggregate` after we
7730 // begin interning elems.7776 // begin interning elems.
7731 switch (aggregate.storage) {7777 switch (aggregate.storage) {
7732 .bytes => {7778 .bytes => |bytes| {
7733 // We have to intern each value here, so unfortunately we can't easily avoid7779 // We have to intern each value here, so unfortunately we can't easily avoid
7734 // the repeated indexToKey calls.7780 // the repeated indexToKey calls.
7735 for (agg_elems, 0..) |*elem, i| {7781 for (agg_elems, 0..) |*elem, index| {
7736 const x = ip.indexToKey(val).aggregate.storage.bytes[i];
7737 elem.* = try ip.get(gpa, .{ .int = .{7782 elem.* = try ip.get(gpa, .{ .int = .{
7738 .ty = .u8_type,7783 .ty = .u8_type,
7739 .storage = .{ .u64 = x },7784 .storage = .{ .u64 = bytes.at(index, ip) },
7740 } });7785 } });
7741 }7786 }
7742 },7787 },
...@@ -8169,9 +8214,8 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {...@@ -8169,9 +8214,8 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
81698214
8170 .bytes => b: {8215 .bytes => b: {
8171 const info = ip.extraData(Bytes, data);8216 const info = ip.extraData(Bytes, data);
8172 const len = @as(u32, @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)));8217 const len: usize = @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty));
8173 break :b @sizeOf(Bytes) + len +8218 break :b @sizeOf(Bytes) + len + @intFromBool(info.bytes.at(len - 1, ip) != 0);
8174 @intFromBool(ip.string_bytes.items[@intFromEnum(info.bytes) + len - 1] != 0);
8175 },8219 },
8176 .aggregate => b: {8220 .aggregate => b: {
8177 const info = ip.extraData(Tag.Aggregate, data);8221 const info = ip.extraData(Tag.Aggregate, data);
...@@ -8434,15 +8478,35 @@ pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex)...@@ -8434,15 +8478,35 @@ pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex)
8434 };8478 };
8435}8479}
84368480
8481const EmbeddedNulls = enum {
8482 no_embedded_nulls,
8483 maybe_embedded_nulls,
8484
8485 fn StringType(comptime embedded_nulls: EmbeddedNulls) type {
8486 return switch (embedded_nulls) {
8487 .no_embedded_nulls => NullTerminatedString,
8488 .maybe_embedded_nulls => String,
8489 };
8490 }
8491
8492 fn OptionalStringType(comptime embedded_nulls: EmbeddedNulls) type {
8493 return switch (embedded_nulls) {
8494 .no_embedded_nulls => OptionalNullTerminatedString,
8495 .maybe_embedded_nulls => OptionalString,
8496 };
8497 }
8498};
8499
8437pub fn getOrPutString(8500pub fn getOrPutString(
8438 ip: *InternPool,8501 ip: *InternPool,
8439 gpa: Allocator,8502 gpa: Allocator,
8440 s: []const u8,8503 slice: []const u8,
8441) Allocator.Error!NullTerminatedString {8504 comptime embedded_nulls: EmbeddedNulls,
8442 try ip.string_bytes.ensureUnusedCapacity(gpa, s.len + 1);8505) Allocator.Error!embedded_nulls.StringType() {
8443 ip.string_bytes.appendSliceAssumeCapacity(s);8506 try ip.string_bytes.ensureUnusedCapacity(gpa, slice.len + 1);
8507 ip.string_bytes.appendSliceAssumeCapacity(slice);
8444 ip.string_bytes.appendAssumeCapacity(0);8508 ip.string_bytes.appendAssumeCapacity(0);
8445 return ip.getOrPutTrailingString(gpa, s.len + 1);8509 return ip.getOrPutTrailingString(gpa, slice.len + 1, embedded_nulls);
8446}8510}
84478511
8448pub fn getOrPutStringFmt(8512pub fn getOrPutStringFmt(
...@@ -8450,23 +8514,24 @@ pub fn getOrPutStringFmt(...@@ -8450,23 +8514,24 @@ pub fn getOrPutStringFmt(
8450 gpa: Allocator,8514 gpa: Allocator,
8451 comptime format: []const u8,8515 comptime format: []const u8,
8452 args: anytype,8516 args: anytype,
8453) Allocator.Error!NullTerminatedString {8517 comptime embedded_nulls: EmbeddedNulls,
8518) Allocator.Error!embedded_nulls.StringType() {
8454 // ensure that references to string_bytes in args do not get invalidated8519 // ensure that references to string_bytes in args do not get invalidated
8455 const len: usize = @intCast(std.fmt.count(format, args) + 1);8520 const len: usize = @intCast(std.fmt.count(format, args) + 1);
8456 try ip.string_bytes.ensureUnusedCapacity(gpa, len);8521 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
8457 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;8522 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;
8458 ip.string_bytes.appendAssumeCapacity(0);8523 ip.string_bytes.appendAssumeCapacity(0);
8459 return ip.getOrPutTrailingString(gpa, len);8524 return ip.getOrPutTrailingString(gpa, len, embedded_nulls);
8460}8525}
84618526
8462pub fn getOrPutStringOpt(8527pub fn getOrPutStringOpt(
8463 ip: *InternPool,8528 ip: *InternPool,
8464 gpa: Allocator,8529 gpa: Allocator,
8465 optional_string: ?[]const u8,8530 slice: ?[]const u8,
8466) Allocator.Error!OptionalNullTerminatedString {8531 comptime embedded_nulls: EmbeddedNulls,
8467 const s = optional_string orelse return .none;8532) Allocator.Error!embedded_nulls.OptionalStringType() {
8468 const interned = try getOrPutString(ip, gpa, s);8533 const string = try getOrPutString(ip, gpa, slice orelse return .none, embedded_nulls);
8469 return interned.toOptional();8534 return string.toOptional();
8470}8535}
84718536
8472/// Uses the last len bytes of ip.string_bytes as the key.8537/// Uses the last len bytes of ip.string_bytes as the key.
...@@ -8474,7 +8539,8 @@ pub fn getOrPutTrailingString(...@@ -8474,7 +8539,8 @@ pub fn getOrPutTrailingString(
8474 ip: *InternPool,8539 ip: *InternPool,
8475 gpa: Allocator,8540 gpa: Allocator,
8476 len: usize,8541 len: usize,
8477) Allocator.Error!NullTerminatedString {8542 comptime embedded_nulls: EmbeddedNulls,
8543) Allocator.Error!embedded_nulls.StringType() {
8478 const string_bytes = &ip.string_bytes;8544 const string_bytes = &ip.string_bytes;
8479 const str_index: u32 = @intCast(string_bytes.items.len - len);8545 const str_index: u32 = @intCast(string_bytes.items.len - len);
8480 if (len > 0 and string_bytes.getLast() == 0) {8546 if (len > 0 and string_bytes.getLast() == 0) {
...@@ -8483,6 +8549,14 @@ pub fn getOrPutTrailingString(...@@ -8483,6 +8549,14 @@ pub fn getOrPutTrailingString(
8483 try string_bytes.ensureUnusedCapacity(gpa, 1);8549 try string_bytes.ensureUnusedCapacity(gpa, 1);
8484 }8550 }
8485 const key: []const u8 = string_bytes.items[str_index..];8551 const key: []const u8 = string_bytes.items[str_index..];
8552 const has_embedded_null = std.mem.indexOfScalar(u8, key, 0) != null;
8553 switch (embedded_nulls) {
8554 .no_embedded_nulls => assert(!has_embedded_null),
8555 .maybe_embedded_nulls => if (has_embedded_null) {
8556 string_bytes.appendAssumeCapacity(0);
8557 return @enumFromInt(str_index);
8558 },
8559 }
8486 const gop = try ip.string_table.getOrPutContextAdapted(gpa, key, std.hash_map.StringIndexAdapter{8560 const gop = try ip.string_table.getOrPutContextAdapted(gpa, key, std.hash_map.StringIndexAdapter{
8487 .bytes = string_bytes,8561 .bytes = string_bytes,
8488 }, std.hash_map.StringIndexContext{8562 }, std.hash_map.StringIndexContext{
...@@ -8498,58 +8572,10 @@ pub fn getOrPutTrailingString(...@@ -8498,58 +8572,10 @@ pub fn getOrPutTrailingString(
8498 }8572 }
8499}8573}
85008574
8501/// Uses the last len bytes of ip.string_bytes as the key.
8502pub fn getTrailingAggregate(
8503 ip: *InternPool,
8504 gpa: Allocator,
8505 ty: Index,
8506 len: usize,
8507) Allocator.Error!Index {
8508 try ip.items.ensureUnusedCapacity(gpa, 1);
8509 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len);
8510
8511 const str: String = @enumFromInt(ip.string_bytes.items.len - len);
8512 const adapter: KeyAdapter = .{ .intern_pool = ip };
8513 const gop = try ip.map.getOrPutAdapted(gpa, Key{ .aggregate = .{
8514 .ty = ty,
8515 .storage = .{ .bytes = ip.string_bytes.items[@intFromEnum(str)..] },
8516 } }, adapter);
8517 if (gop.found_existing) return @enumFromInt(gop.index);
8518
8519 ip.items.appendAssumeCapacity(.{
8520 .tag = .bytes,
8521 .data = ip.addExtraAssumeCapacity(Bytes{
8522 .ty = ty,
8523 .bytes = str,
8524 }),
8525 });
8526 return @enumFromInt(ip.items.len - 1);
8527}
8528
8529pub fn getString(ip: *InternPool, s: []const u8) OptionalNullTerminatedString {8575pub fn getString(ip: *InternPool, s: []const u8) OptionalNullTerminatedString {
8530 if (ip.string_table.getKeyAdapted(s, std.hash_map.StringIndexAdapter{8576 return if (ip.string_table.getKeyAdapted(s, std.hash_map.StringIndexAdapter{
8531 .bytes = &ip.string_bytes,8577 .bytes = &ip.string_bytes,
8532 })) |index| {8578 })) |index| @enumFromInt(index) else .none;
8533 return @as(NullTerminatedString, @enumFromInt(index)).toOptional();
8534 } else {
8535 return .none;
8536 }
8537}
8538
8539pub fn stringToSlice(ip: *const InternPool, s: NullTerminatedString) [:0]const u8 {
8540 const string_bytes = ip.string_bytes.items;
8541 const start = @intFromEnum(s);
8542 var end: usize = start;
8543 while (string_bytes[end] != 0) end += 1;
8544 return string_bytes[start..end :0];
8545}
8546
8547pub fn stringToSliceUnwrap(ip: *const InternPool, s: OptionalNullTerminatedString) ?[:0]const u8 {
8548 return ip.stringToSlice(s.unwrap() orelse return null);
8549}
8550
8551pub fn stringEqlSlice(ip: *const InternPool, a: NullTerminatedString, b: []const u8) bool {
8552 return std.mem.eql(u8, stringToSlice(ip, a), b);
8553}8579}
85548580
8555pub fn typeOf(ip: *const InternPool, index: Index) Index {8581pub fn typeOf(ip: *const InternPool, index: Index) Index {
...@@ -8767,7 +8793,7 @@ pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 {...@@ -8767,7 +8793,7 @@ pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 {
8767 return switch (ip.indexToKey(ty)) {8793 return switch (ip.indexToKey(ty)) {
8768 .struct_type => ip.loadStructType(ty).field_types.len,8794 .struct_type => ip.loadStructType(ty).field_types.len,
8769 .anon_struct_type => |anon_struct_type| anon_struct_type.types.len,8795 .anon_struct_type => |anon_struct_type| anon_struct_type.types.len,
8770 .array_type => |array_type| array_type.len + @intFromBool(array_type.sentinel != .none),8796 .array_type => |array_type| array_type.lenIncludingSentinel(),
8771 .vector_type => |vector_type| vector_type.len,8797 .vector_type => |vector_type| vector_type.len,
8772 else => unreachable,8798 else => unreachable,
8773 };8799 };
src/Module.zig+63-50
...@@ -763,11 +763,11 @@ pub const Namespace = struct {...@@ -763,11 +763,11 @@ pub const Namespace = struct {
763 ) !InternPool.NullTerminatedString {763 ) !InternPool.NullTerminatedString {
764 const ip = &zcu.intern_pool;764 const ip = &zcu.intern_pool;
765 const count = count: {765 const count = count: {
766 var count: usize = ip.stringToSlice(name).len + 1;766 var count: usize = name.length(ip) + 1;
767 var cur_ns = &ns;767 var cur_ns = &ns;
768 while (true) {768 while (true) {
769 const decl = zcu.declPtr(cur_ns.decl_index);769 const decl = zcu.declPtr(cur_ns.decl_index);
770 count += ip.stringToSlice(decl.name).len + 1;770 count += decl.name.length(ip) + 1;
771 cur_ns = zcu.namespacePtr(cur_ns.parent.unwrap() orelse {771 cur_ns = zcu.namespacePtr(cur_ns.parent.unwrap() orelse {
772 count += ns.file_scope.sub_file_path.len;772 count += ns.file_scope.sub_file_path.len;
773 break :count count;773 break :count count;
...@@ -793,7 +793,7 @@ pub const Namespace = struct {...@@ -793,7 +793,7 @@ pub const Namespace = struct {
793 };793 };
794 }794 }
795795
796 return ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);796 return ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start, .no_embedded_nulls);
797 }797 }
798798
799 pub fn getType(ns: Namespace, zcu: *Zcu) Type {799 pub fn getType(ns: Namespace, zcu: *Zcu) Type {
...@@ -980,17 +980,13 @@ pub const File = struct {...@@ -980,17 +980,13 @@ pub const File = struct {
980 const ip = &mod.intern_pool;980 const ip = &mod.intern_pool;
981 const start = ip.string_bytes.items.len;981 const start = ip.string_bytes.items.len;
982 try file.renderFullyQualifiedName(ip.string_bytes.writer(mod.gpa));982 try file.renderFullyQualifiedName(ip.string_bytes.writer(mod.gpa));
983 return ip.getOrPutTrailingString(mod.gpa, ip.string_bytes.items.len - start);983 return ip.getOrPutTrailingString(mod.gpa, ip.string_bytes.items.len - start, .no_embedded_nulls);
984 }984 }
985985
986 pub fn fullPath(file: File, ally: Allocator) ![]u8 {986 pub fn fullPath(file: File, ally: Allocator) ![]u8 {
987 return file.mod.root.joinString(ally, file.sub_file_path);987 return file.mod.root.joinString(ally, file.sub_file_path);
988 }988 }
989989
990 pub fn fullPathZ(file: File, ally: Allocator) ![:0]u8 {
991 return file.mod.root.joinStringZ(ally, file.sub_file_path);
992 }
993
994 pub fn dumpSrc(file: *File, src: LazySrcLoc) void {990 pub fn dumpSrc(file: *File, src: LazySrcLoc) void {
995 const loc = std.zig.findLineColumn(file.source.bytes, src);991 const loc = std.zig.findLineColumn(file.source.bytes, src);
996 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });992 std.debug.print("{s}:{d}:{d}\n", .{ file.sub_file_path, loc.line + 1, loc.column + 1 });
...@@ -2534,6 +2530,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void {...@@ -2534,6 +2530,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void {
2534 const name_ip = try zcu.intern_pool.getOrPutString(2530 const name_ip = try zcu.intern_pool.getOrPutString(
2535 zcu.gpa,2531 zcu.gpa,
2536 old_zir.nullTerminatedString(name_zir),2532 old_zir.nullTerminatedString(name_zir),
2533 .no_embedded_nulls,
2537 );2534 );
2538 try old_names.put(zcu.gpa, name_ip, {});2535 try old_names.put(zcu.gpa, name_ip, {});
2539 }2536 }
...@@ -2551,6 +2548,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void {...@@ -2551,6 +2548,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void {
2551 const name_ip = try zcu.intern_pool.getOrPutString(2548 const name_ip = try zcu.intern_pool.getOrPutString(
2552 zcu.gpa,2549 zcu.gpa,
2553 old_zir.nullTerminatedString(name_zir),2550 old_zir.nullTerminatedString(name_zir),
2551 .no_embedded_nulls,
2554 );2552 );
2555 if (!old_names.swapRemove(name_ip)) continue;2553 if (!old_names.swapRemove(name_ip)) continue;
2556 // Name added2554 // Name added
...@@ -3555,37 +3553,46 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -3555,37 +3553,46 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
3555 const gpa = mod.gpa;3553 const gpa = mod.gpa;
3556 const zir = decl.getFileScope(mod).zir;3554 const zir = decl.getFileScope(mod).zir;
35573555
3558 const builtin_type_target_index: InternPool.Index = blk: {3556 const builtin_type_target_index: InternPool.Index = ip_index: {
3559 const std_mod = mod.std_mod;3557 const std_mod = mod.std_mod;
3560 if (decl.getFileScope(mod).mod != std_mod) break :blk .none;3558 if (decl.getFileScope(mod).mod != std_mod) break :ip_index .none;
3561 // We're in the std module.3559 // We're in the std module.
3562 const std_file = (try mod.importPkg(std_mod)).file;3560 const std_file = (try mod.importPkg(std_mod)).file;
3563 const std_decl = mod.declPtr(std_file.root_decl.unwrap().?);3561 const std_decl = mod.declPtr(std_file.root_decl.unwrap().?);
3564 const std_namespace = std_decl.getInnerNamespace(mod).?;3562 const std_namespace = std_decl.getInnerNamespace(mod).?;
3565 const builtin_str = try ip.getOrPutString(gpa, "builtin");3563 const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls);
3566 const builtin_decl = mod.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, DeclAdapter{ .zcu = mod }) orelse break :blk .none);3564 const builtin_decl = mod.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, DeclAdapter{ .zcu = mod }) orelse break :ip_index .none);
3567 const builtin_namespace = builtin_decl.getInnerNamespaceIndex(mod).unwrap() orelse break :blk .none;3565 const builtin_namespace = builtin_decl.getInnerNamespaceIndex(mod).unwrap() orelse break :ip_index .none;
3568 if (decl.src_namespace != builtin_namespace) break :blk .none;3566 if (decl.src_namespace != builtin_namespace) break :ip_index .none;
3569 // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index.3567 // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index.
3570 for ([_]struct { []const u8, InternPool.Index }{3568 for ([_][]const u8{
3571 .{ "AtomicOrder", .atomic_order_type },3569 "AtomicOrder",
3572 .{ "AtomicRmwOp", .atomic_rmw_op_type },3570 "AtomicRmwOp",
3573 .{ "CallingConvention", .calling_convention_type },3571 "CallingConvention",
3574 .{ "AddressSpace", .address_space_type },3572 "AddressSpace",
3575 .{ "FloatMode", .float_mode_type },3573 "FloatMode",
3576 .{ "ReduceOp", .reduce_op_type },3574 "ReduceOp",
3577 .{ "CallModifier", .call_modifier_type },3575 "CallModifier",
3578 .{ "PrefetchOptions", .prefetch_options_type },3576 "PrefetchOptions",
3579 .{ "ExportOptions", .export_options_type },3577 "ExportOptions",
3580 .{ "ExternOptions", .extern_options_type },3578 "ExternOptions",
3581 .{ "Type", .type_info_type },3579 "Type",
3582 }) |pair| {3580 }, [_]InternPool.Index{
3583 const decl_name = ip.stringToSlice(decl.name);3581 .atomic_order_type,
3584 if (std.mem.eql(u8, decl_name, pair[0])) {3582 .atomic_rmw_op_type,
3585 break :blk pair[1];3583 .calling_convention_type,
3586 }3584 .address_space_type,
3585 .float_mode_type,
3586 .reduce_op_type,
3587 .call_modifier_type,
3588 .prefetch_options_type,
3589 .export_options_type,
3590 .extern_options_type,
3591 .type_info_type,
3592 }) |type_name, type_ip| {
3593 if (decl.name.eqlSlice(type_name, ip)) break :ip_index type_ip;
3587 }3594 }
3588 break :blk .none;3595 break :ip_index .none;
3589 };3596 };
35903597
3591 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));3598 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));
...@@ -3725,8 +3732,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -3725,8 +3732,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
3725 } else if (bytes.len == 0) {3732 } else if (bytes.len == 0) {
3726 return sema.fail(&block_scope, section_src, "linksection cannot be empty", .{});3733 return sema.fail(&block_scope, section_src, "linksection cannot be empty", .{});
3727 }3734 }
3728 const section = try ip.getOrPutString(gpa, bytes);3735 break :blk try ip.getOrPutStringOpt(gpa, bytes, .no_embedded_nulls);
3729 break :blk section.toOptional();
3730 };3736 };
3731 decl.@"addrspace" = blk: {3737 decl.@"addrspace" = blk: {
3732 const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_val.toIntern())) {3738 const addrspace_ctx: Sema.AddressSpaceContext = switch (ip.indexToKey(decl_val.toIntern())) {
...@@ -4101,7 +4107,10 @@ fn newEmbedFile(...@@ -4101,7 +4107,10 @@ fn newEmbedFile(
4101 .sentinel = .zero_u8,4107 .sentinel = .zero_u8,
4102 .child = .u8_type,4108 .child = .u8_type,
4103 } });4109 } });
4104 const array_val = try ip.getTrailingAggregate(gpa, array_ty, bytes.len);4110 const array_val = try ip.get(gpa, .{ .aggregate = .{
4111 .ty = array_ty,
4112 .storage = .{ .bytes = try ip.getOrPutTrailingString(gpa, bytes.len, .maybe_embedded_nulls) },
4113 } });
41054114
4106 const ptr_ty = (try mod.ptrType(.{4115 const ptr_ty = (try mod.ptrType(.{
4107 .child = array_ty,4116 .child = array_ty,
...@@ -4111,7 +4120,6 @@ fn newEmbedFile(...@@ -4111,7 +4120,6 @@ fn newEmbedFile(
4111 .address_space = .generic,4120 .address_space = .generic,
4112 },4121 },
4113 })).toIntern();4122 })).toIntern();
4114
4115 const ptr_val = try ip.get(gpa, .{ .ptr = .{4123 const ptr_val = try ip.get(gpa, .{ .ptr = .{
4116 .ty = ptr_ty,4124 .ty = ptr_ty,
4117 .addr = .{ .anon_decl = .{4125 .addr = .{ .anon_decl = .{
...@@ -4122,7 +4130,7 @@ fn newEmbedFile(...@@ -4122,7 +4130,7 @@ fn newEmbedFile(
41224130
4123 result.* = new_file;4131 result.* = new_file;
4124 new_file.* = .{4132 new_file.* = .{
4125 .sub_file_path = try ip.getOrPutString(gpa, sub_file_path),4133 .sub_file_path = try ip.getOrPutString(gpa, sub_file_path, .no_embedded_nulls),
4126 .owner = pkg,4134 .owner = pkg,
4127 .stat = stat,4135 .stat = stat,
4128 .val = ptr_val,4136 .val = ptr_val,
...@@ -4214,11 +4222,11 @@ const ScanDeclIter = struct {...@@ -4214,11 +4222,11 @@ const ScanDeclIter = struct {
4214 const zcu = iter.zcu;4222 const zcu = iter.zcu;
4215 const gpa = zcu.gpa;4223 const gpa = zcu.gpa;
4216 const ip = &zcu.intern_pool;4224 const ip = &zcu.intern_pool;
4217 var name = try ip.getOrPutStringFmt(gpa, fmt, args);4225 var name = try ip.getOrPutStringFmt(gpa, fmt, args, .no_embedded_nulls);
4218 var gop = try iter.seen_decls.getOrPut(gpa, name);4226 var gop = try iter.seen_decls.getOrPut(gpa, name);
4219 var next_suffix: u32 = 0;4227 var next_suffix: u32 = 0;
4220 while (gop.found_existing) {4228 while (gop.found_existing) {
4221 name = try ip.getOrPutStringFmt(gpa, fmt ++ "_{d}", args ++ .{next_suffix});4229 name = try ip.getOrPutStringFmt(gpa, "{}_{d}", .{ name.fmt(ip), next_suffix }, .no_embedded_nulls);
4222 gop = try iter.seen_decls.getOrPut(gpa, name);4230 gop = try iter.seen_decls.getOrPut(gpa, name);
4223 next_suffix += 1;4231 next_suffix += 1;
4224 }4232 }
...@@ -4300,7 +4308,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4300,7 +4308,11 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4300 };4308 };
4301 } else info: {4309 } else info: {
4302 if (iter.pass != .named) return;4310 if (iter.pass != .named) return;
4303 const name = try ip.getOrPutString(gpa, zir.nullTerminatedString(declaration.name.toString(zir).?));4311 const name = try ip.getOrPutString(
4312 gpa,
4313 zir.nullTerminatedString(declaration.name.toString(zir).?),
4314 .no_embedded_nulls,
4315 );
4304 try iter.seen_decls.putNoClobber(gpa, name, {});4316 try iter.seen_decls.putNoClobber(gpa, name, {});
4305 break :info .{4317 break :info .{
4306 name,4318 name,
...@@ -4362,9 +4374,10 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4362,9 +4374,10 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4362 if (!comp.config.is_test) break :a false;4374 if (!comp.config.is_test) break :a false;
4363 if (decl_mod != zcu.main_mod) break :a false;4375 if (decl_mod != zcu.main_mod) break :a false;
4364 if (is_named_test and comp.test_filters.len > 0) {4376 if (is_named_test and comp.test_filters.len > 0) {
4365 const decl_fqn = ip.stringToSlice(try namespace.fullyQualifiedName(zcu, decl_name));4377 const decl_fqn = try namespace.fullyQualifiedName(zcu, decl_name);
4378 const decl_fqn_slice = decl_fqn.toSlice(ip);
4366 for (comp.test_filters) |test_filter| {4379 for (comp.test_filters) |test_filter| {
4367 if (mem.indexOf(u8, decl_fqn, test_filter)) |_| break;4380 if (mem.indexOf(u8, decl_fqn_slice, test_filter)) |_| break;
4368 } else break :a false;4381 } else break :a false;
4369 }4382 }
4370 zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update4383 zcu.test_functions.putAssumeCapacity(decl_index, {}); // may clobber on incremental update
...@@ -4377,8 +4390,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void...@@ -4377,8 +4390,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4377 // `is_export` is unchanged. In this case, the incremental update mechanism will handle4390 // `is_export` is unchanged. In this case, the incremental update mechanism will handle
4378 // re-analysis for us if necessary.4391 // re-analysis for us if necessary.
4379 if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) {4392 if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) {
4380 log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{s}' decl_index={d}", .{4393 log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{
4381 namespace.file_scope.sub_file_path, ip.stringToSlice(decl_name), decl_index,4394 namespace.file_scope.sub_file_path, decl_name.fmt(ip), decl_index,
4382 });4395 });
4383 comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index });4396 comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index });
4384 }4397 }
...@@ -5300,7 +5313,7 @@ pub fn populateTestFunctions(...@@ -5300,7 +5313,7 @@ pub fn populateTestFunctions(
5300 const builtin_file = (mod.importPkg(builtin_mod) catch unreachable).file;5313 const builtin_file = (mod.importPkg(builtin_mod) catch unreachable).file;
5301 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);5314 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);
5302 const builtin_namespace = mod.namespacePtr(root_decl.src_namespace);5315 const builtin_namespace = mod.namespacePtr(root_decl.src_namespace);
5303 const test_functions_str = try ip.getOrPutString(gpa, "test_functions");5316 const test_functions_str = try ip.getOrPutString(gpa, "test_functions", .no_embedded_nulls);
5304 const decl_index = builtin_namespace.decls.getKeyAdapted(5317 const decl_index = builtin_namespace.decls.getKeyAdapted(
5305 test_functions_str,5318 test_functions_str,
5306 DeclAdapter{ .zcu = mod },5319 DeclAdapter{ .zcu = mod },
...@@ -5327,16 +5340,16 @@ pub fn populateTestFunctions(...@@ -5327,16 +5340,16 @@ pub fn populateTestFunctions(
53275340
5328 for (test_fn_vals, mod.test_functions.keys()) |*test_fn_val, test_decl_index| {5341 for (test_fn_vals, mod.test_functions.keys()) |*test_fn_val, test_decl_index| {
5329 const test_decl = mod.declPtr(test_decl_index);5342 const test_decl = mod.declPtr(test_decl_index);
5330 const test_decl_name = try gpa.dupe(u8, ip.stringToSlice(try test_decl.fullyQualifiedName(mod)));5343 const test_decl_name = try test_decl.fullyQualifiedName(mod);
5331 defer gpa.free(test_decl_name);5344 const test_decl_name_len = test_decl_name.length(ip);
5332 const test_name_anon_decl: InternPool.Key.Ptr.Addr.AnonDecl = n: {5345 const test_name_anon_decl: InternPool.Key.Ptr.Addr.AnonDecl = n: {
5333 const test_name_ty = try mod.arrayType(.{5346 const test_name_ty = try mod.arrayType(.{
5334 .len = test_decl_name.len,5347 .len = test_decl_name_len,
5335 .child = .u8_type,5348 .child = .u8_type,
5336 });5349 });
5337 const test_name_val = try mod.intern(.{ .aggregate = .{5350 const test_name_val = try mod.intern(.{ .aggregate = .{
5338 .ty = test_name_ty.toIntern(),5351 .ty = test_name_ty.toIntern(),
5339 .storage = .{ .bytes = test_decl_name },5352 .storage = .{ .bytes = test_decl_name.toString() },
5340 } });5353 } });
5341 break :n .{5354 break :n .{
5342 .orig_ty = (try mod.singleConstPtrType(test_name_ty)).toIntern(),5355 .orig_ty = (try mod.singleConstPtrType(test_name_ty)).toIntern(),
...@@ -5354,7 +5367,7 @@ pub fn populateTestFunctions(...@@ -5354,7 +5367,7 @@ pub fn populateTestFunctions(
5354 } }),5367 } }),
5355 .len = try mod.intern(.{ .int = .{5368 .len = try mod.intern(.{ .int = .{
5356 .ty = .usize_type,5369 .ty = .usize_type,
5357 .storage = .{ .u64 = test_decl_name.len },5370 .storage = .{ .u64 = test_decl_name_len },
5358 } }),5371 } }),
5359 } }),5372 } }),
5360 // func5373 // func
src/Sema.zig+325-256
...@@ -2059,12 +2059,12 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)...@@ -2059,12 +2059,12 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
2059 const st_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(stack_trace_ty));2059 const st_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(stack_trace_ty));
20602060
2061 // st.instruction_addresses = &addrs;2061 // st.instruction_addresses = &addrs;
2062 const instruction_addresses_field_name = try ip.getOrPutString(gpa, "instruction_addresses");2062 const instruction_addresses_field_name = try ip.getOrPutString(gpa, "instruction_addresses", .no_embedded_nulls);
2063 const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, instruction_addresses_field_name, src, true);2063 const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, instruction_addresses_field_name, src, true);
2064 try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store);2064 try sema.storePtr2(&err_trace_block, src, addr_field_ptr, src, addrs_ptr, src, .store);
20652065
2066 // st.index = 0;2066 // st.index = 0;
2067 const index_field_name = try ip.getOrPutString(gpa, "index");2067 const index_field_name = try ip.getOrPutString(gpa, "index", .no_embedded_nulls);
2068 const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, index_field_name, src, true);2068 const index_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, index_field_name, src, true);
2069 try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store);2069 try sema.storePtr2(&err_trace_block, src, index_field_ptr, src, .zero_usize, src, .store);
20702070
...@@ -2348,13 +2348,13 @@ fn failWithInvalidFieldAccess(...@@ -2348,13 +2348,13 @@ fn failWithInvalidFieldAccess(
2348fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.NullTerminatedString) bool {2348fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.NullTerminatedString) bool {
2349 const ip = &mod.intern_pool;2349 const ip = &mod.intern_pool;
2350 switch (ty.zigTypeTag(mod)) {2350 switch (ty.zigTypeTag(mod)) {
2351 .Array => return ip.stringEqlSlice(field_name, "len"),2351 .Array => return field_name.eqlSlice("len", ip),
2352 .Pointer => {2352 .Pointer => {
2353 const ptr_info = ty.ptrInfo(mod);2353 const ptr_info = ty.ptrInfo(mod);
2354 if (ptr_info.flags.size == .Slice) {2354 if (ptr_info.flags.size == .Slice) {
2355 return ip.stringEqlSlice(field_name, "ptr") or ip.stringEqlSlice(field_name, "len");2355 return field_name.eqlSlice("ptr", ip) or field_name.eqlSlice("len", ip);
2356 } else if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {2356 } else if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
2357 return ip.stringEqlSlice(field_name, "len");2357 return field_name.eqlSlice("len", ip);
2358 } else return false;2358 } else return false;
2359 },2359 },
2360 .Type, .Struct, .Union => return true,2360 .Type, .Struct, .Union => return true,
...@@ -2703,12 +2703,20 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2703,12 +2703,20 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2703 break :capture .{ .runtime = sema.typeOf(air_ref).toIntern() };2703 break :capture .{ .runtime = sema.typeOf(air_ref).toIntern() };
2704 }),2704 }),
2705 .decl_val => |str| capture: {2705 .decl_val => |str| capture: {
2706 const decl_name = try ip.getOrPutString(sema.gpa, sema.code.nullTerminatedString(str));2706 const decl_name = try ip.getOrPutString(
2707 sema.gpa,
2708 sema.code.nullTerminatedString(str),
2709 .no_embedded_nulls,
2710 );
2707 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?2711 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?
2708 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });2712 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });
2709 },2713 },
2710 .decl_ref => |str| capture: {2714 .decl_ref => |str| capture: {
2711 const decl_name = try ip.getOrPutString(sema.gpa, sema.code.nullTerminatedString(str));2715 const decl_name = try ip.getOrPutString(
2716 sema.gpa,
2717 sema.code.nullTerminatedString(str),
2718 .no_embedded_nulls,
2719 );
2712 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?2720 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?
2713 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });2721 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });
2714 },2722 },
...@@ -2882,7 +2890,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2882,7 +2890,7 @@ fn createAnonymousDeclTypeNamed(
28822890
2883 const name = mod.intern_pool.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{2891 const name = mod.intern_pool.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2884 src_decl.name.fmt(&mod.intern_pool), anon_prefix, @intFromEnum(new_decl_index),2892 src_decl.name.fmt(&mod.intern_pool), anon_prefix, @intFromEnum(new_decl_index),
2885 }) catch unreachable;2893 }, .no_embedded_nulls) catch unreachable;
2886 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);2894 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2887 return new_decl_index;2895 return new_decl_index;
2888 },2896 },
...@@ -2923,7 +2931,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2923,7 +2931,7 @@ fn createAnonymousDeclTypeNamed(
2923 };2931 };
29242932
2925 try writer.writeByte(')');2933 try writer.writeByte(')');
2926 const name = try mod.intern_pool.getOrPutString(gpa, buf.items);2934 const name = try mod.intern_pool.getOrPutString(gpa, buf.items, .no_embedded_nulls);
2927 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);2935 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2928 return new_decl_index;2936 return new_decl_index;
2929 },2937 },
...@@ -2937,8 +2945,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2937,8 +2945,7 @@ fn createAnonymousDeclTypeNamed(
29372945
2938 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}.{s}", .{2946 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}.{s}", .{
2939 src_decl.name.fmt(&mod.intern_pool), zir_data[i].str_op.getStr(sema.code),2947 src_decl.name.fmt(&mod.intern_pool), zir_data[i].str_op.getStr(sema.code),
2940 });2948 }, .no_embedded_nulls);
2941
2942 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);2949 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name);
2943 return new_decl_index;2950 return new_decl_index;
2944 },2951 },
...@@ -3157,7 +3164,7 @@ fn zirEnumDecl(...@@ -3157,7 +3164,7 @@ fn zirEnumDecl(
3157 const field_name_zir = sema.code.nullTerminatedString(field_name_index);3164 const field_name_zir = sema.code.nullTerminatedString(field_name_index);
3158 extra_index += 2; // field name, doc comment3165 extra_index += 2; // field name, doc comment
31593166
3160 const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir);3167 const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
31613168
3162 const tag_overflow = if (has_tag_value) overflow: {3169 const tag_overflow = if (has_tag_value) overflow: {
3163 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);3170 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
...@@ -3462,7 +3469,7 @@ fn zirErrorSetDecl(...@@ -3462,7 +3469,7 @@ fn zirErrorSetDecl(
3462 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string3469 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
3463 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);3470 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);
3464 const name = sema.code.nullTerminatedString(name_index);3471 const name = sema.code.nullTerminatedString(name_index);
3465 const name_ip = try mod.intern_pool.getOrPutString(gpa, name);3472 const name_ip = try mod.intern_pool.getOrPutString(gpa, name, .no_embedded_nulls);
3466 _ = try mod.getErrorValue(name_ip);3473 _ = try mod.getErrorValue(name_ip);
3467 const result = names.getOrPutAssumeCapacity(name_ip);3474 const result = names.getOrPutAssumeCapacity(name_ip);
3468 assert(!result.found_existing); // verified in AstGen3475 assert(!result.found_existing); // verified in AstGen
...@@ -3635,7 +3642,7 @@ fn indexablePtrLen(...@@ -3635,7 +3642,7 @@ fn indexablePtrLen(
3635 const is_pointer_to = object_ty.isSinglePointer(mod);3642 const is_pointer_to = object_ty.isSinglePointer(mod);
3636 const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty;3643 const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty;
3637 try checkIndexable(sema, block, src, indexable_ty);3644 try checkIndexable(sema, block, src, indexable_ty);
3638 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len");3645 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len", .no_embedded_nulls);
3639 return sema.fieldVal(block, src, object, field_name, src);3646 return sema.fieldVal(block, src, object, field_name, src);
3640}3647}
36413648
...@@ -3649,7 +3656,7 @@ fn indexablePtrLenOrNone(...@@ -3649,7 +3656,7 @@ fn indexablePtrLenOrNone(
3649 const operand_ty = sema.typeOf(operand);3656 const operand_ty = sema.typeOf(operand);
3650 try checkMemOperand(sema, block, src, operand_ty);3657 try checkMemOperand(sema, block, src, operand_ty);
3651 if (operand_ty.ptrSize(mod) == .Many) return .none;3658 if (operand_ty.ptrSize(mod) == .Many) return .none;
3652 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len");3659 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "len", .no_embedded_nulls);
3653 return sema.fieldVal(block, src, operand, field_name, src);3660 return sema.fieldVal(block, src, operand, field_name, src);
3654}3661}
36553662
...@@ -4363,7 +4370,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4363,7 +4370,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4363 }4370 }
4364 if (!object_ty.indexableHasLen(mod)) continue;4371 if (!object_ty.indexableHasLen(mod)) continue;
43654372
4366 break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, "len"), arg_src);4373 break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, "len", .no_embedded_nulls), arg_src);
4367 };4374 };
4368 const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src);4375 const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src);
4369 if (len == .none) {4376 if (len == .none) {
...@@ -4747,7 +4754,11 @@ fn validateUnionInit(...@@ -4747,7 +4754,11 @@ fn validateUnionInit(
4747 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;4754 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
4748 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };4755 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
4749 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;4756 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
4750 const field_name = try mod.intern_pool.getOrPutString(gpa, sema.code.nullTerminatedString(field_ptr_extra.field_name_start));4757 const field_name = try mod.intern_pool.getOrPutString(
4758 gpa,
4759 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
4760 .no_embedded_nulls,
4761 );
4751 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);4762 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);
4752 const air_tags = sema.air_instructions.items(.tag);4763 const air_tags = sema.air_instructions.items(.tag);
4753 const air_datas = sema.air_instructions.items(.data);4764 const air_datas = sema.air_instructions.items(.data);
...@@ -4890,6 +4901,7 @@ fn validateStructInit(...@@ -4890,6 +4901,7 @@ fn validateStructInit(
4890 const field_name = try ip.getOrPutString(4901 const field_name = try ip.getOrPutString(
4891 gpa,4902 gpa,
4892 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),4903 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
4904 .no_embedded_nulls,
4893 );4905 );
4894 field_index.* = if (struct_ty.isTuple(mod))4906 field_index.* = if (struct_ty.isTuple(mod))
4895 try sema.tupleFieldIndex(block, struct_ty, field_name, field_src)4907 try sema.tupleFieldIndex(block, struct_ty, field_name, field_src)
...@@ -5672,25 +5684,26 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v...@@ -5672,25 +5684,26 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
56725684
5673fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5685fn zirStr(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
5674 const bytes = sema.code.instructions.items(.data)[@intFromEnum(inst)].str.get(sema.code);5686 const bytes = sema.code.instructions.items(.data)[@intFromEnum(inst)].str.get(sema.code);
5675 return sema.addStrLitNoAlias(bytes);5687 return sema.addStrLit(
5688 try sema.mod.intern_pool.getOrPutString(sema.gpa, bytes, .maybe_embedded_nulls),
5689 bytes.len,
5690 );
5676}5691}
56775692
5678fn addStrLit(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref {5693fn addNullTerminatedStrLit(sema: *Sema, string: InternPool.NullTerminatedString) CompileError!Air.Inst.Ref {
5679 const duped_bytes = try sema.arena.dupe(u8, bytes);5694 return sema.addStrLit(string.toString(), string.length(&sema.mod.intern_pool));
5680 return addStrLitNoAlias(sema, duped_bytes);
5681}5695}
56825696
5683/// Safe to call when `bytes` does not point into `InternPool`.5697fn addStrLit(sema: *Sema, string: InternPool.String, len: u64) CompileError!Air.Inst.Ref {
5684fn addStrLitNoAlias(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref {
5685 const mod = sema.mod;5698 const mod = sema.mod;
5686 const array_ty = try mod.arrayType(.{5699 const array_ty = try mod.arrayType(.{
5687 .len = bytes.len,5700 .len = len,
5688 .sentinel = .zero_u8,5701 .sentinel = .zero_u8,
5689 .child = .u8_type,5702 .child = .u8_type,
5690 });5703 });
5691 const val = try mod.intern(.{ .aggregate = .{5704 const val = try mod.intern(.{ .aggregate = .{
5692 .ty = array_ty.toIntern(),5705 .ty = array_ty.toIntern(),
5693 .storage = .{ .bytes = bytes },5706 .storage = .{ .bytes = string },
5694 } });5707 } });
5695 return anonDeclRef(sema, val);5708 return anonDeclRef(sema, val);
5696}5709}
...@@ -6370,7 +6383,11 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -6370,7 +6383,11 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
6370 const src = inst_data.src();6383 const src = inst_data.src();
6371 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6384 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6372 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };6385 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
6373 const decl_name = try mod.intern_pool.getOrPutString(mod.gpa, sema.code.nullTerminatedString(extra.decl_name));6386 const decl_name = try mod.intern_pool.getOrPutString(
6387 mod.gpa,
6388 sema.code.nullTerminatedString(extra.decl_name),
6389 .no_embedded_nulls,
6390 );
6374 const decl_index = if (extra.namespace != .none) index_blk: {6391 const decl_index = if (extra.namespace != .none) index_blk: {
6375 const container_ty = try sema.resolveType(block, operand_src, extra.namespace);6392 const container_ty = try sema.resolveType(block, operand_src, extra.namespace);
6376 const container_namespace = container_ty.getNamespaceIndex(mod);6393 const container_namespace = container_ty.getNamespaceIndex(mod);
...@@ -6721,7 +6738,11 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -6721,7 +6738,11 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
6721 const mod = sema.mod;6738 const mod = sema.mod;
6722 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;6739 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
6723 const src = inst_data.src();6740 const src = inst_data.src();
6724 const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));6741 const decl_name = try mod.intern_pool.getOrPutString(
6742 sema.gpa,
6743 inst_data.get(sema.code),
6744 .no_embedded_nulls,
6745 );
6725 const decl_index = try sema.lookupIdentifier(block, src, decl_name);6746 const decl_index = try sema.lookupIdentifier(block, src, decl_name);
6726 try sema.addReferencedBy(block, src, decl_index);6747 try sema.addReferencedBy(block, src, decl_index);
6727 return sema.analyzeDeclRef(decl_index);6748 return sema.analyzeDeclRef(decl_index);
...@@ -6731,7 +6752,11 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -6731,7 +6752,11 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
6731 const mod = sema.mod;6752 const mod = sema.mod;
6732 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;6753 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
6733 const src = inst_data.src();6754 const src = inst_data.src();
6734 const decl_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));6755 const decl_name = try mod.intern_pool.getOrPutString(
6756 sema.gpa,
6757 inst_data.get(sema.code),
6758 .no_embedded_nulls,
6759 );
6735 const decl = try sema.lookupIdentifier(block, src, decl_name);6760 const decl = try sema.lookupIdentifier(block, src, decl_name);
6736 return sema.analyzeDeclVal(block, src, decl);6761 return sema.analyzeDeclVal(block, src, decl);
6737}6762}
...@@ -6883,7 +6908,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref...@@ -6883,7 +6908,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
6883 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,6908 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6884 else => |e| return e,6909 else => |e| return e,
6885 };6910 };
6886 const field_name = try mod.intern_pool.getOrPutString(gpa, "index");6911 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6887 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) {6912 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) {
6888 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"),6913 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"),
6889 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,6914 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
...@@ -6926,7 +6951,7 @@ fn popErrorReturnTrace(...@@ -6926,7 +6951,7 @@ fn popErrorReturnTrace(
6926 try sema.resolveTypeFields(stack_trace_ty);6951 try sema.resolveTypeFields(stack_trace_ty);
6927 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);6952 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);
6928 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);6953 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);
6929 const field_name = try mod.intern_pool.getOrPutString(gpa, "index");6954 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6930 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true);6955 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true);
6931 try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store);6956 try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store);
6932 } else if (is_non_error == null) {6957 } else if (is_non_error == null) {
...@@ -6952,7 +6977,7 @@ fn popErrorReturnTrace(...@@ -6952,7 +6977,7 @@ fn popErrorReturnTrace(
6952 try sema.resolveTypeFields(stack_trace_ty);6977 try sema.resolveTypeFields(stack_trace_ty);
6953 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);6978 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);
6954 const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty);6979 const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty);
6955 const field_name = try mod.intern_pool.getOrPutString(gpa, "index");6980 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6956 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);6981 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);
6957 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);6982 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);
6958 _ = try then_block.addBr(cond_block_inst, .void_value);6983 _ = try then_block.addBr(cond_block_inst, .void_value);
...@@ -7010,7 +7035,11 @@ fn zirCall(...@@ -7010,7 +7035,11 @@ fn zirCall(
7010 .direct => .{ .direct = try sema.resolveInst(extra.data.callee) },7035 .direct => .{ .direct = try sema.resolveInst(extra.data.callee) },
7011 .field => blk: {7036 .field => blk: {
7012 const object_ptr = try sema.resolveInst(extra.data.obj_ptr);7037 const object_ptr = try sema.resolveInst(extra.data.obj_ptr);
7013 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.data.field_name_start));7038 const field_name = try mod.intern_pool.getOrPutString(
7039 sema.gpa,
7040 sema.code.nullTerminatedString(extra.data.field_name_start),
7041 .no_embedded_nulls,
7042 );
7014 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };7043 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
7015 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);7044 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);
7016 },7045 },
...@@ -7073,7 +7102,7 @@ fn zirCall(...@@ -7073,7 +7102,7 @@ fn zirCall(
7073 if (input_is_error or (pop_error_return_trace and return_ty.isError(mod))) {7102 if (input_is_error or (pop_error_return_trace and return_ty.isError(mod))) {
7074 const stack_trace_ty = try sema.getBuiltinType("StackTrace");7103 const stack_trace_ty = try sema.getBuiltinType("StackTrace");
7075 try sema.resolveTypeFields(stack_trace_ty);7104 try sema.resolveTypeFields(stack_trace_ty);
7076 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "index");7105 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, "index", .no_embedded_nulls);
7077 const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src);7106 const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src);
70787107
7079 // Insert a save instruction before the arg resolution + call instructions we just generated7108 // Insert a save instruction before the arg resolution + call instructions we just generated
...@@ -8648,7 +8677,11 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -8648,7 +8677,11 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
8648 _ = block;8677 _ = block;
8649 const mod = sema.mod;8678 const mod = sema.mod;
8650 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;8679 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
8651 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));8680 const name = try mod.intern_pool.getOrPutString(
8681 sema.gpa,
8682 inst_data.get(sema.code),
8683 .no_embedded_nulls,
8684 );
8652 _ = try mod.getErrorValue(name);8685 _ = try mod.getErrorValue(name);
8653 // Create an error set type with only this error value, and return the value.8686 // Create an error set type with only this error value, and return the value.
8654 const error_set_type = try mod.singleErrorSetType(name);8687 const error_set_type = try mod.singleErrorSetType(name);
...@@ -8804,7 +8837,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8804,7 +8837,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8804 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;8837 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
8805 const name = inst_data.get(sema.code);8838 const name = inst_data.get(sema.code);
8806 return Air.internedToRef((try mod.intern(.{8839 return Air.internedToRef((try mod.intern(.{
8807 .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name),8840 .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, name, .no_embedded_nulls),
8808 })));8841 })));
8809}8842}
88108843
...@@ -9761,7 +9794,7 @@ fn funcCommon(...@@ -9761,7 +9794,7 @@ fn funcCommon(
9761 const func_index = try ip.getExternFunc(gpa, .{9794 const func_index = try ip.getExternFunc(gpa, .{
9762 .ty = func_ty,9795 .ty = func_ty,
9763 .decl = sema.owner_decl_index,9796 .decl = sema.owner_decl_index,
9764 .lib_name = try mod.intern_pool.getOrPutStringOpt(gpa, opt_lib_name),9797 .lib_name = try mod.intern_pool.getOrPutStringOpt(gpa, opt_lib_name, .no_embedded_nulls),
9765 });9798 });
9766 return finishFunc(9799 return finishFunc(
9767 sema,9800 sema,
...@@ -10225,7 +10258,11 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10225,7 +10258,11 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
10225 const src = inst_data.src();10258 const src = inst_data.src();
10226 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };10259 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
10227 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10260 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10228 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start));10261 const field_name = try mod.intern_pool.getOrPutString(
10262 sema.gpa,
10263 sema.code.nullTerminatedString(extra.field_name_start),
10264 .no_embedded_nulls,
10265 );
10229 const object = try sema.resolveInst(extra.lhs);10266 const object = try sema.resolveInst(extra.lhs);
10230 return sema.fieldVal(block, src, object, field_name, field_name_src);10267 return sema.fieldVal(block, src, object, field_name, field_name_src);
10231}10268}
...@@ -10239,7 +10276,11 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10239,7 +10276,11 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
10239 const src = inst_data.src();10276 const src = inst_data.src();
10240 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };10277 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
10241 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10278 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10242 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start));10279 const field_name = try mod.intern_pool.getOrPutString(
10280 sema.gpa,
10281 sema.code.nullTerminatedString(extra.field_name_start),
10282 .no_embedded_nulls,
10283 );
10243 const object_ptr = try sema.resolveInst(extra.lhs);10284 const object_ptr = try sema.resolveInst(extra.lhs);
10244 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false);10285 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false);
10245}10286}
...@@ -10253,7 +10294,11 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi...@@ -10253,7 +10294,11 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
10253 const src = inst_data.src();10294 const src = inst_data.src();
10254 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };10295 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };
10255 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10296 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10256 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, sema.code.nullTerminatedString(extra.field_name_start));10297 const field_name = try mod.intern_pool.getOrPutString(
10298 sema.gpa,
10299 sema.code.nullTerminatedString(extra.field_name_start),
10300 .no_embedded_nulls,
10301 );
10257 const object_ptr = try sema.resolveInst(extra.lhs);10302 const object_ptr = try sema.resolveInst(extra.lhs);
10258 const struct_ty = sema.typeOf(object_ptr).childType(mod);10303 const struct_ty = sema.typeOf(object_ptr).childType(mod);
10259 switch (struct_ty.zigTypeTag(mod)) {10304 switch (struct_ty.zigTypeTag(mod)) {
...@@ -13759,8 +13804,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13759,8 +13804,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13759 switch (ip.indexToKey(ty.toIntern())) {13804 switch (ip.indexToKey(ty.toIntern())) {
13760 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {13805 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
13761 .Slice => {13806 .Slice => {
13762 if (ip.stringEqlSlice(field_name, "ptr")) break :hf true;13807 if (field_name.eqlSlice("ptr", ip)) break :hf true;
13763 if (ip.stringEqlSlice(field_name, "len")) break :hf true;13808 if (field_name.eqlSlice("len", ip)) break :hf true;
13764 break :hf false;13809 break :hf false;
13765 },13810 },
13766 else => {},13811 else => {},
...@@ -13783,7 +13828,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13783,7 +13828,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13783 .enum_type => {13828 .enum_type => {
13784 break :hf ip.loadEnumType(ty.toIntern()).nameIndex(ip, field_name) != null;13829 break :hf ip.loadEnumType(ty.toIntern()).nameIndex(ip, field_name) != null;
13785 },13830 },
13786 .array_type => break :hf ip.stringEqlSlice(field_name, "len"),13831 .array_type => break :hf field_name.eqlSlice("len", ip),
13787 else => {},13832 else => {},
13788 }13833 }
13789 return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{13834 return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{
...@@ -13885,7 +13930,11 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13885,7 +13930,11 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
13885fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {13930fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
13886 const mod = sema.mod;13931 const mod = sema.mod;
13887 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;13932 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
13888 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));13933 const name = try mod.intern_pool.getOrPutString(
13934 sema.gpa,
13935 inst_data.get(sema.code),
13936 .no_embedded_nulls,
13937 );
13889 _ = try mod.getErrorValue(name);13938 _ = try mod.getErrorValue(name);
13890 const error_set_type = try mod.singleErrorSetType(name);13939 const error_set_type = try mod.singleErrorSetType(name);
13891 return Air.internedToRef((try mod.intern(.{ .err = .{13940 return Air.internedToRef((try mod.intern(.{ .err = .{
...@@ -17552,11 +17601,9 @@ fn zirBuiltinSrc(...@@ -17552,11 +17601,9 @@ fn zirBuiltinSrc(
17552 const gpa = sema.gpa;17601 const gpa = sema.gpa;
1755317602
17554 const func_name_val = v: {17603 const func_name_val = v: {
17555 // This dupe prevents InternPool string pool memory from being reallocated17604 const func_name_len = fn_owner_decl.name.length(ip);
17556 // while a reference exists.
17557 const bytes = try sema.arena.dupe(u8, ip.stringToSlice(fn_owner_decl.name));
17558 const array_ty = try ip.get(gpa, .{ .array_type = .{17605 const array_ty = try ip.get(gpa, .{ .array_type = .{
17559 .len = bytes.len,17606 .len = func_name_len,
17560 .sentinel = .zero_u8,17607 .sentinel = .zero_u8,
17561 .child = .u8_type,17608 .child = .u8_type,
17562 } });17609 } });
...@@ -17568,19 +17615,19 @@ fn zirBuiltinSrc(...@@ -17568,19 +17615,19 @@ fn zirBuiltinSrc(
17568 .orig_ty = .slice_const_u8_sentinel_0_type,17615 .orig_ty = .slice_const_u8_sentinel_0_type,
17569 .val = try ip.get(gpa, .{ .aggregate = .{17616 .val = try ip.get(gpa, .{ .aggregate = .{
17570 .ty = array_ty,17617 .ty = array_ty,
17571 .storage = .{ .bytes = bytes },17618 .storage = .{ .bytes = fn_owner_decl.name.toString() },
17572 } }),17619 } }),
17573 } },17620 } },
17574 } }),17621 } }),
17575 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),17622 .len = (try mod.intValue(Type.usize, func_name_len)).toIntern(),
17576 } });17623 } });
17577 };17624 };
1757817625
17579 const file_name_val = v: {17626 const file_name_val = v: {
17580 // The compiler must not call realpath anywhere.17627 // The compiler must not call realpath anywhere.
17581 const bytes = try fn_owner_decl.getFileScope(mod).fullPathZ(sema.arena);17628 const file_name = try fn_owner_decl.getFileScope(mod).fullPath(sema.arena);
17582 const array_ty = try ip.get(gpa, .{ .array_type = .{17629 const array_ty = try ip.get(gpa, .{ .array_type = .{
17583 .len = bytes.len,17630 .len = file_name.len,
17584 .sentinel = .zero_u8,17631 .sentinel = .zero_u8,
17585 .child = .u8_type,17632 .child = .u8_type,
17586 } });17633 } });
...@@ -17592,11 +17639,13 @@ fn zirBuiltinSrc(...@@ -17592,11 +17639,13 @@ fn zirBuiltinSrc(
17592 .orig_ty = .slice_const_u8_sentinel_0_type,17639 .orig_ty = .slice_const_u8_sentinel_0_type,
17593 .val = try ip.get(gpa, .{ .aggregate = .{17640 .val = try ip.get(gpa, .{ .aggregate = .{
17594 .ty = array_ty,17641 .ty = array_ty,
17595 .storage = .{ .bytes = bytes },17642 .storage = .{
17643 .bytes = try ip.getOrPutString(gpa, file_name, .maybe_embedded_nulls),
17644 },
17596 } }),17645 } }),
17597 } },17646 } },
17598 } }),17647 } }),
17599 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),17648 .len = (try mod.intValue(Type.usize, file_name.len)).toIntern(),
17600 } });17649 } });
17601 };17650 };
1760217651
...@@ -17651,7 +17700,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17651,7 +17700,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17651 block,17700 block,
17652 src,17701 src,
17653 type_info_ty.getNamespaceIndex(mod),17702 type_info_ty.getNamespaceIndex(mod),
17654 try ip.getOrPutString(gpa, "Fn"),17703 try ip.getOrPutString(gpa, "Fn", .no_embedded_nulls),
17655 )).?;17704 )).?;
17656 try sema.ensureDeclAnalyzed(fn_info_decl_index);17705 try sema.ensureDeclAnalyzed(fn_info_decl_index);
17657 const fn_info_decl = mod.declPtr(fn_info_decl_index);17706 const fn_info_decl = mod.declPtr(fn_info_decl_index);
...@@ -17661,7 +17710,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17661,7 +17710,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17661 block,17710 block,
17662 src,17711 src,
17663 fn_info_ty.getNamespaceIndex(mod),17712 fn_info_ty.getNamespaceIndex(mod),
17664 try ip.getOrPutString(gpa, "Param"),17713 try ip.getOrPutString(gpa, "Param", .no_embedded_nulls),
17665 )).?;17714 )).?;
17666 try sema.ensureDeclAnalyzed(param_info_decl_index);17715 try sema.ensureDeclAnalyzed(param_info_decl_index);
17667 const param_info_decl = mod.declPtr(param_info_decl_index);17716 const param_info_decl = mod.declPtr(param_info_decl_index);
...@@ -17762,7 +17811,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17762,7 +17811,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17762 block,17811 block,
17763 src,17812 src,
17764 type_info_ty.getNamespaceIndex(mod),17813 type_info_ty.getNamespaceIndex(mod),
17765 try ip.getOrPutString(gpa, "Int"),17814 try ip.getOrPutString(gpa, "Int", .no_embedded_nulls),
17766 )).?;17815 )).?;
17767 try sema.ensureDeclAnalyzed(int_info_decl_index);17816 try sema.ensureDeclAnalyzed(int_info_decl_index);
17768 const int_info_decl = mod.declPtr(int_info_decl_index);17817 const int_info_decl = mod.declPtr(int_info_decl_index);
...@@ -17790,7 +17839,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17790,7 +17839,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17790 block,17839 block,
17791 src,17840 src,
17792 type_info_ty.getNamespaceIndex(mod),17841 type_info_ty.getNamespaceIndex(mod),
17793 try ip.getOrPutString(gpa, "Float"),17842 try ip.getOrPutString(gpa, "Float", .no_embedded_nulls),
17794 )).?;17843 )).?;
17795 try sema.ensureDeclAnalyzed(float_info_decl_index);17844 try sema.ensureDeclAnalyzed(float_info_decl_index);
17796 const float_info_decl = mod.declPtr(float_info_decl_index);17845 const float_info_decl = mod.declPtr(float_info_decl_index);
...@@ -17822,7 +17871,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17822,7 +17871,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17822 block,17871 block,
17823 src,17872 src,
17824 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),17873 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),
17825 try ip.getOrPutString(gpa, "Pointer"),17874 try ip.getOrPutString(gpa, "Pointer", .no_embedded_nulls),
17826 )).?;17875 )).?;
17827 try sema.ensureDeclAnalyzed(decl_index);17876 try sema.ensureDeclAnalyzed(decl_index);
17828 const decl = mod.declPtr(decl_index);17877 const decl = mod.declPtr(decl_index);
...@@ -17833,7 +17882,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17833,7 +17882,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17833 block,17882 block,
17834 src,17883 src,
17835 pointer_ty.getNamespaceIndex(mod),17884 pointer_ty.getNamespaceIndex(mod),
17836 try ip.getOrPutString(gpa, "Size"),17885 try ip.getOrPutString(gpa, "Size", .no_embedded_nulls),
17837 )).?;17886 )).?;
17838 try sema.ensureDeclAnalyzed(decl_index);17887 try sema.ensureDeclAnalyzed(decl_index);
17839 const decl = mod.declPtr(decl_index);17888 const decl = mod.declPtr(decl_index);
...@@ -17876,7 +17925,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17876,7 +17925,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17876 block,17925 block,
17877 src,17926 src,
17878 type_info_ty.getNamespaceIndex(mod),17927 type_info_ty.getNamespaceIndex(mod),
17879 try ip.getOrPutString(gpa, "Array"),17928 try ip.getOrPutString(gpa, "Array", .no_embedded_nulls),
17880 )).?;17929 )).?;
17881 try sema.ensureDeclAnalyzed(array_field_ty_decl_index);17930 try sema.ensureDeclAnalyzed(array_field_ty_decl_index);
17882 const array_field_ty_decl = mod.declPtr(array_field_ty_decl_index);17931 const array_field_ty_decl = mod.declPtr(array_field_ty_decl_index);
...@@ -17907,7 +17956,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17907,7 +17956,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17907 block,17956 block,
17908 src,17957 src,
17909 type_info_ty.getNamespaceIndex(mod),17958 type_info_ty.getNamespaceIndex(mod),
17910 try ip.getOrPutString(gpa, "Vector"),17959 try ip.getOrPutString(gpa, "Vector", .no_embedded_nulls),
17911 )).?;17960 )).?;
17912 try sema.ensureDeclAnalyzed(vector_field_ty_decl_index);17961 try sema.ensureDeclAnalyzed(vector_field_ty_decl_index);
17913 const vector_field_ty_decl = mod.declPtr(vector_field_ty_decl_index);17962 const vector_field_ty_decl = mod.declPtr(vector_field_ty_decl_index);
...@@ -17936,7 +17985,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17936,7 +17985,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17936 block,17985 block,
17937 src,17986 src,
17938 type_info_ty.getNamespaceIndex(mod),17987 type_info_ty.getNamespaceIndex(mod),
17939 try ip.getOrPutString(gpa, "Optional"),17988 try ip.getOrPutString(gpa, "Optional", .no_embedded_nulls),
17940 )).?;17989 )).?;
17941 try sema.ensureDeclAnalyzed(optional_field_ty_decl_index);17990 try sema.ensureDeclAnalyzed(optional_field_ty_decl_index);
17942 const optional_field_ty_decl = mod.declPtr(optional_field_ty_decl_index);17991 const optional_field_ty_decl = mod.declPtr(optional_field_ty_decl_index);
...@@ -17963,7 +18012,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17963,7 +18012,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17963 block,18012 block,
17964 src,18013 src,
17965 type_info_ty.getNamespaceIndex(mod),18014 type_info_ty.getNamespaceIndex(mod),
17966 try ip.getOrPutString(gpa, "Error"),18015 try ip.getOrPutString(gpa, "Error", .no_embedded_nulls),
17967 )).?;18016 )).?;
17968 try sema.ensureDeclAnalyzed(set_field_ty_decl_index);18017 try sema.ensureDeclAnalyzed(set_field_ty_decl_index);
17969 const set_field_ty_decl = mod.declPtr(set_field_ty_decl_index);18018 const set_field_ty_decl = mod.declPtr(set_field_ty_decl_index);
...@@ -17980,18 +18029,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17980,18 +18029,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17980 else => |err_set_ty_index| blk: {18029 else => |err_set_ty_index| blk: {
17981 const names = ip.indexToKey(err_set_ty_index).error_set_type.names;18030 const names = ip.indexToKey(err_set_ty_index).error_set_type.names;
17982 const vals = try sema.arena.alloc(InternPool.Index, names.len);18031 const vals = try sema.arena.alloc(InternPool.Index, names.len);
17983 for (vals, 0..) |*field_val, i| {18032 for (vals, 0..) |*field_val, error_index| {
17984 // TODO: write something like getCoercedInts to avoid needing to dupe18033 const error_name = names.get(ip)[error_index];
17985 const name = try sema.arena.dupeZ(u8, ip.stringToSlice(names.get(ip)[i]));18034 const error_name_len = error_name.length(ip);
17986 const name_val = v: {18035 const error_name_val = v: {
17987 const new_decl_ty = try mod.arrayType(.{18036 const new_decl_ty = try mod.arrayType(.{
17988 .len = name.len,18037 .len = error_name_len,
17989 .sentinel = .zero_u8,18038 .sentinel = .zero_u8,
17990 .child = .u8_type,18039 .child = .u8_type,
17991 });18040 });
17992 const new_decl_val = try mod.intern(.{ .aggregate = .{18041 const new_decl_val = try mod.intern(.{ .aggregate = .{
17993 .ty = new_decl_ty.toIntern(),18042 .ty = new_decl_ty.toIntern(),
17994 .storage = .{ .bytes = name },18043 .storage = .{ .bytes = error_name.toString() },
17995 } });18044 } });
17996 break :v try mod.intern(.{ .slice = .{18045 break :v try mod.intern(.{ .slice = .{
17997 .ty = .slice_const_u8_sentinel_0_type,18046 .ty = .slice_const_u8_sentinel_0_type,
...@@ -18002,13 +18051,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18002,13 +18051,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18002 .orig_ty = .slice_const_u8_sentinel_0_type,18051 .orig_ty = .slice_const_u8_sentinel_0_type,
18003 } },18052 } },
18004 } }),18053 } }),
18005 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),18054 .len = (try mod.intValue(Type.usize, error_name_len)).toIntern(),
18006 } });18055 } });
18007 };18056 };
1800818057
18009 const error_field_fields = .{18058 const error_field_fields = .{
18010 // name: [:0]const u8,18059 // name: [:0]const u8,
18011 name_val,18060 error_name_val,
18012 };18061 };
18013 field_val.* = try mod.intern(.{ .aggregate = .{18062 field_val.* = try mod.intern(.{ .aggregate = .{
18014 .ty = error_field_ty.toIntern(),18063 .ty = error_field_ty.toIntern(),
...@@ -18069,7 +18118,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18069,7 +18118,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18069 block,18118 block,
18070 src,18119 src,
18071 type_info_ty.getNamespaceIndex(mod),18120 type_info_ty.getNamespaceIndex(mod),
18072 try ip.getOrPutString(gpa, "ErrorUnion"),18121 try ip.getOrPutString(gpa, "ErrorUnion", .no_embedded_nulls),
18073 )).?;18122 )).?;
18074 try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index);18123 try sema.ensureDeclAnalyzed(error_union_field_ty_decl_index);
18075 const error_union_field_ty_decl = mod.declPtr(error_union_field_ty_decl_index);18124 const error_union_field_ty_decl = mod.declPtr(error_union_field_ty_decl_index);
...@@ -18099,7 +18148,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18099,7 +18148,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18099 block,18148 block,
18100 src,18149 src,
18101 type_info_ty.getNamespaceIndex(mod),18150 type_info_ty.getNamespaceIndex(mod),
18102 try ip.getOrPutString(gpa, "EnumField"),18151 try ip.getOrPutString(gpa, "EnumField", .no_embedded_nulls),
18103 )).?;18152 )).?;
18104 try sema.ensureDeclAnalyzed(enum_field_ty_decl_index);18153 try sema.ensureDeclAnalyzed(enum_field_ty_decl_index);
18105 const enum_field_ty_decl = mod.declPtr(enum_field_ty_decl_index);18154 const enum_field_ty_decl = mod.declPtr(enum_field_ty_decl_index);
...@@ -18107,27 +18156,29 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18107,27 +18156,29 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18107 };18156 };
1810818157
18109 const enum_field_vals = try sema.arena.alloc(InternPool.Index, ip.loadEnumType(ty.toIntern()).names.len);18158 const enum_field_vals = try sema.arena.alloc(InternPool.Index, ip.loadEnumType(ty.toIntern()).names.len);
18110 for (enum_field_vals, 0..) |*field_val, i| {18159 for (enum_field_vals, 0..) |*field_val, tag_index| {
18111 const enum_type = ip.loadEnumType(ty.toIntern());18160 const enum_type = ip.loadEnumType(ty.toIntern());
18112 const value_val = if (enum_type.values.len > 0)18161 const value_val = if (enum_type.values.len > 0)
18113 try mod.intern_pool.getCoercedInts(18162 try mod.intern_pool.getCoercedInts(
18114 mod.gpa,18163 mod.gpa,
18115 mod.intern_pool.indexToKey(enum_type.values.get(ip)[i]).int,18164 mod.intern_pool.indexToKey(enum_type.values.get(ip)[tag_index]).int,
18116 .comptime_int_type,18165 .comptime_int_type,
18117 )18166 )
18118 else18167 else
18119 (try mod.intValue(Type.comptime_int, i)).toIntern();18168 (try mod.intValue(Type.comptime_int, tag_index)).toIntern();
18169
18120 // TODO: write something like getCoercedInts to avoid needing to dupe18170 // TODO: write something like getCoercedInts to avoid needing to dupe
18121 const name = try sema.arena.dupeZ(u8, ip.stringToSlice(enum_type.names.get(ip)[i]));
18122 const name_val = v: {18171 const name_val = v: {
18172 const tag_name = enum_type.names.get(ip)[tag_index];
18173 const tag_name_len = tag_name.length(ip);
18123 const new_decl_ty = try mod.arrayType(.{18174 const new_decl_ty = try mod.arrayType(.{
18124 .len = name.len,18175 .len = tag_name_len,
18125 .sentinel = .zero_u8,18176 .sentinel = .zero_u8,
18126 .child = .u8_type,18177 .child = .u8_type,
18127 });18178 });
18128 const new_decl_val = try mod.intern(.{ .aggregate = .{18179 const new_decl_val = try mod.intern(.{ .aggregate = .{
18129 .ty = new_decl_ty.toIntern(),18180 .ty = new_decl_ty.toIntern(),
18130 .storage = .{ .bytes = name },18181 .storage = .{ .bytes = tag_name.toString() },
18131 } });18182 } });
18132 break :v try mod.intern(.{ .slice = .{18183 break :v try mod.intern(.{ .slice = .{
18133 .ty = .slice_const_u8_sentinel_0_type,18184 .ty = .slice_const_u8_sentinel_0_type,
...@@ -18138,7 +18189,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18138,7 +18189,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18138 .orig_ty = .slice_const_u8_sentinel_0_type,18189 .orig_ty = .slice_const_u8_sentinel_0_type,
18139 } },18190 } },
18140 } }),18191 } }),
18141 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),18192 .len = (try mod.intValue(Type.usize, tag_name_len)).toIntern(),
18142 } });18193 } });
18143 };18194 };
1814418195
...@@ -18191,7 +18242,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18191,7 +18242,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18191 block,18242 block,
18192 src,18243 src,
18193 type_info_ty.getNamespaceIndex(mod),18244 type_info_ty.getNamespaceIndex(mod),
18194 try ip.getOrPutString(gpa, "Enum"),18245 try ip.getOrPutString(gpa, "Enum", .no_embedded_nulls),
18195 )).?;18246 )).?;
18196 try sema.ensureDeclAnalyzed(type_enum_ty_decl_index);18247 try sema.ensureDeclAnalyzed(type_enum_ty_decl_index);
18197 const type_enum_ty_decl = mod.declPtr(type_enum_ty_decl_index);18248 const type_enum_ty_decl = mod.declPtr(type_enum_ty_decl_index);
...@@ -18223,7 +18274,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18223,7 +18274,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18223 block,18274 block,
18224 src,18275 src,
18225 type_info_ty.getNamespaceIndex(mod),18276 type_info_ty.getNamespaceIndex(mod),
18226 try ip.getOrPutString(gpa, "Union"),18277 try ip.getOrPutString(gpa, "Union", .no_embedded_nulls),
18227 )).?;18278 )).?;
18228 try sema.ensureDeclAnalyzed(type_union_ty_decl_index);18279 try sema.ensureDeclAnalyzed(type_union_ty_decl_index);
18229 const type_union_ty_decl = mod.declPtr(type_union_ty_decl_index);18280 const type_union_ty_decl = mod.declPtr(type_union_ty_decl_index);
...@@ -18235,7 +18286,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18235,7 +18286,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18235 block,18286 block,
18236 src,18287 src,
18237 type_info_ty.getNamespaceIndex(mod),18288 type_info_ty.getNamespaceIndex(mod),
18238 try ip.getOrPutString(gpa, "UnionField"),18289 try ip.getOrPutString(gpa, "UnionField", .no_embedded_nulls),
18239 )).?;18290 )).?;
18240 try sema.ensureDeclAnalyzed(union_field_ty_decl_index);18291 try sema.ensureDeclAnalyzed(union_field_ty_decl_index);
18241 const union_field_ty_decl = mod.declPtr(union_field_ty_decl_index);18292 const union_field_ty_decl = mod.declPtr(union_field_ty_decl_index);
...@@ -18250,18 +18301,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18250,18 +18301,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18250 const union_field_vals = try gpa.alloc(InternPool.Index, tag_type.names.len);18301 const union_field_vals = try gpa.alloc(InternPool.Index, tag_type.names.len);
18251 defer gpa.free(union_field_vals);18302 defer gpa.free(union_field_vals);
1825218303
18253 for (union_field_vals, 0..) |*field_val, i| {18304 for (union_field_vals, 0..) |*field_val, field_index| {
18254 // TODO: write something like getCoercedInts to avoid needing to dupe
18255 const name = try sema.arena.dupeZ(u8, ip.stringToSlice(tag_type.names.get(ip)[i]));
18256 const name_val = v: {18305 const name_val = v: {
18306 const field_name = tag_type.names.get(ip)[field_index];
18307 const field_name_len = field_name.length(ip);
18257 const new_decl_ty = try mod.arrayType(.{18308 const new_decl_ty = try mod.arrayType(.{
18258 .len = name.len,18309 .len = field_name_len,
18259 .sentinel = .zero_u8,18310 .sentinel = .zero_u8,
18260 .child = .u8_type,18311 .child = .u8_type,
18261 });18312 });
18262 const new_decl_val = try mod.intern(.{ .aggregate = .{18313 const new_decl_val = try mod.intern(.{ .aggregate = .{
18263 .ty = new_decl_ty.toIntern(),18314 .ty = new_decl_ty.toIntern(),
18264 .storage = .{ .bytes = name },18315 .storage = .{ .bytes = field_name.toString() },
18265 } });18316 } });
18266 break :v try mod.intern(.{ .slice = .{18317 break :v try mod.intern(.{ .slice = .{
18267 .ty = .slice_const_u8_sentinel_0_type,18318 .ty = .slice_const_u8_sentinel_0_type,
...@@ -18272,16 +18323,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18272,16 +18323,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18272 .orig_ty = .slice_const_u8_sentinel_0_type,18323 .orig_ty = .slice_const_u8_sentinel_0_type,
18273 } },18324 } },
18274 } }),18325 } }),
18275 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),18326 .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(),
18276 } });18327 } });
18277 };18328 };
1827818329
18279 const alignment = switch (layout) {18330 const alignment = switch (layout) {
18280 .auto, .@"extern" => try sema.unionFieldAlignment(union_obj, @intCast(i)),18331 .auto, .@"extern" => try sema.unionFieldAlignment(union_obj, @intCast(field_index)),
18281 .@"packed" => .none,18332 .@"packed" => .none,
18282 };18333 };
1828318334
18284 const field_ty = union_obj.field_types.get(ip)[i];18335 const field_ty = union_obj.field_types.get(ip)[field_index];
18285 const union_field_fields = .{18336 const union_field_fields = .{
18286 // name: [:0]const u8,18337 // name: [:0]const u8,
18287 name_val,18338 name_val,
...@@ -18338,7 +18389,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18338,7 +18389,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18338 block,18389 block,
18339 src,18390 src,
18340 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),18391 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),
18341 try ip.getOrPutString(gpa, "ContainerLayout"),18392 try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls),
18342 )).?;18393 )).?;
18343 try sema.ensureDeclAnalyzed(decl_index);18394 try sema.ensureDeclAnalyzed(decl_index);
18344 const decl = mod.declPtr(decl_index);18395 const decl = mod.declPtr(decl_index);
...@@ -18371,7 +18422,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18371,7 +18422,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18371 block,18422 block,
18372 src,18423 src,
18373 type_info_ty.getNamespaceIndex(mod),18424 type_info_ty.getNamespaceIndex(mod),
18374 try ip.getOrPutString(gpa, "Struct"),18425 try ip.getOrPutString(gpa, "Struct", .no_embedded_nulls),
18375 )).?;18426 )).?;
18376 try sema.ensureDeclAnalyzed(type_struct_ty_decl_index);18427 try sema.ensureDeclAnalyzed(type_struct_ty_decl_index);
18377 const type_struct_ty_decl = mod.declPtr(type_struct_ty_decl_index);18428 const type_struct_ty_decl = mod.declPtr(type_struct_ty_decl_index);
...@@ -18383,7 +18434,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18383,7 +18434,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18383 block,18434 block,
18384 src,18435 src,
18385 type_info_ty.getNamespaceIndex(mod),18436 type_info_ty.getNamespaceIndex(mod),
18386 try ip.getOrPutString(gpa, "StructField"),18437 try ip.getOrPutString(gpa, "StructField", .no_embedded_nulls),
18387 )).?;18438 )).?;
18388 try sema.ensureDeclAnalyzed(struct_field_ty_decl_index);18439 try sema.ensureDeclAnalyzed(struct_field_ty_decl_index);
18389 const struct_field_ty_decl = mod.declPtr(struct_field_ty_decl_index);18440 const struct_field_ty_decl = mod.declPtr(struct_field_ty_decl_index);
...@@ -18396,27 +18447,25 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18396,27 +18447,25 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18396 defer gpa.free(struct_field_vals);18447 defer gpa.free(struct_field_vals);
18397 fv: {18448 fv: {
18398 const struct_type = switch (ip.indexToKey(ty.toIntern())) {18449 const struct_type = switch (ip.indexToKey(ty.toIntern())) {
18399 .anon_struct_type => |tuple| {18450 .anon_struct_type => |anon_struct_type| {
18400 struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len);18451 struct_field_vals = try gpa.alloc(InternPool.Index, anon_struct_type.types.len);
18401 for (struct_field_vals, 0..) |*struct_field_val, i| {18452 for (struct_field_vals, 0..) |*struct_field_val, field_index| {
18402 const anon_struct_type = ip.indexToKey(ty.toIntern()).anon_struct_type;18453 const field_ty = anon_struct_type.types.get(ip)[field_index];
18403 const field_ty = anon_struct_type.types.get(ip)[i];18454 const field_val = anon_struct_type.values.get(ip)[field_index];
18404 const field_val = anon_struct_type.values.get(ip)[i];
18405 const name_val = v: {18455 const name_val = v: {
18406 // TODO: write something like getCoercedInts to avoid needing to dupe18456 const field_name = if (anon_struct_type.names.len != 0)
18407 const bytes = if (tuple.names.len != 0)18457 anon_struct_type.names.get(ip)[field_index]
18408 // https://github.com/ziglang/zig/issues/15709
18409 try sema.arena.dupeZ(u8, ip.stringToSlice(ip.indexToKey(ty.toIntern()).anon_struct_type.names.get(ip)[i]))
18410 else18458 else
18411 try std.fmt.allocPrintZ(sema.arena, "{d}", .{i});18459 try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls);
18460 const field_name_len = field_name.length(ip);
18412 const new_decl_ty = try mod.arrayType(.{18461 const new_decl_ty = try mod.arrayType(.{
18413 .len = bytes.len,18462 .len = field_name_len,
18414 .sentinel = .zero_u8,18463 .sentinel = .zero_u8,
18415 .child = .u8_type,18464 .child = .u8_type,
18416 });18465 });
18417 const new_decl_val = try mod.intern(.{ .aggregate = .{18466 const new_decl_val = try mod.intern(.{ .aggregate = .{
18418 .ty = new_decl_ty.toIntern(),18467 .ty = new_decl_ty.toIntern(),
18419 .storage = .{ .bytes = bytes },18468 .storage = .{ .bytes = field_name.toString() },
18420 } });18469 } });
18421 break :v try mod.intern(.{ .slice = .{18470 break :v try mod.intern(.{ .slice = .{
18422 .ty = .slice_const_u8_sentinel_0_type,18471 .ty = .slice_const_u8_sentinel_0_type,
...@@ -18427,7 +18476,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18427,7 +18476,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18427 .orig_ty = .slice_const_u8_sentinel_0_type,18476 .orig_ty = .slice_const_u8_sentinel_0_type,
18428 } },18477 } },
18429 } }),18478 } }),
18430 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),18479 .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(),
18431 } });18480 } });
18432 };18481 };
1843318482
...@@ -18462,24 +18511,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18462,24 +18511,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1846218511
18463 try sema.resolveStructFieldInits(ty);18512 try sema.resolveStructFieldInits(ty);
1846418513
18465 for (struct_field_vals, 0..) |*field_val, i| {18514 for (struct_field_vals, 0..) |*field_val, field_index| {
18466 // TODO: write something like getCoercedInts to avoid needing to dupe18515 const field_name = if (struct_type.fieldName(ip, field_index).unwrap()) |field_name|
18467 const name = if (struct_type.fieldName(ip, i).unwrap()) |name_nts|18516 field_name
18468 try sema.arena.dupeZ(u8, ip.stringToSlice(name_nts))
18469 else18517 else
18470 try std.fmt.allocPrintZ(sema.arena, "{d}", .{i});18518 try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls);
18471 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);18519 const field_name_len = field_name.length(ip);
18472 const field_init = struct_type.fieldInit(ip, i);18520 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
18473 const field_is_comptime = struct_type.fieldIsComptime(ip, i);18521 const field_init = struct_type.fieldInit(ip, field_index);
18522 const field_is_comptime = struct_type.fieldIsComptime(ip, field_index);
18474 const name_val = v: {18523 const name_val = v: {
18475 const new_decl_ty = try mod.arrayType(.{18524 const new_decl_ty = try mod.arrayType(.{
18476 .len = name.len,18525 .len = field_name_len,
18477 .sentinel = .zero_u8,18526 .sentinel = .zero_u8,
18478 .child = .u8_type,18527 .child = .u8_type,
18479 });18528 });
18480 const new_decl_val = try mod.intern(.{ .aggregate = .{18529 const new_decl_val = try mod.intern(.{ .aggregate = .{
18481 .ty = new_decl_ty.toIntern(),18530 .ty = new_decl_ty.toIntern(),
18482 .storage = .{ .bytes = name },18531 .storage = .{ .bytes = field_name.toString() },
18483 } });18532 } });
18484 break :v try mod.intern(.{ .slice = .{18533 break :v try mod.intern(.{ .slice = .{
18485 .ty = .slice_const_u8_sentinel_0_type,18534 .ty = .slice_const_u8_sentinel_0_type,
...@@ -18490,7 +18539,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18490,7 +18539,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18490 .orig_ty = .slice_const_u8_sentinel_0_type,18539 .orig_ty = .slice_const_u8_sentinel_0_type,
18491 } },18540 } },
18492 } }),18541 } }),
18493 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),18542 .len = (try mod.intValue(Type.usize, field_name_len)).toIntern(),
18494 } });18543 } });
18495 };18544 };
1849618545
...@@ -18499,7 +18548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18499,7 +18548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18499 const alignment = switch (struct_type.layout) {18548 const alignment = switch (struct_type.layout) {
18500 .@"packed" => .none,18549 .@"packed" => .none,
18501 else => try sema.structFieldAlignment(18550 else => try sema.structFieldAlignment(
18502 struct_type.fieldAlign(ip, i),18551 struct_type.fieldAlign(ip, field_index),
18503 field_ty,18552 field_ty,
18504 struct_type.layout,18553 struct_type.layout,
18505 ),18554 ),
...@@ -18569,7 +18618,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18569,7 +18618,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18569 block,18618 block,
18570 src,18619 src,
18571 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),18620 (try sema.getBuiltinType("Type")).getNamespaceIndex(mod),
18572 try ip.getOrPutString(gpa, "ContainerLayout"),18621 try ip.getOrPutString(gpa, "ContainerLayout", .no_embedded_nulls),
18573 )).?;18622 )).?;
18574 try sema.ensureDeclAnalyzed(decl_index);18623 try sema.ensureDeclAnalyzed(decl_index);
18575 const decl = mod.declPtr(decl_index);18624 const decl = mod.declPtr(decl_index);
...@@ -18605,7 +18654,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18605,7 +18654,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18605 block,18654 block,
18606 src,18655 src,
18607 type_info_ty.getNamespaceIndex(mod),18656 type_info_ty.getNamespaceIndex(mod),
18608 try ip.getOrPutString(gpa, "Opaque"),18657 try ip.getOrPutString(gpa, "Opaque", .no_embedded_nulls),
18609 )).?;18658 )).?;
18610 try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index);18659 try sema.ensureDeclAnalyzed(type_opaque_ty_decl_index);
18611 const type_opaque_ty_decl = mod.declPtr(type_opaque_ty_decl_index);18660 const type_opaque_ty_decl = mod.declPtr(type_opaque_ty_decl_index);
...@@ -18648,7 +18697,7 @@ fn typeInfoDecls(...@@ -18648,7 +18697,7 @@ fn typeInfoDecls(
18648 block,18697 block,
18649 src,18698 src,
18650 type_info_ty.getNamespaceIndex(mod),18699 type_info_ty.getNamespaceIndex(mod),
18651 try mod.intern_pool.getOrPutString(gpa, "Declaration"),18700 try mod.intern_pool.getOrPutString(gpa, "Declaration", .no_embedded_nulls),
18652 )).?;18701 )).?;
18653 try sema.ensureDeclAnalyzed(declaration_ty_decl_index);18702 try sema.ensureDeclAnalyzed(declaration_ty_decl_index);
18654 const declaration_ty_decl = mod.declPtr(declaration_ty_decl_index);18703 const declaration_ty_decl = mod.declPtr(declaration_ty_decl_index);
...@@ -18722,16 +18771,15 @@ fn typeInfoNamespaceDecls(...@@ -18722,16 +18771,15 @@ fn typeInfoNamespaceDecls(
18722 }18771 }
18723 if (decl.kind != .named) continue;18772 if (decl.kind != .named) continue;
18724 const name_val = v: {18773 const name_val = v: {
18725 // TODO: write something like getCoercedInts to avoid needing to dupe18774 const decl_name_len = decl.name.length(ip);
18726 const name = try sema.arena.dupeZ(u8, ip.stringToSlice(decl.name));
18727 const new_decl_ty = try mod.arrayType(.{18775 const new_decl_ty = try mod.arrayType(.{
18728 .len = name.len,18776 .len = decl_name_len,
18729 .sentinel = .zero_u8,18777 .sentinel = .zero_u8,
18730 .child = .u8_type,18778 .child = .u8_type,
18731 });18779 });
18732 const new_decl_val = try mod.intern(.{ .aggregate = .{18780 const new_decl_val = try mod.intern(.{ .aggregate = .{
18733 .ty = new_decl_ty.toIntern(),18781 .ty = new_decl_ty.toIntern(),
18734 .storage = .{ .bytes = name },18782 .storage = .{ .bytes = decl.name.toString() },
18735 } });18783 } });
18736 break :v try mod.intern(.{ .slice = .{18784 break :v try mod.intern(.{ .slice = .{
18737 .ty = .slice_const_u8_sentinel_0_type,18785 .ty = .slice_const_u8_sentinel_0_type,
...@@ -18742,7 +18790,7 @@ fn typeInfoNamespaceDecls(...@@ -18742,7 +18790,7 @@ fn typeInfoNamespaceDecls(
18742 .val = new_decl_val,18790 .val = new_decl_val,
18743 } },18791 } },
18744 } }),18792 } }),
18745 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),18793 .len = (try mod.intValue(Type.usize, decl_name_len)).toIntern(),
18746 } });18794 } });
18747 };18795 };
1874818796
...@@ -19385,7 +19433,11 @@ fn zirRetErrValue(...@@ -19385,7 +19433,11 @@ fn zirRetErrValue(
19385) CompileError!void {19433) CompileError!void {
19386 const mod = sema.mod;19434 const mod = sema.mod;
19387 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;19435 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
19388 const err_name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));19436 const err_name = try mod.intern_pool.getOrPutString(
19437 sema.gpa,
19438 inst_data.get(sema.code),
19439 .no_embedded_nulls,
19440 );
19389 _ = try mod.getErrorValue(err_name);19441 _ = try mod.getErrorValue(err_name);
19390 const src = inst_data.src();19442 const src = inst_data.src();
19391 // Return the error code from the function.19443 // Return the error code from the function.
...@@ -20072,7 +20124,11 @@ fn zirStructInit(...@@ -20072,7 +20124,11 @@ fn zirStructInit(
20072 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;20124 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
20073 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };20125 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
20074 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;20126 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
20075 const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start));20127 const field_name = try ip.getOrPutString(
20128 gpa,
20129 sema.code.nullTerminatedString(field_type_extra.name_start),
20130 .no_embedded_nulls,
20131 );
20076 const field_index = if (resolved_ty.isTuple(mod))20132 const field_index = if (resolved_ty.isTuple(mod))
20077 try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src)20133 try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src)
20078 else20134 else
...@@ -20109,7 +20165,11 @@ fn zirStructInit(...@@ -20109,7 +20165,11 @@ fn zirStructInit(
20109 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;20165 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
20110 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };20166 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
20111 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;20167 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
20112 const field_name = try ip.getOrPutString(gpa, sema.code.nullTerminatedString(field_type_extra.name_start));20168 const field_name = try ip.getOrPutString(
20169 gpa,
20170 sema.code.nullTerminatedString(field_type_extra.name_start),
20171 .no_embedded_nulls,
20172 );
20113 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);20173 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
20114 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);20174 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);
20115 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);20175 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
...@@ -20417,8 +20477,7 @@ fn structInitAnon(...@@ -20417,8 +20477,7 @@ fn structInitAnon(
20417 },20477 },
20418 };20478 };
2041920479
20420 const name_ip = try mod.intern_pool.getOrPutString(gpa, name);20480 field_name.* = try mod.intern_pool.getOrPutString(gpa, name, .no_embedded_nulls);
20421 field_name.* = name_ip;
2042220481
20423 const init = try sema.resolveInst(item.data.init);20482 const init = try sema.resolveInst(item.data.init);
20424 field_ty.* = sema.typeOf(init).toIntern();20483 field_ty.* = sema.typeOf(init).toIntern();
...@@ -20809,7 +20868,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -20809,7 +20868,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
20809 };20868 };
20810 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod);20869 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod);
20811 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);20870 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);
20812 const field_name = try ip.getOrPutString(sema.gpa, zir_field_name);20871 const field_name = try ip.getOrPutString(sema.gpa, zir_field_name, .no_embedded_nulls);
20813 return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src);20872 return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src);
20814}20873}
2081520874
...@@ -20975,7 +21034,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -20975,7 +21034,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2097521034
20976 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {21035 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
20977 const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name;21036 const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name;
20978 return sema.addStrLit(sema.mod.intern_pool.stringToSlice(err_name));21037 return sema.addNullTerminatedStrLit(err_name);
20979 }21038 }
2098021039
20981 // Similar to zirTagName, we have special AIR instruction for the error name in case an optimimzation pass21040 // Similar to zirTagName, we have special AIR instruction for the error name in case an optimimzation pass
...@@ -21093,7 +21152,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -21093,7 +21152,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
21093 .EnumLiteral => {21152 .EnumLiteral => {
21094 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);21153 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);
21095 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;21154 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
21096 return sema.addStrLit(ip.stringToSlice(tag_name));21155 return sema.addNullTerminatedStrLit(tag_name);
21097 },21156 },
21098 .Enum => operand_ty,21157 .Enum => operand_ty,
21099 .Union => operand_ty.unionTagType(mod) orelse21158 .Union => operand_ty.unionTagType(mod) orelse
...@@ -21127,7 +21186,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -21127,7 +21186,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
21127 };21186 };
21128 // TODO: write something like getCoercedInts to avoid needing to dupe21187 // TODO: write something like getCoercedInts to avoid needing to dupe
21129 const field_name = enum_ty.enumFieldName(field_index, mod);21188 const field_name = enum_ty.enumFieldName(field_index, mod);
21130 return sema.addStrLit(ip.stringToSlice(field_name));21189 return sema.addNullTerminatedStrLit(field_name);
21131 }21190 }
21132 try sema.requireRuntimeBlock(block, src, operand_src);21191 try sema.requireRuntimeBlock(block, src, operand_src);
21133 if (block.wantSafety() and sema.mod.backendSupportsFeature(.is_named_enum_value)) {21192 if (block.wantSafety() and sema.mod.backendSupportsFeature(.is_named_enum_value)) {
...@@ -21179,11 +21238,11 @@ fn zirReify(...@@ -21179,11 +21238,11 @@ fn zirReify(
21179 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21238 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21180 const signedness_val = try Value.fromInterned(union_val.val).fieldValue(21239 const signedness_val = try Value.fromInterned(union_val.val).fieldValue(
21181 mod,21240 mod,
21182 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness")).?,21241 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness", .no_embedded_nulls)).?,
21183 );21242 );
21184 const bits_val = try Value.fromInterned(union_val.val).fieldValue(21243 const bits_val = try Value.fromInterned(union_val.val).fieldValue(
21185 mod,21244 mod,
21186 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits")).?,21245 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits", .no_embedded_nulls)).?,
21187 );21246 );
2118821247
21189 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);21248 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
...@@ -21195,11 +21254,11 @@ fn zirReify(...@@ -21195,11 +21254,11 @@ fn zirReify(
21195 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21254 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21196 const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21255 const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21197 ip,21256 ip,
21198 try ip.getOrPutString(gpa, "len"),21257 try ip.getOrPutString(gpa, "len", .no_embedded_nulls),
21199 ).?);21258 ).?);
21200 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21259 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21201 ip,21260 ip,
21202 try ip.getOrPutString(gpa, "child"),21261 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
21203 ).?);21262 ).?);
2120421263
21205 const len: u32 = @intCast(try len_val.toUnsignedIntAdvanced(sema));21264 const len: u32 = @intCast(try len_val.toUnsignedIntAdvanced(sema));
...@@ -21217,7 +21276,7 @@ fn zirReify(...@@ -21217,7 +21276,7 @@ fn zirReify(
21217 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21276 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21218 const bits_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21277 const bits_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21219 ip,21278 ip,
21220 try ip.getOrPutString(gpa, "bits"),21279 try ip.getOrPutString(gpa, "bits", .no_embedded_nulls),
21221 ).?);21280 ).?);
2122221281
21223 const bits: u16 = @intCast(try bits_val.toUnsignedIntAdvanced(sema));21282 const bits: u16 = @intCast(try bits_val.toUnsignedIntAdvanced(sema));
...@@ -21235,35 +21294,35 @@ fn zirReify(...@@ -21235,35 +21294,35 @@ fn zirReify(
21235 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21294 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21236 const size_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21295 const size_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21237 ip,21296 ip,
21238 try ip.getOrPutString(gpa, "size"),21297 try ip.getOrPutString(gpa, "size", .no_embedded_nulls),
21239 ).?);21298 ).?);
21240 const is_const_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21299 const is_const_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21241 ip,21300 ip,
21242 try ip.getOrPutString(gpa, "is_const"),21301 try ip.getOrPutString(gpa, "is_const", .no_embedded_nulls),
21243 ).?);21302 ).?);
21244 const is_volatile_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21303 const is_volatile_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21245 ip,21304 ip,
21246 try ip.getOrPutString(gpa, "is_volatile"),21305 try ip.getOrPutString(gpa, "is_volatile", .no_embedded_nulls),
21247 ).?);21306 ).?);
21248 const alignment_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21307 const alignment_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21249 ip,21308 ip,
21250 try ip.getOrPutString(gpa, "alignment"),21309 try ip.getOrPutString(gpa, "alignment", .no_embedded_nulls),
21251 ).?);21310 ).?);
21252 const address_space_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21311 const address_space_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21253 ip,21312 ip,
21254 try ip.getOrPutString(gpa, "address_space"),21313 try ip.getOrPutString(gpa, "address_space", .no_embedded_nulls),
21255 ).?);21314 ).?);
21256 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21315 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21257 ip,21316 ip,
21258 try ip.getOrPutString(gpa, "child"),21317 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
21259 ).?);21318 ).?);
21260 const is_allowzero_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21319 const is_allowzero_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21261 ip,21320 ip,
21262 try ip.getOrPutString(gpa, "is_allowzero"),21321 try ip.getOrPutString(gpa, "is_allowzero", .no_embedded_nulls),
21263 ).?);21322 ).?);
21264 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21323 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21265 ip,21324 ip,
21266 try ip.getOrPutString(gpa, "sentinel"),21325 try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls),
21267 ).?);21326 ).?);
2126821327
21269 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {21328 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
...@@ -21341,15 +21400,15 @@ fn zirReify(...@@ -21341,15 +21400,15 @@ fn zirReify(
21341 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21400 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21342 const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21401 const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21343 ip,21402 ip,
21344 try ip.getOrPutString(gpa, "len"),21403 try ip.getOrPutString(gpa, "len", .no_embedded_nulls),
21345 ).?);21404 ).?);
21346 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21405 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21347 ip,21406 ip,
21348 try ip.getOrPutString(gpa, "child"),21407 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
21349 ).?);21408 ).?);
21350 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21409 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21351 ip,21410 ip,
21352 try ip.getOrPutString(gpa, "sentinel"),21411 try ip.getOrPutString(gpa, "sentinel", .no_embedded_nulls),
21353 ).?);21412 ).?);
2135421413
21355 const len = try len_val.toUnsignedIntAdvanced(sema);21414 const len = try len_val.toUnsignedIntAdvanced(sema);
...@@ -21370,7 +21429,7 @@ fn zirReify(...@@ -21370,7 +21429,7 @@ fn zirReify(
21370 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21429 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21371 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21430 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21372 ip,21431 ip,
21373 try ip.getOrPutString(gpa, "child"),21432 try ip.getOrPutString(gpa, "child", .no_embedded_nulls),
21374 ).?);21433 ).?);
2137521434
21376 const child_ty = child_val.toType();21435 const child_ty = child_val.toType();
...@@ -21382,11 +21441,11 @@ fn zirReify(...@@ -21382,11 +21441,11 @@ fn zirReify(
21382 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21441 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21383 const error_set_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21442 const error_set_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21384 ip,21443 ip,
21385 try ip.getOrPutString(gpa, "error_set"),21444 try ip.getOrPutString(gpa, "error_set", .no_embedded_nulls),
21386 ).?);21445 ).?);
21387 const payload_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21446 const payload_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21388 ip,21447 ip,
21389 try ip.getOrPutString(gpa, "payload"),21448 try ip.getOrPutString(gpa, "payload", .no_embedded_nulls),
21390 ).?);21449 ).?);
2139121450
21392 const error_set_ty = error_set_val.toType();21451 const error_set_ty = error_set_val.toType();
...@@ -21415,7 +21474,7 @@ fn zirReify(...@@ -21415,7 +21474,7 @@ fn zirReify(
21415 const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern()));21474 const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern()));
21416 const name_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(21475 const name_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(
21417 ip,21476 ip,
21418 try ip.getOrPutString(gpa, "name"),21477 try ip.getOrPutString(gpa, "name", .no_embedded_nulls),
21419 ).?);21478 ).?);
2142021479
21421 const name = try sema.sliceToIpString(block, src, name_val, .{21480 const name = try sema.sliceToIpString(block, src, name_val, .{
...@@ -21437,23 +21496,23 @@ fn zirReify(...@@ -21437,23 +21496,23 @@ fn zirReify(
21437 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21496 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21438 const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21497 const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21439 ip,21498 ip,
21440 try ip.getOrPutString(gpa, "layout"),21499 try ip.getOrPutString(gpa, "layout", .no_embedded_nulls),
21441 ).?);21500 ).?);
21442 const backing_integer_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21501 const backing_integer_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21443 ip,21502 ip,
21444 try ip.getOrPutString(gpa, "backing_integer"),21503 try ip.getOrPutString(gpa, "backing_integer", .no_embedded_nulls),
21445 ).?);21504 ).?);
21446 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21505 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21447 ip,21506 ip,
21448 try ip.getOrPutString(gpa, "fields"),21507 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
21449 ).?);21508 ).?);
21450 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21509 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21451 ip,21510 ip,
21452 try ip.getOrPutString(gpa, "decls"),21511 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
21453 ).?);21512 ).?);
21454 const is_tuple_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21513 const is_tuple_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21455 ip,21514 ip,
21456 try ip.getOrPutString(gpa, "is_tuple"),21515 try ip.getOrPutString(gpa, "is_tuple", .no_embedded_nulls),
21457 ).?);21516 ).?);
2145821517
21459 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);21518 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);
...@@ -21477,19 +21536,19 @@ fn zirReify(...@@ -21477,19 +21536,19 @@ fn zirReify(
21477 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21536 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21478 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21537 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21479 ip,21538 ip,
21480 try ip.getOrPutString(gpa, "tag_type"),21539 try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls),
21481 ).?);21540 ).?);
21482 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21541 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21483 ip,21542 ip,
21484 try ip.getOrPutString(gpa, "fields"),21543 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
21485 ).?);21544 ).?);
21486 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21545 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21487 ip,21546 ip,
21488 try ip.getOrPutString(gpa, "decls"),21547 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
21489 ).?);21548 ).?);
21490 const is_exhaustive_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21549 const is_exhaustive_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21491 ip,21550 ip,
21492 try ip.getOrPutString(gpa, "is_exhaustive"),21551 try ip.getOrPutString(gpa, "is_exhaustive", .no_embedded_nulls),
21493 ).?);21552 ).?);
2149421553
21495 if (try decls_val.sliceLen(sema) > 0) {21554 if (try decls_val.sliceLen(sema) > 0) {
...@@ -21506,7 +21565,7 @@ fn zirReify(...@@ -21506,7 +21565,7 @@ fn zirReify(
21506 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21565 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21507 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21566 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21508 ip,21567 ip,
21509 try ip.getOrPutString(gpa, "decls"),21568 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
21510 ).?);21569 ).?);
2151121570
21512 // Decls21571 // Decls
...@@ -21544,19 +21603,19 @@ fn zirReify(...@@ -21544,19 +21603,19 @@ fn zirReify(
21544 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21603 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21545 const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21604 const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21546 ip,21605 ip,
21547 try ip.getOrPutString(gpa, "layout"),21606 try ip.getOrPutString(gpa, "layout", .no_embedded_nulls),
21548 ).?);21607 ).?);
21549 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21608 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21550 ip,21609 ip,
21551 try ip.getOrPutString(gpa, "tag_type"),21610 try ip.getOrPutString(gpa, "tag_type", .no_embedded_nulls),
21552 ).?);21611 ).?);
21553 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21612 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21554 ip,21613 ip,
21555 try ip.getOrPutString(gpa, "fields"),21614 try ip.getOrPutString(gpa, "fields", .no_embedded_nulls),
21556 ).?);21615 ).?);
21557 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21616 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21558 ip,21617 ip,
21559 try ip.getOrPutString(gpa, "decls"),21618 try ip.getOrPutString(gpa, "decls", .no_embedded_nulls),
21560 ).?);21619 ).?);
2156121620
21562 if (try decls_val.sliceLen(sema) > 0) {21621 if (try decls_val.sliceLen(sema) > 0) {
...@@ -21574,23 +21633,23 @@ fn zirReify(...@@ -21574,23 +21633,23 @@ fn zirReify(
21574 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));21633 const struct_type = ip.loadStructType(ip.typeOf(union_val.val));
21575 const calling_convention_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21634 const calling_convention_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21576 ip,21635 ip,
21577 try ip.getOrPutString(gpa, "calling_convention"),21636 try ip.getOrPutString(gpa, "calling_convention", .no_embedded_nulls),
21578 ).?);21637 ).?);
21579 const is_generic_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21638 const is_generic_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21580 ip,21639 ip,
21581 try ip.getOrPutString(gpa, "is_generic"),21640 try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls),
21582 ).?);21641 ).?);
21583 const is_var_args_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21642 const is_var_args_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21584 ip,21643 ip,
21585 try ip.getOrPutString(gpa, "is_var_args"),21644 try ip.getOrPutString(gpa, "is_var_args", .no_embedded_nulls),
21586 ).?);21645 ).?);
21587 const return_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21646 const return_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21588 ip,21647 ip,
21589 try ip.getOrPutString(gpa, "return_type"),21648 try ip.getOrPutString(gpa, "return_type", .no_embedded_nulls),
21590 ).?);21649 ).?);
21591 const params_slice_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(21650 const params_slice_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
21592 ip,21651 ip,
21593 try ip.getOrPutString(gpa, "params"),21652 try ip.getOrPutString(gpa, "params", .no_embedded_nulls),
21594 ).?);21653 ).?);
2159521654
21596 const is_generic = is_generic_val.toBool();21655 const is_generic = is_generic_val.toBool();
...@@ -21620,15 +21679,15 @@ fn zirReify(...@@ -21620,15 +21679,15 @@ fn zirReify(
21620 const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern()));21679 const elem_struct_type = ip.loadStructType(ip.typeOf(elem_val.toIntern()));
21621 const param_is_generic_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(21680 const param_is_generic_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(
21622 ip,21681 ip,
21623 try ip.getOrPutString(gpa, "is_generic"),21682 try ip.getOrPutString(gpa, "is_generic", .no_embedded_nulls),
21624 ).?);21683 ).?);
21625 const param_is_noalias_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(21684 const param_is_noalias_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(
21626 ip,21685 ip,
21627 try ip.getOrPutString(gpa, "is_noalias"),21686 try ip.getOrPutString(gpa, "is_noalias", .no_embedded_nulls),
21628 ).?);21687 ).?);
21629 const opt_param_type_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(21688 const opt_param_type_val = try elem_val.fieldValue(mod, elem_struct_type.nameIndex(
21630 ip,21689 ip,
21631 try ip.getOrPutString(gpa, "type"),21690 try ip.getOrPutString(gpa, "type", .no_embedded_nulls),
21632 ).?);21691 ).?);
2163321692
21634 if (param_is_generic_val.toBool()) {21693 if (param_is_generic_val.toBool()) {
...@@ -22366,13 +22425,14 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)...@@ -22366,13 +22425,14 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2236622425
22367fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22426fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22368 const mod = sema.mod;22427 const mod = sema.mod;
22428 const ip = &mod.intern_pool;
22429
22369 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;22430 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
22370 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };22431 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22371 const ty = try sema.resolveType(block, ty_src, inst_data.operand);22432 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2237222433
22373 var bytes = std.ArrayList(u8).init(sema.arena);22434 const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls);
22374 try ty.print(bytes.writer(), mod);22435 return sema.addNullTerminatedStrLit(type_name);
22375 return addStrLitNoAlias(sema, bytes.items);
22376}22436}
2237722437
22378fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22438fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -23507,7 +23567,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6...@@ -23507,7 +23567,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
23507 }23567 }
2350823568
23509 const field_index = if (ty.isTuple(mod)) blk: {23569 const field_index = if (ty.isTuple(mod)) blk: {
23510 if (ip.stringEqlSlice(field_name, "len")) {23570 if (field_name.eqlSlice("len", ip)) {
23511 return sema.fail(block, src, "no offset available for 'len' field of tuple", .{});23571 return sema.fail(block, src, "no offset available for 'len' field of tuple", .{});
23512 }23572 }
23513 break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src);23573 break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src);
...@@ -23977,18 +24037,18 @@ fn resolveExportOptions(...@@ -23977,18 +24037,18 @@ fn resolveExportOptions(
23977 const section_src = sema.maybeOptionsSrc(block, src, "section");24037 const section_src = sema.maybeOptionsSrc(block, src, "section");
23978 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");24038 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");
2397924039
23980 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);24040 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
23981 const name = try sema.toConstString(block, name_src, name_operand, .{24041 const name = try sema.toConstString(block, name_src, name_operand, .{
23982 .needed_comptime_reason = "name of exported value must be comptime-known",24042 .needed_comptime_reason = "name of exported value must be comptime-known",
23983 });24043 });
2398424044
23985 const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);24045 const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage", .no_embedded_nulls), linkage_src);
23986 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{24046 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{
23987 .needed_comptime_reason = "linkage of exported value must be comptime-known",24047 .needed_comptime_reason = "linkage of exported value must be comptime-known",
23988 });24048 });
23989 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);24049 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2399024050
23991 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src);24051 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section", .no_embedded_nulls), section_src);
23992 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{24052 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{
23993 .needed_comptime_reason = "linksection of exported value must be comptime-known",24053 .needed_comptime_reason = "linksection of exported value must be comptime-known",
23994 });24054 });
...@@ -23999,7 +24059,7 @@ fn resolveExportOptions(...@@ -23999,7 +24059,7 @@ fn resolveExportOptions(
23999 else24059 else
24000 null;24060 null;
2400124061
24002 const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src);24062 const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility", .no_embedded_nulls), visibility_src);
24003 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{24063 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{
24004 .needed_comptime_reason = "visibility of exported value must be comptime-known",24064 .needed_comptime_reason = "visibility of exported value must be comptime-known",
24005 });24065 });
...@@ -24016,9 +24076,9 @@ fn resolveExportOptions(...@@ -24016,9 +24076,9 @@ fn resolveExportOptions(
24016 }24076 }
2401724077
24018 return .{24078 return .{
24019 .name = try ip.getOrPutString(gpa, name),24079 .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls),
24020 .linkage = linkage,24080 .linkage = linkage,
24021 .section = try ip.getOrPutStringOpt(gpa, section),24081 .section = try ip.getOrPutStringOpt(gpa, section, .no_embedded_nulls),
24022 .visibility = visibility,24082 .visibility = visibility,
24023 };24083 };
24024}24084}
...@@ -24896,7 +24956,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -24896,7 +24956,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
24896 const field_index = switch (parent_ty.zigTypeTag(mod)) {24956 const field_index = switch (parent_ty.zigTypeTag(mod)) {
24897 .Struct => blk: {24957 .Struct => blk: {
24898 if (parent_ty.isTuple(mod)) {24958 if (parent_ty.isTuple(mod)) {
24899 if (ip.stringEqlSlice(field_name, "len")) {24959 if (field_name.eqlSlice("len", ip)) {
24900 return sema.fail(block, inst_src, "cannot get @fieldParentPtr of 'len' field of tuple", .{});24960 return sema.fail(block, inst_src, "cannot get @fieldParentPtr of 'len' field of tuple", .{});
24901 }24961 }
24902 break :blk try sema.tupleFieldIndex(block, parent_ty, field_name, field_name_src);24962 break :blk try sema.tupleFieldIndex(block, parent_ty, field_name, field_name_src);
...@@ -25578,7 +25638,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25578,7 +25638,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2557825638
25579 const runtime_src = rs: {25639 const runtime_src = rs: {
25580 const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;25640 const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;
25581 const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, "len"), dest_src);25641 const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, "len", .no_embedded_nulls), dest_src);
25582 const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src;25642 const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src;
25583 const len_u64 = (try len_val.getUnsignedIntAdvanced(mod, sema)).?;25643 const len_u64 = (try len_val.getUnsignedIntAdvanced(mod, sema)).?;
25584 const len = try sema.usizeCast(block, dest_src, len_u64);25644 const len = try sema.usizeCast(block, dest_src, len_u64);
...@@ -25708,7 +25768,7 @@ fn zirVarExtended(...@@ -25708,7 +25768,7 @@ fn zirVarExtended(
25708 .ty = var_ty.toIntern(),25768 .ty = var_ty.toIntern(),
25709 .init = init_val,25769 .init = init_val,
25710 .decl = sema.owner_decl_index,25770 .decl = sema.owner_decl_index,
25711 .lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, lib_name),25771 .lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, lib_name, .no_embedded_nulls),
25712 .is_extern = small.is_extern,25772 .is_extern = small.is_extern,
25713 .is_const = small.is_const,25773 .is_const = small.is_const,
25714 .is_threadlocal = small.is_threadlocal,25774 .is_threadlocal = small.is_threadlocal,
...@@ -26076,17 +26136,17 @@ fn resolvePrefetchOptions(...@@ -26076,17 +26136,17 @@ fn resolvePrefetchOptions(
26076 const locality_src = sema.maybeOptionsSrc(block, src, "locality");26136 const locality_src = sema.maybeOptionsSrc(block, src, "locality");
26077 const cache_src = sema.maybeOptionsSrc(block, src, "cache");26137 const cache_src = sema.maybeOptionsSrc(block, src, "cache");
2607826138
26079 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src);26139 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src);
26080 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{26140 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
26081 .needed_comptime_reason = "prefetch read/write must be comptime-known",26141 .needed_comptime_reason = "prefetch read/write must be comptime-known",
26082 });26142 });
2608326143
26084 const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src);26144 const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality", .no_embedded_nulls), locality_src);
26085 const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{26145 const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{
26086 .needed_comptime_reason = "prefetch locality must be comptime-known",26146 .needed_comptime_reason = "prefetch locality must be comptime-known",
26087 });26147 });
2608826148
26089 const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src);26149 const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache", .no_embedded_nulls), cache_src);
26090 const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{26150 const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{
26091 .needed_comptime_reason = "prefetch cache must be comptime-known",26151 .needed_comptime_reason = "prefetch cache must be comptime-known",
26092 });26152 });
...@@ -26155,23 +26215,23 @@ fn resolveExternOptions(...@@ -26155,23 +26215,23 @@ fn resolveExternOptions(
26155 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");26215 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");
26156 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");26216 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");
2615726217
26158 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);26218 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
26159 const name = try sema.toConstString(block, name_src, name_ref, .{26219 const name = try sema.toConstString(block, name_src, name_ref, .{
26160 .needed_comptime_reason = "name of the extern symbol must be comptime-known",26220 .needed_comptime_reason = "name of the extern symbol must be comptime-known",
26161 });26221 });
2616226222
26163 const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src);26223 const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name", .no_embedded_nulls), library_src);
26164 const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{26224 const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{
26165 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",26225 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
26166 });26226 });
2616726227
26168 const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);26228 const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage", .no_embedded_nulls), linkage_src);
26169 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{26229 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{
26170 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",26230 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
26171 });26231 });
26172 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);26232 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2617326233
26174 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src);26234 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local", .no_embedded_nulls), thread_local_src);
26175 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{26235 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{
26176 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",26236 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
26177 });26237 });
...@@ -26196,8 +26256,8 @@ fn resolveExternOptions(...@@ -26196,8 +26256,8 @@ fn resolveExternOptions(
26196 }26256 }
2619726257
26198 return .{26258 return .{
26199 .name = try ip.getOrPutString(gpa, name),26259 .name = try ip.getOrPutString(gpa, name, .no_embedded_nulls),
26200 .library_name = try ip.getOrPutStringOpt(gpa, library_name),26260 .library_name = try ip.getOrPutStringOpt(gpa, library_name, .no_embedded_nulls),
26201 .linkage = linkage,26261 .linkage = linkage,
26202 .is_thread_local = is_thread_local_val.toBool(),26262 .is_thread_local = is_thread_local_val.toBool(),
26203 };26263 };
...@@ -26809,7 +26869,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP...@@ -26809,7 +26869,7 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP
26809 block,26869 block,
26810 .unneeded,26870 .unneeded,
26811 panic_messages_ty.getNamespaceIndex(mod),26871 panic_messages_ty.getNamespaceIndex(mod),
26812 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id)),26872 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls),
26813 ) catch |err| switch (err) {26873 ) catch |err| switch (err) {
26814 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"),26874 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"),
26815 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,26875 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
...@@ -27129,9 +27189,9 @@ fn fieldVal(...@@ -27129,9 +27189,9 @@ fn fieldVal(
2712927189
27130 switch (inner_ty.zigTypeTag(mod)) {27190 switch (inner_ty.zigTypeTag(mod)) {
27131 .Array => {27191 .Array => {
27132 if (ip.stringEqlSlice(field_name, "len")) {27192 if (field_name.eqlSlice("len", ip)) {
27133 return Air.internedToRef((try mod.intValue(Type.usize, inner_ty.arrayLen(mod))).toIntern());27193 return Air.internedToRef((try mod.intValue(Type.usize, inner_ty.arrayLen(mod))).toIntern());
27134 } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) {27194 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
27135 const ptr_info = object_ty.ptrInfo(mod);27195 const ptr_info = object_ty.ptrInfo(mod);
27136 const result_ty = try sema.ptrType(.{27196 const result_ty = try sema.ptrType(.{
27137 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),27197 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),
...@@ -27160,13 +27220,13 @@ fn fieldVal(...@@ -27160,13 +27220,13 @@ fn fieldVal(
27160 .Pointer => {27220 .Pointer => {
27161 const ptr_info = inner_ty.ptrInfo(mod);27221 const ptr_info = inner_ty.ptrInfo(mod);
27162 if (ptr_info.flags.size == .Slice) {27222 if (ptr_info.flags.size == .Slice) {
27163 if (ip.stringEqlSlice(field_name, "ptr")) {27223 if (field_name.eqlSlice("ptr", ip)) {
27164 const slice = if (is_pointer_to)27224 const slice = if (is_pointer_to)
27165 try sema.analyzeLoad(block, src, object, object_src)27225 try sema.analyzeLoad(block, src, object, object_src)
27166 else27226 else
27167 object;27227 object;
27168 return sema.analyzeSlicePtr(block, object_src, slice, inner_ty);27228 return sema.analyzeSlicePtr(block, object_src, slice, inner_ty);
27169 } else if (ip.stringEqlSlice(field_name, "len")) {27229 } else if (field_name.eqlSlice("len", ip)) {
27170 const slice = if (is_pointer_to)27230 const slice = if (is_pointer_to)
27171 try sema.analyzeLoad(block, src, object, object_src)27231 try sema.analyzeLoad(block, src, object, object_src)
27172 else27232 else
...@@ -27319,10 +27379,10 @@ fn fieldPtr(...@@ -27319,10 +27379,10 @@ fn fieldPtr(
2731927379
27320 switch (inner_ty.zigTypeTag(mod)) {27380 switch (inner_ty.zigTypeTag(mod)) {
27321 .Array => {27381 .Array => {
27322 if (ip.stringEqlSlice(field_name, "len")) {27382 if (field_name.eqlSlice("len", ip)) {
27323 const int_val = try mod.intValue(Type.usize, inner_ty.arrayLen(mod));27383 const int_val = try mod.intValue(Type.usize, inner_ty.arrayLen(mod));
27324 return anonDeclRef(sema, int_val.toIntern());27384 return anonDeclRef(sema, int_val.toIntern());
27325 } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) {27385 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
27326 const ptr_info = object_ty.ptrInfo(mod);27386 const ptr_info = object_ty.ptrInfo(mod);
27327 const new_ptr_ty = try sema.ptrType(.{27387 const new_ptr_ty = try sema.ptrType(.{
27328 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),27388 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),
...@@ -27370,7 +27430,7 @@ fn fieldPtr(...@@ -27370,7 +27430,7 @@ fn fieldPtr(
2737027430
27371 const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty;27431 const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty;
2737227432
27373 if (ip.stringEqlSlice(field_name, "ptr")) {27433 if (field_name.eqlSlice("ptr", ip)) {
27374 const slice_ptr_ty = inner_ty.slicePtrFieldType(mod);27434 const slice_ptr_ty = inner_ty.slicePtrFieldType(mod);
2737527435
27376 const result_ty = try sema.ptrType(.{27436 const result_ty = try sema.ptrType(.{
...@@ -27396,7 +27456,7 @@ fn fieldPtr(...@@ -27396,7 +27456,7 @@ fn fieldPtr(
27396 const field_ptr = try block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr);27456 const field_ptr = try block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr);
27397 try sema.checkKnownAllocPtr(block, inner_ptr, field_ptr);27457 try sema.checkKnownAllocPtr(block, inner_ptr, field_ptr);
27398 return field_ptr;27458 return field_ptr;
27399 } else if (ip.stringEqlSlice(field_name, "len")) {27459 } else if (field_name.eqlSlice("len", ip)) {
27400 const result_ty = try sema.ptrType(.{27460 const result_ty = try sema.ptrType(.{
27401 .child = .usize_type,27461 .child = .usize_type,
27402 .flags = .{27462 .flags = .{
...@@ -27584,7 +27644,7 @@ fn fieldCallBind(...@@ -27584,7 +27644,7 @@ fn fieldCallBind(
2758427644
27585 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);27645 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);
27586 } else if (concrete_ty.isTuple(mod)) {27646 } else if (concrete_ty.isTuple(mod)) {
27587 if (ip.stringEqlSlice(field_name, "len")) {27647 if (field_name.eqlSlice("len", ip)) {
27588 return .{ .direct = try mod.intRef(Type.usize, concrete_ty.structFieldCount(mod)) };27648 return .{ .direct = try mod.intRef(Type.usize, concrete_ty.structFieldCount(mod)) };
27589 }27649 }
27590 if (field_name.toUnsigned(ip)) |field_index| {27650 if (field_name.toUnsigned(ip)) |field_index| {
...@@ -27808,7 +27868,7 @@ fn structFieldPtr(...@@ -27808,7 +27868,7 @@ fn structFieldPtr(
27808 try sema.resolveStructLayout(struct_ty);27868 try sema.resolveStructLayout(struct_ty);
2780927869
27810 if (struct_ty.isTuple(mod)) {27870 if (struct_ty.isTuple(mod)) {
27811 if (ip.stringEqlSlice(field_name, "len")) {27871 if (field_name.eqlSlice("len", ip)) {
27812 const len_inst = try mod.intRef(Type.usize, struct_ty.structFieldCount(mod));27872 const len_inst = try mod.intRef(Type.usize, struct_ty.structFieldCount(mod));
27813 return sema.analyzeRef(block, src, len_inst);27873 return sema.analyzeRef(block, src, len_inst);
27814 }27874 }
...@@ -28023,7 +28083,7 @@ fn tupleFieldVal(...@@ -28023,7 +28083,7 @@ fn tupleFieldVal(
28023 tuple_ty: Type,28083 tuple_ty: Type,
28024) CompileError!Air.Inst.Ref {28084) CompileError!Air.Inst.Ref {
28025 const mod = sema.mod;28085 const mod = sema.mod;
28026 if (mod.intern_pool.stringEqlSlice(field_name, "len")) {28086 if (field_name.eqlSlice("len", &mod.intern_pool)) {
28027 return mod.intRef(Type.usize, tuple_ty.structFieldCount(mod));28087 return mod.intRef(Type.usize, tuple_ty.structFieldCount(mod));
28028 }28088 }
28029 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);28089 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);
...@@ -28039,16 +28099,17 @@ fn tupleFieldIndex(...@@ -28039,16 +28099,17 @@ fn tupleFieldIndex(
28039 field_name_src: LazySrcLoc,28099 field_name_src: LazySrcLoc,
28040) CompileError!u32 {28100) CompileError!u32 {
28041 const mod = sema.mod;28101 const mod = sema.mod;
28042 assert(!mod.intern_pool.stringEqlSlice(field_name, "len"));28102 const ip = &mod.intern_pool;
28043 if (field_name.toUnsigned(&mod.intern_pool)) |field_index| {28103 assert(!field_name.eqlSlice("len", ip));
28104 if (field_name.toUnsigned(ip)) |field_index| {
28044 if (field_index < tuple_ty.structFieldCount(mod)) return field_index;28105 if (field_index < tuple_ty.structFieldCount(mod)) return field_index;
28045 return sema.fail(block, field_name_src, "index '{}' out of bounds of tuple '{}'", .{28106 return sema.fail(block, field_name_src, "index '{}' out of bounds of tuple '{}'", .{
28046 field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod),28107 field_name.fmt(ip), tuple_ty.fmt(mod),
28047 });28108 });
28048 }28109 }
2804928110
28050 return sema.fail(block, field_name_src, "no field named '{}' in tuple '{}'", .{28111 return sema.fail(block, field_name_src, "no field named '{}' in tuple '{}'", .{
28051 field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod),28112 field_name.fmt(ip), tuple_ty.fmt(mod),
28052 });28113 });
28053}28114}
2805428115
...@@ -28076,7 +28137,7 @@ fn tupleFieldValByIndex(...@@ -28076,7 +28137,7 @@ fn tupleFieldValByIndex(
28076 return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) {28137 return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) {
28077 .undef => mod.undefRef(field_ty),28138 .undef => mod.undefRef(field_ty),
28078 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {28139 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {
28079 .bytes => |bytes| try mod.intValue(Type.u8, bytes[0]),28140 .bytes => |bytes| try mod.intValue(Type.u8, bytes.at(field_index, &mod.intern_pool)),
28080 .elems => |elems| Value.fromInterned(elems[field_index]),28141 .elems => |elems| Value.fromInterned(elems[field_index]),
28081 .repeated_elem => |elem| Value.fromInterned(elem),28142 .repeated_elem => |elem| Value.fromInterned(elem),
28082 }.toIntern()),28143 }.toIntern()),
...@@ -32266,38 +32327,36 @@ fn coerceTupleToStruct(...@@ -32266,38 +32327,36 @@ fn coerceTupleToStruct(
32266 .struct_type => ip.loadStructType(inst_ty.toIntern()).field_types.len,32327 .struct_type => ip.loadStructType(inst_ty.toIntern()).field_types.len,
32267 else => unreachable,32328 else => unreachable,
32268 };32329 };
32269 for (0..field_count) |field_index_usize| {32330 for (0..field_count) |tuple_field_index| {
32270 const field_i: u32 = @intCast(field_index_usize);
32271 const field_src = inst_src; // TODO better source location32331 const field_src = inst_src; // TODO better source location
32272 // https://github.com/ziglang/zig/issues/15709
32273 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {32332 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
32274 .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0)32333 .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0)
32275 anon_struct_type.names.get(ip)[field_i]32334 anon_struct_type.names.get(ip)[tuple_field_index]
32276 else32335 else
32277 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}),32336 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{tuple_field_index}, .no_embedded_nulls),
32278 .struct_type => ip.loadStructType(inst_ty.toIntern()).field_names.get(ip)[field_i],32337 .struct_type => ip.loadStructType(inst_ty.toIntern()).field_names.get(ip)[tuple_field_index],
32279 else => unreachable,32338 else => unreachable,
32280 };32339 };
32281 const field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);32340 const struct_field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);
32282 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);32341 const struct_field_ty = Type.fromInterned(struct_type.field_types.get(ip)[struct_field_index]);
32283 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i);32342 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, @intCast(tuple_field_index));
32284 const coerced = try sema.coerce(block, field_ty, elem_ref, field_src);32343 const coerced = try sema.coerce(block, struct_field_ty, elem_ref, field_src);
32285 field_refs[field_index] = coerced;32344 field_refs[struct_field_index] = coerced;
32286 if (struct_type.fieldIsComptime(ip, field_index)) {32345 if (struct_type.fieldIsComptime(ip, struct_field_index)) {
32287 const init_val = (try sema.resolveValue(coerced)) orelse {32346 const init_val = (try sema.resolveValue(coerced)) orelse {
32288 return sema.failWithNeededComptime(block, field_src, .{32347 return sema.failWithNeededComptime(block, field_src, .{
32289 .needed_comptime_reason = "value stored in comptime field must be comptime-known",32348 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
32290 });32349 });
32291 };32350 };
3229232351
32293 const field_init = Value.fromInterned(struct_type.field_inits.get(ip)[field_index]);32352 const field_init = Value.fromInterned(struct_type.field_inits.get(ip)[struct_field_index]);
32294 if (!init_val.eql(field_init, field_ty, sema.mod)) {32353 if (!init_val.eql(field_init, struct_field_ty, sema.mod)) {
32295 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);32354 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, tuple_field_index);
32296 }32355 }
32297 }32356 }
32298 if (runtime_src == null) {32357 if (runtime_src == null) {
32299 if (try sema.resolveValue(coerced)) |field_val| {32358 if (try sema.resolveValue(coerced)) |field_val| {
32300 field_vals[field_index] = field_val.toIntern();32359 field_vals[struct_field_index] = field_val.toIntern();
32301 } else {32360 } else {
32302 runtime_src = field_src;32361 runtime_src = field_src;
32303 }32362 }
...@@ -32382,24 +32441,23 @@ fn coerceTupleToTuple(...@@ -32382,24 +32441,23 @@ fn coerceTupleToTuple(
32382 for (0..dest_field_count) |field_index_usize| {32441 for (0..dest_field_count) |field_index_usize| {
32383 const field_i: u32 = @intCast(field_index_usize);32442 const field_i: u32 = @intCast(field_index_usize);
32384 const field_src = inst_src; // TODO better source location32443 const field_src = inst_src; // TODO better source location
32385 // https://github.com/ziglang/zig/issues/15709
32386 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {32444 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
32387 .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0)32445 .anon_struct_type => |anon_struct_type| if (anon_struct_type.names.len > 0)
32388 anon_struct_type.names.get(ip)[field_i]32446 anon_struct_type.names.get(ip)[field_i]
32389 else32447 else
32390 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}),32448 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls),
32391 .struct_type => s: {32449 .struct_type => s: {
32392 const struct_type = ip.loadStructType(inst_ty.toIntern());32450 const struct_type = ip.loadStructType(inst_ty.toIntern());
32393 if (struct_type.field_names.len > 0) {32451 if (struct_type.field_names.len > 0) {
32394 break :s struct_type.field_names.get(ip)[field_i];32452 break :s struct_type.field_names.get(ip)[field_i];
32395 } else {32453 } else {
32396 break :s try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i});32454 break :s try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_i}, .no_embedded_nulls);
32397 }32455 }
32398 },32456 },
32399 else => unreachable,32457 else => unreachable,
32400 };32458 };
3240132459
32402 if (ip.stringEqlSlice(field_name, "len"))32460 if (field_name.eqlSlice("len", ip))
32403 return sema.fail(block, field_src, "cannot assign to 'len' field of tuple", .{});32461 return sema.fail(block, field_src, "cannot assign to 'len' field of tuple", .{});
3240432462
32405 const field_ty = switch (ip.indexToKey(tuple_ty.toIntern())) {32463 const field_ty = switch (ip.indexToKey(tuple_ty.toIntern())) {
...@@ -34196,7 +34254,7 @@ const PeerResolveResult = union(enum) {...@@ -34196,7 +34254,7 @@ const PeerResolveResult = union(enum) {
34196 /// There was an error when resolving the type of a struct or tuple field.34254 /// There was an error when resolving the type of a struct or tuple field.
34197 field_error: struct {34255 field_error: struct {
34198 /// The name of the field which caused the failure.34256 /// The name of the field which caused the failure.
34199 field_name: []const u8,34257 field_name: InternPool.NullTerminatedString,
34200 /// The type of this field in each peer.34258 /// The type of this field in each peer.
34201 field_types: []Type,34259 field_types: []Type,
34202 /// The error from resolving the field type. Guaranteed not to be `success`.34260 /// The error from resolving the field type. Guaranteed not to be `success`.
...@@ -34237,8 +34295,8 @@ const PeerResolveResult = union(enum) {...@@ -34237,8 +34295,8 @@ const PeerResolveResult = union(enum) {
34237 };34295 };
34238 },34296 },
34239 .field_error => |field_error| {34297 .field_error => |field_error| {
34240 const fmt = "struct field '{s}' has conflicting types";34298 const fmt = "struct field '{}' has conflicting types";
34241 const args = .{field_error.field_name};34299 const args = .{field_error.field_name.fmt(&mod.intern_pool)};
34242 if (opt_msg) |msg| {34300 if (opt_msg) |msg| {
34243 try sema.errNote(block, src, msg, fmt, args);34301 try sema.errNote(block, src, msg, fmt, args);
34244 } else {34302 } else {
...@@ -35321,7 +35379,7 @@ fn resolvePeerTypesInner(...@@ -35321,7 +35379,7 @@ fn resolvePeerTypesInner(
35321 const sub_peer_tys = try sema.arena.alloc(?Type, peer_tys.len);35379 const sub_peer_tys = try sema.arena.alloc(?Type, peer_tys.len);
35322 const sub_peer_vals = try sema.arena.alloc(?Value, peer_vals.len);35380 const sub_peer_vals = try sema.arena.alloc(?Value, peer_vals.len);
3532335381
35324 for (field_types, field_vals, 0..) |*field_ty, *field_val, field_idx| {35382 for (field_types, field_vals, 0..) |*field_ty, *field_val, field_index| {
35325 // Fill buffers with types and values of the field35383 // Fill buffers with types and values of the field
35326 for (peer_tys, peer_vals, sub_peer_tys, sub_peer_vals) |opt_ty, opt_val, *peer_field_ty, *peer_field_val| {35384 for (peer_tys, peer_vals, sub_peer_tys, sub_peer_vals) |opt_ty, opt_val, *peer_field_ty, *peer_field_val| {
35327 const ty = opt_ty orelse {35385 const ty = opt_ty orelse {
...@@ -35329,8 +35387,8 @@ fn resolvePeerTypesInner(...@@ -35329,8 +35387,8 @@ fn resolvePeerTypesInner(
35329 peer_field_val.* = null;35387 peer_field_val.* = null;
35330 continue;35388 continue;
35331 };35389 };
35332 peer_field_ty.* = ty.structFieldType(field_idx, mod);35390 peer_field_ty.* = ty.structFieldType(field_index, mod);
35333 peer_field_val.* = if (opt_val) |val| try val.fieldValue(mod, field_idx) else null;35391 peer_field_val.* = if (opt_val) |val| try val.fieldValue(mod, field_index) else null;
35334 }35392 }
3533535393
35336 // Resolve field type recursively35394 // Resolve field type recursively
...@@ -35339,9 +35397,10 @@ fn resolvePeerTypesInner(...@@ -35339,9 +35397,10 @@ fn resolvePeerTypesInner(
35339 else => |result| {35397 else => |result| {
35340 const result_buf = try sema.arena.create(PeerResolveResult);35398 const result_buf = try sema.arena.create(PeerResolveResult);
35341 result_buf.* = result;35399 result_buf.* = result;
35342 const field_name = if (is_tuple) name: {35400 const field_name = if (is_tuple)
35343 break :name try std.fmt.allocPrint(sema.arena, "{d}", .{field_idx});35401 try ip.getOrPutStringFmt(sema.gpa, "{d}", .{field_index}, .no_embedded_nulls)
35344 } else try sema.arena.dupe(u8, ip.stringToSlice(field_names[field_idx]));35402 else
35403 field_names[field_index];
3534535404
35346 // The error info needs the field types, but we can't reuse sub_peer_tys35405 // The error info needs the field types, but we can't reuse sub_peer_tys
35347 // since the recursive call may have clobbered it.35406 // since the recursive call may have clobbered it.
...@@ -35350,7 +35409,7 @@ fn resolvePeerTypesInner(...@@ -35350,7 +35409,7 @@ fn resolvePeerTypesInner(
35350 // Already-resolved types won't be referenced by the error so it's fine35409 // Already-resolved types won't be referenced by the error so it's fine
35351 // to leave them undefined.35410 // to leave them undefined.
35352 const ty = opt_ty orelse continue;35411 const ty = opt_ty orelse continue;
35353 peer_field_ty.* = ty.structFieldType(field_idx, mod);35412 peer_field_ty.* = ty.structFieldType(field_index, mod);
35354 }35413 }
3535535414
35356 return .{ .field_error = .{35415 return .{ .field_error = .{
...@@ -35369,7 +35428,7 @@ fn resolvePeerTypesInner(...@@ -35369,7 +35428,7 @@ fn resolvePeerTypesInner(
35369 const struct_ty = opt_ty orelse continue;35428 const struct_ty = opt_ty orelse continue;
35370 try sema.resolveStructFieldInits(struct_ty);35429 try sema.resolveStructFieldInits(struct_ty);
3537135430
35372 const uncoerced_field_val = try struct_ty.structFieldValueComptime(mod, field_idx) orelse {35431 const uncoerced_field_val = try struct_ty.structFieldValueComptime(mod, field_index) orelse {
35373 comptime_val = null;35432 comptime_val = null;
35374 break;35433 break;
35375 };35434 };
...@@ -36811,7 +36870,7 @@ fn semaStructFields(...@@ -36811,7 +36870,7 @@ fn semaStructFields(
3681136870
36812 // This string needs to outlive the ZIR code.36871 // This string needs to outlive the ZIR code.
36813 if (opt_field_name_zir) |field_name_zir| {36872 if (opt_field_name_zir) |field_name_zir| {
36814 const field_name = try ip.getOrPutString(gpa, field_name_zir);36873 const field_name = try ip.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
36815 assert(struct_type.addFieldName(ip, field_name) == null);36874 assert(struct_type.addFieldName(ip, field_name) == null);
36816 }36875 }
3681736876
...@@ -37342,7 +37401,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -37342,7 +37401,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
37342 }37401 }
3734337402
37344 // This string needs to outlive the ZIR code.37403 // This string needs to outlive the ZIR code.
37345 const field_name = try ip.getOrPutString(gpa, field_name_zir);37404 const field_name = try ip.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
37346 if (enum_field_names.len != 0) {37405 if (enum_field_names.len != 0) {
37347 enum_field_names[field_i] = field_name;37406 enum_field_names[field_i] = field_name;
37348 }37407 }
...@@ -37528,7 +37587,12 @@ fn generateUnionTagTypeNumbered(...@@ -37528,7 +37587,12 @@ fn generateUnionTagTypeNumbered(
37528 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);37587 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
37529 errdefer mod.destroyDecl(new_decl_index);37588 errdefer mod.destroyDecl(new_decl_index);
37530 const fqn = try union_owner_decl.fullyQualifiedName(mod);37589 const fqn = try union_owner_decl.fullyQualifiedName(mod);
37531 const name = try ip.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(ip)});37590 const name = try ip.getOrPutStringFmt(
37591 gpa,
37592 "@typeInfo({}).Union.tag_type.?",
37593 .{fqn.fmt(ip)},
37594 .no_embedded_nulls,
37595 );
37532 try mod.initNewAnonDecl(37596 try mod.initNewAnonDecl(
37533 new_decl_index,37597 new_decl_index,
37534 src_decl.src_line,37598 src_decl.src_line,
...@@ -37574,7 +37638,12 @@ fn generateUnionTagTypeSimple(...@@ -37574,7 +37638,12 @@ fn generateUnionTagTypeSimple(
37574 const src_decl = mod.declPtr(block.src_decl);37638 const src_decl = mod.declPtr(block.src_decl);
37575 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);37639 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
37576 errdefer mod.destroyDecl(new_decl_index);37640 errdefer mod.destroyDecl(new_decl_index);
37577 const name = try ip.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(ip)});37641 const name = try ip.getOrPutStringFmt(
37642 gpa,
37643 "@typeInfo({}).Union.tag_type.?",
37644 .{fqn.fmt(ip)},
37645 .no_embedded_nulls,
37646 );
37578 try mod.initNewAnonDecl(37647 try mod.initNewAnonDecl(
37579 new_decl_index,37648 new_decl_index,
37580 src_decl.src_line,37649 src_decl.src_line,
...@@ -37638,7 +37707,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int...@@ -37638,7 +37707,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int
37638 block,37707 block,
37639 src,37708 src,
37640 mod.declPtr(std_file.root_decl.unwrap().?).src_namespace.toOptional(),37709 mod.declPtr(std_file.root_decl.unwrap().?).src_namespace.toOptional(),
37641 try ip.getOrPutString(gpa, "builtin"),37710 try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls),
37642 )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'");37711 )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'");
37643 const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst, src);37712 const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst, src);
37644 const builtin_ty = sema.analyzeAsType(block, src, builtin_inst) catch |err| switch (err) {37713 const builtin_ty = sema.analyzeAsType(block, src, builtin_inst) catch |err| switch (err) {
...@@ -37649,7 +37718,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int...@@ -37649,7 +37718,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int
37649 block,37718 block,
37650 src,37719 src,
37651 builtin_ty.getNamespaceIndex(mod),37720 builtin_ty.getNamespaceIndex(mod),
37652 try ip.getOrPutString(gpa, name),37721 try ip.getOrPutString(gpa, name, .no_embedded_nulls),
37653 )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name});37722 )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name});
37654 return decl_index;37723 return decl_index;
37655}37724}
...@@ -38820,7 +38889,7 @@ fn intFitsInType(...@@ -38820,7 +38889,7 @@ fn intFitsInType(
38820 .aggregate => |aggregate| {38889 .aggregate => |aggregate| {
38821 assert(ty.zigTypeTag(mod) == .Vector);38890 assert(ty.zigTypeTag(mod) == .Vector);
38822 return switch (aggregate.storage) {38891 return switch (aggregate.storage) {
38823 .bytes => |bytes| for (bytes, 0..) |byte, i| {38892 .bytes => |bytes| for (bytes.toSlice(ty.vectorLen(mod), &mod.intern_pool), 0..) |byte, i| {
38824 if (byte == 0) continue;38893 if (byte == 0) continue;
38825 const actual_needed_bits = std.math.log2(byte) + 1 + @intFromBool(info.signedness == .signed);38894 const actual_needed_bits = std.math.log2(byte) + 1 + @intFromBool(info.signedness == .signed);
38826 if (info.bits >= actual_needed_bits) continue;38895 if (info.bits >= actual_needed_bits) continue;
src/Value.zig+95-85
...@@ -52,30 +52,31 @@ pub fn toIpString(val: Value, ty: Type, mod: *Module) !InternPool.NullTerminated...@@ -52,30 +52,31 @@ pub fn toIpString(val: Value, ty: Type, mod: *Module) !InternPool.NullTerminated
52 assert(ty.zigTypeTag(mod) == .Array);52 assert(ty.zigTypeTag(mod) == .Array);
53 assert(ty.childType(mod).toIntern() == .u8_type);53 assert(ty.childType(mod).toIntern() == .u8_type);
54 const ip = &mod.intern_pool;54 const ip = &mod.intern_pool;
55 return switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {55 switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {
56 .bytes => |bytes| try ip.getOrPutString(mod.gpa, bytes),56 .bytes => |bytes| return bytes.toNullTerminatedString(ty.arrayLen(mod), ip),
57 .elems => try arrayToIpString(val, ty.arrayLen(mod), mod),57 .elems => return arrayToIpString(val, ty.arrayLen(mod), mod),
58 .repeated_elem => |elem| {58 .repeated_elem => |elem| {
59 const byte = @as(u8, @intCast(Value.fromInterned(elem).toUnsignedInt(mod)));59 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(mod));
60 const len = @as(usize, @intCast(ty.arrayLen(mod)));60 const len: usize = @intCast(ty.arrayLen(mod));
61 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);61 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);
62 return ip.getOrPutTrailingString(mod.gpa, len);62 return ip.getOrPutTrailingString(mod.gpa, len, .no_embedded_nulls);
63 },63 },
64 };64 }
65}65}
6666
67/// Asserts that the value is representable as an array of bytes.67/// Asserts that the value is representable as an array of bytes.
68/// Copies the value into a freshly allocated slice of memory, which is owned by the caller.68/// Copies the value into a freshly allocated slice of memory, which is owned by the caller.
69pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module) ![]u8 {69pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module) ![]u8 {
70 return switch (mod.intern_pool.indexToKey(val.toIntern())) {70 const ip = &mod.intern_pool;
71 .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)),71 return switch (ip.indexToKey(val.toIntern())) {
72 .enum_literal => |enum_literal| allocator.dupe(u8, enum_literal.toSlice(ip)),
72 .slice => |slice| try arrayToAllocatedBytes(val, Value.fromInterned(slice.len).toUnsignedInt(mod), allocator, mod),73 .slice => |slice| try arrayToAllocatedBytes(val, Value.fromInterned(slice.len).toUnsignedInt(mod), allocator, mod),
73 .aggregate => |aggregate| switch (aggregate.storage) {74 .aggregate => |aggregate| switch (aggregate.storage) {
74 .bytes => |bytes| try allocator.dupe(u8, bytes),75 .bytes => |bytes| try allocator.dupe(u8, bytes.toSlice(ty.arrayLenIncludingSentinel(mod), ip)),
75 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),76 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
76 .repeated_elem => |elem| {77 .repeated_elem => |elem| {
77 const byte = @as(u8, @intCast(Value.fromInterned(elem).toUnsignedInt(mod)));78 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(mod));
78 const result = try allocator.alloc(u8, @as(usize, @intCast(ty.arrayLen(mod))));79 const result = try allocator.alloc(u8, @intCast(ty.arrayLen(mod)));
79 @memset(result, byte);80 @memset(result, byte);
80 return result;81 return result;
81 },82 },
...@@ -85,10 +86,10 @@ pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module...@@ -85,10 +86,10 @@ pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module
85}86}
8687
87fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 {88fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 {
88 const result = try allocator.alloc(u8, @as(usize, @intCast(len)));89 const result = try allocator.alloc(u8, @intCast(len));
89 for (result, 0..) |*elem, i| {90 for (result, 0..) |*elem, i| {
90 const elem_val = try val.elemValue(mod, i);91 const elem_val = try val.elemValue(mod, i);
91 elem.* = @as(u8, @intCast(elem_val.toUnsignedInt(mod)));92 elem.* = @intCast(elem_val.toUnsignedInt(mod));
92 }93 }
93 return result;94 return result;
94}95}
...@@ -96,7 +97,7 @@ fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Modul...@@ -96,7 +97,7 @@ fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Modul
96fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTerminatedString {97fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTerminatedString {
97 const gpa = mod.gpa;98 const gpa = mod.gpa;
98 const ip = &mod.intern_pool;99 const ip = &mod.intern_pool;
99 const len = @as(usize, @intCast(len_u64));100 const len: usize = @intCast(len_u64);
100 try ip.string_bytes.ensureUnusedCapacity(gpa, len);101 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
101 for (0..len) |i| {102 for (0..len) |i| {
102 // I don't think elemValue has the possibility to affect ip.string_bytes. Let's103 // I don't think elemValue has the possibility to affect ip.string_bytes. Let's
...@@ -104,10 +105,10 @@ fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTermi...@@ -104,10 +105,10 @@ fn arrayToIpString(val: Value, len_u64: u64, mod: *Module) !InternPool.NullTermi
104 const prev = ip.string_bytes.items.len;105 const prev = ip.string_bytes.items.len;
105 const elem_val = try val.elemValue(mod, i);106 const elem_val = try val.elemValue(mod, i);
106 assert(ip.string_bytes.items.len == prev);107 assert(ip.string_bytes.items.len == prev);
107 const byte = @as(u8, @intCast(elem_val.toUnsignedInt(mod)));108 const byte: u8 = @intCast(elem_val.toUnsignedInt(mod));
108 ip.string_bytes.appendAssumeCapacity(byte);109 ip.string_bytes.appendAssumeCapacity(byte);
109 }110 }
110 return ip.getOrPutTrailingString(gpa, len);111 return ip.getOrPutTrailingString(gpa, len, .no_embedded_nulls);
111}112}
112113
113pub fn fromInterned(i: InternPool.Index) Value {114pub fn fromInterned(i: InternPool.Index) Value {
...@@ -256,7 +257,7 @@ pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64...@@ -256,7 +257,7 @@ pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64
256 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;257 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
257 const struct_ty = Value.fromInterned(field.base).typeOf(mod).childType(mod);258 const struct_ty = Value.fromInterned(field.base).typeOf(mod).childType(mod);
258 if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty);259 if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty);
259 return base_addr + struct_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod);260 return base_addr + struct_ty.structFieldOffset(@intCast(field.index), mod);
260 },261 },
261 else => null,262 else => null,
262 },263 },
...@@ -351,17 +352,17 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{...@@ -351,17 +352,17 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{
351 bigint.writeTwosComplement(buffer[0..byte_count], endian);352 bigint.writeTwosComplement(buffer[0..byte_count], endian);
352 },353 },
353 .Float => switch (ty.floatBits(target)) {354 .Float => switch (ty.floatBits(target)) {
354 16 => std.mem.writeInt(u16, buffer[0..2], @as(u16, @bitCast(val.toFloat(f16, mod))), endian),355 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(val.toFloat(f16, mod)), endian),
355 32 => std.mem.writeInt(u32, buffer[0..4], @as(u32, @bitCast(val.toFloat(f32, mod))), endian),356 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(val.toFloat(f32, mod)), endian),
356 64 => std.mem.writeInt(u64, buffer[0..8], @as(u64, @bitCast(val.toFloat(f64, mod))), endian),357 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(val.toFloat(f64, mod)), endian),
357 80 => std.mem.writeInt(u80, buffer[0..10], @as(u80, @bitCast(val.toFloat(f80, mod))), endian),358 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(val.toFloat(f80, mod)), endian),
358 128 => std.mem.writeInt(u128, buffer[0..16], @as(u128, @bitCast(val.toFloat(f128, mod))), endian),359 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(val.toFloat(f128, mod)), endian),
359 else => unreachable,360 else => unreachable,
360 },361 },
361 .Array => {362 .Array => {
362 const len = ty.arrayLen(mod);363 const len = ty.arrayLen(mod);
363 const elem_ty = ty.childType(mod);364 const elem_ty = ty.childType(mod);
364 const elem_size = @as(usize, @intCast(elem_ty.abiSize(mod)));365 const elem_size: usize = @intCast(elem_ty.abiSize(mod));
365 var elem_i: usize = 0;366 var elem_i: usize = 0;
366 var buf_off: usize = 0;367 var buf_off: usize = 0;
367 while (elem_i < len) : (elem_i += 1) {368 while (elem_i < len) : (elem_i += 1) {
...@@ -380,17 +381,17 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{...@@ -380,17 +381,17 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{
380 const struct_type = mod.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;381 const struct_type = mod.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;
381 switch (struct_type.layout) {382 switch (struct_type.layout) {
382 .auto => return error.IllDefinedMemoryLayout,383 .auto => return error.IllDefinedMemoryLayout,
383 .@"extern" => for (0..struct_type.field_types.len) |i| {384 .@"extern" => for (0..struct_type.field_types.len) |field_index| {
384 const off: usize = @intCast(ty.structFieldOffset(i, mod));385 const off: usize = @intCast(ty.structFieldOffset(field_index, mod));
385 const field_val = Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {386 const field_val = Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
386 .bytes => |bytes| {387 .bytes => |bytes| {
387 buffer[off] = bytes[i];388 buffer[off] = bytes.at(field_index, ip);
388 continue;389 continue;
389 },390 },
390 .elems => |elems| elems[i],391 .elems => |elems| elems[field_index],
391 .repeated_elem => |elem| elem,392 .repeated_elem => |elem| elem,
392 });393 });
393 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);394 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
394 try writeToMemory(field_val, field_ty, mod, buffer[off..]);395 try writeToMemory(field_val, field_ty, mod, buffer[off..]);
395 },396 },
396 .@"packed" => {397 .@"packed" => {
...@@ -423,7 +424,7 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{...@@ -423,7 +424,7 @@ pub fn writeToMemory(val: Value, ty: Type, mod: *Module, buffer: []u8) error{
423 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;424 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;
424 const field_type = Type.fromInterned(union_obj.field_types.get(&mod.intern_pool)[field_index]);425 const field_type = Type.fromInterned(union_obj.field_types.get(&mod.intern_pool)[field_index]);
425 const field_val = try val.fieldValue(mod, field_index);426 const field_val = try val.fieldValue(mod, field_index);
426 const byte_count = @as(usize, @intCast(field_type.abiSize(mod)));427 const byte_count: usize = @intCast(field_type.abiSize(mod));
427 return writeToMemory(field_val, field_type, mod, buffer[0..byte_count]);428 return writeToMemory(field_val, field_type, mod, buffer[0..byte_count]);
428 } else {429 } else {
429 const backing_ty = try ty.unionBackingType(mod);430 const backing_ty = try ty.unionBackingType(mod);
...@@ -471,7 +472,7 @@ pub fn writeToPackedMemory(...@@ -471,7 +472,7 @@ pub fn writeToPackedMemory(
471 const target = mod.getTarget();472 const target = mod.getTarget();
472 const endian = target.cpu.arch.endian();473 const endian = target.cpu.arch.endian();
473 if (val.isUndef(mod)) {474 if (val.isUndef(mod)) {
474 const bit_size = @as(usize, @intCast(ty.bitSize(mod)));475 const bit_size: usize = @intCast(ty.bitSize(mod));
475 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);476 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);
476 return;477 return;
477 }478 }
...@@ -507,17 +508,17 @@ pub fn writeToPackedMemory(...@@ -507,17 +508,17 @@ pub fn writeToPackedMemory(
507 }508 }
508 },509 },
509 .Float => switch (ty.floatBits(target)) {510 .Float => switch (ty.floatBits(target)) {
510 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @as(u16, @bitCast(val.toFloat(f16, mod))), endian),511 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(val.toFloat(f16, mod)), endian),
511 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @as(u32, @bitCast(val.toFloat(f32, mod))), endian),512 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(val.toFloat(f32, mod)), endian),
512 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @as(u64, @bitCast(val.toFloat(f64, mod))), endian),513 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(val.toFloat(f64, mod)), endian),
513 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @as(u80, @bitCast(val.toFloat(f80, mod))), endian),514 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(val.toFloat(f80, mod)), endian),
514 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @as(u128, @bitCast(val.toFloat(f128, mod))), endian),515 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(val.toFloat(f128, mod)), endian),
515 else => unreachable,516 else => unreachable,
516 },517 },
517 .Vector => {518 .Vector => {
518 const elem_ty = ty.childType(mod);519 const elem_ty = ty.childType(mod);
519 const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod)));520 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(mod));
520 const len = @as(usize, @intCast(ty.arrayLen(mod)));521 const len: usize = @intCast(ty.arrayLen(mod));
521522
522 var bits: u16 = 0;523 var bits: u16 = 0;
523 var elem_i: usize = 0;524 var elem_i: usize = 0;
...@@ -644,22 +645,22 @@ pub fn readFromMemory(...@@ -644,22 +645,22 @@ pub fn readFromMemory(
644 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{645 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{
645 .ty = ty.toIntern(),646 .ty = ty.toIntern(),
646 .storage = switch (ty.floatBits(target)) {647 .storage = switch (ty.floatBits(target)) {
647 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readInt(u16, buffer[0..2], endian))) },648 16 => .{ .f16 = @bitCast(std.mem.readInt(u16, buffer[0..2], endian)) },
648 32 => .{ .f32 = @as(f32, @bitCast(std.mem.readInt(u32, buffer[0..4], endian))) },649 32 => .{ .f32 = @bitCast(std.mem.readInt(u32, buffer[0..4], endian)) },
649 64 => .{ .f64 = @as(f64, @bitCast(std.mem.readInt(u64, buffer[0..8], endian))) },650 64 => .{ .f64 = @bitCast(std.mem.readInt(u64, buffer[0..8], endian)) },
650 80 => .{ .f80 = @as(f80, @bitCast(std.mem.readInt(u80, buffer[0..10], endian))) },651 80 => .{ .f80 = @bitCast(std.mem.readInt(u80, buffer[0..10], endian)) },
651 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readInt(u128, buffer[0..16], endian))) },652 128 => .{ .f128 = @bitCast(std.mem.readInt(u128, buffer[0..16], endian)) },
652 else => unreachable,653 else => unreachable,
653 },654 },
654 } }))),655 } }))),
655 .Array => {656 .Array => {
656 const elem_ty = ty.childType(mod);657 const elem_ty = ty.childType(mod);
657 const elem_size = elem_ty.abiSize(mod);658 const elem_size = elem_ty.abiSize(mod);
658 const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod))));659 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod)));
659 var offset: usize = 0;660 var offset: usize = 0;
660 for (elems) |*elem| {661 for (elems) |*elem| {
661 elem.* = (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).toIntern();662 elem.* = (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).toIntern();
662 offset += @as(usize, @intCast(elem_size));663 offset += @intCast(elem_size);
663 }664 }
664 return Value.fromInterned((try mod.intern(.{ .aggregate = .{665 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
665 .ty = ty.toIntern(),666 .ty = ty.toIntern(),
...@@ -795,7 +796,7 @@ pub fn readFromPackedMemory(...@@ -795,7 +796,7 @@ pub fn readFromPackedMemory(
795 };796 };
796797
797 // Slow path, we have to construct a big-int798 // Slow path, we have to construct a big-int
798 const abi_size = @as(usize, @intCast(ty.abiSize(mod)));799 const abi_size: usize = @intCast(ty.abiSize(mod));
799 const Limb = std.math.big.Limb;800 const Limb = std.math.big.Limb;
800 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);801 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);
801 const limbs_buffer = try arena.alloc(Limb, limb_count);802 const limbs_buffer = try arena.alloc(Limb, limb_count);
...@@ -812,20 +813,20 @@ pub fn readFromPackedMemory(...@@ -812,20 +813,20 @@ pub fn readFromPackedMemory(
812 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{813 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{
813 .ty = ty.toIntern(),814 .ty = ty.toIntern(),
814 .storage = switch (ty.floatBits(target)) {815 .storage = switch (ty.floatBits(target)) {
815 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian))) },816 16 => .{ .f16 = @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian)) },
816 32 => .{ .f32 = @as(f32, @bitCast(std.mem.readPackedInt(u32, buffer, bit_offset, endian))) },817 32 => .{ .f32 = @bitCast(std.mem.readPackedInt(u32, buffer, bit_offset, endian)) },
817 64 => .{ .f64 = @as(f64, @bitCast(std.mem.readPackedInt(u64, buffer, bit_offset, endian))) },818 64 => .{ .f64 = @bitCast(std.mem.readPackedInt(u64, buffer, bit_offset, endian)) },
818 80 => .{ .f80 = @as(f80, @bitCast(std.mem.readPackedInt(u80, buffer, bit_offset, endian))) },819 80 => .{ .f80 = @bitCast(std.mem.readPackedInt(u80, buffer, bit_offset, endian)) },
819 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian))) },820 128 => .{ .f128 = @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian)) },
820 else => unreachable,821 else => unreachable,
821 },822 },
822 } }))),823 } }))),
823 .Vector => {824 .Vector => {
824 const elem_ty = ty.childType(mod);825 const elem_ty = ty.childType(mod);
825 const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod))));826 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod)));
826827
827 var bits: u16 = 0;828 var bits: u16 = 0;
828 const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod)));829 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(mod));
829 for (elems, 0..) |_, i| {830 for (elems, 0..) |_, i| {
830 // On big-endian systems, LLVM reverses the element order of vectors by default831 // On big-endian systems, LLVM reverses the element order of vectors by default
831 const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i;832 const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i;
...@@ -909,7 +910,7 @@ fn bigIntToFloat(limbs: []const std.math.big.Limb, positive: bool) f128 {...@@ -909,7 +910,7 @@ fn bigIntToFloat(limbs: []const std.math.big.Limb, positive: bool) f128 {
909 var i: usize = limbs.len;910 var i: usize = limbs.len;
910 while (i != 0) {911 while (i != 0) {
911 i -= 1;912 i -= 1;
912 const limb: f128 = @as(f128, @floatFromInt(limbs[i]));913 const limb: f128 = @floatFromInt(limbs[i]);
913 result = @mulAdd(f128, base, result, limb);914 result = @mulAdd(f128, base, result, limb);
914 }915 }
915 if (positive) {916 if (positive) {
...@@ -934,7 +935,7 @@ pub fn ctz(val: Value, ty: Type, mod: *Module) u64 {...@@ -934,7 +935,7 @@ pub fn ctz(val: Value, ty: Type, mod: *Module) u64 {
934pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {935pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {
935 var bigint_buf: BigIntSpace = undefined;936 var bigint_buf: BigIntSpace = undefined;
936 const bigint = val.toBigInt(&bigint_buf, mod);937 const bigint = val.toBigInt(&bigint_buf, mod);
937 return @as(u64, @intCast(bigint.popCount(ty.intInfo(mod).bits)));938 return @intCast(bigint.popCount(ty.intInfo(mod).bits));
938}939}
939940
940pub fn bitReverse(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value {941pub fn bitReverse(val: Value, ty: Type, mod: *Module, arena: Allocator) !Value {
...@@ -1191,7 +1192,7 @@ pub fn compareAllWithZeroAdvancedExtra(...@@ -1191,7 +1192,7 @@ pub fn compareAllWithZeroAdvancedExtra(
1191 inline else => |x| if (std.math.isNan(x)) return op == .neq,1192 inline else => |x| if (std.math.isNan(x)) return op == .neq,
1192 },1193 },
1193 .aggregate => |aggregate| return switch (aggregate.storage) {1194 .aggregate => |aggregate| return switch (aggregate.storage) {
1194 .bytes => |bytes| for (bytes) |byte| {1195 .bytes => |bytes| for (bytes.toSlice(lhs.typeOf(mod).arrayLenIncludingSentinel(mod), &mod.intern_pool)) |byte| {
1195 if (!std.math.order(byte, 0).compare(op)) break false;1196 if (!std.math.order(byte, 0).compare(op)) break false;
1196 } else true,1197 } else true,
1197 .elems => |elems| for (elems) |elem| {1198 .elems => |elems| for (elems) |elem| {
...@@ -1279,7 +1280,7 @@ pub fn elemValue(val: Value, zcu: *Zcu, index: usize) Allocator.Error!Value {...@@ -1279,7 +1280,7 @@ pub fn elemValue(val: Value, zcu: *Zcu, index: usize) Allocator.Error!Value {
1279 if (index < len) return Value.fromInterned(switch (aggregate.storage) {1280 if (index < len) return Value.fromInterned(switch (aggregate.storage) {
1280 .bytes => |bytes| try zcu.intern(.{ .int = .{1281 .bytes => |bytes| try zcu.intern(.{ .int = .{
1281 .ty = .u8_type,1282 .ty = .u8_type,
1282 .storage = .{ .u64 = bytes[index] },1283 .storage = .{ .u64 = bytes.at(index, ip) },
1283 } }),1284 } }),
1284 .elems => |elems| elems[index],1285 .elems => |elems| elems[index],
1285 .repeated_elem => |elem| elem,1286 .repeated_elem => |elem| elem,
...@@ -1318,28 +1319,37 @@ pub fn sliceArray(...@@ -1318,28 +1319,37 @@ pub fn sliceArray(
1318 start: usize,1319 start: usize,
1319 end: usize,1320 end: usize,
1320) error{OutOfMemory}!Value {1321) error{OutOfMemory}!Value {
1321 // TODO: write something like getCoercedInts to avoid needing to dupe
1322 const mod = sema.mod;1322 const mod = sema.mod;
1323 const aggregate = mod.intern_pool.indexToKey(val.toIntern()).aggregate;1323 const ip = &mod.intern_pool;
1324 return Value.fromInterned(try mod.intern(.{ .aggregate = .{1324 return Value.fromInterned(try mod.intern(.{
1325 .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) {1325 .aggregate = .{
1326 .array_type => |array_type| try mod.arrayType(.{1326 .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) {
1327 .len = @as(u32, @intCast(end - start)),1327 .array_type => |array_type| try mod.arrayType(.{
1328 .child = array_type.child,1328 .len = @intCast(end - start),
1329 .sentinel = if (end == array_type.len) array_type.sentinel else .none,1329 .child = array_type.child,
1330 }),1330 .sentinel = if (end == array_type.len) array_type.sentinel else .none,
1331 .vector_type => |vector_type| try mod.vectorType(.{1331 }),
1332 .len = @as(u32, @intCast(end - start)),1332 .vector_type => |vector_type| try mod.vectorType(.{
1333 .child = vector_type.child,1333 .len = @intCast(end - start),
1334 }),1334 .child = vector_type.child,
1335 else => unreachable,1335 }),
1336 }.toIntern(),1336 else => unreachable,
1337 .storage = switch (aggregate.storage) {1337 }.toIntern(),
1338 .bytes => .{ .bytes = try sema.arena.dupe(u8, mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.bytes[start..end]) },1338 .storage = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
1339 .elems => .{ .elems = try sema.arena.dupe(InternPool.Index, mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.elems[start..end]) },1339 .bytes => |bytes| storage: {
1340 .repeated_elem => |elem| .{ .repeated_elem = elem },1340 try ip.string_bytes.ensureUnusedCapacity(sema.gpa, end - start + 1);
1341 break :storage .{ .bytes = try ip.getOrPutString(
1342 sema.gpa,
1343 bytes.toSlice(end, ip)[start..],
1344 .maybe_embedded_nulls,
1345 ) };
1346 },
1347 // TODO: write something like getCoercedInts to avoid needing to dupe
1348 .elems => |elems| .{ .elems = try sema.arena.dupe(InternPool.Index, elems[start..end]) },
1349 .repeated_elem => |elem| .{ .repeated_elem = elem },
1350 },
1341 },1351 },
1342 } }));1352 }));
1343}1353}
13441354
1345pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {1355pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {
...@@ -1350,7 +1360,7 @@ pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {...@@ -1350,7 +1360,7 @@ pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {
1350 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {1360 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {
1351 .bytes => |bytes| try mod.intern(.{ .int = .{1361 .bytes => |bytes| try mod.intern(.{ .int = .{
1352 .ty = .u8_type,1362 .ty = .u8_type,
1353 .storage = .{ .u64 = bytes[index] },1363 .storage = .{ .u64 = bytes.at(index, &mod.intern_pool) },
1354 } }),1364 } }),
1355 .elems => |elems| elems[index],1365 .elems => |elems| elems[index],
1356 .repeated_elem => |elem| elem,1366 .repeated_elem => |elem| elem,
...@@ -1461,7 +1471,7 @@ pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTermi...@@ -1461,7 +1471,7 @@ pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTermi
14611471
1462pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {1472pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {
1463 return if (getErrorName(val, mod).unwrap()) |err_name|1473 return if (getErrorName(val, mod).unwrap()) |err_name|
1464 @as(Module.ErrorInt, @intCast(mod.global_error_set.getIndex(err_name).?))1474 @intCast(mod.global_error_set.getIndex(err_name).?)
1465 else1475 else
1466 0;1476 0;
1467}1477}
...@@ -2413,14 +2423,14 @@ pub fn intTruncBitsAsValue(...@@ -2413,14 +2423,14 @@ pub fn intTruncBitsAsValue(
2413 for (result_data, 0..) |*scalar, i| {2423 for (result_data, 0..) |*scalar, i| {
2414 const elem_val = try val.elemValue(mod, i);2424 const elem_val = try val.elemValue(mod, i);
2415 const bits_elem = try bits.elemValue(mod, i);2425 const bits_elem = try bits.elemValue(mod, i);
2416 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @as(u16, @intCast(bits_elem.toUnsignedInt(mod))), mod)).toIntern();2426 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(bits_elem.toUnsignedInt(mod)), mod)).toIntern();
2417 }2427 }
2418 return Value.fromInterned((try mod.intern(.{ .aggregate = .{2428 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2419 .ty = ty.toIntern(),2429 .ty = ty.toIntern(),
2420 .storage = .{ .elems = result_data },2430 .storage = .{ .elems = result_data },
2421 } })));2431 } })));
2422 }2432 }
2423 return intTruncScalar(val, ty, allocator, signedness, @as(u16, @intCast(bits.toUnsignedInt(mod))), mod);2433 return intTruncScalar(val, ty, allocator, signedness, @intCast(bits.toUnsignedInt(mod)), mod);
2424}2434}
24252435
2426pub fn intTruncScalar(2436pub fn intTruncScalar(
...@@ -2468,7 +2478,7 @@ pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *M...@@ -2468,7 +2478,7 @@ pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *M
2468 // resorting to BigInt first.2478 // resorting to BigInt first.
2469 var lhs_space: Value.BigIntSpace = undefined;2479 var lhs_space: Value.BigIntSpace = undefined;
2470 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);2480 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);
2471 const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod)));2481 const shift: usize = @intCast(rhs.toUnsignedInt(mod));
2472 const limbs = try allocator.alloc(2482 const limbs = try allocator.alloc(
2473 std.math.big.Limb,2483 std.math.big.Limb,
2474 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,2484 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
...@@ -2530,7 +2540,7 @@ pub fn shlWithOverflowScalar(...@@ -2530,7 +2540,7 @@ pub fn shlWithOverflowScalar(
2530 const info = ty.intInfo(mod);2540 const info = ty.intInfo(mod);
2531 var lhs_space: Value.BigIntSpace = undefined;2541 var lhs_space: Value.BigIntSpace = undefined;
2532 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);2542 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);
2533 const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod)));2543 const shift: usize = @intCast(rhs.toUnsignedInt(mod));
2534 const limbs = try allocator.alloc(2544 const limbs = try allocator.alloc(
2535 std.math.big.Limb,2545 std.math.big.Limb,
2536 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,2546 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
...@@ -2587,7 +2597,7 @@ pub fn shlSatScalar(...@@ -2587,7 +2597,7 @@ pub fn shlSatScalar(
25872597
2588 var lhs_space: Value.BigIntSpace = undefined;2598 var lhs_space: Value.BigIntSpace = undefined;
2589 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);2599 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);
2590 const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod)));2600 const shift: usize = @intCast(rhs.toUnsignedInt(mod));
2591 const limbs = try arena.alloc(2601 const limbs = try arena.alloc(
2592 std.math.big.Limb,2602 std.math.big.Limb,
2593 std.math.big.int.calcTwosCompLimbCount(info.bits) + 1,2603 std.math.big.int.calcTwosCompLimbCount(info.bits) + 1,
...@@ -2659,7 +2669,7 @@ pub fn shrScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *M...@@ -2659,7 +2669,7 @@ pub fn shrScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *M
2659 // resorting to BigInt first.2669 // resorting to BigInt first.
2660 var lhs_space: Value.BigIntSpace = undefined;2670 var lhs_space: Value.BigIntSpace = undefined;
2661 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);2671 const lhs_bigint = lhs.toBigInt(&lhs_space, mod);
2662 const shift = @as(usize, @intCast(rhs.toUnsignedInt(mod)));2672 const shift: usize = @intCast(rhs.toUnsignedInt(mod));
26632673
2664 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));2674 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
2665 if (result_limbs == 0) {2675 if (result_limbs == 0) {
src/arch/aarch64/CodeGen.zig+2-2
...@@ -4345,8 +4345,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4345,8 +4345,8 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4345 .data = .{ .reg = .x30 },4345 .data = .{ .reg = .x30 },
4346 });4346 });
4347 } else if (func_value.getExternFunc(mod)) |extern_func| {4347 } else if (func_value.getExternFunc(mod)) |extern_func| {
4348 const decl_name = mod.intern_pool.stringToSlice(mod.declPtr(extern_func.decl).name);4348 const decl_name = mod.declPtr(extern_func.decl).name.toSlice(&mod.intern_pool);
4349 const lib_name = mod.intern_pool.stringToSliceUnwrap(extern_func.lib_name);4349 const lib_name = extern_func.lib_name.toSlice(&mod.intern_pool);
4350 if (self.bin_file.cast(link.File.MachO)) |macho_file| {4350 if (self.bin_file.cast(link.File.MachO)) |macho_file| {
4351 _ = macho_file;4351 _ = macho_file;
4352 @panic("TODO airCall");4352 @panic("TODO airCall");
src/arch/wasm/CodeGen.zig+10-9
...@@ -2199,9 +2199,9 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2199,9 +2199,9 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2199 const atom = func.bin_file.getAtomPtr(atom_index);2199 const atom = func.bin_file.getAtomPtr(atom_index);
2200 const type_index = try func.bin_file.storeDeclType(extern_func.decl, func_type);2200 const type_index = try func.bin_file.storeDeclType(extern_func.decl, func_type);
2201 try func.bin_file.addOrUpdateImport(2201 try func.bin_file.addOrUpdateImport(
2202 mod.intern_pool.stringToSlice(ext_decl.name),2202 ext_decl.name.toSlice(&mod.intern_pool),
2203 atom.sym_index,2203 atom.sym_index,
2204 mod.intern_pool.stringToSliceUnwrap(ext_decl.getOwnedExternFunc(mod).?.lib_name),2204 ext_decl.getOwnedExternFunc(mod).?.lib_name.toSlice(&mod.intern_pool),
2205 type_index,2205 type_index,
2206 );2206 );
2207 break :blk extern_func.decl;2207 break :blk extern_func.decl;
...@@ -7236,8 +7236,8 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7236,8 +7236,8 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
7236 defer arena_allocator.deinit();7236 defer arena_allocator.deinit();
7237 const arena = arena_allocator.allocator();7237 const arena = arena_allocator.allocator();
72387238
7239 const fqn = ip.stringToSlice(try mod.declPtr(enum_decl_index).fullyQualifiedName(mod));7239 const fqn = try mod.declPtr(enum_decl_index).fullyQualifiedName(mod);
7240 const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn});7240 const func_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(ip)});
72417241
7242 // check if we already generated code for this.7242 // check if we already generated code for this.
7243 if (func.bin_file.findGlobalSymbol(func_name)) |loc| {7243 if (func.bin_file.findGlobalSymbol(func_name)) |loc| {
...@@ -7268,17 +7268,18 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7268,17 +7268,18 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
7268 // generate an if-else chain for each tag value as well as constant.7268 // generate an if-else chain for each tag value as well as constant.
7269 const tag_names = enum_ty.enumFields(mod);7269 const tag_names = enum_ty.enumFields(mod);
7270 for (0..tag_names.len) |tag_index| {7270 for (0..tag_names.len) |tag_index| {
7271 const tag_name = ip.stringToSlice(tag_names.get(ip)[tag_index]);7271 const tag_name = tag_names.get(ip)[tag_index];
7272 const tag_name_len = tag_name.length(ip);
7272 // for each tag name, create an unnamed const,7273 // for each tag name, create an unnamed const,
7273 // and then get a pointer to its value.7274 // and then get a pointer to its value.
7274 const name_ty = try mod.arrayType(.{7275 const name_ty = try mod.arrayType(.{
7275 .len = tag_name.len,7276 .len = tag_name_len,
7276 .child = .u8_type,7277 .child = .u8_type,
7277 .sentinel = .zero_u8,7278 .sentinel = .zero_u8,
7278 });7279 });
7279 const name_val = try mod.intern(.{ .aggregate = .{7280 const name_val = try mod.intern(.{ .aggregate = .{
7280 .ty = name_ty.toIntern(),7281 .ty = name_ty.toIntern(),
7281 .storage = .{ .bytes = tag_name },7282 .storage = .{ .bytes = tag_name.toString() },
7282 } });7283 } });
7283 const tag_sym_index = try func.bin_file.lowerUnnamedConst(7284 const tag_sym_index = try func.bin_file.lowerUnnamedConst(
7284 Value.fromInterned(name_val),7285 Value.fromInterned(name_val),
...@@ -7338,7 +7339,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7338,7 +7339,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
73387339
7339 // store length7340 // store length
7340 try writer.writeByte(std.wasm.opcode(.i32_const));7341 try writer.writeByte(std.wasm.opcode(.i32_const));
7341 try leb.writeULEB128(writer, @as(u32, @intCast(tag_name.len)));7342 try leb.writeULEB128(writer, @as(u32, @intCast(tag_name_len)));
7342 try writer.writeByte(std.wasm.opcode(.i32_store));7343 try writer.writeByte(std.wasm.opcode(.i32_store));
7343 try leb.writeULEB128(writer, encoded_alignment);7344 try leb.writeULEB128(writer, encoded_alignment);
7344 try leb.writeULEB128(writer, @as(u32, 4));7345 try leb.writeULEB128(writer, @as(u32, 4));
...@@ -7359,7 +7360,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7359,7 +7360,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
73597360
7360 // store length7361 // store length
7361 try writer.writeByte(std.wasm.opcode(.i64_const));7362 try writer.writeByte(std.wasm.opcode(.i64_const));
7362 try leb.writeULEB128(writer, @as(u64, @intCast(tag_name.len)));7363 try leb.writeULEB128(writer, @as(u64, @intCast(tag_name_len)));
7363 try writer.writeByte(std.wasm.opcode(.i64_store));7364 try writer.writeByte(std.wasm.opcode(.i64_store));
7364 try leb.writeULEB128(writer, encoded_alignment);7365 try leb.writeULEB128(writer, encoded_alignment);
7365 try leb.writeULEB128(writer, @as(u32, 8));7366 try leb.writeULEB128(writer, @as(u32, 8));
src/arch/x86_64/CodeGen.zig+3-3
...@@ -2247,7 +2247,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {...@@ -2247,7 +2247,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
2247 var data_off: i32 = 0;2247 var data_off: i32 = 0;
2248 const tag_names = enum_ty.enumFields(mod);2248 const tag_names = enum_ty.enumFields(mod);
2249 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| {2249 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| {
2250 const tag_name_len = ip.stringToSlice(tag_names.get(ip)[tag_index]).len;2250 const tag_name_len = tag_names.get(ip)[tag_index].length(ip);
2251 const tag_val = try mod.enumValueFieldIndex(enum_ty, @intCast(tag_index));2251 const tag_val = try mod.enumValueFieldIndex(enum_ty, @intCast(tag_index));
2252 const tag_mcv = try self.genTypedValue(tag_val);2252 const tag_mcv = try self.genTypedValue(tag_val);
2253 try self.genBinOpMir(.{ ._, .cmp }, enum_ty, enum_mcv, tag_mcv);2253 try self.genBinOpMir(.{ ._, .cmp }, enum_ty, enum_mcv, tag_mcv);
...@@ -12314,8 +12314,8 @@ fn genCall(self: *Self, info: union(enum) {...@@ -12314,8 +12314,8 @@ fn genCall(self: *Self, info: union(enum) {
12314 },12314 },
12315 .extern_func => |extern_func| {12315 .extern_func => |extern_func| {
12316 const owner_decl = mod.declPtr(extern_func.decl);12316 const owner_decl = mod.declPtr(extern_func.decl);
12317 const lib_name = mod.intern_pool.stringToSliceUnwrap(extern_func.lib_name);12317 const lib_name = extern_func.lib_name.toSlice(&mod.intern_pool);
12318 const decl_name = mod.intern_pool.stringToSlice(owner_decl.name);12318 const decl_name = owner_decl.name.toSlice(&mod.intern_pool);
12319 try self.genExternSymbolRef(.call, lib_name, decl_name);12319 try self.genExternSymbolRef(.call, lib_name, decl_name);
12320 },12320 },
12321 else => return self.fail("TODO implement calling bitcasted functions", .{}),12321 else => return self.fail("TODO implement calling bitcasted functions", .{}),
src/codegen.zig+50-57
...@@ -97,7 +97,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian...@@ -97,7 +97,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian
97 _ = target;97 _ = target;
98 const bits = @typeInfo(F).Float.bits;98 const bits = @typeInfo(F).Float.bits;
99 const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } });99 const Int = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = bits } });
100 const int = @as(Int, @bitCast(f));100 const int: Int = @bitCast(f);
101 mem.writeInt(Int, code[0..@divExact(bits, 8)], int, endian);101 mem.writeInt(Int, code[0..@divExact(bits, 8)], int, endian);
102}102}
103103
...@@ -136,24 +136,24 @@ pub fn generateLazySymbol(...@@ -136,24 +136,24 @@ pub fn generateLazySymbol(
136 if (lazy_sym.ty.isAnyError(zcu)) {136 if (lazy_sym.ty.isAnyError(zcu)) {
137 alignment.* = .@"4";137 alignment.* = .@"4";
138 const err_names = zcu.global_error_set.keys();138 const err_names = zcu.global_error_set.keys();
139 mem.writeInt(u32, try code.addManyAsArray(4), @as(u32, @intCast(err_names.len)), endian);139 mem.writeInt(u32, try code.addManyAsArray(4), @intCast(err_names.len), endian);
140 var offset = code.items.len;140 var offset = code.items.len;
141 try code.resize((1 + err_names.len + 1) * 4);141 try code.resize((1 + err_names.len + 1) * 4);
142 for (err_names) |err_name_nts| {142 for (err_names) |err_name_nts| {
143 const err_name = zcu.intern_pool.stringToSlice(err_name_nts);143 const err_name = err_name_nts.toSlice(ip);
144 mem.writeInt(u32, code.items[offset..][0..4], @as(u32, @intCast(code.items.len)), endian);144 mem.writeInt(u32, code.items[offset..][0..4], @intCast(code.items.len), endian);
145 offset += 4;145 offset += 4;
146 try code.ensureUnusedCapacity(err_name.len + 1);146 try code.ensureUnusedCapacity(err_name.len + 1);
147 code.appendSliceAssumeCapacity(err_name);147 code.appendSliceAssumeCapacity(err_name);
148 code.appendAssumeCapacity(0);148 code.appendAssumeCapacity(0);
149 }149 }
150 mem.writeInt(u32, code.items[offset..][0..4], @as(u32, @intCast(code.items.len)), endian);150 mem.writeInt(u32, code.items[offset..][0..4], @intCast(code.items.len), endian);
151 return Result.ok;151 return Result.ok;
152 } else if (lazy_sym.ty.zigTypeTag(zcu) == .Enum) {152 } else if (lazy_sym.ty.zigTypeTag(zcu) == .Enum) {
153 alignment.* = .@"1";153 alignment.* = .@"1";
154 const tag_names = lazy_sym.ty.enumFields(zcu);154 const tag_names = lazy_sym.ty.enumFields(zcu);
155 for (0..tag_names.len) |tag_index| {155 for (0..tag_names.len) |tag_index| {
156 const tag_name = zcu.intern_pool.stringToSlice(tag_names.get(ip)[tag_index]);156 const tag_name = tag_names.get(ip)[tag_index].toSlice(ip);
157 try code.ensureUnusedCapacity(tag_name.len + 1);157 try code.ensureUnusedCapacity(tag_name.len + 1);
158 code.appendSliceAssumeCapacity(tag_name);158 code.appendSliceAssumeCapacity(tag_name);
159 code.appendAssumeCapacity(0);159 code.appendAssumeCapacity(0);
...@@ -241,13 +241,13 @@ pub fn generateSymbol(...@@ -241,13 +241,13 @@ pub fn generateSymbol(
241 },241 },
242 .err => |err| {242 .err => |err| {
243 const int = try mod.getErrorValue(err.name);243 const int = try mod.getErrorValue(err.name);
244 try code.writer().writeInt(u16, @as(u16, @intCast(int)), endian);244 try code.writer().writeInt(u16, @intCast(int), endian);
245 },245 },
246 .error_union => |error_union| {246 .error_union => |error_union| {
247 const payload_ty = ty.errorUnionPayload(mod);247 const payload_ty = ty.errorUnionPayload(mod);
248 const err_val = switch (error_union.val) {248 const err_val: u16 = switch (error_union.val) {
249 .err_name => |err_name| @as(u16, @intCast(try mod.getErrorValue(err_name))),249 .err_name => |err_name| @intCast(try mod.getErrorValue(err_name)),
250 .payload => @as(u16, 0),250 .payload => 0,
251 };251 };
252252
253 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {253 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
...@@ -357,15 +357,13 @@ pub fn generateSymbol(...@@ -357,15 +357,13 @@ pub fn generateSymbol(
357 },357 },
358 .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) {358 .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) {
359 .array_type => |array_type| switch (aggregate.storage) {359 .array_type => |array_type| switch (aggregate.storage) {
360 .bytes => |bytes| try code.appendSlice(bytes),360 .bytes => |bytes| try code.appendSlice(bytes.toSlice(array_type.lenIncludingSentinel(), ip)),
361 .elems, .repeated_elem => {361 .elems, .repeated_elem => {
362 var index: u64 = 0;362 var index: u64 = 0;
363 const len_including_sentinel =363 while (index < array_type.lenIncludingSentinel()) : (index += 1) {
364 array_type.len + @intFromBool(array_type.sentinel != .none);
365 while (index < len_including_sentinel) : (index += 1) {
366 switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(switch (aggregate.storage) {364 switch (try generateSymbol(bin_file, src_loc, Value.fromInterned(switch (aggregate.storage) {
367 .bytes => unreachable,365 .bytes => unreachable,
368 .elems => |elems| elems[@as(usize, @intCast(index))],366 .elems => |elems| elems[@intCast(index)],
369 .repeated_elem => |elem| if (index < array_type.len)367 .repeated_elem => |elem| if (index < array_type.len)
370 elem368 elem
371 else369 else
...@@ -399,7 +397,7 @@ pub fn generateSymbol(...@@ -399,7 +397,7 @@ pub fn generateSymbol(
399 }) {397 }) {
400 .bool_true => true,398 .bool_true => true,
401 .bool_false => false,399 .bool_false => false,
402 else => |elem| switch (mod.intern_pool.indexToKey(elem)) {400 else => |elem| switch (ip.indexToKey(elem)) {
403 .undef => continue,401 .undef => continue,
404 .int => |int| switch (int.storage) {402 .int => |int| switch (int.storage) {
405 .u64 => |x| switch (x) {403 .u64 => |x| switch (x) {
...@@ -420,7 +418,7 @@ pub fn generateSymbol(...@@ -420,7 +418,7 @@ pub fn generateSymbol(
420 }418 }
421 } else {419 } else {
422 switch (aggregate.storage) {420 switch (aggregate.storage) {
423 .bytes => |bytes| try code.appendSlice(bytes),421 .bytes => |bytes| try code.appendSlice(bytes.toSlice(vector_type.len, ip)),
424 .elems, .repeated_elem => {422 .elems, .repeated_elem => {
425 var index: u64 = 0;423 var index: u64 = 0;
426 while (index < vector_type.len) : (index += 1) {424 while (index < vector_type.len) : (index += 1) {
...@@ -457,7 +455,7 @@ pub fn generateSymbol(...@@ -457,7 +455,7 @@ pub fn generateSymbol(
457 const field_val = switch (aggregate.storage) {455 const field_val = switch (aggregate.storage) {
458 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{456 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
459 .ty = field_ty,457 .ty = field_ty,
460 .storage = .{ .u64 = bytes[index] },458 .storage = .{ .u64 = bytes.at(index, ip) },
461 } }),459 } }),
462 .elems => |elems| elems[index],460 .elems => |elems| elems[index],
463 .repeated_elem => |elem| elem,461 .repeated_elem => |elem| elem,
...@@ -493,7 +491,7 @@ pub fn generateSymbol(...@@ -493,7 +491,7 @@ pub fn generateSymbol(
493 const field_val = switch (aggregate.storage) {491 const field_val = switch (aggregate.storage) {
494 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{492 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
495 .ty = field_ty,493 .ty = field_ty,
496 .storage = .{ .u64 = bytes[index] },494 .storage = .{ .u64 = bytes.at(index, ip) },
497 } }),495 } }),
498 .elems => |elems| elems[index],496 .elems => |elems| elems[index],
499 .repeated_elem => |elem| elem,497 .repeated_elem => |elem| elem,
...@@ -513,7 +511,7 @@ pub fn generateSymbol(...@@ -513,7 +511,7 @@ pub fn generateSymbol(
513 } else {511 } else {
514 Value.fromInterned(field_val).writeToPackedMemory(Type.fromInterned(field_ty), mod, code.items[current_pos..], bits) catch unreachable;512 Value.fromInterned(field_val).writeToPackedMemory(Type.fromInterned(field_ty), mod, code.items[current_pos..], bits) catch unreachable;
515 }513 }
516 bits += @as(u16, @intCast(Type.fromInterned(field_ty).bitSize(mod)));514 bits += @intCast(Type.fromInterned(field_ty).bitSize(mod));
517 }515 }
518 },516 },
519 .auto, .@"extern" => {517 .auto, .@"extern" => {
...@@ -529,7 +527,7 @@ pub fn generateSymbol(...@@ -529,7 +527,7 @@ pub fn generateSymbol(
529 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {527 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
530 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{528 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
531 .ty = field_ty,529 .ty = field_ty,
532 .storage = .{ .u64 = bytes[field_index] },530 .storage = .{ .u64 = bytes.at(field_index, ip) },
533 } }),531 } }),
534 .elems => |elems| elems[field_index],532 .elems => |elems| elems[field_index],
535 .repeated_elem => |elem| elem,533 .repeated_elem => |elem| elem,
...@@ -625,7 +623,8 @@ fn lowerParentPtr(...@@ -625,7 +623,8 @@ fn lowerParentPtr(
625 reloc_info: RelocInfo,623 reloc_info: RelocInfo,
626) CodeGenError!Result {624) CodeGenError!Result {
627 const mod = bin_file.comp.module.?;625 const mod = bin_file.comp.module.?;
628 const ptr = mod.intern_pool.indexToKey(parent_ptr).ptr;626 const ip = &mod.intern_pool;
627 const ptr = ip.indexToKey(parent_ptr).ptr;
629 return switch (ptr.addr) {628 return switch (ptr.addr) {
630 .decl => |decl| try lowerDeclRef(bin_file, src_loc, decl, code, debug_output, reloc_info),629 .decl => |decl| try lowerDeclRef(bin_file, src_loc, decl, code, debug_output, reloc_info),
631 .anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info),630 .anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info),
...@@ -636,10 +635,10 @@ fn lowerParentPtr(...@@ -636,10 +635,10 @@ fn lowerParentPtr(
636 eu_payload,635 eu_payload,
637 code,636 code,
638 debug_output,637 debug_output,
639 reloc_info.offset(@as(u32, @intCast(errUnionPayloadOffset(638 reloc_info.offset(@intCast(errUnionPayloadOffset(
640 Type.fromInterned(mod.intern_pool.typeOf(eu_payload)),639 Type.fromInterned(ip.typeOf(eu_payload)),
641 mod,640 mod,
642 )))),641 ))),
643 ),642 ),
644 .opt_payload => |opt_payload| try lowerParentPtr(643 .opt_payload => |opt_payload| try lowerParentPtr(
645 bin_file,644 bin_file,
...@@ -655,19 +654,19 @@ fn lowerParentPtr(...@@ -655,19 +654,19 @@ fn lowerParentPtr(
655 elem.base,654 elem.base,
656 code,655 code,
657 debug_output,656 debug_output,
658 reloc_info.offset(@as(u32, @intCast(elem.index *657 reloc_info.offset(@intCast(elem.index *
659 Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).abiSize(mod)))),658 Type.fromInterned(ip.typeOf(elem.base)).elemType2(mod).abiSize(mod))),
660 ),659 ),
661 .field => |field| {660 .field => |field| {
662 const base_ptr_ty = mod.intern_pool.typeOf(field.base);661 const base_ptr_ty = ip.typeOf(field.base);
663 const base_ty = mod.intern_pool.indexToKey(base_ptr_ty).ptr_type.child;662 const base_ty = ip.indexToKey(base_ptr_ty).ptr_type.child;
664 return lowerParentPtr(663 return lowerParentPtr(
665 bin_file,664 bin_file,
666 src_loc,665 src_loc,
667 field.base,666 field.base,
668 code,667 code,
669 debug_output,668 debug_output,
670 reloc_info.offset(switch (mod.intern_pool.indexToKey(base_ty)) {669 reloc_info.offset(switch (ip.indexToKey(base_ty)) {
671 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {670 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
672 .One, .Many, .C => unreachable,671 .One, .Many, .C => unreachable,
673 .Slice => switch (field.index) {672 .Slice => switch (field.index) {
...@@ -723,11 +722,12 @@ fn lowerAnonDeclRef(...@@ -723,11 +722,12 @@ fn lowerAnonDeclRef(
723) CodeGenError!Result {722) CodeGenError!Result {
724 _ = debug_output;723 _ = debug_output;
725 const zcu = lf.comp.module.?;724 const zcu = lf.comp.module.?;
725 const ip = &zcu.intern_pool;
726 const target = lf.comp.root_mod.resolved_target.result;726 const target = lf.comp.root_mod.resolved_target.result;
727727
728 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);728 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
729 const decl_val = anon_decl.val;729 const decl_val = anon_decl.val;
730 const decl_ty = Type.fromInterned(zcu.intern_pool.typeOf(decl_val));730 const decl_ty = Type.fromInterned(ip.typeOf(decl_val));
731 log.debug("lowerAnonDecl: ty = {}", .{decl_ty.fmt(zcu)});731 log.debug("lowerAnonDecl: ty = {}", .{decl_ty.fmt(zcu)});
732 const is_fn_body = decl_ty.zigTypeTag(zcu) == .Fn;732 const is_fn_body = decl_ty.zigTypeTag(zcu) == .Fn;
733 if (!is_fn_body and !decl_ty.hasRuntimeBits(zcu)) {733 if (!is_fn_body and !decl_ty.hasRuntimeBits(zcu)) {
...@@ -735,7 +735,7 @@ fn lowerAnonDeclRef(...@@ -735,7 +735,7 @@ fn lowerAnonDeclRef(
735 return Result.ok;735 return Result.ok;
736 }736 }
737737
738 const decl_align = zcu.intern_pool.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment;738 const decl_align = ip.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment;
739 const res = try lf.lowerAnonDecl(decl_val, decl_align, src_loc);739 const res = try lf.lowerAnonDecl(decl_val, decl_align, src_loc);
740 switch (res) {740 switch (res) {
741 .ok => {},741 .ok => {},
...@@ -787,8 +787,8 @@ fn lowerDeclRef(...@@ -787,8 +787,8 @@ fn lowerDeclRef(
787 });787 });
788 const endian = target.cpu.arch.endian();788 const endian = target.cpu.arch.endian();
789 switch (ptr_width) {789 switch (ptr_width) {
790 16 => mem.writeInt(u16, try code.addManyAsArray(2), @as(u16, @intCast(vaddr)), endian),790 16 => mem.writeInt(u16, try code.addManyAsArray(2), @intCast(vaddr), endian),
791 32 => mem.writeInt(u32, try code.addManyAsArray(4), @as(u32, @intCast(vaddr)), endian),791 32 => mem.writeInt(u32, try code.addManyAsArray(4), @intCast(vaddr), endian),
792 64 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian),792 64 => mem.writeInt(u64, try code.addManyAsArray(8), vaddr, endian),
793 else => unreachable,793 else => unreachable,
794 }794 }
...@@ -859,6 +859,7 @@ fn genDeclRef(...@@ -859,6 +859,7 @@ fn genDeclRef(
859 ptr_decl_index: InternPool.DeclIndex,859 ptr_decl_index: InternPool.DeclIndex,
860) CodeGenError!GenResult {860) CodeGenError!GenResult {
861 const zcu = lf.comp.module.?;861 const zcu = lf.comp.module.?;
862 const ip = &zcu.intern_pool;
862 const ty = val.typeOf(zcu);863 const ty = val.typeOf(zcu);
863 log.debug("genDeclRef: val = {}", .{val.fmtValue(zcu)});864 log.debug("genDeclRef: val = {}", .{val.fmtValue(zcu)});
864865
...@@ -869,7 +870,7 @@ fn genDeclRef(...@@ -869,7 +870,7 @@ fn genDeclRef(
869 const ptr_bits = target.ptrBitWidth();870 const ptr_bits = target.ptrBitWidth();
870 const ptr_bytes: u64 = @divExact(ptr_bits, 8);871 const ptr_bytes: u64 = @divExact(ptr_bits, 8);
871872
872 const decl_index = switch (zcu.intern_pool.indexToKey(ptr_decl.val.toIntern())) {873 const decl_index = switch (ip.indexToKey(ptr_decl.val.toIntern())) {
873 .func => |func| func.owner_decl,874 .func => |func| func.owner_decl,
874 .extern_func => |extern_func| extern_func.decl,875 .extern_func => |extern_func| extern_func.decl,
875 else => ptr_decl_index,876 else => ptr_decl_index,
...@@ -909,12 +910,9 @@ fn genDeclRef(...@@ -909,12 +910,9 @@ fn genDeclRef(
909910
910 if (lf.cast(link.File.Elf)) |elf_file| {911 if (lf.cast(link.File.Elf)) |elf_file| {
911 if (is_extern) {912 if (is_extern) {
912 const name = zcu.intern_pool.stringToSlice(decl.name);913 const name = decl.name.toSlice(ip);
913 // TODO audit this914 // TODO audit this
914 const lib_name = if (decl.getOwnedVariable(zcu)) |ov|915 const lib_name = if (decl.getOwnedVariable(zcu)) |ov| ov.lib_name.toSlice(ip) else null;
915 zcu.intern_pool.stringToSliceUnwrap(ov.lib_name)
916 else
917 null;
918 const sym_index = try elf_file.getGlobalSymbol(name, lib_name);916 const sym_index = try elf_file.getGlobalSymbol(name, lib_name);
919 elf_file.symbol(elf_file.zigObjectPtr().?.symbol(sym_index)).flags.needs_got = true;917 elf_file.symbol(elf_file.zigObjectPtr().?.symbol(sym_index)).flags.needs_got = true;
920 return GenResult.mcv(.{ .load_symbol = sym_index });918 return GenResult.mcv(.{ .load_symbol = sym_index });
...@@ -927,11 +925,8 @@ fn genDeclRef(...@@ -927,11 +925,8 @@ fn genDeclRef(
927 return GenResult.mcv(.{ .load_symbol = sym.esym_index });925 return GenResult.mcv(.{ .load_symbol = sym.esym_index });
928 } else if (lf.cast(link.File.MachO)) |macho_file| {926 } else if (lf.cast(link.File.MachO)) |macho_file| {
929 if (is_extern) {927 if (is_extern) {
930 const name = zcu.intern_pool.stringToSlice(decl.name);928 const name = decl.name.toSlice(ip);
931 const lib_name = if (decl.getOwnedVariable(zcu)) |ov|929 const lib_name = if (decl.getOwnedVariable(zcu)) |ov| ov.lib_name.toSlice(ip) else null;
932 zcu.intern_pool.stringToSliceUnwrap(ov.lib_name)
933 else
934 null;
935 const sym_index = try macho_file.getGlobalSymbol(name, lib_name);930 const sym_index = try macho_file.getGlobalSymbol(name, lib_name);
936 macho_file.getSymbol(macho_file.getZigObject().?.symbols.items[sym_index]).flags.needs_got = true;931 macho_file.getSymbol(macho_file.getZigObject().?.symbols.items[sym_index]).flags.needs_got = true;
937 return GenResult.mcv(.{ .load_symbol = sym_index });932 return GenResult.mcv(.{ .load_symbol = sym_index });
...@@ -944,12 +939,9 @@ fn genDeclRef(...@@ -944,12 +939,9 @@ fn genDeclRef(
944 return GenResult.mcv(.{ .load_symbol = sym.nlist_idx });939 return GenResult.mcv(.{ .load_symbol = sym.nlist_idx });
945 } else if (lf.cast(link.File.Coff)) |coff_file| {940 } else if (lf.cast(link.File.Coff)) |coff_file| {
946 if (is_extern) {941 if (is_extern) {
947 const name = zcu.intern_pool.stringToSlice(decl.name);942 const name = decl.name.toSlice(ip);
948 // TODO audit this943 // TODO audit this
949 const lib_name = if (decl.getOwnedVariable(zcu)) |ov|944 const lib_name = if (decl.getOwnedVariable(zcu)) |ov| ov.lib_name.toSlice(ip) else null;
950 zcu.intern_pool.stringToSliceUnwrap(ov.lib_name)
951 else
952 null;
953 const global_index = try coff_file.getGlobalSymbol(name, lib_name);945 const global_index = try coff_file.getGlobalSymbol(name, lib_name);
954 try coff_file.need_got_table.put(gpa, global_index, {}); // needs GOT946 try coff_file.need_got_table.put(gpa, global_index, {}); // needs GOT
955 return GenResult.mcv(.{ .load_got = link.File.Coff.global_symbol_bit | global_index });947 return GenResult.mcv(.{ .load_got = link.File.Coff.global_symbol_bit | global_index });
...@@ -1012,6 +1004,7 @@ pub fn genTypedValue(...@@ -1012,6 +1004,7 @@ pub fn genTypedValue(
1012 owner_decl_index: InternPool.DeclIndex,1004 owner_decl_index: InternPool.DeclIndex,
1013) CodeGenError!GenResult {1005) CodeGenError!GenResult {
1014 const zcu = lf.comp.module.?;1006 const zcu = lf.comp.module.?;
1007 const ip = &zcu.intern_pool;
1015 const ty = val.typeOf(zcu);1008 const ty = val.typeOf(zcu);
10161009
1017 log.debug("genTypedValue: val = {}", .{val.fmtValue(zcu)});1010 log.debug("genTypedValue: val = {}", .{val.fmtValue(zcu)});
...@@ -1024,7 +1017,7 @@ pub fn genTypedValue(...@@ -1024,7 +1017,7 @@ pub fn genTypedValue(
1024 const target = namespace.file_scope.mod.resolved_target.result;1017 const target = namespace.file_scope.mod.resolved_target.result;
1025 const ptr_bits = target.ptrBitWidth();1018 const ptr_bits = target.ptrBitWidth();
10261019
1027 if (!ty.isSlice(zcu)) switch (zcu.intern_pool.indexToKey(val.toIntern())) {1020 if (!ty.isSlice(zcu)) switch (ip.indexToKey(val.toIntern())) {
1028 .ptr => |ptr| switch (ptr.addr) {1021 .ptr => |ptr| switch (ptr.addr) {
1029 .decl => |decl| return genDeclRef(lf, src_loc, val, decl),1022 .decl => |decl| return genDeclRef(lf, src_loc, val, decl),
1030 else => {},1023 else => {},
...@@ -1041,7 +1034,7 @@ pub fn genTypedValue(...@@ -1041,7 +1034,7 @@ pub fn genTypedValue(
1041 return GenResult.mcv(.{ .immediate = 0 });1034 return GenResult.mcv(.{ .immediate = 0 });
1042 },1035 },
1043 .none => {},1036 .none => {},
1044 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {1037 else => switch (ip.indexToKey(val.toIntern())) {
1045 .int => {1038 .int => {
1046 return GenResult.mcv(.{ .immediate = val.toUnsignedInt(zcu) });1039 return GenResult.mcv(.{ .immediate = val.toUnsignedInt(zcu) });
1047 },1040 },
...@@ -1052,8 +1045,8 @@ pub fn genTypedValue(...@@ -1052,8 +1045,8 @@ pub fn genTypedValue(
1052 .Int => {1045 .Int => {
1053 const info = ty.intInfo(zcu);1046 const info = ty.intInfo(zcu);
1054 if (info.bits <= ptr_bits) {1047 if (info.bits <= ptr_bits) {
1055 const unsigned = switch (info.signedness) {1048 const unsigned: u64 = switch (info.signedness) {
1056 .signed => @as(u64, @bitCast(val.toSignedInt(zcu))),1049 .signed => @bitCast(val.toSignedInt(zcu)),
1057 .unsigned => val.toUnsignedInt(zcu),1050 .unsigned => val.toUnsignedInt(zcu),
1058 };1051 };
1059 return GenResult.mcv(.{ .immediate = unsigned });1052 return GenResult.mcv(.{ .immediate = unsigned });
...@@ -1075,7 +1068,7 @@ pub fn genTypedValue(...@@ -1075,7 +1068,7 @@ pub fn genTypedValue(
1075 }1068 }
1076 },1069 },
1077 .Enum => {1070 .Enum => {
1078 const enum_tag = zcu.intern_pool.indexToKey(val.toIntern()).enum_tag;1071 const enum_tag = ip.indexToKey(val.toIntern()).enum_tag;
1079 return genTypedValue(1072 return genTypedValue(
1080 lf,1073 lf,
1081 src_loc,1074 src_loc,
...@@ -1084,7 +1077,7 @@ pub fn genTypedValue(...@@ -1084,7 +1077,7 @@ pub fn genTypedValue(
1084 );1077 );
1085 },1078 },
1086 .ErrorSet => {1079 .ErrorSet => {
1087 const err_name = zcu.intern_pool.indexToKey(val.toIntern()).err.name;1080 const err_name = ip.indexToKey(val.toIntern()).err.name;
1088 const error_index = zcu.global_error_set.getIndex(err_name).?;1081 const error_index = zcu.global_error_set.getIndex(err_name).?;
1089 return GenResult.mcv(.{ .immediate = error_index });1082 return GenResult.mcv(.{ .immediate = error_index });
1090 },1083 },
...@@ -1094,7 +1087,7 @@ pub fn genTypedValue(...@@ -1094,7 +1087,7 @@ pub fn genTypedValue(
1094 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {1087 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
1095 // We use the error type directly as the type.1088 // We use the error type directly as the type.
1096 const err_int_ty = try zcu.errorIntType();1089 const err_int_ty = try zcu.errorIntType();
1097 switch (zcu.intern_pool.indexToKey(val.toIntern()).error_union.val) {1090 switch (ip.indexToKey(val.toIntern()).error_union.val) {
1098 .err_name => |err_name| return genTypedValue(1091 .err_name => |err_name| return genTypedValue(
1099 lf,1092 lf,
1100 src_loc,1093 src_loc,
src/codegen/c.zig+53-53
...@@ -505,7 +505,7 @@ pub const Function = struct {...@@ -505,7 +505,7 @@ pub const Function = struct {
505 .never_inline,505 .never_inline,
506 => |owner_decl| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{506 => |owner_decl| try ctype_pool.fmt(gpa, "zig_{s}_{}__{d}", .{
507 @tagName(key),507 @tagName(key),
508 fmtIdent(zcu.intern_pool.stringToSlice(zcu.declPtr(owner_decl).name)),508 fmtIdent(zcu.declPtr(owner_decl).name.toSlice(&zcu.intern_pool)),
509 @intFromEnum(owner_decl),509 @intFromEnum(owner_decl),
510 }),510 }),
511 },511 },
...@@ -898,7 +898,7 @@ pub const DeclGen = struct {...@@ -898,7 +898,7 @@ pub const DeclGen = struct {
898 },898 },
899 },899 },
900 .err => |err| try writer.print("zig_error_{}", .{900 .err => |err| try writer.print("zig_error_{}", .{
901 fmtIdent(ip.stringToSlice(err.name)),901 fmtIdent(err.name.toSlice(ip)),
902 }),902 }),
903 .error_union => |error_union| {903 .error_union => |error_union| {
904 const payload_ty = ty.errorUnionPayload(zcu);904 const payload_ty = ty.errorUnionPayload(zcu);
...@@ -1178,7 +1178,7 @@ pub const DeclGen = struct {...@@ -1178,7 +1178,7 @@ pub const DeclGen = struct {
1178 switch (ip.indexToKey(val.toIntern()).aggregate.storage) {1178 switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
1179 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{1179 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{
1180 .ty = field_ty.toIntern(),1180 .ty = field_ty.toIntern(),
1181 .storage = .{ .u64 = bytes[field_index] },1181 .storage = .{ .u64 = bytes.at(field_index, ip) },
1182 } }),1182 } }),
1183 .elems => |elems| elems[field_index],1183 .elems => |elems| elems[field_index],
1184 .repeated_elem => |elem| elem,1184 .repeated_elem => |elem| elem,
...@@ -1212,7 +1212,7 @@ pub const DeclGen = struct {...@@ -1212,7 +1212,7 @@ pub const DeclGen = struct {
1212 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {1212 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
1213 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{1213 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{
1214 .ty = field_ty.toIntern(),1214 .ty = field_ty.toIntern(),
1215 .storage = .{ .u64 = bytes[field_index] },1215 .storage = .{ .u64 = bytes.at(field_index, ip) },
1216 } }),1216 } }),
1217 .elems => |elems| elems[field_index],1217 .elems => |elems| elems[field_index],
1218 .repeated_elem => |elem| elem,1218 .repeated_elem => |elem| elem,
...@@ -1258,7 +1258,7 @@ pub const DeclGen = struct {...@@ -1258,7 +1258,7 @@ pub const DeclGen = struct {
1258 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {1258 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
1259 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{1259 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{
1260 .ty = field_ty.toIntern(),1260 .ty = field_ty.toIntern(),
1261 .storage = .{ .u64 = bytes[field_index] },1261 .storage = .{ .u64 = bytes.at(field_index, ip) },
1262 } }),1262 } }),
1263 .elems => |elems| elems[field_index],1263 .elems => |elems| elems[field_index],
1264 .repeated_elem => |elem| elem,1264 .repeated_elem => |elem| elem,
...@@ -1299,7 +1299,7 @@ pub const DeclGen = struct {...@@ -1299,7 +1299,7 @@ pub const DeclGen = struct {
1299 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {1299 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
1300 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{1300 .bytes => |bytes| try ip.get(zcu.gpa, .{ .int = .{
1301 .ty = field_ty.toIntern(),1301 .ty = field_ty.toIntern(),
1302 .storage = .{ .u64 = bytes[field_index] },1302 .storage = .{ .u64 = bytes.at(field_index, ip) },
1303 } }),1303 } }),
1304 .elems => |elems| elems[field_index],1304 .elems => |elems| elems[field_index],
1305 .repeated_elem => |elem| elem,1305 .repeated_elem => |elem| elem,
...@@ -1392,7 +1392,7 @@ pub const DeclGen = struct {...@@ -1392,7 +1392,7 @@ pub const DeclGen = struct {
1392 try writer.writeAll(" .payload = {");1392 try writer.writeAll(" .payload = {");
1393 }1393 }
1394 if (field_ty.hasRuntimeBits(zcu)) {1394 if (field_ty.hasRuntimeBits(zcu)) {
1395 try writer.print(" .{ } = ", .{fmtIdent(ip.stringToSlice(field_name))});1395 try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))});
1396 try dg.renderValue(writer, Value.fromInterned(un.val), initializer_type);1396 try dg.renderValue(writer, Value.fromInterned(un.val), initializer_type);
1397 try writer.writeByte(' ');1397 try writer.writeByte(' ');
1398 } else for (0..loaded_union.field_types.len) |this_field_index| {1398 } else for (0..loaded_union.field_types.len) |this_field_index| {
...@@ -1741,14 +1741,12 @@ pub const DeclGen = struct {...@@ -1741,14 +1741,12 @@ pub const DeclGen = struct {
1741 switch (name) {1741 switch (name) {
1742 .export_index => |export_index| mangled: {1742 .export_index => |export_index| mangled: {
1743 const maybe_exports = zcu.decl_exports.get(fn_decl_index);1743 const maybe_exports = zcu.decl_exports.get(fn_decl_index);
1744 const external_name = ip.stringToSlice(1744 const external_name = (if (maybe_exports) |exports|
1745 if (maybe_exports) |exports|1745 exports.items[export_index].opts.name
1746 exports.items[export_index].opts.name1746 else if (fn_decl.isExtern(zcu))
1747 else if (fn_decl.isExtern(zcu))1747 fn_decl.name
1748 fn_decl.name1748 else
1749 else1749 break :mangled).toSlice(ip);
1750 break :mangled,
1751 );
1752 const is_mangled = isMangledIdent(external_name, true);1750 const is_mangled = isMangledIdent(external_name, true);
1753 const is_export = export_index > 0;1751 const is_export = export_index > 0;
1754 if (is_mangled and is_export) {1752 if (is_mangled and is_export) {
...@@ -1756,7 +1754,7 @@ pub const DeclGen = struct {...@@ -1756,7 +1754,7 @@ pub const DeclGen = struct {
1756 fmtIdent(external_name),1754 fmtIdent(external_name),
1757 fmtStringLiteral(external_name, null),1755 fmtStringLiteral(external_name, null),
1758 fmtStringLiteral(1756 fmtStringLiteral(
1759 ip.stringToSlice(maybe_exports.?.items[0].opts.name),1757 maybe_exports.?.items[0].opts.name.toSlice(ip),
1760 null,1758 null,
1761 ),1759 ),
1762 });1760 });
...@@ -1767,7 +1765,7 @@ pub const DeclGen = struct {...@@ -1767,7 +1765,7 @@ pub const DeclGen = struct {
1767 } else if (is_export) {1765 } else if (is_export) {
1768 try w.print(" zig_export({s}, {s})", .{1766 try w.print(" zig_export({s}, {s})", .{
1769 fmtStringLiteral(1767 fmtStringLiteral(
1770 ip.stringToSlice(maybe_exports.?.items[0].opts.name),1768 maybe_exports.?.items[0].opts.name.toSlice(ip),
1771 null,1769 null,
1772 ),1770 ),
1773 fmtStringLiteral(external_name, null),1771 fmtStringLiteral(external_name, null),
...@@ -2075,12 +2073,12 @@ pub const DeclGen = struct {...@@ -2075,12 +2073,12 @@ pub const DeclGen = struct {
2075 .complete,2073 .complete,
2076 );2074 );
2077 mangled: {2075 mangled: {
2078 const external_name = zcu.intern_pool.stringToSlice(if (maybe_exports) |exports|2076 const external_name = (if (maybe_exports) |exports|
2079 exports.items[0].opts.name2077 exports.items[0].opts.name
2080 else if (variable.is_extern)2078 else if (variable.is_extern)
2081 decl.name2079 decl.name
2082 else2080 else
2083 break :mangled);2081 break :mangled).toSlice(&zcu.intern_pool);
2084 if (isMangledIdent(external_name, true)) {2082 if (isMangledIdent(external_name, true)) {
2085 try fwd.print(" zig_mangled_{s}({ }, {s})", .{2083 try fwd.print(" zig_mangled_{s}({ }, {s})", .{
2086 @tagName(fwd_kind),2084 @tagName(fwd_kind),
...@@ -2094,15 +2092,16 @@ pub const DeclGen = struct {...@@ -2094,15 +2092,16 @@ pub const DeclGen = struct {
20942092
2095 fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: InternPool.DeclIndex, export_index: u32) !void {2093 fn renderDeclName(dg: *DeclGen, writer: anytype, decl_index: InternPool.DeclIndex, export_index: u32) !void {
2096 const zcu = dg.zcu;2094 const zcu = dg.zcu;
2095 const ip = &zcu.intern_pool;
2097 const decl = zcu.declPtr(decl_index);2096 const decl = zcu.declPtr(decl_index);
20982097
2099 if (zcu.decl_exports.get(decl_index)) |exports| {2098 if (zcu.decl_exports.get(decl_index)) |exports| {
2100 try writer.print("{ }", .{2099 try writer.print("{ }", .{
2101 fmtIdent(zcu.intern_pool.stringToSlice(exports.items[export_index].opts.name)),2100 fmtIdent(exports.items[export_index].opts.name.toSlice(ip)),
2102 });2101 });
2103 } else if (decl.getExternDecl(zcu).unwrap()) |extern_decl_index| {2102 } else if (decl.getExternDecl(zcu).unwrap()) |extern_decl_index| {
2104 try writer.print("{ }", .{2103 try writer.print("{ }", .{
2105 fmtIdent(zcu.intern_pool.stringToSlice(zcu.declPtr(extern_decl_index).name)),2104 fmtIdent(zcu.declPtr(extern_decl_index).name.toSlice(ip)),
2106 });2105 });
2107 } else {2106 } else {
2108 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),2107 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
...@@ -2226,7 +2225,7 @@ fn renderFwdDeclTypeName(...@@ -2226,7 +2225,7 @@ fn renderFwdDeclTypeName(
2226 switch (fwd_decl.name) {2225 switch (fwd_decl.name) {
2227 .anon => try w.print("anon__lazy_{d}", .{@intFromEnum(ctype.index)}),2226 .anon => try w.print("anon__lazy_{d}", .{@intFromEnum(ctype.index)}),
2228 .owner_decl => |owner_decl| try w.print("{}__{d}", .{2227 .owner_decl => |owner_decl| try w.print("{}__{d}", .{
2229 fmtIdent(zcu.intern_pool.stringToSlice(zcu.declPtr(owner_decl).name)),2228 fmtIdent(zcu.declPtr(owner_decl).name.toSlice(&zcu.intern_pool)),
2230 @intFromEnum(owner_decl),2229 @intFromEnum(owner_decl),
2231 }),2230 }),
2232 }2231 }
...@@ -2548,7 +2547,7 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2548,7 +2547,7 @@ pub fn genErrDecls(o: *Object) !void {
2548 try writer.writeAll("enum {\n");2547 try writer.writeAll("enum {\n");
2549 o.indent_writer.pushIndent();2548 o.indent_writer.pushIndent();
2550 for (zcu.global_error_set.keys()[1..], 1..) |name_nts, value| {2549 for (zcu.global_error_set.keys()[1..], 1..) |name_nts, value| {
2551 const name = ip.stringToSlice(name_nts);2550 const name = name_nts.toSlice(ip);
2552 max_name_len = @max(name.len, max_name_len);2551 max_name_len = @max(name.len, max_name_len);
2553 const err_val = try zcu.intern(.{ .err = .{2552 const err_val = try zcu.intern(.{ .err = .{
2554 .ty = .anyerror_type,2553 .ty = .anyerror_type,
...@@ -2566,19 +2565,19 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2566,19 +2565,19 @@ pub fn genErrDecls(o: *Object) !void {
2566 defer o.dg.gpa.free(name_buf);2565 defer o.dg.gpa.free(name_buf);
25672566
2568 @memcpy(name_buf[0..name_prefix.len], name_prefix);2567 @memcpy(name_buf[0..name_prefix.len], name_prefix);
2569 for (zcu.global_error_set.keys()) |name_ip| {2568 for (zcu.global_error_set.keys()) |name| {
2570 const name = ip.stringToSlice(name_ip);2569 const name_slice = name.toSlice(ip);
2571 @memcpy(name_buf[name_prefix.len..][0..name.len], name);2570 @memcpy(name_buf[name_prefix.len..][0..name_slice.len], name_slice);
2572 const identifier = name_buf[0 .. name_prefix.len + name.len];2571 const identifier = name_buf[0 .. name_prefix.len + name_slice.len];
25732572
2574 const name_ty = try zcu.arrayType(.{2573 const name_ty = try zcu.arrayType(.{
2575 .len = name.len,2574 .len = name_slice.len,
2576 .child = .u8_type,2575 .child = .u8_type,
2577 .sentinel = .zero_u8,2576 .sentinel = .zero_u8,
2578 });2577 });
2579 const name_val = try zcu.intern(.{ .aggregate = .{2578 const name_val = try zcu.intern(.{ .aggregate = .{
2580 .ty = name_ty.toIntern(),2579 .ty = name_ty.toIntern(),
2581 .storage = .{ .bytes = name },2580 .storage = .{ .bytes = name.toString() },
2582 } });2581 } });
25832582
2584 try writer.writeAll("static ");2583 try writer.writeAll("static ");
...@@ -2611,7 +2610,7 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2611,7 +2610,7 @@ pub fn genErrDecls(o: *Object) !void {
2611 );2610 );
2612 try writer.writeAll(" = {");2611 try writer.writeAll(" = {");
2613 for (zcu.global_error_set.keys(), 0..) |name_nts, value| {2612 for (zcu.global_error_set.keys(), 0..) |name_nts, value| {
2614 const name = ip.stringToSlice(name_nts);2613 const name = name_nts.toSlice(ip);
2615 if (value != 0) try writer.writeByte(',');2614 if (value != 0) try writer.writeByte(',');
2616 try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{2615 try writer.print("{{" ++ name_prefix ++ "{}, {}}}", .{
2617 fmtIdent(name),2616 fmtIdent(name),
...@@ -2659,7 +2658,7 @@ fn genExports(o: *Object) !void {...@@ -2659,7 +2658,7 @@ fn genExports(o: *Object) !void {
2659 for (exports.items[1..]) |@"export"| {2658 for (exports.items[1..]) |@"export"| {
2660 try fwd.writeAll("zig_extern ");2659 try fwd.writeAll("zig_extern ");
2661 if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage ");2660 if (@"export".opts.linkage == .weak) try fwd.writeAll("zig_weak_linkage ");
2662 const export_name = ip.stringToSlice(@"export".opts.name);2661 const export_name = @"export".opts.name.toSlice(ip);
2663 try o.dg.renderTypeAndName(2662 try o.dg.renderTypeAndName(
2664 fwd,2663 fwd,
2665 decl.typeOf(zcu),2664 decl.typeOf(zcu),
...@@ -2672,11 +2671,11 @@ fn genExports(o: *Object) !void {...@@ -2672,11 +2671,11 @@ fn genExports(o: *Object) !void {
2672 try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{2671 try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{
2673 fmtIdent(export_name),2672 fmtIdent(export_name),
2674 fmtStringLiteral(export_name, null),2673 fmtStringLiteral(export_name, null),
2675 fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),2674 fmtStringLiteral(exports.items[0].opts.name.toSlice(ip), null),
2676 });2675 });
2677 } else {2676 } else {
2678 try fwd.print(" zig_export({s}, {s})", .{2677 try fwd.print(" zig_export({s}, {s})", .{
2679 fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),2678 fmtStringLiteral(exports.items[0].opts.name.toSlice(ip), null),
2680 fmtStringLiteral(export_name, null),2679 fmtStringLiteral(export_name, null),
2681 });2680 });
2682 }2681 }
...@@ -2706,17 +2705,18 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn...@@ -2706,17 +2705,18 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
2706 try w.writeAll(") {\n switch (tag) {\n");2705 try w.writeAll(") {\n switch (tag) {\n");
2707 const tag_names = enum_ty.enumFields(zcu);2706 const tag_names = enum_ty.enumFields(zcu);
2708 for (0..tag_names.len) |tag_index| {2707 for (0..tag_names.len) |tag_index| {
2709 const tag_name = ip.stringToSlice(tag_names.get(ip)[tag_index]);2708 const tag_name = tag_names.get(ip)[tag_index];
2709 const tag_name_len = tag_name.length(ip);
2710 const tag_val = try zcu.enumValueFieldIndex(enum_ty, @intCast(tag_index));2710 const tag_val = try zcu.enumValueFieldIndex(enum_ty, @intCast(tag_index));
27112711
2712 const name_ty = try zcu.arrayType(.{2712 const name_ty = try zcu.arrayType(.{
2713 .len = tag_name.len,2713 .len = tag_name_len,
2714 .child = .u8_type,2714 .child = .u8_type,
2715 .sentinel = .zero_u8,2715 .sentinel = .zero_u8,
2716 });2716 });
2717 const name_val = try zcu.intern(.{ .aggregate = .{2717 const name_val = try zcu.intern(.{ .aggregate = .{
2718 .ty = name_ty.toIntern(),2718 .ty = name_ty.toIntern(),
2719 .storage = .{ .bytes = tag_name },2719 .storage = .{ .bytes = tag_name.toString() },
2720 } });2720 } });
27212721
2722 try w.print(" case {}: {{\n static ", .{2722 try w.print(" case {}: {{\n static ", .{
...@@ -2729,7 +2729,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn...@@ -2729,7 +2729,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
2729 try o.dg.renderType(w, name_slice_ty);2729 try o.dg.renderType(w, name_slice_ty);
2730 try w.print("){{{}, {}}};\n", .{2730 try w.print("){{{}, {}}};\n", .{
2731 fmtIdent("name"),2731 fmtIdent("name"),
2732 try o.dg.fmtIntLiteral(try zcu.intValue(Type.usize, tag_name.len), .Other),2732 try o.dg.fmtIntLiteral(try zcu.intValue(Type.usize, tag_name_len), .Other),
2733 });2733 });
27342734
2735 try w.writeAll(" }\n");2735 try w.writeAll(" }\n");
...@@ -2797,7 +2797,7 @@ pub fn genFunc(f: *Function) !void {...@@ -2797,7 +2797,7 @@ pub fn genFunc(f: *Function) !void {
27972797
2798 try o.indent_writer.insertNewline();2798 try o.indent_writer.insertNewline();
2799 if (!is_global) try o.writer().writeAll("static ");2799 if (!is_global) try o.writer().writeAll("static ");
2800 if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |s|2800 if (decl.@"linksection".toSlice(&zcu.intern_pool)) |s|
2801 try o.writer().print("zig_linksection_fn({s}) ", .{fmtStringLiteral(s, null)});2801 try o.writer().print("zig_linksection_fn({s}) ", .{fmtStringLiteral(s, null)});
2802 try o.dg.renderFunctionSignature(o.writer(), decl_index, .complete, .{ .export_index = 0 });2802 try o.dg.renderFunctionSignature(o.writer(), decl_index, .complete, .{ .export_index = 0 });
2803 try o.writer().writeByte(' ');2803 try o.writer().writeByte(' ');
...@@ -2887,7 +2887,7 @@ pub fn genDecl(o: *Object) !void {...@@ -2887,7 +2887,7 @@ pub fn genDecl(o: *Object) !void {
2887 if (!is_global) try w.writeAll("static ");2887 if (!is_global) try w.writeAll("static ");
2888 if (variable.is_weak_linkage) try w.writeAll("zig_weak_linkage ");2888 if (variable.is_weak_linkage) try w.writeAll("zig_weak_linkage ");
2889 if (variable.is_threadlocal and !o.dg.mod.single_threaded) try w.writeAll("zig_threadlocal ");2889 if (variable.is_threadlocal and !o.dg.mod.single_threaded) try w.writeAll("zig_threadlocal ");
2890 if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |s|2890 if (decl.@"linksection".toSlice(&zcu.intern_pool)) |s|
2891 try w.print("zig_linksection({s}) ", .{fmtStringLiteral(s, null)});2891 try w.print("zig_linksection({s}) ", .{fmtStringLiteral(s, null)});
2892 const decl_c_value = .{ .decl = decl_index };2892 const decl_c_value = .{ .decl = decl_index };
2893 try o.dg.renderTypeAndName(w, decl_ty, decl_c_value, .{}, decl.alignment, .complete);2893 try o.dg.renderTypeAndName(w, decl_ty, decl_c_value, .{}, decl.alignment, .complete);
...@@ -2920,7 +2920,7 @@ pub fn genDeclValue(...@@ -2920,7 +2920,7 @@ pub fn genDeclValue(
2920 switch (o.dg.pass) {2920 switch (o.dg.pass) {
2921 .decl => |decl_index| {2921 .decl => |decl_index| {
2922 if (zcu.decl_exports.get(decl_index)) |exports| {2922 if (zcu.decl_exports.get(decl_index)) |exports| {
2923 const export_name = zcu.intern_pool.stringToSlice(exports.items[0].opts.name);2923 const export_name = exports.items[0].opts.name.toSlice(&zcu.intern_pool);
2924 if (isMangledIdent(export_name, true)) {2924 if (isMangledIdent(export_name, true)) {
2925 try fwd_decl_writer.print(" zig_mangled_final({ }, {s})", .{2925 try fwd_decl_writer.print(" zig_mangled_final({ }, {s})", .{
2926 fmtIdent(export_name), fmtStringLiteral(export_name, null),2926 fmtIdent(export_name), fmtStringLiteral(export_name, null),
...@@ -2936,7 +2936,7 @@ pub fn genDeclValue(...@@ -2936,7 +2936,7 @@ pub fn genDeclValue(
29362936
2937 const w = o.writer();2937 const w = o.writer();
2938 if (!is_global) try w.writeAll("static ");2938 if (!is_global) try w.writeAll("static ");
2939 if (zcu.intern_pool.stringToSliceUnwrap(@"linksection")) |s|2939 if (@"linksection".toSlice(&zcu.intern_pool)) |s|
2940 try w.print("zig_linksection({s}) ", .{fmtStringLiteral(s, null)});2940 try w.print("zig_linksection({s}) ", .{fmtStringLiteral(s, null)});
2941 try o.dg.renderTypeAndName(w, ty, decl_c_value, Const, alignment, .complete);2941 try o.dg.renderTypeAndName(w, ty, decl_c_value, Const, alignment, .complete);
2942 try w.writeAll(" = ");2942 try w.writeAll(" = ");
...@@ -5454,7 +5454,7 @@ fn fieldLocation(...@@ -5454,7 +5454,7 @@ fn fieldLocation(
5454 .{ .byte_offset = loaded_struct.offsets.get(ip)[field_index] }5454 .{ .byte_offset = loaded_struct.offsets.get(ip)[field_index] }
5455 else5455 else
5456 .{ .field = if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|5456 .{ .field = if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|
5457 .{ .identifier = ip.stringToSlice(field_name) }5457 .{ .identifier = field_name.toSlice(ip) }
5458 else5458 else
5459 .{ .field = field_index } },5459 .{ .field = field_index } },
5460 .@"packed" => if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0)5460 .@"packed" => if (field_ptr_ty.ptrInfo(zcu).packed_offset.host_size == 0)
...@@ -5470,7 +5470,7 @@ fn fieldLocation(...@@ -5470,7 +5470,7 @@ fn fieldLocation(
5470 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }5470 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }
5471 else5471 else
5472 .{ .field = if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|5472 .{ .field = if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|
5473 .{ .identifier = ip.stringToSlice(field_name) }5473 .{ .identifier = field_name.toSlice(ip) }
5474 else5474 else
5475 .{ .field = field_index } },5475 .{ .field = field_index } },
5476 .union_type => {5476 .union_type => {
...@@ -5485,9 +5485,9 @@ fn fieldLocation(...@@ -5485,9 +5485,9 @@ fn fieldLocation(
5485 .begin;5485 .begin;
5486 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];5486 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
5487 return .{ .field = if (loaded_union.hasTag(ip))5487 return .{ .field = if (loaded_union.hasTag(ip))
5488 .{ .payload_identifier = ip.stringToSlice(field_name) }5488 .{ .payload_identifier = field_name.toSlice(ip) }
5489 else5489 else
5490 .{ .identifier = ip.stringToSlice(field_name) } };5490 .{ .identifier = field_name.toSlice(ip) } };
5491 },5491 },
5492 .@"packed" => return .begin,5492 .@"packed" => return .begin,
5493 }5493 }
...@@ -5643,7 +5643,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5643,7 +5643,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5643 const loaded_struct = ip.loadStructType(struct_ty.toIntern());5643 const loaded_struct = ip.loadStructType(struct_ty.toIntern());
5644 switch (loaded_struct.layout) {5644 switch (loaded_struct.layout) {
5645 .auto, .@"extern" => break :field_name if (loaded_struct.fieldName(ip, extra.field_index).unwrap()) |field_name|5645 .auto, .@"extern" => break :field_name if (loaded_struct.fieldName(ip, extra.field_index).unwrap()) |field_name|
5646 .{ .identifier = ip.stringToSlice(field_name) }5646 .{ .identifier = field_name.toSlice(ip) }
5647 else5647 else
5648 .{ .field = extra.field_index },5648 .{ .field = extra.field_index },
5649 .@"packed" => {5649 .@"packed" => {
...@@ -5701,7 +5701,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5701,7 +5701,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5701 }5701 }
5702 },5702 },
5703 .anon_struct_type => |anon_struct_info| if (anon_struct_info.fieldName(ip, extra.field_index).unwrap()) |field_name|5703 .anon_struct_type => |anon_struct_info| if (anon_struct_info.fieldName(ip, extra.field_index).unwrap()) |field_name|
5704 .{ .identifier = ip.stringToSlice(field_name) }5704 .{ .identifier = field_name.toSlice(ip) }
5705 else5705 else
5706 .{ .field = extra.field_index },5706 .{ .field = extra.field_index },
5707 .union_type => field_name: {5707 .union_type => field_name: {
...@@ -5710,9 +5710,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5710,9 +5710,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5710 .auto, .@"extern" => {5710 .auto, .@"extern" => {
5711 const name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index];5711 const name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index];
5712 break :field_name if (loaded_union.hasTag(ip))5712 break :field_name if (loaded_union.hasTag(ip))
5713 .{ .payload_identifier = ip.stringToSlice(name) }5713 .{ .payload_identifier = name.toSlice(ip) }
5714 else5714 else
5715 .{ .identifier = ip.stringToSlice(name) };5715 .{ .identifier = name.toSlice(ip) };
5716 },5716 },
5717 .@"packed" => {5717 .@"packed" => {
5718 const operand_lval = if (struct_byval == .constant) blk: {5718 const operand_lval = if (struct_byval == .constant) blk: {
...@@ -7062,7 +7062,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7062,7 +7062,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
70627062
7063 const a = try Assignment.start(f, writer, field_ty);7063 const a = try Assignment.start(f, writer, field_ty);
7064 try f.writeCValueMember(writer, local, if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|7064 try f.writeCValueMember(writer, local, if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|
7065 .{ .identifier = ip.stringToSlice(field_name) }7065 .{ .identifier = field_name.toSlice(ip) }
7066 else7066 else
7067 .{ .field = field_index });7067 .{ .field = field_index });
7068 try a.assign(f, writer);7068 try a.assign(f, writer);
...@@ -7142,7 +7142,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7142,7 +7142,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
71427142
7143 const a = try Assignment.start(f, writer, field_ty);7143 const a = try Assignment.start(f, writer, field_ty);
7144 try f.writeCValueMember(writer, local, if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|7144 try f.writeCValueMember(writer, local, if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|
7145 .{ .identifier = ip.stringToSlice(field_name) }7145 .{ .identifier = field_name.toSlice(ip) }
7146 else7146 else
7147 .{ .field = field_index });7147 .{ .field = field_index });
7148 try a.assign(f, writer);7148 try a.assign(f, writer);
...@@ -7190,8 +7190,8 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7190,8 +7190,8 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
7190 try writer.print("{}", .{try f.fmtIntLiteral(try tag_val.intFromEnum(tag_ty, zcu))});7190 try writer.print("{}", .{try f.fmtIntLiteral(try tag_val.intFromEnum(tag_ty, zcu))});
7191 try a.end(f, writer);7191 try a.end(f, writer);
7192 }7192 }
7193 break :field .{ .payload_identifier = ip.stringToSlice(field_name) };7193 break :field .{ .payload_identifier = field_name.toSlice(ip) };
7194 } else .{ .identifier = ip.stringToSlice(field_name) };7194 } else .{ .identifier = field_name.toSlice(ip) };
71957195
7196 const a = try Assignment.start(f, writer, payload_ty);7196 const a = try Assignment.start(f, writer, payload_ty);
7197 try f.writeCValueMember(writer, local, field);7197 try f.writeCValueMember(writer, local, field);
src/codegen/c/Type.zig+5-5
...@@ -1465,7 +1465,7 @@ pub const Pool = struct {...@@ -1465,7 +1465,7 @@ pub const Pool = struct {
1465 },1465 },
1466 },1466 },
1467 .array_type => |array_info| {1467 .array_type => |array_info| {
1468 const len = array_info.len + @intFromBool(array_info.sentinel != .none);1468 const len = array_info.lenIncludingSentinel();
1469 if (len == 0) return .{ .index = .void };1469 if (len == 0) return .{ .index = .void };
1470 const elem_type = Type.fromInterned(array_info.child);1470 const elem_type = Type.fromInterned(array_info.child);
1471 const elem_ctype = try pool.fromType(1471 const elem_ctype = try pool.fromType(
...@@ -1479,7 +1479,7 @@ pub const Pool = struct {...@@ -1479,7 +1479,7 @@ pub const Pool = struct {
1479 if (elem_ctype.index == .void) return .{ .index = .void };1479 if (elem_ctype.index == .void) return .{ .index = .void };
1480 const array_ctype = try pool.getArray(allocator, .{1480 const array_ctype = try pool.getArray(allocator, .{
1481 .elem_ctype = elem_ctype,1481 .elem_ctype = elem_ctype,
1482 .len = array_info.len + @intFromBool(array_info.sentinel != .none),1482 .len = len,
1483 });1483 });
1484 if (!kind.isParameter()) return array_ctype;1484 if (!kind.isParameter()) return array_ctype;
1485 var fields = [_]Info.Field{1485 var fields = [_]Info.Field{
...@@ -1625,7 +1625,7 @@ pub const Pool = struct {...@@ -1625,7 +1625,7 @@ pub const Pool = struct {
1625 if (field_ctype.index == .void) continue;1625 if (field_ctype.index == .void) continue;
1626 const field_name = if (loaded_struct.fieldName(ip, field_index)1626 const field_name = if (loaded_struct.fieldName(ip, field_index)
1627 .unwrap()) |field_name|1627 .unwrap()) |field_name|
1628 try pool.string(allocator, ip.stringToSlice(field_name))1628 try pool.string(allocator, field_name.toSlice(ip))
1629 else1629 else
1630 try pool.fmt(allocator, "f{d}", .{field_index});1630 try pool.fmt(allocator, "f{d}", .{field_index});
1631 const field_alignas = AlignAs.fromAlignment(.{1631 const field_alignas = AlignAs.fromAlignment(.{
...@@ -1685,7 +1685,7 @@ pub const Pool = struct {...@@ -1685,7 +1685,7 @@ pub const Pool = struct {
1685 if (field_ctype.index == .void) continue;1685 if (field_ctype.index == .void) continue;
1686 const field_name = if (anon_struct_info.fieldName(ip, @intCast(field_index))1686 const field_name = if (anon_struct_info.fieldName(ip, @intCast(field_index))
1687 .unwrap()) |field_name|1687 .unwrap()) |field_name|
1688 try pool.string(allocator, ip.stringToSlice(field_name))1688 try pool.string(allocator, field_name.toSlice(ip))
1689 else1689 else
1690 try pool.fmt(allocator, "f{d}", .{field_index});1690 try pool.fmt(allocator, "f{d}", .{field_index});
1691 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{1691 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
...@@ -1766,7 +1766,7 @@ pub const Pool = struct {...@@ -1766,7 +1766,7 @@ pub const Pool = struct {
1766 if (field_ctype.index == .void) continue;1766 if (field_ctype.index == .void) continue;
1767 const field_name = try pool.string(1767 const field_name = try pool.string(
1768 allocator,1768 allocator,
1769 ip.stringToSlice(loaded_tag.names.get(ip)[field_index]),1769 loaded_tag.names.get(ip)[field_index].toSlice(ip),
1770 );1770 );
1771 const field_alignas = AlignAs.fromAlignment(.{1771 const field_alignas = AlignAs.fromAlignment(.{
1772 .@"align" = loaded_union.fieldAlign(ip, @intCast(field_index)),1772 .@"align" = loaded_union.fieldAlign(ip, @intCast(field_index)),
src/codegen/llvm.zig+53-60
...@@ -1011,7 +1011,7 @@ pub const Object = struct {...@@ -1011,7 +1011,7 @@ pub const Object = struct {
10111011
1012 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);1012 llvm_errors[0] = try o.builder.undefConst(llvm_slice_ty);
1013 for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name| {1013 for (llvm_errors[1..], error_name_list[1..]) |*llvm_error, name| {
1014 const name_string = try o.builder.stringNull(mod.intern_pool.stringToSlice(name));1014 const name_string = try o.builder.stringNull(name.toSlice(&mod.intern_pool));
1015 const name_init = try o.builder.stringConst(name_string);1015 const name_init = try o.builder.stringConst(name_string);
1016 const name_variable_index =1016 const name_variable_index =
1017 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);1017 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
...@@ -1086,7 +1086,7 @@ pub const Object = struct {...@@ -1086,7 +1086,7 @@ pub const Object = struct {
1086 for (object.extern_collisions.keys()) |decl_index| {1086 for (object.extern_collisions.keys()) |decl_index| {
1087 const global = object.decl_map.get(decl_index) orelse continue;1087 const global = object.decl_map.get(decl_index) orelse continue;
1088 // Same logic as below but for externs instead of exports.1088 // Same logic as below but for externs instead of exports.
1089 const decl_name = object.builder.strtabStringIfExists(mod.intern_pool.stringToSlice(mod.declPtr(decl_index).name)) orelse continue;1089 const decl_name = object.builder.strtabStringIfExists(mod.declPtr(decl_index).name.toSlice(&mod.intern_pool)) orelse continue;
1090 const other_global = object.builder.getGlobal(decl_name) orelse continue;1090 const other_global = object.builder.getGlobal(decl_name) orelse continue;
1091 if (other_global.toConst().getBase(&object.builder) ==1091 if (other_global.toConst().getBase(&object.builder) ==
1092 global.toConst().getBase(&object.builder)) continue;1092 global.toConst().getBase(&object.builder)) continue;
...@@ -1116,7 +1116,7 @@ pub const Object = struct {...@@ -1116,7 +1116,7 @@ pub const Object = struct {
1116 for (export_list) |exp| {1116 for (export_list) |exp| {
1117 // Detect if the LLVM global has already been created as an extern. In such1117 // Detect if the LLVM global has already been created as an extern. In such
1118 // case, we need to replace all uses of it with this exported global.1118 // case, we need to replace all uses of it with this exported global.
1119 const exp_name = object.builder.strtabStringIfExists(mod.intern_pool.stringToSlice(exp.opts.name)) orelse continue;1119 const exp_name = object.builder.strtabStringIfExists(exp.opts.name.toSlice(&mod.intern_pool)) orelse continue;
11201120
1121 const other_global = object.builder.getGlobal(exp_name) orelse continue;1121 const other_global = object.builder.getGlobal(exp_name) orelse continue;
1122 if (other_global.toConst().getBase(&object.builder) == global_base) continue;1122 if (other_global.toConst().getBase(&object.builder) == global_base) continue;
...@@ -1442,7 +1442,7 @@ pub const Object = struct {...@@ -1442,7 +1442,7 @@ pub const Object = struct {
1442 } }, &o.builder);1442 } }, &o.builder);
1443 }1443 }
14441444
1445 if (ip.stringToSliceUnwrap(decl.@"linksection")) |section|1445 if (decl.@"linksection".toSlice(ip)) |section|
1446 function_index.setSection(try o.builder.string(section), &o.builder);1446 function_index.setSection(try o.builder.string(section), &o.builder);
14471447
1448 var deinit_wip = true;1448 var deinit_wip = true;
...@@ -1662,7 +1662,7 @@ pub const Object = struct {...@@ -1662,7 +1662,7 @@ pub const Object = struct {
16621662
1663 const subprogram = try o.builder.debugSubprogram(1663 const subprogram = try o.builder.debugSubprogram(
1664 file,1664 file,
1665 try o.builder.metadataString(ip.stringToSlice(decl.name)),1665 try o.builder.metadataString(decl.name.toSlice(ip)),
1666 try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)),1666 try o.builder.metadataStringFromStrtabString(function_index.name(&o.builder)),
1667 line_number,1667 line_number,
1668 line_number + func.lbrace_line,1668 line_number + func.lbrace_line,
...@@ -1752,6 +1752,7 @@ pub const Object = struct {...@@ -1752,6 +1752,7 @@ pub const Object = struct {
1752 .value => |val| return updateExportedValue(self, mod, val, exports),1752 .value => |val| return updateExportedValue(self, mod, val, exports),
1753 };1753 };
1754 const gpa = mod.gpa;1754 const gpa = mod.gpa;
1755 const ip = &mod.intern_pool;
1755 // If the module does not already have the function, we ignore this function call1756 // If the module does not already have the function, we ignore this function call
1756 // because we call `updateExports` at the end of `updateFunc` and `updateDecl`.1757 // because we call `updateExports` at the end of `updateFunc` and `updateDecl`.
1757 const global_index = self.decl_map.get(decl_index) orelse return;1758 const global_index = self.decl_map.get(decl_index) orelse return;
...@@ -1759,17 +1760,14 @@ pub const Object = struct {...@@ -1759,17 +1760,14 @@ pub const Object = struct {
1759 const comp = mod.comp;1760 const comp = mod.comp;
1760 if (decl.isExtern(mod)) {1761 if (decl.isExtern(mod)) {
1761 const decl_name = decl_name: {1762 const decl_name = decl_name: {
1762 const decl_name = mod.intern_pool.stringToSlice(decl.name);
1763
1764 if (mod.getTarget().isWasm() and decl.val.typeOf(mod).zigTypeTag(mod) == .Fn) {1763 if (mod.getTarget().isWasm() and decl.val.typeOf(mod).zigTypeTag(mod) == .Fn) {
1765 if (mod.intern_pool.stringToSliceUnwrap(decl.getOwnedExternFunc(mod).?.lib_name)) |lib_name| {1764 if (decl.getOwnedExternFunc(mod).?.lib_name.toSlice(ip)) |lib_name| {
1766 if (!std.mem.eql(u8, lib_name, "c")) {1765 if (!std.mem.eql(u8, lib_name, "c")) {
1767 break :decl_name try self.builder.strtabStringFmt("{s}|{s}", .{ decl_name, lib_name });1766 break :decl_name try self.builder.strtabStringFmt("{}|{s}", .{ decl.name.fmt(ip), lib_name });
1768 }1767 }
1769 }1768 }
1770 }1769 }
17711770 break :decl_name try self.builder.strtabString(decl.name.toSlice(ip));
1772 break :decl_name try self.builder.strtabString(decl_name);
1773 };1771 };
17741772
1775 if (self.builder.getGlobal(decl_name)) |other_global| {1773 if (self.builder.getGlobal(decl_name)) |other_global| {
...@@ -1792,9 +1790,7 @@ pub const Object = struct {...@@ -1792,9 +1790,7 @@ pub const Object = struct {
1792 if (decl_var.is_weak_linkage) global_index.setLinkage(.extern_weak, &self.builder);1790 if (decl_var.is_weak_linkage) global_index.setLinkage(.extern_weak, &self.builder);
1793 }1791 }
1794 } else if (exports.len != 0) {1792 } else if (exports.len != 0) {
1795 const main_exp_name = try self.builder.strtabString(1793 const main_exp_name = try self.builder.strtabString(exports[0].opts.name.toSlice(ip));
1796 mod.intern_pool.stringToSlice(exports[0].opts.name),
1797 );
1798 try global_index.rename(main_exp_name, &self.builder);1794 try global_index.rename(main_exp_name, &self.builder);
17991795
1800 if (decl.val.getVariable(mod)) |decl_var| if (decl_var.is_threadlocal)1796 if (decl.val.getVariable(mod)) |decl_var| if (decl_var.is_threadlocal)
...@@ -1803,9 +1799,7 @@ pub const Object = struct {...@@ -1803,9 +1799,7 @@ pub const Object = struct {
18031799
1804 return updateExportedGlobal(self, mod, global_index, exports);1800 return updateExportedGlobal(self, mod, global_index, exports);
1805 } else {1801 } else {
1806 const fqn = try self.builder.strtabString(1802 const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(mod)).toSlice(ip));
1807 mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod)),
1808 );
1809 try global_index.rename(fqn, &self.builder);1803 try global_index.rename(fqn, &self.builder);
1810 global_index.setLinkage(.internal, &self.builder);1804 global_index.setLinkage(.internal, &self.builder);
1811 if (comp.config.dll_export_fns)1805 if (comp.config.dll_export_fns)
...@@ -1832,9 +1826,8 @@ pub const Object = struct {...@@ -1832,9 +1826,8 @@ pub const Object = struct {
1832 exports: []const *Module.Export,1826 exports: []const *Module.Export,
1833 ) link.File.UpdateExportsError!void {1827 ) link.File.UpdateExportsError!void {
1834 const gpa = mod.gpa;1828 const gpa = mod.gpa;
1835 const main_exp_name = try o.builder.strtabString(1829 const ip = &mod.intern_pool;
1836 mod.intern_pool.stringToSlice(exports[0].opts.name),1830 const main_exp_name = try o.builder.strtabString(exports[0].opts.name.toSlice(ip));
1837 );
1838 const global_index = i: {1831 const global_index = i: {
1839 const gop = try o.anon_decl_map.getOrPut(gpa, exported_value);1832 const gop = try o.anon_decl_map.getOrPut(gpa, exported_value);
1840 if (gop.found_existing) {1833 if (gop.found_existing) {
...@@ -1845,7 +1838,7 @@ pub const Object = struct {...@@ -1845,7 +1838,7 @@ pub const Object = struct {
1845 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);1838 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);
1846 const variable_index = try o.builder.addVariable(1839 const variable_index = try o.builder.addVariable(
1847 main_exp_name,1840 main_exp_name,
1848 try o.lowerType(Type.fromInterned(mod.intern_pool.typeOf(exported_value))),1841 try o.lowerType(Type.fromInterned(ip.typeOf(exported_value))),
1849 llvm_addr_space,1842 llvm_addr_space,
1850 );1843 );
1851 const global_index = variable_index.ptrConst(&o.builder).global;1844 const global_index = variable_index.ptrConst(&o.builder).global;
...@@ -1867,8 +1860,9 @@ pub const Object = struct {...@@ -1867,8 +1860,9 @@ pub const Object = struct {
1867 global_index: Builder.Global.Index,1860 global_index: Builder.Global.Index,
1868 exports: []const *Module.Export,1861 exports: []const *Module.Export,
1869 ) link.File.UpdateExportsError!void {1862 ) link.File.UpdateExportsError!void {
1870 global_index.setUnnamedAddr(.default, &o.builder);
1871 const comp = mod.comp;1863 const comp = mod.comp;
1864 const ip = &mod.intern_pool;
1865 global_index.setUnnamedAddr(.default, &o.builder);
1872 if (comp.config.dll_export_fns)1866 if (comp.config.dll_export_fns)
1873 global_index.setDllStorageClass(.dllexport, &o.builder);1867 global_index.setDllStorageClass(.dllexport, &o.builder);
1874 global_index.setLinkage(switch (exports[0].opts.linkage) {1868 global_index.setLinkage(switch (exports[0].opts.linkage) {
...@@ -1882,7 +1876,7 @@ pub const Object = struct {...@@ -1882,7 +1876,7 @@ pub const Object = struct {
1882 .hidden => .hidden,1876 .hidden => .hidden,
1883 .protected => .protected,1877 .protected => .protected,
1884 }, &o.builder);1878 }, &o.builder);
1885 if (mod.intern_pool.stringToSliceUnwrap(exports[0].opts.section)) |section|1879 if (exports[0].opts.section.toSlice(ip)) |section|
1886 switch (global_index.ptrConst(&o.builder).kind) {1880 switch (global_index.ptrConst(&o.builder).kind) {
1887 .variable => |impl_index| impl_index.setSection(1881 .variable => |impl_index| impl_index.setSection(
1888 try o.builder.string(section),1882 try o.builder.string(section),
...@@ -1900,7 +1894,7 @@ pub const Object = struct {...@@ -1900,7 +1894,7 @@ pub const Object = struct {
1900 // Until then we iterate over existing aliases and make them point1894 // Until then we iterate over existing aliases and make them point
1901 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.1895 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.
1902 for (exports[1..]) |exp| {1896 for (exports[1..]) |exp| {
1903 const exp_name = try o.builder.strtabString(mod.intern_pool.stringToSlice(exp.opts.name));1897 const exp_name = try o.builder.strtabString(exp.opts.name.toSlice(ip));
1904 if (o.builder.getGlobal(exp_name)) |global| {1898 if (o.builder.getGlobal(exp_name)) |global| {
1905 switch (global.ptrConst(&o.builder).kind) {1899 switch (global.ptrConst(&o.builder).kind) {
1906 .alias => |alias| {1900 .alias => |alias| {
...@@ -2013,7 +2007,7 @@ pub const Object = struct {...@@ -2013,7 +2007,7 @@ pub const Object = struct {
2013 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();2007 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
20142008
2015 enumerators[i] = try o.builder.debugEnumerator(2009 enumerators[i] = try o.builder.debugEnumerator(
2016 try o.builder.metadataString(ip.stringToSlice(field_name_ip)),2010 try o.builder.metadataString(field_name_ip.toSlice(ip)),
2017 int_info.signedness == .unsigned,2011 int_info.signedness == .unsigned,
2018 int_info.bits,2012 int_info.bits,
2019 bigint,2013 bigint,
...@@ -2473,7 +2467,7 @@ pub const Object = struct {...@@ -2473,7 +2467,7 @@ pub const Object = struct {
2473 offset = field_offset + field_size;2467 offset = field_offset + field_size;
24742468
2475 const field_name = if (tuple.names.len != 0)2469 const field_name = if (tuple.names.len != 0)
2476 ip.stringToSlice(tuple.names.get(ip)[i])2470 tuple.names.get(ip)[i].toSlice(ip)
2477 else2471 else
2478 try std.fmt.allocPrintZ(gpa, "{d}", .{i});2472 try std.fmt.allocPrintZ(gpa, "{d}", .{i});
2479 defer if (tuple.names.len == 0) gpa.free(field_name);2473 defer if (tuple.names.len == 0) gpa.free(field_name);
...@@ -2557,10 +2551,10 @@ pub const Object = struct {...@@ -2557,10 +2551,10 @@ pub const Object = struct {
2557 const field_offset = ty.structFieldOffset(field_index, mod);2551 const field_offset = ty.structFieldOffset(field_index, mod);
25582552
2559 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse2553 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
2560 try ip.getOrPutStringFmt(gpa, "{d}", .{field_index});2554 try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls);
25612555
2562 fields.appendAssumeCapacity(try o.builder.debugMemberType(2556 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2563 try o.builder.metadataString(ip.stringToSlice(field_name)),2557 try o.builder.metadataString(field_name.toSlice(ip)),
2564 .none, // File2558 .none, // File
2565 debug_fwd_ref,2559 debug_fwd_ref,
2566 0, // Line2560 0, // Line
...@@ -2655,7 +2649,7 @@ pub const Object = struct {...@@ -2655,7 +2649,7 @@ pub const Object = struct {
26552649
2656 const field_name = tag_type.names.get(ip)[field_index];2650 const field_name = tag_type.names.get(ip)[field_index];
2657 fields.appendAssumeCapacity(try o.builder.debugMemberType(2651 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2658 try o.builder.metadataString(ip.stringToSlice(field_name)),2652 try o.builder.metadataString(field_name.toSlice(ip)),
2659 .none, // File2653 .none, // File
2660 debug_union_fwd_ref,2654 debug_union_fwd_ref,
2661 0, // Line2655 0, // Line
...@@ -2827,7 +2821,7 @@ pub const Object = struct {...@@ -2827,7 +2821,7 @@ pub const Object = struct {
2827 const mod = o.module;2821 const mod = o.module;
2828 const decl = mod.declPtr(decl_index);2822 const decl = mod.declPtr(decl_index);
2829 return o.builder.debugStructType(2823 return o.builder.debugStructType(
2830 try o.builder.metadataString(mod.intern_pool.stringToSlice(decl.name)), // TODO use fully qualified name2824 try o.builder.metadataString(decl.name.toSlice(&mod.intern_pool)), // TODO use fully qualified name
2831 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),2825 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),
2832 try o.namespaceToDebugScope(decl.src_namespace),2826 try o.namespaceToDebugScope(decl.src_namespace),
2833 decl.src_line + 1,2827 decl.src_line + 1,
...@@ -2844,11 +2838,11 @@ pub const Object = struct {...@@ -2844,11 +2838,11 @@ pub const Object = struct {
2844 const std_mod = mod.std_mod;2838 const std_mod = mod.std_mod;
2845 const std_file = (mod.importPkg(std_mod) catch unreachable).file;2839 const std_file = (mod.importPkg(std_mod) catch unreachable).file;
28462840
2847 const builtin_str = try mod.intern_pool.getOrPutString(mod.gpa, "builtin");2841 const builtin_str = try mod.intern_pool.getOrPutString(mod.gpa, "builtin", .no_embedded_nulls);
2848 const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace);2842 const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace);
2849 const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = mod }).?;2843 const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = mod }).?;
28502844
2851 const stack_trace_str = try mod.intern_pool.getOrPutString(mod.gpa, "StackTrace");2845 const stack_trace_str = try mod.intern_pool.getOrPutString(mod.gpa, "StackTrace", .no_embedded_nulls);
2852 // buffer is only used for int_type, `builtin` is a struct.2846 // buffer is only used for int_type, `builtin` is a struct.
2853 const builtin_ty = mod.declPtr(builtin_decl).val.toType();2847 const builtin_ty = mod.declPtr(builtin_decl).val.toType();
2854 const builtin_namespace = mod.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(mod)).?;2848 const builtin_namespace = mod.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(mod)).?;
...@@ -2892,10 +2886,10 @@ pub const Object = struct {...@@ -2892,10 +2886,10 @@ pub const Object = struct {
2892 const is_extern = decl.isExtern(zcu);2886 const is_extern = decl.isExtern(zcu);
2893 const function_index = try o.builder.addFunction(2887 const function_index = try o.builder.addFunction(
2894 try o.lowerType(zig_fn_type),2888 try o.lowerType(zig_fn_type),
2895 try o.builder.strtabString(ip.stringToSlice(if (is_extern)2889 try o.builder.strtabString((if (is_extern)
2896 decl.name2890 decl.name
2897 else2891 else
2898 try decl.fullyQualifiedName(zcu))),2892 try decl.fullyQualifiedName(zcu)).toSlice(ip)),
2899 toLlvmAddressSpace(decl.@"addrspace", target),2893 toLlvmAddressSpace(decl.@"addrspace", target),
2900 );2894 );
2901 gop.value_ptr.* = function_index.ptrConst(&o.builder).global;2895 gop.value_ptr.* = function_index.ptrConst(&o.builder).global;
...@@ -2910,9 +2904,9 @@ pub const Object = struct {...@@ -2910,9 +2904,9 @@ pub const Object = struct {
2910 if (target.isWasm()) {2904 if (target.isWasm()) {
2911 try attributes.addFnAttr(.{ .string = .{2905 try attributes.addFnAttr(.{ .string = .{
2912 .kind = try o.builder.string("wasm-import-name"),2906 .kind = try o.builder.string("wasm-import-name"),
2913 .value = try o.builder.string(ip.stringToSlice(decl.name)),2907 .value = try o.builder.string(decl.name.toSlice(ip)),
2914 } }, &o.builder);2908 } }, &o.builder);
2915 if (ip.stringToSliceUnwrap(decl.getOwnedExternFunc(zcu).?.lib_name)) |lib_name| {2909 if (decl.getOwnedExternFunc(zcu).?.lib_name.toSlice(ip)) |lib_name| {
2916 if (!std.mem.eql(u8, lib_name, "c")) try attributes.addFnAttr(.{ .string = .{2910 if (!std.mem.eql(u8, lib_name, "c")) try attributes.addFnAttr(.{ .string = .{
2917 .kind = try o.builder.string("wasm-import-module"),2911 .kind = try o.builder.string("wasm-import-module"),
2918 .value = try o.builder.string(lib_name),2912 .value = try o.builder.string(lib_name),
...@@ -3108,9 +3102,10 @@ pub const Object = struct {...@@ -3108,9 +3102,10 @@ pub const Object = struct {
3108 const is_extern = decl.isExtern(mod);3102 const is_extern = decl.isExtern(mod);
31093103
3110 const variable_index = try o.builder.addVariable(3104 const variable_index = try o.builder.addVariable(
3111 try o.builder.strtabString(mod.intern_pool.stringToSlice(3105 try o.builder.strtabString((if (is_extern)
3112 if (is_extern) decl.name else try decl.fullyQualifiedName(mod),3106 decl.name
3113 )),3107 else
3108 try decl.fullyQualifiedName(mod)).toSlice(&mod.intern_pool)),
3114 try o.lowerType(decl.typeOf(mod)),3109 try o.lowerType(decl.typeOf(mod)),
3115 toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()),3110 toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()),
3116 );3111 );
...@@ -3258,7 +3253,7 @@ pub const Object = struct {...@@ -3258,7 +3253,7 @@ pub const Object = struct {
3258 };3253 };
3259 },3254 },
3260 .array_type => |array_type| o.builder.arrayType(3255 .array_type => |array_type| o.builder.arrayType(
3261 array_type.len + @intFromBool(array_type.sentinel != .none),3256 array_type.lenIncludingSentinel(),
3262 try o.lowerType(Type.fromInterned(array_type.child)),3257 try o.lowerType(Type.fromInterned(array_type.child)),
3263 ),3258 ),
3264 .vector_type => |vector_type| o.builder.vectorType(3259 .vector_type => |vector_type| o.builder.vectorType(
...@@ -3335,9 +3330,7 @@ pub const Object = struct {...@@ -3335,9 +3330,7 @@ pub const Object = struct {
3335 return int_ty;3330 return int_ty;
3336 }3331 }
33373332
3338 const name = try o.builder.string(ip.stringToSlice(3333 const fqn = try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(mod);
3339 try mod.declPtr(struct_type.decl.unwrap().?).fullyQualifiedName(mod),
3340 ));
33413334
3342 var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){};3335 var llvm_field_types = std.ArrayListUnmanaged(Builder.Type){};
3343 defer llvm_field_types.deinit(o.gpa);3336 defer llvm_field_types.deinit(o.gpa);
...@@ -3402,7 +3395,7 @@ pub const Object = struct {...@@ -3402,7 +3395,7 @@ pub const Object = struct {
3402 );3395 );
3403 }3396 }
34043397
3405 const ty = try o.builder.opaqueType(name);3398 const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3406 try o.type_map.put(o.gpa, t.toIntern(), ty);3399 try o.type_map.put(o.gpa, t.toIntern(), ty);
34073400
3408 o.builder.namedTypeSetBody(3401 o.builder.namedTypeSetBody(
...@@ -3491,9 +3484,7 @@ pub const Object = struct {...@@ -3491,9 +3484,7 @@ pub const Object = struct {
3491 return enum_tag_ty;3484 return enum_tag_ty;
3492 }3485 }
34933486
3494 const name = try o.builder.string(ip.stringToSlice(3487 const fqn = try mod.declPtr(union_obj.decl).fullyQualifiedName(mod);
3495 try mod.declPtr(union_obj.decl).fullyQualifiedName(mod),
3496 ));
34973488
3498 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);3489 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);
3499 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);3490 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);
...@@ -3513,7 +3504,7 @@ pub const Object = struct {...@@ -3513,7 +3504,7 @@ pub const Object = struct {
3513 };3504 };
35143505
3515 if (layout.tag_size == 0) {3506 if (layout.tag_size == 0) {
3516 const ty = try o.builder.opaqueType(name);3507 const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3517 try o.type_map.put(o.gpa, t.toIntern(), ty);3508 try o.type_map.put(o.gpa, t.toIntern(), ty);
35183509
3519 o.builder.namedTypeSetBody(3510 o.builder.namedTypeSetBody(
...@@ -3541,7 +3532,7 @@ pub const Object = struct {...@@ -3541,7 +3532,7 @@ pub const Object = struct {
3541 llvm_fields_len += 1;3532 llvm_fields_len += 1;
3542 }3533 }
35433534
3544 const ty = try o.builder.opaqueType(name);3535 const ty = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3545 try o.type_map.put(o.gpa, t.toIntern(), ty);3536 try o.type_map.put(o.gpa, t.toIntern(), ty);
35463537
3547 o.builder.namedTypeSetBody(3538 o.builder.namedTypeSetBody(
...@@ -3554,8 +3545,8 @@ pub const Object = struct {...@@ -3554,8 +3545,8 @@ pub const Object = struct {
3554 const gop = try o.type_map.getOrPut(o.gpa, t.toIntern());3545 const gop = try o.type_map.getOrPut(o.gpa, t.toIntern());
3555 if (!gop.found_existing) {3546 if (!gop.found_existing) {
3556 const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl);3547 const decl = mod.declPtr(ip.loadOpaqueType(t.toIntern()).decl);
3557 const name = try o.builder.string(ip.stringToSlice(try decl.fullyQualifiedName(mod)));3548 const fqn = try decl.fullyQualifiedName(mod);
3558 gop.value_ptr.* = try o.builder.opaqueType(name);3549 gop.value_ptr.* = try o.builder.opaqueType(try o.builder.string(fqn.toSlice(ip)));
3559 }3550 }
3560 return gop.value_ptr.*;3551 return gop.value_ptr.*;
3561 },3552 },
...@@ -3859,7 +3850,9 @@ pub const Object = struct {...@@ -3859,7 +3850,9 @@ pub const Object = struct {
3859 },3850 },
3860 .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) {3851 .aggregate => |aggregate| switch (ip.indexToKey(ty.toIntern())) {
3861 .array_type => |array_type| switch (aggregate.storage) {3852 .array_type => |array_type| switch (aggregate.storage) {
3862 .bytes => |bytes| try o.builder.stringConst(try o.builder.string(bytes)),3853 .bytes => |bytes| try o.builder.stringConst(try o.builder.string(
3854 bytes.toSlice(array_type.lenIncludingSentinel(), ip),
3855 )),
3863 .elems => |elems| {3856 .elems => |elems| {
3864 const array_ty = try o.lowerType(ty);3857 const array_ty = try o.lowerType(ty);
3865 const elem_ty = array_ty.childType(&o.builder);3858 const elem_ty = array_ty.childType(&o.builder);
...@@ -3892,8 +3885,7 @@ pub const Object = struct {...@@ -3892,8 +3885,7 @@ pub const Object = struct {
3892 },3885 },
3893 .repeated_elem => |elem| {3886 .repeated_elem => |elem| {
3894 const len: usize = @intCast(array_type.len);3887 const len: usize = @intCast(array_type.len);
3895 const len_including_sentinel: usize =3888 const len_including_sentinel: usize = @intCast(array_type.lenIncludingSentinel());
3896 @intCast(len + @intFromBool(array_type.sentinel != .none));
3897 const array_ty = try o.lowerType(ty);3889 const array_ty = try o.lowerType(ty);
3898 const elem_ty = array_ty.childType(&o.builder);3890 const elem_ty = array_ty.childType(&o.builder);
38993891
...@@ -3942,7 +3934,7 @@ pub const Object = struct {...@@ -3942,7 +3934,7 @@ pub const Object = struct {
3942 defer allocator.free(vals);3934 defer allocator.free(vals);
39433935
3944 switch (aggregate.storage) {3936 switch (aggregate.storage) {
3945 .bytes => |bytes| for (vals, bytes) |*result_val, byte| {3937 .bytes => |bytes| for (vals, bytes.toSlice(vector_type.len, ip)) |*result_val, byte| {
3946 result_val.* = try o.builder.intConst(.i8, byte);3938 result_val.* = try o.builder.intConst(.i8, byte);
3947 },3939 },
3948 .elems => |elems| for (vals, elems) |*result_val, elem| {3940 .elems => |elems| for (vals, elems) |*result_val, elem| {
...@@ -4633,7 +4625,7 @@ pub const Object = struct {...@@ -4633,7 +4625,7 @@ pub const Object = struct {
4633 defer wip_switch.finish(&wip);4625 defer wip_switch.finish(&wip);
46344626
4635 for (0..enum_type.names.len) |field_index| {4627 for (0..enum_type.names.len) |field_index| {
4636 const name = try o.builder.stringNull(ip.stringToSlice(enum_type.names.get(ip)[field_index]));4628 const name = try o.builder.stringNull(enum_type.names.get(ip)[field_index].toSlice(ip));
4637 const name_init = try o.builder.stringConst(name);4629 const name_init = try o.builder.stringConst(name);
4638 const name_variable_index =4630 const name_variable_index =
4639 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);4631 try o.builder.addVariable(.empty, name_init.typeOf(&o.builder), .default);
...@@ -4693,6 +4685,7 @@ pub const DeclGen = struct {...@@ -4693,6 +4685,7 @@ pub const DeclGen = struct {
4693 fn genDecl(dg: *DeclGen) !void {4685 fn genDecl(dg: *DeclGen) !void {
4694 const o = dg.object;4686 const o = dg.object;
4695 const zcu = o.module;4687 const zcu = o.module;
4688 const ip = &zcu.intern_pool;
4696 const decl = dg.decl;4689 const decl = dg.decl;
4697 const decl_index = dg.decl_index;4690 const decl_index = dg.decl_index;
4698 assert(decl.has_tv);4691 assert(decl.has_tv);
...@@ -4705,7 +4698,7 @@ pub const DeclGen = struct {...@@ -4705,7 +4698,7 @@ pub const DeclGen = struct {
4705 decl.getAlignment(zcu).toLlvm(),4698 decl.getAlignment(zcu).toLlvm(),
4706 &o.builder,4699 &o.builder,
4707 );4700 );
4708 if (zcu.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |section|4701 if (decl.@"linksection".toSlice(ip)) |section|
4709 variable_index.setSection(try o.builder.string(section), &o.builder);4702 variable_index.setSection(try o.builder.string(section), &o.builder);
4710 assert(decl.has_tv);4703 assert(decl.has_tv);
4711 const init_val = if (decl.val.getVariable(zcu)) |decl_var| decl_var.init else init_val: {4704 const init_val = if (decl.val.getVariable(zcu)) |decl_var| decl_var.init else init_val: {
...@@ -4728,7 +4721,7 @@ pub const DeclGen = struct {...@@ -4728,7 +4721,7 @@ pub const DeclGen = struct {
4728 const debug_file = try o.getDebugFile(namespace.file_scope);4721 const debug_file = try o.getDebugFile(namespace.file_scope);
47294722
4730 const debug_global_var = try o.builder.debugGlobalVar(4723 const debug_global_var = try o.builder.debugGlobalVar(
4731 try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)), // Name4724 try o.builder.metadataString(decl.name.toSlice(ip)), // Name
4732 try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name4725 try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder)), // Linkage name
4733 debug_file, // File4726 debug_file, // File
4734 debug_file, // Scope4727 debug_file, // Scope
...@@ -5156,8 +5149,8 @@ pub const FuncGen = struct {...@@ -5156,8 +5149,8 @@ pub const FuncGen = struct {
51565149
5157 self.scope = try o.builder.debugSubprogram(5150 self.scope = try o.builder.debugSubprogram(
5158 self.file,5151 self.file,
5159 try o.builder.metadataString(zcu.intern_pool.stringToSlice(decl.name)),5152 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)),
5160 try o.builder.metadataString(zcu.intern_pool.stringToSlice(fqn)),5153 try o.builder.metadataString(fqn.toSlice(&zcu.intern_pool)),
5161 line_number,5154 line_number,
5162 line_number + func.lbrace_line,5155 line_number + func.lbrace_line,
5163 try o.lowerDebugType(fn_ty),5156 try o.lowerDebugType(fn_ty),
src/codegen/spirv.zig+17-26
...@@ -1028,39 +1028,30 @@ const DeclGen = struct {...@@ -1028,39 +1028,30 @@ const DeclGen = struct {
1028 inline .array_type, .vector_type => |array_type, tag| {1028 inline .array_type, .vector_type => |array_type, tag| {
1029 const elem_ty = Type.fromInterned(array_type.child);1029 const elem_ty = Type.fromInterned(array_type.child);
10301030
1031 const constituents = try self.gpa.alloc(IdRef, @as(u32, @intCast(ty.arrayLenIncludingSentinel(mod))));1031 const constituents = try self.gpa.alloc(IdRef, @intCast(ty.arrayLenIncludingSentinel(mod)));
1032 defer self.gpa.free(constituents);1032 defer self.gpa.free(constituents);
10331033
1034 switch (aggregate.storage) {1034 switch (aggregate.storage) {
1035 .bytes => |bytes| {1035 .bytes => |bytes| {
1036 // TODO: This is really space inefficient, perhaps there is a better1036 // TODO: This is really space inefficient, perhaps there is a better
1037 // way to do it?1037 // way to do it?
1038 for (bytes, 0..) |byte, i| {1038 for (constituents, bytes.toSlice(constituents.len, ip)) |*constituent, byte| {
1039 constituents[i] = try self.constInt(elem_ty, byte, .indirect);1039 constituent.* = try self.constInt(elem_ty, byte, .indirect);
1040 }1040 }
1041 },1041 },
1042 .elems => |elems| {1042 .elems => |elems| {
1043 for (0..@as(usize, @intCast(array_type.len))) |i| {1043 for (constituents, elems) |*constituent, elem| {
1044 constituents[i] = try self.constant(elem_ty, Value.fromInterned(elems[i]), .indirect);1044 constituent.* = try self.constant(elem_ty, Value.fromInterned(elem), .indirect);
1045 }1045 }
1046 },1046 },
1047 .repeated_elem => |elem| {1047 .repeated_elem => |elem| {
1048 const val_id = try self.constant(elem_ty, Value.fromInterned(elem), .indirect);1048 @memset(constituents, try self.constant(elem_ty, Value.fromInterned(elem), .indirect));
1049 for (0..@as(usize, @intCast(array_type.len))) |i| {
1050 constituents[i] = val_id;
1051 }
1052 },1049 },
1053 }1050 }
10541051
1055 switch (tag) {1052 switch (tag) {
1056 inline .array_type => {1053 .array_type => return self.constructArray(ty, constituents),
1057 if (array_type.sentinel != .none) {1054 .vector_type => return self.constructVector(ty, constituents),
1058 const sentinel = Value.fromInterned(array_type.sentinel);
1059 constituents[constituents.len - 1] = try self.constant(elem_ty, sentinel, .indirect);
1060 }
1061 return self.constructArray(ty, constituents);
1062 },
1063 inline .vector_type => return self.constructVector(ty, constituents),
1064 else => unreachable,1055 else => unreachable,
1065 }1056 }
1066 },1057 },
...@@ -1683,9 +1674,9 @@ const DeclGen = struct {...@@ -1683,9 +1674,9 @@ const DeclGen = struct {
1683 }1674 }
16841675
1685 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse1676 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
1686 try ip.getOrPutStringFmt(mod.gpa, "{d}", .{field_index});1677 try ip.getOrPutStringFmt(mod.gpa, "{d}", .{field_index}, .no_embedded_nulls);
1687 try member_types.append(try self.resolveType(field_ty, .indirect));1678 try member_types.append(try self.resolveType(field_ty, .indirect));
1688 try member_names.append(ip.stringToSlice(field_name));1679 try member_names.append(field_name.toSlice(ip));
1689 }1680 }
16901681
1691 const result_id = try self.spv.structType(member_types.items, member_names.items);1682 const result_id = try self.spv.structType(member_types.items, member_names.items);
...@@ -2123,12 +2114,12 @@ const DeclGen = struct {...@@ -2123,12 +2114,12 @@ const DeclGen = struct {
2123 // Append the actual code into the functions section.2114 // Append the actual code into the functions section.
2124 try self.spv.addFunction(spv_decl_index, self.func);2115 try self.spv.addFunction(spv_decl_index, self.func);
21252116
2126 const fqn = ip.stringToSlice(try decl.fullyQualifiedName(self.module));2117 const fqn = try decl.fullyQualifiedName(self.module);
2127 try self.spv.debugName(result_id, fqn);2118 try self.spv.debugName(result_id, fqn.toSlice(ip));
21282119
2129 // Temporarily generate a test kernel declaration if this is a test function.2120 // Temporarily generate a test kernel declaration if this is a test function.
2130 if (self.module.test_functions.contains(self.decl_index)) {2121 if (self.module.test_functions.contains(self.decl_index)) {
2131 try self.generateTestEntryPoint(fqn, spv_decl_index);2122 try self.generateTestEntryPoint(fqn.toSlice(ip), spv_decl_index);
2132 }2123 }
2133 },2124 },
2134 .global => {2125 .global => {
...@@ -2152,8 +2143,8 @@ const DeclGen = struct {...@@ -2152,8 +2143,8 @@ const DeclGen = struct {
2152 .storage_class = final_storage_class,2143 .storage_class = final_storage_class,
2153 });2144 });
21542145
2155 const fqn = ip.stringToSlice(try decl.fullyQualifiedName(self.module));2146 const fqn = try decl.fullyQualifiedName(self.module);
2156 try self.spv.debugName(result_id, fqn);2147 try self.spv.debugName(result_id, fqn.toSlice(ip));
2157 try self.spv.declareDeclDeps(spv_decl_index, &.{});2148 try self.spv.declareDeclDeps(spv_decl_index, &.{});
2158 },2149 },
2159 .invocation_global => {2150 .invocation_global => {
...@@ -2197,8 +2188,8 @@ const DeclGen = struct {...@@ -2197,8 +2188,8 @@ const DeclGen = struct {
2197 try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {});2188 try self.func.body.emit(self.spv.gpa, .OpFunctionEnd, {});
2198 try self.spv.addFunction(spv_decl_index, self.func);2189 try self.spv.addFunction(spv_decl_index, self.func);
21992190
2200 const fqn = ip.stringToSlice(try decl.fullyQualifiedName(self.module));2191 const fqn = try decl.fullyQualifiedName(self.module);
2201 try self.spv.debugNameFmt(initializer_id, "initializer of {s}", .{fqn});2192 try self.spv.debugNameFmt(initializer_id, "initializer of {}", .{fqn.fmt(ip)});
22022193
2203 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{2194 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpExtInst, .{
2204 .id_result_type = ptr_ty_id,2195 .id_result_type = ptr_ty_id,
src/link/Coff.zig+23-25
...@@ -1176,9 +1176,9 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd...@@ -1176,9 +1176,9 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
1176 gop.value_ptr.* = .{};1176 gop.value_ptr.* = .{};
1177 }1177 }
1178 const unnamed_consts = gop.value_ptr;1178 const unnamed_consts = gop.value_ptr;
1179 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));1179 const decl_name = try decl.fullyQualifiedName(mod);
1180 const index = unnamed_consts.items.len;1180 const index = unnamed_consts.items.len;
1181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index });1181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1182 defer gpa.free(sym_name);1182 defer gpa.free(sym_name);
1183 const ty = val.typeOf(mod);1183 const ty = val.typeOf(mod);
1184 const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.srcLoc(mod))) {1184 const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.srcLoc(mod))) {
...@@ -1257,8 +1257,8 @@ pub fn updateDecl(...@@ -1257,8 +1257,8 @@ pub fn updateDecl(
1257 if (decl.isExtern(mod)) {1257 if (decl.isExtern(mod)) {
1258 // TODO make this part of getGlobalSymbol1258 // TODO make this part of getGlobalSymbol
1259 const variable = decl.getOwnedVariable(mod).?;1259 const variable = decl.getOwnedVariable(mod).?;
1260 const name = mod.intern_pool.stringToSlice(decl.name);1260 const name = decl.name.toSlice(&mod.intern_pool);
1261 const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);1261 const lib_name = variable.lib_name.toSlice(&mod.intern_pool);
1262 const global_index = try self.getGlobalSymbol(name, lib_name);1262 const global_index = try self.getGlobalSymbol(name, lib_name);
1263 try self.need_got_table.put(gpa, global_index, {});1263 try self.need_got_table.put(gpa, global_index, {});
1264 return;1264 return;
...@@ -1425,9 +1425,9 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com...@@ -1425,9 +1425,9 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com
1425 const mod = self.base.comp.module.?;1425 const mod = self.base.comp.module.?;
1426 const decl = mod.declPtr(decl_index);1426 const decl = mod.declPtr(decl_index);
14271427
1428 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));1428 const decl_name = try decl.fullyQualifiedName(mod);
14291429
1430 log.debug("updateDeclCode {s}{*}", .{ decl_name, decl });1430 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
1431 const required_alignment: u32 = @intCast(decl.getAlignment(mod).toByteUnits() orelse 0);1431 const required_alignment: u32 = @intCast(decl.getAlignment(mod).toByteUnits() orelse 0);
14321432
1433 const decl_metadata = self.decls.get(decl_index).?;1433 const decl_metadata = self.decls.get(decl_index).?;
...@@ -1439,7 +1439,7 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com...@@ -1439,7 +1439,7 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com
14391439
1440 if (atom.size != 0) {1440 if (atom.size != 0) {
1441 const sym = atom.getSymbolPtr(self);1441 const sym = atom.getSymbolPtr(self);
1442 try self.setSymbolName(sym, decl_name);1442 try self.setSymbolName(sym, decl_name.toSlice(&mod.intern_pool));
1443 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));1443 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
1444 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };1444 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
14451445
...@@ -1447,7 +1447,7 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com...@@ -1447,7 +1447,7 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com
1447 const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, sym.value, required_alignment);1447 const need_realloc = code.len > capacity or !mem.isAlignedGeneric(u64, sym.value, required_alignment);
1448 if (need_realloc) {1448 if (need_realloc) {
1449 const vaddr = try self.growAtom(atom_index, code_len, required_alignment);1449 const vaddr = try self.growAtom(atom_index, code_len, required_alignment);
1450 log.debug("growing {s} from 0x{x} to 0x{x}", .{ decl_name, sym.value, vaddr });1450 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), sym.value, vaddr });
1451 log.debug(" (required alignment 0x{x}", .{required_alignment});1451 log.debug(" (required alignment 0x{x}", .{required_alignment});
14521452
1453 if (vaddr != sym.value) {1453 if (vaddr != sym.value) {
...@@ -1463,13 +1463,13 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com...@@ -1463,13 +1463,13 @@ fn updateDeclCode(self: *Coff, decl_index: InternPool.DeclIndex, code: []u8, com
1463 self.getAtomPtr(atom_index).size = code_len;1463 self.getAtomPtr(atom_index).size = code_len;
1464 } else {1464 } else {
1465 const sym = atom.getSymbolPtr(self);1465 const sym = atom.getSymbolPtr(self);
1466 try self.setSymbolName(sym, decl_name);1466 try self.setSymbolName(sym, decl_name.toSlice(&mod.intern_pool));
1467 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));1467 sym.section_number = @as(coff.SectionNumber, @enumFromInt(sect_index + 1));
1468 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };1468 sym.type = .{ .complex_type = complex_type, .base_type = .NULL };
14691469
1470 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);1470 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);
1471 errdefer self.freeAtom(atom_index);1471 errdefer self.freeAtom(atom_index);
1472 log.debug("allocated atom for {s} at 0x{x}", .{ decl_name, vaddr });1472 log.debug("allocated atom for {} at 0x{x}", .{ decl_name.fmt(&mod.intern_pool), vaddr });
1473 self.getAtomPtr(atom_index).size = code_len;1473 self.getAtomPtr(atom_index).size = code_len;
1474 sym.value = vaddr;1474 sym.value = vaddr;
14751475
...@@ -1534,20 +1534,18 @@ pub fn updateExports(...@@ -1534,20 +1534,18 @@ pub fn updateExports(
1534 else => std.builtin.CallingConvention.C,1534 else => std.builtin.CallingConvention.C,
1535 };1535 };
1536 const decl_cc = exported_decl.typeOf(mod).fnCallingConvention(mod);1536 const decl_cc = exported_decl.typeOf(mod).fnCallingConvention(mod);
1537 if (decl_cc == .C and ip.stringEqlSlice(exp.opts.name, "main") and1537 if (decl_cc == .C and exp.opts.name.eqlSlice("main", ip) and comp.config.link_libc) {
1538 comp.config.link_libc)
1539 {
1540 mod.stage1_flags.have_c_main = true;1538 mod.stage1_flags.have_c_main = true;
1541 } else if (decl_cc == winapi_cc and target.os.tag == .windows) {1539 } else if (decl_cc == winapi_cc and target.os.tag == .windows) {
1542 if (ip.stringEqlSlice(exp.opts.name, "WinMain")) {1540 if (exp.opts.name.eqlSlice("WinMain", ip)) {
1543 mod.stage1_flags.have_winmain = true;1541 mod.stage1_flags.have_winmain = true;
1544 } else if (ip.stringEqlSlice(exp.opts.name, "wWinMain")) {1542 } else if (exp.opts.name.eqlSlice("wWinMain", ip)) {
1545 mod.stage1_flags.have_wwinmain = true;1543 mod.stage1_flags.have_wwinmain = true;
1546 } else if (ip.stringEqlSlice(exp.opts.name, "WinMainCRTStartup")) {1544 } else if (exp.opts.name.eqlSlice("WinMainCRTStartup", ip)) {
1547 mod.stage1_flags.have_winmain_crt_startup = true;1545 mod.stage1_flags.have_winmain_crt_startup = true;
1548 } else if (ip.stringEqlSlice(exp.opts.name, "wWinMainCRTStartup")) {1546 } else if (exp.opts.name.eqlSlice("wWinMainCRTStartup", ip)) {
1549 mod.stage1_flags.have_wwinmain_crt_startup = true;1547 mod.stage1_flags.have_wwinmain_crt_startup = true;
1550 } else if (ip.stringEqlSlice(exp.opts.name, "DllMainCRTStartup")) {1548 } else if (exp.opts.name.eqlSlice("DllMainCRTStartup", ip)) {
1551 mod.stage1_flags.have_dllmain_crt_startup = true;1549 mod.stage1_flags.have_dllmain_crt_startup = true;
1552 }1550 }
1553 }1551 }
...@@ -1585,7 +1583,7 @@ pub fn updateExports(...@@ -1585,7 +1583,7 @@ pub fn updateExports(
1585 for (exports) |exp| {1583 for (exports) |exp| {
1586 log.debug("adding new export '{}'", .{exp.opts.name.fmt(&mod.intern_pool)});1584 log.debug("adding new export '{}'", .{exp.opts.name.fmt(&mod.intern_pool)});
15871585
1588 if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section_name| {1586 if (exp.opts.section.toSlice(&mod.intern_pool)) |section_name| {
1589 if (!mem.eql(u8, section_name, ".text")) {1587 if (!mem.eql(u8, section_name, ".text")) {
1590 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(1588 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
1591 gpa,1589 gpa,
...@@ -1607,7 +1605,7 @@ pub fn updateExports(...@@ -1607,7 +1605,7 @@ pub fn updateExports(
1607 continue;1605 continue;
1608 }1606 }
16091607
1610 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);1608 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1611 const sym_index = metadata.getExport(self, exp_name) orelse blk: {1609 const sym_index = metadata.getExport(self, exp_name) orelse blk: {
1612 const sym_index = if (self.getGlobalIndex(exp_name)) |global_index| ind: {1610 const sym_index = if (self.getGlobalIndex(exp_name)) |global_index| ind: {
1613 const global = self.globals.items[global_index];1611 const global = self.globals.items[global_index];
...@@ -1646,18 +1644,18 @@ pub fn updateExports(...@@ -1646,18 +1644,18 @@ pub fn updateExports(
1646pub fn deleteDeclExport(1644pub fn deleteDeclExport(
1647 self: *Coff,1645 self: *Coff,
1648 decl_index: InternPool.DeclIndex,1646 decl_index: InternPool.DeclIndex,
1649 name_ip: InternPool.NullTerminatedString,1647 name: InternPool.NullTerminatedString,
1650) void {1648) void {
1651 if (self.llvm_object) |_| return;1649 if (self.llvm_object) |_| return;
1652 const metadata = self.decls.getPtr(decl_index) orelse return;1650 const metadata = self.decls.getPtr(decl_index) orelse return;
1653 const mod = self.base.comp.module.?;1651 const mod = self.base.comp.module.?;
1654 const name = mod.intern_pool.stringToSlice(name_ip);1652 const name_slice = name.toSlice(&mod.intern_pool);
1655 const sym_index = metadata.getExportPtr(self, name) orelse return;1653 const sym_index = metadata.getExportPtr(self, name_slice) orelse return;
16561654
1657 const gpa = self.base.comp.gpa;1655 const gpa = self.base.comp.gpa;
1658 const sym_loc = SymbolWithLoc{ .sym_index = sym_index.*, .file = null };1656 const sym_loc = SymbolWithLoc{ .sym_index = sym_index.*, .file = null };
1659 const sym = self.getSymbolPtr(sym_loc);1657 const sym = self.getSymbolPtr(sym_loc);
1660 log.debug("deleting export '{s}'", .{name});1658 log.debug("deleting export '{}'", .{name.fmt(&mod.intern_pool)});
1661 assert(sym.storage_class == .EXTERNAL and sym.section_number != .UNDEFINED);1659 assert(sym.storage_class == .EXTERNAL and sym.section_number != .UNDEFINED);
1662 sym.* = .{1660 sym.* = .{
1663 .name = [_]u8{0} ** 8,1661 .name = [_]u8{0} ** 8,
...@@ -1669,7 +1667,7 @@ pub fn deleteDeclExport(...@@ -1669,7 +1667,7 @@ pub fn deleteDeclExport(
1669 };1667 };
1670 self.locals_free_list.append(gpa, sym_index.*) catch {};1668 self.locals_free_list.append(gpa, sym_index.*) catch {};
16711669
1672 if (self.resolver.fetchRemove(name)) |entry| {1670 if (self.resolver.fetchRemove(name_slice)) |entry| {
1673 defer gpa.free(entry.key);1671 defer gpa.free(entry.key);
1674 self.globals_free_list.append(gpa, entry.value) catch {};1672 self.globals_free_list.append(gpa, entry.value) catch {};
1675 self.globals.items[entry.value] = .{1673 self.globals.items[entry.value] = .{
src/link/Dwarf.zig+17-20
...@@ -339,15 +339,14 @@ pub const DeclState = struct {...@@ -339,15 +339,14 @@ pub const DeclState = struct {
339 struct_type.field_names.get(ip),339 struct_type.field_names.get(ip),
340 struct_type.field_types.get(ip),340 struct_type.field_types.get(ip),
341 struct_type.offsets.get(ip),341 struct_type.offsets.get(ip),
342 ) |field_name_ip, field_ty, field_off| {342 ) |field_name, field_ty, field_off| {
343 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;343 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
344 const field_name = ip.stringToSlice(field_name_ip);344 const field_name_slice = field_name.toSlice(ip);
345 // DW.AT.member345 // DW.AT.member
346 try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2);346 try dbg_info_buffer.ensureUnusedCapacity(field_name_slice.len + 2);
347 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.struct_member));347 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.struct_member));
348 // DW.AT.name, DW.FORM.string348 // DW.AT.name, DW.FORM.string
349 dbg_info_buffer.appendSliceAssumeCapacity(field_name);349 dbg_info_buffer.appendSliceAssumeCapacity(field_name_slice[0 .. field_name_slice.len + 1]);
350 dbg_info_buffer.appendAssumeCapacity(0);
351 // DW.AT.type, DW.FORM.ref4350 // DW.AT.type, DW.FORM.ref4
352 const index = dbg_info_buffer.items.len;351 const index = dbg_info_buffer.items.len;
353 try dbg_info_buffer.appendNTimes(0, 4);352 try dbg_info_buffer.appendNTimes(0, 4);
...@@ -374,14 +373,13 @@ pub const DeclState = struct {...@@ -374,14 +373,13 @@ pub const DeclState = struct {
374 try dbg_info_buffer.append(0);373 try dbg_info_buffer.append(0);
375374
376 const enum_type = ip.loadEnumType(ty.ip_index);375 const enum_type = ip.loadEnumType(ty.ip_index);
377 for (enum_type.names.get(ip), 0..) |field_name_index, field_i| {376 for (enum_type.names.get(ip), 0..) |field_name, field_i| {
378 const field_name = ip.stringToSlice(field_name_index);377 const field_name_slice = field_name.toSlice(ip);
379 // DW.AT.enumerator378 // DW.AT.enumerator
380 try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2 + @sizeOf(u64));379 try dbg_info_buffer.ensureUnusedCapacity(field_name_slice.len + 2 + @sizeOf(u64));
381 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.enum_variant));380 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.enum_variant));
382 // DW.AT.name, DW.FORM.string381 // DW.AT.name, DW.FORM.string
383 dbg_info_buffer.appendSliceAssumeCapacity(field_name);382 dbg_info_buffer.appendSliceAssumeCapacity(field_name_slice[0 .. field_name_slice.len + 1]);
384 dbg_info_buffer.appendAssumeCapacity(0);
385 // DW.AT.const_value, DW.FORM.data8383 // DW.AT.const_value, DW.FORM.data8
386 const value: u64 = value: {384 const value: u64 = value: {
387 if (enum_type.values.len == 0) break :value field_i; // auto-numbered385 if (enum_type.values.len == 0) break :value field_i; // auto-numbered
...@@ -443,11 +441,11 @@ pub const DeclState = struct {...@@ -443,11 +441,11 @@ pub const DeclState = struct {
443441
444 for (union_obj.field_types.get(ip), union_obj.loadTagType(ip).names.get(ip)) |field_ty, field_name| {442 for (union_obj.field_types.get(ip), union_obj.loadTagType(ip).names.get(ip)) |field_ty, field_name| {
445 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;443 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
444 const field_name_slice = field_name.toSlice(ip);
446 // DW.AT.member445 // DW.AT.member
447 try dbg_info_buffer.append(@intFromEnum(AbbrevCode.struct_member));446 try dbg_info_buffer.append(@intFromEnum(AbbrevCode.struct_member));
448 // DW.AT.name, DW.FORM.string447 // DW.AT.name, DW.FORM.string
449 try dbg_info_buffer.appendSlice(ip.stringToSlice(field_name));448 try dbg_info_buffer.appendSlice(field_name_slice[0 .. field_name_slice.len + 1]);
450 try dbg_info_buffer.append(0);
451 // DW.AT.type, DW.FORM.ref4449 // DW.AT.type, DW.FORM.ref4
452 const index = dbg_info_buffer.items.len;450 const index = dbg_info_buffer.items.len;
453 try dbg_info_buffer.appendNTimes(0, 4);451 try dbg_info_buffer.appendNTimes(0, 4);
...@@ -1155,8 +1153,8 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde...@@ -1155,8 +1153,8 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde
1155 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);1153 dbg_line_buffer.appendAssumeCapacity(DW.LNS.copy);
11561154
1157 // .debug_info subprogram1155 // .debug_info subprogram
1158 const decl_name_slice = mod.intern_pool.stringToSlice(decl.name);1156 const decl_name_slice = decl.name.toSlice(&mod.intern_pool);
1159 const decl_linkage_name_slice = mod.intern_pool.stringToSlice(decl_linkage_name);1157 const decl_linkage_name_slice = decl_linkage_name.toSlice(&mod.intern_pool);
1160 try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +1158 try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +
1161 (decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1));1159 (decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1));
11621160
...@@ -2866,15 +2864,14 @@ fn addDbgInfoErrorSetNames(...@@ -2866,15 +2864,14 @@ fn addDbgInfoErrorSetNames(
2866 // DW.AT.const_value, DW.FORM.data82864 // DW.AT.const_value, DW.FORM.data8
2867 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), 0, target_endian);2865 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), 0, target_endian);
28682866
2869 for (error_names) |error_name_ip| {2867 for (error_names) |error_name| {
2870 const int = try mod.getErrorValue(error_name_ip);2868 const int = try mod.getErrorValue(error_name);
2871 const error_name = mod.intern_pool.stringToSlice(error_name_ip);2869 const error_name_slice = error_name.toSlice(&mod.intern_pool);
2872 // DW.AT.enumerator2870 // DW.AT.enumerator
2873 try dbg_info_buffer.ensureUnusedCapacity(error_name.len + 2 + @sizeOf(u64));2871 try dbg_info_buffer.ensureUnusedCapacity(error_name_slice.len + 2 + @sizeOf(u64));
2874 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.enum_variant));2872 dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevCode.enum_variant));
2875 // DW.AT.name, DW.FORM.string2873 // DW.AT.name, DW.FORM.string
2876 dbg_info_buffer.appendSliceAssumeCapacity(error_name);2874 dbg_info_buffer.appendSliceAssumeCapacity(error_name_slice[0 .. error_name_slice.len + 1]);
2877 dbg_info_buffer.appendAssumeCapacity(0);
2878 // DW.AT.const_value, DW.FORM.data82875 // DW.AT.const_value, DW.FORM.data8
2879 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), int, target_endian);2876 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), int, target_endian);
2880 }2877 }
src/link/Elf/ZigObject.zig+16-16
...@@ -902,9 +902,9 @@ fn updateDeclCode(...@@ -902,9 +902,9 @@ fn updateDeclCode(
902 const gpa = elf_file.base.comp.gpa;902 const gpa = elf_file.base.comp.gpa;
903 const mod = elf_file.base.comp.module.?;903 const mod = elf_file.base.comp.module.?;
904 const decl = mod.declPtr(decl_index);904 const decl = mod.declPtr(decl_index);
905 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));905 const decl_name = try decl.fullyQualifiedName(mod);
906906
907 log.debug("updateDeclCode {s}{*}", .{ decl_name, decl });907 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
908908
909 const required_alignment = decl.getAlignment(mod);909 const required_alignment = decl.getAlignment(mod);
910910
...@@ -915,7 +915,7 @@ fn updateDeclCode(...@@ -915,7 +915,7 @@ fn updateDeclCode(
915 sym.output_section_index = shdr_index;915 sym.output_section_index = shdr_index;
916 atom_ptr.output_section_index = shdr_index;916 atom_ptr.output_section_index = shdr_index;
917917
918 sym.name_offset = try self.strtab.insert(gpa, decl_name);918 sym.name_offset = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool));
919 atom_ptr.flags.alive = true;919 atom_ptr.flags.alive = true;
920 atom_ptr.name_offset = sym.name_offset;920 atom_ptr.name_offset = sym.name_offset;
921 esym.st_name = sym.name_offset;921 esym.st_name = sym.name_offset;
...@@ -932,7 +932,7 @@ fn updateDeclCode(...@@ -932,7 +932,7 @@ fn updateDeclCode(
932 const need_realloc = code.len > capacity or !required_alignment.check(atom_ptr.value);932 const need_realloc = code.len > capacity or !required_alignment.check(atom_ptr.value);
933 if (need_realloc) {933 if (need_realloc) {
934 try atom_ptr.grow(elf_file);934 try atom_ptr.grow(elf_file);
935 log.debug("growing {s} from 0x{x} to 0x{x}", .{ decl_name, old_vaddr, atom_ptr.value });935 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), old_vaddr, atom_ptr.value });
936 if (old_vaddr != atom_ptr.value) {936 if (old_vaddr != atom_ptr.value) {
937 sym.value = 0;937 sym.value = 0;
938 esym.st_value = 0;938 esym.st_value = 0;
...@@ -1000,9 +1000,9 @@ fn updateTlv(...@@ -1000,9 +1000,9 @@ fn updateTlv(
1000 const gpa = elf_file.base.comp.gpa;1000 const gpa = elf_file.base.comp.gpa;
1001 const mod = elf_file.base.comp.module.?;1001 const mod = elf_file.base.comp.module.?;
1002 const decl = mod.declPtr(decl_index);1002 const decl = mod.declPtr(decl_index);
1003 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));1003 const decl_name = try decl.fullyQualifiedName(mod);
10041004
1005 log.debug("updateTlv {s} ({*})", .{ decl_name, decl });1005 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl });
10061006
1007 const required_alignment = decl.getAlignment(mod);1007 const required_alignment = decl.getAlignment(mod);
10081008
...@@ -1014,7 +1014,7 @@ fn updateTlv(...@@ -1014,7 +1014,7 @@ fn updateTlv(
1014 sym.output_section_index = shndx;1014 sym.output_section_index = shndx;
1015 atom_ptr.output_section_index = shndx;1015 atom_ptr.output_section_index = shndx;
10161016
1017 sym.name_offset = try self.strtab.insert(gpa, decl_name);1017 sym.name_offset = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool));
1018 atom_ptr.flags.alive = true;1018 atom_ptr.flags.alive = true;
1019 atom_ptr.name_offset = sym.name_offset;1019 atom_ptr.name_offset = sym.name_offset;
1020 esym.st_value = 0;1020 esym.st_value = 0;
...@@ -1136,8 +1136,8 @@ pub fn updateDecl(...@@ -1136,8 +1136,8 @@ pub fn updateDecl(
1136 if (decl.isExtern(mod)) {1136 if (decl.isExtern(mod)) {
1137 // Extern variable gets a .got entry only.1137 // Extern variable gets a .got entry only.
1138 const variable = decl.getOwnedVariable(mod).?;1138 const variable = decl.getOwnedVariable(mod).?;
1139 const name = mod.intern_pool.stringToSlice(decl.name);1139 const name = decl.name.toSlice(&mod.intern_pool);
1140 const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);1140 const lib_name = variable.lib_name.toSlice(&mod.intern_pool);
1141 const esym_index = try self.getGlobalSymbol(elf_file, name, lib_name);1141 const esym_index = try self.getGlobalSymbol(elf_file, name, lib_name);
1142 elf_file.symbol(self.symbol(esym_index)).flags.needs_got = true;1142 elf_file.symbol(self.symbol(esym_index)).flags.needs_got = true;
1143 return;1143 return;
...@@ -1293,9 +1293,9 @@ pub fn lowerUnnamedConst(...@@ -1293,9 +1293,9 @@ pub fn lowerUnnamedConst(
1293 }1293 }
1294 const unnamed_consts = gop.value_ptr;1294 const unnamed_consts = gop.value_ptr;
1295 const decl = mod.declPtr(decl_index);1295 const decl = mod.declPtr(decl_index);
1296 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));1296 const decl_name = try decl.fullyQualifiedName(mod);
1297 const index = unnamed_consts.items.len;1297 const index = unnamed_consts.items.len;
1298 const name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index });1298 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1299 defer gpa.free(name);1299 defer gpa.free(name);
1300 const ty = val.typeOf(mod);1300 const ty = val.typeOf(mod);
1301 const sym_index = switch (try self.lowerConst(1301 const sym_index = switch (try self.lowerConst(
...@@ -1418,7 +1418,7 @@ pub fn updateExports(...@@ -1418,7 +1418,7 @@ pub fn updateExports(
14181418
1419 for (exports) |exp| {1419 for (exports) |exp| {
1420 if (exp.opts.section.unwrap()) |section_name| {1420 if (exp.opts.section.unwrap()) |section_name| {
1421 if (!mod.intern_pool.stringEqlSlice(section_name, ".text")) {1421 if (!section_name.eqlSlice(".text", &mod.intern_pool)) {
1422 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1422 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1423 mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(1423 mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(
1424 gpa,1424 gpa,
...@@ -1445,7 +1445,7 @@ pub fn updateExports(...@@ -1445,7 +1445,7 @@ pub fn updateExports(
1445 },1445 },
1446 };1446 };
1447 const stt_bits: u8 = @as(u4, @truncate(esym.st_info));1447 const stt_bits: u8 = @as(u4, @truncate(esym.st_info));
1448 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);1448 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1449 const name_off = try self.strtab.insert(gpa, exp_name);1449 const name_off = try self.strtab.insert(gpa, exp_name);
1450 const global_esym_index = if (metadata.@"export"(self, exp_name)) |exp_index|1450 const global_esym_index = if (metadata.@"export"(self, exp_name)) |exp_index|
1451 exp_index.*1451 exp_index.*
...@@ -1476,9 +1476,9 @@ pub fn updateDeclLineNumber(...@@ -1476,9 +1476,9 @@ pub fn updateDeclLineNumber(
1476 defer tracy.end();1476 defer tracy.end();
14771477
1478 const decl = mod.declPtr(decl_index);1478 const decl = mod.declPtr(decl_index);
1479 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));1479 const decl_name = try decl.fullyQualifiedName(mod);
14801480
1481 log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl });1481 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
14821482
1483 if (self.dwarf) |*dw| {1483 if (self.dwarf) |*dw| {
1484 try dw.updateDeclLineNumber(mod, decl_index);1484 try dw.updateDeclLineNumber(mod, decl_index);
...@@ -1493,7 +1493,7 @@ pub fn deleteDeclExport(...@@ -1493,7 +1493,7 @@ pub fn deleteDeclExport(
1493) void {1493) void {
1494 const metadata = self.decls.getPtr(decl_index) orelse return;1494 const metadata = self.decls.getPtr(decl_index) orelse return;
1495 const mod = elf_file.base.comp.module.?;1495 const mod = elf_file.base.comp.module.?;
1496 const exp_name = mod.intern_pool.stringToSlice(name);1496 const exp_name = name.toSlice(&mod.intern_pool);
1497 const esym_index = metadata.@"export"(self, exp_name) orelse return;1497 const esym_index = metadata.@"export"(self, exp_name) orelse return;
1498 log.debug("deleting export '{s}'", .{exp_name});1498 log.debug("deleting export '{s}'", .{exp_name});
1499 const esym = &self.global_esyms.items(.elf_sym)[esym_index.*];1499 const esym = &self.global_esyms.items(.elf_sym)[esym_index.*];
src/link/MachO/ZigObject.zig+19-19
...@@ -716,8 +716,8 @@ pub fn updateDecl(...@@ -716,8 +716,8 @@ pub fn updateDecl(
716 if (decl.isExtern(mod)) {716 if (decl.isExtern(mod)) {
717 // Extern variable gets a __got entry only717 // Extern variable gets a __got entry only
718 const variable = decl.getOwnedVariable(mod).?;718 const variable = decl.getOwnedVariable(mod).?;
719 const name = mod.intern_pool.stringToSlice(decl.name);719 const name = decl.name.toSlice(&mod.intern_pool);
720 const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);720 const lib_name = variable.lib_name.toSlice(&mod.intern_pool);
721 const index = try self.getGlobalSymbol(macho_file, name, lib_name);721 const index = try self.getGlobalSymbol(macho_file, name, lib_name);
722 const actual_index = self.symbols.items[index];722 const actual_index = self.symbols.items[index];
723 macho_file.getSymbol(actual_index).flags.needs_got = true;723 macho_file.getSymbol(actual_index).flags.needs_got = true;
...@@ -786,9 +786,9 @@ fn updateDeclCode(...@@ -786,9 +786,9 @@ fn updateDeclCode(
786 const gpa = macho_file.base.comp.gpa;786 const gpa = macho_file.base.comp.gpa;
787 const mod = macho_file.base.comp.module.?;787 const mod = macho_file.base.comp.module.?;
788 const decl = mod.declPtr(decl_index);788 const decl = mod.declPtr(decl_index);
789 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));789 const decl_name = try decl.fullyQualifiedName(mod);
790790
791 log.debug("updateDeclCode {s}{*}", .{ decl_name, decl });791 log.debug("updateDeclCode {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
792792
793 const required_alignment = decl.getAlignment(mod);793 const required_alignment = decl.getAlignment(mod);
794794
...@@ -800,7 +800,7 @@ fn updateDeclCode(...@@ -800,7 +800,7 @@ fn updateDeclCode(
800 sym.out_n_sect = sect_index;800 sym.out_n_sect = sect_index;
801 atom.out_n_sect = sect_index;801 atom.out_n_sect = sect_index;
802802
803 sym.name = try self.strtab.insert(gpa, decl_name);803 sym.name = try self.strtab.insert(gpa, decl_name.toSlice(&mod.intern_pool));
804 atom.flags.alive = true;804 atom.flags.alive = true;
805 atom.name = sym.name;805 atom.name = sym.name;
806 nlist.n_strx = sym.name;806 nlist.n_strx = sym.name;
...@@ -819,7 +819,7 @@ fn updateDeclCode(...@@ -819,7 +819,7 @@ fn updateDeclCode(
819819
820 if (need_realloc) {820 if (need_realloc) {
821 try atom.grow(macho_file);821 try atom.grow(macho_file);
822 log.debug("growing {s} from 0x{x} to 0x{x}", .{ decl_name, old_vaddr, atom.value });822 log.debug("growing {} from 0x{x} to 0x{x}", .{ decl_name.fmt(&mod.intern_pool), old_vaddr, atom.value });
823 if (old_vaddr != atom.value) {823 if (old_vaddr != atom.value) {
824 sym.value = 0;824 sym.value = 0;
825 nlist.n_value = 0;825 nlist.n_value = 0;
...@@ -870,23 +870,24 @@ fn updateTlv(...@@ -870,23 +870,24 @@ fn updateTlv(
870) !void {870) !void {
871 const mod = macho_file.base.comp.module.?;871 const mod = macho_file.base.comp.module.?;
872 const decl = mod.declPtr(decl_index);872 const decl = mod.declPtr(decl_index);
873 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));873 const decl_name = try decl.fullyQualifiedName(mod);
874874
875 log.debug("updateTlv {s} ({*})", .{ decl_name, decl });875 log.debug("updateTlv {} ({*})", .{ decl_name.fmt(&mod.intern_pool), decl });
876876
877 const decl_name_slice = decl_name.toSlice(&mod.intern_pool);
877 const required_alignment = decl.getAlignment(mod);878 const required_alignment = decl.getAlignment(mod);
878879
879 // 1. Lower TLV initializer880 // 1. Lower TLV initializer
880 const init_sym_index = try self.createTlvInitializer(881 const init_sym_index = try self.createTlvInitializer(
881 macho_file,882 macho_file,
882 decl_name,883 decl_name_slice,
883 required_alignment,884 required_alignment,
884 sect_index,885 sect_index,
885 code,886 code,
886 );887 );
887888
888 // 2. Create TLV descriptor889 // 2. Create TLV descriptor
889 try self.createTlvDescriptor(macho_file, sym_index, init_sym_index, decl_name);890 try self.createTlvDescriptor(macho_file, sym_index, init_sym_index, decl_name_slice);
890}891}
891892
892fn createTlvInitializer(893fn createTlvInitializer(
...@@ -1073,9 +1074,9 @@ pub fn lowerUnnamedConst(...@@ -1073,9 +1074,9 @@ pub fn lowerUnnamedConst(
1073 }1074 }
1074 const unnamed_consts = gop.value_ptr;1075 const unnamed_consts = gop.value_ptr;
1075 const decl = mod.declPtr(decl_index);1076 const decl = mod.declPtr(decl_index);
1076 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));1077 const decl_name = try decl.fullyQualifiedName(mod);
1077 const index = unnamed_consts.items.len;1078 const index = unnamed_consts.items.len;
1078 const name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index });1079 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1079 defer gpa.free(name);1080 defer gpa.free(name);
1080 const sym_index = switch (try self.lowerConst(1081 const sym_index = switch (try self.lowerConst(
1081 macho_file,1082 macho_file,
...@@ -1199,7 +1200,7 @@ pub fn updateExports(...@@ -1199,7 +1200,7 @@ pub fn updateExports(
11991200
1200 for (exports) |exp| {1201 for (exports) |exp| {
1201 if (exp.opts.section.unwrap()) |section_name| {1202 if (exp.opts.section.unwrap()) |section_name| {
1202 if (!mod.intern_pool.stringEqlSlice(section_name, "__text")) {1203 if (!section_name.eqlSlice("__text", &mod.intern_pool)) {
1203 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1204 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1204 mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(1205 mod.failed_exports.putAssumeCapacityNoClobber(exp, try Module.ErrorMsg.create(
1205 gpa,1206 gpa,
...@@ -1220,7 +1221,7 @@ pub fn updateExports(...@@ -1220,7 +1221,7 @@ pub fn updateExports(
1220 continue;1221 continue;
1221 }1222 }
12221223
1223 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);1224 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1224 const global_nlist_index = if (metadata.@"export"(self, exp_name)) |exp_index|1225 const global_nlist_index = if (metadata.@"export"(self, exp_name)) |exp_index|
1225 exp_index.*1226 exp_index.*
1226 else blk: {1227 else blk: {
...@@ -1349,13 +1350,12 @@ pub fn deleteDeclExport(...@@ -1349,13 +1350,12 @@ pub fn deleteDeclExport(
1349 decl_index: InternPool.DeclIndex,1350 decl_index: InternPool.DeclIndex,
1350 name: InternPool.NullTerminatedString,1351 name: InternPool.NullTerminatedString,
1351) void {1352) void {
1352 const metadata = self.decls.getPtr(decl_index) orelse return;
1353
1354 const mod = macho_file.base.comp.module.?;1353 const mod = macho_file.base.comp.module.?;
1355 const exp_name = mod.intern_pool.stringToSlice(name);
1356 const nlist_index = metadata.@"export"(self, exp_name) orelse return;
13571354
1358 log.debug("deleting export '{s}'", .{exp_name});1355 const metadata = self.decls.getPtr(decl_index) orelse return;
1356 const nlist_index = metadata.@"export"(self, name.toSlice(&mod.intern_pool)) orelse return;
1357
1358 log.debug("deleting export '{}'", .{name.fmt(&mod.intern_pool)});
13591359
1360 const nlist = &self.symtab.items(.nlist)[nlist_index.*];1360 const nlist = &self.symtab.items(.nlist)[nlist_index.*];
1361 self.symtab.items(.size)[nlist_index.*] = 0;1361 self.symtab.items(.size)[nlist_index.*] = 0;
src/link/Plan9.zig+23-19
...@@ -477,11 +477,11 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn...@@ -477,11 +477,11 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
477 }477 }
478 const unnamed_consts = gop.value_ptr;478 const unnamed_consts = gop.value_ptr;
479479
480 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));480 const decl_name = try decl.fullyQualifiedName(mod);
481481
482 const index = unnamed_consts.items.len;482 const index = unnamed_consts.items.len;
483 // name is freed when the unnamed const is freed483 // name is freed when the unnamed const is freed
484 const name = try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index });484 const name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
485485
486 const sym_index = try self.allocateSymbolIndex();486 const sym_index = try self.allocateSymbolIndex();
487 const new_atom_idx = try self.createAtom();487 const new_atom_idx = try self.createAtom();
...@@ -529,7 +529,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)...@@ -529,7 +529,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
529 const decl = mod.declPtr(decl_index);529 const decl = mod.declPtr(decl_index);
530530
531 if (decl.isExtern(mod)) {531 if (decl.isExtern(mod)) {
532 log.debug("found extern decl: {s}", .{mod.intern_pool.stringToSlice(decl.name)});532 log.debug("found extern decl: {}", .{decl.name.fmt(&mod.intern_pool)});
533 return;533 return;
534 }534 }
535 const atom_idx = try self.seeDecl(decl_index);535 const atom_idx = try self.seeDecl(decl_index);
...@@ -573,7 +573,7 @@ fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void {...@@ -573,7 +573,7 @@ fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void {
573 const sym: aout.Sym = .{573 const sym: aout.Sym = .{
574 .value = undefined, // the value of stuff gets filled in in flushModule574 .value = undefined, // the value of stuff gets filled in in flushModule
575 .type = atom.type,575 .type = atom.type,
576 .name = try gpa.dupe(u8, mod.intern_pool.stringToSlice(decl.name)),576 .name = try gpa.dupe(u8, decl.name.toSlice(&mod.intern_pool)),
577 };577 };
578578
579 if (atom.sym_index) |s| {579 if (atom.sym_index) |s| {
...@@ -1013,10 +1013,12 @@ fn addDeclExports(...@@ -1013,10 +1013,12 @@ fn addDeclExports(
1013 const atom = self.getAtom(metadata.index);1013 const atom = self.getAtom(metadata.index);
10141014
1015 for (exports) |exp| {1015 for (exports) |exp| {
1016 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);1016 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1017 // plan9 does not support custom sections1017 // plan9 does not support custom sections
1018 if (exp.opts.section.unwrap()) |section_name| {1018 if (exp.opts.section.unwrap()) |section_name| {
1019 if (!mod.intern_pool.stringEqlSlice(section_name, ".text") and !mod.intern_pool.stringEqlSlice(section_name, ".data")) {1019 if (!section_name.eqlSlice(".text", &mod.intern_pool) and
1020 !section_name.eqlSlice(".data", &mod.intern_pool))
1021 {
1020 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(1022 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
1021 gpa,1023 gpa,
1022 mod.declPtr(decl_index).srcLoc(mod),1024 mod.declPtr(decl_index).srcLoc(mod),
...@@ -1129,19 +1131,21 @@ pub fn seeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) !Atom.Index {...@@ -1129,19 +1131,21 @@ pub fn seeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) !Atom.Index {
1129 // handle externs here because they might not get updateDecl called on them1131 // handle externs here because they might not get updateDecl called on them
1130 const mod = self.base.comp.module.?;1132 const mod = self.base.comp.module.?;
1131 const decl = mod.declPtr(decl_index);1133 const decl = mod.declPtr(decl_index);
1132 const name = mod.intern_pool.stringToSlice(decl.name);
1133 if (decl.isExtern(mod)) {1134 if (decl.isExtern(mod)) {
1134 // this is a "phantom atom" - it is never actually written to disk, just convenient for us to store stuff about externs1135 // this is a "phantom atom" - it is never actually written to disk, just convenient for us to store stuff about externs
1135 if (std.mem.eql(u8, name, "etext")) {1136 if (decl.name.eqlSlice("etext", &mod.intern_pool)) {
1136 self.etext_edata_end_atom_indices[0] = atom_idx;1137 self.etext_edata_end_atom_indices[0] = atom_idx;
1137 } else if (std.mem.eql(u8, name, "edata")) {1138 } else if (decl.name.eqlSlice("edata", &mod.intern_pool)) {
1138 self.etext_edata_end_atom_indices[1] = atom_idx;1139 self.etext_edata_end_atom_indices[1] = atom_idx;
1139 } else if (std.mem.eql(u8, name, "end")) {1140 } else if (decl.name.eqlSlice("end", &mod.intern_pool)) {
1140 self.etext_edata_end_atom_indices[2] = atom_idx;1141 self.etext_edata_end_atom_indices[2] = atom_idx;
1141 }1142 }
1142 try self.updateFinish(decl_index);1143 try self.updateFinish(decl_index);
1143 log.debug("seeDecl(extern) for {s} (got_addr=0x{x})", .{ name, self.getAtom(atom_idx).getOffsetTableAddress(self) });1144 log.debug("seeDecl(extern) for {} (got_addr=0x{x})", .{
1144 } else log.debug("seeDecl for {s}", .{name});1145 decl.name.fmt(&mod.intern_pool),
1146 self.getAtom(atom_idx).getOffsetTableAddress(self),
1147 });
1148 } else log.debug("seeDecl for {}", .{decl.name.fmt(&mod.intern_pool)});
1145 return atom_idx;1149 return atom_idx;
1146}1150}
11471151
...@@ -1393,7 +1397,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {...@@ -1393,7 +1397,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
1393 const sym = self.syms.items[atom.sym_index.?];1397 const sym = self.syms.items[atom.sym_index.?];
1394 try self.writeSym(writer, sym);1398 try self.writeSym(writer, sym);
1395 if (self.base.comp.module.?.decl_exports.get(decl_index)) |exports| {1399 if (self.base.comp.module.?.decl_exports.get(decl_index)) |exports| {
1396 for (exports.items) |e| if (decl_metadata.getExport(self, ip.stringToSlice(e.opts.name))) |exp_i| {1400 for (exports.items) |e| if (decl_metadata.getExport(self, e.opts.name.toSlice(ip))) |exp_i| {
1397 try self.writeSym(writer, self.syms.items[exp_i]);1401 try self.writeSym(writer, self.syms.items[exp_i]);
1398 };1402 };
1399 }1403 }
...@@ -1440,7 +1444,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {...@@ -1440,7 +1444,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
1440 const sym = self.syms.items[atom.sym_index.?];1444 const sym = self.syms.items[atom.sym_index.?];
1441 try self.writeSym(writer, sym);1445 try self.writeSym(writer, sym);
1442 if (self.base.comp.module.?.decl_exports.get(decl_index)) |exports| {1446 if (self.base.comp.module.?.decl_exports.get(decl_index)) |exports| {
1443 for (exports.items) |e| if (decl_metadata.getExport(self, ip.stringToSlice(e.opts.name))) |exp_i| {1447 for (exports.items) |e| if (decl_metadata.getExport(self, e.opts.name.toSlice(ip))) |exp_i| {
1444 const s = self.syms.items[exp_i];1448 const s = self.syms.items[exp_i];
1445 if (mem.eql(u8, s.name, "_start"))1449 if (mem.eql(u8, s.name, "_start"))
1446 self.entry_val = s.value;1450 self.entry_val = s.value;
...@@ -1483,25 +1487,25 @@ pub fn getDeclVAddr(...@@ -1483,25 +1487,25 @@ pub fn getDeclVAddr(
1483 reloc_info: link.File.RelocInfo,1487 reloc_info: link.File.RelocInfo,
1484) !u64 {1488) !u64 {
1485 const mod = self.base.comp.module.?;1489 const mod = self.base.comp.module.?;
1490 const ip = &mod.intern_pool;
1486 const decl = mod.declPtr(decl_index);1491 const decl = mod.declPtr(decl_index);
1487 log.debug("getDeclVAddr for {s}", .{mod.intern_pool.stringToSlice(decl.name)});1492 log.debug("getDeclVAddr for {}", .{decl.name.fmt(ip)});
1488 if (decl.isExtern(mod)) {1493 if (decl.isExtern(mod)) {
1489 const extern_name = mod.intern_pool.stringToSlice(decl.name);1494 if (decl.name.eqlSlice("etext", ip)) {
1490 if (std.mem.eql(u8, extern_name, "etext")) {
1491 try self.addReloc(reloc_info.parent_atom_index, .{1495 try self.addReloc(reloc_info.parent_atom_index, .{
1492 .target = undefined,1496 .target = undefined,
1493 .offset = reloc_info.offset,1497 .offset = reloc_info.offset,
1494 .addend = reloc_info.addend,1498 .addend = reloc_info.addend,
1495 .type = .special_etext,1499 .type = .special_etext,
1496 });1500 });
1497 } else if (std.mem.eql(u8, extern_name, "edata")) {1501 } else if (decl.name.eqlSlice("edata", ip)) {
1498 try self.addReloc(reloc_info.parent_atom_index, .{1502 try self.addReloc(reloc_info.parent_atom_index, .{
1499 .target = undefined,1503 .target = undefined,
1500 .offset = reloc_info.offset,1504 .offset = reloc_info.offset,
1501 .addend = reloc_info.addend,1505 .addend = reloc_info.addend,
1502 .type = .special_edata,1506 .type = .special_edata,
1503 });1507 });
1504 } else if (std.mem.eql(u8, extern_name, "end")) {1508 } else if (decl.name.eqlSlice("end", ip)) {
1505 try self.addReloc(reloc_info.parent_atom_index, .{1509 try self.addReloc(reloc_info.parent_atom_index, .{
1506 .target = undefined,1510 .target = undefined,
1507 .offset = reloc_info.offset,1511 .offset = reloc_info.offset,
src/link/SpirV.zig+5-6
...@@ -130,7 +130,7 @@ pub fn updateFunc(self: *SpirV, module: *Module, func_index: InternPool.Index, a...@@ -130,7 +130,7 @@ pub fn updateFunc(self: *SpirV, module: *Module, func_index: InternPool.Index, a
130130
131 const func = module.funcInfo(func_index);131 const func = module.funcInfo(func_index);
132 const decl = module.declPtr(func.owner_decl);132 const decl = module.declPtr(func.owner_decl);
133 log.debug("lowering function {s}", .{module.intern_pool.stringToSlice(decl.name)});133 log.debug("lowering function {}", .{decl.name.fmt(&module.intern_pool)});
134134
135 try self.object.updateFunc(module, func_index, air, liveness);135 try self.object.updateFunc(module, func_index, air, liveness);
136}136}
...@@ -141,7 +141,7 @@ pub fn updateDecl(self: *SpirV, module: *Module, decl_index: InternPool.DeclInde...@@ -141,7 +141,7 @@ pub fn updateDecl(self: *SpirV, module: *Module, decl_index: InternPool.DeclInde
141 }141 }
142142
143 const decl = module.declPtr(decl_index);143 const decl = module.declPtr(decl_index);
144 log.debug("lowering declaration {s}", .{module.intern_pool.stringToSlice(decl.name)});144 log.debug("lowering declaration {}", .{decl.name.fmt(&module.intern_pool)});
145145
146 try self.object.updateDecl(module, decl_index);146 try self.object.updateDecl(module, decl_index);
147}147}
...@@ -178,7 +178,7 @@ pub fn updateExports(...@@ -178,7 +178,7 @@ pub fn updateExports(
178 for (exports) |exp| {178 for (exports) |exp| {
179 try self.object.spv.declareEntryPoint(179 try self.object.spv.declareEntryPoint(
180 spv_decl_index,180 spv_decl_index,
181 mod.intern_pool.stringToSlice(exp.opts.name),181 exp.opts.name.toSlice(&mod.intern_pool),
182 execution_model,182 execution_model,
183 );183 );
184 }184 }
...@@ -227,14 +227,13 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node...@@ -227,14 +227,13 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: *std.Progress.Node
227227
228 try error_info.appendSlice("zig_errors");228 try error_info.appendSlice("zig_errors");
229 const mod = self.base.comp.module.?;229 const mod = self.base.comp.module.?;
230 for (mod.global_error_set.keys()) |name_nts| {230 for (mod.global_error_set.keys()) |name| {
231 const name = mod.intern_pool.stringToSlice(name_nts);
232 // Errors can contain pretty much any character - to encode them in a string we must escape231 // Errors can contain pretty much any character - to encode them in a string we must escape
233 // them somehow. Easiest here is to use some established scheme, one which also preseves the232 // them somehow. Easiest here is to use some established scheme, one which also preseves the
234 // name if it contains no strange characters is nice for debugging. URI encoding fits the bill.233 // name if it contains no strange characters is nice for debugging. URI encoding fits the bill.
235 // We're using : as separator, which is a reserved character.234 // We're using : as separator, which is a reserved character.
236235
237 const escaped_name = try std.Uri.escapeString(gpa, name);236 const escaped_name = try std.Uri.escapeString(gpa, name.toSlice(&mod.intern_pool));
238 defer gpa.free(escaped_name);237 defer gpa.free(escaped_name);
239 try error_info.writer().print(":{s}", .{escaped_name});238 try error_info.writer().print(":{s}", .{escaped_name});
240 }239 }
src/link/Wasm/ZigObject.zig+22-26
...@@ -258,8 +258,8 @@ pub fn updateDecl(...@@ -258,8 +258,8 @@ pub fn updateDecl(
258258
259 if (decl.isExtern(mod)) {259 if (decl.isExtern(mod)) {
260 const variable = decl.getOwnedVariable(mod).?;260 const variable = decl.getOwnedVariable(mod).?;
261 const name = mod.intern_pool.stringToSlice(decl.name);261 const name = decl.name.toSlice(&mod.intern_pool);
262 const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);262 const lib_name = variable.lib_name.toSlice(&mod.intern_pool);
263 return zig_object.addOrUpdateImport(wasm_file, name, atom.sym_index, lib_name, null);263 return zig_object.addOrUpdateImport(wasm_file, name, atom.sym_index, lib_name, null);
264 }264 }
265 const val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;265 const val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
...@@ -341,8 +341,8 @@ fn finishUpdateDecl(...@@ -341,8 +341,8 @@ fn finishUpdateDecl(
341 const atom_index = decl_info.atom;341 const atom_index = decl_info.atom;
342 const atom = wasm_file.getAtomPtr(atom_index);342 const atom = wasm_file.getAtomPtr(atom_index);
343 const sym = zig_object.symbol(atom.sym_index);343 const sym = zig_object.symbol(atom.sym_index);
344 const full_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));344 const full_name = try decl.fullyQualifiedName(mod);
345 sym.name = try zig_object.string_table.insert(gpa, full_name);345 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&mod.intern_pool));
346 try atom.code.appendSlice(gpa, code);346 try atom.code.appendSlice(gpa, code);
347 atom.size = @intCast(code.len);347 atom.size = @intCast(code.len);
348348
...@@ -382,7 +382,7 @@ fn finishUpdateDecl(...@@ -382,7 +382,7 @@ fn finishUpdateDecl(
382 // Will be freed upon freeing of decl or after cleanup of Wasm binary.382 // Will be freed upon freeing of decl or after cleanup of Wasm binary.
383 const full_segment_name = try std.mem.concat(gpa, u8, &.{383 const full_segment_name = try std.mem.concat(gpa, u8, &.{
384 segment_name,384 segment_name,
385 full_name,385 full_name.toSlice(&mod.intern_pool),
386 });386 });
387 errdefer gpa.free(full_segment_name);387 errdefer gpa.free(full_segment_name);
388 sym.tag = .data;388 sym.tag = .data;
...@@ -427,9 +427,9 @@ pub fn getOrCreateAtomForDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_ind...@@ -427,9 +427,9 @@ pub fn getOrCreateAtomForDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_ind
427 gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) };427 gop.value_ptr.* = .{ .atom = try wasm_file.createAtom(sym_index, zig_object.index) };
428 const mod = wasm_file.base.comp.module.?;428 const mod = wasm_file.base.comp.module.?;
429 const decl = mod.declPtr(decl_index);429 const decl = mod.declPtr(decl_index);
430 const full_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));430 const full_name = try decl.fullyQualifiedName(mod);
431 const sym = zig_object.symbol(sym_index);431 const sym = zig_object.symbol(sym_index);
432 sym.name = try zig_object.string_table.insert(gpa, full_name);432 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&mod.intern_pool));
433 }433 }
434 return gop.value_ptr.atom;434 return gop.value_ptr.atom;
435}435}
...@@ -478,9 +478,9 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d...@@ -478,9 +478,9 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
478 const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index);478 const parent_atom_index = try zig_object.getOrCreateAtomForDecl(wasm_file, decl_index);
479 const parent_atom = wasm_file.getAtom(parent_atom_index);479 const parent_atom = wasm_file.getAtom(parent_atom_index);
480 const local_index = parent_atom.locals.items.len;480 const local_index = parent_atom.locals.items.len;
481 const fqn = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));481 const fqn = try decl.fullyQualifiedName(mod);
482 const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{s}_{d}", .{482 const name = try std.fmt.allocPrintZ(gpa, "__unnamed_{}_{d}", .{
483 fqn, local_index,483 fqn.fmt(&mod.intern_pool), local_index,
484 });484 });
485 defer gpa.free(name);485 defer gpa.free(name);
486486
...@@ -623,11 +623,11 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm) !void {...@@ -623,11 +623,11 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm) !void {
623 // Addend for each relocation to the table623 // Addend for each relocation to the table
624 var addend: u32 = 0;624 var addend: u32 = 0;
625 const mod = wasm_file.base.comp.module.?;625 const mod = wasm_file.base.comp.module.?;
626 for (mod.global_error_set.keys()) |error_name_nts| {626 for (mod.global_error_set.keys()) |error_name| {
627 const atom = wasm_file.getAtomPtr(atom_index);627 const atom = wasm_file.getAtomPtr(atom_index);
628628
629 const error_name = mod.intern_pool.stringToSlice(error_name_nts);629 const error_name_slice = error_name.toSlice(&mod.intern_pool);
630 const len: u32 = @intCast(error_name.len + 1); // names are 0-terminated630 const len: u32 = @intCast(error_name_slice.len + 1); // names are 0-terminated
631631
632 const slice_ty = Type.slice_const_u8_sentinel_0;632 const slice_ty = Type.slice_const_u8_sentinel_0;
633 const offset = @as(u32, @intCast(atom.code.items.len));633 const offset = @as(u32, @intCast(atom.code.items.len));
...@@ -646,10 +646,9 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm) !void {...@@ -646,10 +646,9 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm) !void {
646646
647 // as we updated the error name table, we now store the actual name within the names atom647 // as we updated the error name table, we now store the actual name within the names atom
648 try names_atom.code.ensureUnusedCapacity(gpa, len);648 try names_atom.code.ensureUnusedCapacity(gpa, len);
649 names_atom.code.appendSliceAssumeCapacity(error_name);649 names_atom.code.appendSliceAssumeCapacity(error_name_slice[0..len]);
650 names_atom.code.appendAssumeCapacity(0);
651650
652 log.debug("Populated error name: '{s}'", .{error_name});651 log.debug("Populated error name: '{}'", .{error_name.fmt(&mod.intern_pool)});
653 }652 }
654 names_atom.size = addend;653 names_atom.size = addend;
655 zig_object.error_names_atom = names_atom_index;654 zig_object.error_names_atom = names_atom_index;
...@@ -833,8 +832,7 @@ pub fn deleteDeclExport(...@@ -833,8 +832,7 @@ pub fn deleteDeclExport(
833) void {832) void {
834 const mod = wasm_file.base.comp.module.?;833 const mod = wasm_file.base.comp.module.?;
835 const decl_info = zig_object.decls_map.getPtr(decl_index) orelse return;834 const decl_info = zig_object.decls_map.getPtr(decl_index) orelse return;
836 const export_name = mod.intern_pool.stringToSlice(name);835 if (decl_info.@"export"(zig_object, name.toSlice(&mod.intern_pool))) |sym_index| {
837 if (decl_info.@"export"(zig_object, export_name)) |sym_index| {
838 const sym = zig_object.symbol(sym_index);836 const sym = zig_object.symbol(sym_index);
839 decl_info.deleteExport(sym_index);837 decl_info.deleteExport(sym_index);
840 std.debug.assert(zig_object.global_syms.remove(sym.name));838 std.debug.assert(zig_object.global_syms.remove(sym.name));
...@@ -864,10 +862,10 @@ pub fn updateExports(...@@ -864,10 +862,10 @@ pub fn updateExports(
864 const atom = wasm_file.getAtom(atom_index);862 const atom = wasm_file.getAtom(atom_index);
865 const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*;863 const atom_sym = atom.symbolLoc().getSymbol(wasm_file).*;
866 const gpa = mod.gpa;864 const gpa = mod.gpa;
867 log.debug("Updating exports for decl '{s}'", .{mod.intern_pool.stringToSlice(decl.name)});865 log.debug("Updating exports for decl '{}'", .{decl.name.fmt(&mod.intern_pool)});
868866
869 for (exports) |exp| {867 for (exports) |exp| {
870 if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section| {868 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {
871 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(869 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
872 gpa,870 gpa,
873 decl.srcLoc(mod),871 decl.srcLoc(mod),
...@@ -877,10 +875,8 @@ pub fn updateExports(...@@ -877,10 +875,8 @@ pub fn updateExports(
877 continue;875 continue;
878 }876 }
879877
880 const export_string = mod.intern_pool.stringToSlice(exp.opts.name);878 const export_string = exp.opts.name.toSlice(&mod.intern_pool);
881 const sym_index = if (decl_info.@"export"(zig_object, export_string)) |idx|879 const sym_index = if (decl_info.@"export"(zig_object, export_string)) |idx| idx else index: {
882 idx
883 else index: {
884 const sym_index = try zig_object.allocateSymbol(gpa);880 const sym_index = try zig_object.allocateSymbol(gpa);
885 try decl_info.appendExport(gpa, sym_index);881 try decl_info.appendExport(gpa, sym_index);
886 break :index sym_index;882 break :index sym_index;
...@@ -1089,9 +1085,9 @@ pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm_file: *Wasm, inde...@@ -1089,9 +1085,9 @@ pub fn createDebugSectionForIndex(zig_object: *ZigObject, wasm_file: *Wasm, inde
1089pub fn updateDeclLineNumber(zig_object: *ZigObject, mod: *Module, decl_index: InternPool.DeclIndex) !void {1085pub fn updateDeclLineNumber(zig_object: *ZigObject, mod: *Module, decl_index: InternPool.DeclIndex) !void {
1090 if (zig_object.dwarf) |*dw| {1086 if (zig_object.dwarf) |*dw| {
1091 const decl = mod.declPtr(decl_index);1087 const decl = mod.declPtr(decl_index);
1092 const decl_name = mod.intern_pool.stringToSlice(try decl.fullyQualifiedName(mod));1088 const decl_name = try decl.fullyQualifiedName(mod);
10931089
1094 log.debug("updateDeclLineNumber {s}{*}", .{ decl_name, decl });1090 log.debug("updateDeclLineNumber {}{*}", .{ decl_name.fmt(&mod.intern_pool), decl });
1095 try dw.updateDeclLineNumber(mod, decl_index);1091 try dw.updateDeclLineNumber(mod, decl_index);
1096 }1092 }
1097}1093}
src/mutable_value.zig+6-6
...@@ -73,7 +73,7 @@ pub const MutableValue = union(enum) {...@@ -73,7 +73,7 @@ pub const MutableValue = union(enum) {
73 } }),73 } }),
74 .bytes => |b| try ip.get(gpa, .{ .aggregate = .{74 .bytes => |b| try ip.get(gpa, .{ .aggregate = .{
75 .ty = b.ty,75 .ty = b.ty,
76 .storage = .{ .bytes = b.data },76 .storage = .{ .bytes = try ip.getOrPutString(gpa, b.data, .maybe_embedded_nulls) },
77 } }),77 } }),
78 .aggregate => |a| {78 .aggregate => |a| {
79 const elems = try arena.alloc(InternPool.Index, a.elems.len);79 const elems = try arena.alloc(InternPool.Index, a.elems.len);
...@@ -158,18 +158,18 @@ pub const MutableValue = union(enum) {...@@ -158,18 +158,18 @@ pub const MutableValue = union(enum) {
158 },158 },
159 .aggregate => |agg| switch (agg.storage) {159 .aggregate => |agg| switch (agg.storage) {
160 .bytes => |bytes| {160 .bytes => |bytes| {
161 assert(bytes.len == ip.aggregateTypeLenIncludingSentinel(agg.ty));161 const len: usize = @intCast(ip.aggregateTypeLenIncludingSentinel(agg.ty));
162 assert(ip.childType(agg.ty) == .u8_type);162 assert(ip.childType(agg.ty) == .u8_type);
163 if (allow_bytes) {163 if (allow_bytes) {
164 const arena_bytes = try arena.alloc(u8, bytes.len);164 const arena_bytes = try arena.alloc(u8, len);
165 @memcpy(arena_bytes, bytes);165 @memcpy(arena_bytes, bytes.toSlice(len, ip));
166 mv.* = .{ .bytes = .{166 mv.* = .{ .bytes = .{
167 .ty = agg.ty,167 .ty = agg.ty,
168 .data = arena_bytes,168 .data = arena_bytes,
169 } };169 } };
170 } else {170 } else {
171 const mut_elems = try arena.alloc(MutableValue, bytes.len);171 const mut_elems = try arena.alloc(MutableValue, len);
172 for (bytes, mut_elems) |b, *mut_elem| {172 for (bytes.toSlice(len, ip), mut_elems) |b, *mut_elem| {
173 mut_elem.* = .{ .interned = try ip.get(gpa, .{ .int = .{173 mut_elem.* = .{ .interned = try ip.get(gpa, .{ .int = .{
174 .ty = .u8_type,174 .ty = .u8_type,
175 .storage = .{ .u64 = b },175 .storage = .{ .u64 = b },
src/print_value.zig+29-20
...@@ -204,26 +204,35 @@ fn printAggregate(...@@ -204,26 +204,35 @@ fn printAggregate(
204 try writer.writeAll(" }");204 try writer.writeAll(" }");
205 return;205 return;
206 },206 },
207 .Array => if (aggregate.storage == .bytes and aggregate.storage.bytes.len > 0) {207 .Array => {
208 const skip_terminator = aggregate.storage.bytes[aggregate.storage.bytes.len - 1] == 0;208 switch (aggregate.storage) {
209 const bytes = if (skip_terminator) b: {209 .bytes => |bytes| string: {
210 break :b aggregate.storage.bytes[0 .. aggregate.storage.bytes.len - 1];210 const len = ty.arrayLenIncludingSentinel(zcu);
211 } else aggregate.storage.bytes;211 if (len == 0) break :string;
212 try writer.print("\"{}\"", .{std.zig.fmtEscapes(bytes)});212 const slice = bytes.toSlice(if (bytes.at(len - 1, ip) == 0) len - 1 else len, ip);
213 if (!is_ref) try writer.writeAll(".*");213 try writer.print("\"{}\"", .{std.zig.fmtEscapes(slice)});
214 return;214 if (!is_ref) try writer.writeAll(".*");
215 } else if (ty.arrayLen(zcu) == 0) {215 return;
216 if (is_ref) try writer.writeByte('&');216 },
217 return writer.writeAll(".{}");217 .elems, .repeated_elem => {},
218 } else if (ty.arrayLen(zcu) == 1) one_byte_str: {218 }
219 // The repr isn't `bytes`, but we might still be able to print this as a string219 switch (ty.arrayLen(zcu)) {
220 if (ty.childType(zcu).toIntern() != .u8_type) break :one_byte_str;220 0 => {
221 const elem_val = Value.fromInterned(aggregate.storage.values()[0]);221 if (is_ref) try writer.writeByte('&');
222 if (elem_val.isUndef(zcu)) break :one_byte_str;222 return writer.writeAll(".{}");
223 const byte = elem_val.toUnsignedInt(zcu);223 },
224 try writer.print("\"{}\"", .{std.zig.fmtEscapes(&.{@intCast(byte)})});224 1 => one_byte_str: {
225 if (!is_ref) try writer.writeAll(".*");225 // The repr isn't `bytes`, but we might still be able to print this as a string
226 return;226 if (ty.childType(zcu).toIntern() != .u8_type) break :one_byte_str;
227 const elem_val = Value.fromInterned(aggregate.storage.values()[0]);
228 if (elem_val.isUndef(zcu)) break :one_byte_str;
229 const byte = elem_val.toUnsignedInt(zcu);
230 try writer.print("\"{}\"", .{std.zig.fmtEscapes(&.{@intCast(byte)})});
231 if (!is_ref) try writer.writeAll(".*");
232 return;
233 },
234 else => {},
235 }
227 },236 },
228 .Vector => if (ty.arrayLen(zcu) == 0) {237 .Vector => if (ty.arrayLen(zcu) == 0) {
229 if (is_ref) try writer.writeByte('&');238 if (is_ref) try writer.writeByte('&');
src/type.zig+7-15
...@@ -490,18 +490,10 @@ pub const Type = struct {...@@ -490,18 +490,10 @@ pub const Type = struct {
490 };490 };
491 },491 },
492 .anyframe_type => true,492 .anyframe_type => true,
493 .array_type => |array_type| {493 .array_type => |array_type| return array_type.lenIncludingSentinel() > 0 and
494 if (array_type.sentinel != .none) {494 try Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat),
495 return Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);495 .vector_type => |vector_type| return vector_type.len > 0 and
496 } else {496 try Type.fromInterned(vector_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat),
497 return array_type.len > 0 and
498 try Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
499 }
500 },
501 .vector_type => |vector_type| {
502 return vector_type.len > 0 and
503 try Type.fromInterned(vector_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
504 },
505 .opt_type => |child| {497 .opt_type => |child| {
506 const child_ty = Type.fromInterned(child);498 const child_ty = Type.fromInterned(child);
507 if (child_ty.isNoReturn(mod)) {499 if (child_ty.isNoReturn(mod)) {
...@@ -1240,7 +1232,7 @@ pub const Type = struct {...@@ -1240,7 +1232,7 @@ pub const Type = struct {
1240 .anyframe_type => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },1232 .anyframe_type => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
12411233
1242 .array_type => |array_type| {1234 .array_type => |array_type| {
1243 const len = array_type.len + @intFromBool(array_type.sentinel != .none);1235 const len = array_type.lenIncludingSentinel();
1244 if (len == 0) return .{ .scalar = 0 };1236 if (len == 0) return .{ .scalar = 0 };
1245 switch (try Type.fromInterned(array_type.child).abiSizeAdvanced(mod, strat)) {1237 switch (try Type.fromInterned(array_type.child).abiSizeAdvanced(mod, strat)) {
1246 .scalar => |elem_size| return .{ .scalar = len * elem_size },1238 .scalar => |elem_size| return .{ .scalar = len * elem_size },
...@@ -1577,7 +1569,7 @@ pub const Type = struct {...@@ -1577,7 +1569,7 @@ pub const Type = struct {
1577 .anyframe_type => return target.ptrBitWidth(),1569 .anyframe_type => return target.ptrBitWidth(),
15781570
1579 .array_type => |array_type| {1571 .array_type => |array_type| {
1580 const len = array_type.len + @intFromBool(array_type.sentinel != .none);1572 const len = array_type.lenIncludingSentinel();
1581 if (len == 0) return 0;1573 if (len == 0) return 0;
1582 const elem_ty = Type.fromInterned(array_type.child);1574 const elem_ty = Type.fromInterned(array_type.child);
1583 const elem_size = @max(1575 const elem_size = @max(
...@@ -1731,7 +1723,7 @@ pub const Type = struct {...@@ -1731,7 +1723,7 @@ pub const Type = struct {
1731 .struct_type => ip.loadStructType(ty.toIntern()).haveLayout(ip),1723 .struct_type => ip.loadStructType(ty.toIntern()).haveLayout(ip),
1732 .union_type => ip.loadUnionType(ty.toIntern()).haveLayout(ip),1724 .union_type => ip.loadUnionType(ty.toIntern()).haveLayout(ip),
1733 .array_type => |array_type| {1725 .array_type => |array_type| {
1734 if ((array_type.len + @intFromBool(array_type.sentinel != .none)) == 0) return true;1726 if (array_type.lenIncludingSentinel() == 0) return true;
1735 return Type.fromInterned(array_type.child).layoutIsResolved(mod);1727 return Type.fromInterned(array_type.child).layoutIsResolved(mod);
1736 },1728 },
1737 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod),1729 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod),