| author | |
| committer | |
| log | 3a0a9aa9b866ad8483d298c6b891f9b321303bb9 |
| tree | f8f9bdbc744147889227f38fcb801ba3651f218c |
| parent | 8f330ab70ea4f28b0b5efb349b89a9c9a8b95bf0 |
| parent | 847c34ac66986fa0f2b9cd9b578b120965cb1dc3 |
| signature |
compiler: remove doc comments from Zir7 files changed, 60 insertions(+), 211 deletions(-)
lib/std/zig/AstGen.zig+15-114| ... | ... | @@ -1377,7 +1377,7 @@ fn fnProtoExpr( |
| 1377 | 1377 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; |
| 1378 | 1378 | // We pass `prev_param_insts` as `&.{}` here because a function prototype can't refer to previous |
| 1379 | 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 | 1381 | assert(param_inst_expected == param_inst); |
| 1382 | 1382 | } |
| 1383 | 1383 | } |
| ... | ... | @@ -4172,8 +4172,6 @@ fn fnDecl( |
| 4172 | 4172 | break :blk token_tags[maybe_noinline_token] == .keyword_noinline; |
| 4173 | 4173 | }; |
| 4174 | 4174 | |
| 4175 | const doc_comment_index = try astgen.docCommentAsString(fn_proto.firstToken()); | |
| 4176 | ||
| 4177 | 4175 | wip_members.nextDecl(decl_inst); |
| 4178 | 4176 | |
| 4179 | 4177 | // Note that the capacity here may not be sufficient, as this does not include `anytype` parameters. |
| ... | ... | @@ -4263,7 +4261,7 @@ fn fnDecl( |
| 4263 | 4261 | const main_tokens = tree.nodes.items(.main_token); |
| 4264 | 4262 | const name_token = param.name_token orelse main_tokens[param_type_node]; |
| 4265 | 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 | 4265 | assert(param_inst_expected == param_inst); |
| 4268 | 4266 | break :param param_inst.toRef(); |
| 4269 | 4267 | }; |
| ... | ... | @@ -4525,7 +4523,6 @@ fn fnDecl( |
| 4525 | 4523 | decl_gz.decl_line, |
| 4526 | 4524 | is_pub, |
| 4527 | 4525 | is_export, |
| 4528 | doc_comment_index, | |
| 4529 | 4526 | &decl_gz, |
| 4530 | 4527 | // align, linksection, and addrspace are passed in the func instruction in this case. |
| 4531 | 4528 | // TODO: move them from the function instruction to the declaration instruction? |
| ... | ... | @@ -4598,8 +4595,6 @@ fn globalVarDecl( |
| 4598 | 4595 | break :blk lib_name_str.index; |
| 4599 | 4596 | } else .empty; |
| 4600 | 4597 | |
| 4601 | const doc_comment_index = try astgen.docCommentAsString(var_decl.firstToken()); | |
| 4602 | ||
| 4603 | 4598 | assert(var_decl.comptime_token == null); // handled by parser |
| 4604 | 4599 | |
| 4605 | 4600 | const var_inst: Zir.Inst.Ref = if (var_decl.ast.init_node != 0) vi: { |
| ... | ... | @@ -4698,7 +4693,6 @@ fn globalVarDecl( |
| 4698 | 4693 | block_scope.decl_line, |
| 4699 | 4694 | is_pub, |
| 4700 | 4695 | is_export, |
| 4701 | doc_comment_index, | |
| 4702 | 4696 | &block_scope, |
| 4703 | 4697 | .{ |
| 4704 | 4698 | .align_gz = &align_gz, |
| ... | ... | @@ -4756,7 +4750,6 @@ fn comptimeDecl( |
| 4756 | 4750 | decl_block.decl_line, |
| 4757 | 4751 | false, |
| 4758 | 4752 | false, |
| 4759 | .empty, | |
| 4760 | 4753 | &decl_block, |
| 4761 | 4754 | null, |
| 4762 | 4755 | ); |
| ... | ... | @@ -4814,7 +4807,6 @@ fn usingnamespaceDecl( |
| 4814 | 4807 | decl_block.decl_line, |
| 4815 | 4808 | is_pub, |
| 4816 | 4809 | false, |
| 4817 | .empty, | |
| 4818 | 4810 | &decl_block, |
| 4819 | 4811 | null, |
| 4820 | 4812 | ); |
| ... | ... | @@ -4932,7 +4924,7 @@ fn testDecl( |
| 4932 | 4924 | return astgen.failTok(test_name_token, "use of undeclared identifier '{s}'", .{ident_name}); |
| 4933 | 4925 | } |
| 4934 | 4926 | |
| 4935 | break :blk .{ .decltest = name_str_index }; | |
| 4927 | break :blk .{ .decltest = test_name_token }; | |
| 4936 | 4928 | }, |
| 4937 | 4929 | }; |
| 4938 | 4930 | |
| ... | ... | @@ -5021,7 +5013,6 @@ fn testDecl( |
| 5021 | 5013 | decl_block.decl_line, |
| 5022 | 5014 | false, |
| 5023 | 5015 | false, |
| 5024 | .empty, | |
| 5025 | 5016 | &decl_block, |
| 5026 | 5017 | null, |
| 5027 | 5018 | ); |
| ... | ... | @@ -5174,9 +5165,6 @@ fn structDeclInner( |
| 5174 | 5165 | assert(!member.ast.tuple_like); |
| 5175 | 5166 | wip_members.appendToField(@intFromEnum(field_name)); |
| 5176 | 5167 | |
| 5177 | const doc_comment_index = try astgen.docCommentAsString(member.firstToken()); | |
| 5178 | wip_members.appendToField(@intFromEnum(doc_comment_index)); | |
| 5179 | ||
| 5180 | 5168 | if (member.ast.type_expr == 0) { |
| 5181 | 5169 | return astgen.failTok(member.ast.main_token, "struct field missing type", .{}); |
| 5182 | 5170 | } |
| ... | ... | @@ -5448,7 +5436,7 @@ fn unionDeclInner( |
| 5448 | 5436 | .none; |
| 5449 | 5437 | |
| 5450 | 5438 | const bits_per_field = 4; |
| 5451 | const max_field_size = 5; | |
| 5439 | const max_field_size = 4; | |
| 5452 | 5440 | var any_aligned_fields = false; |
| 5453 | 5441 | var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, field_count, bits_per_field, max_field_size); |
| 5454 | 5442 | defer wip_members.deinit(); |
| ... | ... | @@ -5479,9 +5467,6 @@ fn unionDeclInner( |
| 5479 | 5467 | const field_name = try astgen.identAsString(member.ast.main_token); |
| 5480 | 5468 | wip_members.appendToField(@intFromEnum(field_name)); |
| 5481 | 5469 | |
| 5482 | const doc_comment_index = try astgen.docCommentAsString(member.firstToken()); | |
| 5483 | wip_members.appendToField(@intFromEnum(doc_comment_index)); | |
| 5484 | ||
| 5485 | 5470 | const have_type = member.ast.type_expr != 0; |
| 5486 | 5471 | const have_align = member.ast.align_expr != 0; |
| 5487 | 5472 | const have_value = member.ast.value_expr != 0; |
| ... | ... | @@ -5744,7 +5729,7 @@ fn containerDecl( |
| 5744 | 5729 | .none; |
| 5745 | 5730 | |
| 5746 | 5731 | const bits_per_field = 1; |
| 5747 | const max_field_size = 3; | |
| 5732 | const max_field_size = 2; | |
| 5748 | 5733 | var wip_members = try WipMembers.init(gpa, &astgen.scratch, @intCast(counts.decls), @intCast(counts.total_fields), bits_per_field, max_field_size); |
| 5749 | 5734 | defer wip_members.deinit(); |
| 5750 | 5735 | |
| ... | ... | @@ -5772,9 +5757,6 @@ fn containerDecl( |
| 5772 | 5757 | const field_name = try astgen.identAsString(member.ast.main_token); |
| 5773 | 5758 | wip_members.appendToField(@intFromEnum(field_name)); |
| 5774 | 5759 | |
| 5775 | const doc_comment_index = try astgen.docCommentAsString(member.firstToken()); | |
| 5776 | wip_members.appendToField(@intFromEnum(doc_comment_index)); | |
| 5777 | ||
| 5778 | 5760 | const have_value = member.ast.value_expr != 0; |
| 5779 | 5761 | wip_members.nextField(bits_per_field, .{have_value}); |
| 5780 | 5762 | |
| ... | ... | @@ -6054,10 +6036,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi |
| 6054 | 6036 | } |
| 6055 | 6037 | gop.value_ptr.* = tok_i; |
| 6056 | 6038 | |
| 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)); | |
| 6061 | 6040 | fields_len += 1; |
| 6062 | 6041 | }, |
| 6063 | 6042 | .r_brace => break, |
| ... | ... | @@ -11719,73 +11698,6 @@ fn identAsString(astgen: *AstGen, ident_token: Ast.TokenIndex) !Zir.NullTerminat |
| 11719 | 11698 | } |
| 11720 | 11699 | } |
| 11721 | 11700 | |
| 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. | |
| 11725 | fn 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. | |
| 11742 | fn 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 | ||
| 11789 | 11701 | const IndexSlice = struct { index: Zir.NullTerminatedString, len: u32 }; |
| 11790 | 11702 | |
| 11791 | 11703 | fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice { |
| ... | ... | @@ -12722,7 +12634,6 @@ const GenZir = struct { |
| 12722 | 12634 | /// Absolute token index. This function does the conversion to Decl offset. |
| 12723 | 12635 | abs_tok_index: Ast.TokenIndex, |
| 12724 | 12636 | name: Zir.NullTerminatedString, |
| 12725 | first_doc_comment: ?Ast.TokenIndex, | |
| 12726 | 12637 | ) !Zir.Inst.Index { |
| 12727 | 12638 | const gpa = gz.astgen.gpa; |
| 12728 | 12639 | const param_body = param_gz.instructionsSlice(); |
| ... | ... | @@ -12730,14 +12641,8 @@ const GenZir = struct { |
| 12730 | 12641 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12731 | 12642 | try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).@"struct".fields.len + body_len); |
| 12732 | 12643 | |
| 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 | 12644 | const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{ |
| 12739 | 12645 | .name = name, |
| 12740 | .doc_comment = doc_comment_index, | |
| 12741 | 12646 | .body_len = @intCast(body_len), |
| 12742 | 12647 | }); |
| 12743 | 12648 | gz.astgen.appendBodyWithFixupsExtraRefsArrayList(&gz.astgen.extra, param_body, prev_param_insts); |
| ... | ... | @@ -14143,8 +14048,8 @@ fn lowerAstErrors(astgen: *AstGen) !void { |
| 14143 | 14048 | const DeclarationName = union(enum) { |
| 14144 | 14049 | named: Ast.TokenIndex, |
| 14145 | 14050 | named_test: Ast.TokenIndex, |
| 14051 | decltest: Ast.TokenIndex, | |
| 14146 | 14052 | unnamed_test, |
| 14147 | decltest: Zir.NullTerminatedString, | |
| 14148 | 14053 | @"comptime", |
| 14149 | 14054 | @"usingnamespace", |
| 14150 | 14055 | }; |
| ... | ... | @@ -14174,7 +14079,6 @@ fn addFailedDeclaration( |
| 14174 | 14079 | gz.astgen.source_line, |
| 14175 | 14080 | is_pub, |
| 14176 | 14081 | false, // we don't care about exports since semantic analysis will fail |
| 14177 | .empty, | |
| 14178 | 14082 | &decl_gz, |
| 14179 | 14083 | null, |
| 14180 | 14084 | ); |
| ... | ... | @@ -14189,7 +14093,6 @@ fn setDeclaration( |
| 14189 | 14093 | src_line: u32, |
| 14190 | 14094 | is_pub: bool, |
| 14191 | 14095 | is_export: bool, |
| 14192 | doc_comment: Zir.NullTerminatedString, | |
| 14193 | 14096 | value_gz: *GenZir, |
| 14194 | 14097 | /// May be `null` if all these blocks would be empty. |
| 14195 | 14098 | /// If `null`, then `value_gz` must have nothing stacked on it. |
| ... | ... | @@ -14218,11 +14121,6 @@ fn setDeclaration( |
| 14218 | 14121 | const linksection_len = astgen.countBodyLenAfterFixups(linksection_body); |
| 14219 | 14122 | const addrspace_len = astgen.countBodyLenAfterFixups(addrspace_body); |
| 14220 | 14123 | |
| 14221 | const true_doc_comment: Zir.NullTerminatedString = switch (name) { | |
| 14222 | .decltest => |test_name| test_name, | |
| 14223 | else => doc_comment, | |
| 14224 | }; | |
| 14225 | ||
| 14226 | 14124 | const src_hash_arr: [4]u32 = @bitCast(src_hash); |
| 14227 | 14125 | |
| 14228 | 14126 | const extra: Zir.Inst.Declaration = .{ |
| ... | ... | @@ -14233,8 +14131,14 @@ fn setDeclaration( |
| 14233 | 14131 | .name = switch (name) { |
| 14234 | 14132 | .named => |tok| @enumFromInt(@intFromEnum(try astgen.identAsString(tok))), |
| 14235 | 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 | 14141 | .unnamed_test => .unnamed_test, |
| 14237 | .decltest => .decltest, | |
| 14238 | 14142 | .@"comptime" => .@"comptime", |
| 14239 | 14143 | .@"usingnamespace" => .@"usingnamespace", |
| 14240 | 14144 | }, |
| ... | ... | @@ -14243,14 +14147,11 @@ fn setDeclaration( |
| 14243 | 14147 | .value_body_len = @intCast(value_len), |
| 14244 | 14148 | .is_pub = is_pub, |
| 14245 | 14149 | .is_export = is_export, |
| 14246 | .has_doc_comment = true_doc_comment != .empty, | |
| 14150 | .test_is_decltest = name == .decltest, | |
| 14247 | 14151 | .has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0, |
| 14248 | 14152 | }, |
| 14249 | 14153 | }; |
| 14250 | 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 | 14155 | if (extra.flags.has_align_linksection_addrspace) { |
| 14255 | 14156 | try astgen.extra.appendSlice(gpa, &.{ |
| 14256 | 14157 | align_len, |
lib/std/zig/Zir.zig+12-26| ... | ... | @@ -2612,20 +2612,19 @@ pub const Inst = struct { |
| 2612 | 2612 | }; |
| 2613 | 2613 | |
| 2614 | 2614 | /// 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 | |
| 2620 | 2619 | /// - for each `value_body_len` |
| 2621 | 2620 | /// - 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 | |
| 2623 | 2622 | /// - for each `align_body_len` |
| 2624 | 2623 | /// - 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 | |
| 2626 | 2625 | /// - for each `linksection_body_len` |
| 2627 | 2626 | /// - 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 | |
| 2629 | 2628 | /// - for each `addrspace_body_len` |
| 2630 | 2629 | /// - body to be exited via `break_inline` to this `declaration` instruction |
| 2631 | 2630 | pub const Declaration = struct { |
| ... | ... | @@ -2643,7 +2642,7 @@ pub const Inst = struct { |
| 2643 | 2642 | value_body_len: u28, |
| 2644 | 2643 | is_pub: bool, |
| 2645 | 2644 | is_export: bool, |
| 2646 | has_doc_comment: bool, | |
| 2645 | test_is_decltest: bool, | |
| 2647 | 2646 | has_align_linksection_addrspace: bool, |
| 2648 | 2647 | }; |
| 2649 | 2648 | |
| ... | ... | @@ -2651,9 +2650,6 @@ pub const Inst = struct { |
| 2651 | 2650 | @"comptime" = std.math.maxInt(u32), |
| 2652 | 2651 | @"usingnamespace" = std.math.maxInt(u32) - 1, |
| 2653 | 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 | 2653 | /// Other values are `NullTerminatedString` values, i.e. index into |
| 2658 | 2654 | /// `string_bytes`. If the byte referenced is 0, the decl is a named |
| 2659 | 2655 | /// test, and the actual name begins at the following byte. |
| ... | ... | @@ -2661,13 +2657,13 @@ pub const Inst = struct { |
| 2661 | 2657 | |
| 2662 | 2658 | pub fn isNamedTest(name: Name, zir: Zir) bool { |
| 2663 | 2659 | return switch (name) { |
| 2664 | .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => false, | |
| 2660 | .@"comptime", .@"usingnamespace", .unnamed_test => false, | |
| 2665 | 2661 | _ => zir.string_bytes[@intFromEnum(name)] == 0, |
| 2666 | 2662 | }; |
| 2667 | 2663 | } |
| 2668 | 2664 | pub fn toString(name: Name, zir: Zir) ?NullTerminatedString { |
| 2669 | 2665 | switch (name) { |
| 2670 | .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => return null, | |
| 2666 | .@"comptime", .@"usingnamespace", .unnamed_test => return null, | |
| 2671 | 2667 | _ => {}, |
| 2672 | 2668 | } |
| 2673 | 2669 | const idx: u32 = @intFromEnum(name); |
| ... | ... | @@ -2688,7 +2684,6 @@ pub const Inst = struct { |
| 2688 | 2684 | |
| 2689 | 2685 | pub fn getBodies(declaration: Declaration, extra_end: u32, zir: Zir) Bodies { |
| 2690 | 2686 | var extra_index: u32 = extra_end; |
| 2691 | extra_index += @intFromBool(declaration.flags.has_doc_comment); | |
| 2692 | 2687 | const value_body_len = declaration.flags.value_body_len; |
| 2693 | 2688 | const align_body_len, const linksection_body_len, const addrspace_body_len = lens: { |
| 2694 | 2689 | if (!declaration.flags.has_align_linksection_addrspace) { |
| ... | ... | @@ -3059,7 +3054,6 @@ pub const Inst = struct { |
| 3059 | 3054 | /// 0bX000: whether corresponding field has a type expression |
| 3060 | 3055 | /// 9. fields: { // for every fields_len |
| 3061 | 3056 | /// field_name: u32, |
| 3062 | /// doc_comment: NullTerminatedString, // .empty if no doc comment | |
| 3063 | 3057 | /// field_type: Ref, // if corresponding bit is not set. none means anytype. |
| 3064 | 3058 | /// field_type_body_len: u32, // if corresponding bit is set |
| 3065 | 3059 | /// align_body_len: u32, // if corresponding bit is set |
| ... | ... | @@ -3220,7 +3214,6 @@ pub const Inst = struct { |
| 3220 | 3214 | /// - the bit is whether corresponding field has an value expression |
| 3221 | 3215 | /// 9. fields: { // for every fields_len |
| 3222 | 3216 | /// field_name: u32, |
| 3223 | /// doc_comment: u32, // .empty if no doc_comment | |
| 3224 | 3217 | /// value: Ref, // if corresponding bit is set |
| 3225 | 3218 | /// } |
| 3226 | 3219 | pub const EnumDecl = struct { |
| ... | ... | @@ -3263,9 +3256,7 @@ pub const Inst = struct { |
| 3263 | 3256 | /// 0bX000: unused |
| 3264 | 3257 | /// 9. fields: { // for every fields_len |
| 3265 | 3258 | /// field_name: NullTerminatedString, // null terminated string index |
| 3266 | /// doc_comment: NullTerminatedString, // .empty if no doc comment | |
| 3267 | 3259 | /// field_type: Ref, // if corresponding bit is set |
| 3268 | /// - if none, means `anytype`. | |
| 3269 | 3260 | /// align: Ref, // if corresponding bit is set |
| 3270 | 3261 | /// tag_value: Ref, // if corresponding bit is set |
| 3271 | 3262 | /// } |
| ... | ... | @@ -3328,10 +3319,7 @@ pub const Inst = struct { |
| 3328 | 3319 | }; |
| 3329 | 3320 | |
| 3330 | 3321 | /// 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 | |
| 3335 | 3323 | pub const ErrorSetDecl = struct { |
| 3336 | 3324 | fields_len: u32, |
| 3337 | 3325 | }; |
| ... | ... | @@ -3474,8 +3462,6 @@ pub const Inst = struct { |
| 3474 | 3462 | pub const Param = struct { |
| 3475 | 3463 | /// Null-terminated string index. |
| 3476 | 3464 | name: NullTerminatedString, |
| 3477 | /// Null-terminated string index. | |
| 3478 | doc_comment: NullTerminatedString, | |
| 3479 | 3465 | /// The body contains the type of the parameter. |
| 3480 | 3466 | body_len: u32, |
| 3481 | 3467 | }; |
| ... | ... | @@ -4163,7 +4149,7 @@ fn findTrackableInner( |
| 4163 | 4149 | const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0; |
| 4164 | 4150 | cur_bit_bag >>= 1; |
| 4165 | 4151 | |
| 4166 | fields_extra_index += 2; // field_name, doc_comment | |
| 4152 | fields_extra_index += 1; // field_name | |
| 4167 | 4153 | |
| 4168 | 4154 | if (has_type_body) { |
| 4169 | 4155 | const field_type_body_len = zir.extra[fields_extra_index]; |
src/Sema.zig+5-8| ... | ... | @@ -3399,8 +3399,8 @@ fn zirErrorSetDecl( |
| 3399 | 3399 | try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len); |
| 3400 | 3400 | |
| 3401 | 3401 | 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) { | |
| 3404 | 3404 | const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]); |
| 3405 | 3405 | const name = sema.code.nullTerminatedString(name_index); |
| 3406 | 3406 | const name_ip = try zcu.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls); |
| ... | ... | @@ -36827,7 +36827,7 @@ fn structFields( |
| 36827 | 36827 | if (is_comptime) struct_type.setFieldComptime(ip, field_i); |
| 36828 | 36828 | |
| 36829 | 36829 | 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 | |
| 36831 | 36831 | |
| 36832 | 36832 | fields[field_i] = .{}; |
| 36833 | 36833 | |
| ... | ... | @@ -37007,7 +37007,7 @@ fn structFieldInits( |
| 37007 | 37007 | const has_type_body = @as(u1, @truncate(cur_bit_bag)) != 0; |
| 37008 | 37008 | cur_bit_bag >>= 1; |
| 37009 | 37009 | |
| 37010 | extra_index += 2; // field_name, doc_comment | |
| 37010 | extra_index += 1; // field_name | |
| 37011 | 37011 | |
| 37012 | 37012 | fields[field_i] = .{}; |
| 37013 | 37013 | |
| ... | ... | @@ -37228,9 +37228,6 @@ fn unionFields( |
| 37228 | 37228 | const field_name_zir = zir.nullTerminatedString(field_name_index); |
| 37229 | 37229 | extra_index += 1; |
| 37230 | 37230 | |
| 37231 | // doc_comment | |
| 37232 | extra_index += 1; | |
| 37233 | ||
| 37234 | 37231 | const field_type_ref: Zir.Inst.Ref = if (has_type) blk: { |
| 37235 | 37232 | const field_type_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| 37236 | 37233 | extra_index += 1; |
| ... | ... | @@ -39095,7 +39092,7 @@ pub fn resolveDeclaredEnum( |
| 39095 | 39092 | |
| 39096 | 39093 | const field_name_index: Zir.NullTerminatedString = @enumFromInt(zir.extra[extra_index]); |
| 39097 | 39094 | const field_name_zir = zir.nullTerminatedString(field_name_index); |
| 39098 | extra_index += 2; // field name, doc comment | |
| 39095 | extra_index += 1; // field name | |
| 39099 | 39096 | |
| 39100 | 39097 | const field_name = try ip.getOrPutString(gpa, pt.tid, field_name_zir, .no_embedded_nulls); |
| 39101 | 39098 |
src/Zcu.zig+18-7| ... | ... | @@ -2643,6 +2643,9 @@ pub fn mapOldZirToNew( |
| 2643 | 2643 | // Maps test name to `declaration` instruction. |
| 2644 | 2644 | var named_tests: std.StringHashMapUnmanaged(Zir.Inst.Index) = .empty; |
| 2645 | 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 | 2649 | // All unnamed tests, in order, for a best-effort match. |
| 2647 | 2650 | var unnamed_tests: std.ArrayListUnmanaged(Zir.Inst.Index) = .empty; |
| 2648 | 2651 | defer unnamed_tests.deinit(gpa); |
| ... | ... | @@ -2660,12 +2663,16 @@ pub fn mapOldZirToNew( |
| 2660 | 2663 | switch (old_decl.name) { |
| 2661 | 2664 | .@"comptime" => try comptime_decls.append(gpa, old_decl_inst), |
| 2662 | 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 | 2668 | const name_nts = old_decl.name.toString(old_zir).?; |
| 2666 | 2669 | const name = old_zir.nullTerminatedString(name_nts); |
| 2667 | 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 | 2676 | } else { |
| 2670 | 2677 | try named_decls.put(gpa, name, old_decl_inst); |
| 2671 | 2678 | } |
| ... | ... | @@ -2683,8 +2690,8 @@ pub fn mapOldZirToNew( |
| 2683 | 2690 | const new_decl, _ = new_zir.getDeclaration(new_decl_inst); |
| 2684 | 2691 | // Attempt to match this to a declaration in the old ZIR: |
| 2685 | 2692 | // * 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. | |
| 2688 | 2695 | // * For comptime blocks, we match based on order. |
| 2689 | 2696 | // * For usingnamespace decls, we match based on order. |
| 2690 | 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 | 2706 | defer usingnamespace_decl_idx += 1; |
| 2700 | 2707 | break :inst usingnamespace_decls.items[usingnamespace_decl_idx]; |
| 2701 | 2708 | }, |
| 2702 | .unnamed_test, .decltest => inst: { | |
| 2709 | .unnamed_test => inst: { | |
| 2703 | 2710 | if (unnamed_test_idx == unnamed_tests.items.len) continue; |
| 2704 | 2711 | defer unnamed_test_idx += 1; |
| 2705 | 2712 | break :inst unnamed_tests.items[unnamed_test_idx]; |
| ... | ... | @@ -2708,7 +2715,11 @@ pub fn mapOldZirToNew( |
| 2708 | 2715 | const name_nts = new_decl.name.toString(new_zir).?; |
| 2709 | 2716 | const name = new_zir.nullTerminatedString(name_nts); |
| 2710 | 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 | 2723 | } else { |
| 2713 | 2724 | break :inst named_decls.get(name) orelse continue; |
| 2714 | 2725 | } |
| ... | ... | @@ -3329,7 +3340,7 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv |
| 3329 | 3340 | else => a: { |
| 3330 | 3341 | if (!comp.config.is_test) break :a false; |
| 3331 | 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 | 3344 | const nav = ip.getCau(cau).owner.unwrap().nav; |
| 3334 | 3345 | const fqn_slice = ip.getNav(nav).fqn.toSlice(ip); |
| 3335 | 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 | 462 | while (it.next()) |decl_inst| { |
| 463 | 463 | const decl_name = old_zir.getDeclaration(decl_inst)[0].name; |
| 464 | 464 | switch (decl_name) { |
| 465 | .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue, | |
| 465 | .@"comptime", .@"usingnamespace", .unnamed_test => continue, | |
| 466 | 466 | _ => if (decl_name.isNamedTest(old_zir)) continue, |
| 467 | 467 | } |
| 468 | 468 | const name_zir = decl_name.toString(old_zir).?; |
| ... | ... | @@ -481,7 +481,7 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void { |
| 481 | 481 | while (it.next()) |decl_inst| { |
| 482 | 482 | const decl_name = new_zir.getDeclaration(decl_inst)[0].name; |
| 483 | 483 | switch (decl_name) { |
| 484 | .@"comptime", .@"usingnamespace", .unnamed_test, .decltest => continue, | |
| 484 | .@"comptime", .@"usingnamespace", .unnamed_test => continue, | |
| 485 | 485 | _ => if (decl_name.isNamedTest(new_zir)) continue, |
| 486 | 486 | } |
| 487 | 487 | const name_zir = decl_name.toString(new_zir).?; |
| ... | ... | @@ -1929,22 +1929,12 @@ const ScanDeclIter = struct { |
| 1929 | 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 | 1932 | _ => if (declaration.name.isNamedTest(zir)) info: { |
| 1944 | 1933 | // We consider these to be unnamed since the decl name can be adjusted to avoid conflicts if necessary. |
| 1945 | 1934 | if (iter.pass != .unnamed) return; |
| 1935 | const prefix = if (declaration.flags.test_is_decltest) "decltest" else "test"; | |
| 1946 | 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 | 1938 | .@"test", |
| 1949 | 1939 | true, |
| 1950 | 1940 | }; |
src/link/Dwarf.zig+1-4| ... | ... | @@ -2208,7 +2208,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2208 | 2208 | .@"comptime", |
| 2209 | 2209 | .@"usingnamespace", |
| 2210 | 2210 | .unnamed_test, |
| 2211 | .decltest, | |
| 2212 | 2211 | => DW.ACCESS.private, |
| 2213 | 2212 | _ => if (decl_extra.name.isNamedTest(file.zir)) |
| 2214 | 2213 | DW.ACCESS.private |
| ... | ... | @@ -2258,7 +2257,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2258 | 2257 | .@"comptime", |
| 2259 | 2258 | .@"usingnamespace", |
| 2260 | 2259 | .unnamed_test, |
| 2261 | .decltest, | |
| 2262 | 2260 | => DW.ACCESS.private, |
| 2263 | 2261 | _ => if (decl_extra.name.isNamedTest(file.zir)) |
| 2264 | 2262 | DW.ACCESS.private |
| ... | ... | @@ -2306,7 +2304,6 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 2306 | 2304 | .@"comptime", |
| 2307 | 2305 | .@"usingnamespace", |
| 2308 | 2306 | .unnamed_test, |
| 2309 | .decltest, | |
| 2310 | 2307 | => DW.ACCESS.private, |
| 2311 | 2308 | _ => if (decl_extra.name.isNamedTest(file.zir)) |
| 2312 | 2309 | DW.ACCESS.private |
| ... | ... | @@ -2548,7 +2545,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 2548 | 2545 | const decl_extra = file.zir.extraData(Zir.Inst.Declaration, decl_inst.data.declaration.payload_index); |
| 2549 | 2546 | |
| 2550 | 2547 | const is_test = switch (decl_extra.data.name) { |
| 2551 | .unnamed_test, .decltest => true, | |
| 2548 | .unnamed_test => true, | |
| 2552 | 2549 | .@"comptime", .@"usingnamespace" => false, |
| 2553 | 2550 | _ => decl_extra.data.name.isNamedTest(file.zir), |
| 2554 | 2551 | }; |
src/print_zir.zig+5-38| ... | ... | @@ -952,11 +952,6 @@ const Writer = struct { |
| 952 | 952 | std.zig.fmtEscapes(self.code.nullTerminatedString(extra.data.name)), |
| 953 | 953 | }); |
| 954 | 954 | |
| 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 | 955 | try self.writeBracedBody(stream, body); |
| 961 | 956 | try stream.writeAll(") "); |
| 962 | 957 | try self.writeSrcTok(stream, inst_data.src_tok); |
| ... | ... | @@ -1482,7 +1477,6 @@ const Writer = struct { |
| 1482 | 1477 | const fields_per_u32 = 32 / bits_per_field; |
| 1483 | 1478 | const bit_bags_count = std.math.divCeil(usize, fields_len, fields_per_u32) catch unreachable; |
| 1484 | 1479 | const Field = struct { |
| 1485 | doc_comment_index: Zir.NullTerminatedString, | |
| 1486 | 1480 | type_len: u32 = 0, |
| 1487 | 1481 | align_len: u32 = 0, |
| 1488 | 1482 | init_len: u32 = 0, |
| ... | ... | @@ -1512,11 +1506,8 @@ const Writer = struct { |
| 1512 | 1506 | |
| 1513 | 1507 | const field_name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]); |
| 1514 | 1508 | extra_index += 1; |
| 1515 | const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]); | |
| 1516 | extra_index += 1; | |
| 1517 | 1509 | |
| 1518 | 1510 | fields[field_i] = .{ |
| 1519 | .doc_comment_index = doc_comment_index, | |
| 1520 | 1511 | .is_comptime = is_comptime, |
| 1521 | 1512 | .name = field_name_index, |
| 1522 | 1513 | }; |
| ... | ... | @@ -1544,7 +1535,6 @@ const Writer = struct { |
| 1544 | 1535 | self.indent += 2; |
| 1545 | 1536 | |
| 1546 | 1537 | for (fields, 0..) |field, i| { |
| 1547 | try self.writeDocComment(stream, field.doc_comment_index); | |
| 1548 | 1538 | try stream.writeByteNTimes(' ', self.indent); |
| 1549 | 1539 | try self.writeFlag(stream, "comptime ", field.is_comptime); |
| 1550 | 1540 | if (field.name != .empty) { |
| ... | ... | @@ -1721,10 +1711,7 @@ const Writer = struct { |
| 1721 | 1711 | const field_name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]); |
| 1722 | 1712 | const field_name = self.code.nullTerminatedString(field_name_index); |
| 1723 | 1713 | extra_index += 1; |
| 1724 | const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]); | |
| 1725 | extra_index += 1; | |
| 1726 | 1714 | |
| 1727 | try self.writeDocComment(stream, doc_comment_index); | |
| 1728 | 1715 | try stream.writeByteNTimes(' ', self.indent); |
| 1729 | 1716 | try stream.print("{p}", .{std.zig.fmtId(field_name)}); |
| 1730 | 1717 | |
| ... | ... | @@ -1870,11 +1857,6 @@ const Writer = struct { |
| 1870 | 1857 | const field_name = self.code.nullTerminatedString(@enumFromInt(self.code.extra[extra_index])); |
| 1871 | 1858 | extra_index += 1; |
| 1872 | 1859 | |
| 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 | 1860 | try stream.writeByteNTimes(' ', self.indent); |
| 1879 | 1861 | try stream.print("{p}", .{std.zig.fmtId(field_name)}); |
| 1880 | 1862 | |
| ... | ... | @@ -1987,12 +1969,10 @@ const Writer = struct { |
| 1987 | 1969 | self.indent += 2; |
| 1988 | 1970 | |
| 1989 | 1971 | 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) { | |
| 1992 | 1974 | const name_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index]); |
| 1993 | 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 | 1976 | try stream.writeByteNTimes(' ', self.indent); |
| 1997 | 1977 | try stream.print("{p},\n", .{std.zig.fmtId(name)}); |
| 1998 | 1978 | } |
| ... | ... | @@ -2740,9 +2720,6 @@ const Writer = struct { |
| 2740 | 2720 | fn writeDeclaration(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| 2741 | 2721 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].declaration; |
| 2742 | 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; | |
| 2746 | 2723 | |
| 2747 | 2724 | const prev_parent_decl_node = self.parent_decl_node; |
| 2748 | 2725 | defer self.parent_decl_node = prev_parent_decl_node; |
| ... | ... | @@ -2754,10 +2731,11 @@ const Writer = struct { |
| 2754 | 2731 | .@"comptime" => try stream.writeAll("comptime"), |
| 2755 | 2732 | .@"usingnamespace" => try stream.writeAll("usingnamespace"), |
| 2756 | 2733 | .unnamed_test => try stream.writeAll("test"), |
| 2757 | .decltest => try stream.print("decltest '{s}'", .{self.code.nullTerminatedString(doc_comment.?)}), | |
| 2758 | 2734 | _ => { |
| 2759 | 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 | 2739 | try stream.print("{s}'{s}'", .{ prefix, self.code.nullTerminatedString(name) }); |
| 2762 | 2740 | }, |
| 2763 | 2741 | } |
| ... | ... | @@ -2963,17 +2941,6 @@ const Writer = struct { |
| 2963 | 2941 | } |
| 2964 | 2942 | } |
| 2965 | 2943 | |
| 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 | 2944 | fn writeBody(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void { |
| 2978 | 2945 | for (body) |inst| { |
| 2979 | 2946 | try stream.writeByteNTimes(' ', self.indent); |