Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: more progress on incremental #19273

Merged
merged 10 commits into from
Mar 14, 2024
50 changes: 49 additions & 1 deletion lib/std/zig/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13496,6 +13496,15 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast.
const node_tags = tree.nodes.items(.tag);
const main_tokens = tree.nodes.items(.main_token);
const token_tags = tree.tokens.items(.tag);

// We don't have shadowing for test names, so we just track those for duplicate reporting locally.
var named_tests: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.Node.Index) = .{};
var decltests: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.Node.Index) = .{};
defer {
named_tests.deinit(gpa);
decltests.deinit(gpa);
}

var decl_count: u32 = 0;
for (members) |member_node| {
const name_token = switch (node_tags[member_node]) {
Expand Down Expand Up @@ -13525,11 +13534,50 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const Ast.
break :blk ident;
},

.@"comptime", .@"usingnamespace", .test_decl => {
.@"comptime", .@"usingnamespace" => {
decl_count += 1;
continue;
},

.test_decl => {
decl_count += 1;
// We don't want shadowing detection here, and test names work a bit differently, so
// we must do the redeclaration detection ourselves.
const test_name_token = main_tokens[member_node] + 1;
switch (token_tags[test_name_token]) {
else => {}, // unnamed test
.string_literal => {
const name = try astgen.strLitAsString(test_name_token);
const gop = try named_tests.getOrPut(gpa, name.index);
if (gop.found_existing) {
const name_slice = astgen.string_bytes.items[@intFromEnum(name.index)..][0..name.len];
const name_duped = try gpa.dupe(u8, name_slice);
defer gpa.free(name_duped);
try astgen.appendErrorNodeNotes(member_node, "duplicate test name '{s}'", .{name_duped}, &.{
try astgen.errNoteNode(gop.value_ptr.*, "other test here", .{}),
});
} else {
gop.value_ptr.* = member_node;
}
},
.identifier => {
const name = try astgen.identAsString(test_name_token);
const gop = try decltests.getOrPut(gpa, name);
if (gop.found_existing) {
const name_slice = mem.span(astgen.nullTerminatedString(name));
const name_duped = try gpa.dupe(u8, name_slice);
defer gpa.free(name_duped);
try astgen.appendErrorNodeNotes(member_node, "duplicate decltest '{s}'", .{name_duped}, &.{
try astgen.errNoteNode(gop.value_ptr.*, "other decltest here", .{}),
});
} else {
gop.value_ptr.* = member_node;
}
},
}
continue;
},

else => continue,
};

Expand Down
13 changes: 10 additions & 3 deletions src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ src_hash_deps: std.AutoArrayHashMapUnmanaged(TrackedInst.Index, DepEntry.Index)
/// Dependencies on the value of a Decl.
/// Value is index into `dep_entries` of the first dependency on this Decl value.
decl_val_deps: std.AutoArrayHashMapUnmanaged(DeclIndex, DepEntry.Index) = .{},
/// Dependencies on the IES of a runtime function.
/// Value is index into `dep_entries` of the first dependency on this Decl value.
func_ies_deps: std.AutoArrayHashMapUnmanaged(Index, DepEntry.Index) = .{},
/// Dependencies on the full set of names in a ZIR namespace.
/// Key refers to a `struct_decl`, `union_decl`, etc.
/// Value is index into `dep_entries` of the first dependency on this namespace.
Expand Down Expand Up @@ -167,6 +170,7 @@ pub const Depender = enum(u32) {
pub const Dependee = union(enum) {
src_hash: TrackedInst.Index,
decl_val: DeclIndex,
func_ies: Index,
namespace: TrackedInst.Index,
namespace_name: NamespaceNameKey,
};
Expand Down Expand Up @@ -212,6 +216,7 @@ pub fn dependencyIterator(ip: *const InternPool, dependee: Dependee) DependencyI
const first_entry = switch (dependee) {
.src_hash => |x| ip.src_hash_deps.get(x),
.decl_val => |x| ip.decl_val_deps.get(x),
.func_ies => |x| ip.func_ies_deps.get(x),
.namespace => |x| ip.namespace_deps.get(x),
.namespace_name => |x| ip.namespace_name_deps.get(x),
} orelse return .{
Expand Down Expand Up @@ -251,6 +256,7 @@ pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: Depender, depend
const gop = try switch (tag) {
.src_hash => ip.src_hash_deps,
.decl_val => ip.decl_val_deps,
.func_ies => ip.func_ies_deps,
.namespace => ip.namespace_deps,
.namespace_name => ip.namespace_name_deps,
}.getOrPut(gpa, dependee_payload);
Expand Down Expand Up @@ -4324,6 +4330,7 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void {

ip.src_hash_deps.deinit(gpa);
ip.decl_val_deps.deinit(gpa);
ip.func_ies_deps.deinit(gpa);
ip.namespace_deps.deinit(gpa);
ip.namespace_name_deps.deinit(gpa);

Expand Down Expand Up @@ -7103,7 +7110,7 @@ pub fn getGeneratedTagEnumType(ip: *InternPool, gpa: Allocator, ini: GeneratedTa
return @enumFromInt(gop.index);
}

pub const OpaqueTypeIni = struct {
pub const OpaqueTypeInit = struct {
has_namespace: bool,
key: union(enum) {
declared: struct {
Expand All @@ -7117,7 +7124,7 @@ pub const OpaqueTypeIni = struct {
},
};

pub fn getOpaqueType(ip: *InternPool, gpa: Allocator, ini: OpaqueTypeIni) Allocator.Error!WipNamespaceType.Result {
pub fn getOpaqueType(ip: *InternPool, gpa: Allocator, ini: OpaqueTypeInit) Allocator.Error!WipNamespaceType.Result {
const adapter: KeyAdapter = .{ .intern_pool = ip };
const gop = try ip.map.getOrPutAdapted(gpa, Key{ .opaque_type = switch (ini.key) {
.declared => |d| .{ .declared = .{
Expand Down Expand Up @@ -9216,7 +9223,7 @@ pub fn funcTypeParamsLen(ip: *const InternPool, i: Index) u32 {
return ip.extra.items[start + std.meta.fieldIndex(Tag.TypeFunction, "params_len").?];
}

fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index {
pub fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index {
const tags = ip.items.items(.tag);
return switch (tags[@intFromEnum(i)]) {
.func_coerced => {
Expand Down
Loading