authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-07 22:28:24-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-07 22:28:24-08:00
log3176fdc0b921b36ee7d8346ef302d0817b980cfa
tree213a34bd1618ff429ec54efbc6652b2ee9940ff9
parent2115d7d1beeba32f975d8a032e5f5068e96e74f4
parent01b48e938198a206b95ed06f3a7e530e859c1cbc
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #18470 from castholm/typeInfo-sentinels

Make `@typeInfo` return null-terminated strings

9 files changed, 46 insertions(+), 40 deletions(-)

deps/aro/aro/Attribute.zig+1-1
...@@ -645,7 +645,7 @@ pub const Arguments = blk: {...@@ -645,7 +645,7 @@ pub const Arguments = blk: {
645 var union_fields: [decls.len]ZigType.UnionField = undefined;645 var union_fields: [decls.len]ZigType.UnionField = undefined;
646 for (decls, &union_fields) |decl, *field| {646 for (decls, &union_fields) |decl, *field| {
647 field.* = .{647 field.* = .{
648 .name = decl.name,648 .name = decl.name ++ "",
649 .type = @field(attributes, decl.name),649 .type = @field(attributes, decl.name),
650 .alignment = 0,650 .alignment = 0,
651 };651 };
lib/std/builtin.zig+5-5
...@@ -314,7 +314,7 @@ pub const Type = union(enum) {...@@ -314,7 +314,7 @@ pub const Type = union(enum) {
314 /// This data structure is used by the Zig language code generation and314 /// This data structure is used by the Zig language code generation and
315 /// therefore must be kept in sync with the compiler implementation.315 /// therefore must be kept in sync with the compiler implementation.
316 pub const StructField = struct {316 pub const StructField = struct {
317 name: []const u8,317 name: [:0]const u8,
318 type: type,318 type: type,
319 default_value: ?*const anyopaque,319 default_value: ?*const anyopaque,
320 is_comptime: bool,320 is_comptime: bool,
...@@ -348,7 +348,7 @@ pub const Type = union(enum) {...@@ -348,7 +348,7 @@ pub const Type = union(enum) {
348 /// This data structure is used by the Zig language code generation and348 /// This data structure is used by the Zig language code generation and
349 /// therefore must be kept in sync with the compiler implementation.349 /// therefore must be kept in sync with the compiler implementation.
350 pub const Error = struct {350 pub const Error = struct {
351 name: []const u8,351 name: [:0]const u8,
352 };352 };
353353
354 /// This data structure is used by the Zig language code generation and354 /// This data structure is used by the Zig language code generation and
...@@ -358,7 +358,7 @@ pub const Type = union(enum) {...@@ -358,7 +358,7 @@ pub const Type = union(enum) {
358 /// This data structure is used by the Zig language code generation and358 /// This data structure is used by the Zig language code generation and
359 /// therefore must be kept in sync with the compiler implementation.359 /// therefore must be kept in sync with the compiler implementation.
360 pub const EnumField = struct {360 pub const EnumField = struct {
361 name: []const u8,361 name: [:0]const u8,
362 value: comptime_int,362 value: comptime_int,
363 };363 };
364364
...@@ -374,7 +374,7 @@ pub const Type = union(enum) {...@@ -374,7 +374,7 @@ pub const Type = union(enum) {
374 /// This data structure is used by the Zig language code generation and374 /// This data structure is used by the Zig language code generation and
375 /// therefore must be kept in sync with the compiler implementation.375 /// therefore must be kept in sync with the compiler implementation.
376 pub const UnionField = struct {376 pub const UnionField = struct {
377 name: []const u8,377 name: [:0]const u8,
378 type: type,378 type: type,
379 alignment: comptime_int,379 alignment: comptime_int,
380 };380 };
...@@ -436,7 +436,7 @@ pub const Type = union(enum) {...@@ -436,7 +436,7 @@ pub const Type = union(enum) {
436 /// This data structure is used by the Zig language code generation and436 /// This data structure is used by the Zig language code generation and
437 /// therefore must be kept in sync with the compiler implementation.437 /// therefore must be kept in sync with the compiler implementation.
438 pub const Declaration = struct {438 pub const Declaration = struct {
439 name: []const u8,439 name: [:0]const u8,
440 };440 };
441};441};
442442
lib/std/enums.zig+1-1
...@@ -14,7 +14,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def...@@ -14,7 +14,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def
14 var fields: []const StructField = &[_]StructField{};14 var fields: []const StructField = &[_]StructField{};
15 for (std.meta.fields(E)) |field| {15 for (std.meta.fields(E)) |field| {
16 fields = fields ++ &[_]StructField{.{16 fields = fields ++ &[_]StructField{.{
17 .name = field.name,17 .name = field.name ++ "",
18 .type = Data,18 .type = Data,
19 .default_value = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null,19 .default_value = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null,
20 .is_comptime = false,20 .is_comptime = false,
lib/std/io.zig+1-1
...@@ -635,7 +635,7 @@ pub fn PollFiles(comptime StreamEnum: type) type {...@@ -635,7 +635,7 @@ pub fn PollFiles(comptime StreamEnum: type) type {
635 var struct_fields: [enum_fields.len]std.builtin.Type.StructField = undefined;635 var struct_fields: [enum_fields.len]std.builtin.Type.StructField = undefined;
636 for (&struct_fields, enum_fields) |*struct_field, enum_field| {636 for (&struct_fields, enum_fields) |*struct_field, enum_field| {
637 struct_field.* = .{637 struct_field.* = .{
638 .name = enum_field.name,638 .name = enum_field.name ++ "",
639 .type = fs.File,639 .type = fs.File,
640 .default_value = null,640 .default_value = null,
641 .is_comptime = false,641 .is_comptime = false,
lib/std/meta.zig+3-3
...@@ -556,7 +556,7 @@ pub fn FieldEnum(comptime T: type) type {...@@ -556,7 +556,7 @@ pub fn FieldEnum(comptime T: type) type {
556 var decls = [_]std.builtin.Type.Declaration{};556 var decls = [_]std.builtin.Type.Declaration{};
557 inline for (field_infos, 0..) |field, i| {557 inline for (field_infos, 0..) |field, i| {
558 enumFields[i] = .{558 enumFields[i] = .{
559 .name = field.name,559 .name = field.name ++ "",
560 .value = i,560 .value = i,
561 };561 };
562 }562 }
...@@ -628,7 +628,7 @@ pub fn DeclEnum(comptime T: type) type {...@@ -628,7 +628,7 @@ pub fn DeclEnum(comptime T: type) type {
628 var enumDecls: [fieldInfos.len]std.builtin.Type.EnumField = undefined;628 var enumDecls: [fieldInfos.len]std.builtin.Type.EnumField = undefined;
629 var decls = [_]std.builtin.Type.Declaration{};629 var decls = [_]std.builtin.Type.Declaration{};
630 inline for (fieldInfos, 0..) |field, i| {630 inline for (fieldInfos, 0..) |field, i| {
631 enumDecls[i] = .{ .name = field.name, .value = i };631 enumDecls[i] = .{ .name = field.name ++ "", .value = i };
632 }632 }
633 return @Type(.{633 return @Type(.{
634 .Enum = .{634 .Enum = .{
...@@ -1015,7 +1015,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type {...@@ -1015,7 +1015,7 @@ fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type {
1015 @setEvalBranchQuota(10_000);1015 @setEvalBranchQuota(10_000);
1016 var num_buf: [128]u8 = undefined;1016 var num_buf: [128]u8 = undefined;
1017 tuple_fields[i] = .{1017 tuple_fields[i] = .{
1018 .name = std.fmt.bufPrint(&num_buf, "{d}", .{i}) catch unreachable,1018 .name = std.fmt.bufPrintZ(&num_buf, "{d}", .{i}) catch unreachable,
1019 .type = T,1019 .type = T,
1020 .default_value = null,1020 .default_value = null,
1021 .is_comptime = false,1021 .is_comptime = false,
src/InternPool.zig+1-1
...@@ -5315,7 +5315,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -5315,7 +5315,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
53155315
5316 try ip.extra.ensureUnusedCapacity(5316 try ip.extra.ensureUnusedCapacity(
5317 gpa,5317 gpa,
5318 @typeInfo(Tag.Aggregate).Struct.fields.len + @as(usize, @intCast(len_including_sentinel)),5318 @typeInfo(Tag.Aggregate).Struct.fields.len + @as(usize, @intCast(len_including_sentinel + 1)),
5319 );5319 );
5320 ip.items.appendAssumeCapacity(.{5320 ip.items.appendAssumeCapacity(.{
5321 .tag = .aggregate,5321 .tag = .aggregate,
src/Sema.zig+31-25
...@@ -17259,10 +17259,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17259,10 +17259,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17259 const vals = try sema.arena.alloc(InternPool.Index, names.len);17259 const vals = try sema.arena.alloc(InternPool.Index, names.len);
17260 for (vals, 0..) |*field_val, i| {17260 for (vals, 0..) |*field_val, i| {
17261 // TODO: write something like getCoercedInts to avoid needing to dupe17261 // TODO: write something like getCoercedInts to avoid needing to dupe
17262 const name = try sema.arena.dupe(u8, ip.stringToSlice(names.get(ip)[i]));17262 const name = try sema.arena.dupeZ(u8, ip.stringToSlice(names.get(ip)[i]));
17263 const name_val = v: {17263 const name_val = v: {
17264 const new_decl_ty = try mod.arrayType(.{17264 const new_decl_ty = try mod.arrayType(.{
17265 .len = name.len,17265 .len = name.len,
17266 .sentinel = .zero_u8,
17266 .child = .u8_type,17267 .child = .u8_type,
17267 });17268 });
17268 const new_decl_val = try mod.intern(.{ .aggregate = .{17269 const new_decl_val = try mod.intern(.{ .aggregate = .{
...@@ -17270,17 +17271,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17270,17 +17271,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17270 .storage = .{ .bytes = name },17271 .storage = .{ .bytes = name },
17271 } });17272 } });
17272 break :v try mod.intern(.{ .ptr = .{17273 break :v try mod.intern(.{ .ptr = .{
17273 .ty = .slice_const_u8_type,17274 .ty = .slice_const_u8_sentinel_0_type,
17274 .addr = .{ .anon_decl = .{17275 .addr = .{ .anon_decl = .{
17275 .val = new_decl_val,17276 .val = new_decl_val,
17276 .orig_ty = .slice_const_u8_type,17277 .orig_ty = .slice_const_u8_sentinel_0_type,
17277 } },17278 } },
17278 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),17279 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
17279 } });17280 } });
17280 };17281 };
1728117282
17282 const error_field_fields = .{17283 const error_field_fields = .{
17283 // name: []const u8,17284 // name: [:0]const u8,
17284 name_val,17285 name_val,
17285 };17286 };
17286 field_val.* = try mod.intern(.{ .aggregate = .{17287 field_val.* = try mod.intern(.{ .aggregate = .{
...@@ -17387,10 +17388,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17387,10 +17388,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17387 else17388 else
17388 (try mod.intValue(Type.comptime_int, i)).toIntern();17389 (try mod.intValue(Type.comptime_int, i)).toIntern();
17389 // TODO: write something like getCoercedInts to avoid needing to dupe17390 // TODO: write something like getCoercedInts to avoid needing to dupe
17390 const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names.get(ip)[i]));17391 const name = try sema.arena.dupeZ(u8, ip.stringToSlice(enum_type.names.get(ip)[i]));
17391 const name_val = v: {17392 const name_val = v: {
17392 const new_decl_ty = try mod.arrayType(.{17393 const new_decl_ty = try mod.arrayType(.{
17393 .len = name.len,17394 .len = name.len,
17395 .sentinel = .zero_u8,
17394 .child = .u8_type,17396 .child = .u8_type,
17395 });17397 });
17396 const new_decl_val = try mod.intern(.{ .aggregate = .{17398 const new_decl_val = try mod.intern(.{ .aggregate = .{
...@@ -17398,17 +17400,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17398,17 +17400,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17398 .storage = .{ .bytes = name },17400 .storage = .{ .bytes = name },
17399 } });17401 } });
17400 break :v try mod.intern(.{ .ptr = .{17402 break :v try mod.intern(.{ .ptr = .{
17401 .ty = .slice_const_u8_type,17403 .ty = .slice_const_u8_sentinel_0_type,
17402 .addr = .{ .anon_decl = .{17404 .addr = .{ .anon_decl = .{
17403 .val = new_decl_val,17405 .val = new_decl_val,
17404 .orig_ty = .slice_const_u8_type,17406 .orig_ty = .slice_const_u8_sentinel_0_type,
17405 } },17407 } },
17406 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),17408 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
17407 } });17409 } });
17408 };17410 };
1740917411
17410 const enum_field_fields = .{17412 const enum_field_fields = .{
17411 // name: []const u8,17413 // name: [:0]const u8,
17412 name_val,17414 name_val,
17413 // value: comptime_int,17415 // value: comptime_int,
17414 value_val,17416 value_val,
...@@ -17512,10 +17514,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17512,10 +17514,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1751217514
17513 for (union_field_vals, 0..) |*field_val, i| {17515 for (union_field_vals, 0..) |*field_val, i| {
17514 // TODO: write something like getCoercedInts to avoid needing to dupe17516 // TODO: write something like getCoercedInts to avoid needing to dupe
17515 const name = try sema.arena.dupe(u8, ip.stringToSlice(union_obj.field_names.get(ip)[i]));17517 const name = try sema.arena.dupeZ(u8, ip.stringToSlice(union_obj.field_names.get(ip)[i]));
17516 const name_val = v: {17518 const name_val = v: {
17517 const new_decl_ty = try mod.arrayType(.{17519 const new_decl_ty = try mod.arrayType(.{
17518 .len = name.len,17520 .len = name.len,
17521 .sentinel = .zero_u8,
17519 .child = .u8_type,17522 .child = .u8_type,
17520 });17523 });
17521 const new_decl_val = try mod.intern(.{ .aggregate = .{17524 const new_decl_val = try mod.intern(.{ .aggregate = .{
...@@ -17523,10 +17526,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17523,10 +17526,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17523 .storage = .{ .bytes = name },17526 .storage = .{ .bytes = name },
17524 } });17527 } });
17525 break :v try mod.intern(.{ .ptr = .{17528 break :v try mod.intern(.{ .ptr = .{
17526 .ty = .slice_const_u8_type,17529 .ty = .slice_const_u8_sentinel_0_type,
17527 .addr = .{ .anon_decl = .{17530 .addr = .{ .anon_decl = .{
17528 .val = new_decl_val,17531 .val = new_decl_val,
17529 .orig_ty = .slice_const_u8_type,17532 .orig_ty = .slice_const_u8_sentinel_0_type,
17530 } },17533 } },
17531 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),17534 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
17532 } });17535 } });
...@@ -17539,7 +17542,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17539,7 +17542,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1753917542
17540 const field_ty = union_obj.field_types.get(ip)[i];17543 const field_ty = union_obj.field_types.get(ip)[i];
17541 const union_field_fields = .{17544 const union_field_fields = .{
17542 // name: []const u8,17545 // name: [:0]const u8,
17543 name_val,17546 name_val,
17544 // type: type,17547 // type: type,
17545 field_ty,17548 field_ty,
...@@ -17658,11 +17661,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17658,11 +17661,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17658 // TODO: write something like getCoercedInts to avoid needing to dupe17661 // TODO: write something like getCoercedInts to avoid needing to dupe
17659 const bytes = if (tuple.names.len != 0)17662 const bytes = if (tuple.names.len != 0)
17660 // https://github.com/ziglang/zig/issues/1570917663 // https://github.com/ziglang/zig/issues/15709
17661 try sema.arena.dupe(u8, ip.stringToSlice(ip.indexToKey(ty.toIntern()).anon_struct_type.names.get(ip)[i]))17664 try sema.arena.dupeZ(u8, ip.stringToSlice(ip.indexToKey(ty.toIntern()).anon_struct_type.names.get(ip)[i]))
17662 else17665 else
17663 try std.fmt.allocPrint(sema.arena, "{d}", .{i});17666 try std.fmt.allocPrintZ(sema.arena, "{d}", .{i});
17664 const new_decl_ty = try mod.arrayType(.{17667 const new_decl_ty = try mod.arrayType(.{
17665 .len = bytes.len,17668 .len = bytes.len,
17669 .sentinel = .zero_u8,
17666 .child = .u8_type,17670 .child = .u8_type,
17667 });17671 });
17668 const new_decl_val = try mod.intern(.{ .aggregate = .{17672 const new_decl_val = try mod.intern(.{ .aggregate = .{
...@@ -17670,10 +17674,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17670,10 +17674,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17670 .storage = .{ .bytes = bytes },17674 .storage = .{ .bytes = bytes },
17671 } });17675 } });
17672 break :v try mod.intern(.{ .ptr = .{17676 break :v try mod.intern(.{ .ptr = .{
17673 .ty = .slice_const_u8_type,17677 .ty = .slice_const_u8_sentinel_0_type,
17674 .addr = .{ .anon_decl = .{17678 .addr = .{ .anon_decl = .{
17675 .val = new_decl_val,17679 .val = new_decl_val,
17676 .orig_ty = .slice_const_u8_type,17680 .orig_ty = .slice_const_u8_sentinel_0_type,
17677 } },17681 } },
17678 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),17682 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),
17679 } });17683 } });
...@@ -17685,7 +17689,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17685,7 +17689,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17685 const opt_default_val = if (is_comptime) Value.fromInterned(field_val) else null;17689 const opt_default_val = if (is_comptime) Value.fromInterned(field_val) else null;
17686 const default_val_ptr = try sema.optRefValue(opt_default_val);17690 const default_val_ptr = try sema.optRefValue(opt_default_val);
17687 const struct_field_fields = .{17691 const struct_field_fields = .{
17688 // name: []const u8,17692 // name: [:0]const u8,
17689 name_val,17693 name_val,
17690 // type: type,17694 // type: type,
17691 field_ty,17695 field_ty,
...@@ -17713,7 +17717,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17713,7 +17717,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17713 for (struct_field_vals, 0..) |*field_val, i| {17717 for (struct_field_vals, 0..) |*field_val, i| {
17714 // TODO: write something like getCoercedInts to avoid needing to dupe17718 // TODO: write something like getCoercedInts to avoid needing to dupe
17715 const name = if (struct_type.fieldName(ip, i).unwrap()) |name_nts|17719 const name = if (struct_type.fieldName(ip, i).unwrap()) |name_nts|
17716 try sema.arena.dupe(u8, ip.stringToSlice(name_nts))17720 try sema.arena.dupeZ(u8, ip.stringToSlice(name_nts))
17717 else17721 else
17718 try std.fmt.allocPrintZ(sema.arena, "{d}", .{i});17722 try std.fmt.allocPrintZ(sema.arena, "{d}", .{i});
17719 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);17723 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
...@@ -17722,6 +17726,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17722,6 +17726,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17722 const name_val = v: {17726 const name_val = v: {
17723 const new_decl_ty = try mod.arrayType(.{17727 const new_decl_ty = try mod.arrayType(.{
17724 .len = name.len,17728 .len = name.len,
17729 .sentinel = .zero_u8,
17725 .child = .u8_type,17730 .child = .u8_type,
17726 });17731 });
17727 const new_decl_val = try mod.intern(.{ .aggregate = .{17732 const new_decl_val = try mod.intern(.{ .aggregate = .{
...@@ -17729,10 +17734,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17729,10 +17734,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17729 .storage = .{ .bytes = name },17734 .storage = .{ .bytes = name },
17730 } });17735 } });
17731 break :v try mod.intern(.{ .ptr = .{17736 break :v try mod.intern(.{ .ptr = .{
17732 .ty = .slice_const_u8_type,17737 .ty = .slice_const_u8_sentinel_0_type,
17733 .addr = .{ .anon_decl = .{17738 .addr = .{ .anon_decl = .{
17734 .val = new_decl_val,17739 .val = new_decl_val,
17735 .orig_ty = .slice_const_u8_type,17740 .orig_ty = .slice_const_u8_sentinel_0_type,
17736 } },17741 } },
17737 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),17742 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
17738 } });17743 } });
...@@ -17750,7 +17755,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17750,7 +17755,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17750 };17755 };
1775117756
17752 const struct_field_fields = .{17757 const struct_field_fields = .{
17753 // name: []const u8,17758 // name: [:0]const u8,
17754 name_val,17759 name_val,
17755 // type: type,17760 // type: type,
17756 field_ty.toIntern(),17761 field_ty.toIntern(),
...@@ -17957,9 +17962,10 @@ fn typeInfoNamespaceDecls(...@@ -17957,9 +17962,10 @@ fn typeInfoNamespaceDecls(
17957 if (decl.kind != .named or !decl.is_pub) continue;17962 if (decl.kind != .named or !decl.is_pub) continue;
17958 const name_val = v: {17963 const name_val = v: {
17959 // TODO: write something like getCoercedInts to avoid needing to dupe17964 // TODO: write something like getCoercedInts to avoid needing to dupe
17960 const name = try sema.arena.dupe(u8, ip.stringToSlice(decl.name));17965 const name = try sema.arena.dupeZ(u8, ip.stringToSlice(decl.name));
17961 const new_decl_ty = try mod.arrayType(.{17966 const new_decl_ty = try mod.arrayType(.{
17962 .len = name.len,17967 .len = name.len,
17968 .sentinel = .zero_u8,
17963 .child = .u8_type,17969 .child = .u8_type,
17964 });17970 });
17965 const new_decl_val = try mod.intern(.{ .aggregate = .{17971 const new_decl_val = try mod.intern(.{ .aggregate = .{
...@@ -17967,9 +17973,9 @@ fn typeInfoNamespaceDecls(...@@ -17967,9 +17973,9 @@ fn typeInfoNamespaceDecls(
17967 .storage = .{ .bytes = name },17973 .storage = .{ .bytes = name },
17968 } });17974 } });
17969 break :v try mod.intern(.{ .ptr = .{17975 break :v try mod.intern(.{ .ptr = .{
17970 .ty = .slice_const_u8_type,17976 .ty = .slice_const_u8_sentinel_0_type,
17971 .addr = .{ .anon_decl = .{17977 .addr = .{ .anon_decl = .{
17972 .orig_ty = .slice_const_u8_type,17978 .orig_ty = .slice_const_u8_sentinel_0_type,
17973 .val = new_decl_val,17979 .val = new_decl_val,
17974 } },17980 } },
17975 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),17981 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
...@@ -17977,7 +17983,7 @@ fn typeInfoNamespaceDecls(...@@ -17977,7 +17983,7 @@ fn typeInfoNamespaceDecls(
17977 };17983 };
1797817984
17979 const fields = .{17985 const fields = .{
17980 //name: []const u8,17986 //name: [:0]const u8,
17981 name_val,17987 name_val,
17982 };17988 };
17983 try decl_vals.append(try mod.intern(.{ .aggregate = .{17989 try decl_vals.append(try mod.intern(.{ .aggregate = .{
src/value.zig+1-1
...@@ -4050,7 +4050,7 @@ pub const Value = struct {...@@ -4050,7 +4050,7 @@ pub const Value = struct {
4050 const tags = @typeInfo(Tag).Enum.fields;4050 const tags = @typeInfo(Tag).Enum.fields;
4051 var fields: [tags.len]std.builtin.Type.StructField = undefined;4051 var fields: [tags.len]std.builtin.Type.StructField = undefined;
4052 for (&fields, tags) |*field, t| field.* = .{4052 for (&fields, tags) |*field, t| field.* = .{
4053 .name = t.name,4053 .name = t.name ++ "",
4054 .type = *@field(Tag, t.name).Type(),4054 .type = *@field(Tag, t.name).Type(),
4055 .default_value = null,4055 .default_value = null,
4056 .is_comptime = false,4056 .is_comptime = false,
test/behavior/type.zig+2-2
...@@ -549,7 +549,7 @@ test "Type.Fn" {...@@ -549,7 +549,7 @@ test "Type.Fn" {
549549
550test "reified struct field name from optional payload" {550test "reified struct field name from optional payload" {
551 comptime {551 comptime {
552 const m_name: ?[1]u8 = "a".*;552 const m_name: ?[1:0]u8 = "a".*;
553 if (m_name) |*name| {553 if (m_name) |*name| {
554 const T = @Type(.{ .Struct = .{554 const T = @Type(.{ .Struct = .{
555 .layout = .Auto,555 .layout = .Auto,
...@@ -711,7 +711,7 @@ test "struct field names sliced at comptime from larger string" {...@@ -711,7 +711,7 @@ test "struct field names sliced at comptime from larger string" {
711 while (it.next()) |name| {711 while (it.next()) |name| {
712 fields = fields ++ &[_]Type.StructField{.{712 fields = fields ++ &[_]Type.StructField{.{
713 .alignment = 0,713 .alignment = 0,
714 .name = name,714 .name = name ++ "",
715 .type = usize,715 .type = usize,
716 .default_value = null,716 .default_value = null,
717 .is_comptime = false,717 .is_comptime = false,