@@ -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(¶m_gz, &.{}, tag, name_token, param_name, param.first_doc_comment );
1380
+ const param_inst = try block_scope.addParam(¶m_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(¶m_gz, param_insts.items, tag, name_token, param_name, param.first_doc_comment );
4264
+ const param_inst = try decl_gz.addParam(¶m_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,22 +12634,15 @@ 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();
12729
12640
const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(param_body, prev_param_insts);
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,
0 commit comments