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) {
7878 },
7979 struct_type: struct {
8080 fields_len: u32,
81 // TODO move Module.Struct data to here
81 // TODO move Module.Struct data to InternPool
82 },
83 union_type: struct {
84 fields_len: u32,
85 // TODO move Module.Union data to InternPool
8286 },
8387
8488 pub const IntType = std.builtin.Type.Int;
......@@ -126,6 +130,10 @@ pub const Key = union(enum) {
126130 @panic("TODO");
127131 }
128132 },
133 .union_type => |union_type| {
134 _ = union_type;
135 @panic("TODO");
136 },
129137 }
130138 }
131139
......@@ -195,6 +203,14 @@ pub const Key = union(enum) {
195203
196204 @panic("TODO");
197205 },
206
207 .union_type => |a_info| {
208 const b_info = b.union_type;
209
210 _ = a_info;
211 _ = b_info;
212 @panic("TODO");
213 },
198214 }
199215 }
200216
......@@ -208,6 +224,7 @@ pub const Key = union(enum) {
208224 .error_union_type,
209225 .simple_type,
210226 .struct_type,
227 .union_type,
211228 => return .type_type,
212229
213230 .int => |x| return x.ty,
......@@ -978,6 +995,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
978995 .data = @enumToInt(SimpleInternal.type_empty_struct),
979996 });
980997 },
998
999 .union_type => |union_type| {
1000 _ = union_type;
1001 @panic("TODO");
1002 },
9811003 }
9821004 return @intToEnum(Index, ip.items.len - 1);
9831005}
src/Sema.zig+113-22
......@@ -31373,6 +31373,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3137331373 .error_union_type => @panic("TODO"),
3137431374 .simple_type => @panic("TODO"),
3137531375 .struct_type => @panic("TODO"),
31376 .union_type => @panic("TODO"),
3137631377 .simple_value => unreachable,
3137731378 .extern_func => unreachable,
3137831379 .int => unreachable,
......@@ -31660,30 +31661,118 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {
3166031661}
3166131662
3166231663pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
31663 switch (ty.tag()) {
31664 .@"struct" => {
31665 const struct_obj = ty.castTag(.@"struct").?.data;
31666 try sema.resolveTypeFieldsStruct(ty, struct_obj);
31667 return ty;
31668 },
31669 .@"union", .union_safety_tagged, .union_tagged => {
31670 const union_obj = ty.cast(Type.Payload.Union).?.data;
31671 try sema.resolveTypeFieldsUnion(ty, union_obj);
31672 return ty;
31664 const mod = sema.mod;
31665
31666 switch (ty.ip_index) {
31667 .none => switch (ty.tag()) {
31668 .@"struct" => {
31669 const struct_obj = ty.castTag(.@"struct").?.data;
31670 try sema.resolveTypeFieldsStruct(ty, struct_obj);
31671 return ty;
31672 },
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,
3167331691 },
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 },
3168731776 }
3168831777}
3168931778
......@@ -32824,6 +32913,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3282432913 .var_args_param => unreachable,
3282532914 },
3282632915 .struct_type => @panic("TODO"),
32916 .union_type => @panic("TODO"),
3282732917 .simple_value => unreachable,
3282832918 .extern_func => unreachable,
3282932919 .int => unreachable,
......@@ -33475,6 +33565,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3347533565 .error_union_type => @panic("TODO"),
3347633566 .simple_type => @panic("TODO"),
3347733567 .struct_type => @panic("TODO"),
33568 .union_type => @panic("TODO"),
3347833569 .simple_value => unreachable,
3347933570 .extern_func => unreachable,
3348033571 .int => unreachable,
src/type.zig+10
......@@ -43,6 +43,7 @@ pub const Type = struct {
4343 .optional_type => return .Optional,
4444 .error_union_type => return .ErrorUnion,
4545 .struct_type => return .Struct,
46 .union_type => return .Union,
4647 .simple_type => |s| switch (s) {
4748 .f16,
4849 .f32,
......@@ -2018,6 +2019,7 @@ pub const Type = struct {
20182019 .error_union_type => @panic("TODO"),
20192020 .simple_type => |s| return writer.writeAll(@tagName(s)),
20202021 .struct_type => @panic("TODO"),
2022 .union_type => @panic("TODO"),
20212023 .simple_value => unreachable,
20222024 .extern_func => unreachable,
20232025 .int => unreachable,
......@@ -2490,6 +2492,7 @@ pub const Type = struct {
24902492 .var_args_param => unreachable,
24912493 },
24922494 .struct_type => @panic("TODO"),
2495 .union_type => @panic("TODO"),
24932496 .simple_value => unreachable,
24942497 .extern_func => unreachable,
24952498 .int => unreachable,
......@@ -2768,6 +2771,7 @@ pub const Type = struct {
27682771 => false,
27692772 },
27702773 .struct_type => @panic("TODO"),
2774 .union_type => @panic("TODO"),
27712775 .simple_value => unreachable,
27722776 .extern_func => unreachable,
27732777 .int => unreachable,
......@@ -3083,6 +3087,7 @@ pub const Type = struct {
30833087 .error_union_type => @panic("TODO"),
30843088 .simple_type => @panic("TODO"),
30853089 .struct_type => @panic("TODO"),
3090 .union_type => @panic("TODO"),
30863091 .simple_value => unreachable,
30873092 .extern_func => unreachable,
30883093 .int => unreachable,
......@@ -3478,6 +3483,7 @@ pub const Type = struct {
34783483 .error_union_type => @panic("TODO"),
34793484 .simple_type => @panic("TODO"),
34803485 .struct_type => @panic("TODO"),
3486 .union_type => @panic("TODO"),
34813487 .simple_value => unreachable,
34823488 .extern_func => unreachable,
34833489 .int => unreachable,
......@@ -3816,6 +3822,7 @@ pub const Type = struct {
38163822 .error_union_type => @panic("TODO"),
38173823 .simple_type => @panic("TODO"),
38183824 .struct_type => @panic("TODO"),
3825 .union_type => @panic("TODO"),
38193826 .simple_value => unreachable,
38203827 .extern_func => unreachable,
38213828 .int => unreachable,
......@@ -4847,6 +4854,7 @@ pub const Type = struct {
48474854 .error_union_type => @panic("TODO"),
48484855 .simple_type => @panic("TODO"),
48494856 .struct_type => unreachable,
4857 .union_type => unreachable,
48504858 .simple_value => unreachable,
48514859 .extern_func => unreachable,
48524860 .int => unreachable,
......@@ -5171,6 +5179,7 @@ pub const Type = struct {
51715179 .var_args_param => unreachable,
51725180 },
51735181 .struct_type => @panic("TODO"),
5182 .union_type => @panic("TODO"),
51745183 .simple_value => unreachable,
51755184 .extern_func => unreachable,
51765185 .int => unreachable,
......@@ -5373,6 +5382,7 @@ pub const Type = struct {
53735382 .error_union_type => @panic("TODO"),
53745383 .simple_type => @panic("TODO"),
53755384 .struct_type => @panic("TODO"),
5385 .union_type => @panic("TODO"),
53765386 .simple_value => unreachable,
53775387 .extern_func => unreachable,
53785388 .int => unreachable,