stage2: error_set_merged type equality

This implements type equality for error sets. This is done
through element-wise error set comparison.

Inferred error sets are always distinct types and other error sets are
always sorted. See #11022.
This commit is contained in:
Mitchell Hashimoto
2022-03-08 20:44:58 -08:00
committed by Andrew Kelley
parent 0b82c02945
commit 569870ca41
8 changed files with 185 additions and 58 deletions

View File

@@ -824,7 +824,7 @@ pub const ErrorSet = struct {
/// Offset from Decl node index, points to the error set AST node.
node_offset: i32,
/// The string bytes are stored in the owner Decl arena.
/// They are in the same order they appear in the AST.
/// These must be in sorted order. See sortNames.
names: NameMap,
pub const NameMap = std.StringArrayHashMapUnmanaged(void);
@@ -836,6 +836,18 @@ pub const ErrorSet = struct {
.lazy = .{ .node_offset = self.node_offset },
};
}
/// sort the NameMap. This should be called whenever the map is modified.
/// alloc should be the allocator used for the NameMap data.
pub fn sortNames(names: *NameMap) void {
const Context = struct {
keys: [][]const u8,
pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool {
return std.mem.lessThan(u8, ctx.keys[a_index], ctx.keys[b_index]);
}
};
names.sort(Context{ .keys = names.keys() });
}
};
pub const RequiresComptime = enum { no, yes, unknown, wip };