authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-18 19:05:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:53-07:00
logf21ca3da190c8c64fd99c700f0840af59792b6b2
tree7a2853ce05fb11ad9dc81d9252f32d601459f156
parent17882162b3be5542b4e289e5ddc6535a4bb4c6b1

compiler: move `anyframe->T` to InternPool

Also I moved `anyframe` from being represented by `SimpleType` to being represented by the `none` tag of `anyframe_type` because most code wants to handle these two types together.

4 files changed, 101 insertions(+), 105 deletions(-)

src/InternPool.zig+28-6
...@@ -132,6 +132,9 @@ pub const Key = union(enum) {...@@ -132,6 +132,9 @@ pub const Key = union(enum) {
132 array_type: ArrayType,132 array_type: ArrayType,
133 vector_type: VectorType,133 vector_type: VectorType,
134 opt_type: Index,134 opt_type: Index,
135 /// `anyframe->T`. The payload is the child type, which may be `none` to indicate
136 /// `anyframe`.
137 anyframe_type: Index,
135 error_union_type: struct {138 error_union_type: struct {
136 error_set_type: Index,139 error_set_type: Index,
137 payload_type: Index,140 payload_type: Index,
...@@ -503,6 +506,7 @@ pub const Key = union(enum) {...@@ -503,6 +506,7 @@ pub const Key = union(enum) {
503 .array_type,506 .array_type,
504 .vector_type,507 .vector_type,
505 .opt_type,508 .opt_type,
509 .anyframe_type,
506 .error_union_type,510 .error_union_type,
507 .simple_type,511 .simple_type,
508 .simple_value,512 .simple_value,
...@@ -597,7 +601,11 @@ pub const Key = union(enum) {...@@ -597,7 +601,11 @@ pub const Key = union(enum) {
597 },601 },
598 .opt_type => |a_info| {602 .opt_type => |a_info| {
599 const b_info = b.opt_type;603 const b_info = b.opt_type;
600 return std.meta.eql(a_info, b_info);604 return a_info == b_info;
605 },
606 .anyframe_type => |a_info| {
607 const b_info = b.anyframe_type;
608 return a_info == b_info;
601 },609 },
602 .error_union_type => |a_info| {610 .error_union_type => |a_info| {
603 const b_info = b.error_union_type;611 const b_info = b.error_union_type;
...@@ -752,6 +760,7 @@ pub const Key = union(enum) {...@@ -752,6 +760,7 @@ pub const Key = union(enum) {
752 .array_type,760 .array_type,
753 .vector_type,761 .vector_type,
754 .opt_type,762 .opt_type,
763 .anyframe_type,
755 .error_union_type,764 .error_union_type,
756 .simple_type,765 .simple_type,
757 .struct_type,766 .struct_type,
...@@ -1037,7 +1046,7 @@ pub const static_keys = [_]Key{...@@ -1037,7 +1046,7 @@ pub const static_keys = [_]Key{
1037 .{ .simple_type = .comptime_int },1046 .{ .simple_type = .comptime_int },
1038 .{ .simple_type = .comptime_float },1047 .{ .simple_type = .comptime_float },
1039 .{ .simple_type = .noreturn },1048 .{ .simple_type = .noreturn },
1040 .{ .simple_type = .@"anyframe" },1049 .{ .anyframe_type = .none },
1041 .{ .simple_type = .null },1050 .{ .simple_type = .null },
1042 .{ .simple_type = .undefined },1051 .{ .simple_type = .undefined },
1043 .{ .simple_type = .enum_literal },1052 .{ .simple_type = .enum_literal },
...@@ -1203,6 +1212,10 @@ pub const Tag = enum(u8) {...@@ -1203,6 +1212,10 @@ pub const Tag = enum(u8) {
1203 /// An optional type.1212 /// An optional type.
1204 /// data is the child type.1213 /// data is the child type.
1205 type_optional,1214 type_optional,
1215 /// The type `anyframe->T`.
1216 /// data is the child type.
1217 /// If the child type is `none`, the type is `anyframe`.
1218 type_anyframe,
1206 /// An error union type.1219 /// An error union type.
1207 /// data is payload to ErrorUnion.1220 /// data is payload to ErrorUnion.
1208 type_error_union,1221 type_error_union,
...@@ -1421,7 +1434,6 @@ pub const SimpleType = enum(u32) {...@@ -1421,7 +1434,6 @@ pub const SimpleType = enum(u32) {
1421 comptime_int,1434 comptime_int,
1422 comptime_float,1435 comptime_float,
1423 noreturn,1436 noreturn,
1424 @"anyframe",
1425 null,1437 null,
1426 undefined,1438 undefined,
1427 enum_literal,1439 enum_literal,
...@@ -1781,6 +1793,7 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {...@@ -1781,6 +1793,7 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
1781 },1793 },
17821794
1783 .type_optional => .{ .opt_type = @intToEnum(Index, data) },1795 .type_optional => .{ .opt_type = @intToEnum(Index, data) },
1796 .type_anyframe => .{ .anyframe_type = @intToEnum(Index, data) },
17841797
1785 .type_error_union => @panic("TODO"),1798 .type_error_union => @panic("TODO"),
17861799
...@@ -2144,10 +2157,18 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -2144,10 +2157,18 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
2144 }),2157 }),
2145 });2158 });
2146 },2159 },
2147 .opt_type => |opt_type| {2160 .opt_type => |payload_type| {
2161 assert(payload_type != .none);
2148 ip.items.appendAssumeCapacity(.{2162 ip.items.appendAssumeCapacity(.{
2149 .tag = .type_optional,2163 .tag = .type_optional,
2150 .data = @enumToInt(opt_type),2164 .data = @enumToInt(payload_type),
2165 });
2166 },
2167 .anyframe_type => |payload_type| {
2168 // payload_type might be none, indicating the type is `anyframe`.
2169 ip.items.appendAssumeCapacity(.{
2170 .tag = .type_anyframe,
2171 .data = @enumToInt(payload_type),
2151 });2172 });
2152 },2173 },
2153 .error_union_type => |error_union_type| {2174 .error_union_type => |error_union_type| {
...@@ -3063,7 +3084,7 @@ pub fn childType(ip: InternPool, i: Index) Index {...@@ -3063,7 +3084,7 @@ pub fn childType(ip: InternPool, i: Index) Index {
3063 .ptr_type => |ptr_type| ptr_type.elem_type,3084 .ptr_type => |ptr_type| ptr_type.elem_type,
3064 .vector_type => |vector_type| vector_type.child,3085 .vector_type => |vector_type| vector_type.child,
3065 .array_type => |array_type| array_type.child,3086 .array_type => |array_type| array_type.child,
3066 .opt_type => |child| child,3087 .opt_type, .anyframe_type => |child| child,
3067 else => unreachable,3088 else => unreachable,
3068 };3089 };
3069}3090}
...@@ -3231,6 +3252,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void {...@@ -3231,6 +3252,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void {
3231 .type_pointer => @sizeOf(Pointer),3252 .type_pointer => @sizeOf(Pointer),
3232 .type_slice => 0,3253 .type_slice => 0,
3233 .type_optional => 0,3254 .type_optional => 0,
3255 .type_anyframe => 0,
3234 .type_error_union => @sizeOf(ErrorUnion),3256 .type_error_union => @sizeOf(ErrorUnion),
3235 .type_enum_explicit, .type_enum_nonexhaustive => @sizeOf(EnumExplicit),3257 .type_enum_explicit, .type_enum_nonexhaustive => @sizeOf(EnumExplicit),
3236 .type_enum_auto => @sizeOf(EnumAuto),3258 .type_enum_auto => @sizeOf(EnumAuto),
src/Module.zig+6
...@@ -6869,6 +6869,12 @@ pub fn funcType(mod: *Module, info: InternPool.Key.FuncType) Allocator.Error!Typ...@@ -6869,6 +6869,12 @@ pub fn funcType(mod: *Module, info: InternPool.Key.FuncType) Allocator.Error!Typ
6869 return (try intern(mod, .{ .func_type = info })).toType();6869 return (try intern(mod, .{ .func_type = info })).toType();
6870}6870}
68716871
6872/// Use this for `anyframe->T` only.
6873/// For `anyframe`, use the `InternPool.Index.anyframe` tag directly.
6874pub fn anyframeType(mod: *Module, payload_ty: Type) Allocator.Error!Type {
6875 return (try intern(mod, .{ .anyframe_type = payload_ty.toIntern() })).toType();
6876}
6877
6872/// Supports optionals in addition to pointers.6878/// Supports optionals in addition to pointers.
6873pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {6879pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
6874 if (ty.isPtrLikeOptional(mod)) {6880 if (ty.isPtrLikeOptional(mod)) {
src/Sema.zig+11-13
...@@ -8042,9 +8042,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8042,9 +8042,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
8042 if (true) {8042 if (true) {
8043 return sema.failWithUseOfAsync(block, inst_data.src());8043 return sema.failWithUseOfAsync(block, inst_data.src());
8044 }8044 }
8045 const mod = sema.mod;
8045 const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node };8046 const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node };
8046 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);8047 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);
8047 const anyframe_type = try Type.Tag.anyframe_T.create(sema.arena, return_type);8048 const anyframe_type = try mod.anyframeType(return_type);
80488049
8049 return sema.addType(anyframe_type);8050 return sema.addType(anyframe_type);
8050}8051}
...@@ -31626,10 +31627,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -31626,10 +31627,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31626 },31627 },
3162731628
31628 .error_union => return sema.resolveTypeRequiresComptime(ty.errorUnionPayload()),31629 .error_union => return sema.resolveTypeRequiresComptime(ty.errorUnionPayload()),
31629 .anyframe_T => {
31630 const child_ty = ty.castTag(.anyframe_T).?.data;
31631 return sema.resolveTypeRequiresComptime(child_ty);
31632 },
31633 },31630 },
31634 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {31631 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
31635 .int_type => false,31632 .int_type => false,
...@@ -31641,6 +31638,10 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -31641,6 +31638,10 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31641 return sema.resolveTypeRequiresComptime(child_ty);31638 return sema.resolveTypeRequiresComptime(child_ty);
31642 }31639 }
31643 },31640 },
31641 .anyframe_type => |child| {
31642 if (child == .none) return false;
31643 return sema.resolveTypeRequiresComptime(child.toType());
31644 },
31644 .array_type => |array_type| return sema.resolveTypeRequiresComptime(array_type.child.toType()),31645 .array_type => |array_type| return sema.resolveTypeRequiresComptime(array_type.child.toType()),
31645 .vector_type => |vector_type| return sema.resolveTypeRequiresComptime(vector_type.child.toType()),31646 .vector_type => |vector_type| return sema.resolveTypeRequiresComptime(vector_type.child.toType()),
31646 .opt_type => |child| return sema.resolveTypeRequiresComptime(child.toType()),31647 .opt_type => |child| return sema.resolveTypeRequiresComptime(child.toType()),
...@@ -31669,7 +31670,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -31669,7 +31670,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31669 .bool,31670 .bool,
31670 .void,31671 .void,
31671 .anyerror,31672 .anyerror,
31672 .@"anyframe",
31673 .noreturn,31673 .noreturn,
31674 .generic_poison,31674 .generic_poison,
31675 .var_args_param,31675 .var_args_param,
...@@ -33054,7 +33054,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33054,7 +33054,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33054 .error_set_merged,33054 .error_set_merged,
33055 .error_union,33055 .error_union,
33056 .error_set_inferred,33056 .error_set_inferred,
33057 .anyframe_T,
33058 .pointer,33057 .pointer,
33059 => return null,33058 => return null,
3306033059
...@@ -33083,6 +33082,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33083,6 +33082,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33083 .ptr_type,33082 .ptr_type,
33084 .error_union_type,33083 .error_union_type,
33085 .func_type,33084 .func_type,
33085 .anyframe_type,
33086 => null,33086 => null,
3308733087
33088 .array_type => |array_type| {33088 .array_type => |array_type| {
...@@ -33130,7 +33130,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33130,7 +33130,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33130 .anyerror,33130 .anyerror,
33131 .comptime_int,33131 .comptime_int,
33132 .comptime_float,33132 .comptime_float,
33133 .@"anyframe",
33134 .enum_literal,33133 .enum_literal,
33135 .atomic_order,33134 .atomic_order,
33136 .atomic_rmw_op,33135 .atomic_rmw_op,
...@@ -33688,10 +33687,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -33688,10 +33687,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33688 },33687 },
3368933688
33690 .error_union => return sema.typeRequiresComptime(ty.errorUnionPayload()),33689 .error_union => return sema.typeRequiresComptime(ty.errorUnionPayload()),
33691 .anyframe_T => {
33692 const child_ty = ty.castTag(.anyframe_T).?.data;
33693 return sema.typeRequiresComptime(child_ty);
33694 },
33695 },33690 },
33696 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {33691 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
33697 .int_type => return false,33692 .int_type => return false,
...@@ -33703,6 +33698,10 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -33703,6 +33698,10 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33703 return sema.typeRequiresComptime(child_ty);33698 return sema.typeRequiresComptime(child_ty);
33704 }33699 }
33705 },33700 },
33701 .anyframe_type => |child| {
33702 if (child == .none) return false;
33703 return sema.typeRequiresComptime(child.toType());
33704 },
33706 .array_type => |array_type| return sema.typeRequiresComptime(array_type.child.toType()),33705 .array_type => |array_type| return sema.typeRequiresComptime(array_type.child.toType()),
33707 .vector_type => |vector_type| return sema.typeRequiresComptime(vector_type.child.toType()),33706 .vector_type => |vector_type| return sema.typeRequiresComptime(vector_type.child.toType()),
33708 .opt_type => |child| return sema.typeRequiresComptime(child.toType()),33707 .opt_type => |child| return sema.typeRequiresComptime(child.toType()),
...@@ -33733,7 +33732,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -33733,7 +33732,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33733 .bool,33732 .bool,
33734 .void,33733 .void,
33735 .anyerror,33734 .anyerror,
33736 .@"anyframe",
33737 .noreturn,33735 .noreturn,
33738 .generic_poison,33736 .generic_poison,
33739 .atomic_order,33737 .atomic_order,
src/type.zig+56-86
...@@ -50,21 +50,20 @@ pub const Type = struct {...@@ -50,21 +50,20 @@ pub const Type = struct {
50 .optional => return .Optional,50 .optional => return .Optional,
5151
52 .error_union => return .ErrorUnion,52 .error_union => return .ErrorUnion,
53
54 .anyframe_T => return .AnyFrame,
55 },53 },
56 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {54 else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
57 .int_type => return .Int,55 .int_type => .Int,
58 .ptr_type => return .Pointer,56 .ptr_type => .Pointer,
59 .array_type => return .Array,57 .array_type => .Array,
60 .vector_type => return .Vector,58 .vector_type => .Vector,
61 .opt_type => return .Optional,59 .opt_type => .Optional,
62 .error_union_type => return .ErrorUnion,60 .error_union_type => .ErrorUnion,
63 .struct_type, .anon_struct_type => return .Struct,61 .struct_type, .anon_struct_type => .Struct,
64 .union_type => return .Union,62 .union_type => .Union,
65 .opaque_type => return .Opaque,63 .opaque_type => .Opaque,
66 .enum_type => return .Enum,64 .enum_type => .Enum,
67 .func_type => return .Fn,65 .func_type => .Fn,
66 .anyframe_type => .AnyFrame,
68 .simple_type => |s| switch (s) {67 .simple_type => |s| switch (s) {
69 .f16,68 .f16,
70 .f32,69 .f32,
...@@ -72,7 +71,7 @@ pub const Type = struct {...@@ -72,7 +71,7 @@ pub const Type = struct {
72 .f80,71 .f80,
73 .f128,72 .f128,
74 .c_longdouble,73 .c_longdouble,
75 => return .Float,74 => .Float,
7675
77 .usize,76 .usize,
78 .isize,77 .isize,
...@@ -85,20 +84,19 @@ pub const Type = struct {...@@ -85,20 +84,19 @@ pub const Type = struct {
85 .c_ulong,84 .c_ulong,
86 .c_longlong,85 .c_longlong,
87 .c_ulonglong,86 .c_ulonglong,
88 => return .Int,87 => .Int,
8988
90 .anyopaque => return .Opaque,89 .anyopaque => .Opaque,
91 .bool => return .Bool,90 .bool => .Bool,
92 .void => return .Void,91 .void => .Void,
93 .type => return .Type,92 .type => .Type,
94 .anyerror => return .ErrorSet,93 .anyerror => .ErrorSet,
95 .comptime_int => return .ComptimeInt,94 .comptime_int => .ComptimeInt,
96 .comptime_float => return .ComptimeFloat,95 .comptime_float => .ComptimeFloat,
97 .noreturn => return .NoReturn,96 .noreturn => .NoReturn,
98 .@"anyframe" => return .AnyFrame,97 .null => .Null,
99 .null => return .Null,98 .undefined => .Undefined,
100 .undefined => return .Undefined,99 .enum_literal => .EnumLiteral,
101 .enum_literal => return .EnumLiteral,
102100
103 .atomic_order,101 .atomic_order,
104 .atomic_rmw_op,102 .atomic_rmw_op,
...@@ -107,14 +105,14 @@ pub const Type = struct {...@@ -107,14 +105,14 @@ pub const Type = struct {
107 .float_mode,105 .float_mode,
108 .reduce_op,106 .reduce_op,
109 .call_modifier,107 .call_modifier,
110 => return .Enum,108 => .Enum,
111109
112 .prefetch_options,110 .prefetch_options,
113 .export_options,111 .export_options,
114 .extern_options,112 .extern_options,
115 => return .Struct,113 => .Struct,
116114
117 .type_info => return .Union,115 .type_info => .Union,
118116
119 .generic_poison => return error.GenericPoison,117 .generic_poison => return error.GenericPoison,
120 .var_args_param => unreachable,118 .var_args_param => unreachable,
...@@ -408,11 +406,6 @@ pub const Type = struct {...@@ -408,11 +406,6 @@ pub const Type = struct {
408406
409 return true;407 return true;
410 },408 },
411
412 .anyframe_T => {
413 if (b.zigTypeTag(mod) != .AnyFrame) return false;
414 return a.elemType2(mod).eql(b.elemType2(mod), mod);
415 },
416 }409 }
417 }410 }
418411
...@@ -488,11 +481,6 @@ pub const Type = struct {...@@ -488,11 +481,6 @@ pub const Type = struct {
488 const payload_ty = ty.errorUnionPayload();481 const payload_ty = ty.errorUnionPayload();
489 hashWithHasher(payload_ty, hasher, mod);482 hashWithHasher(payload_ty, hasher, mod);
490 },483 },
491
492 .anyframe_T => {
493 std.hash.autoHash(hasher, std.builtin.TypeId.AnyFrame);
494 hashWithHasher(ty.childType(mod), hasher, mod);
495 },
496 }484 }
497 }485 }
498486
...@@ -542,9 +530,7 @@ pub const Type = struct {...@@ -542,9 +530,7 @@ pub const Type = struct {
542 .inferred_alloc_mut,530 .inferred_alloc_mut,
543 => unreachable,531 => unreachable,
544532
545 .optional,533 .optional => {
546 .anyframe_T,
547 => {
548 const payload = self.cast(Payload.ElemType).?;534 const payload = self.cast(Payload.ElemType).?;
549 const new_payload = try allocator.create(Payload.ElemType);535 const new_payload = try allocator.create(Payload.ElemType);
550 new_payload.* = .{536 new_payload.* = .{
...@@ -668,12 +654,6 @@ pub const Type = struct {...@@ -668,12 +654,6 @@ pub const Type = struct {
668 while (true) {654 while (true) {
669 const t = ty.tag();655 const t = ty.tag();
670 switch (t) {656 switch (t) {
671 .anyframe_T => {
672 const return_type = ty.castTag(.anyframe_T).?.data;
673 try writer.print("anyframe->", .{});
674 ty = return_type;
675 continue;
676 },
677 .optional => {657 .optional => {
678 const child_type = ty.castTag(.optional).?.data;658 const child_type = ty.castTag(.optional).?.data;
679 try writer.writeByte('?');659 try writer.writeByte('?');
...@@ -838,11 +818,6 @@ pub const Type = struct {...@@ -838,11 +818,6 @@ pub const Type = struct {
838 try writer.writeByte('?');818 try writer.writeByte('?');
839 try print(child_type, writer, mod);819 try print(child_type, writer, mod);
840 },820 },
841 .anyframe_T => {
842 const return_type = ty.castTag(.anyframe_T).?.data;
843 try writer.print("anyframe->", .{});
844 try print(return_type, writer, mod);
845 },
846 .error_set => {821 .error_set => {
847 const names = ty.castTag(.error_set).?.data.names.keys();822 const names = ty.castTag(.error_set).?.data.names.keys();
848 try writer.writeAll("error{");823 try writer.writeAll("error{");
...@@ -1034,6 +1009,11 @@ pub const Type = struct {...@@ -1034,6 +1009,11 @@ pub const Type = struct {
1034 try print(fn_info.return_type.toType(), writer, mod);1009 try print(fn_info.return_type.toType(), writer, mod);
1035 }1010 }
1036 },1011 },
1012 .anyframe_type => |child| {
1013 if (child == .none) return writer.writeAll("anyframe");
1014 try writer.writeAll("anyframe->");
1015 return print(child.toType(), writer, mod);
1016 },
10371017
1038 // values, not types1018 // values, not types
1039 .undef => unreachable,1019 .undef => unreachable,
...@@ -1098,9 +1078,7 @@ pub const Type = struct {...@@ -1098,9 +1078,7 @@ pub const Type = struct {
10981078
1099 // Pointers to zero-bit types still have a runtime address; however, pointers1079 // Pointers to zero-bit types still have a runtime address; however, pointers
1100 // to comptime-only types do not, with the exception of function pointers.1080 // to comptime-only types do not, with the exception of function pointers.
1101 .anyframe_T,1081 .pointer => {
1102 .pointer,
1103 => {
1104 if (ignore_comptime_only) {1082 if (ignore_comptime_only) {
1105 return true;1083 return true;
1106 } else if (ty.childType(mod).zigTypeTag(mod) == .Fn) {1084 } else if (ty.childType(mod).zigTypeTag(mod) == .Fn) {
...@@ -1141,6 +1119,7 @@ pub const Type = struct {...@@ -1141,6 +1119,7 @@ pub const Type = struct {
1141 if (strat == .sema) return !(try strat.sema.typeRequiresComptime(ty));1119 if (strat == .sema) return !(try strat.sema.typeRequiresComptime(ty));
1142 return !comptimeOnly(ty, mod);1120 return !comptimeOnly(ty, mod);
1143 },1121 },
1122 .anyframe_type => true,
1144 .array_type => |array_type| {1123 .array_type => |array_type| {
1145 if (array_type.sentinel != .none) {1124 if (array_type.sentinel != .none) {
1146 return array_type.child.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);1125 return array_type.child.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
...@@ -1195,7 +1174,6 @@ pub const Type = struct {...@@ -1195,7 +1174,6 @@ pub const Type = struct {
1195 .c_longdouble,1174 .c_longdouble,
1196 .bool,1175 .bool,
1197 .anyerror,1176 .anyerror,
1198 .@"anyframe",
1199 .anyopaque,1177 .anyopaque,
1200 .atomic_order,1178 .atomic_order,
1201 .atomic_rmw_op,1179 .atomic_rmw_op,
...@@ -1319,7 +1297,6 @@ pub const Type = struct {...@@ -1319,7 +1297,6 @@ pub const Type = struct {
1319 .error_set_inferred,1297 .error_set_inferred,
1320 .error_set_merged,1298 .error_set_merged,
1321 .error_union,1299 .error_union,
1322 .anyframe_T,
1323 => false,1300 => false,
13241301
1325 .inferred_alloc_mut => unreachable,1302 .inferred_alloc_mut => unreachable,
...@@ -1336,6 +1313,7 @@ pub const Type = struct {...@@ -1336,6 +1313,7 @@ pub const Type = struct {
1336 .error_union_type,1313 .error_union_type,
1337 .anon_struct_type,1314 .anon_struct_type,
1338 .opaque_type,1315 .opaque_type,
1316 .anyframe_type,
1339 // These are function bodies, not function pointers.1317 // These are function bodies, not function pointers.
1340 .func_type,1318 .func_type,
1341 => false,1319 => false,
...@@ -1366,7 +1344,6 @@ pub const Type = struct {...@@ -1366,7 +1344,6 @@ pub const Type = struct {
1366 => true,1344 => true,
13671345
1368 .anyerror,1346 .anyerror,
1369 .@"anyframe",
1370 .anyopaque,1347 .anyopaque,
1371 .atomic_order,1348 .atomic_order,
1372 .atomic_rmw_op,1349 .atomic_rmw_op,
...@@ -1594,9 +1571,7 @@ pub const Type = struct {...@@ -1594,9 +1571,7 @@ pub const Type = struct {
1594 switch (ty.ip_index) {1571 switch (ty.ip_index) {
1595 .empty_struct_type => return AbiAlignmentAdvanced{ .scalar = 0 },1572 .empty_struct_type => return AbiAlignmentAdvanced{ .scalar = 0 },
1596 .none => switch (ty.tag()) {1573 .none => switch (ty.tag()) {
1597 .pointer,1574 .pointer => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
1598 .anyframe_T,
1599 => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
16001575
1601 // TODO revisit this when we have the concept of the error tag type1576 // TODO revisit this when we have the concept of the error tag type
1602 .error_set_inferred,1577 .error_set_inferred,
...@@ -1617,7 +1592,7 @@ pub const Type = struct {...@@ -1617,7 +1592,7 @@ pub const Type = struct {
1617 if (int_type.bits == 0) return AbiAlignmentAdvanced{ .scalar = 0 };1592 if (int_type.bits == 0) return AbiAlignmentAdvanced{ .scalar = 0 };
1618 return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(int_type.bits, target) };1593 return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(int_type.bits, target) };
1619 },1594 },
1620 .ptr_type => {1595 .ptr_type, .anyframe_type => {
1621 return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) };1596 return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) };
1622 },1597 },
1623 .array_type => |array_type| {1598 .array_type => |array_type| {
...@@ -1657,7 +1632,6 @@ pub const Type = struct {...@@ -1657,7 +1632,6 @@ pub const Type = struct {
1657 .isize,1632 .isize,
1658 .export_options,1633 .export_options,
1659 .extern_options,1634 .extern_options,
1660 .@"anyframe",
1661 => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },1635 => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
16621636
1663 .c_char => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.char) },1637 .c_char => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.char) },
...@@ -1976,8 +1950,6 @@ pub const Type = struct {...@@ -1976,8 +1950,6 @@ pub const Type = struct {
1976 .inferred_alloc_const => unreachable,1950 .inferred_alloc_const => unreachable,
1977 .inferred_alloc_mut => unreachable,1951 .inferred_alloc_mut => unreachable,
19781952
1979 .anyframe_T => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
1980
1981 .pointer => switch (ty.castTag(.pointer).?.data.size) {1953 .pointer => switch (ty.castTag(.pointer).?.data.size) {
1982 .Slice => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },1954 .Slice => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },
1983 else => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },1955 else => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
...@@ -2039,6 +2011,8 @@ pub const Type = struct {...@@ -2039,6 +2011,8 @@ pub const Type = struct {
2039 .Slice => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },2011 .Slice => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },
2040 else => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) },2012 else => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) },
2041 },2013 },
2014 .anyframe_type => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
2015
2042 .array_type => |array_type| {2016 .array_type => |array_type| {
2043 const len = array_type.len + @boolToInt(array_type.sentinel != .none);2017 const len = array_type.len + @boolToInt(array_type.sentinel != .none);
2044 switch (try array_type.child.toType().abiSizeAdvanced(mod, strat)) {2018 switch (try array_type.child.toType().abiSizeAdvanced(mod, strat)) {
...@@ -2102,7 +2076,6 @@ pub const Type = struct {...@@ -2102,7 +2076,6 @@ pub const Type = struct {
21022076
2103 .usize,2077 .usize,
2104 .isize,2078 .isize,
2105 .@"anyframe",
2106 => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },2079 => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
21072080
2108 .c_char => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.char) },2081 .c_char => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.char) },
...@@ -2298,8 +2271,6 @@ pub const Type = struct {...@@ -2298,8 +2271,6 @@ pub const Type = struct {
2298 .inferred_alloc_const => unreachable,2271 .inferred_alloc_const => unreachable,
2299 .inferred_alloc_mut => unreachable,2272 .inferred_alloc_mut => unreachable,
23002273
2301 .anyframe_T => return target.ptrBitWidth(),
2302
2303 .pointer => switch (ty.castTag(.pointer).?.data.size) {2274 .pointer => switch (ty.castTag(.pointer).?.data.size) {
2304 .Slice => return target.ptrBitWidth() * 2,2275 .Slice => return target.ptrBitWidth() * 2,
2305 else => return target.ptrBitWidth(),2276 else => return target.ptrBitWidth(),
...@@ -2323,6 +2294,8 @@ pub const Type = struct {...@@ -2323,6 +2294,8 @@ pub const Type = struct {
2323 .Slice => return target.ptrBitWidth() * 2,2294 .Slice => return target.ptrBitWidth() * 2,
2324 else => return target.ptrBitWidth() * 2,2295 else => return target.ptrBitWidth() * 2,
2325 },2296 },
2297 .anyframe_type => return target.ptrBitWidth(),
2298
2326 .array_type => |array_type| {2299 .array_type => |array_type| {
2327 const len = array_type.len + @boolToInt(array_type.sentinel != .none);2300 const len = array_type.len + @boolToInt(array_type.sentinel != .none);
2328 if (len == 0) return 0;2301 if (len == 0) return 0;
...@@ -2349,7 +2322,6 @@ pub const Type = struct {...@@ -2349,7 +2322,6 @@ pub const Type = struct {
23492322
2350 .usize,2323 .usize,
2351 .isize,2324 .isize,
2352 .@"anyframe",
2353 => return target.ptrBitWidth(),2325 => return target.ptrBitWidth(),
23542326
2355 .c_char => return target.c_type_bit_size(.char),2327 .c_char => return target.c_type_bit_size(.char),
...@@ -2777,8 +2749,6 @@ pub const Type = struct {...@@ -2777,8 +2749,6 @@ pub const Type = struct {
2777 },2749 },
2778 .optional => ty.castTag(.optional).?.data.childType(mod),2750 .optional => ty.castTag(.optional).?.data.childType(mod),
27792751
2780 .anyframe_T => ty.castTag(.anyframe_T).?.data,
2781
2782 else => unreachable,2752 else => unreachable,
2783 },2753 },
2784 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {2754 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
...@@ -2786,6 +2756,10 @@ pub const Type = struct {...@@ -2786,6 +2756,10 @@ pub const Type = struct {
2786 .One => ptr_type.elem_type.toType().shallowElemType(mod),2756 .One => ptr_type.elem_type.toType().shallowElemType(mod),
2787 .Many, .C, .Slice => ptr_type.elem_type.toType(),2757 .Many, .C, .Slice => ptr_type.elem_type.toType(),
2788 },2758 },
2759 .anyframe_type => |child| {
2760 assert(child != .none);
2761 return child.toType();
2762 },
2789 .vector_type => |vector_type| vector_type.child.toType(),2763 .vector_type => |vector_type| vector_type.child.toType(),
2790 .array_type => |array_type| array_type.child.toType(),2764 .array_type => |array_type| array_type.child.toType(),
2791 .opt_type => |child| mod.intern_pool.childType(child).toType(),2765 .opt_type => |child| mod.intern_pool.childType(child).toType(),
...@@ -3154,6 +3128,7 @@ pub const Type = struct {...@@ -3154,6 +3128,7 @@ pub const Type = struct {
3154 .anon_struct_type => unreachable,3128 .anon_struct_type => unreachable,
31553129
3156 .ptr_type => unreachable,3130 .ptr_type => unreachable,
3131 .anyframe_type => unreachable,
3157 .array_type => unreachable,3132 .array_type => unreachable,
31583133
3159 .opt_type => unreachable,3134 .opt_type => unreachable,
...@@ -3327,7 +3302,6 @@ pub const Type = struct {...@@ -3327,7 +3302,6 @@ pub const Type = struct {
3327 .error_set,3302 .error_set,
3328 .error_set_merged,3303 .error_set_merged,
3329 .error_set_inferred,3304 .error_set_inferred,
3330 .anyframe_T,
3331 .pointer,3305 .pointer,
3332 => return null,3306 => return null,
33333307
...@@ -3355,6 +3329,7 @@ pub const Type = struct {...@@ -3355,6 +3329,7 @@ pub const Type = struct {
3355 .ptr_type,3329 .ptr_type,
3356 .error_union_type,3330 .error_union_type,
3357 .func_type,3331 .func_type,
3332 .anyframe_type,
3358 => return null,3333 => return null,
33593334
3360 .array_type => |array_type| {3335 .array_type => |array_type| {
...@@ -3401,7 +3376,6 @@ pub const Type = struct {...@@ -3401,7 +3376,6 @@ pub const Type = struct {
3401 .anyerror,3376 .anyerror,
3402 .comptime_int,3377 .comptime_int,
3403 .comptime_float,3378 .comptime_float,
3404 .@"anyframe",
3405 .enum_literal,3379 .enum_literal,
3406 .atomic_order,3380 .atomic_order,
3407 .atomic_rmw_op,3381 .atomic_rmw_op,
...@@ -3555,10 +3529,6 @@ pub const Type = struct {...@@ -3555,10 +3529,6 @@ pub const Type = struct {
3555 },3529 },
35563530
3557 .error_union => return ty.errorUnionPayload().comptimeOnly(mod),3531 .error_union => return ty.errorUnionPayload().comptimeOnly(mod),
3558 .anyframe_T => {
3559 const child_ty = ty.castTag(.anyframe_T).?.data;
3560 return child_ty.comptimeOnly(mod);
3561 },
3562 },3532 },
3563 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {3533 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
3564 .int_type => false,3534 .int_type => false,
...@@ -3570,6 +3540,10 @@ pub const Type = struct {...@@ -3570,6 +3540,10 @@ pub const Type = struct {
3570 return child_ty.comptimeOnly(mod);3540 return child_ty.comptimeOnly(mod);
3571 }3541 }
3572 },3542 },
3543 .anyframe_type => |child| {
3544 if (child == .none) return false;
3545 return child.toType().comptimeOnly(mod);
3546 },
3573 .array_type => |array_type| array_type.child.toType().comptimeOnly(mod),3547 .array_type => |array_type| array_type.child.toType().comptimeOnly(mod),
3574 .vector_type => |vector_type| vector_type.child.toType().comptimeOnly(mod),3548 .vector_type => |vector_type| vector_type.child.toType().comptimeOnly(mod),
3575 .opt_type => |child| child.toType().comptimeOnly(mod),3549 .opt_type => |child| child.toType().comptimeOnly(mod),
...@@ -3599,7 +3573,6 @@ pub const Type = struct {...@@ -3599,7 +3573,6 @@ pub const Type = struct {
3599 .bool,3573 .bool,
3600 .void,3574 .void,
3601 .anyerror,3575 .anyerror,
3602 .@"anyframe",
3603 .noreturn,3576 .noreturn,
3604 .generic_poison,3577 .generic_poison,
3605 .atomic_order,3578 .atomic_order,
...@@ -4245,7 +4218,6 @@ pub const Type = struct {...@@ -4245,7 +4218,6 @@ pub const Type = struct {
4245 pointer,4218 pointer,
4246 optional,4219 optional,
4247 error_union,4220 error_union,
4248 anyframe_T,
4249 error_set,4221 error_set,
4250 error_set_single,4222 error_set_single,
4251 /// The type is the inferred error set of a specific function.4223 /// The type is the inferred error set of a specific function.
...@@ -4261,9 +4233,7 @@ pub const Type = struct {...@@ -4261,9 +4233,7 @@ pub const Type = struct {
4261 .inferred_alloc_mut,4233 .inferred_alloc_mut,
4262 => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"),4234 => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"),
42634235
4264 .optional,4236 .optional => Payload.ElemType,
4265 .anyframe_T,
4266 => Payload.ElemType,
42674237
4268 .error_set => Payload.ErrorSet,4238 .error_set => Payload.ErrorSet,
4269 .error_set_inferred => Payload.ErrorSetInferred,4239 .error_set_inferred => Payload.ErrorSetInferred,