From fc9430f56798a53f9393a697f4ccd6bf9981b970 Mon Sep 17 00:00:00 2001 From: Martin Wickham Date: Thu, 3 Jun 2021 15:39:26 -0500 Subject: Breaking hash map changes for 0.8.0 - hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig --- src/type.zig | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index 14646450aa..3e6c810b20 100644 --- a/src/type.zig +++ b/src/type.zig @@ -596,6 +596,15 @@ pub const Type = extern union { return hasher.final(); } + pub const HashContext = struct { + pub fn hash(self: @This(), t: Type) u64 { + return t.hash(); + } + pub fn eql(self: @This(), a: Type, b: Type) bool { + return a.eql(b); + } + }; + pub fn copy(self: Type, allocator: *Allocator) error{OutOfMemory}!Type { if (self.tag_if_small_enough < Tag.no_payload_count) { return Type{ .tag_if_small_enough = self.tag_if_small_enough }; @@ -1147,8 +1156,8 @@ pub const Type = extern union { .@"struct" => { // TODO introduce lazy value mechanism const struct_obj = self.castTag(.@"struct").?.data; - for (struct_obj.fields.entries.items) |entry| { - if (entry.value.ty.hasCodeGenBits()) + for (struct_obj.fields.values()) |value| { + if (value.ty.hasCodeGenBits()) return true; } else { return false; @@ -1169,8 +1178,8 @@ pub const Type = extern union { }, .@"union" => { const union_obj = self.castTag(.@"union").?.data; - for (union_obj.fields.entries.items) |entry| { - if (entry.value.ty.hasCodeGenBits()) + for (union_obj.fields.values()) |value| { + if (value.ty.hasCodeGenBits()) return true; } else { return false; @@ -1181,8 +1190,8 @@ pub const Type = extern union { if (union_obj.tag_ty.hasCodeGenBits()) { return true; } - for (union_obj.fields.entries.items) |entry| { - if (entry.value.ty.hasCodeGenBits()) + for (union_obj.fields.values()) |value| { + if (value.ty.hasCodeGenBits()) return true; } else { return false; @@ -1380,10 +1389,9 @@ pub const Type = extern union { // like we have in stage1. const struct_obj = self.castTag(.@"struct").?.data; var biggest: u32 = 0; - for (struct_obj.fields.entries.items) |entry| { - const field_ty = entry.value.ty; - if (!field_ty.hasCodeGenBits()) continue; - const field_align = field_ty.abiAlignment(target); + for (struct_obj.fields.values()) |field| { + if (!field.ty.hasCodeGenBits()) continue; + const field_align = field.ty.abiAlignment(target); if (field_align > biggest) { return field_align; } @@ -1399,10 +1407,9 @@ pub const Type = extern union { .union_tagged => { const union_obj = self.castTag(.union_tagged).?.data; var biggest: u32 = union_obj.tag_ty.abiAlignment(target); - for (union_obj.fields.entries.items) |entry| { - const field_ty = entry.value.ty; - if (!field_ty.hasCodeGenBits()) continue; - const field_align = field_ty.abiAlignment(target); + for (union_obj.fields.values()) |field| { + if (!field.ty.hasCodeGenBits()) continue; + const field_align = field.ty.abiAlignment(target); if (field_align > biggest) { biggest = field_align; } @@ -1413,10 +1420,9 @@ pub const Type = extern union { .@"union" => { const union_obj = self.castTag(.@"union").?.data; var biggest: u32 = 0; - for (union_obj.fields.entries.items) |entry| { - const field_ty = entry.value.ty; - if (!field_ty.hasCodeGenBits()) continue; - const field_align = field_ty.abiAlignment(target); + for (union_obj.fields.values()) |field| { + if (!field.ty.hasCodeGenBits()) continue; + const field_align = field.ty.abiAlignment(target); if (field_align > biggest) { biggest = field_align; } @@ -2415,9 +2421,8 @@ pub const Type = extern union { .@"struct" => { const s = ty.castTag(.@"struct").?.data; assert(s.haveFieldTypes()); - for (s.fields.entries.items) |entry| { - const field_ty = entry.value.ty; - if (field_ty.onePossibleValue() == null) { + for (s.fields.values()) |field| { + if (field.ty.onePossibleValue() == null) { return null; } } @@ -2426,7 +2431,7 @@ pub const Type = extern union { .enum_full => { const enum_full = ty.castTag(.enum_full).?.data; if (enum_full.fields.count() == 1) { - return enum_full.values.entries.items[0].key; + return enum_full.values.keys()[0]; } else { return null; } @@ -2583,11 +2588,11 @@ pub const Type = extern union { switch (ty.tag()) { .enum_full, .enum_nonexhaustive => { const enum_full = ty.cast(Payload.EnumFull).?.data; - return enum_full.fields.entries.items[field_index].key; + return enum_full.fields.keys()[field_index]; }, .enum_simple => { const enum_simple = ty.castTag(.enum_simple).?.data; - return enum_simple.fields.entries.items[field_index].key; + return enum_simple.fields.keys()[field_index]; }, .atomic_ordering, .atomic_rmw_op, -- cgit v1.2.3