authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-16 02:48:28+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-12-16 02:48:28+00:00
log3a0a9aa9b866ad8483d298c6b891f9b321303bb9
treef8f9bdbc744147889227f38fcb801ba3651f218c
parent8f330ab70ea4f28b0b5efb349b89a9c9a8b95bf0
parent847c34ac66986fa0f2b9cd9b578b120965cb1dc3
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22245 from mlugg/zir-no-doc-comments

compiler: remove doc comments from Zir

7 files changed, 60 insertions(+), 211 deletions(-)

lib/std/zig/AstGen.zig+15-114
......@@ -1377,7 +1377,7 @@ fn fnProtoExpr(
13771377 const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param;
13781378 // We pass `prev_param_insts` as `&.{}` here because a function prototype can't refer to previous
13791379 // arguments (we haven't set up scopes here).
1380 const param_inst = try block_scope.addParam(&param_gz, &.{}, tag, name_token, param_name, param.first_doc_comment);
1380 const param_inst = try block_scope.addParam(&param_gz, &.{}, tag, name_token, param_name);
13811381 assert(param_inst_expected == param_inst);
13821382 }
13831383 }
......@@ -4172,8 +4172,6 @@ fn fnDecl(
41724172 break :blk token_tags[maybe_noinline_token] == .keyword_noinline;
41734173 };
41744174
4175 const doc_comment_index = try astgen.docCommentAsString(fn_proto.firstToken());
4176
41774175 wip_members.nextDecl(decl_inst);
41784176
41794177 // Note that the capacity here may not be sufficient, as this does not include `anytype` parameters.
......@@ -4263,7 +4261,7 @@ fn fnDecl(
42634261 const main_tokens = tree.nodes.items(.main_token);
42644262 const name_token = param.name_token orelse main_tokens[param_type_node];
42654263 const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param;
4266 const param_inst = try decl_gz.addParam(&param_gz, param_insts.items, tag, name_token, param_name, param.first_doc_comment);
4264 const param_inst = try decl_gz.addParam(&param_gz, param_insts.items, tag, name_token, param_name);
42674265 assert(param_inst_expected == param_inst);
42684266 break :param param_inst.toRef();
42694267 };
......@@ -4525,7 +4523,6 @@ fn fnDecl(
45254523 decl_gz.decl_line,
45264524 is_pub,
45274525 is_export,
4528 doc_comment_index,
45294526 &decl_gz,
45304527 // align, linksection, and addrspace are passed in the func instruction in this case.
45314528 // TODO: move them from the function instruction to the declaration instruction?
......@@ -4598,8 +4595,6 @@ fn globalVarDecl(
45984595 break :blk lib_name_str.index;
45994596 } else .empty;
46004597
4601 const doc_comment_index = try astgen.docCommentAsString(var_decl.firstToken());
4602
46034598 assert(var_decl.comptime_token == null); // handled by parser
46044599
46054600 const var_inst: Zir.Inst.Ref = if (var_decl.ast.init_node != 0) vi: {
......@@ -4698,7 +4693,6 @@ fn globalVarDecl(
46984693 block_scope.decl_line,
46994694 is_pub,
47004695 is_export,
4701 doc_comment_index,
47024696 &block_scope,
47034697 .{
47044698 .align_gz = &align_gz,
......@@ -4756,7 +4750,6 @@ fn comptimeDecl(
47564750 decl_block.decl_line,
47574751 false,
47584752 false,
4759 .empty,
47604753 &decl_block,
47614754 null,
47624755 );
......@@ -4814,7 +4807,6 @@ fn usingnamespaceDecl(
48144807 decl_block.decl_line,
48154808 is_pub,
48164809 false,
4817 .empty,
48184810 &decl_block,
48194811 null,
48204812 );
......@@ -4932,7 +4924,7 @@ fn testDecl(
49324924 return astgen.failTok(test_name_token, "use of undeclared identifier '{s}'", .{ident_name});
49334925 }
49344926
4935 break :blk .{ .decltest = name_str_index };
4927 break :blk .{ .decltest = test_name_token };
49364928 },
49374929 };
49384930
......@@ -5021,7 +5013,6 @@ fn testDecl(
50215013 decl_block.decl_line,
50225014 false,
50235015 false,
5024 .empty,
50255016 &decl_block,
50265017 null,
50275018 );
......@@ -5174,9 +5165,6 @@ fn structDeclInner(
51745165 assert(!member.ast.tuple_like);
51755166 wip_members.appendToField(@intFromEnum(field_name));
51765167
5177 const doc_comment_index = try astgen.docCommentAsString(member.firstToken());
5178 wip_members.appendToField(@intFromEnum(doc_comment_index));
5179
51805168 if (member.ast.type_expr == 0) {
51815169 return astgen.failTok(member.ast.main_token, "struct field missing type", .{});
51825170 }
......@@ -5448,7 +5436,7 @@ fn unionDeclInner(
54485436 .none;
54495437
54505438 const bits_per_field = 4;
5451 const max_field_size = 5;
5439 const max_field_size = 4;
54525440 var any_aligned_fields = false;
54535441 var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, field_count, bits_per_field, max_field_size);
54545442 defer wip_members.deinit();
......@@ -5479,9 +5467,6 @@ fn unionDeclInner(
54795467 const field_name = try astgen.identAsString(member.ast.main_token);
54805468 wip_members.appendToField(@intFromEnum(field_name));
54815469
5482 const doc_comment_index = try astgen.docCommentAsString(member.firstToken());
5483 wip_members.appendToField(@intFromEnum(doc_comment_index));
5484
54855470 const have_type = member.ast.type_expr != 0;
54865471 const have_align = member.ast.align_expr != 0;
54875472 const have_value = member.ast.value_expr != 0;
......@@ -5744,7 +5729,7 @@ fn containerDecl(
57445729 .none;
57455730
57465731 const bits_per_field = 1;
5747 const max_field_size = 3;
5732 const max_field_size = 2;
57485733 var wip_members = try WipMembers.init(gpa, &astgen.scratch, @intCast(counts.decls), @intCast(counts.total_fields), bits_per_field, max_field_size);
57495734 defer wip_members.deinit();
57505735
......@@ -5772,9 +5757,6 @@ fn containerDecl(
57725757 const field_name = try astgen.identAsString(member.ast.main_token);
57735758 wip_members.appendToField(@intFromEnum(field_name));
57745759
5775 const doc_comment_index = try astgen.docCommentAsString(member.firstToken());
5776 wip_members.appendToField(@intFromEnum(doc_comment_index));
5777
57785760 const have_value = member.ast.value_expr != 0;
57795761 wip_members.nextField(bits_per_field, .{have_value});
57805762
......@@ -6054,10 +6036,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
60546036 }
60556037 gop.value_ptr.* = tok_i;
60566038
6057 try astgen.extra.ensureUnusedCapacity(gpa, 2);
6058 astgen.extra.appendAssumeCapacity(@intFromEnum(str_index));
6059 const doc_comment_index = try astgen.docCommentAsString(tok_i);
6060 astgen.extra.appendAssumeCapacity(@intFromEnum(doc_comment_index));
6039 try astgen.extra.append(gpa, @intFromEnum(str_index));
60616040 fields_len += 1;
60626041 },
60636042 .r_brace => break,
......@@ -11719,73 +11698,6 @@ fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !Zir.NullTerminat
1171911698 }
1172011699}
1172111700
11722/// Adds a doc comment block to `string_bytes` by walking backwards from `end_token`.
11723/// `end_token` must point at the first token after the last doc comment line.
11724/// Returns 0 if no doc comment is present.
11725fn docCommentAsString(astgen: *AstGen, end_token: Ast.TokenIndex) !Zir.NullTerminatedString {
11726 if (end_token == 0) return .empty;
11727
11728 const token_tags = astgen.tree.tokens.items(.tag);
11729
11730 var tok = end_token - 1;
11731 while (token_tags[tok] == .doc_comment) {
11732 if (tok == 0) break;
11733 tok -= 1;
11734 } else {
11735 tok += 1;
11736 }
11737
11738 return docCommentAsStringFromFirst(astgen, end_token, tok);
11739}
11740
11741/// end_token must be > the index of the last doc comment.
11742fn docCommentAsStringFromFirst(
11743 astgen: *AstGen,
11744 end_token: Ast.TokenIndex,
11745 start_token: Ast.TokenIndex,
11746) !Zir.NullTerminatedString {
11747 if (start_token == end_token) return .empty;
11748
11749 const gpa = astgen.gpa;
11750 const string_bytes = &astgen.string_bytes;
11751 const str_index: u32 = @intCast(string_bytes.items.len);
11752 const token_starts = astgen.tree.tokens.items(.start);
11753 const token_tags = astgen.tree.tokens.items(.tag);
11754
11755 const total_bytes = token_starts[end_token] - token_starts[start_token];
11756 try string_bytes.ensureUnusedCapacity(gpa, total_bytes);
11757
11758 var current_token = start_token;
11759 while (current_token < end_token) : (current_token += 1) {
11760 switch (token_tags[current_token]) {
11761 .doc_comment => {
11762 const tok_bytes = astgen.tree.tokenSlice(current_token)[3..];
11763 string_bytes.appendSliceAssumeCapacity(tok_bytes);
11764 if (current_token != end_token - 1) {
11765 string_bytes.appendAssumeCapacity('\n');
11766 }
11767 },
11768 else => break,
11769 }
11770 }
11771
11772 const key: []const u8 = string_bytes.items[str_index..];
11773 const gop = try astgen.string_table.getOrPutContextAdapted(gpa, key, StringIndexAdapter{
11774 .bytes = string_bytes,
11775 }, StringIndexContext{
11776 .bytes = string_bytes,
11777 });
11778
11779 if (gop.found_existing) {
11780 string_bytes.shrinkRetainingCapacity(str_index);
11781 return @enumFromInt(gop.key_ptr.*);
11782 } else {
11783 gop.key_ptr.* = str_index;
11784 try string_bytes.append(gpa, 0);
11785 return @enumFromInt(str_index);
11786 }
11787}
11788
1178911701const IndexSlice = struct { index: Zir.NullTerminatedString, len: u32 };
1179011702
1179111703fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
......@@ -12722,7 +12634,6 @@ const GenZir = struct {
1272212634 /// Absolute token index. This function does the conversion to Decl offset.
1272312635 abs_tok_index: Ast.TokenIndex,
1272412636 name: Zir.NullTerminatedString,
12725 first_doc_comment: ?Ast.TokenIndex,
1272612637 ) !Zir.Inst.Index {
1272712638 const gpa = gz.astgen.gpa;
1272812639 const param_body = param_gz.instructionsSlice();
......@@ -12730,14 +12641,8 @@ const GenZir = struct {
1273012641 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
1273112642 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).@"struct".fields.len + body_len);
1273212643
12733 const doc_comment_index = if (first_doc_comment) |first|
12734 try gz.astgen.docCommentAsStringFromFirst(abs_tok_index, first)
12735 else
12736 .empty;
12737
1273812644 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
1273912645 .name = name,
12740 .doc_comment = doc_comment_index,
1274112646 .body_len = @intCast(body_len),
1274212647 });
1274312648 gz.astgen.appendBodyWithFixupsExtraRefsArrayList(&gz.astgen.extra, param_body, prev_param_insts);
......@@ -14143,8 +14048,8 @@ fn lowerAstErrors(astgen: *AstGen) !void {
1414314048const DeclarationName = union(enum) {
1414414049 named: Ast.TokenIndex,
1414514050 named_test: Ast.TokenIndex,
14051 decltest: Ast.TokenIndex,
1414614052 unnamed_test,
14147 decltest: Zir.NullTerminatedString,
1414814053 @"comptime",
1414914054 @"usingnamespace",
1415014055};
......@@ -14174,7 +14079,6 @@ fn addFailedDeclaration(
1417414079 gz.astgen.source_line,
1417514080 is_pub,
1417614081 false, // we don't care about exports since semantic analysis will fail
14177 .empty,
1417814082 &decl_gz,
1417914083 null,
1418014084 );
......@@ -14189,7 +14093,6 @@ fn setDeclaration(
1418914093 src_line: u32,
1419014094 is_pub: bool,
1419114095 is_export: bool,
14192 doc_comment: Zir.NullTerminatedString,
1419314096 value_gz: *GenZir,
1419414097 /// May be `null` if all these blocks would be empty.
1419514098 /// If `null`, then `value_gz` must have nothing stacked on it.
......@@ -14218,11 +14121,6 @@ fn setDeclaration(
1421814121 const linksection_len = astgen.countBodyLenAfterFixups(linksection_body);
1421914122 const addrspace_len = astgen.countBodyLenAfterFixups(addrspace_body);
1422014123
14221 const true_doc_comment: Zir.NullTerminatedString = switch (name) {
14222 .decltest => |test_name| test_name,
14223 else => doc_comment,
14224 };
14225
1422614124 const src_hash_arr: [4]u32 = @bitCast(src_hash);
1422714125
1422814126 const extra: Zir.Inst.Declaration = .{
......@@ -14233,8 +14131,14 @@ fn setDeclaration(
1423314131 .name = switch (name) {
1423414132 .named => |tok| @enumFromInt(@intFromEnum(try astgen.identAsString(tok))),
1423514133 .named_test => |tok| @enumFromInt(@intFromEnum(try astgen.testNameString(tok))),
14134 .decltest => |tok| @enumFromInt(str_idx: {
14135 const idx = astgen.string_bytes.items.len;
14136 try astgen.string_bytes.append(gpa, 0); // indicates this is a test
14137 try astgen.appendIdentStr(tok, &astgen.string_bytes);
14138 try astgen.string_bytes.append(gpa, 0); // end of the string
14139 break :str_idx idx;
14140 }),
1423614141 .unnamed_test => .unnamed_test,
14237 .decltest => .decltest,
1423814142 .@"comptime" => .@"comptime",
1423914143 .@"usingnamespace" => .@"usingnamespace",
1424014144 },
......@@ -14243,14 +14147,11 @@ fn setDeclaration(
1424314147 .value_body_len = @intCast(value_len),
1424414148 .is_pub = is_pub,
1424514149 .is_export = is_export,
14246 .has_doc_comment = true_doc_comment != .empty,
14150 .test_is_decltest = name == .decltest,
1424714151 .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,
1424814152 },
1424914153 };
1425014154 astgen.instructions.items(.data)[@intFromEnum(decl_inst)].declaration.payload_index = try astgen.addExtra(extra);
14251 if (extra.flags.has_doc_comment) {
14252 try astgen.extra.append(gpa, @intFromEnum(true_doc_comment));
14253 }
1425414155 if (extra.flags.has_align_linksection_addrspace) {
1425514156 try astgen.extra.appendSlice(gpa, &.{
1425614157 align_len,
lib/std/zig/Zir.zig+12-26
......@@ -2612,20 +2612,19 @@ pub const Inst = struct {
26122612 };
26132613
26142614 /// Trailing:
2615 /// 0. doc_comment: u32 // if `has_doc_comment`; null-terminated string index
2616 /// 1. align_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `align`
2617 /// 2. linksection_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `linksection`
2618 /// 3. addrspace_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `addrspace`
2619 /// 4. value_body_inst: Zir.Inst.Index
2615 /// 0. align_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `align`
2616 /// 1. linksection_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `linksection`
2617 /// 2. addrspace_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `addrspace`
2618 /// 3. value_body_inst: Zir.Inst.Index
26202619 /// - for each `value_body_len`
26212620 /// - body to be exited via `break_inline` to this `declaration` instruction
2622 /// 5. align_body_inst: Zir.Inst.Index
2621 /// 4. align_body_inst: Zir.Inst.Index
26232622 /// - for each `align_body_len`
26242623 /// - body to be exited via `break_inline` to this `declaration` instruction
2625 /// 6. linksection_body_inst: Zir.Inst.Index
2624 /// 5. linksection_body_inst: Zir.Inst.Index
26262625 /// - for each `linksection_body_len`
26272626 /// - body to be exited via `break_inline` to this `declaration` instruction
2628 /// 7. addrspace_body_inst: Zir.Inst.Index
2627 /// 6. addrspace_body_inst: Zir.Inst.Index
26292628 /// - for each `addrspace_body_len`
26302629 /// - body to be exited via `break_inline` to this `declaration` instruction
26312630 pub const Declaration = struct {
......@@ -2643,7 +2642,7 @@ pub const Inst = struct {
26432642 value_body_len: u28,
26442643 is_pub: bool,
26452644 is_export: bool,
2646 has_doc_comment: bool,
2645 test_is_decltest: bool,
26472646 has_align_linksection_addrspace: bool,
26482647 };
26492648
......@@ -2651,9 +2650,6 @@ pub const Inst = struct {
26512650 @"comptime" = std.math.maxInt(u32),
26522651 @"usingnamespace" = std.math.maxInt(u32) - 1,
26532652 unnamed_test = std.math.maxInt(u32) - 2,
2654 /// In this case, `has_doc_comment` will be true, and the doc
2655 /// comment body is the identifier name.
2656 decltest = std.math.maxInt(u32) - 3,
26572653 /// Other values are `NullTerminatedString` values, i.e. index into
26582654 /// `string_bytes`. If the byte referenced is 0, the decl is a named
26592655 /// test, and the actual name begins at the following byte.
......@@ -2661,13 +2657,13 @@ pub const Inst = struct {
26612657
26622658 pub fn isNamedTest(name: Name, zir: Zir) bool {
26632659 return switch (name) {
2664 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => false,
2660 .@"comptime", .@"usingnamespace", .unnamed_test => false,
26652661 _ => zir.string_bytes[@intFromEnum(name)] == 0,
26662662 };
26672663 }
26682664 pub fn toString(name: Name, zir: Zir) ?NullTerminatedString {
26692665 switch (name) {
2670 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => return null,
2666 .@"comptime", .@"usingnamespace", .unnamed_test => return null,
26712667 _ => {},
26722668 }
26732669 const idx: u32 = @intFromEnum(name);
......@@ -2688,7 +2684,6 @@ pub const Inst = struct {
26882684
26892685 pub fn getBodies(declaration: Declaration, extra_end: u32, zir: Zir) Bodies {
26902686 var extra_index: u32 = extra_end;
2691 extra_index += @intFromBool(declaration.flags.has_doc_comment);
26922687 const value_body_len = declaration.flags.value_body_len;
26932688 const align_body_len, const linksection_body_len, const addrspace_body_len = lens: {
26942689 if (!declaration.flags.has_align_linksection_addrspace) {
......@@ -3059,7 +3054,6 @@ pub const Inst = struct {
30593054 /// 0bX000: whether corresponding field has a type expression
30603055 /// 9. fields: { // for every fields_len
30613056 /// field_name: u32,
3062 /// doc_comment: NullTerminatedString, // .empty if no doc comment
30633057 /// field_type: Ref, // if corresponding bit is not set. none means anytype.
30643058 /// field_type_body_len: u32, // if corresponding bit is set
30653059 /// align_body_len: u32, // if corresponding bit is set
......@@ -3220,7 +3214,6 @@ pub const Inst = struct {
32203214 /// - the bit is whether corresponding field has an value expression
32213215 /// 9. fields: { // for every fields_len
32223216 /// field_name: u32,
3223 /// doc_comment: u32, // .empty if no doc_comment
32243217 /// value: Ref, // if corresponding bit is set
32253218 /// }
32263219 pub const EnumDecl = struct {
......@@ -3263,9 +3256,7 @@ pub const Inst = struct {
32633256 /// 0bX000: unused
32643257 /// 9. fields: { // for every fields_len
32653258 /// field_name: NullTerminatedString, // null terminated string index
3266 /// doc_comment: NullTerminatedString, // .empty if no doc comment
32673259 /// field_type: Ref, // if corresponding bit is set
3268 /// - if none, means `anytype`.
32693260 /// align: Ref, // if corresponding bit is set
32703261 /// tag_value: Ref, // if corresponding bit is set
32713262 /// }
......@@ -3328,10 +3319,7 @@ pub const Inst = struct {
33283319 };
33293320
33303321 /// Trailing:
3331 /// { // for every fields_len
3332 /// field_name: NullTerminatedString // null terminated string index
3333 /// doc_comment: NullTerminatedString // null terminated string index
3334 /// }
3322 /// 0. field_name: NullTerminatedString // for every fields_len
33353323 pub const ErrorSetDecl = struct {
33363324 fields_len: u32,
33373325 };
......@@ -3474,8 +3462,6 @@ pub const Inst = struct {
34743462 pub const Param = struct {
34753463 /// Null-terminated string index.
34763464 name: NullTerminatedString,
3477 /// Null-terminated string index.
3478 doc_comment: NullTerminatedString,
34793465 /// The body contains the type of the parameter.
34803466 body_len: u32,
34813467 };
......@@ -4163,7 +4149,7 @@ fn findTrackableInner(
41634149 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
41644150 cur_bit_bag >>= 1;
41654151
4166 fields_extra_index += 2; // field_name, doc_comment
4152 fields_extra_index += 1; // field_name
41674153
41684154 if (has_type_body) {
41694155 const field_type_body_len = zir.extra[fields_extra_index];
src/Sema.zig+5-8
......@@ -3399,8 +3399,8 @@ fn zirErrorSetDecl(
33993399 try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len);
34003400
34013401 var extra_index: u32 = @intCast(extra.end);
3402 const extra_index_end = extra_index + (extra.data.fields_len * 2);
3403 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
3402 const extra_index_end = extra_index + extra.data.fields_len;
3403 while (extra_index < extra_index_end) : (extra_index += 1) {
34043404 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);
34053405 const name = sema.code.nullTerminatedString(name_index);
34063406 const name_ip = try zcu.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
......@@ -36827,7 +36827,7 @@ fn structFields(
3682736827 if (is_comptime) struct_type.setFieldComptime(ip, field_i);
3682836828
3682936829 const field_name_zir: [:0]const u8 = zir.nullTerminatedString(@enumFromInt(zir.extra[extra_index]));
36830 extra_index += 2; // field_name, doc_comment
36830 extra_index += 1; // field_name
3683136831
3683236832 fields[field_i] = .{};
3683336833
......@@ -37007,7 +37007,7 @@ fn structFieldInits(
3700737007 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
3700837008 cur_bit_bag >>= 1;
3700937009
37010 extra_index += 2; // field_name, doc_comment
37010 extra_index += 1; // field_name
3701137011
3701237012 fields[field_i] = .{};
3701337013
......@@ -37228,9 +37228,6 @@ fn unionFields(
3722837228 const field_name_zir = zir.nullTerminatedString(field_name_index);
3722937229 extra_index += 1;
3723037230
37231 // doc_comment
37232 extra_index += 1;
37233
3723437231 const field_type_ref: Zir.Inst.Ref = if (has_type) blk: {
3723537232 const field_type_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
3723637233 extra_index += 1;
......@@ -39095,7 +39092,7 @@ pub fn resolveDeclaredEnum(
3909539092
3909639093 const field_name_index: Zir.NullTerminatedString = @enumFromInt(zir.extra[extra_index]);
3909739094 const field_name_zir = zir.nullTerminatedString(field_name_index);
39098 extra_index += 2; // field name, doc comment
39095 extra_index += 1; // field name
3909939096
3910039097 const field_name = try ip.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls);
3910139098
src/Zcu.zig+18-7
......@@ -2643,6 +2643,9 @@ pub fn mapOldZirToNew(
26432643 // Maps test name to `declaration` instruction.
26442644 var named_tests: std.StringHashMapUnmanaged(Zir.Inst.Index) = .empty;
26452645 defer named_tests.deinit(gpa);
2646 // Maps test name to `declaration` instruction.
2647 var named_decltests: std.StringHashMapUnmanaged(Zir.Inst.Index) = .empty;
2648 defer named_decltests.deinit(gpa);
26462649 // All unnamed tests, in order, for a best-effort match.
26472650 var unnamed_tests: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty;
26482651 defer unnamed_tests.deinit(gpa);
......@@ -2660,12 +2663,16 @@ pub fn mapOldZirToNew(
26602663 switch (old_decl.name) {
26612664 .@"comptime" => try comptime_decls.append(gpa, old_decl_inst),
26622665 .@"usingnamespace" => try usingnamespace_decls.append(gpa, old_decl_inst),
2663 .unnamed_test, .decltest => try unnamed_tests.append(gpa, old_decl_inst),
2666 .unnamed_test => try unnamed_tests.append(gpa, old_decl_inst),
26642667 _ => {
26652668 const name_nts = old_decl.name.toString(old_zir).?;
26662669 const name = old_zir.nullTerminatedString(name_nts);
26672670 if (old_decl.name.isNamedTest(old_zir)) {
2668 try named_tests.put(gpa, name, old_decl_inst);
2671 if (old_decl.flags.test_is_decltest) {
2672 try named_decltests.put(gpa, name, old_decl_inst);
2673 } else {
2674 try named_tests.put(gpa, name, old_decl_inst);
2675 }
26692676 } else {
26702677 try named_decls.put(gpa, name, old_decl_inst);
26712678 }
......@@ -2683,8 +2690,8 @@ pub fn mapOldZirToNew(
26832690 const new_decl, _ = new_zir.getDeclaration(new_decl_inst);
26842691 // Attempt to match this to a declaration in the old ZIR:
26852692 // * For named declarations (`const`/`var`/`fn`), we match based on name.
2686 // * For named tests (`test "foo"`), we also match based on name.
2687 // * For unnamed tests and decltests, we match based on order.
2693 // * For named tests (`test "foo"`) and decltests (`test foo`), we also match based on name.
2694 // * For unnamed tests, we match based on order.
26882695 // * For comptime blocks, we match based on order.
26892696 // * For usingnamespace decls, we match based on order.
26902697 // If we cannot match this declaration, we can't match anything nested inside of it either, so we just `continue`.
......@@ -2699,7 +2706,7 @@ pub fn mapOldZirToNew(
26992706 defer usingnamespace_decl_idx += 1;
27002707 break :inst usingnamespace_decls.items[usingnamespace_decl_idx];
27012708 },
2702 .unnamed_test, .decltest => inst: {
2709 .unnamed_test => inst: {
27032710 if (unnamed_test_idx == unnamed_tests.items.len) continue;
27042711 defer unnamed_test_idx += 1;
27052712 break :inst unnamed_tests.items[unnamed_test_idx];
......@@ -2708,7 +2715,11 @@ pub fn mapOldZirToNew(
27082715 const name_nts = new_decl.name.toString(new_zir).?;
27092716 const name = new_zir.nullTerminatedString(name_nts);
27102717 if (new_decl.name.isNamedTest(new_zir)) {
2711 break :inst named_tests.get(name) orelse continue;
2718 if (new_decl.flags.test_is_decltest) {
2719 break :inst named_decltests.get(name) orelse continue;
2720 } else {
2721 break :inst named_tests.get(name) orelse continue;
2722 }
27122723 } else {
27132724 break :inst named_decls.get(name) orelse continue;
27142725 }
......@@ -3329,7 +3340,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
33293340 else => a: {
33303341 if (!comp.config.is_test) break :a false;
33313342 if (file.mod != zcu.main_mod) break :a false;
3332 if (declaration.name.isNamedTest(zir) or declaration.name == .decltest) {
3343 if (declaration.name.isNamedTest(zir)) {
33333344 const nav = ip.getCau(cau).owner.unwrap().nav;
33343345 const fqn_slice = ip.getNav(nav).fqn.toSlice(ip);
33353346 for (comp.test_filters) |test_filter| {
src/Zcu/PerThread.zig+4-14
......@@ -462,7 +462,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {
462462 while (it.next()) |decl_inst| {
463463 const decl_name = old_zir.getDeclaration(decl_inst)[0].name;
464464 switch (decl_name) {
465 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue,
465 .@"comptime", .@"usingnamespace", .unnamed_test => continue,
466466 _ => if (decl_name.isNamedTest(old_zir)) continue,
467467 }
468468 const name_zir = decl_name.toString(old_zir).?;
......@@ -481,7 +481,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {
481481 while (it.next()) |decl_inst| {
482482 const decl_name = new_zir.getDeclaration(decl_inst)[0].name;
483483 switch (decl_name) {
484 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue,
484 .@"comptime", .@"usingnamespace", .unnamed_test => continue,
485485 _ => if (decl_name.isNamedTest(new_zir)) continue,
486486 }
487487 const name_zir = decl_name.toString(new_zir).?;
......@@ -1929,22 +1929,12 @@ const ScanDeclIter = struct {
19291929 false,
19301930 };
19311931 },
1932 .decltest => info: {
1933 // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary.
1934 if (iter.pass != .unnamed) return;
1935 assert(declaration.flags.has_doc_comment);
1936 const name = zir.nullTerminatedString(@enumFromInt(zir.extra[extra.end]));
1937 break :info .{
1938 (try iter.avoidNameConflict("decltest.{s}", .{name})).toOptional(),
1939 .@"test",
1940 true,
1941 };
1942 },
19431932 _ => if (declaration.name.isNamedTest(zir)) info: {
19441933 // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary.
19451934 if (iter.pass != .unnamed) return;
1935 const prefix = if (declaration.flags.test_is_decltest) "decltest" else "test";
19461936 break :info .{
1947 (try iter.avoidNameConflict("test.{s}", .{zir.nullTerminatedString(declaration.name.toString(zir).?)})).toOptional(),
1937 (try iter.avoidNameConflict("{s}.{s}", .{ prefix, zir.nullTerminatedString(declaration.name.toString(zir).?) })).toOptional(),
19481938 .@"test",
19491939 true,
19501940 };
src/link/Dwarf.zig+1-4
......@@ -2208,7 +2208,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22082208 .@"comptime",
22092209 .@"usingnamespace",
22102210 .unnamed_test,
2211 .decltest,
22122211 => DW.ACCESS.private,
22132212 _ => if (decl_extra.name.isNamedTest(file.zir))
22142213 DW.ACCESS.private
......@@ -2258,7 +2257,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
22582257 .@"comptime",
22592258 .@"usingnamespace",
22602259 .unnamed_test,
2261 .decltest,
22622260 => DW.ACCESS.private,
22632261 _ => if (decl_extra.name.isNamedTest(file.zir))
22642262 DW.ACCESS.private
......@@ -2306,7 +2304,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
23062304 .@"comptime",
23072305 .@"usingnamespace",
23082306 .unnamed_test,
2309 .decltest,
23102307 => DW.ACCESS.private,
23112308 _ => if (decl_extra.name.isNamedTest(file.zir))
23122309 DW.ACCESS.private
......@@ -2548,7 +2545,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
25482545 const decl_extra = file.zir.extraData(Zir.Inst.Declaration, decl_inst.data.declaration.payload_index);
25492546
25502547 const is_test = switch (decl_extra.data.name) {
2551 .unnamed_test, .decltest => true,
2548 .unnamed_test => true,
25522549 .@"comptime", .@"usingnamespace" => false,
25532550 _ => decl_extra.data.name.isNamedTest(file.zir),
25542551 };
src/print_zir.zig+5-38
......@@ -952,11 +952,6 @@ const Writer = struct {
952952 std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)),
953953 });
954954
955 if (extra.data.doc_comment != .empty) {
956 try stream.writeAll("\n");
957 try self.writeDocComment(stream, extra.data.doc_comment);
958 try stream.writeByteNTimes(' ', self.indent);
959 }
960955 try self.writeBracedBody(stream, body);
961956 try stream.writeAll(") ");
962957 try self.writeSrcTok(stream, inst_data.src_tok);
......@@ -1482,7 +1477,6 @@ const Writer = struct {
14821477 const fields_per_u32 = 32 / bits_per_field;
14831478 const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;
14841479 const Field = struct {
1485 doc_comment_index: Zir.NullTerminatedString,
14861480 type_len: u32 = 0,
14871481 align_len: u32 = 0,
14881482 init_len: u32 = 0,
......@@ -1512,11 +1506,8 @@ const Writer = struct {
15121506
15131507 const field_name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
15141508 extra_index += 1;
1515 const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
1516 extra_index += 1;
15171509
15181510 fields[field_i] = .{
1519 .doc_comment_index = doc_comment_index,
15201511 .is_comptime = is_comptime,
15211512 .name = field_name_index,
15221513 };
......@@ -1544,7 +1535,6 @@ const Writer = struct {
15441535 self.indent += 2;
15451536
15461537 for (fields, 0..) |field, i| {
1547 try self.writeDocComment(stream, field.doc_comment_index);
15481538 try stream.writeByteNTimes(' ', self.indent);
15491539 try self.writeFlag(stream, "comptime ", field.is_comptime);
15501540 if (field.name != .empty) {
......@@ -1721,10 +1711,7 @@ const Writer = struct {
17211711 const field_name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
17221712 const field_name = self.code.nullTerminatedString(field_name_index);
17231713 extra_index += 1;
1724 const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
1725 extra_index += 1;
17261714
1727 try self.writeDocComment(stream, doc_comment_index);
17281715 try stream.writeByteNTimes(' ', self.indent);
17291716 try stream.print("{p}", .{std.zig.fmtId(field_name)});
17301717
......@@ -1870,11 +1857,6 @@ const Writer = struct {
18701857 const field_name = self.code.nullTerminatedString(@enumFromInt(self.code.extra[extra_index]));
18711858 extra_index += 1;
18721859
1873 const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
1874 extra_index += 1;
1875
1876 try self.writeDocComment(stream, doc_comment_index);
1877
18781860 try stream.writeByteNTimes(' ', self.indent);
18791861 try stream.print("{p}", .{std.zig.fmtId(field_name)});
18801862
......@@ -1987,12 +1969,10 @@ const Writer = struct {
19871969 self.indent += 2;
19881970
19891971 var extra_index = @as(u32, @intCast(extra.end));
1990 const extra_index_end = extra_index + (extra.data.fields_len * 2);
1991 while (extra_index < extra_index_end) : (extra_index += 2) {
1972 const extra_index_end = extra_index + extra.data.fields_len;
1973 while (extra_index < extra_index_end) : (extra_index += 1) {
19921974 const name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
19931975 const name = self.code.nullTerminatedString(name_index);
1994 const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index + 1]);
1995 try self.writeDocComment(stream, doc_comment_index);
19961976 try stream.writeByteNTimes(' ', self.indent);
19971977 try stream.print("{p},\n", .{std.zig.fmtId(name)});
19981978 }
......@@ -2740,9 +2720,6 @@ const Writer = struct {
27402720 fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
27412721 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].declaration;
27422722 const extra = self.code.extraData(Zir.Inst.Declaration, inst_data.payload_index);
2743 const doc_comment: ?Zir.NullTerminatedString = if (extra.data.flags.has_doc_comment) dc: {
2744 break :dc @enumFromInt(self.code.extra[extra.end]);
2745 } else null;
27462723
27472724 const prev_parent_decl_node = self.parent_decl_node;
27482725 defer self.parent_decl_node = prev_parent_decl_node;
......@@ -2754,10 +2731,11 @@ const Writer = struct {
27542731 .@"comptime" => try stream.writeAll("comptime"),
27552732 .@"usingnamespace" => try stream.writeAll("usingnamespace"),
27562733 .unnamed_test => try stream.writeAll("test"),
2757 .decltest => try stream.print("decltest '{s}'", .{self.code.nullTerminatedString(doc_comment.?)}),
27582734 _ => {
27592735 const name = extra.data.name.toString(self.code).?;
2760 const prefix = if (extra.data.name.isNamedTest(self.code)) "test " else "";
2736 const prefix = if (extra.data.name.isNamedTest(self.code)) p: {
2737 break :p if (extra.data.flags.test_is_decltest) "decltest " else "test ";
2738 } else "";
27612739 try stream.print("{s}'{s}'", .{ prefix, self.code.nullTerminatedString(name) });
27622740 },
27632741 }
......@@ -2963,17 +2941,6 @@ const Writer = struct {
29632941 }
29642942 }
29652943
2966 fn writeDocComment(self: *Writer, stream: anytype, doc_comment_index: Zir.NullTerminatedString) !void {
2967 if (doc_comment_index != .empty) {
2968 const doc_comment = self.code.nullTerminatedString(doc_comment_index);
2969 var it = std.mem.tokenizeScalar(u8, doc_comment, '\n');
2970 while (it.next()) |doc_line| {
2971 try stream.writeByteNTimes(' ', self.indent);
2972 try stream.print("///{s}\n", .{doc_line});
2973 }
2974 }
2975 }
2976
29772944 fn writeBody(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {
29782945 for (body) |inst| {
29792946 try stream.writeByteNTimes(' ', self.indent);