authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-03 18:11:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:40:04-07:00
log836d8a1f64cb811641e621799429c54f222717eb
treebbcdd77b43cf4fa0bdd97abcfbe2457b57d9ae46
parentbcd4bb8afbea84d86fd8758b581b141e7086b16b

stage2: move most simple types to InternPool


14 files changed, 435 insertions(+), 985 deletions(-)

src/Air.zig+2-2
......@@ -1333,7 +1333,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
13331333 .ret_load,
13341334 .unreach,
13351335 .trap,
1336 => return Type.initTag(.noreturn),
1336 => return Type.noreturn,
13371337
13381338 .breakpoint,
13391339 .dbg_stmt,
......@@ -1370,7 +1370,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
13701370 .wasm_memory_grow => return Type.i32,
13711371 .wasm_memory_size => return Type.u32,
13721372
1373 .bool_to_int => return Type.initTag(.u1),
1373 .bool_to_int => return Type.u1,
13741374
13751375 .tag_name, .error_name => return Type.initTag(.const_slice_u8_sentinel_0),
13761376
src/Module.zig+27-24
......@@ -1005,7 +1005,7 @@ pub const Struct = struct {
10051005 /// If the layout is packed, this is the backing integer type of the packed struct.
10061006 /// Whether zig chooses this type or the user specifies it, it is stored here.
10071007 /// This will be set to the noreturn type until status is `have_layout`.
1008 backing_int_ty: Type = Type.initTag(.noreturn),
1008 backing_int_ty: Type = Type.noreturn,
10091009 status: enum {
10101010 none,
10111011 field_types_wip,
......@@ -1705,31 +1705,34 @@ pub const Fn = struct {
17051705 is_resolved: bool = false,
17061706
17071707 pub fn addErrorSet(self: *InferredErrorSet, gpa: Allocator, err_set_ty: Type) !void {
1708 switch (err_set_ty.tag()) {
1709 .error_set => {
1710 const names = err_set_ty.castTag(.error_set).?.data.names.keys();
1711 for (names) |name| {
1712 try self.errors.put(gpa, name, {});
1713 }
1714 },
1715 .error_set_single => {
1716 const name = err_set_ty.castTag(.error_set_single).?.data;
1717 try self.errors.put(gpa, name, {});
1718 },
1719 .error_set_inferred => {
1720 const ies = err_set_ty.castTag(.error_set_inferred).?.data;
1721 try self.inferred_error_sets.put(gpa, ies, {});
1708 switch (err_set_ty.ip_index) {
1709 .anyerror_type => {
1710 self.is_anyerror = true;
17221711 },
1723 .error_set_merged => {
1724 const names = err_set_ty.castTag(.error_set_merged).?.data.keys();
1725 for (names) |name| {
1712 .none => switch (err_set_ty.tag()) {
1713 .error_set => {
1714 const names = err_set_ty.castTag(.error_set).?.data.names.keys();
1715 for (names) |name| {
1716 try self.errors.put(gpa, name, {});
1717 }
1718 },
1719 .error_set_single => {
1720 const name = err_set_ty.castTag(.error_set_single).?.data;
17261721 try self.errors.put(gpa, name, {});
1727 }
1728 },
1729 .anyerror => {
1730 self.is_anyerror = true;
1722 },
1723 .error_set_inferred => {
1724 const ies = err_set_ty.castTag(.error_set_inferred).?.data;
1725 try self.inferred_error_sets.put(gpa, ies, {});
1726 },
1727 .error_set_merged => {
1728 const names = err_set_ty.castTag(.error_set_merged).?.data.keys();
1729 for (names) |name| {
1730 try self.errors.put(gpa, name, {});
1731 }
1732 },
1733 else => unreachable,
17311734 },
1732 else => unreachable,
1735 else => @panic("TODO"),
17331736 }
17341737 }
17351738 };
......@@ -4566,7 +4569,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
45664569 const struct_obj = try new_decl_arena_allocator.create(Module.Struct);
45674570 const struct_ty = try Type.Tag.@"struct".create(new_decl_arena_allocator, struct_obj);
45684571 const struct_val = try Value.Tag.ty.create(new_decl_arena_allocator, struct_ty);
4569 const ty_ty = comptime Type.initTag(.type);
4572 const ty_ty = comptime Type.type;
45704573 struct_obj.* = .{
45714574 .owner_decl = undefined, // set below
45724575 .fields = .{},
src/Sema.zig+209-294
......@@ -1776,7 +1776,7 @@ fn analyzeAsType(
17761776 src: LazySrcLoc,
17771777 air_inst: Air.Inst.Ref,
17781778) !Type {
1779 const wanted_type = Type.initTag(.type);
1779 const wanted_type = Type.type;
17801780 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
17811781 const val = try sema.resolveConstValue(block, src, coerced_inst, "types must be comptime-known");
17821782 const ty = val.toType();
......@@ -3132,7 +3132,7 @@ fn zirUnionDecl(
31323132 errdefer mod.abortAnonDecl(new_decl_index);
31333133 union_obj.* = .{
31343134 .owner_decl = new_decl_index,
3135 .tag_ty = Type.initTag(.null),
3135 .tag_ty = Type.null,
31363136 .fields = .{},
31373137 .zir_index = inst,
31383138 .layout = small.layout,
......@@ -6362,7 +6362,7 @@ fn zirCall(
63626362 if (arg_index >= fn_params_len)
63636363 break :inst Air.Inst.Ref.var_args_param_type;
63646364
6365 if (func_ty_info.param_types[arg_index].tag() == .generic_poison)
6365 if (func_ty_info.param_types[arg_index].isGenericPoison())
63666366 break :inst Air.Inst.Ref.generic_poison_type;
63676367
63686368 break :inst try sema.addType(func_ty_info.param_types[arg_index]);
......@@ -8175,7 +8175,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
81758175 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(sema.mod)});
81768176
81778177 // Anything merged with anyerror is anyerror.
8178 if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) {
8178 if (lhs_ty.ip_index == .anyerror_type or rhs_ty.ip_index == .anyerror_type) {
81798179 return Air.Inst.Ref.anyerror_type;
81808180 }
81818181
......@@ -8206,7 +8206,7 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
82068206 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
82078207 const duped_name = try sema.arena.dupe(u8, inst_data.get(sema.code));
82088208 return sema.addConstant(
8209 Type.initTag(.enum_literal),
8209 .{ .ip_index = .enum_literal_type, .legacy = undefined },
82108210 try Value.Tag.enum_literal.create(sema.arena, duped_name),
82118211 );
82128212}
......@@ -8503,6 +8503,7 @@ fn analyzeErrUnionPayload(
85038503 operand_src: LazySrcLoc,
85048504 safety_check: bool,
85058505) CompileError!Air.Inst.Ref {
8506 const mod = sema.mod;
85068507 const payload_ty = err_union_ty.errorUnionPayload();
85078508 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
85088509 if (val.getError()) |name| {
......@@ -8516,7 +8517,7 @@ fn analyzeErrUnionPayload(
85168517
85178518 // If the error set has no fields then no safety check is needed.
85188519 if (safety_check and block.wantSafety() and
8519 !err_union_ty.errorUnionSet().errorSetIsEmpty())
8520 !err_union_ty.errorUnionSet().errorSetIsEmpty(mod))
85208521 {
85218522 try sema.panicUnwrapError(block, operand, .unwrap_errunion_err, .is_non_err);
85228523 }
......@@ -8602,7 +8603,7 @@ fn analyzeErrUnionPayloadPtr(
86028603
86038604 // If the error set has no fields then no safety check is needed.
86048605 if (safety_check and block.wantSafety() and
8605 !err_union_ty.errorUnionSet().errorSetIsEmpty())
8606 !err_union_ty.errorUnionSet().errorSetIsEmpty(mod))
86068607 {
86078608 try sema.panicUnwrapError(block, operand, .unwrap_errunion_err_ptr, .is_non_err_ptr);
86088609 }
......@@ -8701,7 +8702,7 @@ fn zirFunc(
87018702 break :blk ret_ty;
87028703 } else |err| switch (err) {
87038704 error.GenericPoison => {
8704 break :blk Type.initTag(.generic_poison);
8705 break :blk Type.generic_poison;
87058706 },
87068707 else => |e| return e,
87078708 }
......@@ -8778,7 +8779,7 @@ fn resolveGenericBody(
87788779 };
87798780 switch (err) {
87808781 error.GenericPoison => {
8781 if (dest_ty.tag() == .type) {
8782 if (dest_ty.ip_index == .type_type) {
87828783 return Value.initTag(.generic_poison_type);
87838784 } else {
87848785 return Value.initTag(.generic_poison);
......@@ -9319,7 +9320,7 @@ fn zirParam(
93199320 // We result the param instruction with a poison value and
93209321 // insert an anytype parameter.
93219322 try block.params.append(sema.gpa, .{
9322 .ty = Type.initTag(.generic_poison),
9323 .ty = Type.generic_poison,
93239324 .is_comptime = comptime_syntax,
93249325 .name = param_name,
93259326 });
......@@ -9340,7 +9341,7 @@ fn zirParam(
93409341 // We result the param instruction with a poison value and
93419342 // insert an anytype parameter.
93429343 try block.params.append(sema.gpa, .{
9343 .ty = Type.initTag(.generic_poison),
9344 .ty = Type.generic_poison,
93449345 .is_comptime = comptime_syntax,
93459346 .name = param_name,
93469347 });
......@@ -9438,7 +9439,7 @@ fn zirParamAnytype(
94389439 // We are evaluating a generic function without any comptime args provided.
94399440
94409441 try block.params.append(sema.gpa, .{
9441 .ty = Type.initTag(.generic_poison),
9442 .ty = Type.generic_poison,
94429443 .is_comptime = comptime_syntax,
94439444 .name = param_name,
94449445 });
......@@ -18877,7 +18878,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1887718878 },
1887818879 .ErrorSet => {
1887918880 const payload_val = union_val.val.optionalValue(mod) orelse
18880 return sema.addType(Type.initTag(.anyerror));
18881 return sema.addType(Type.anyerror);
1888118882 const slice_val = payload_val.castTag(.slice).?.data;
1888218883
1888318884 const len = try sema.usizeCast(block, src, slice_val.len.toUnsignedInt(mod));
......@@ -19150,7 +19151,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1915019151 errdefer mod.abortAnonDecl(new_decl_index);
1915119152 union_obj.* = .{
1915219153 .owner_decl = new_decl_index,
19153 .tag_ty = Type.initTag(.null),
19154 .tag_ty = Type.null,
1915419155 .fields = .{},
1915519156 .zir_index = inst,
1915619157 .layout = layout,
......@@ -22697,7 +22698,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2269722698 extra_index += 1;
2269822699 const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime-known") catch |err| switch (err) {
2269922700 error.GenericPoison => {
22700 break :blk Type.initTag(.generic_poison);
22701 break :blk Type.generic_poison;
2270122702 },
2270222703 else => |e| return e,
2270322704 };
......@@ -23022,7 +23023,7 @@ fn zirBuiltinExtern(
2302223023 new_decl.src_line = sema.owner_decl.src_line;
2302323024 // We only access this decl through the decl_ref with the correct type created
2302423025 // below, so this type doesn't matter
23025 new_decl.ty = Type.Tag.init(.anyopaque);
23026 new_decl.ty = Type.anyopaque;
2302623027 new_decl.val = try Value.Tag.variable.create(new_decl_arena_allocator, new_var);
2302723028 new_decl.@"align" = 0;
2302823029 new_decl.@"linksection" = null;
......@@ -24380,9 +24381,8 @@ fn fieldCallBind(
2438024381 decl_type.fnParamLen() >= 1)
2438124382 {
2438224383 const first_param_type = decl_type.fnParamType(0);
24383 const first_param_tag = first_param_type.tag();
2438424384 // zig fmt: off
24385 if (first_param_tag == .generic_poison or (
24385 if (first_param_type.isGenericPoison() or (
2438624386 first_param_type.zigTypeTag(mod) == .Pointer and
2438724387 (first_param_type.ptrSize() == .One or
2438824388 first_param_type.ptrSize() == .C) and
......@@ -25535,10 +25535,7 @@ fn coerceExtra(
2553525535 inst_src: LazySrcLoc,
2553625536 opts: CoerceOpts,
2553725537) CoersionError!Air.Inst.Ref {
25538 switch (dest_ty_unresolved.tag()) {
25539 .generic_poison => return inst,
25540 else => {},
25541 }
25538 if (dest_ty_unresolved.isGenericPoison()) return inst;
2554225539 const dest_ty_src = inst_src; // TODO better source location
2554325540 const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved);
2554425541 const inst_ty = try sema.resolveTypeFields(sema.typeOf(inst));
......@@ -25577,7 +25574,8 @@ fn coerceExtra(
2557725574
2557825575 // cast from ?*T and ?[*]T to ?*anyopaque
2557925576 // but don't do it if the source type is a double pointer
25580 if (dest_ty.isPtrLikeOptional(mod) and dest_ty.elemType2(mod).tag() == .anyopaque and
25577 if (dest_ty.isPtrLikeOptional(mod) and
25578 dest_ty.elemType2(mod).ip_index == .anyopaque_type and
2558125579 inst_ty.isPtrAtRuntime(mod))
2558225580 anyopaque_check: {
2558325581 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :optional;
......@@ -25715,7 +25713,7 @@ fn coerceExtra(
2571525713
2571625714 // cast from *T and [*]T to *anyopaque
2571725715 // but don't do it if the source type is a double pointer
25718 if (dest_info.pointee_type.tag() == .anyopaque and inst_ty.zigTypeTag(mod) == .Pointer) to_anyopaque: {
25716 if (dest_info.pointee_type.ip_index == .anyopaque_type and inst_ty.zigTypeTag(mod) == .Pointer) to_anyopaque: {
2571925717 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
2572025718 const elem_ty = inst_ty.elemType2(mod);
2572125719 if (elem_ty.zigTypeTag(mod) == .Pointer or elem_ty.isPtrLikeOptional(mod)) {
......@@ -26759,6 +26757,8 @@ fn coerceInMemoryAllowedErrorSets(
2675926757 dest_src: LazySrcLoc,
2676026758 src_src: LazySrcLoc,
2676126759) !InMemoryCoercionResult {
26760 const mod = sema.mod;
26761
2676226762 // Coercion to `anyerror`. Note that this check can return false negatives
2676326763 // in case the error sets did not get resolved.
2676426764 if (dest_ty.isAnyError()) {
......@@ -26769,36 +26769,41 @@ fn coerceInMemoryAllowedErrorSets(
2676926769 const dst_ies = dst_payload.data;
2677026770 // We will make an effort to return `ok` without resolving either error set, to
2677126771 // avoid unnecessary "unable to resolve error set" dependency loop errors.
26772 switch (src_ty.tag()) {
26773 .error_set_inferred => {
26774 // If both are inferred error sets of functions, and
26775 // the dest includes the source function, the coercion is OK.
26776 // This check is important because it works without forcing a full resolution
26777 // of inferred error sets.
26778 const src_ies = src_ty.castTag(.error_set_inferred).?.data;
26779
26780 if (dst_ies.inferred_error_sets.contains(src_ies)) {
26781 return .ok;
26782 }
26783 },
26784 .error_set_single => {
26785 const name = src_ty.castTag(.error_set_single).?.data;
26786 if (dst_ies.errors.contains(name)) return .ok;
26787 },
26788 .error_set_merged => {
26789 const names = src_ty.castTag(.error_set_merged).?.data.keys();
26790 for (names) |name| {
26791 if (!dst_ies.errors.contains(name)) break;
26792 } else return .ok;
26772 switch (src_ty.ip_index) {
26773 .none => switch (src_ty.tag()) {
26774 .error_set_inferred => {
26775 // If both are inferred error sets of functions, and
26776 // the dest includes the source function, the coercion is OK.
26777 // This check is important because it works without forcing a full resolution
26778 // of inferred error sets.
26779 const src_ies = src_ty.castTag(.error_set_inferred).?.data;
26780
26781 if (dst_ies.inferred_error_sets.contains(src_ies)) {
26782 return .ok;
26783 }
26784 },
26785 .error_set_single => {
26786 const name = src_ty.castTag(.error_set_single).?.data;
26787 if (dst_ies.errors.contains(name)) return .ok;
26788 },
26789 .error_set_merged => {
26790 const names = src_ty.castTag(.error_set_merged).?.data.keys();
26791 for (names) |name| {
26792 if (!dst_ies.errors.contains(name)) break;
26793 } else return .ok;
26794 },
26795 .error_set => {
26796 const names = src_ty.castTag(.error_set).?.data.names.keys();
26797 for (names) |name| {
26798 if (!dst_ies.errors.contains(name)) break;
26799 } else return .ok;
26800 },
26801 else => unreachable,
2679326802 },
26794 .error_set => {
26795 const names = src_ty.castTag(.error_set).?.data.names.keys();
26796 for (names) |name| {
26797 if (!dst_ies.errors.contains(name)) break;
26798 } else return .ok;
26803 .anyerror_type => {},
26804 else => switch (mod.intern_pool.indexToKey(src_ty.ip_index)) {
26805 else => @panic("TODO"),
2679926806 },
26800 .anyerror => {},
26801 else => unreachable,
2680226807 }
2680326808
2680426809 if (dst_ies.func == sema.owner_func) {
......@@ -26818,79 +26823,87 @@ fn coerceInMemoryAllowedErrorSets(
2681826823 var missing_error_buf = std.ArrayList([]const u8).init(sema.gpa);
2681926824 defer missing_error_buf.deinit();
2682026825
26821 switch (src_ty.tag()) {
26822 .error_set_inferred => {
26823 const src_data = src_ty.castTag(.error_set_inferred).?.data;
26826 switch (src_ty.ip_index) {
26827 .none => switch (src_ty.tag()) {
26828 .error_set_inferred => {
26829 const src_data = src_ty.castTag(.error_set_inferred).?.data;
2682426830
26825 try sema.resolveInferredErrorSet(block, src_src, src_data);
26826 // src anyerror status might have changed after the resolution.
26827 if (src_ty.isAnyError()) {
26828 // dest_ty.isAnyError() == true is already checked for at this point.
26829 return .from_anyerror;
26830 }
26831 try sema.resolveInferredErrorSet(block, src_src, src_data);
26832 // src anyerror status might have changed after the resolution.
26833 if (src_ty.isAnyError()) {
26834 // dest_ty.isAnyError() == true is already checked for at this point.
26835 return .from_anyerror;
26836 }
2683126837
26832 for (src_data.errors.keys()) |key| {
26833 if (!dest_ty.errorSetHasField(key)) {
26834 try missing_error_buf.append(key);
26838 for (src_data.errors.keys()) |key| {
26839 if (!dest_ty.errorSetHasField(key)) {
26840 try missing_error_buf.append(key);
26841 }
2683526842 }
26836 }
2683726843
26838 if (missing_error_buf.items.len != 0) {
26839 return InMemoryCoercionResult{
26840 .missing_error = try sema.arena.dupe([]const u8, missing_error_buf.items),
26841 };
26842 }
26844 if (missing_error_buf.items.len != 0) {
26845 return InMemoryCoercionResult{
26846 .missing_error = try sema.arena.dupe([]const u8, missing_error_buf.items),
26847 };
26848 }
2684326849
26844 return .ok;
26845 },
26846 .error_set_single => {
26847 const name = src_ty.castTag(.error_set_single).?.data;
26848 if (dest_ty.errorSetHasField(name)) {
2684926850 return .ok;
26850 }
26851 const list = try sema.arena.alloc([]const u8, 1);
26852 list[0] = name;
26853 return InMemoryCoercionResult{ .missing_error = list };
26854 },
26855 .error_set_merged => {
26856 const names = src_ty.castTag(.error_set_merged).?.data.keys();
26857 for (names) |name| {
26858 if (!dest_ty.errorSetHasField(name)) {
26859 try missing_error_buf.append(name);
26851 },
26852 .error_set_single => {
26853 const name = src_ty.castTag(.error_set_single).?.data;
26854 if (dest_ty.errorSetHasField(name)) {
26855 return .ok;
26856 }
26857 const list = try sema.arena.alloc([]const u8, 1);
26858 list[0] = name;
26859 return InMemoryCoercionResult{ .missing_error = list };
26860 },
26861 .error_set_merged => {
26862 const names = src_ty.castTag(.error_set_merged).?.data.keys();
26863 for (names) |name| {
26864 if (!dest_ty.errorSetHasField(name)) {
26865 try missing_error_buf.append(name);
26866 }
2686026867 }
26861 }
2686226868
26863 if (missing_error_buf.items.len != 0) {
26864 return InMemoryCoercionResult{
26865 .missing_error = try sema.arena.dupe([]const u8, missing_error_buf.items),
26866 };
26867 }
26869 if (missing_error_buf.items.len != 0) {
26870 return InMemoryCoercionResult{
26871 .missing_error = try sema.arena.dupe([]const u8, missing_error_buf.items),
26872 };
26873 }
2686826874
26869 return .ok;
26870 },
26871 .error_set => {
26872 const names = src_ty.castTag(.error_set).?.data.names.keys();
26873 for (names) |name| {
26874 if (!dest_ty.errorSetHasField(name)) {
26875 try missing_error_buf.append(name);
26875 return .ok;
26876 },
26877 .error_set => {
26878 const names = src_ty.castTag(.error_set).?.data.names.keys();
26879 for (names) |name| {
26880 if (!dest_ty.errorSetHasField(name)) {
26881 try missing_error_buf.append(name);
26882 }
2687626883 }
26877 }
2687826884
26879 if (missing_error_buf.items.len != 0) {
26880 return InMemoryCoercionResult{
26881 .missing_error = try sema.arena.dupe([]const u8, missing_error_buf.items),
26882 };
26883 }
26885 if (missing_error_buf.items.len != 0) {
26886 return InMemoryCoercionResult{
26887 .missing_error = try sema.arena.dupe([]const u8, missing_error_buf.items),
26888 };
26889 }
2688426890
26885 return .ok;
26886 },
26887 .anyerror => switch (dest_ty.tag()) {
26888 .error_set_inferred => unreachable, // Caught by dest_ty.isAnyError() above.
26889 .error_set_single, .error_set_merged, .error_set => return .from_anyerror,
26890 .anyerror => unreachable, // Filtered out above.
26891 return .ok;
26892 },
2689126893 else => unreachable,
2689226894 },
26893 else => unreachable,
26895
26896 .anyerror_type => switch (dest_ty.ip_index) {
26897 .none => switch (dest_ty.tag()) {
26898 .error_set_inferred => unreachable, // Caught by dest_ty.isAnyError() above.
26899 .error_set_single, .error_set_merged, .error_set => return .from_anyerror,
26900 else => unreachable,
26901 },
26902 .anyerror_type => unreachable, // Filtered out above.
26903 else => @panic("TODO"),
26904 },
26905
26906 else => @panic("TODO"),
2689426907 }
2689526908
2689626909 unreachable;
......@@ -29355,42 +29368,49 @@ fn analyzeIsNonErrComptimeOnly(
2935529368 // exception if the error union error set is known to be empty,
2935629369 // we allow the comparison but always make it comptime-known.
2935729370 const set_ty = operand_ty.errorUnionSet();
29358 switch (set_ty.tag()) {
29359 .anyerror => {},
29360 .error_set_inferred => blk: {
29361 // If the error set is empty, we must return a comptime true or false.
29362 // However we want to avoid unnecessarily resolving an inferred error set
29363 // in case it is already non-empty.
29364 const ies = set_ty.castTag(.error_set_inferred).?.data;
29365 if (ies.is_anyerror) break :blk;
29366 if (ies.errors.count() != 0) break :blk;
29367 if (maybe_operand_val == null) {
29368 // Try to avoid resolving inferred error set if possible.
29369 if (ies.errors.count() != 0) break :blk;
29371 switch (set_ty.ip_index) {
29372 .none => switch (set_ty.tag()) {
29373 .error_set_inferred => blk: {
29374 // If the error set is empty, we must return a comptime true or false.
29375 // However we want to avoid unnecessarily resolving an inferred error set
29376 // in case it is already non-empty.
29377 const ies = set_ty.castTag(.error_set_inferred).?.data;
2937029378 if (ies.is_anyerror) break :blk;
29371 for (ies.inferred_error_sets.keys()) |other_ies| {
29372 if (ies == other_ies) continue;
29373 try sema.resolveInferredErrorSet(block, src, other_ies);
29374 if (other_ies.is_anyerror) {
29375 ies.is_anyerror = true;
29376 ies.is_resolved = true;
29377 break :blk;
29378 }
29379 if (ies.errors.count() != 0) break :blk;
29380 if (maybe_operand_val == null) {
29381 // Try to avoid resolving inferred error set if possible.
29382 if (ies.errors.count() != 0) break :blk;
29383 if (ies.is_anyerror) break :blk;
29384 for (ies.inferred_error_sets.keys()) |other_ies| {
29385 if (ies == other_ies) continue;
29386 try sema.resolveInferredErrorSet(block, src, other_ies);
29387 if (other_ies.is_anyerror) {
29388 ies.is_anyerror = true;
29389 ies.is_resolved = true;
29390 break :blk;
29391 }
2937929392
29380 if (other_ies.errors.count() != 0) break :blk;
29381 }
29382 if (ies.func == sema.owner_func) {
29383 // We're checking the inferred errorset of the current function and none of
29384 // its child inferred error sets contained any errors meaning that any value
29385 // so far with this type can't contain errors either.
29386 return Air.Inst.Ref.bool_true;
29393 if (other_ies.errors.count() != 0) break :blk;
29394 }
29395 if (ies.func == sema.owner_func) {
29396 // We're checking the inferred errorset of the current function and none of
29397 // its child inferred error sets contained any errors meaning that any value
29398 // so far with this type can't contain errors either.
29399 return Air.Inst.Ref.bool_true;
29400 }
29401 try sema.resolveInferredErrorSet(block, src, ies);
29402 if (ies.is_anyerror) break :blk;
29403 if (ies.errors.count() == 0) return Air.Inst.Ref.bool_true;
2938729404 }
29388 try sema.resolveInferredErrorSet(block, src, ies);
29389 if (ies.is_anyerror) break :blk;
29390 if (ies.errors.count() == 0) return Air.Inst.Ref.bool_true;
29391 }
29405 },
29406 else => if (set_ty.errorSetNames().len == 0) return Air.Inst.Ref.bool_true,
29407 },
29408
29409 .anyerror_type => {},
29410
29411 else => switch (mod.intern_pool.indexToKey(set_ty.ip_index)) {
29412 else => @panic("TODO"),
2939229413 },
29393 else => if (set_ty.errorSetNames().len == 0) return Air.Inst.Ref.bool_true,
2939429414 }
2939529415
2939629416 if (maybe_operand_val) |err_union| {
......@@ -30308,43 +30328,48 @@ fn wrapErrorUnionSet(
3030830328 const inst_ty = sema.typeOf(inst);
3030930329 const dest_err_set_ty = dest_ty.errorUnionSet();
3031030330 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30311 switch (dest_err_set_ty.tag()) {
30312 .anyerror => {},
30313 .error_set_single => ok: {
30314 const expected_name = val.castTag(.@"error").?.data.name;
30315 const n = dest_err_set_ty.castTag(.error_set_single).?.data;
30316 if (mem.eql(u8, expected_name, n)) break :ok;
30317 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);
30318 },
30319 .error_set => {
30320 const expected_name = val.castTag(.@"error").?.data.name;
30321 const error_set = dest_err_set_ty.castTag(.error_set).?.data;
30322 if (!error_set.names.contains(expected_name)) {
30331 switch (dest_err_set_ty.ip_index) {
30332 .anyerror_type => {},
30333
30334 .none => switch (dest_err_set_ty.tag()) {
30335 .error_set_single => ok: {
30336 const expected_name = val.castTag(.@"error").?.data.name;
30337 const n = dest_err_set_ty.castTag(.error_set_single).?.data;
30338 if (mem.eql(u8, expected_name, n)) break :ok;
3032330339 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);
30324 }
30325 },
30326 .error_set_inferred => ok: {
30327 const expected_name = val.castTag(.@"error").?.data.name;
30328 const ies = dest_err_set_ty.castTag(.error_set_inferred).?.data;
30329
30330 // We carefully do this in an order that avoids unnecessarily
30331 // resolving the destination error set type.
30332 if (ies.is_anyerror) break :ok;
30333 if (ies.errors.contains(expected_name)) break :ok;
30334 if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
30335 break :ok;
30336 }
30340 },
30341 .error_set => {
30342 const expected_name = val.castTag(.@"error").?.data.name;
30343 const error_set = dest_err_set_ty.castTag(.error_set).?.data;
30344 if (!error_set.names.contains(expected_name)) {
30345 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);
30346 }
30347 },
30348 .error_set_inferred => ok: {
30349 const expected_name = val.castTag(.@"error").?.data.name;
30350 const ies = dest_err_set_ty.castTag(.error_set_inferred).?.data;
30351
30352 // We carefully do this in an order that avoids unnecessarily
30353 // resolving the destination error set type.
30354 if (ies.is_anyerror) break :ok;
30355 if (ies.errors.contains(expected_name)) break :ok;
30356 if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
30357 break :ok;
30358 }
3033730359
30338 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);
30339 },
30340 .error_set_merged => {
30341 const expected_name = val.castTag(.@"error").?.data.name;
30342 const error_set = dest_err_set_ty.castTag(.error_set_merged).?.data;
30343 if (!error_set.contains(expected_name)) {
3034430360 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);
30345 }
30361 },
30362 .error_set_merged => {
30363 const expected_name = val.castTag(.@"error").?.data.name;
30364 const error_set = dest_err_set_ty.castTag(.error_set_merged).?.data;
30365 if (!error_set.contains(expected_name)) {
30366 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);
30367 }
30368 },
30369 else => unreachable,
3034630370 },
30347 else => unreachable,
30371
30372 else => @panic("TODO"),
3034830373 }
3034930374 return sema.addConstant(dest_ty, val);
3035030375 }
......@@ -30380,7 +30405,7 @@ fn resolvePeerTypes(
3038030405) !Type {
3038130406 const mod = sema.mod;
3038230407 switch (instructions.len) {
30383 0 => return Type.initTag(.noreturn),
30408 0 => return Type.noreturn,
3038430409 1 => return sema.typeOf(instructions[0]),
3038530410 else => {},
3038630411 }
......@@ -31445,24 +31470,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3144531470 .i64,
3144631471 .u128,
3144731472 .i128,
31448 .anyopaque,
31449 .bool,
31450 .void,
31451 .anyerror,
31452 .noreturn,
31453 .@"anyframe",
31454 .null,
31455 .undefined,
31456 .atomic_order,
31457 .atomic_rmw_op,
31458 .calling_convention,
31459 .address_space,
31460 .float_mode,
31461 .reduce_op,
31462 .modifier,
31463 .prefetch_options,
31464 .export_options,
31465 .extern_options,
31473
3146631474 .manyptr_u8,
3146731475 .manyptr_const_u8,
3146831476 .manyptr_const_u8_sentinel_0,
......@@ -31476,17 +31484,12 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3147631484 .error_set_inferred,
3147731485 .error_set_merged,
3147831486 .@"opaque",
31479 .generic_poison,
3148031487 .array_u8,
3148131488 .array_u8_sentinel_0,
3148231489 .enum_simple,
3148331490 => false,
3148431491
3148531492 .single_const_pointer_to_comptime_int,
31486 .type,
31487 .comptime_int,
31488 .enum_literal,
31489 .type_info,
3149031493 .function,
3149131494 => true,
3149231495
......@@ -31709,17 +31712,6 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
3170931712 try sema.resolveTypeFieldsUnion(ty, union_obj);
3171031713 return ty;
3171131714 },
31712 .type_info => return sema.getBuiltinType("Type"),
31713 .extern_options => return sema.getBuiltinType("ExternOptions"),
31714 .export_options => return sema.getBuiltinType("ExportOptions"),
31715 .atomic_order => return sema.getBuiltinType("AtomicOrder"),
31716 .atomic_rmw_op => return sema.getBuiltinType("AtomicRmwOp"),
31717 .calling_convention => return sema.getBuiltinType("CallingConvention"),
31718 .address_space => return sema.getBuiltinType("AddressSpace"),
31719 .float_mode => return sema.getBuiltinType("FloatMode"),
31720 .reduce_op => return sema.getBuiltinType("ReduceOp"),
31721 .modifier => return sema.getBuiltinType("CallModifier"),
31722 .prefetch_options => return sema.getBuiltinType("PrefetchOptions"),
3172331715
3172431716 else => return ty,
3172531717 },
......@@ -31772,6 +31764,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
3177231764 .const_slice_u8_type,
3177331765 .anyerror_void_error_union_type,
3177431766 .generic_poison_type,
31767 .var_args_param_type,
3177531768 .empty_struct_type,
3177631769 => return ty,
3177731770
......@@ -31789,7 +31782,6 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
3178931782 .bool_false => unreachable,
3179031783 .empty_struct => unreachable,
3179131784 .generic_poison => unreachable,
31792 .var_args_param_type => unreachable,
3179331785
3179431786 .type_info_type => return sema.getBuiltinType("Type"),
3179531787 .extern_options_type => return sema.getBuiltinType("ExternOptions"),
......@@ -32118,7 +32110,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3211832110 return sema.failWithOwnedErrorMsg(msg);
3211932111 }
3212032112 gop.value_ptr.* = .{
32121 .ty = Type.initTag(.noreturn),
32113 .ty = Type.noreturn,
3212232114 .abi_align = 0,
3212332115 .default_val = Value.initTag(.unreachable_value),
3212432116 .is_comptime = is_comptime,
......@@ -32552,7 +32544,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3255232544 const field_ty: Type = if (!has_type)
3255332545 Type.void
3255432546 else if (field_type_ref == .none)
32555 Type.initTag(.noreturn)
32547 Type.noreturn
3255632548 else
3255732549 sema.resolveType(&block_scope, .unneeded, field_type_ref) catch |err| switch (err) {
3255832550 error.NeededSourceLocation => {
......@@ -32956,7 +32948,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3295632948 };
3295732949
3295832950 switch (ty.tag()) {
32959 .comptime_int,
3296032951 .u1,
3296132952 .u8,
3296232953 .i8,
......@@ -32969,9 +32960,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3296932960 .i64,
3297032961 .u128,
3297132962 .i128,
32972 .bool,
32973 .type,
32974 .anyerror,
32963
3297532964 .error_set_single,
3297632965 .error_set,
3297732966 .error_set_merged,
......@@ -32984,28 +32973,14 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3298432973 .const_slice_u8_sentinel_0,
3298532974 .const_slice,
3298632975 .mut_slice,
32987 .anyopaque,
3298832976 .optional_single_mut_pointer,
3298932977 .optional_single_const_pointer,
32990 .enum_literal,
3299132978 .anyerror_void_error_union,
3299232979 .error_set_inferred,
3299332980 .@"opaque",
3299432981 .manyptr_u8,
3299532982 .manyptr_const_u8,
3299632983 .manyptr_const_u8_sentinel_0,
32997 .atomic_order,
32998 .atomic_rmw_op,
32999 .calling_convention,
33000 .address_space,
33001 .float_mode,
33002 .reduce_op,
33003 .modifier,
33004 .prefetch_options,
33005 .export_options,
33006 .extern_options,
33007 .type_info,
33008 .@"anyframe",
3300932984 .anyframe_T,
3301032985 .many_const_pointer,
3301132986 .many_mut_pointer,
......@@ -33138,10 +33113,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3313833113 },
3313933114
3314033115 .empty_struct, .empty_struct_literal => return Value.initTag(.empty_struct_value),
33141 .void => return Value.void,
33142 .noreturn => return Value.initTag(.unreachable_value),
33143 .null => return Value.null,
33144 .undefined => return Value.initTag(.undef),
3314533116
3314633117 .vector, .array, .array_u8 => {
3314733118 if (ty.arrayLen() == 0)
......@@ -33154,7 +33125,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3315433125
3315533126 .inferred_alloc_const => unreachable,
3315633127 .inferred_alloc_mut => unreachable,
33157 .generic_poison => return error.GenericPoison,
3315833128 }
3315933129}
3316033130
......@@ -33194,34 +33164,12 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
3319433164 .i64 => return .i64_type,
3319533165 .u128 => return .u128_type,
3319633166 .i128 => return .i128_type,
33197 .anyopaque => return .anyopaque_type,
33198 .bool => return .bool_type,
33199 .void => return .void_type,
33200 .type => return .type_type,
33201 .anyerror => return .anyerror_type,
33202 .comptime_int => return .comptime_int_type,
33203 .noreturn => return .noreturn_type,
33204 .@"anyframe" => return .anyframe_type,
33205 .null => return .null_type,
33206 .undefined => return .undefined_type,
33207 .enum_literal => return .enum_literal_type,
33208 .atomic_order => return .atomic_order_type,
33209 .atomic_rmw_op => return .atomic_rmw_op_type,
33210 .calling_convention => return .calling_convention_type,
33211 .address_space => return .address_space_type,
33212 .float_mode => return .float_mode_type,
33213 .reduce_op => return .reduce_op_type,
33214 .modifier => return .call_modifier_type,
33215 .prefetch_options => return .prefetch_options_type,
33216 .export_options => return .export_options_type,
33217 .extern_options => return .extern_options_type,
33218 .type_info => return .type_info_type,
33167
3321933168 .manyptr_u8 => return .manyptr_u8_type,
3322033169 .manyptr_const_u8 => return .manyptr_const_u8_type,
3322133170 .single_const_pointer_to_comptime_int => return .single_const_pointer_to_comptime_int_type,
3322233171 .const_slice_u8 => return .const_slice_u8_type,
3322333172 .anyerror_void_error_union => return .anyerror_void_error_union_type,
33224 .generic_poison => return .generic_poison_type,
3322533173 else => {},
3322633174 }
3322733175 try sema.air_instructions.append(sema.gpa, .{
......@@ -33658,22 +33606,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3365833606 .i64,
3365933607 .u128,
3366033608 .i128,
33661 .anyopaque,
33662 .bool,
33663 .void,
33664 .anyerror,
33665 .noreturn,
33666 .@"anyframe",
33667 .atomic_order,
33668 .atomic_rmw_op,
33669 .calling_convention,
33670 .address_space,
33671 .float_mode,
33672 .reduce_op,
33673 .modifier,
33674 .prefetch_options,
33675 .export_options,
33676 .extern_options,
33609
3367733610 .manyptr_u8,
3367833611 .manyptr_const_u8,
3367933612 .manyptr_const_u8_sentinel_0,
......@@ -33687,19 +33620,12 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3368733620 .error_set_inferred,
3368833621 .error_set_merged,
3368933622 .@"opaque",
33690 .generic_poison,
3369133623 .array_u8,
3369233624 .array_u8_sentinel_0,
3369333625 .enum_simple,
3369433626 => false,
3369533627
3369633628 .single_const_pointer_to_comptime_int,
33697 .type,
33698 .comptime_int,
33699 .enum_literal,
33700 .null,
33701 .undefined,
33702 .type_info,
3370333629 .function,
3370433630 => true,
3370533631
......@@ -34476,17 +34402,6 @@ fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
3447634402 const tag_ty = try mod.intType(.unsigned, bits);
3447734403 return sema.intInRange(tag_ty, int, fields_len);
3447834404 },
34479 .atomic_order,
34480 .atomic_rmw_op,
34481 .calling_convention,
34482 .address_space,
34483 .float_mode,
34484 .reduce_op,
34485 .modifier,
34486 .prefetch_options,
34487 .export_options,
34488 .extern_options,
34489 => unreachable,
3449034405
3449134406 else => unreachable,
3449234407 }
src/arch/aarch64/CodeGen.zig+4-3
......@@ -3071,7 +3071,7 @@ fn errUnionErr(
30713071 const mod = self.bin_file.options.module.?;
30723072 const err_ty = error_union_ty.errorUnionSet();
30733073 const payload_ty = error_union_ty.errorUnionPayload();
3074 if (err_ty.errorSetIsEmpty()) {
3074 if (err_ty.errorSetIsEmpty(mod)) {
30753075 return MCValue{ .immediate = 0 };
30763076 }
30773077 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -3151,7 +3151,7 @@ fn errUnionPayload(
31513151 const mod = self.bin_file.options.module.?;
31523152 const err_ty = error_union_ty.errorUnionSet();
31533153 const payload_ty = error_union_ty.errorUnionPayload();
3154 if (err_ty.errorSetIsEmpty()) {
3154 if (err_ty.errorSetIsEmpty(mod)) {
31553155 return try error_union_bind.resolveToMcv(self);
31563156 }
31573157 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -4905,9 +4905,10 @@ fn isErr(
49054905 error_union_bind: ReadArg.Bind,
49064906 error_union_ty: Type,
49074907) !MCValue {
4908 const mod = self.bin_file.options.module.?;
49084909 const error_type = error_union_ty.errorUnionSet();
49094910
4910 if (error_type.errorSetIsEmpty()) {
4911 if (error_type.errorSetIsEmpty(mod)) {
49114912 return MCValue{ .immediate = 0 }; // always false
49124913 }
49134914
src/arch/arm/CodeGen.zig+4-3
......@@ -2047,7 +2047,7 @@ fn errUnionErr(
20472047 const mod = self.bin_file.options.module.?;
20482048 const err_ty = error_union_ty.errorUnionSet();
20492049 const payload_ty = error_union_ty.errorUnionPayload();
2050 if (err_ty.errorSetIsEmpty()) {
2050 if (err_ty.errorSetIsEmpty(mod)) {
20512051 return MCValue{ .immediate = 0 };
20522052 }
20532053 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -2124,7 +2124,7 @@ fn errUnionPayload(
21242124 const mod = self.bin_file.options.module.?;
21252125 const err_ty = error_union_ty.errorUnionSet();
21262126 const payload_ty = error_union_ty.errorUnionPayload();
2127 if (err_ty.errorSetIsEmpty()) {
2127 if (err_ty.errorSetIsEmpty(mod)) {
21282128 return try error_union_bind.resolveToMcv(self);
21292129 }
21302130 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -4882,9 +4882,10 @@ fn isErr(
48824882 error_union_bind: ReadArg.Bind,
48834883 error_union_ty: Type,
48844884) !MCValue {
4885 const mod = self.bin_file.options.module.?;
48854886 const error_type = error_union_ty.errorUnionSet();
48864887
4887 if (error_type.errorSetIsEmpty()) {
4888 if (error_type.errorSetIsEmpty(mod)) {
48884889 return MCValue{ .immediate = 0 }; // always false
48894890 }
48904891
src/arch/sparc64/CodeGen.zig+1-1
......@@ -3530,7 +3530,7 @@ fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type)
35303530 const mod = self.bin_file.options.module.?;
35313531 const err_ty = error_union_ty.errorUnionSet();
35323532 const payload_ty = error_union_ty.errorUnionPayload();
3533 if (err_ty.errorSetIsEmpty()) {
3533 if (err_ty.errorSetIsEmpty(mod)) {
35343534 return error_union_mcv;
35353535 }
35363536 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
src/arch/wasm/CodeGen.zig+5-5
......@@ -1036,8 +1036,8 @@ fn genValtype(ty: Type, mod: *Module) u8 {
10361036/// Differently from `genValtype` this also allows `void` to create a block
10371037/// with no return type
10381038fn genBlockType(ty: Type, mod: *Module) u8 {
1039 return switch (ty.tag()) {
1040 .void, .noreturn => wasm.block_empty,
1039 return switch (ty.ip_index) {
1040 .void_type, .noreturn_type => wasm.block_empty,
10411041 else => genValtype(ty, mod),
10421042 };
10431043}
......@@ -3948,7 +3948,7 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
39483948 const pl_ty = err_union_ty.errorUnionPayload();
39493949
39503950 const result = result: {
3951 if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
3951 if (err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
39523952 switch (opcode) {
39533953 .i32_ne => break :result WValue{ .imm32 = 0 },
39543954 .i32_eq => break :result WValue{ .imm32 = 1 },
......@@ -4013,7 +4013,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
40134013 const payload_ty = err_ty.errorUnionPayload();
40144014
40154015 const result = result: {
4016 if (err_ty.errorUnionSet().errorSetIsEmpty()) {
4016 if (err_ty.errorUnionSet().errorSetIsEmpty(mod)) {
40174017 break :result WValue{ .imm32 = 0 };
40184018 }
40194019
......@@ -6214,7 +6214,7 @@ fn lowerTry(
62146214 const pl_ty = err_union_ty.errorUnionPayload();
62156215 const pl_has_bits = pl_ty.hasRuntimeBitsIgnoreComptime(mod);
62166216
6217 if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) {
6217 if (!err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
62186218 // Block we can jump out of when error is not set
62196219 try func.startBlock(.block, wasm.block_empty);
62206220
src/arch/x86_64/CodeGen.zig+4-4
......@@ -3624,7 +3624,7 @@ fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
36243624 const operand = try self.resolveInst(ty_op.operand);
36253625
36263626 const result: MCValue = result: {
3627 if (err_ty.errorSetIsEmpty()) {
3627 if (err_ty.errorSetIsEmpty(mod)) {
36283628 break :result MCValue{ .immediate = 0 };
36293629 }
36303630
......@@ -5811,7 +5811,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
58115811 switch (tag) {
58125812 .not => {
58135813 const limb_abi_size = @intCast(u16, @min(src_ty.abiSize(mod), 8));
5814 const int_info = if (src_ty.tag() == .bool)
5814 const int_info = if (src_ty.ip_index == .bool_type)
58155815 std.builtin.Type.Int{ .signedness = .unsigned, .bits = 1 }
58165816 else
58175817 src_ty.intInfo(mod);
......@@ -8716,7 +8716,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
87168716 try self.asmRegisterRegister(.{ ._, .@"test" }, alias_reg, alias_reg);
87178717 return .{ .eflags = .z };
87188718 }
8719 assert(some_info.ty.tag() == .bool);
8719 assert(some_info.ty.ip_index == .bool_type);
87208720 const opt_abi_size = @intCast(u32, opt_ty.abiSize(mod));
87218721 try self.asmRegisterImmediate(
87228722 .{ ._, .bt },
......@@ -8808,7 +8808,7 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, ty: Type, operand: MCValue) !
88088808 const mod = self.bin_file.options.module.?;
88098809 const err_type = ty.errorUnionSet();
88108810
8811 if (err_type.errorSetIsEmpty()) {
8811 if (err_type.errorSetIsEmpty(mod)) {
88128812 return MCValue{ .immediate = 0 }; // always false
88138813 }
88148814
src/codegen/c.zig+8-8
......@@ -1508,7 +1508,7 @@ pub const DeclGen = struct {
15081508 }
15091509 if (fn_decl.val.castTag(.function)) |func_payload|
15101510 if (func_payload.data.is_cold) try w.writeAll("zig_cold ");
1511 if (fn_info.return_type.tag() == .noreturn) try w.writeAll("zig_noreturn ");
1511 if (fn_info.return_type.ip_index == .noreturn_type) try w.writeAll("zig_noreturn ");
15121512
15131513 const trailing = try renderTypePrefix(
15141514 dg.decl_index,
......@@ -3783,7 +3783,7 @@ fn airNot(f: *Function, inst: Air.Inst.Index) !CValue {
37833783 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
37843784 const operand_ty = f.typeOf(ty_op.operand);
37853785 const scalar_ty = operand_ty.scalarType(mod);
3786 if (scalar_ty.tag() != .bool) return try airUnBuiltinCall(f, inst, "not", .bits);
3786 if (scalar_ty.ip_index != .bool_type) return try airUnBuiltinCall(f, inst, "not", .bits);
37873787
37883788 const op = try f.resolveInst(ty_op.operand);
37893789 try reap(f, inst, &.{ty_op.operand});
......@@ -4292,7 +4292,7 @@ fn airBlock(f: *Function, inst: Air.Inst.Index) !CValue {
42924292 const writer = f.object.writer();
42934293
42944294 const inst_ty = f.typeOfIndex(inst);
4295 const result = if (inst_ty.tag() != .void and !f.liveness.isUnused(inst))
4295 const result = if (inst_ty.ip_index != .void_type and !f.liveness.isUnused(inst))
42964296 try f.allocLocal(inst, inst_ty)
42974297 else
42984298 .none;
......@@ -4354,7 +4354,7 @@ fn lowerTry(
43544354 const payload_ty = err_union_ty.errorUnionPayload();
43554355 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(mod);
43564356
4357 if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) {
4357 if (!err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
43584358 try writer.writeAll("if (");
43594359 if (!payload_has_bits) {
43604360 if (is_ptr)
......@@ -5549,7 +5549,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
55495549 if (!payload_ty.hasRuntimeBits(mod)) {
55505550 try f.writeCValue(writer, operand, .Other);
55515551 } else {
5552 if (!error_ty.errorSetIsEmpty())
5552 if (!error_ty.errorSetIsEmpty(mod))
55535553 if (operand_is_ptr)
55545554 try f.writeCValueDerefMember(writer, operand, .{ .identifier = "error" })
55555555 else
......@@ -5768,7 +5768,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
57685768 try f.writeCValue(writer, local, .Other);
57695769 try writer.writeAll(" = ");
57705770
5771 if (!error_ty.errorSetIsEmpty())
5771 if (!error_ty.errorSetIsEmpty(mod))
57725772 if (payload_ty.hasRuntimeBits(mod))
57735773 if (is_ptr)
57745774 try f.writeCValueDerefMember(writer, operand, .{ .identifier = "error" })
......@@ -6032,7 +6032,7 @@ fn airCmpBuiltinCall(
60326032 try writer.writeByte(')');
60336033 if (!ref_ret) try writer.print(" {s} {}", .{
60346034 compareOperatorC(operator),
6035 try f.fmtIntLiteral(Type.initTag(.i32), Value.zero),
6035 try f.fmtIntLiteral(Type.i32, Value.zero),
60366036 });
60376037 try writer.writeAll(";\n");
60386038 try v.end(f, inst, writer);
......@@ -7749,7 +7749,7 @@ const LowerFnRetTyBuffer = struct {
77497749 payload: Type.Payload.AnonStruct,
77507750};
77517751fn lowerFnRetTy(ret_ty: Type, buffer: *LowerFnRetTyBuffer, mod: *const Module) Type {
7752 if (ret_ty.zigTypeTag(mod) == .NoReturn) return Type.initTag(.noreturn);
7752 if (ret_ty.zigTypeTag(mod) == .NoReturn) return Type.noreturn;
77537753
77547754 if (lowersToArray(ret_ty, mod)) {
77557755 buffer.names = [1][]const u8{"array"};
src/codegen/llvm.zig+18-20
......@@ -1730,7 +1730,7 @@ pub const Object = struct {
17301730 return ptr_di_ty;
17311731 },
17321732 .Opaque => {
1733 if (ty.tag() == .anyopaque) {
1733 if (ty.ip_index == .anyopaque_type) {
17341734 const di_ty = dib.createBasicType("anyopaque", 0, DW.ATE.signed);
17351735 gop.value_ptr.* = AnnotatedDITypePtr.initFull(di_ty);
17361736 return di_ty;
......@@ -2847,25 +2847,23 @@ pub const DeclGen = struct {
28472847 const llvm_addrspace = toLlvmAddressSpace(ptr_info.@"addrspace", target);
28482848 return dg.context.pointerType(llvm_addrspace);
28492849 },
2850 .Opaque => switch (t.tag()) {
2851 .@"opaque" => {
2852 const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module });
2853 if (gop.found_existing) return gop.value_ptr.*;
2850 .Opaque => {
2851 if (t.ip_index == .anyopaque_type) return dg.context.intType(8);
28542852
2855 // The Type memory is ephemeral; since we want to store a longer-lived
2856 // reference, we need to copy it here.
2857 gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
2853 const gop = try dg.object.type_map.getOrPutContext(gpa, t, .{ .mod = dg.module });
2854 if (gop.found_existing) return gop.value_ptr.*;
28582855
2859 const opaque_obj = t.castTag(.@"opaque").?.data;
2860 const name = try opaque_obj.getFullyQualifiedName(dg.module);
2861 defer gpa.free(name);
2856 // The Type memory is ephemeral; since we want to store a longer-lived
2857 // reference, we need to copy it here.
2858 gop.key_ptr.* = try t.copy(dg.object.type_map_arena.allocator());
28622859
2863 const llvm_struct_ty = dg.context.structCreateNamed(name);
2864 gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
2865 return llvm_struct_ty;
2866 },
2867 .anyopaque => return dg.context.intType(8),
2868 else => unreachable,
2860 const opaque_obj = t.castTag(.@"opaque").?.data;
2861 const name = try opaque_obj.getFullyQualifiedName(dg.module);
2862 defer gpa.free(name);
2863
2864 const llvm_struct_ty = dg.context.structCreateNamed(name);
2865 gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
2866 return llvm_struct_ty;
28692867 },
28702868 .Array => {
28712869 const elem_ty = t.childType();
......@@ -5531,7 +5529,7 @@ pub const FuncGen = struct {
55315529 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(mod);
55325530 const err_union_llvm_ty = try fg.dg.lowerType(err_union_ty);
55335531
5534 if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) {
5532 if (!err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
55355533 const is_err = err: {
55365534 const err_set_ty = try fg.dg.lowerType(Type.anyerror);
55375535 const zero = err_set_ty.constNull();
......@@ -6715,7 +6713,7 @@ pub const FuncGen = struct {
67156713 const err_set_ty = try self.dg.lowerType(Type.anyerror);
67166714 const zero = err_set_ty.constNull();
67176715
6718 if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
6716 if (err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
67196717 const llvm_i1 = self.context.intType(1);
67206718 switch (op) {
67216719 .EQ => return llvm_i1.constInt(1, .False), // 0 == 0
......@@ -6864,7 +6862,7 @@ pub const FuncGen = struct {
68646862 const operand = try self.resolveInst(ty_op.operand);
68656863 const operand_ty = self.typeOf(ty_op.operand);
68666864 const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
6867 if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
6865 if (err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
68686866 const err_llvm_ty = try self.dg.lowerType(Type.anyerror);
68696867 if (operand_is_ptr) {
68706868 return operand;
src/codegen/spirv.zig+4-2
......@@ -2849,6 +2849,7 @@ pub const DeclGen = struct {
28492849 }
28502850
28512851 fn airTry(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2852 const mod = self.module;
28522853 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
28532854 const err_union_id = try self.resolve(pl_op.operand);
28542855 const extra = self.air.extraData(Air.Try, pl_op.payload);
......@@ -2862,7 +2863,7 @@ pub const DeclGen = struct {
28622863
28632864 const eu_layout = self.errorUnionLayout(payload_ty);
28642865
2865 if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) {
2866 if (!err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
28662867 const err_id = if (eu_layout.payload_has_bits)
28672868 try self.extractField(Type.anyerror, err_union_id, eu_layout.errorFieldIndex())
28682869 else
......@@ -2910,12 +2911,13 @@ pub const DeclGen = struct {
29102911 fn airErrUnionErr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
29112912 if (self.liveness.isUnused(inst)) return null;
29122913
2914 const mod = self.module;
29132915 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
29142916 const operand_id = try self.resolve(ty_op.operand);
29152917 const err_union_ty = self.typeOf(ty_op.operand);
29162918 const err_ty_ref = try self.resolveType(Type.anyerror, .direct);
29172919
2918 if (err_union_ty.errorUnionSet().errorSetIsEmpty()) {
2920 if (err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
29192921 // No error possible, so just return undefined.
29202922 return try self.spv.constUndef(err_ty_ref);
29212923 }
src/print_air.zig-1
......@@ -370,7 +370,6 @@ const Writer = struct {
370370 switch (t) {
371371 .inferred_alloc_const => try s.writeAll("(inferred_alloc_const)"),
372372 .inferred_alloc_mut => try s.writeAll("(inferred_alloc_mut)"),
373 .generic_poison => try s.writeAll("(generic_poison)"),
374373 else => try ty.print(s, w.module),
375374 }
376375 }
src/type.zig+135-604
......@@ -85,9 +85,9 @@ pub const Type = struct {
8585 .address_space,
8686 .float_mode,
8787 .reduce_op,
88 .call_modifier,
8889 => return .Enum,
8990
90 .call_modifier,
9191 .prefetch_options,
9292 .export_options,
9393 .extern_options,
......@@ -95,7 +95,7 @@ pub const Type = struct {
9595
9696 .type_info => return .Union,
9797
98 .generic_poison => unreachable,
98 .generic_poison => return error.GenericPoison,
9999 .var_args_param => unreachable,
100100 },
101101
......@@ -107,8 +107,6 @@ pub const Type = struct {
107107 }
108108 }
109109 switch (ty.tag()) {
110 .generic_poison => return error.GenericPoison,
111
112110 .u1,
113111 .u8,
114112 .i8,
......@@ -125,19 +123,11 @@ pub const Type = struct {
125123
126124 .error_set,
127125 .error_set_single,
128 .anyerror,
129126 .error_set_inferred,
130127 .error_set_merged,
131128 => return .ErrorSet,
132129
133 .anyopaque, .@"opaque" => return .Opaque,
134 .bool => return .Bool,
135 .void => return .Void,
136 .type => return .Type,
137 .comptime_int => return .ComptimeInt,
138 .noreturn => return .NoReturn,
139 .null => return .Null,
140 .undefined => return .Undefined,
130 .@"opaque" => return .Opaque,
141131
142132 .function => return .Fn,
143133
......@@ -172,18 +162,14 @@ pub const Type = struct {
172162 .optional_single_const_pointer,
173163 .optional_single_mut_pointer,
174164 => return .Optional,
175 .enum_literal => return .EnumLiteral,
176165
177166 .anyerror_void_error_union, .error_union => return .ErrorUnion,
178167
179 .anyframe_T, .@"anyframe" => return .AnyFrame,
168 .anyframe_T => return .AnyFrame,
180169
181170 .empty_struct,
182171 .empty_struct_literal,
183172 .@"struct",
184 .prefetch_options,
185 .export_options,
186 .extern_options,
187173 .tuple,
188174 .anon_struct,
189175 => return .Struct,
......@@ -192,19 +178,11 @@ pub const Type = struct {
192178 .enum_nonexhaustive,
193179 .enum_simple,
194180 .enum_numbered,
195 .atomic_order,
196 .atomic_rmw_op,
197 .calling_convention,
198 .address_space,
199 .float_mode,
200 .reduce_op,
201 .modifier,
202181 => return .Enum,
203182
204183 .@"union",
205184 .union_safety_tagged,
206185 .union_tagged,
207 .type_info,
208186 => return .Union,
209187 }
210188 }
......@@ -393,7 +371,7 @@ pub const Type = struct {
393371 pub fn ptrInfo(self: Type) Payload.Pointer {
394372 switch (self.tag()) {
395373 .single_const_pointer_to_comptime_int => return .{ .data = .{
396 .pointee_type = Type.initTag(.comptime_int),
374 .pointee_type = Type.comptime_int,
397375 .sentinel = null,
398376 .@"align" = 0,
399377 .@"addrspace" = .generic,
......@@ -405,7 +383,7 @@ pub const Type = struct {
405383 .size = .One,
406384 } },
407385 .const_slice_u8 => return .{ .data = .{
408 .pointee_type = Type.initTag(.u8),
386 .pointee_type = Type.u8,
409387 .sentinel = null,
410388 .@"align" = 0,
411389 .@"addrspace" = .generic,
......@@ -417,7 +395,7 @@ pub const Type = struct {
417395 .size = .Slice,
418396 } },
419397 .const_slice_u8_sentinel_0 => return .{ .data = .{
420 .pointee_type = Type.initTag(.u8),
398 .pointee_type = Type.u8,
421399 .sentinel = Value.zero,
422400 .@"align" = 0,
423401 .@"addrspace" = .generic,
......@@ -465,7 +443,7 @@ pub const Type = struct {
465443 .size = .Many,
466444 } },
467445 .manyptr_const_u8 => return .{ .data = .{
468 .pointee_type = Type.initTag(.u8),
446 .pointee_type = Type.u8,
469447 .sentinel = null,
470448 .@"align" = 0,
471449 .@"addrspace" = .generic,
......@@ -477,7 +455,7 @@ pub const Type = struct {
477455 .size = .Many,
478456 } },
479457 .manyptr_const_u8_sentinel_0 => return .{ .data = .{
480 .pointee_type = Type.initTag(.u8),
458 .pointee_type = Type.u8,
481459 .sentinel = Value.zero,
482460 .@"align" = 0,
483461 .@"addrspace" = .generic,
......@@ -501,7 +479,7 @@ pub const Type = struct {
501479 .size = .Many,
502480 } },
503481 .manyptr_u8 => return .{ .data = .{
504 .pointee_type = Type.initTag(.u8),
482 .pointee_type = Type.u8,
505483 .sentinel = null,
506484 .@"align" = 0,
507485 .@"addrspace" = .generic,
......@@ -608,23 +586,6 @@ pub const Type = struct {
608586 if (a.legacy.tag_if_small_enough == b.legacy.tag_if_small_enough) return true;
609587
610588 switch (a.tag()) {
611 .generic_poison => unreachable,
612
613 .bool,
614 .void,
615 .type,
616 .comptime_int,
617 .noreturn,
618 .null,
619 .undefined,
620 .anyopaque,
621 .@"anyframe",
622 .enum_literal,
623 => |a_tag| {
624 assert(a_tag != b.tag()); // because of the comparison at the top of the function.
625 return false;
626 },
627
628589 .u1,
629590 .u8,
630591 .i8,
......@@ -653,10 +614,6 @@ pub const Type = struct {
653614 return a_ies == b_ies;
654615 },
655616
656 .anyerror => {
657 return b.tag() == .anyerror;
658 },
659
660617 .error_set,
661618 .error_set_single,
662619 .error_set_merged,
......@@ -927,13 +884,6 @@ pub const Type = struct {
927884 return true;
928885 },
929886
930 // we can't compare these based on tags because it wouldn't detect if,
931 // for example, a was resolved into .@"struct" but b was one of these tags.
932 .prefetch_options,
933 .export_options,
934 .extern_options,
935 => unreachable, // needed to resolve the type before now
936
937887 .enum_full, .enum_nonexhaustive => {
938888 const a_enum_obj = a.cast(Payload.EnumFull).?.data;
939889 const b_enum_obj = (b.cast(Payload.EnumFull) orelse return false).data;
......@@ -949,26 +899,12 @@ pub const Type = struct {
949899 const b_enum_obj = (b.cast(Payload.EnumNumbered) orelse return false).data;
950900 return a_enum_obj == b_enum_obj;
951901 },
952 // we can't compare these based on tags because it wouldn't detect if,
953 // for example, a was resolved into .enum_simple but b was one of these tags.
954 .atomic_order,
955 .atomic_rmw_op,
956 .calling_convention,
957 .address_space,
958 .float_mode,
959 .reduce_op,
960 .modifier,
961 => unreachable, // needed to resolve the type before now
962902
963903 .@"union", .union_safety_tagged, .union_tagged => {
964904 const a_union_obj = a.cast(Payload.Union).?.data;
965905 const b_union_obj = (b.cast(Payload.Union) orelse return false).data;
966906 return a_union_obj == b_union_obj;
967907 },
968 // we can't compare these based on tags because it wouldn't detect if,
969 // for example, a was resolved into .union_tagged but b was one of these tags.
970 .type_info => unreachable, // needed to resolve the type before now
971
972908 }
973909 }
974910
......@@ -987,31 +923,6 @@ pub const Type = struct {
987923 return;
988924 }
989925 switch (ty.tag()) {
990 .generic_poison => unreachable,
991
992 .bool => std.hash.autoHash(hasher, std.builtin.TypeId.Bool),
993 .void => std.hash.autoHash(hasher, std.builtin.TypeId.Void),
994 .type => std.hash.autoHash(hasher, std.builtin.TypeId.Type),
995 .comptime_int => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeInt),
996 .noreturn => std.hash.autoHash(hasher, std.builtin.TypeId.NoReturn),
997 .null => std.hash.autoHash(hasher, std.builtin.TypeId.Null),
998 .undefined => std.hash.autoHash(hasher, std.builtin.TypeId.Undefined),
999
1000 .anyopaque => {
1001 std.hash.autoHash(hasher, std.builtin.TypeId.Opaque);
1002 std.hash.autoHash(hasher, Tag.anyopaque);
1003 },
1004
1005 .@"anyframe" => {
1006 std.hash.autoHash(hasher, std.builtin.TypeId.AnyFrame);
1007 std.hash.autoHash(hasher, Tag.@"anyframe");
1008 },
1009
1010 .enum_literal => {
1011 std.hash.autoHash(hasher, std.builtin.TypeId.EnumLiteral);
1012 std.hash.autoHash(hasher, Tag.enum_literal);
1013 },
1014
1015926 .u1,
1016927 .u8,
1017928 .i8,
......@@ -1046,12 +957,6 @@ pub const Type = struct {
1046957 for (names) |name| hasher.update(name);
1047958 },
1048959
1049 .anyerror => {
1050 // anyerror is distinct from other error sets
1051 std.hash.autoHash(hasher, std.builtin.TypeId.ErrorSet);
1052 std.hash.autoHash(hasher, Tag.anyerror);
1053 },
1054
1055960 .error_set_inferred => {
1056961 // inferred error sets are compared using their data pointer
1057962 const ies: *Module.Fn.InferredErrorSet = ty.castTag(.error_set_inferred).?.data;
......@@ -1209,12 +1114,6 @@ pub const Type = struct {
12091114 }
12101115 },
12111116
1212 // we can't hash these based on tags because they wouldn't match the expanded version.
1213 .prefetch_options,
1214 .export_options,
1215 .extern_options,
1216 => unreachable, // needed to resolve the type before now
1217
12181117 .enum_full, .enum_nonexhaustive => {
12191118 const enum_obj: *const Module.EnumFull = ty.cast(Payload.EnumFull).?.data;
12201119 std.hash.autoHash(hasher, std.builtin.TypeId.Enum);
......@@ -1230,24 +1129,12 @@ pub const Type = struct {
12301129 std.hash.autoHash(hasher, std.builtin.TypeId.Enum);
12311130 std.hash.autoHash(hasher, enum_obj);
12321131 },
1233 // we can't hash these based on tags because they wouldn't match the expanded version.
1234 .atomic_order,
1235 .atomic_rmw_op,
1236 .calling_convention,
1237 .address_space,
1238 .float_mode,
1239 .reduce_op,
1240 .modifier,
1241 => unreachable, // needed to resolve the type before now
12421132
12431133 .@"union", .union_safety_tagged, .union_tagged => {
12441134 const union_obj: *const Module.Union = ty.cast(Payload.Union).?.data;
12451135 std.hash.autoHash(hasher, std.builtin.TypeId.Union);
12461136 std.hash.autoHash(hasher, union_obj);
12471137 },
1248 // we can't hash these based on tags because they wouldn't match the expanded version.
1249 .type_info => unreachable, // needed to resolve the type before now
1250
12511138 }
12521139 }
12531140
......@@ -1305,19 +1192,9 @@ pub const Type = struct {
13051192 .i64,
13061193 .u128,
13071194 .i128,
1308 .anyopaque,
1309 .bool,
1310 .void,
1311 .type,
1312 .anyerror,
1313 .comptime_int,
1314 .noreturn,
1315 .null,
1316 .undefined,
13171195 .single_const_pointer_to_comptime_int,
13181196 .const_slice_u8,
13191197 .const_slice_u8_sentinel_0,
1320 .enum_literal,
13211198 .anyerror_void_error_union,
13221199 .inferred_alloc_const,
13231200 .inferred_alloc_mut,
......@@ -1325,19 +1202,6 @@ pub const Type = struct {
13251202 .manyptr_u8,
13261203 .manyptr_const_u8,
13271204 .manyptr_const_u8_sentinel_0,
1328 .atomic_order,
1329 .atomic_rmw_op,
1330 .calling_convention,
1331 .address_space,
1332 .float_mode,
1333 .reduce_op,
1334 .modifier,
1335 .prefetch_options,
1336 .export_options,
1337 .extern_options,
1338 .type_info,
1339 .@"anyframe",
1340 .generic_poison,
13411205 => unreachable,
13421206
13431207 .array_u8,
......@@ -1580,20 +1444,8 @@ pub const Type = struct {
15801444 .i64,
15811445 .u128,
15821446 .i128,
1583 .anyopaque,
1584 .bool,
1585 .void,
1586 .type,
1587 .anyerror,
1588 .@"anyframe",
1589 .comptime_int,
1590 .noreturn,
15911447 => return writer.writeAll(@tagName(t)),
15921448
1593 .enum_literal => return writer.writeAll("@Type(.EnumLiteral)"),
1594 .null => return writer.writeAll("@Type(.Null)"),
1595 .undefined => return writer.writeAll("@Type(.Undefined)"),
1596
15971449 .empty_struct, .empty_struct_literal => return writer.writeAll("struct {}"),
15981450
15991451 .@"struct" => {
......@@ -1640,17 +1492,6 @@ pub const Type = struct {
16401492 .manyptr_u8 => return writer.writeAll("[*]u8"),
16411493 .manyptr_const_u8 => return writer.writeAll("[*]const u8"),
16421494 .manyptr_const_u8_sentinel_0 => return writer.writeAll("[*:0]const u8"),
1643 .atomic_order => return writer.writeAll("std.builtin.AtomicOrder"),
1644 .atomic_rmw_op => return writer.writeAll("std.builtin.AtomicRmwOp"),
1645 .calling_convention => return writer.writeAll("std.builtin.CallingConvention"),
1646 .address_space => return writer.writeAll("std.builtin.AddressSpace"),
1647 .float_mode => return writer.writeAll("std.builtin.FloatMode"),
1648 .reduce_op => return writer.writeAll("std.builtin.ReduceOp"),
1649 .modifier => return writer.writeAll("std.builtin.CallModifier"),
1650 .prefetch_options => return writer.writeAll("std.builtin.PrefetchOptions"),
1651 .export_options => return writer.writeAll("std.builtin.ExportOptions"),
1652 .extern_options => return writer.writeAll("std.builtin.ExternOptions"),
1653 .type_info => return writer.writeAll("std.builtin.Type"),
16541495 .function => {
16551496 const payload = ty.castTag(.function).?.data;
16561497 try writer.writeAll("fn(");
......@@ -1889,7 +1730,6 @@ pub const Type = struct {
18891730 },
18901731 .inferred_alloc_const => return writer.writeAll("(inferred_alloc_const)"),
18911732 .inferred_alloc_mut => return writer.writeAll("(inferred_alloc_mut)"),
1892 .generic_poison => return writer.writeAll("(generic poison)"),
18931733 }
18941734 unreachable;
18951735 }
......@@ -1931,20 +1771,6 @@ pub const Type = struct {
19311771 switch (t) {
19321772 .inferred_alloc_const => unreachable,
19331773 .inferred_alloc_mut => unreachable,
1934 .generic_poison => unreachable,
1935
1936 // TODO get rid of these Type.Tag values.
1937 .atomic_order => unreachable,
1938 .atomic_rmw_op => unreachable,
1939 .calling_convention => unreachable,
1940 .address_space => unreachable,
1941 .float_mode => unreachable,
1942 .reduce_op => unreachable,
1943 .modifier => unreachable,
1944 .prefetch_options => unreachable,
1945 .export_options => unreachable,
1946 .extern_options => unreachable,
1947 .type_info => unreachable,
19481774
19491775 .u1,
19501776 .u8,
......@@ -1958,19 +1784,8 @@ pub const Type = struct {
19581784 .i64,
19591785 .u128,
19601786 .i128,
1961 .anyopaque,
1962 .bool,
1963 .void,
1964 .type,
1965 .anyerror,
1966 .@"anyframe",
1967 .comptime_int,
1968 .noreturn,
19691787 => try writer.writeAll(@tagName(t)),
19701788
1971 .enum_literal => try writer.writeAll("@TypeOf(.enum_literal)"),
1972 .null => try writer.writeAll("@TypeOf(null)"),
1973 .undefined => try writer.writeAll("@TypeOf(undefined)"),
19741789 .empty_struct_literal => try writer.writeAll("@TypeOf(.{})"),
19751790
19761791 .empty_struct => {
......@@ -2249,34 +2064,12 @@ pub const Type = struct {
22492064 .i32 => return Value.initTag(.i32_type),
22502065 .u64 => return Value.initTag(.u64_type),
22512066 .i64 => return Value.initTag(.i64_type),
2252 .anyopaque => return Value.initTag(.anyopaque_type),
2253 .bool => return Value.initTag(.bool_type),
2254 .void => return Value.initTag(.void_type),
2255 .type => return Value.initTag(.type_type),
2256 .anyerror => return Value.initTag(.anyerror_type),
2257 .@"anyframe" => return Value.initTag(.anyframe_type),
2258 .comptime_int => return Value.initTag(.comptime_int_type),
2259 .noreturn => return Value.initTag(.noreturn_type),
2260 .null => return Value.initTag(.null_type),
2261 .undefined => return Value.initTag(.undefined_type),
22622067 .single_const_pointer_to_comptime_int => return Value.initTag(.single_const_pointer_to_comptime_int_type),
22632068 .const_slice_u8 => return Value.initTag(.const_slice_u8_type),
22642069 .const_slice_u8_sentinel_0 => return Value.initTag(.const_slice_u8_sentinel_0_type),
2265 .enum_literal => return Value.initTag(.enum_literal_type),
22662070 .manyptr_u8 => return Value.initTag(.manyptr_u8_type),
22672071 .manyptr_const_u8 => return Value.initTag(.manyptr_const_u8_type),
22682072 .manyptr_const_u8_sentinel_0 => return Value.initTag(.manyptr_const_u8_sentinel_0_type),
2269 .atomic_order => return Value.initTag(.atomic_order_type),
2270 .atomic_rmw_op => return Value.initTag(.atomic_rmw_op_type),
2271 .calling_convention => return Value.initTag(.calling_convention_type),
2272 .address_space => return Value.initTag(.address_space_type),
2273 .float_mode => return Value.initTag(.float_mode_type),
2274 .reduce_op => return Value.initTag(.reduce_op_type),
2275 .modifier => return Value.initTag(.modifier_type),
2276 .prefetch_options => return Value.initTag(.prefetch_options_type),
2277 .export_options => return Value.initTag(.export_options_type),
2278 .extern_options => return Value.initTag(.extern_options_type),
2279 .type_info => return Value.initTag(.type_info_type),
22802073 .inferred_alloc_const => unreachable,
22812074 .inferred_alloc_mut => unreachable,
22822075 else => return Value.Tag.ty.create(allocator, self),
......@@ -2378,8 +2171,7 @@ pub const Type = struct {
23782171 .i64,
23792172 .u128,
23802173 .i128,
2381 .bool,
2382 .anyerror,
2174
23832175 .const_slice_u8,
23842176 .const_slice_u8_sentinel_0,
23852177 .array_u8_sentinel_0,
......@@ -2388,18 +2180,7 @@ pub const Type = struct {
23882180 .manyptr_u8,
23892181 .manyptr_const_u8,
23902182 .manyptr_const_u8_sentinel_0,
2391 .atomic_order,
2392 .atomic_rmw_op,
2393 .calling_convention,
2394 .address_space,
2395 .float_mode,
2396 .reduce_op,
2397 .modifier,
2398 .prefetch_options,
2399 .export_options,
2400 .extern_options,
2401 .@"anyframe",
2402 .anyopaque,
2183
24032184 .@"opaque",
24042185 .error_set_single,
24052186 .error_union,
......@@ -2435,16 +2216,8 @@ pub const Type = struct {
24352216
24362217 // These are false because they are comptime-only types.
24372218 .single_const_pointer_to_comptime_int,
2438 .void,
2439 .type,
2440 .comptime_int,
2441 .noreturn,
2442 .null,
2443 .undefined,
2444 .enum_literal,
24452219 .empty_struct,
24462220 .empty_struct_literal,
2447 .type_info,
24482221 // These are function *bodies*, not pointers.
24492222 // Special exceptions have to be made when emitting functions due to
24502223 // this returning false.
......@@ -2558,7 +2331,6 @@ pub const Type = struct {
25582331
25592332 .inferred_alloc_const => unreachable,
25602333 .inferred_alloc_mut => unreachable,
2561 .generic_poison => unreachable,
25622334 }
25632335 }
25642336
......@@ -2641,8 +2413,7 @@ pub const Type = struct {
26412413 .i64,
26422414 .u128,
26432415 .i128,
2644 .bool,
2645 .void,
2416
26462417 .manyptr_u8,
26472418 .manyptr_const_u8,
26482419 .manyptr_const_u8_sentinel_0,
......@@ -2662,32 +2433,11 @@ pub const Type = struct {
26622433 .optional_single_const_pointer,
26632434 => true,
26642435
2665 .anyopaque,
2666 .anyerror,
2667 .noreturn,
2668 .null,
2669 .@"anyframe",
2670 .undefined,
2671 .atomic_order,
2672 .atomic_rmw_op,
2673 .calling_convention,
2674 .address_space,
2675 .float_mode,
2676 .reduce_op,
2677 .modifier,
2678 .prefetch_options,
2679 .export_options,
2680 .extern_options,
26812436 .error_set,
26822437 .error_set_single,
26832438 .error_set_inferred,
26842439 .error_set_merged,
26852440 .@"opaque",
2686 .generic_poison,
2687 .type,
2688 .comptime_int,
2689 .enum_literal,
2690 .type_info,
26912441 // These are function bodies, not function pointers.
26922442 .function,
26932443 .const_slice_u8,
......@@ -2773,7 +2523,6 @@ pub const Type = struct {
27732523 else => return false,
27742524
27752525 @enumToInt(InternPool.Index.none) => switch (ty.tag()) {
2776 .noreturn => return true,
27772526 .error_set => {
27782527 const err_set_obj = ty.castTag(.error_set).?.data;
27792528 const names = err_set_obj.names.keys();
......@@ -3003,21 +2752,10 @@ pub const Type = struct {
30032752 .u1,
30042753 .u8,
30052754 .i8,
3006 .bool,
2755
30072756 .array_u8_sentinel_0,
30082757 .array_u8,
3009 .atomic_order,
3010 .atomic_rmw_op,
3011 .calling_convention,
3012 .address_space,
3013 .float_mode,
3014 .reduce_op,
3015 .modifier,
3016 .prefetch_options,
3017 .export_options,
3018 .extern_options,
30192758 .@"opaque",
3020 .anyopaque,
30212759 => return AbiAlignmentAdvanced{ .scalar = 1 },
30222760
30232761 // represents machine code; not a pointer
......@@ -3044,13 +2782,11 @@ pub const Type = struct {
30442782 .manyptr_u8,
30452783 .manyptr_const_u8,
30462784 .manyptr_const_u8_sentinel_0,
3047 .@"anyframe",
30482785 .anyframe_T,
30492786 => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
30502787
30512788 // TODO revisit this when we have the concept of the error tag type
30522789 .anyerror_void_error_union,
3053 .anyerror,
30542790 .error_set_inferred,
30552791 .error_set_single,
30562792 .error_set,
......@@ -3229,22 +2965,12 @@ pub const Type = struct {
32292965 },
32302966
32312967 .empty_struct,
3232 .void,
32332968 .empty_struct_literal,
3234 .type,
3235 .comptime_int,
3236 .null,
3237 .undefined,
3238 .enum_literal,
3239 .type_info,
32402969 => return AbiAlignmentAdvanced{ .scalar = 0 },
32412970
3242 .noreturn,
32432971 .inferred_alloc_const,
32442972 .inferred_alloc_mut,
32452973 => unreachable,
3246
3247 .generic_poison => unreachable,
32482974 }
32492975 }
32502976
......@@ -3422,26 +3148,12 @@ pub const Type = struct {
34223148 switch (ty.tag()) {
34233149 .function => unreachable, // represents machine code; not a pointer
34243150 .@"opaque" => unreachable, // no size available
3425 .noreturn => unreachable,
34263151 .inferred_alloc_const => unreachable,
34273152 .inferred_alloc_mut => unreachable,
3428 .generic_poison => unreachable,
3429 .modifier => unreachable, // missing call to resolveTypeFields
3430 .prefetch_options => unreachable, // missing call to resolveTypeFields
3431 .export_options => unreachable, // missing call to resolveTypeFields
3432 .extern_options => unreachable, // missing call to resolveTypeFields
3433 .type_info => unreachable, // missing call to resolveTypeFields
3434
3435 .anyopaque,
3436 .type,
3437 .comptime_int,
3438 .null,
3439 .undefined,
3440 .enum_literal,
3153
34413154 .single_const_pointer_to_comptime_int,
34423155 .empty_struct_literal,
34433156 .empty_struct,
3444 .void,
34453157 => return AbiSizeAdvanced{ .scalar = 0 },
34463158
34473159 .@"struct", .tuple, .anon_struct => switch (ty.containerLayout()) {
......@@ -3496,13 +3208,6 @@ pub const Type = struct {
34963208 .u1,
34973209 .u8,
34983210 .i8,
3499 .bool,
3500 .atomic_order,
3501 .atomic_rmw_op,
3502 .calling_convention,
3503 .address_space,
3504 .float_mode,
3505 .reduce_op,
35063211 => return AbiSizeAdvanced{ .scalar = 1 },
35073212
35083213 .array_u8 => return AbiSizeAdvanced{ .scalar = ty.castTag(.array_u8).?.data },
......@@ -3552,7 +3257,6 @@ pub const Type = struct {
35523257 return AbiSizeAdvanced{ .scalar = result };
35533258 },
35543259
3555 .@"anyframe",
35563260 .anyframe_T,
35573261 .optional_single_const_pointer,
35583262 .optional_single_mut_pointer,
......@@ -3580,7 +3284,6 @@ pub const Type = struct {
35803284
35813285 // TODO revisit this when we have the concept of the error tag type
35823286 .anyerror_void_error_union,
3583 .anyerror,
35843287 .error_set_inferred,
35853288 .error_set,
35863289 .error_set_merged,
......@@ -3758,6 +3461,7 @@ pub const Type = struct {
37583461 .undefined => unreachable,
37593462 .enum_literal => unreachable,
37603463 .generic_poison => unreachable,
3464 .var_args_param => unreachable,
37613465
37623466 .atomic_order => unreachable, // missing call to resolveTypeFields
37633467 .atomic_rmw_op => unreachable, // missing call to resolveTypeFields
......@@ -3770,7 +3474,6 @@ pub const Type = struct {
37703474 .export_options => unreachable, // missing call to resolveTypeFields
37713475 .extern_options => unreachable, // missing call to resolveTypeFields
37723476 .type_info => unreachable, // missing call to resolveTypeFields
3773 .var_args_param => unreachable,
37743477 },
37753478 .struct_type => @panic("TODO"),
37763479 .union_type => @panic("TODO"),
......@@ -3784,23 +3487,14 @@ pub const Type = struct {
37843487
37853488 switch (ty.tag()) {
37863489 .function => unreachable, // represents machine code; not a pointer
3787 .anyopaque => unreachable,
3788 .type => unreachable,
3789 .comptime_int => unreachable,
3790 .noreturn => unreachable,
3791 .null => unreachable,
3792 .undefined => unreachable,
3793 .enum_literal => unreachable,
37943490 .single_const_pointer_to_comptime_int => unreachable,
37953491 .empty_struct => unreachable,
37963492 .empty_struct_literal => unreachable,
37973493 .inferred_alloc_const => unreachable,
37983494 .inferred_alloc_mut => unreachable,
37993495 .@"opaque" => unreachable,
3800 .generic_poison => unreachable,
38013496
3802 .void => return 0,
3803 .bool, .u1 => return 1,
3497 .u1 => return 1,
38043498 .u8, .i8 => return 8,
38053499 .i16, .u16 => return 16,
38063500 .u29 => return 29,
......@@ -3875,9 +3569,7 @@ pub const Type = struct {
38753569 return payload.len * 8 * elem_size + elem_bit_size;
38763570 },
38773571
3878 .@"anyframe",
3879 .anyframe_T,
3880 => return target.ptrBitWidth(),
3572 .anyframe_T => return target.ptrBitWidth(),
38813573
38823574 .const_slice,
38833575 .mut_slice,
......@@ -3916,7 +3608,6 @@ pub const Type = struct {
39163608 .error_set,
39173609 .error_set_single,
39183610 .anyerror_void_error_union,
3919 .anyerror,
39203611 .error_set_inferred,
39213612 .error_set_merged,
39223613 => return 16, // TODO revisit this when we have the concept of the error tag type
......@@ -3926,19 +3617,6 @@ pub const Type = struct {
39263617 // includes padding bits.
39273618 return (try abiSizeAdvanced(ty, mod, strat)).scalar * 8;
39283619 },
3929
3930 .atomic_order,
3931 .atomic_rmw_op,
3932 .calling_convention,
3933 .address_space,
3934 .float_mode,
3935 .reduce_op,
3936 .modifier,
3937 .prefetch_options,
3938 .export_options,
3939 .extern_options,
3940 .type_info,
3941 => @panic("TODO at some point we gotta resolve builtin types"),
39423620 }
39433621 }
39443622
......@@ -4326,7 +4004,7 @@ pub const Type = struct {
43264004 .manyptr_const_u8_sentinel_0,
43274005 => Type.u8,
43284006
4329 .single_const_pointer_to_comptime_int => Type.initTag(.comptime_int),
4007 .single_const_pointer_to_comptime_int => Type.comptime_int,
43304008 .pointer => ty.castTag(.pointer).?.data.pointee_type,
43314009
43324010 else => unreachable,
......@@ -4372,7 +4050,7 @@ pub const Type = struct {
43724050 .manyptr_const_u8_sentinel_0,
43734051 => Type.u8,
43744052
4375 .single_const_pointer_to_comptime_int => Type.initTag(.comptime_int),
4053 .single_const_pointer_to_comptime_int => Type.comptime_int,
43764054 .pointer => {
43774055 const info = ty.castTag(.pointer).?.data;
43784056 const child_ty = info.pointee_type;
......@@ -4387,7 +4065,6 @@ pub const Type = struct {
43874065 .optional_single_const_pointer => ty.castPointer().?.data,
43884066
43894067 .anyframe_T => ty.castTag(.anyframe_T).?.data,
4390 .@"anyframe" => Type.void,
43914068
43924069 else => unreachable,
43934070 };
......@@ -4468,19 +4145,6 @@ pub const Type = struct {
44684145 return union_obj.tag_ty;
44694146 },
44704147
4471 .atomic_order,
4472 .atomic_rmw_op,
4473 .calling_convention,
4474 .address_space,
4475 .float_mode,
4476 .reduce_op,
4477 .modifier,
4478 .prefetch_options,
4479 .export_options,
4480 .extern_options,
4481 .type_info,
4482 => unreachable, // needed to call resolveTypeFields first
4483
44844148 else => null,
44854149 };
44864150 }
......@@ -4495,19 +4159,6 @@ pub const Type = struct {
44954159 return union_obj.tag_ty;
44964160 },
44974161
4498 .atomic_order,
4499 .atomic_rmw_op,
4500 .calling_convention,
4501 .address_space,
4502 .float_mode,
4503 .reduce_op,
4504 .modifier,
4505 .prefetch_options,
4506 .export_options,
4507 .extern_options,
4508 .type_info,
4509 => unreachable, // needed to call resolveTypeFields first
4510
45114162 else => null,
45124163 };
45134164 }
......@@ -4572,7 +4223,7 @@ pub const Type = struct {
45724223 /// Asserts that the type is an error union.
45734224 pub fn errorUnionPayload(self: Type) Type {
45744225 return switch (self.tag()) {
4575 .anyerror_void_error_union => Type.initTag(.void),
4226 .anyerror_void_error_union => Type.void,
45764227 .error_union => self.castTag(.error_union).?.data.payload,
45774228 else => unreachable,
45784229 };
......@@ -4580,33 +4231,38 @@ pub const Type = struct {
45804231
45814232 pub fn errorUnionSet(self: Type) Type {
45824233 return switch (self.tag()) {
4583 .anyerror_void_error_union => Type.initTag(.anyerror),
4234 .anyerror_void_error_union => Type.anyerror,
45844235 .error_union => self.castTag(.error_union).?.data.error_set,
45854236 else => unreachable,
45864237 };
45874238 }
45884239
45894240 /// Returns false for unresolved inferred error sets.
4590 pub fn errorSetIsEmpty(ty: Type) bool {
4591 switch (ty.tag()) {
4592 .anyerror => return false,
4593 .error_set_inferred => {
4594 const inferred_error_set = ty.castTag(.error_set_inferred).?.data;
4595 // Can't know for sure.
4596 if (!inferred_error_set.is_resolved) return false;
4597 if (inferred_error_set.is_anyerror) return false;
4598 return inferred_error_set.errors.count() == 0;
4599 },
4600 .error_set_single => return false,
4601 .error_set => {
4602 const err_set_obj = ty.castTag(.error_set).?.data;
4603 return err_set_obj.names.count() == 0;
4241 pub fn errorSetIsEmpty(ty: Type, mod: *const Module) bool {
4242 switch (ty.ip_index) {
4243 .none => switch (ty.tag()) {
4244 .error_set_inferred => {
4245 const inferred_error_set = ty.castTag(.error_set_inferred).?.data;
4246 // Can't know for sure.
4247 if (!inferred_error_set.is_resolved) return false;
4248 if (inferred_error_set.is_anyerror) return false;
4249 return inferred_error_set.errors.count() == 0;
4250 },
4251 .error_set_single => return false,
4252 .error_set => {
4253 const err_set_obj = ty.castTag(.error_set).?.data;
4254 return err_set_obj.names.count() == 0;
4255 },
4256 .error_set_merged => {
4257 const name_map = ty.castTag(.error_set_merged).?.data;
4258 return name_map.count() == 0;
4259 },
4260 else => unreachable,
46044261 },
4605 .error_set_merged => {
4606 const name_map = ty.castTag(.error_set_merged).?.data;
4607 return name_map.count() == 0;
4262 .anyerror_type => return false,
4263 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4264 else => @panic("TODO"),
46084265 },
4609 else => unreachable,
46104266 }
46114267 }
46124268
......@@ -4614,9 +4270,13 @@ pub const Type = struct {
46144270 /// Note that the result may be a false negative if the type did not get error set
46154271 /// resolution prior to this call.
46164272 pub fn isAnyError(ty: Type) bool {
4617 return switch (ty.tag()) {
4618 .anyerror => true,
4619 .error_set_inferred => ty.castTag(.error_set_inferred).?.data.is_anyerror,
4273 return switch (ty.ip_index) {
4274 .none => switch (ty.tag()) {
4275 .error_set_inferred => ty.castTag(.error_set_inferred).?.data.is_anyerror,
4276 else => false,
4277 },
4278 .anyerror_type => true,
4279 // TODO handle error_set_inferred here
46204280 else => false,
46214281 };
46224282 }
......@@ -4788,72 +4448,75 @@ pub const Type = struct {
47884448 const target = mod.getTarget();
47894449 var ty = starting_ty;
47904450
4791 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4792 .int_type => |int_type| return int_type,
4793 .ptr_type => unreachable,
4794 .array_type => unreachable,
4795 .vector_type => @panic("TODO"),
4796 .optional_type => unreachable,
4797 .error_union_type => unreachable,
4798 .simple_type => |t| switch (t) {
4799 .usize => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },
4800 .isize => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },
4801 .c_char => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.char) },
4802 .c_short => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.short) },
4803 .c_ushort => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ushort) },
4804 .c_int => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.int) },
4805 .c_uint => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.uint) },
4806 .c_long => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.long) },
4807 .c_ulong => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulong) },
4808 .c_longlong => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.longlong) },
4809 .c_ulonglong => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },
4810 else => unreachable,
4811 },
4812 .struct_type => @panic("TODO"),
4813 .union_type => unreachable,
4814 .simple_value => unreachable,
4815 .extern_func => unreachable,
4816 .int => unreachable,
4817 .enum_tag => unreachable, // it's a value, not a type
4818 };
4451 while (true) switch (ty.ip_index) {
4452 .none => switch (ty.tag()) {
4453 .u1 => return .{ .signedness = .unsigned, .bits = 1 },
4454 .u8 => return .{ .signedness = .unsigned, .bits = 8 },
4455 .i8 => return .{ .signedness = .signed, .bits = 8 },
4456 .u16 => return .{ .signedness = .unsigned, .bits = 16 },
4457 .i16 => return .{ .signedness = .signed, .bits = 16 },
4458 .u29 => return .{ .signedness = .unsigned, .bits = 29 },
4459 .u32 => return .{ .signedness = .unsigned, .bits = 32 },
4460 .i32 => return .{ .signedness = .signed, .bits = 32 },
4461 .u64 => return .{ .signedness = .unsigned, .bits = 64 },
4462 .i64 => return .{ .signedness = .signed, .bits = 64 },
4463 .u128 => return .{ .signedness = .unsigned, .bits = 128 },
4464 .i128 => return .{ .signedness = .signed, .bits = 128 },
4465
4466 .enum_full, .enum_nonexhaustive => ty = ty.cast(Payload.EnumFull).?.data.tag_ty,
4467 .enum_numbered => ty = ty.castTag(.enum_numbered).?.data.tag_ty,
4468 .enum_simple => {
4469 const enum_obj = ty.castTag(.enum_simple).?.data;
4470 const field_count = enum_obj.fields.count();
4471 if (field_count == 0) return .{ .signedness = .unsigned, .bits = 0 };
4472 return .{ .signedness = .unsigned, .bits = smallestUnsignedBits(field_count - 1) };
4473 },
48194474
4820 while (true) switch (ty.tag()) {
4821 .u1 => return .{ .signedness = .unsigned, .bits = 1 },
4822 .u8 => return .{ .signedness = .unsigned, .bits = 8 },
4823 .i8 => return .{ .signedness = .signed, .bits = 8 },
4824 .u16 => return .{ .signedness = .unsigned, .bits = 16 },
4825 .i16 => return .{ .signedness = .signed, .bits = 16 },
4826 .u29 => return .{ .signedness = .unsigned, .bits = 29 },
4827 .u32 => return .{ .signedness = .unsigned, .bits = 32 },
4828 .i32 => return .{ .signedness = .signed, .bits = 32 },
4829 .u64 => return .{ .signedness = .unsigned, .bits = 64 },
4830 .i64 => return .{ .signedness = .signed, .bits = 64 },
4831 .u128 => return .{ .signedness = .unsigned, .bits = 128 },
4832 .i128 => return .{ .signedness = .signed, .bits = 128 },
4833
4834 .enum_full, .enum_nonexhaustive => ty = ty.cast(Payload.EnumFull).?.data.tag_ty,
4835 .enum_numbered => ty = ty.castTag(.enum_numbered).?.data.tag_ty,
4836 .enum_simple => {
4837 const enum_obj = ty.castTag(.enum_simple).?.data;
4838 const field_count = enum_obj.fields.count();
4839 if (field_count == 0) return .{ .signedness = .unsigned, .bits = 0 };
4840 return .{ .signedness = .unsigned, .bits = smallestUnsignedBits(field_count - 1) };
4841 },
4475 .error_set, .error_set_single, .error_set_inferred, .error_set_merged => {
4476 // TODO revisit this when error sets support custom int types
4477 return .{ .signedness = .unsigned, .bits = 16 };
4478 },
4479
4480 .vector => ty = ty.castTag(.vector).?.data.elem_type,
4481
4482 .@"struct" => {
4483 const struct_obj = ty.castTag(.@"struct").?.data;
4484 assert(struct_obj.layout == .Packed);
4485 ty = struct_obj.backing_int_ty;
4486 },
48424487
4843 .error_set, .error_set_single, .anyerror, .error_set_inferred, .error_set_merged => {
4488 else => unreachable,
4489 },
4490 .anyerror_type => {
48444491 // TODO revisit this when error sets support custom int types
48454492 return .{ .signedness = .unsigned, .bits = 16 };
48464493 },
4847
4848 .vector => ty = ty.castTag(.vector).?.data.elem_type,
4849
4850 .@"struct" => {
4851 const struct_obj = ty.castTag(.@"struct").?.data;
4852 assert(struct_obj.layout == .Packed);
4853 ty = struct_obj.backing_int_ty;
4494 .usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },
4495 .isize_type => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },
4496 .c_char_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.char) },
4497 .c_short_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.short) },
4498 .c_ushort_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ushort) },
4499 .c_int_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.int) },
4500 .c_uint_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.uint) },
4501 .c_long_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.long) },
4502 .c_ulong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulong) },
4503 .c_longlong_type => return .{ .signedness = .signed, .bits = target.c_type_bit_size(.longlong) },
4504 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },
4505 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4506 .int_type => |int_type| return int_type,
4507 .ptr_type => unreachable,
4508 .array_type => unreachable,
4509 .vector_type => @panic("TODO"),
4510 .optional_type => unreachable,
4511 .error_union_type => unreachable,
4512 .simple_type => unreachable, // handled via Index enum tag above
4513 .struct_type => @panic("TODO"),
4514 .union_type => unreachable,
4515 .simple_value => unreachable,
4516 .extern_func => unreachable,
4517 .int => unreachable,
4518 .enum_tag => unreachable,
48544519 },
4855
4856 else => unreachable,
48574520 };
48584521 }
48594522
......@@ -5021,7 +4684,6 @@ pub const Type = struct {
50214684 else => false,
50224685 };
50234686 return switch (ty.tag()) {
5024 .comptime_int,
50254687 .u1,
50264688 .u8,
50274689 .i8,
......@@ -5114,7 +4776,6 @@ pub const Type = struct {
51144776 };
51154777
51164778 while (true) switch (ty.tag()) {
5117 .comptime_int,
51184779 .u1,
51194780 .u8,
51204781 .i8,
......@@ -5127,9 +4788,7 @@ pub const Type = struct {
51274788 .i64,
51284789 .u128,
51294790 .i128,
5130 .bool,
5131 .type,
5132 .anyerror,
4791
51334792 .error_union,
51344793 .error_set_single,
51354794 .error_set,
......@@ -5142,28 +4801,14 @@ pub const Type = struct {
51424801 .const_slice_u8_sentinel_0,
51434802 .const_slice,
51444803 .mut_slice,
5145 .anyopaque,
51464804 .optional_single_mut_pointer,
51474805 .optional_single_const_pointer,
5148 .enum_literal,
51494806 .anyerror_void_error_union,
51504807 .error_set_inferred,
51514808 .@"opaque",
51524809 .manyptr_u8,
51534810 .manyptr_const_u8,
51544811 .manyptr_const_u8_sentinel_0,
5155 .atomic_order,
5156 .atomic_rmw_op,
5157 .calling_convention,
5158 .address_space,
5159 .float_mode,
5160 .reduce_op,
5161 .modifier,
5162 .prefetch_options,
5163 .export_options,
5164 .extern_options,
5165 .type_info,
5166 .@"anyframe",
51674812 .anyframe_T,
51684813 .many_const_pointer,
51694814 .many_mut_pointer,
......@@ -5258,10 +4903,6 @@ pub const Type = struct {
52584903 },
52594904
52604905 .empty_struct, .empty_struct_literal => return Value.initTag(.empty_struct_value),
5261 .void => return Value.initTag(.void_value),
5262 .noreturn => return Value.initTag(.unreachable_value),
5263 .null => return Value.initTag(.null_value),
5264 .undefined => return Value.initTag(.undef),
52654906
52664907 .vector, .array, .array_u8 => {
52674908 if (ty.arrayLen() == 0)
......@@ -5273,7 +4914,6 @@ pub const Type = struct {
52734914
52744915 .inferred_alloc_const => unreachable,
52754916 .inferred_alloc_mut => unreachable,
5276 .generic_poison => unreachable,
52774917 };
52784918 }
52794919
......@@ -5358,22 +4998,7 @@ pub const Type = struct {
53584998 .i64,
53594999 .u128,
53605000 .i128,
5361 .anyopaque,
5362 .bool,
5363 .void,
5364 .anyerror,
5365 .noreturn,
5366 .@"anyframe",
5367 .atomic_order,
5368 .atomic_rmw_op,
5369 .calling_convention,
5370 .address_space,
5371 .float_mode,
5372 .reduce_op,
5373 .modifier,
5374 .prefetch_options,
5375 .export_options,
5376 .extern_options,
5001
53775002 .manyptr_u8,
53785003 .manyptr_const_u8,
53795004 .manyptr_const_u8_sentinel_0,
......@@ -5387,21 +5012,14 @@ pub const Type = struct {
53875012 .error_set_inferred,
53885013 .error_set_merged,
53895014 .@"opaque",
5390 .generic_poison,
53915015 .array_u8,
53925016 .array_u8_sentinel_0,
53935017 .enum_simple,
53945018 => false,
53955019
53965020 .single_const_pointer_to_comptime_int,
5397 .type,
5398 .comptime_int,
5399 .enum_literal,
5400 .type_info,
54015021 // These are function bodies, not function pointers.
54025022 .function,
5403 .null,
5404 .undefined,
54055023 => true,
54065024
54075025 .inferred_alloc_mut => unreachable,
......@@ -5701,17 +5319,6 @@ pub const Type = struct {
57015319 .enum_full, .enum_nonexhaustive => ty.cast(Payload.EnumFull).?.data.fields,
57025320 .enum_simple => ty.castTag(.enum_simple).?.data.fields,
57035321 .enum_numbered => ty.castTag(.enum_numbered).?.data.fields,
5704 .atomic_order,
5705 .atomic_rmw_op,
5706 .calling_convention,
5707 .address_space,
5708 .float_mode,
5709 .reduce_op,
5710 .modifier,
5711 .prefetch_options,
5712 .export_options,
5713 .extern_options,
5714 => @panic("TODO resolve std.builtin types"),
57155322 else => unreachable,
57165323 };
57175324 }
......@@ -5779,17 +5386,6 @@ pub const Type = struct {
57795386 const tag_ty = mod.intType(.unsigned, bits) catch @panic("TODO: handle OOM here");
57805387 return S.fieldWithRange(tag_ty, enum_tag, fields_len, mod);
57815388 },
5782 .atomic_order,
5783 .atomic_rmw_op,
5784 .calling_convention,
5785 .address_space,
5786 .float_mode,
5787 .reduce_op,
5788 .modifier,
5789 .prefetch_options,
5790 .export_options,
5791 .extern_options,
5792 => @panic("TODO resolve std.builtin types"),
57935389 else => unreachable,
57945390 }
57955391 }
......@@ -6102,18 +5698,6 @@ pub const Type = struct {
61025698 const opaque_obj = ty.cast(Payload.Opaque).?.data;
61035699 return opaque_obj.srcLoc(mod);
61045700 },
6105 .atomic_order,
6106 .atomic_rmw_op,
6107 .calling_convention,
6108 .address_space,
6109 .float_mode,
6110 .reduce_op,
6111 .modifier,
6112 .prefetch_options,
6113 .export_options,
6114 .extern_options,
6115 .type_info,
6116 => unreachable, // needed to call resolveTypeFields first
61175701
61185702 else => return null,
61195703 }
......@@ -6150,29 +5734,17 @@ pub const Type = struct {
61505734 const opaque_obj = ty.cast(Payload.Opaque).?.data;
61515735 return opaque_obj.owner_decl;
61525736 },
6153 .atomic_order,
6154 .atomic_rmw_op,
6155 .calling_convention,
6156 .address_space,
6157 .float_mode,
6158 .reduce_op,
6159 .modifier,
6160 .prefetch_options,
6161 .export_options,
6162 .extern_options,
6163 .type_info,
6164 => unreachable, // These need to be resolved earlier.
61655737
61665738 else => return null,
61675739 }
61685740 }
61695741
61705742 pub fn isGenericPoison(ty: Type) bool {
6171 return switch (ty.ip_index) {
6172 .generic_poison_type => true,
6173 .none => ty.tag() == .generic_poison,
6174 else => false,
6175 };
5743 return ty.ip_index == .generic_poison_type;
5744 }
5745
5746 pub fn isVarArgsParam(ty: Type) bool {
5747 return ty.ip_index == .none and ty.tag() == .var_args_param;
61765748 }
61775749
61785750 /// This enum does not directly correspond to `std.builtin.TypeId` because
......@@ -6195,28 +5767,7 @@ pub const Type = struct {
61955767 i64,
61965768 u128,
61975769 i128,
6198 anyopaque,
6199 bool,
6200 void,
6201 type,
6202 anyerror,
6203 comptime_int,
6204 noreturn,
6205 @"anyframe",
6206 null,
6207 undefined,
6208 enum_literal,
6209 atomic_order,
6210 atomic_rmw_op,
6211 calling_convention,
6212 address_space,
6213 float_mode,
6214 reduce_op,
6215 modifier,
6216 prefetch_options,
6217 export_options,
6218 extern_options,
6219 type_info,
5770
62205771 manyptr_u8,
62215772 manyptr_const_u8,
62225773 manyptr_const_u8_sentinel_0,
......@@ -6224,7 +5775,6 @@ pub const Type = struct {
62245775 const_slice_u8,
62255776 const_slice_u8_sentinel_0,
62265777 anyerror_void_error_union,
6227 generic_poison,
62285778 /// Same as `empty_struct` except it has an empty namespace.
62295779 empty_struct_literal,
62305780 /// This is a special value that tracks a set of types that have been stored
......@@ -6292,39 +5842,17 @@ pub const Type = struct {
62925842 .i64,
62935843 .u128,
62945844 .i128,
6295 .anyopaque,
6296 .bool,
6297 .void,
6298 .type,
6299 .anyerror,
6300 .comptime_int,
6301 .noreturn,
6302 .enum_literal,
6303 .null,
6304 .undefined,
5845
63055846 .single_const_pointer_to_comptime_int,
63065847 .anyerror_void_error_union,
63075848 .const_slice_u8,
63085849 .const_slice_u8_sentinel_0,
6309 .generic_poison,
63105850 .inferred_alloc_const,
63115851 .inferred_alloc_mut,
63125852 .empty_struct_literal,
63135853 .manyptr_u8,
63145854 .manyptr_const_u8,
63155855 .manyptr_const_u8_sentinel_0,
6316 .atomic_order,
6317 .atomic_rmw_op,
6318 .calling_convention,
6319 .address_space,
6320 .float_mode,
6321 .reduce_op,
6322 .modifier,
6323 .prefetch_options,
6324 .export_options,
6325 .extern_options,
6326 .type_info,
6327 .@"anyframe",
63285856 => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"),
63295857
63305858 .array_u8,
......@@ -6674,18 +6202,19 @@ pub const Type = struct {
66746202 pub const @"f80": Type = .{ .ip_index = .f80_type, .legacy = undefined };
66756203 pub const @"f128": Type = .{ .ip_index = .f128_type, .legacy = undefined };
66766204
6677 pub const @"bool" = initTag(.bool);
6205 pub const @"bool": Type = .{ .ip_index = .bool_type, .legacy = undefined };
66786206 pub const @"usize": Type = .{ .ip_index = .usize_type, .legacy = undefined };
66796207 pub const @"isize": Type = .{ .ip_index = .isize_type, .legacy = undefined };
66806208 pub const @"comptime_int": Type = .{ .ip_index = .comptime_int_type, .legacy = undefined };
66816209 pub const @"comptime_float": Type = .{ .ip_index = .comptime_float_type, .legacy = undefined };
6682 pub const @"void" = initTag(.void);
6683 pub const @"type" = initTag(.type);
6684 pub const @"anyerror" = initTag(.anyerror);
6685 pub const @"anyopaque" = initTag(.anyopaque);
6686 pub const @"null" = initTag(.null);
6687 pub const @"undefined" = initTag(.undefined);
6688 pub const @"noreturn" = initTag(.noreturn);
6210 pub const @"void": Type = .{ .ip_index = .void_type, .legacy = undefined };
6211 pub const @"type": Type = .{ .ip_index = .type_type, .legacy = undefined };
6212 pub const @"anyerror": Type = .{ .ip_index = .anyerror_type, .legacy = undefined };
6213 pub const @"anyopaque": Type = .{ .ip_index = .anyopaque_type, .legacy = undefined };
6214 pub const @"anyframe": Type = .{ .ip_index = .anyframe_type, .legacy = undefined };
6215 pub const @"null": Type = .{ .ip_index = .null_type, .legacy = undefined };
6216 pub const @"undefined": Type = .{ .ip_index = .undefined_type, .legacy = undefined };
6217 pub const @"noreturn": Type = .{ .ip_index = .noreturn_type, .legacy = undefined };
66896218
66906219 pub const @"c_char": Type = .{ .ip_index = .c_char_type, .legacy = undefined };
66916220 pub const @"c_short": Type = .{ .ip_index = .c_short_type, .legacy = undefined };
......@@ -6698,6 +6227,8 @@ pub const Type = struct {
66986227 pub const @"c_ulonglong": Type = .{ .ip_index = .c_ulonglong_type, .legacy = undefined };
66996228 pub const @"c_longdouble": Type = .{ .ip_index = .c_longdouble_type, .legacy = undefined };
67006229
6230 pub const generic_poison: Type = .{ .ip_index = .generic_poison_type, .legacy = undefined };
6231
67016232 pub const err_int = Type.u16;
67026233
67036234 pub fn ptr(arena: Allocator, mod: *Module, data: Payload.Pointer.Data) !Type {
src/value.zig+14-14
......@@ -991,26 +991,26 @@ pub const Value = struct {
991991 .null_type => Type.null,
992992 .undefined_type => Type.undefined,
993993 .single_const_pointer_to_comptime_int_type => Type.initTag(.single_const_pointer_to_comptime_int),
994 .anyframe_type => Type.initTag(.@"anyframe"),
994 .anyframe_type => Type.@"anyframe",
995995 .const_slice_u8_type => Type.initTag(.const_slice_u8),
996996 .const_slice_u8_sentinel_0_type => Type.initTag(.const_slice_u8_sentinel_0),
997997 .anyerror_void_error_union_type => Type.initTag(.anyerror_void_error_union),
998 .generic_poison_type => Type.initTag(.generic_poison),
999 .enum_literal_type => Type.initTag(.enum_literal),
998 .generic_poison_type => .{ .ip_index = .generic_poison_type, .legacy = undefined },
999 .enum_literal_type => .{ .ip_index = .enum_literal_type, .legacy = undefined },
10001000 .manyptr_u8_type => Type.initTag(.manyptr_u8),
10011001 .manyptr_const_u8_type => Type.initTag(.manyptr_const_u8),
10021002 .manyptr_const_u8_sentinel_0_type => Type.initTag(.manyptr_const_u8_sentinel_0),
1003 .atomic_order_type => Type.initTag(.atomic_order),
1004 .atomic_rmw_op_type => Type.initTag(.atomic_rmw_op),
1005 .calling_convention_type => Type.initTag(.calling_convention),
1006 .address_space_type => Type.initTag(.address_space),
1007 .float_mode_type => Type.initTag(.float_mode),
1008 .reduce_op_type => Type.initTag(.reduce_op),
1009 .modifier_type => Type.initTag(.modifier),
1010 .prefetch_options_type => Type.initTag(.prefetch_options),
1011 .export_options_type => Type.initTag(.export_options),
1012 .extern_options_type => Type.initTag(.extern_options),
1013 .type_info_type => Type.initTag(.type_info),
1003 .atomic_order_type => .{ .ip_index = .atomic_order_type, .legacy = undefined },
1004 .atomic_rmw_op_type => .{ .ip_index = .atomic_rmw_op_type, .legacy = undefined },
1005 .calling_convention_type => .{ .ip_index = .calling_convention_type, .legacy = undefined },
1006 .address_space_type => .{ .ip_index = .address_space_type, .legacy = undefined },
1007 .float_mode_type => .{ .ip_index = .float_mode_type, .legacy = undefined },
1008 .reduce_op_type => .{ .ip_index = .reduce_op_type, .legacy = undefined },
1009 .modifier_type => .{ .ip_index = .call_modifier_type, .legacy = undefined },
1010 .prefetch_options_type => .{ .ip_index = .prefetch_options_type, .legacy = undefined },
1011 .export_options_type => .{ .ip_index = .export_options_type, .legacy = undefined },
1012 .extern_options_type => .{ .ip_index = .extern_options_type, .legacy = undefined },
1013 .type_info_type => .{ .ip_index = .type_info_type, .legacy = undefined },
10141014
10151015 else => unreachable,
10161016 };