authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-15 16:32:55+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-15 16:32:55+00:00
log847c34ac66986fa0f2b9cd9b578b120965cb1dc3
tree20583b9c516549e7e2bf1a35fb481997063155b8
parentaf89bb05d392b34a9ac257d166df1c794542f2e8
signaturelock-open Commit is signed but in an unrecognized format.

compiler: remove doc comments from Zir

This code was left over from the legacy Autodoc implementation. No component of the compiler pipeline actually requires doc comments, so it is a waste of time and space to store them in ZIR.

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

lib/std/zig/AstGen.zig+15-114
...@@ -1377,7 +1377,7 @@ fn fnProtoExpr(...@@ -1377,7 +1377,7 @@ fn fnProtoExpr(
1377 const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param;1377 const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param;
1378 // We pass `prev_param_insts` as `&.{}` here because a function prototype can't refer to previous1378 // We pass `prev_param_insts` as `&.{}` here because a function prototype can't refer to previous
1379 // arguments (we haven't set up scopes here).1379 // 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);
1381 assert(param_inst_expected == param_inst);1381 assert(param_inst_expected == param_inst);
1382 }1382 }
1383 }1383 }
...@@ -4172,8 +4172,6 @@ fn fnDecl(...@@ -4172,8 +4172,6 @@ fn fnDecl(
4172 break :blk token_tags[maybe_noinline_token] == .keyword_noinline;4172 break :blk token_tags[maybe_noinline_token] == .keyword_noinline;
4173 };4173 };
41744174
4175 const doc_comment_index = try astgen.docCommentAsString(fn_proto.firstToken());
4176
4177 wip_members.nextDecl(decl_inst);4175 wip_members.nextDecl(decl_inst);
41784176
4179 // Note that the capacity here may not be sufficient, as this does not include `anytype` parameters.4177 // Note that the capacity here may not be sufficient, as this does not include `anytype` parameters.
...@@ -4263,7 +4261,7 @@ fn fnDecl(...@@ -4263,7 +4261,7 @@ fn fnDecl(
4263 const main_tokens = tree.nodes.items(.main_token);4261 const main_tokens = tree.nodes.items(.main_token);
4264 const name_token = param.name_token orelse main_tokens[param_type_node];4262 const name_token = param.name_token orelse main_tokens[param_type_node];
4265 const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param;4263 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);
4267 assert(param_inst_expected == param_inst);4265 assert(param_inst_expected == param_inst);
4268 break :param param_inst.toRef();4266 break :param param_inst.toRef();
4269 };4267 };
...@@ -4525,7 +4523,6 @@ fn fnDecl(...@@ -4525,7 +4523,6 @@ fn fnDecl(
4525 decl_gz.decl_line,4523 decl_gz.decl_line,
4526 is_pub,4524 is_pub,
4527 is_export,4525 is_export,
4528 doc_comment_index,
4529 &decl_gz,4526 &decl_gz,
4530 // align, linksection, and addrspace are passed in the func instruction in this case.4527 // align, linksection, and addrspace are passed in the func instruction in this case.
4531 // TODO: move them from the function instruction to the declaration instruction?4528 // TODO: move them from the function instruction to the declaration instruction?
...@@ -4598,8 +4595,6 @@ fn globalVarDecl(...@@ -4598,8 +4595,6 @@ fn globalVarDecl(
4598 break :blk lib_name_str.index;4595 break :blk lib_name_str.index;
4599 } else .empty;4596 } else .empty;
46004597
4601 const doc_comment_index = try astgen.docCommentAsString(var_decl.firstToken());
4602
4603 assert(var_decl.comptime_token == null); // handled by parser4598 assert(var_decl.comptime_token == null); // handled by parser
46044599
4605 const var_inst: Zir.Inst.Ref = if (var_decl.ast.init_node != 0) vi: {4600 const var_inst: Zir.Inst.Ref = if (var_decl.ast.init_node != 0) vi: {
...@@ -4698,7 +4693,6 @@ fn globalVarDecl(...@@ -4698,7 +4693,6 @@ fn globalVarDecl(
4698 block_scope.decl_line,4693 block_scope.decl_line,
4699 is_pub,4694 is_pub,
4700 is_export,4695 is_export,
4701 doc_comment_index,
4702 &block_scope,4696 &block_scope,
4703 .{4697 .{
4704 .align_gz = &align_gz,4698 .align_gz = &align_gz,
...@@ -4756,7 +4750,6 @@ fn comptimeDecl(...@@ -4756,7 +4750,6 @@ fn comptimeDecl(
4756 decl_block.decl_line,4750 decl_block.decl_line,
4757 false,4751 false,
4758 false,4752 false,
4759 .empty,
4760 &decl_block,4753 &decl_block,
4761 null,4754 null,
4762 );4755 );
...@@ -4814,7 +4807,6 @@ fn usingnamespaceDecl(...@@ -4814,7 +4807,6 @@ fn usingnamespaceDecl(
4814 decl_block.decl_line,4807 decl_block.decl_line,
4815 is_pub,4808 is_pub,
4816 false,4809 false,
4817 .empty,
4818 &decl_block,4810 &decl_block,
4819 null,4811 null,
4820 );4812 );
...@@ -4932,7 +4924,7 @@ fn testDecl(...@@ -4932,7 +4924,7 @@ fn testDecl(
4932 return astgen.failTok(test_name_token, "use of undeclared identifier '{s}'", .{ident_name});4924 return astgen.failTok(test_name_token, "use of undeclared identifier '{s}'", .{ident_name});
4933 }4925 }
49344926
4935 break :blk .{ .decltest = name_str_index };4927 break :blk .{ .decltest = test_name_token };
4936 },4928 },
4937 };4929 };
49384930
...@@ -5021,7 +5013,6 @@ fn testDecl(...@@ -5021,7 +5013,6 @@ fn testDecl(
5021 decl_block.decl_line,5013 decl_block.decl_line,
5022 false,5014 false,
5023 false,5015 false,
5024 .empty,
5025 &decl_block,5016 &decl_block,
5026 null,5017 null,
5027 );5018 );
...@@ -5174,9 +5165,6 @@ fn structDeclInner(...@@ -5174,9 +5165,6 @@ fn structDeclInner(
5174 assert(!member.ast.tuple_like);5165 assert(!member.ast.tuple_like);
5175 wip_members.appendToField(@intFromEnum(field_name));5166 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
5180 if (member.ast.type_expr == 0) {5168 if (member.ast.type_expr == 0) {
5181 return astgen.failTok(member.ast.main_token, "struct field missing type", .{});5169 return astgen.failTok(member.ast.main_token, "struct field missing type", .{});
5182 }5170 }
...@@ -5448,7 +5436,7 @@ fn unionDeclInner(...@@ -5448,7 +5436,7 @@ fn unionDeclInner(
5448 .none;5436 .none;
54495437
5450 const bits_per_field = 4;5438 const bits_per_field = 4;
5451 const max_field_size = 5;5439 const max_field_size = 4;
5452 var any_aligned_fields = false;5440 var any_aligned_fields = false;
5453 var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, field_count, bits_per_field, max_field_size);5441 var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, field_count, bits_per_field, max_field_size);
5454 defer wip_members.deinit();5442 defer wip_members.deinit();
...@@ -5479,9 +5467,6 @@ fn unionDeclInner(...@@ -5479,9 +5467,6 @@ fn unionDeclInner(
5479 const field_name = try astgen.identAsString(member.ast.main_token);5467 const field_name = try astgen.identAsString(member.ast.main_token);
5480 wip_members.appendToField(@intFromEnum(field_name));5468 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
5485 const have_type = member.ast.type_expr != 0;5470 const have_type = member.ast.type_expr != 0;
5486 const have_align = member.ast.align_expr != 0;5471 const have_align = member.ast.align_expr != 0;
5487 const have_value = member.ast.value_expr != 0;5472 const have_value = member.ast.value_expr != 0;
...@@ -5744,7 +5729,7 @@ fn containerDecl(...@@ -5744,7 +5729,7 @@ fn containerDecl(
5744 .none;5729 .none;
57455730
5746 const bits_per_field = 1;5731 const bits_per_field = 1;
5747 const max_field_size = 3;5732 const max_field_size = 2;
5748 var wip_members = try WipMembers.init(gpa, &astgen.scratch, @intCast(counts.decls), @intCast(counts.total_fields), bits_per_field, max_field_size);5733 var wip_members = try WipMembers.init(gpa, &astgen.scratch, @intCast(counts.decls), @intCast(counts.total_fields), bits_per_field, max_field_size);
5749 defer wip_members.deinit();5734 defer wip_members.deinit();
57505735
...@@ -5772,9 +5757,6 @@ fn containerDecl(...@@ -5772,9 +5757,6 @@ fn containerDecl(
5772 const field_name = try astgen.identAsString(member.ast.main_token);5757 const field_name = try astgen.identAsString(member.ast.main_token);
5773 wip_members.appendToField(@intFromEnum(field_name));5758 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
5778 const have_value = member.ast.value_expr != 0;5760 const have_value = member.ast.value_expr != 0;
5779 wip_members.nextField(bits_per_field, .{have_value});5761 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...@@ -6054,10 +6036,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
6054 }6036 }
6055 gop.value_ptr.* = tok_i;6037 gop.value_ptr.* = tok_i;
60566038
6057 try astgen.extra.ensureUnusedCapacity(gpa, 2);6039 try astgen.extra.append(gpa, @intFromEnum(str_index));
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));
6061 fields_len += 1;6040 fields_len += 1;
6062 },6041 },
6063 .r_brace => break,6042 .r_brace => break,
...@@ -11719,73 +11698,6 @@ fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !Zir.NullTerminat...@@ -11719,73 +11698,6 @@ fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !Zir.NullTerminat
11719 }11698 }
11720}11699}
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
11789const IndexSlice = struct { index: Zir.NullTerminatedString, len: u32 };11701const IndexSlice = struct { index: Zir.NullTerminatedString, len: u32 };
1179011702
11791fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {11703fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
...@@ -12722,7 +12634,6 @@ const GenZir = struct {...@@ -12722,7 +12634,6 @@ const GenZir = struct {
12722 /// Absolute token index. This function does the conversion to Decl offset.12634 /// Absolute token index. This function does the conversion to Decl offset.
12723 abs_tok_index: Ast.TokenIndex,12635 abs_tok_index: Ast.TokenIndex,
12724 name: Zir.NullTerminatedString,12636 name: Zir.NullTerminatedString,
12725 first_doc_comment: ?Ast.TokenIndex,
12726 ) !Zir.Inst.Index {12637 ) !Zir.Inst.Index {
12727 const gpa = gz.astgen.gpa;12638 const gpa = gz.astgen.gpa;
12728 const param_body = param_gz.instructionsSlice();12639 const param_body = param_gz.instructionsSlice();
...@@ -12730,14 +12641,8 @@ const GenZir = struct {...@@ -12730,14 +12641,8 @@ const GenZir = struct {
12730 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);12641 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
12731 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).@"struct".fields.len + body_len);12642 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
12738 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{12644 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
12739 .name = name,12645 .name = name,
12740 .doc_comment = doc_comment_index,
12741 .body_len = @intCast(body_len),12646 .body_len = @intCast(body_len),
12742 });12647 });
12743 gz.astgen.appendBodyWithFixupsExtraRefsArrayList(&gz.astgen.extra, param_body, prev_param_insts);12648 gz.astgen.appendBodyWithFixupsExtraRefsArrayList(&gz.astgen.extra, param_body, prev_param_insts);
...@@ -14143,8 +14048,8 @@ fn lowerAstErrors(astgen: *AstGen) !void {...@@ -14143,8 +14048,8 @@ fn lowerAstErrors(astgen: *AstGen) !void {
14143const DeclarationName = union(enum) {14048const DeclarationName = union(enum) {
14144 named: Ast.TokenIndex,14049 named: Ast.TokenIndex,
14145 named_test: Ast.TokenIndex,14050 named_test: Ast.TokenIndex,
14051 decltest: Ast.TokenIndex,
14146 unnamed_test,14052 unnamed_test,
14147 decltest: Zir.NullTerminatedString,
14148 @"comptime",14053 @"comptime",
14149 @"usingnamespace",14054 @"usingnamespace",
14150};14055};
...@@ -14174,7 +14079,6 @@ fn addFailedDeclaration(...@@ -14174,7 +14079,6 @@ fn addFailedDeclaration(
14174 gz.astgen.source_line,14079 gz.astgen.source_line,
14175 is_pub,14080 is_pub,
14176 false, // we don't care about exports since semantic analysis will fail14081 false, // we don't care about exports since semantic analysis will fail
14177 .empty,
14178 &decl_gz,14082 &decl_gz,
14179 null,14083 null,
14180 );14084 );
...@@ -14189,7 +14093,6 @@ fn setDeclaration(...@@ -14189,7 +14093,6 @@ fn setDeclaration(
14189 src_line: u32,14093 src_line: u32,
14190 is_pub: bool,14094 is_pub: bool,
14191 is_export: bool,14095 is_export: bool,
14192 doc_comment: Zir.NullTerminatedString,
14193 value_gz: *GenZir,14096 value_gz: *GenZir,
14194 /// May be `null` if all these blocks would be empty.14097 /// May be `null` if all these blocks would be empty.
14195 /// If `null`, then `value_gz` must have nothing stacked on it.14098 /// If `null`, then `value_gz` must have nothing stacked on it.
...@@ -14218,11 +14121,6 @@ fn setDeclaration(...@@ -14218,11 +14121,6 @@ fn setDeclaration(
14218 const linksection_len = astgen.countBodyLenAfterFixups(linksection_body);14121 const linksection_len = astgen.countBodyLenAfterFixups(linksection_body);
14219 const addrspace_len = astgen.countBodyLenAfterFixups(addrspace_body);14122 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
14226 const src_hash_arr: [4]u32 = @bitCast(src_hash);14124 const src_hash_arr: [4]u32 = @bitCast(src_hash);
1422714125
14228 const extra: Zir.Inst.Declaration = .{14126 const extra: Zir.Inst.Declaration = .{
...@@ -14233,8 +14131,14 @@ fn setDeclaration(...@@ -14233,8 +14131,14 @@ fn setDeclaration(
14233 .name = switch (name) {14131 .name = switch (name) {
14234 .named => |tok| @enumFromInt(@intFromEnum(try astgen.identAsString(tok))),14132 .named => |tok| @enumFromInt(@intFromEnum(try astgen.identAsString(tok))),
14235 .named_test => |tok| @enumFromInt(@intFromEnum(try astgen.testNameString(tok))),14133 .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 }),
14236 .unnamed_test => .unnamed_test,14141 .unnamed_test => .unnamed_test,
14237 .decltest => .decltest,
14238 .@"comptime" => .@"comptime",14142 .@"comptime" => .@"comptime",
14239 .@"usingnamespace" => .@"usingnamespace",14143 .@"usingnamespace" => .@"usingnamespace",
14240 },14144 },
...@@ -14243,14 +14147,11 @@ fn setDeclaration(...@@ -14243,14 +14147,11 @@ fn setDeclaration(
14243 .value_body_len = @intCast(value_len),14147 .value_body_len = @intCast(value_len),
14244 .is_pub = is_pub,14148 .is_pub = is_pub,
14245 .is_export = is_export,14149 .is_export = is_export,
14246 .has_doc_comment = true_doc_comment != .empty,14150 .test_is_decltest = name == .decltest,
14247 .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,14151 .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,
14248 },14152 },
14249 };14153 };
14250 astgen.instructions.items(.data)[@intFromEnum(decl_inst)].declaration.payload_index = try astgen.addExtra(extra);14154 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 }
14254 if (extra.flags.has_align_linksection_addrspace) {14155 if (extra.flags.has_align_linksection_addrspace) {
14255 try astgen.extra.appendSlice(gpa, &.{14156 try astgen.extra.appendSlice(gpa, &.{
14256 align_len,14157 align_len,
lib/std/zig/Zir.zig+12-26
...@@ -2612,20 +2612,19 @@ pub const Inst = struct {...@@ -2612,20 +2612,19 @@ pub const Inst = struct {
2612 };2612 };
26132613
2614 /// Trailing:2614 /// Trailing:
2615 /// 0. doc_comment: u32 // if `has_doc_comment`; null-terminated string index2615 /// 0. align_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `align`
2616 /// 1. 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. 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. addrspace_body_len: u32 // if `has_align_linksection_addrspace`; 0 means no `addrspace`2618 /// 3. value_body_inst: Zir.Inst.Index
2619 /// 4. value_body_inst: Zir.Inst.Index
2620 /// - for each `value_body_len`2619 /// - for each `value_body_len`
2621 /// - body to be exited via `break_inline` to this `declaration` instruction2620 /// - body to be exited via `break_inline` to this `declaration` instruction
2622 /// 5. align_body_inst: Zir.Inst.Index2621 /// 4. align_body_inst: Zir.Inst.Index
2623 /// - for each `align_body_len`2622 /// - for each `align_body_len`
2624 /// - body to be exited via `break_inline` to this `declaration` instruction2623 /// - body to be exited via `break_inline` to this `declaration` instruction
2625 /// 6. linksection_body_inst: Zir.Inst.Index2624 /// 5. linksection_body_inst: Zir.Inst.Index
2626 /// - for each `linksection_body_len`2625 /// - for each `linksection_body_len`
2627 /// - body to be exited via `break_inline` to this `declaration` instruction2626 /// - body to be exited via `break_inline` to this `declaration` instruction
2628 /// 7. addrspace_body_inst: Zir.Inst.Index2627 /// 6. addrspace_body_inst: Zir.Inst.Index
2629 /// - for each `addrspace_body_len`2628 /// - for each `addrspace_body_len`
2630 /// - body to be exited via `break_inline` to this `declaration` instruction2629 /// - body to be exited via `break_inline` to this `declaration` instruction
2631 pub const Declaration = struct {2630 pub const Declaration = struct {
...@@ -2643,7 +2642,7 @@ pub const Inst = struct {...@@ -2643,7 +2642,7 @@ pub const Inst = struct {
2643 value_body_len: u28,2642 value_body_len: u28,
2644 is_pub: bool,2643 is_pub: bool,
2645 is_export: bool,2644 is_export: bool,
2646 has_doc_comment: bool,2645 test_is_decltest: bool,
2647 has_align_linksection_addrspace: bool,2646 has_align_linksection_addrspace: bool,
2648 };2647 };
26492648
...@@ -2651,9 +2650,6 @@ pub const Inst = struct {...@@ -2651,9 +2650,6 @@ pub const Inst = struct {
2651 @"comptime" = std.math.maxInt(u32),2650 @"comptime" = std.math.maxInt(u32),
2652 @"usingnamespace" = std.math.maxInt(u32) - 1,2651 @"usingnamespace" = std.math.maxInt(u32) - 1,
2653 unnamed_test = std.math.maxInt(u32) - 2,2652 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,
2657 /// Other values are `NullTerminatedString` values, i.e. index into2653 /// Other values are `NullTerminatedString` values, i.e. index into
2658 /// `string_bytes`. If the byte referenced is 0, the decl is a named2654 /// `string_bytes`. If the byte referenced is 0, the decl is a named
2659 /// test, and the actual name begins at the following byte.2655 /// test, and the actual name begins at the following byte.
...@@ -2661,13 +2657,13 @@ pub const Inst = struct {...@@ -2661,13 +2657,13 @@ pub const Inst = struct {
26612657
2662 pub fn isNamedTest(name: Name, zir: Zir) bool {2658 pub fn isNamedTest(name: Name, zir: Zir) bool {
2663 return switch (name) {2659 return switch (name) {
2664 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => false,2660 .@"comptime", .@"usingnamespace", .unnamed_test => false,
2665 _ => zir.string_bytes[@intFromEnum(name)] == 0,2661 _ => zir.string_bytes[@intFromEnum(name)] == 0,
2666 };2662 };
2667 }2663 }
2668 pub fn toString(name: Name, zir: Zir) ?NullTerminatedString {2664 pub fn toString(name: Name, zir: Zir) ?NullTerminatedString {
2669 switch (name) {2665 switch (name) {
2670 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => return null,2666 .@"comptime", .@"usingnamespace", .unnamed_test => return null,
2671 _ => {},2667 _ => {},
2672 }2668 }
2673 const idx: u32 = @intFromEnum(name);2669 const idx: u32 = @intFromEnum(name);
...@@ -2688,7 +2684,6 @@ pub const Inst = struct {...@@ -2688,7 +2684,6 @@ pub const Inst = struct {
26882684
2689 pub fn getBodies(declaration: Declaration, extra_end: u32, zir: Zir) Bodies {2685 pub fn getBodies(declaration: Declaration, extra_end: u32, zir: Zir) Bodies {
2690 var extra_index: u32 = extra_end;2686 var extra_index: u32 = extra_end;
2691 extra_index += @intFromBool(declaration.flags.has_doc_comment);
2692 const value_body_len = declaration.flags.value_body_len;2687 const value_body_len = declaration.flags.value_body_len;
2693 const align_body_len, const linksection_body_len, const addrspace_body_len = lens: {2688 const align_body_len, const linksection_body_len, const addrspace_body_len = lens: {
2694 if (!declaration.flags.has_align_linksection_addrspace) {2689 if (!declaration.flags.has_align_linksection_addrspace) {
...@@ -3059,7 +3054,6 @@ pub const Inst = struct {...@@ -3059,7 +3054,6 @@ pub const Inst = struct {
3059 /// 0bX000: whether corresponding field has a type expression3054 /// 0bX000: whether corresponding field has a type expression
3060 /// 9. fields: { // for every fields_len3055 /// 9. fields: { // for every fields_len
3061 /// field_name: u32,3056 /// field_name: u32,
3062 /// doc_comment: NullTerminatedString, // .empty if no doc comment
3063 /// field_type: Ref, // if corresponding bit is not set. none means anytype.3057 /// field_type: Ref, // if corresponding bit is not set. none means anytype.
3064 /// field_type_body_len: u32, // if corresponding bit is set3058 /// field_type_body_len: u32, // if corresponding bit is set
3065 /// align_body_len: u32, // if corresponding bit is set3059 /// align_body_len: u32, // if corresponding bit is set
...@@ -3220,7 +3214,6 @@ pub const Inst = struct {...@@ -3220,7 +3214,6 @@ pub const Inst = struct {
3220 /// - the bit is whether corresponding field has an value expression3214 /// - the bit is whether corresponding field has an value expression
3221 /// 9. fields: { // for every fields_len3215 /// 9. fields: { // for every fields_len
3222 /// field_name: u32,3216 /// field_name: u32,
3223 /// doc_comment: u32, // .empty if no doc_comment
3224 /// value: Ref, // if corresponding bit is set3217 /// value: Ref, // if corresponding bit is set
3225 /// }3218 /// }
3226 pub const EnumDecl = struct {3219 pub const EnumDecl = struct {
...@@ -3263,9 +3256,7 @@ pub const Inst = struct {...@@ -3263,9 +3256,7 @@ pub const Inst = struct {
3263 /// 0bX000: unused3256 /// 0bX000: unused
3264 /// 9. fields: { // for every fields_len3257 /// 9. fields: { // for every fields_len
3265 /// field_name: NullTerminatedString, // null terminated string index3258 /// field_name: NullTerminatedString, // null terminated string index
3266 /// doc_comment: NullTerminatedString, // .empty if no doc comment
3267 /// field_type: Ref, // if corresponding bit is set3259 /// field_type: Ref, // if corresponding bit is set
3268 /// - if none, means `anytype`.
3269 /// align: Ref, // if corresponding bit is set3260 /// align: Ref, // if corresponding bit is set
3270 /// tag_value: Ref, // if corresponding bit is set3261 /// tag_value: Ref, // if corresponding bit is set
3271 /// }3262 /// }
...@@ -3328,10 +3319,7 @@ pub const Inst = struct {...@@ -3328,10 +3319,7 @@ pub const Inst = struct {
3328 };3319 };
33293320
3330 /// Trailing:3321 /// Trailing:
3331 /// { // for every fields_len3322 /// 0. field_name: NullTerminatedString // for every fields_len
3332 /// field_name: NullTerminatedString // null terminated string index
3333 /// doc_comment: NullTerminatedString // null terminated string index
3334 /// }
3335 pub const ErrorSetDecl = struct {3323 pub const ErrorSetDecl = struct {
3336 fields_len: u32,3324 fields_len: u32,
3337 };3325 };
...@@ -3474,8 +3462,6 @@ pub const Inst = struct {...@@ -3474,8 +3462,6 @@ pub const Inst = struct {
3474 pub const Param = struct {3462 pub const Param = struct {
3475 /// Null-terminated string index.3463 /// Null-terminated string index.
3476 name: NullTerminatedString,3464 name: NullTerminatedString,
3477 /// Null-terminated string index.
3478 doc_comment: NullTerminatedString,
3479 /// The body contains the type of the parameter.3465 /// The body contains the type of the parameter.
3480 body_len: u32,3466 body_len: u32,
3481 };3467 };
...@@ -4163,7 +4149,7 @@ fn findTrackableInner(...@@ -4163,7 +4149,7 @@ fn findTrackableInner(
4163 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;4149 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
4164 cur_bit_bag >>= 1;4150 cur_bit_bag >>= 1;
41654151
4166 fields_extra_index += 2; // field_name, doc_comment4152 fields_extra_index += 1; // field_name
41674153
4168 if (has_type_body) {4154 if (has_type_body) {
4169 const field_type_body_len = zir.extra[fields_extra_index];4155 const field_type_body_len = zir.extra[fields_extra_index];
src/Sema.zig+5-8
...@@ -3399,8 +3399,8 @@ fn zirErrorSetDecl(...@@ -3399,8 +3399,8 @@ fn zirErrorSetDecl(
3399 try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len);3399 try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len);
34003400
3401 var extra_index: u32 = @intCast(extra.end);3401 var extra_index: u32 = @intCast(extra.end);
3402 const extra_index_end = extra_index + (extra.data.fields_len * 2);3402 const extra_index_end = extra_index + extra.data.fields_len;
3403 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string3403 while (extra_index < extra_index_end) : (extra_index += 1) {
3404 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);3404 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);
3405 const name = sema.code.nullTerminatedString(name_index);3405 const name = sema.code.nullTerminatedString(name_index);
3406 const name_ip = try zcu.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);3406 const name_ip = try zcu.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
...@@ -36801,7 +36801,7 @@ fn structFields(...@@ -36801,7 +36801,7 @@ fn structFields(
36801 if (is_comptime) struct_type.setFieldComptime(ip, field_i);36801 if (is_comptime) struct_type.setFieldComptime(ip, field_i);
3680236802
36803 const field_name_zir: [:0]const u8 = zir.nullTerminatedString(@enumFromInt(zir.extra[extra_index]));36803 const field_name_zir: [:0]const u8 = zir.nullTerminatedString(@enumFromInt(zir.extra[extra_index]));
36804 extra_index += 2; // field_name, doc_comment36804 extra_index += 1; // field_name
3680536805
36806 fields[field_i] = .{};36806 fields[field_i] = .{};
3680736807
...@@ -36981,7 +36981,7 @@ fn structFieldInits(...@@ -36981,7 +36981,7 @@ fn structFieldInits(
36981 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;36981 const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0;
36982 cur_bit_bag >>= 1;36982 cur_bit_bag >>= 1;
3698336983
36984 extra_index += 2; // field_name, doc_comment36984 extra_index += 1; // field_name
3698536985
36986 fields[field_i] = .{};36986 fields[field_i] = .{};
3698736987
...@@ -37202,9 +37202,6 @@ fn unionFields(...@@ -37202,9 +37202,6 @@ fn unionFields(
37202 const field_name_zir = zir.nullTerminatedString(field_name_index);37202 const field_name_zir = zir.nullTerminatedString(field_name_index);
37203 extra_index += 1;37203 extra_index += 1;
3720437204
37205 // doc_comment
37206 extra_index += 1;
37207
37208 const field_type_ref: Zir.Inst.Ref = if (has_type) blk: {37205 const field_type_ref: Zir.Inst.Ref = if (has_type) blk: {
37209 const field_type_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);37206 const field_type_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
37210 extra_index += 1;37207 extra_index += 1;
...@@ -39069,7 +39066,7 @@ pub fn resolveDeclaredEnum(...@@ -39069,7 +39066,7 @@ pub fn resolveDeclaredEnum(
3906939066
39070 const field_name_index: Zir.NullTerminatedString = @enumFromInt(zir.extra[extra_index]);39067 const field_name_index: Zir.NullTerminatedString = @enumFromInt(zir.extra[extra_index]);
39071 const field_name_zir = zir.nullTerminatedString(field_name_index);39068 const field_name_zir = zir.nullTerminatedString(field_name_index);
39072 extra_index += 2; // field name, doc comment39069 extra_index += 1; // field name
3907339070
39074 const field_name = try ip.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls);39071 const field_name = try ip.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls);
3907539072
src/Zcu.zig+18-7
...@@ -2643,6 +2643,9 @@ pub fn mapOldZirToNew(...@@ -2643,6 +2643,9 @@ pub fn mapOldZirToNew(
2643 // Maps test name to `declaration` instruction.2643 // Maps test name to `declaration` instruction.
2644 var named_tests: std.StringHashMapUnmanaged(Zir.Inst.Index) = .empty;2644 var named_tests: std.StringHashMapUnmanaged(Zir.Inst.Index) = .empty;
2645 defer named_tests.deinit(gpa);2645 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);
2646 // All unnamed tests, in order, for a best-effort match.2649 // All unnamed tests, in order, for a best-effort match.
2647 var unnamed_tests: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty;2650 var unnamed_tests: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty;
2648 defer unnamed_tests.deinit(gpa);2651 defer unnamed_tests.deinit(gpa);
...@@ -2660,12 +2663,16 @@ pub fn mapOldZirToNew(...@@ -2660,12 +2663,16 @@ pub fn mapOldZirToNew(
2660 switch (old_decl.name) {2663 switch (old_decl.name) {
2661 .@"comptime" => try comptime_decls.append(gpa, old_decl_inst),2664 .@"comptime" => try comptime_decls.append(gpa, old_decl_inst),
2662 .@"usingnamespace" => try usingnamespace_decls.append(gpa, old_decl_inst),2665 .@"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),
2664 _ => {2667 _ => {
2665 const name_nts = old_decl.name.toString(old_zir).?;2668 const name_nts = old_decl.name.toString(old_zir).?;
2666 const name = old_zir.nullTerminatedString(name_nts);2669 const name = old_zir.nullTerminatedString(name_nts);
2667 if (old_decl.name.isNamedTest(old_zir)) {2670 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 }
2669 } else {2676 } else {
2670 try named_decls.put(gpa, name, old_decl_inst);2677 try named_decls.put(gpa, name, old_decl_inst);
2671 }2678 }
...@@ -2683,8 +2690,8 @@ pub fn mapOldZirToNew(...@@ -2683,8 +2690,8 @@ pub fn mapOldZirToNew(
2683 const new_decl, _ = new_zir.getDeclaration(new_decl_inst);2690 const new_decl, _ = new_zir.getDeclaration(new_decl_inst);
2684 // Attempt to match this to a declaration in the old ZIR:2691 // Attempt to match this to a declaration in the old ZIR:
2685 // * For named declarations (`const`/`var`/`fn`), we match based on name.2692 // * For named declarations (`const`/`var`/`fn`), we match based on name.
2686 // * For named tests (`test "foo"`), we also match based on name.2693 // * For named tests (`test "foo"`) and decltests (`test foo`), we also match based on name.
2687 // * For unnamed tests and decltests, we match based on order.2694 // * For unnamed tests, we match based on order.
2688 // * For comptime blocks, we match based on order.2695 // * For comptime blocks, we match based on order.
2689 // * For usingnamespace decls, we match based on order.2696 // * For usingnamespace decls, we match based on order.
2690 // If we cannot match this declaration, we can't match anything nested inside of it either, so we just `continue`.2697 // 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(...@@ -2699,7 +2706,7 @@ pub fn mapOldZirToNew(
2699 defer usingnamespace_decl_idx += 1;2706 defer usingnamespace_decl_idx += 1;
2700 break :inst usingnamespace_decls.items[usingnamespace_decl_idx];2707 break :inst usingnamespace_decls.items[usingnamespace_decl_idx];
2701 },2708 },
2702 .unnamed_test, .decltest => inst: {2709 .unnamed_test => inst: {
2703 if (unnamed_test_idx == unnamed_tests.items.len) continue;2710 if (unnamed_test_idx == unnamed_tests.items.len) continue;
2704 defer unnamed_test_idx += 1;2711 defer unnamed_test_idx += 1;
2705 break :inst unnamed_tests.items[unnamed_test_idx];2712 break :inst unnamed_tests.items[unnamed_test_idx];
...@@ -2708,7 +2715,11 @@ pub fn mapOldZirToNew(...@@ -2708,7 +2715,11 @@ pub fn mapOldZirToNew(
2708 const name_nts = new_decl.name.toString(new_zir).?;2715 const name_nts = new_decl.name.toString(new_zir).?;
2709 const name = new_zir.nullTerminatedString(name_nts);2716 const name = new_zir.nullTerminatedString(name_nts);
2710 if (new_decl.name.isNamedTest(new_zir)) {2717 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 }
2712 } else {2723 } else {
2713 break :inst named_decls.get(name) orelse continue;2724 break :inst named_decls.get(name) orelse continue;
2714 }2725 }
...@@ -3329,7 +3340,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv...@@ -3329,7 +3340,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv
3329 else => a: {3340 else => a: {
3330 if (!comp.config.is_test) break :a false;3341 if (!comp.config.is_test) break :a false;
3331 if (file.mod != zcu.main_mod) break :a false;3342 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)) {
3333 const nav = ip.getCau(cau).owner.unwrap().nav;3344 const nav = ip.getCau(cau).owner.unwrap().nav;
3334 const fqn_slice = ip.getNav(nav).fqn.toSlice(ip);3345 const fqn_slice = ip.getNav(nav).fqn.toSlice(ip);
3335 for (comp.test_filters) |test_filter| {3346 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 {...@@ -462,7 +462,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {
462 while (it.next()) |decl_inst| {462 while (it.next()) |decl_inst| {
463 const decl_name = old_zir.getDeclaration(decl_inst)[0].name;463 const decl_name = old_zir.getDeclaration(decl_inst)[0].name;
464 switch (decl_name) {464 switch (decl_name) {
465 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue,465 .@"comptime", .@"usingnamespace", .unnamed_test => continue,
466 _ => if (decl_name.isNamedTest(old_zir)) continue,466 _ => if (decl_name.isNamedTest(old_zir)) continue,
467 }467 }
468 const name_zir = decl_name.toString(old_zir).?;468 const name_zir = decl_name.toString(old_zir).?;
...@@ -481,7 +481,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {...@@ -481,7 +481,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {
481 while (it.next()) |decl_inst| {481 while (it.next()) |decl_inst| {
482 const decl_name = new_zir.getDeclaration(decl_inst)[0].name;482 const decl_name = new_zir.getDeclaration(decl_inst)[0].name;
483 switch (decl_name) {483 switch (decl_name) {
484 .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue,484 .@"comptime", .@"usingnamespace", .unnamed_test => continue,
485 _ => if (decl_name.isNamedTest(new_zir)) continue,485 _ => if (decl_name.isNamedTest(new_zir)) continue,
486 }486 }
487 const name_zir = decl_name.toString(new_zir).?;487 const name_zir = decl_name.toString(new_zir).?;
...@@ -1929,22 +1929,12 @@ const ScanDeclIter = struct {...@@ -1929,22 +1929,12 @@ const ScanDeclIter = struct {
1929 false,1929 false,
1930 };1930 };
1931 },1931 },
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 },
1943 _ => if (declaration.name.isNamedTest(zir)) info: {1932 _ => if (declaration.name.isNamedTest(zir)) info: {
1944 // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary.1933 // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary.
1945 if (iter.pass != .unnamed) return;1934 if (iter.pass != .unnamed) return;
1935 const prefix = if (declaration.flags.test_is_decltest) "decltest" else "test";
1946 break :info .{1936 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(),
1948 .@"test",1938 .@"test",
1949 true,1939 true,
1950 };1940 };
src/link/Dwarf.zig+1-4
...@@ -2207,7 +2207,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2207,7 +2207,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2207 .@"comptime",2207 .@"comptime",
2208 .@"usingnamespace",2208 .@"usingnamespace",
2209 .unnamed_test,2209 .unnamed_test,
2210 .decltest,
2211 => DW.ACCESS.private,2210 => DW.ACCESS.private,
2212 _ => if (decl_extra.name.isNamedTest(file.zir))2211 _ => if (decl_extra.name.isNamedTest(file.zir))
2213 DW.ACCESS.private2212 DW.ACCESS.private
...@@ -2257,7 +2256,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2257,7 +2256,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2257 .@"comptime",2256 .@"comptime",
2258 .@"usingnamespace",2257 .@"usingnamespace",
2259 .unnamed_test,2258 .unnamed_test,
2260 .decltest,
2261 => DW.ACCESS.private,2259 => DW.ACCESS.private,
2262 _ => if (decl_extra.name.isNamedTest(file.zir))2260 _ => if (decl_extra.name.isNamedTest(file.zir))
2263 DW.ACCESS.private2261 DW.ACCESS.private
...@@ -2305,7 +2303,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -2305,7 +2303,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
2305 .@"comptime",2303 .@"comptime",
2306 .@"usingnamespace",2304 .@"usingnamespace",
2307 .unnamed_test,2305 .unnamed_test,
2308 .decltest,
2309 => DW.ACCESS.private,2306 => DW.ACCESS.private,
2310 _ => if (decl_extra.name.isNamedTest(file.zir))2307 _ => if (decl_extra.name.isNamedTest(file.zir))
2311 DW.ACCESS.private2308 DW.ACCESS.private
...@@ -2547,7 +2544,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2547,7 +2544,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2547 const decl_extra = file.zir.extraData(Zir.Inst.Declaration, decl_inst.data.declaration.payload_index);2544 const decl_extra = file.zir.extraData(Zir.Inst.Declaration, decl_inst.data.declaration.payload_index);
25482545
2549 const is_test = switch (decl_extra.data.name) {2546 const is_test = switch (decl_extra.data.name) {
2550 .unnamed_test, .decltest => true,2547 .unnamed_test => true,
2551 .@"comptime", .@"usingnamespace" => false,2548 .@"comptime", .@"usingnamespace" => false,
2552 _ => decl_extra.data.name.isNamedTest(file.zir),2549 _ => decl_extra.data.name.isNamedTest(file.zir),
2553 };2550 };
src/print_zir.zig+5-38
...@@ -952,11 +952,6 @@ const Writer = struct {...@@ -952,11 +952,6 @@ const Writer = struct {
952 std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)),952 std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)),
953 });953 });
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 }
960 try self.writeBracedBody(stream, body);955 try self.writeBracedBody(stream, body);
961 try stream.writeAll(") ");956 try stream.writeAll(") ");
962 try self.writeSrcTok(stream, inst_data.src_tok);957 try self.writeSrcTok(stream, inst_data.src_tok);
...@@ -1482,7 +1477,6 @@ const Writer = struct {...@@ -1482,7 +1477,6 @@ const Writer = struct {
1482 const fields_per_u32 = 32 / bits_per_field;1477 const fields_per_u32 = 32 / bits_per_field;
1483 const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;1478 const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable;
1484 const Field = struct {1479 const Field = struct {
1485 doc_comment_index: Zir.NullTerminatedString,
1486 type_len: u32 = 0,1480 type_len: u32 = 0,
1487 align_len: u32 = 0,1481 align_len: u32 = 0,
1488 init_len: u32 = 0,1482 init_len: u32 = 0,
...@@ -1512,11 +1506,8 @@ const Writer = struct {...@@ -1512,11 +1506,8 @@ const Writer = struct {
15121506
1513 const field_name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);1507 const field_name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
1514 extra_index += 1;1508 extra_index += 1;
1515 const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
1516 extra_index += 1;
15171509
1518 fields[field_i] = .{1510 fields[field_i] = .{
1519 .doc_comment_index = doc_comment_index,
1520 .is_comptime = is_comptime,1511 .is_comptime = is_comptime,
1521 .name = field_name_index,1512 .name = field_name_index,
1522 };1513 };
...@@ -1544,7 +1535,6 @@ const Writer = struct {...@@ -1544,7 +1535,6 @@ const Writer = struct {
1544 self.indent += 2;1535 self.indent += 2;
15451536
1546 for (fields, 0..) |field, i| {1537 for (fields, 0..) |field, i| {
1547 try self.writeDocComment(stream, field.doc_comment_index);
1548 try stream.writeByteNTimes(' ', self.indent);1538 try stream.writeByteNTimes(' ', self.indent);
1549 try self.writeFlag(stream, "comptime ", field.is_comptime);1539 try self.writeFlag(stream, "comptime ", field.is_comptime);
1550 if (field.name != .empty) {1540 if (field.name != .empty) {
...@@ -1721,10 +1711,7 @@ const Writer = struct {...@@ -1721,10 +1711,7 @@ const Writer = struct {
1721 const field_name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);1711 const field_name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
1722 const field_name = self.code.nullTerminatedString(field_name_index);1712 const field_name = self.code.nullTerminatedString(field_name_index);
1723 extra_index += 1;1713 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);
1728 try stream.writeByteNTimes(' ', self.indent);1715 try stream.writeByteNTimes(' ', self.indent);
1729 try stream.print("{p}", .{std.zig.fmtId(field_name)});1716 try stream.print("{p}", .{std.zig.fmtId(field_name)});
17301717
...@@ -1870,11 +1857,6 @@ const Writer = struct {...@@ -1870,11 +1857,6 @@ const Writer = struct {
1870 const field_name = self.code.nullTerminatedString(@enumFromInt(self.code.extra[extra_index]));1857 const field_name = self.code.nullTerminatedString(@enumFromInt(self.code.extra[extra_index]));
1871 extra_index += 1;1858 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
1878 try stream.writeByteNTimes(' ', self.indent);1860 try stream.writeByteNTimes(' ', self.indent);
1879 try stream.print("{p}", .{std.zig.fmtId(field_name)});1861 try stream.print("{p}", .{std.zig.fmtId(field_name)});
18801862
...@@ -1987,12 +1969,10 @@ const Writer = struct {...@@ -1987,12 +1969,10 @@ const Writer = struct {
1987 self.indent += 2;1969 self.indent += 2;
19881970
1989 var extra_index = @as(u32, @intCast(extra.end));1971 var extra_index = @as(u32, @intCast(extra.end));
1990 const extra_index_end = extra_index + (extra.data.fields_len * 2);1972 const extra_index_end = extra_index + extra.data.fields_len;
1991 while (extra_index < extra_index_end) : (extra_index += 2) {1973 while (extra_index < extra_index_end) : (extra_index += 1) {
1992 const name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);1974 const name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]);
1993 const name = self.code.nullTerminatedString(name_index);1975 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);
1996 try stream.writeByteNTimes(' ', self.indent);1976 try stream.writeByteNTimes(' ', self.indent);
1997 try stream.print("{p},\n", .{std.zig.fmtId(name)});1977 try stream.print("{p},\n", .{std.zig.fmtId(name)});
1998 }1978 }
...@@ -2740,9 +2720,6 @@ const Writer = struct {...@@ -2740,9 +2720,6 @@ const Writer = struct {
2740 fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2720 fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2741 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].declaration;2721 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].declaration;
2742 const extra = self.code.extraData(Zir.Inst.Declaration, inst_data.payload_index);2722 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
2747 const prev_parent_decl_node = self.parent_decl_node;2724 const prev_parent_decl_node = self.parent_decl_node;
2748 defer self.parent_decl_node = prev_parent_decl_node;2725 defer self.parent_decl_node = prev_parent_decl_node;
...@@ -2754,10 +2731,11 @@ const Writer = struct {...@@ -2754,10 +2731,11 @@ const Writer = struct {
2754 .@"comptime" => try stream.writeAll("comptime"),2731 .@"comptime" => try stream.writeAll("comptime"),
2755 .@"usingnamespace" => try stream.writeAll("usingnamespace"),2732 .@"usingnamespace" => try stream.writeAll("usingnamespace"),
2756 .unnamed_test => try stream.writeAll("test"),2733 .unnamed_test => try stream.writeAll("test"),
2757 .decltest => try stream.print("decltest '{s}'", .{self.code.nullTerminatedString(doc_comment.?)}),
2758 _ => {2734 _ => {
2759 const name = extra.data.name.toString(self.code).?;2735 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 "";
2761 try stream.print("{s}'{s}'", .{ prefix, self.code.nullTerminatedString(name) });2739 try stream.print("{s}'{s}'", .{ prefix, self.code.nullTerminatedString(name) });
2762 },2740 },
2763 }2741 }
...@@ -2963,17 +2941,6 @@ const Writer = struct {...@@ -2963,17 +2941,6 @@ const Writer = struct {
2963 }2941 }
2964 }2942 }
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
2977 fn writeBody(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {2944 fn writeBody(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {
2978 for (body) |inst| {2945 for (body) |inst| {
2979 try stream.writeByteNTimes(' ', self.indent);2946 try stream.writeByteNTimes(' ', self.indent);