aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig53
1 files changed, 29 insertions, 24 deletions
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,