authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-03 13:01:10-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:40:03-07:00
log264292f430668652818b30fe6cf5d8b434530c84
tree170811d1df9e87806e3e0a32933590271555b0d3
parentcdf6acba961648cc800027b3e0adb0a3593a610a

InternPool: implement resolveTypeFields


3 files changed, 146 insertions(+), 23 deletions(-)

src/InternPool.zig+23-1
...@@ -78,7 +78,11 @@ pub const Key = union(enum) {...@@ -78,7 +78,11 @@ pub const Key = union(enum) {
78 },78 },
79 struct_type: struct {79 struct_type: struct {
80 fields_len: u32,80 fields_len: u32,
81 // TODO move Module.Struct data to here81 // TODO move Module.Struct data to InternPool
82 },
83 union_type: struct {
84 fields_len: u32,
85 // TODO move Module.Union data to InternPool
82 },86 },
8387
84 pub const IntType = std.builtin.Type.Int;88 pub const IntType = std.builtin.Type.Int;
...@@ -126,6 +130,10 @@ pub const Key = union(enum) {...@@ -126,6 +130,10 @@ pub const Key = union(enum) {
126 @panic("TODO");130 @panic("TODO");
127 }131 }
128 },132 },
133 .union_type => |union_type| {
134 _ = union_type;
135 @panic("TODO");
136 },
129 }137 }
130 }138 }
131139
...@@ -195,6 +203,14 @@ pub const Key = union(enum) {...@@ -195,6 +203,14 @@ pub const Key = union(enum) {
195203
196 @panic("TODO");204 @panic("TODO");
197 },205 },
206
207 .union_type => |a_info| {
208 const b_info = b.union_type;
209
210 _ = a_info;
211 _ = b_info;
212 @panic("TODO");
213 },
198 }214 }
199 }215 }
200216
...@@ -208,6 +224,7 @@ pub const Key = union(enum) {...@@ -208,6 +224,7 @@ pub const Key = union(enum) {
208 .error_union_type,224 .error_union_type,
209 .simple_type,225 .simple_type,
210 .struct_type,226 .struct_type,
227 .union_type,
211 => return .type_type,228 => return .type_type,
212229
213 .int => |x| return x.ty,230 .int => |x| return x.ty,
...@@ -978,6 +995,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -978,6 +995,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
978 .data = @enumToInt(SimpleInternal.type_empty_struct),995 .data = @enumToInt(SimpleInternal.type_empty_struct),
979 });996 });
980 },997 },
998
999 .union_type => |union_type| {
1000 _ = union_type;
1001 @panic("TODO");
1002 },
981 }1003 }
982 return @intToEnum(Index, ip.items.len - 1);1004 return @intToEnum(Index, ip.items.len - 1);
983}1005}
src/Sema.zig+113-22
...@@ -31373,6 +31373,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -31373,6 +31373,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31373 .error_union_type => @panic("TODO"),31373 .error_union_type => @panic("TODO"),
31374 .simple_type => @panic("TODO"),31374 .simple_type => @panic("TODO"),
31375 .struct_type => @panic("TODO"),31375 .struct_type => @panic("TODO"),
31376 .union_type => @panic("TODO"),
31376 .simple_value => unreachable,31377 .simple_value => unreachable,
31377 .extern_func => unreachable,31378 .extern_func => unreachable,
31378 .int => unreachable,31379 .int => unreachable,
...@@ -31660,30 +31661,118 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {...@@ -31660,30 +31661,118 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {
31660}31661}
3166131662
31662pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {31663pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
31663 switch (ty.tag()) {31664 const mod = sema.mod;
31664 .@"struct" => {31665
31665 const struct_obj = ty.castTag(.@"struct").?.data;31666 switch (ty.ip_index) {
31666 try sema.resolveTypeFieldsStruct(ty, struct_obj);31667 .none => switch (ty.tag()) {
31667 return ty;31668 .@"struct" => {
31668 },31669 const struct_obj = ty.castTag(.@"struct").?.data;
31669 .@"union", .union_safety_tagged, .union_tagged => {31670 try sema.resolveTypeFieldsStruct(ty, struct_obj);
31670 const union_obj = ty.cast(Type.Payload.Union).?.data;31671 return ty;
31671 try sema.resolveTypeFieldsUnion(ty, union_obj);31672 },
31672 return ty;31673 .@"union", .union_safety_tagged, .union_tagged => {
31674 const union_obj = ty.cast(Type.Payload.Union).?.data;
31675 try sema.resolveTypeFieldsUnion(ty, union_obj);
31676 return ty;
31677 },
31678 .type_info => return sema.getBuiltinType("Type"),
31679 .extern_options => return sema.getBuiltinType("ExternOptions"),
31680 .export_options => return sema.getBuiltinType("ExportOptions"),
31681 .atomic_order => return sema.getBuiltinType("AtomicOrder"),
31682 .atomic_rmw_op => return sema.getBuiltinType("AtomicRmwOp"),
31683 .calling_convention => return sema.getBuiltinType("CallingConvention"),
31684 .address_space => return sema.getBuiltinType("AddressSpace"),
31685 .float_mode => return sema.getBuiltinType("FloatMode"),
31686 .reduce_op => return sema.getBuiltinType("ReduceOp"),
31687 .modifier => return sema.getBuiltinType("CallModifier"),
31688 .prefetch_options => return sema.getBuiltinType("PrefetchOptions"),
31689
31690 else => return ty,
31673 },31691 },
31674 .type_info => return sema.getBuiltinType("Type"),
31675 .extern_options => return sema.getBuiltinType("ExternOptions"),
31676 .export_options => return sema.getBuiltinType("ExportOptions"),
31677 .atomic_order => return sema.getBuiltinType("AtomicOrder"),
31678 .atomic_rmw_op => return sema.getBuiltinType("AtomicRmwOp"),
31679 .calling_convention => return sema.getBuiltinType("CallingConvention"),
31680 .address_space => return sema.getBuiltinType("AddressSpace"),
31681 .float_mode => return sema.getBuiltinType("FloatMode"),
31682 .reduce_op => return sema.getBuiltinType("ReduceOp"),
31683 .modifier => return sema.getBuiltinType("CallModifier"),
31684 .prefetch_options => return sema.getBuiltinType("PrefetchOptions"),
3168531692
31686 else => return ty,31693 .u1_type,
31694 .u8_type,
31695 .i8_type,
31696 .u16_type,
31697 .i16_type,
31698 .u29_type,
31699 .u32_type,
31700 .i32_type,
31701 .u64_type,
31702 .i64_type,
31703 .u80_type,
31704 .u128_type,
31705 .i128_type,
31706 .usize_type,
31707 .isize_type,
31708 .c_char_type,
31709 .c_short_type,
31710 .c_ushort_type,
31711 .c_int_type,
31712 .c_uint_type,
31713 .c_long_type,
31714 .c_ulong_type,
31715 .c_longlong_type,
31716 .c_ulonglong_type,
31717 .c_longdouble_type,
31718 .f16_type,
31719 .f32_type,
31720 .f64_type,
31721 .f80_type,
31722 .f128_type,
31723 .anyopaque_type,
31724 .bool_type,
31725 .void_type,
31726 .type_type,
31727 .anyerror_type,
31728 .comptime_int_type,
31729 .comptime_float_type,
31730 .noreturn_type,
31731 .anyframe_type,
31732 .null_type,
31733 .undefined_type,
31734 .enum_literal_type,
31735 .manyptr_u8_type,
31736 .manyptr_const_u8_type,
31737 .single_const_pointer_to_comptime_int_type,
31738 .const_slice_u8_type,
31739 .anyerror_void_error_union_type,
31740 .generic_poison_type,
31741 .empty_struct_type,
31742 => return ty,
31743
31744 .undef => unreachable,
31745 .zero => unreachable,
31746 .zero_usize => unreachable,
31747 .one => unreachable,
31748 .one_usize => unreachable,
31749 .calling_convention_c => unreachable,
31750 .calling_convention_inline => unreachable,
31751 .void_value => unreachable,
31752 .unreachable_value => unreachable,
31753 .null_value => unreachable,
31754 .bool_true => unreachable,
31755 .bool_false => unreachable,
31756 .empty_struct => unreachable,
31757 .generic_poison => unreachable,
31758
31759 .type_info_type => return sema.getBuiltinType("Type"),
31760 .extern_options_type => return sema.getBuiltinType("ExternOptions"),
31761 .export_options_type => return sema.getBuiltinType("ExportOptions"),
31762 .atomic_order_type => return sema.getBuiltinType("AtomicOrder"),
31763 .atomic_rmw_op_type => return sema.getBuiltinType("AtomicRmwOp"),
31764 .calling_convention_type => return sema.getBuiltinType("CallingConvention"),
31765 .address_space_type => return sema.getBuiltinType("AddressSpace"),
31766 .float_mode_type => return sema.getBuiltinType("FloatMode"),
31767 .reduce_op_type => return sema.getBuiltinType("ReduceOp"),
31768 .call_modifier_type => return sema.getBuiltinType("CallModifier"),
31769 .prefetch_options_type => return sema.getBuiltinType("PrefetchOptions"),
31770
31771 _ => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
31772 .struct_type => @panic("TODO"),
31773 .union_type => @panic("TODO"),
31774 else => return ty,
31775 },
31687 }31776 }
31688}31777}
3168931778
...@@ -32824,6 +32913,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -32824,6 +32913,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
32824 .var_args_param => unreachable,32913 .var_args_param => unreachable,
32825 },32914 },
32826 .struct_type => @panic("TODO"),32915 .struct_type => @panic("TODO"),
32916 .union_type => @panic("TODO"),
32827 .simple_value => unreachable,32917 .simple_value => unreachable,
32828 .extern_func => unreachable,32918 .extern_func => unreachable,
32829 .int => unreachable,32919 .int => unreachable,
...@@ -33475,6 +33565,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -33475,6 +33565,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33475 .error_union_type => @panic("TODO"),33565 .error_union_type => @panic("TODO"),
33476 .simple_type => @panic("TODO"),33566 .simple_type => @panic("TODO"),
33477 .struct_type => @panic("TODO"),33567 .struct_type => @panic("TODO"),
33568 .union_type => @panic("TODO"),
33478 .simple_value => unreachable,33569 .simple_value => unreachable,
33479 .extern_func => unreachable,33570 .extern_func => unreachable,
33480 .int => unreachable,33571 .int => unreachable,
src/type.zig+10
...@@ -43,6 +43,7 @@ pub const Type = struct {...@@ -43,6 +43,7 @@ pub const Type = struct {
43 .optional_type => return .Optional,43 .optional_type => return .Optional,
44 .error_union_type => return .ErrorUnion,44 .error_union_type => return .ErrorUnion,
45 .struct_type => return .Struct,45 .struct_type => return .Struct,
46 .union_type => return .Union,
46 .simple_type => |s| switch (s) {47 .simple_type => |s| switch (s) {
47 .f16,48 .f16,
48 .f32,49 .f32,
...@@ -2018,6 +2019,7 @@ pub const Type = struct {...@@ -2018,6 +2019,7 @@ pub const Type = struct {
2018 .error_union_type => @panic("TODO"),2019 .error_union_type => @panic("TODO"),
2019 .simple_type => |s| return writer.writeAll(@tagName(s)),2020 .simple_type => |s| return writer.writeAll(@tagName(s)),
2020 .struct_type => @panic("TODO"),2021 .struct_type => @panic("TODO"),
2022 .union_type => @panic("TODO"),
2021 .simple_value => unreachable,2023 .simple_value => unreachable,
2022 .extern_func => unreachable,2024 .extern_func => unreachable,
2023 .int => unreachable,2025 .int => unreachable,
...@@ -2490,6 +2492,7 @@ pub const Type = struct {...@@ -2490,6 +2492,7 @@ pub const Type = struct {
2490 .var_args_param => unreachable,2492 .var_args_param => unreachable,
2491 },2493 },
2492 .struct_type => @panic("TODO"),2494 .struct_type => @panic("TODO"),
2495 .union_type => @panic("TODO"),
2493 .simple_value => unreachable,2496 .simple_value => unreachable,
2494 .extern_func => unreachable,2497 .extern_func => unreachable,
2495 .int => unreachable,2498 .int => unreachable,
...@@ -2768,6 +2771,7 @@ pub const Type = struct {...@@ -2768,6 +2771,7 @@ pub const Type = struct {
2768 => false,2771 => false,
2769 },2772 },
2770 .struct_type => @panic("TODO"),2773 .struct_type => @panic("TODO"),
2774 .union_type => @panic("TODO"),
2771 .simple_value => unreachable,2775 .simple_value => unreachable,
2772 .extern_func => unreachable,2776 .extern_func => unreachable,
2773 .int => unreachable,2777 .int => unreachable,
...@@ -3083,6 +3087,7 @@ pub const Type = struct {...@@ -3083,6 +3087,7 @@ pub const Type = struct {
3083 .error_union_type => @panic("TODO"),3087 .error_union_type => @panic("TODO"),
3084 .simple_type => @panic("TODO"),3088 .simple_type => @panic("TODO"),
3085 .struct_type => @panic("TODO"),3089 .struct_type => @panic("TODO"),
3090 .union_type => @panic("TODO"),
3086 .simple_value => unreachable,3091 .simple_value => unreachable,
3087 .extern_func => unreachable,3092 .extern_func => unreachable,
3088 .int => unreachable,3093 .int => unreachable,
...@@ -3478,6 +3483,7 @@ pub const Type = struct {...@@ -3478,6 +3483,7 @@ pub const Type = struct {
3478 .error_union_type => @panic("TODO"),3483 .error_union_type => @panic("TODO"),
3479 .simple_type => @panic("TODO"),3484 .simple_type => @panic("TODO"),
3480 .struct_type => @panic("TODO"),3485 .struct_type => @panic("TODO"),
3486 .union_type => @panic("TODO"),
3481 .simple_value => unreachable,3487 .simple_value => unreachable,
3482 .extern_func => unreachable,3488 .extern_func => unreachable,
3483 .int => unreachable,3489 .int => unreachable,
...@@ -3816,6 +3822,7 @@ pub const Type = struct {...@@ -3816,6 +3822,7 @@ pub const Type = struct {
3816 .error_union_type => @panic("TODO"),3822 .error_union_type => @panic("TODO"),
3817 .simple_type => @panic("TODO"),3823 .simple_type => @panic("TODO"),
3818 .struct_type => @panic("TODO"),3824 .struct_type => @panic("TODO"),
3825 .union_type => @panic("TODO"),
3819 .simple_value => unreachable,3826 .simple_value => unreachable,
3820 .extern_func => unreachable,3827 .extern_func => unreachable,
3821 .int => unreachable,3828 .int => unreachable,
...@@ -4847,6 +4854,7 @@ pub const Type = struct {...@@ -4847,6 +4854,7 @@ pub const Type = struct {
4847 .error_union_type => @panic("TODO"),4854 .error_union_type => @panic("TODO"),
4848 .simple_type => @panic("TODO"),4855 .simple_type => @panic("TODO"),
4849 .struct_type => unreachable,4856 .struct_type => unreachable,
4857 .union_type => unreachable,
4850 .simple_value => unreachable,4858 .simple_value => unreachable,
4851 .extern_func => unreachable,4859 .extern_func => unreachable,
4852 .int => unreachable,4860 .int => unreachable,
...@@ -5171,6 +5179,7 @@ pub const Type = struct {...@@ -5171,6 +5179,7 @@ pub const Type = struct {
5171 .var_args_param => unreachable,5179 .var_args_param => unreachable,
5172 },5180 },
5173 .struct_type => @panic("TODO"),5181 .struct_type => @panic("TODO"),
5182 .union_type => @panic("TODO"),
5174 .simple_value => unreachable,5183 .simple_value => unreachable,
5175 .extern_func => unreachable,5184 .extern_func => unreachable,
5176 .int => unreachable,5185 .int => unreachable,
...@@ -5373,6 +5382,7 @@ pub const Type = struct {...@@ -5373,6 +5382,7 @@ pub const Type = struct {
5373 .error_union_type => @panic("TODO"),5382 .error_union_type => @panic("TODO"),
5374 .simple_type => @panic("TODO"),5383 .simple_type => @panic("TODO"),
5375 .struct_type => @panic("TODO"),5384 .struct_type => @panic("TODO"),
5385 .union_type => @panic("TODO"),
5376 .simple_value => unreachable,5386 .simple_value => unreachable,
5377 .extern_func => unreachable,5387 .extern_func => unreachable,
5378 .int => unreachable,5388 .int => unreachable,