aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2022-03-08 20:44:58 -0800
committerAndrew Kelley <andrew@ziglang.org>2022-03-10 14:20:16 -0700
commit569870ca41e73c64d8dc9f1eccfef3529caf2266 (patch)
tree8a4ec47628cacc1723efbff01ba36ebc147a86ad /src/Module.zig
parent0b82c02945c69e2e0465b5a4d9de471ea3c76d50 (diff)
downloadzig-569870ca41e73c64d8dc9f1eccfef3529caf2266.tar.gz
zig-569870ca41e73c64d8dc9f1eccfef3529caf2266.zip
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.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 93e4b87d5b..693cc3b5a0 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -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 };