8000 zig/src/type.zig at link-tests · dominictarr/zig · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
6263 lines (5711 loc) · 226 KB

type.zig

File metadata and controls

6263 lines (5711 loc) · 226 KB
const std = @import("std");
const Value = @import("value.zig").Value;
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const Target = std.Target;
const Module = @import("Module.zig");
const log = std.log.scoped(.Type);
const target_util = @import("target.zig");
const TypedValue = @import("TypedValue.zig");
const file_struct = @This();
/// This is the raw data, with no bookkeeping, no memory awareness, no de-duplication.
/// It's important for this type to be small.
/// Types are not de-duplicated, which helps with multi-threading since it obviates the requirement
/// of obtaining a lock on a global type table, as well as making the
/// garbage collection bookkeeping simpler.
/// This union takes advantage of the fact that the first page of memory
/// is unmapped, giving us 4096 possible enum tags that have no payload.
pub const Type = extern union {
/// If the tag value is less than Tag.no_payload_count, then no pointer
/// dereference is needed.
tag_if_small_enough: Tag,
ptr_otherwise: *Payload,
pub fn zigTypeTag(ty: Type) std.builtin.TypeId {
return ty.zigTypeTagOrPoison() catch unreachable;
}
pub fn zigTypeTagOrPoison(ty: Type) error{GenericPoison}!std.builtin.TypeId {
switch (ty.tag()) {
.generic_poison => return error.GenericPoison,
.u1,
.u8,
.i8,
.u16,
.i16,
.u32,
.i32,
.u64,
.i64,
.u128,
.i128,
.usize,
.isize,
.c_short,
.c_ushort,
.c_int,
.c_uint,
.c_long,
.c_ulong,
.c_longlong,
.c_ulonglong,
.int_signed,
.int_unsigned,
=> return .Int,
.f16,
.f32,
.f64,
.f80,
.f128,
.c_longdouble,
=> return .Float,
.error_set,
.error_set_single,
.anyerror,
.error_set_inferred,
.error_set_merged,
=> return .ErrorSet,
.anyopaque, .@"opaque" => return .Opaque,
.bool => return .Bool,
.void => return .Void,
.type => return .Type,
.comptime_int => return .ComptimeInt,
.comptime_float => return .ComptimeFloat,
.noreturn => return .NoReturn,
.@"null" => return .Null,
.@"undefined" => return .Undefined,
.fn_noreturn_no_args => return .Fn,
.fn_void_no_args => return .Fn,
.fn_naked_noreturn_no_args => return .Fn,
.fn_ccc_void_no_args => return .Fn,
.function => return .Fn,
.array,
.array_u8_sentinel_0,
.array_u8,
.array_sentinel,
=> return .Array,
.vector => return .Vector,
.single_const_pointer_to_comptime_int,
.const_slice_u8,
.const_slice_u8_sentinel_0,
.single_const_pointer,
.single_mut_pointer,
.many_const_pointer,
.many_mut_pointer,
.c_const_pointer,
.c_mut_pointer,
.const_slice,
.mut_slice,
.pointer,
.inferred_alloc_const,
.inferred_alloc_mut,
.manyptr_u8,
.manyptr_const_u8,
.manyptr_const_u8_sentinel_0,
=> return .Pointer,
.optional,
.optional_single_const_pointer,
.optional_single_mut_pointer,
=> return .Optional,
.enum_literal => return .EnumLiteral,
.anyerror_void_error_union, .error_union => return .ErrorUnion,
.anyframe_T, .@"anyframe" => return .AnyFrame,
.empty_struct,
.empty_struct_literal,
.@"struct",
.call_options,
.prefetch_options,
.export_options,
.extern_options,
.tuple,
.anon_struct,
=> return .Struct,
.enum_full,
.enum_nonexhaustive,
.enum_simple,
.enum_numbered,
.atomic_order,
.atomic_rmw_op,
.calling_convention,
.address_space,
.float_mode,
.reduce_op,
=> return .Enum,
.@"union",
.union_tagged,
.type_info,
=> return .Union,
.bound_fn => unreachable,
.var_args_param => unreachable, // can be any type
}
}
pub fn isSelfComparable(ty: Type, is_equality_cmp: bool) bool {
return switch (ty.zigTypeTag()) {
.Int,
.Float,
.ComptimeFloat,
.ComptimeInt,
.Vector, // TODO some vectors require is_equality_cmp==true
=> true,
.Bool,
.Type,
.Void,
.ErrorSet,
.Fn,
.BoundFn,
.Opaque,
.AnyFrame,
.Enum,
.EnumLiteral,
=> is_equality_cmp,
.NoReturn,
.Array,
.Struct,
.Undefined,
.Null,
.ErrorUnion,
.Union,
.Frame,
=> false,
.Pointer => is_equality_cmp or ty.isCPtr(),
.Optional => {
if (!is_equality_cmp) return false;
var buf: Payload.ElemType = undefined;
return ty.optionalChild(&buf).isSelfComparable(is_equality_cmp);
},
};
}
pub fn initTag(comptime small_tag: Tag) Type {
comptime assert(@enumToInt(small_tag) < Tag.no_payload_count);
return .{ .tag_if_small_enough = small_tag };
}
pub fn initPayload(payload: *Payload) Type {
assert(@enumToInt(payload.tag) >= Tag.no_payload_count);
return .{ .ptr_otherwise = payload };
}
pub fn tag(self: Type) Tag {
if (@enumToInt(self.tag_if_small_enough) < Tag.no_payload_count) {
return self.tag_if_small_enough;
} else {
return self.ptr_otherwise.tag;
}
}
/// Prefer `castTag` to this.
pub fn cast(self: Type, comptime T: type) ?*T {
if (@hasField(T, "base_tag")) {
return self.castTag(T.base_tag);
}
if (@enumToInt(self.tag_if_small_enough) < Tag.no_payload_count) {
return null;
}
inline for (@typeInfo(Tag).Enum.fields) |field| {
if (field.value < Tag.no_payload_count)
continue;
const t = @intToEnum(Tag, field.value);
if (self.ptr_otherwise.tag == t) {
if (T == t.Type()) {
return @fieldParentPtr(T, "base", self.ptr_otherwise);
}
return null;
}
}
unreachable;
}
pub fn castTag(self: Type, comptime t: Tag) ?*t.Type() {
if (@enumToInt(self.tag_if_small_enough) < Tag.no_payload_count)
return null;
if (self.ptr_otherwise.tag == t)
return @fieldParentPtr(t.Type(), "base", self.ptr_otherwise);
return null;
}
pub fn castPointer(self: Type) ?*Payload.ElemType {
return switch (self.tag()) {
.single_const_pointer,
.single_mut_pointer,
.many_const_pointer,
.many_mut_pointer,
.c_const_pointer,
.c_mut_pointer,
.const_slice,
.mut_slice,
.optional_single_const_pointer,
.optional_single_mut_pointer,
.manyptr_u8,
.manyptr_const_u8,
.manyptr_const_u8_sentinel_0,
=> self.cast(Payload.ElemType),
.inferred_alloc_const => unreachable,
.inferred_alloc_mut => unreachable,
else => null,
};
}
/// If it is a function pointer, returns the function type. Otherwise returns null.
pub fn castPtrToFn(ty: Type) ?Type {
if (ty.zigTypeTag() != .Pointer) return null;
const elem_ty = ty.childType();
if (elem_ty.zigTypeTag() != .Fn) return null;
return elem_ty;
}
pub fn ptrIsMutable(ty: Type) bool {
return switch (ty.tag()) {
.single_const_pointer_to_comptime_int,
.const_slice_u8,
.const_slice_u8_sentinel_0,
.single_const_pointer,
.many_const_pointer,
.manyptr_const_u8,
.manyptr_const_u8_sentinel_0,
.c_const_pointer,
.const_slice,
=> false,
.single_mut_pointer,
.many_mut_pointer,
.manyptr_u8,
.c_mut_pointer,
.mut_slice,
=> true,
.pointer => ty.castTag(.pointer).?.data.mutable,
else => unreachable,
};
}
pub const ArrayInfo = struct { elem_type: Type, sentinel: ?Value = null, len: u64 };
pub fn arrayInfo(self: Type) ArrayInfo {
return .{
.len = self.arrayLen(),
.sentinel = self.sentinel(),
.elem_type = self.elemType(),
};
}
pub fn ptrInfo(self: Type) Payload.Pointer {
switch (self.tag()) {
.single_const_pointer_to_comptime_int => return .{ .data = .{
.pointee_type = Type.initTag(.comptime_int),
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .One,
} },
.const_slice_u8 => return .{ .data = .{
.pointee_type = Type.initTag(.u8),
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .Slice,
} },
.const_slice_u8_sentinel_0 => return .{ .data = .{
.pointee_type = Type.initTag(.u8),
.sentinel = Value.zero,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .Slice,
} },
.single_const_pointer => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .One,
} },
.single_mut_pointer => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = true,
.@"volatile" = false,
.size = .One,
} },
.many_const_pointer => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .Many,
} },
.manyptr_const_u8 => return .{ .data = .{
.pointee_type = Type.initTag(.u8),
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .Many,
} },
.manyptr_const_u8_sentinel_0 => return .{ .data = .{
.pointee_type = Type.initTag(.u8),
.sentinel = Value.zero,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .Many,
} },
.many_mut_pointer => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = true,
.@"volatile" = false,
.size = .Many,
} },
.manyptr_u8 => return .{ .data = .{
.pointee_type = Type.initTag(.u8),
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = true,
.@"volatile" = false,
.size = .Many,
} },
.c_const_pointer => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = true,
.mutable = false,
.@"volatile" = false,
.size = .C,
} },
.c_mut_pointer => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = true,
.mutable = true,
.@"volatile" = false,
.size = .C,
} },
.const_slice => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .Slice,
} },
.mut_slice => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = true,
.@"volatile" = false,
.size = .Slice,
} },
.pointer => return self.castTag(.pointer).?.*,
.optional_single_mut_pointer => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = true,
.@"volatile" = false,
.size = .One,
} },
.optional_single_const_pointer => return .{ .data = .{
.pointee_type = self.castPointer().?.data,
.sentinel = null,
.@"align" = 0,
.@"addrspace" = .generic,
.bit_offset = 0,
.host_size = 0,
.@"allowzero" = false,
.mutable = false,
.@"volatile" = false,
.size = .One,
} },
.optional => {
var buf: Payload.ElemType = undefined;
const child_type = self.optionalChild(&buf);
return child_type.ptrInfo();
},
else => unreachable,
}
}
pub fn eql(a: Type, b: Type, mod: *Module) bool {
// As a shortcut, if the small tags / addresses match, we're done.
if (a.tag_if_small_enough == b.tag_if_small_enough) return true;
switch (a.tag()) {
.generic_poison => unreachable,
// Detect that e.g. u64 != usize, even if the bits match on a particular target.
.usize,
.isize,
.c_short,
.c_ushort,
.c_int,
.c_uint,
.c_long,
.c_ulong,
.c_longlong,
.c_ulonglong,
.f16,
.f32,
.f64,
.f80,
.f128,
.c_longdouble,
.bool,
.void,
.type,
.comptime_int,
.comptime_float,
.noreturn,
.@"null",
.@"undefined",
.@"anyopaque",
.@"anyframe",
.enum_literal,
=> |a_tag| {
assert(a_tag != b.tag()); // because of the comparison at the top of the function.
return false;
},
.u1,
.u8,
.i8,
.u16,
.i16,
.u32,
.i32,
.u64,
.i64,
.u128,
.i128,
.int_signed,
.int_unsigned,
=> {
if (b.zigTypeTag() != .Int) return false;
if (b.isNamedInt()) return false;
// Arbitrary sized integers. The target will not be branched upon,
// because we handled target-dependent cases above.
const info_a = a.intInfo(@as(Target, undefined));
const info_b = b.intInfo(@as(Target, undefined));
return info_a.signedness == info_b.signedness and info_a.bits == info_b.bits;
},
.error_set_inferred => {
// Inferred error sets are only equal if both are inferred
// and they share the same pointer.
const a_ies = a.castTag(.error_set_inferred).?.data;
const b_ies = (b.castTag(.error_set_inferred) orelse return false).data;
return a_ies == b_ies;
},
.anyerror => {
return b.tag() == .anyerror;
},
.error_set,
.error_set_single,
.error_set_merged,
=> {
switch (b.tag()) {
.error_set, .error_set_single, .error_set_merged => {},
else => return false,
}
// Two resolved sets match if their error set names match.
// Since they are pre-sorted we compare them element-wise.
const a_set = a.errorSetNames();
const b_set = b.errorSetNames();
if (a_set.len != b_set.len) return false;
for (a_set) |a_item, i| {
const b_item = b_set[i];
if (!std.mem.eql(u8, a_item, b_item)) return false;
}
return true;
},
.@"opaque" => {
const opaque_obj_a = a.castTag(.@"opaque").?.data;
const opaque_obj_b = (b.castTag(.@"opaque") orelse return false).data;
return opaque_obj_a == opaque_obj_b;
},
.fn_noreturn_no_args,
.fn_void_no_args,
.fn_naked_noreturn_no_args,
.fn_ccc_void_no_args,
.function,
=> {
if (b.zigTypeTag() != .Fn) return false;
const a_info = a.fnInfo();
const b_info = b.fnInfo();
if (!eql(a_info.return_type, b_info.return_type, mod))
return false;
if (a_info.cc != b_info.cc)
return false;
if (a_info.alignment != b_info.alignment)
return false;
if (a_info.is_var_args != b_info.is_var_args)
return false;
if (a_info.is_generic != b_info.is_generic)
return false;
if (a_info.param_types.len != b_info.param_types.len)
return false;
for (a_info.param_types) |a_param_ty, i| {
const b_param_ty = b_info.param_types[i];
if (a_info.comptime_params[i] != b_info.comptime_params[i])
return false;
if (a_param_ty.tag() == .generic_poison) continue;
if (b_param_ty.tag() == .generic_poison) continue;
if (!eql(a_param_ty, b_param_ty, mod))
return false;
}
return true;
},
.array,
.array_u8_sentinel_0,
.array_u8,
.array_sentinel,
.vector,
=> {
if (a.zigTypeTag() != b.zigTypeTag()) return false;
if (a.arrayLen() != b.arrayLen())
return false;
const elem_ty = a.elemType();
if (!elem_ty.eql(b.elemType(), mod))
return false;
const sentinel_a = a.sentinel();
const sentinel_b = b.sentinel();
if (sentinel_a) |sa| {
if (sentinel_b) |sb| {
return sa.eql(sb, elem_ty, mod);
} else {
return false;
}
} else {
return sentinel_b == null;
}
},
.single_const_pointer_to_comptime_int,
.const_slice_u8,
.const_slice_u8_sentinel_0,
.single_const_pointer,
.single_mut_pointer,
.many_const_pointer,
.many_mut_pointer,
.c_const_pointer,
.c_mut_pointer,
.const_slice,
.mut_slice,
.pointer,
.inferred_alloc_const,
.inferred_alloc_mut,
.manyptr_u8,
.manyptr_const_u8,
.manyptr_const_u8_sentinel_0,
=> {
if (b.zigTypeTag() != .Pointer) return false;
const info_a = a.ptrInfo().data;
const info_b = b.ptrInfo().data;
if (!info_a.pointee_type.eql(info_b.pointee_type, mod))
return false;
10BC8 if (info_a.@"align" != info_b.@"align")
return false;
if (info_a.@"addrspace" != info_b.@"addrspace")
return false;
if (info_a.bit_offset != info_b.bit_offset)
return false;
if (info_a.host_size != info_b.host_size)
return false;
if (info_a.@"allowzero" != info_b.@"allowzero")
return false;
if (info_a.mutable != info_b.mutable)
return false;
if (info_a.@"volatile" != info_b.@"volatile")
return false;
if (info_a.size != info_b.size)
return false;
const sentinel_a = info_a.sentinel;
const sentinel_b = info_b.sentinel;
if (sentinel_a) |sa| {
if (sentinel_b) |sb| {
if (!sa.eql(sb, info_a.pointee_type, mod))
return false;
} else {
return false;
}
} else {
if (sentinel_b != null)
return false;
}
return true;
},
.optional,
.optional_single_const_pointer,
.optional_single_mut_pointer,
=> {
if (b.zigTypeTag() != .Optional) return false;
var buf_a: Payload.ElemType = undefined;
var buf_b: Payload.ElemType = undefined;
return a.optionalChild(&buf_a).eql(b.optionalChild(&buf_b), mod);
},
.anyerror_void_error_union, .error_union => {
if (b.zigTypeTag() != .ErrorUnion) return false;
const a_set = a.errorUnionSet();
const b_set = b.errorUnionSet();
if (!a_set.eql(b_set, mod)) return false;
const a_payload = a.errorUnionPayload();
const b_payload = b.errorUnionPayload();
if (!a_payload.eql(b_payload, mod)) return false;
return true;
},
.anyframe_T => {
if (b.zigTypeTag() != .AnyFrame) return false;
return a.childType().eql(b.childType(), mod);
},
.empty_struct => {
const a_namespace = a.castTag(.empty_struct).?.data;
const b_namespace = (b.castTag(.empty_struct) orelse return false).data;
return a_namespace == b_namespace;
},
.@"struct" => {
const a_struct_obj = a.castTag(.@"struct").?.data;
const b_struct_obj = (b.castTag(.@"struct") orelse return false).data;
return a_struct_obj == b_struct_obj;
},
.tuple, .empty_struct_literal => {
if (!b.isTuple()) return false;
const a_tuple = a.tupleFields();
const b_tuple = b.tupleFields();
if (a_tuple.types.len != b_tuple.types.len) return false;
for (a_tuple.types) |a_ty, i| {
const b_ty = b_tuple.types[i];
if (!eql(a_ty, b_ty, mod)) return false;
}
for (a_tuple.values) |a_val, i| {
const ty = a_tuple.types[i];
const b_val = b_tuple.values[i];
if (a_val.tag() == .unreachable_value) {
if (b_val.tag() == .unreachable_value) {
continue;
} else {
return false;
}
} else {
if (b_val.tag() == .unreachable_value) {
return false;
} else {
if (!Value.eql(a_val, b_val, ty, mod)) return false;
}
}
}
return true;
},
.anon_struct => {
const a_struct_obj = a.castTag(.anon_struct).?.data;
const b_struct_obj = (b.castTag(.anon_struct) orelse return false).data;
if (a_struct_obj.types.len != b_struct_obj.types.len) return false;
for (a_struct_obj.names) |a_name, i| {
const b_name = b_struct_obj.names[i];
if (!std.mem.eql(u8, a_name, b_name)) return false;
}
for (a_struct_obj.types) |a_ty, i| {
const b_ty = b_struct_obj.types[i];
if (!eql(a_ty, b_ty, mod)) return false;
}
for (a_struct_obj.values) |a_val, i| {
const ty = a_struct_obj.types[i];
const b_val = b_struct_obj.values[i];
if (a_val.tag() == .unreachable_value) {
if (b_val.tag() == .unreachable_value) {
continue;
} else {
return false;
}
} else {
if (b_val.tag() == .unreachable_value) {
return false;
} else {
if (!Value.eql(a_val, b_val, ty, mod)) return false;
}
}
}
return true;
},
// we can't compare these based on tags because it wouldn't detect if,
// for example, a was resolved into .@"struct" but b was one of these tags.
.call_options,
.prefetch_options,
.export_options,
.extern_options,
=> unreachable, // needed to resolve the type before now
.enum_full, .enum_nonexhaustive => {
const a_enum_obj = a.cast(Payload.EnumFull).?.data;
const b_enum_obj = (b.cast(Payload.EnumFull) orelse return false).data;
return a_enum_obj == b_enum_obj;
},
.enum_simple => {
const a_enum_obj = a.cast(Payload.EnumSimple).?.data;
const b_enum_obj = (b.cast(Payload.EnumSimple) orelse return false).data;
return a_enum_obj == b_enum_obj;
},
.enum_numbered => {
const a_enum_obj = a.cast(Payload.EnumNumbered).?.data;
const b_enum_obj = (b.cast(Payload.EnumNumbered) orelse return false).data;
return a_enum_obj == b_enum_obj;
},
// we can't compare these based on tags because it wouldn't detect if,
// for example, a was resolved into .enum_simple but b was one of these tags.
.atomic_order,
.atomic_rmw_op,
.calling_convention,
.address_space,
.float_mode,
.reduce_op,
=> unreachable, // needed to resolve the type before now
.@"union", .union_tagged => {
const a_union_obj = a.cast(Payload.Union).?.data;
const b_union_obj = (b.cast(Payload.Union) orelse return false).data;
return a_union_obj == b_union_obj;
},
// we can't compare these based on tags because it wouldn't detect if,
// for example, a was resolved into .union_tagged but b was one of these tags.
.type_info => unreachable, // needed to resolve the type before now
.bound_fn => unreachable,
.var_args_param => unreachable, // can be any type
}
}
pub fn hash(self: Type, mod: *Module) u64 {
var hasher = std.hash.Wyhash.init(0);
self.hashWithHasher(&hasher, mod);
return hasher.final();
}
pub fn hashWithHasher(ty: Type, hasher: *std.hash.Wyhash, mod: *Module) void {
switch (ty.tag()) {
.generic_poison => unreachable,
.usize,
.isize,
.c_short,
.c_ushort,
.c_int,
.c_uint,
.c_long,
.c_ulong,
.c_longlong,
.c_ulonglong,
=> |ty_tag| {
std.hash.autoHash(hasher, std.builtin.TypeId.Int);
std.hash.autoHash(hasher, ty_tag);
},
.f16,
.f32,
.f64,
.f80,
.f128,
.c_longdouble,
=> |ty_tag| {
std.hash.autoHash(hasher, std.builtin.TypeId.Float);
std.hash.autoHash(hasher, ty_tag);
},
.bool => std.hash.autoHash(hasher, std.builtin.TypeId.Bool),
.void => std.hash.autoHash(hasher, std.builtin.TypeId.Void),
.type => std.hash.autoHash(hasher, std.builtin.TypeId.Type),
.comptime_int => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeInt),
.comptime_float => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeFloat),
.noreturn => std.hash.autoHash(hasher, std.builtin.TypeId.NoReturn),
.@"null" => std.hash.autoHash(hasher, std.builtin.TypeId.Null),
.@"undefined" => std.hash.autoHash(hasher, std.builtin.TypeId.Undefined),
.@"anyopaque" => {
std.hash.autoHash(hasher, std.builtin.TypeId.Opaque);
std.hash.autoHash(hasher, Tag.@"anyopaque");
},
.@"anyframe" => {
std.hash.autoHash(hasher, std.builtin.TypeId.AnyFrame);
std.hash.autoHash(hasher, Tag.@"anyframe");
},
.enum_literal => {
std.hash.autoHash(hasher, std.builtin.TypeId.EnumLiteral);
std.hash.autoHash(hasher, Tag.enum_literal);
},
.u1,
.u8,
.i8,
.u16,
.i16,
.u32,
.i32,
.u64,
.i64,
.u128,
.i128,
.int_signed,
.int_unsigned,
=> {
// Arbitrary sized integers. The target will not be branched upon,
// because we handled target-dependent cases above.
std.hash.autoHash(hasher, std.builtin.TypeId.Int);
const info = ty.intInfo(@as(Target, undefined));
std.hash.autoHash(hasher, info.signedness);
std.hash.autoHash(hasher, info.bits);
},
.error_set,
.error_set_single,
.error_set_merged,
=> {
// all are treated like an "error set" for hashing
0