Commit 264292f430
Changed files (3)
src/InternPool.zig
@@ -78,7 +78,11 @@ pub const Key = union(enum) {
},
struct_type: struct {
fields_len: u32,
- // TODO move Module.Struct data to here
+ // TODO move Module.Struct data to InternPool
+ },
+ union_type: struct {
+ fields_len: u32,
+ // TODO move Module.Union data to InternPool
},
pub const IntType = std.builtin.Type.Int;
@@ -126,6 +130,10 @@ pub const Key = union(enum) {
@panic("TODO");
}
},
+ .union_type => |union_type| {
+ _ = union_type;
+ @panic("TODO");
+ },
}
}
@@ -195,6 +203,14 @@ pub const Key = union(enum) {
@panic("TODO");
},
+
+ .union_type => |a_info| {
+ const b_info = b.union_type;
+
+ _ = a_info;
+ _ = b_info;
+ @panic("TODO");
+ },
}
}
@@ -208,6 +224,7 @@ pub const Key = union(enum) {
.error_union_type,
.simple_type,
.struct_type,
+ .union_type,
=> return .type_type,
.int => |x| return x.ty,
@@ -978,6 +995,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
.data = @enumToInt(SimpleInternal.type_empty_struct),
});
},
+
+ .union_type => |union_type| {
+ _ = union_type;
+ @panic("TODO");
+ },
}
return @intToEnum(Index, ip.items.len - 1);
}
src/Sema.zig
@@ -31373,6 +31373,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
.error_union_type => @panic("TODO"),
.simple_type => @panic("TODO"),
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -31660,30 +31661,118 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {
}
pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
- switch (ty.tag()) {
- .@"struct" => {
- const struct_obj = ty.castTag(.@"struct").?.data;
- try sema.resolveTypeFieldsStruct(ty, struct_obj);
- return ty;
- },
- .@"union", .union_safety_tagged, .union_tagged => {
- const union_obj = ty.cast(Type.Payload.Union).?.data;
- try sema.resolveTypeFieldsUnion(ty, union_obj);
- return ty;
+ const mod = sema.mod;
+
+ switch (ty.ip_index) {
+ .none => switch (ty.tag()) {
+ .@"struct" => {
+ const struct_obj = ty.castTag(.@"struct").?.data;
+ try sema.resolveTypeFieldsStruct(ty, struct_obj);
+ return ty;
+ },
+ .@"union", .union_safety_tagged, .union_tagged => {
+ const union_obj = ty.cast(Type.Payload.Union).?.data;
+ try sema.resolveTypeFieldsUnion(ty, union_obj);
+ return ty;
+ },
+ .type_info => return sema.getBuiltinType("Type"),
+ .extern_options => return sema.getBuiltinType("ExternOptions"),
+ .export_options => return sema.getBuiltinType("ExportOptions"),
+ .atomic_order => return sema.getBuiltinType("AtomicOrder"),
+ .atomic_rmw_op => return sema.getBuiltinType("AtomicRmwOp"),
+ .calling_convention => return sema.getBuiltinType("CallingConvention"),
+ .address_space => return sema.getBuiltinType("AddressSpace"),
+ .float_mode => return sema.getBuiltinType("FloatMode"),
+ .reduce_op => return sema.getBuiltinType("ReduceOp"),
+ .modifier => return sema.getBuiltinType("CallModifier"),
+ .prefetch_options => return sema.getBuiltinType("PrefetchOptions"),
+
+ else => return ty,
},
- .type_info => return sema.getBuiltinType("Type"),
- .extern_options => return sema.getBuiltinType("ExternOptions"),
- .export_options => return sema.getBuiltinType("ExportOptions"),
- .atomic_order => return sema.getBuiltinType("AtomicOrder"),
- .atomic_rmw_op => return sema.getBuiltinType("AtomicRmwOp"),
- .calling_convention => return sema.getBuiltinType("CallingConvention"),
- .address_space => return sema.getBuiltinType("AddressSpace"),
- .float_mode => return sema.getBuiltinType("FloatMode"),
- .reduce_op => return sema.getBuiltinType("ReduceOp"),
- .modifier => return sema.getBuiltinType("CallModifier"),
- .prefetch_options => return sema.getBuiltinType("PrefetchOptions"),
- else => return ty,
+ .u1_type,
+ .u8_type,
+ .i8_type,
+ .u16_type,
+ .i16_type,
+ .u29_type,
+ .u32_type,
+ .i32_type,
+ .u64_type,
+ .i64_type,
+ .u80_type,
+ .u128_type,
+ .i128_type,
+ .usize_type,
+ .isize_type,
+ .c_char_type,
+ .c_short_type,
+ .c_ushort_type,
+ .c_int_type,
+ .c_uint_type,
+ .c_long_type,
+ .c_ulong_type,
+ .c_longlong_type,
+ .c_ulonglong_type,
+ .c_longdouble_type,
+ .f16_type,
+ .f32_type,
+ .f64_type,
+ .f80_type,
+ .f128_type,
+ .anyopaque_type,
+ .bool_type,
+ .void_type,
+ .type_type,
+ .anyerror_type,
+ .comptime_int_type,
+ .comptime_float_type,
+ .noreturn_type,
+ .anyframe_type,
+ .null_type,
+ .undefined_type,
+ .enum_literal_type,
+ .manyptr_u8_type,
+ .manyptr_const_u8_type,
+ .single_const_pointer_to_comptime_int_type,
+ .const_slice_u8_type,
+ .anyerror_void_error_union_type,
+ .generic_poison_type,
+ .empty_struct_type,
+ => return ty,
+
+ .undef => unreachable,
+ .zero => unreachable,
+ .zero_usize => unreachable,
+ .one => unreachable,
+ .one_usize => unreachable,
+ .calling_convention_c => unreachable,
+ .calling_convention_inline => unreachable,
+ .void_value => unreachable,
+ .unreachable_value => unreachable,
+ .null_value => unreachable,
+ .bool_true => unreachable,
+ .bool_false => unreachable,
+ .empty_struct => unreachable,
+ .generic_poison => unreachable,
+
+ .type_info_type => return sema.getBuiltinType("Type"),
+ .extern_options_type => return sema.getBuiltinType("ExternOptions"),
+ .export_options_type => return sema.getBuiltinType("ExportOptions"),
+ .atomic_order_type => return sema.getBuiltinType("AtomicOrder"),
+ .atomic_rmw_op_type => return sema.getBuiltinType("AtomicRmwOp"),
+ .calling_convention_type => return sema.getBuiltinType("CallingConvention"),
+ .address_space_type => return sema.getBuiltinType("AddressSpace"),
+ .float_mode_type => return sema.getBuiltinType("FloatMode"),
+ .reduce_op_type => return sema.getBuiltinType("ReduceOp"),
+ .call_modifier_type => return sema.getBuiltinType("CallModifier"),
+ .prefetch_options_type => return sema.getBuiltinType("PrefetchOptions"),
+
+ _ => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
+ .struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
+ else => return ty,
+ },
}
}
@@ -32824,6 +32913,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
.var_args_param => unreachable,
},
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -33475,6 +33565,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
.error_union_type => @panic("TODO"),
.simple_type => @panic("TODO"),
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
src/type.zig
@@ -43,6 +43,7 @@ pub const Type = struct {
.optional_type => return .Optional,
.error_union_type => return .ErrorUnion,
.struct_type => return .Struct,
+ .union_type => return .Union,
.simple_type => |s| switch (s) {
.f16,
.f32,
@@ -2018,6 +2019,7 @@ pub const Type = struct {
.error_union_type => @panic("TODO"),
.simple_type => |s| return writer.writeAll(@tagName(s)),
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -2490,6 +2492,7 @@ pub const Type = struct {
.var_args_param => unreachable,
},
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -2768,6 +2771,7 @@ pub const Type = struct {
=> false,
},
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -3083,6 +3087,7 @@ pub const Type = struct {
.error_union_type => @panic("TODO"),
.simple_type => @panic("TODO"),
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -3478,6 +3483,7 @@ pub const Type = struct {
.error_union_type => @panic("TODO"),
.simple_type => @panic("TODO"),
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -3816,6 +3822,7 @@ pub const Type = struct {
.error_union_type => @panic("TODO"),
.simple_type => @panic("TODO"),
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -4847,6 +4854,7 @@ pub const Type = struct {
.error_union_type => @panic("TODO"),
.simple_type => @panic("TODO"),
.struct_type => unreachable,
+ .union_type => unreachable,
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -5171,6 +5179,7 @@ pub const Type = struct {
.var_args_param => unreachable,
},
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,
@@ -5373,6 +5382,7 @@ pub const Type = struct {
.error_union_type => @panic("TODO"),
.simple_type => @panic("TODO"),
.struct_type => @panic("TODO"),
+ .union_type => @panic("TODO"),
.simple_value => unreachable,
.extern_func => unreachable,
.int => unreachable,