authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-03 16:07:36-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:40:03-07:00
log4cd8a40b3b34d4e68853088dd637a9da9b6a8891
tree8fbf70325352d59010ddbeca2cde7ca8538b0703
parentaa1bb5517d57ae7540ce2c7a4315b2f242d1470c

stage2: move float types to InternPool


6 files changed, 403 insertions(+), 256 deletions(-)

src/Sema.zig+102-40
...@@ -5138,7 +5138,7 @@ fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -5138,7 +5138,7 @@ fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
5138 defer tracy.end();5138 defer tracy.end();
51395139
5140 const int = sema.code.instructions.items(.data)[inst].int;5140 const int = sema.code.instructions.items(.data)[inst].int;
5141 return sema.addIntUnsigned(Type.initTag(.comptime_int), int);5141 return sema.addIntUnsigned(Type.comptime_int, int);
5142}5142}
51435143
5144fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5144fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -5154,7 +5154,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -5154,7 +5154,7 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
5154 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);5154 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
51555155
5156 return sema.addConstant(5156 return sema.addConstant(
5157 Type.initTag(.comptime_int),5157 Type.comptime_int,
5158 try Value.Tag.int_big_positive.create(arena, limbs),5158 try Value.Tag.int_big_positive.create(arena, limbs),
5159 );5159 );
5160}5160}
...@@ -5164,7 +5164,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -5164,7 +5164,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
5164 const arena = sema.arena;5164 const arena = sema.arena;
5165 const number = sema.code.instructions.items(.data)[inst].float;5165 const number = sema.code.instructions.items(.data)[inst].float;
5166 return sema.addConstant(5166 return sema.addConstant(
5167 Type.initTag(.comptime_float),5167 Type.comptime_float,
5168 try Value.Tag.float_64.create(arena, number),5168 try Value.Tag.float_64.create(arena, number),
5169 );5169 );
5170}5170}
...@@ -5176,7 +5176,7 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -5176,7 +5176,7 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
5176 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;5176 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
5177 const number = extra.get();5177 const number = extra.get();
5178 return sema.addConstant(5178 return sema.addConstant(
5179 Type.initTag(.comptime_float),5179 Type.comptime_float,
5180 try Value.Tag.float_128.create(arena, number),5180 try Value.Tag.float_128.create(arena, number),
5181 );5181 );
5182}5182}
...@@ -15152,8 +15152,8 @@ fn zirAsm(...@@ -15152,8 +15152,8 @@ fn zirAsm(
15152 const uncasted_arg = try sema.resolveInst(input.data.operand);15152 const uncasted_arg = try sema.resolveInst(input.data.operand);
15153 const uncasted_arg_ty = sema.typeOf(uncasted_arg);15153 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
15154 switch (uncasted_arg_ty.zigTypeTag(mod)) {15154 switch (uncasted_arg_ty.zigTypeTag(mod)) {
15155 .ComptimeInt => arg.* = try sema.coerce(block, Type.initTag(.usize), uncasted_arg, src),15155 .ComptimeInt => arg.* = try sema.coerce(block, Type.usize, uncasted_arg, src),
15156 .ComptimeFloat => arg.* = try sema.coerce(block, Type.initTag(.f64), uncasted_arg, src),15156 .ComptimeFloat => arg.* = try sema.coerce(block, Type.f64, uncasted_arg, src),
15157 else => {15157 else => {
15158 arg.* = uncasted_arg;15158 arg.* = uncasted_arg;
15159 try sema.queueFullTypeResolution(uncasted_arg_ty);15159 try sema.queueFullTypeResolution(uncasted_arg_ty);
...@@ -31369,14 +31369,59 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -31369,14 +31369,59 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
31369pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {31369pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31370 const mod = sema.mod;31370 const mod = sema.mod;
3137131371
31372 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {31372 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
31373 .int_type => return false,31373 .int_type => false,
31374 .ptr_type => @panic("TODO"),31374 .ptr_type => @panic("TODO"),
31375 .array_type => @panic("TODO"),31375 .array_type => @panic("TODO"),
31376 .vector_type => @panic("TODO"),31376 .vector_type => @panic("TODO"),
31377 .optional_type => @panic("TODO"),31377 .optional_type => @panic("TODO"),
31378 .error_union_type => @panic("TODO"),31378 .error_union_type => @panic("TODO"),
31379 .simple_type => @panic("TODO"),31379 .simple_type => |t| switch (t) {
31380 .f16,
31381 .f32,
31382 .f64,
31383 .f80,
31384 .f128,
31385 .usize,
31386 .isize,
31387 .c_char,
31388 .c_short,
31389 .c_ushort,
31390 .c_int,
31391 .c_uint,
31392 .c_long,
31393 .c_ulong,
31394 .c_longlong,
31395 .c_ulonglong,
31396 .c_longdouble,
31397 .anyopaque,
31398 .bool,
31399 .void,
31400 .anyerror,
31401 .@"anyframe",
31402 .noreturn,
31403 .generic_poison,
31404 .atomic_order,
31405 .atomic_rmw_op,
31406 .calling_convention,
31407 .address_space,
31408 .float_mode,
31409 .reduce_op,
31410 .call_modifier,
31411 .prefetch_options,
31412 .export_options,
31413 .extern_options,
31414 => false,
31415
31416 .type,
31417 .comptime_int,
31418 .comptime_float,
31419 .null,
31420 .undefined,
31421 .enum_literal,
31422 .type_info,
31423 => true,
31424 },
31380 .struct_type => @panic("TODO"),31425 .struct_type => @panic("TODO"),
31381 .union_type => @panic("TODO"),31426 .union_type => @panic("TODO"),
31382 .simple_value => unreachable,31427 .simple_value => unreachable,
...@@ -31409,12 +31454,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -31409,12 +31454,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31409 .c_ulong,31454 .c_ulong,
31410 .c_longlong,31455 .c_longlong,
31411 .c_ulonglong,31456 .c_ulonglong,
31412 .c_longdouble,
31413 .f16,
31414 .f32,
31415 .f64,
31416 .f80,
31417 .f128,
31418 .anyopaque,31457 .anyopaque,
31419 .bool,31458 .bool,
31420 .void,31459 .void,
...@@ -31455,7 +31494,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -31455,7 +31494,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31455 .single_const_pointer_to_comptime_int,31494 .single_const_pointer_to_comptime_int,
31456 .type,31495 .type,
31457 .comptime_int,31496 .comptime_int,
31458 .comptime_float,
31459 .enum_literal,31497 .enum_literal,
31460 .type_info,31498 .type_info,
31461 .function,31499 .function,
...@@ -32926,14 +32964,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -32926,14 +32964,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
32926 };32964 };
3292732965
32928 switch (ty.tag()) {32966 switch (ty.tag()) {
32929 .f16,
32930 .f32,
32931 .f64,
32932 .f80,
32933 .f128,
32934 .c_longdouble,
32935 .comptime_int,32967 .comptime_int,
32936 .comptime_float,
32937 .u1,32968 .u1,
32938 .u8,32969 .u8,
32939 .i8,32970 .i8,
...@@ -33193,19 +33224,12 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {...@@ -33193,19 +33224,12 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
33193 .c_ulong => return .c_ulong_type,33224 .c_ulong => return .c_ulong_type,
33194 .c_longlong => return .c_longlong_type,33225 .c_longlong => return .c_longlong_type,
33195 .c_ulonglong => return .c_ulonglong_type,33226 .c_ulonglong => return .c_ulonglong_type,
33196 .c_longdouble => return .c_longdouble_type,
33197 .f16 => return .f16_type,
33198 .f32 => return .f32_type,
33199 .f64 => return .f64_type,
33200 .f80 => return .f80_type,
33201 .f128 => return .f128_type,
33202 .anyopaque => return .anyopaque_type,33227 .anyopaque => return .anyopaque_type,
33203 .bool => return .bool_type,33228 .bool => return .bool_type,
33204 .void => return .void_type,33229 .void => return .void_type,
33205 .type => return .type_type,33230 .type => return .type_type,
33206 .anyerror => return .anyerror_type,33231 .anyerror => return .anyerror_type,
33207 .comptime_int => return .comptime_int_type,33232 .comptime_int => return .comptime_int_type,
33208 .comptime_float => return .comptime_float_type,
33209 .noreturn => return .noreturn_type,33233 .noreturn => return .noreturn_type,
33210 .@"anyframe" => return .anyframe_type,33234 .@"anyframe" => return .anyframe_type,
33211 .null => return .null_type,33235 .null => return .null_type,
...@@ -33595,7 +33619,52 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -33595,7 +33619,52 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33595 .vector_type => @panic("TODO"),33619 .vector_type => @panic("TODO"),
33596 .optional_type => @panic("TODO"),33620 .optional_type => @panic("TODO"),
33597 .error_union_type => @panic("TODO"),33621 .error_union_type => @panic("TODO"),
33598 .simple_type => @panic("TODO"),33622 .simple_type => |t| return switch (t) {
33623 .f16,
33624 .f32,
33625 .f64,
33626 .f80,
33627 .f128,
33628 .usize,
33629 .isize,
33630 .c_char,
33631 .c_short,
33632 .c_ushort,
33633 .c_int,
33634 .c_uint,
33635 .c_long,
33636 .c_ulong,
33637 .c_longlong,
33638 .c_ulonglong,
33639 .c_longdouble,
33640 .anyopaque,
33641 .bool,
33642 .void,
33643 .anyerror,
33644 .@"anyframe",
33645 .noreturn,
33646 .generic_poison,
33647 .atomic_order,
33648 .atomic_rmw_op,
33649 .calling_convention,
33650 .address_space,
33651 .float_mode,
33652 .reduce_op,
33653 .call_modifier,
33654 .prefetch_options,
33655 .export_options,
33656 .extern_options,
33657 => false,
33658
33659 .type,
33660 .comptime_int,
33661 .comptime_float,
33662 .null,
33663 .undefined,
33664 .enum_literal,
33665 .type_info,
33666 => true,
33667 },
33599 .struct_type => @panic("TODO"),33668 .struct_type => @panic("TODO"),
33600 .union_type => @panic("TODO"),33669 .union_type => @panic("TODO"),
33601 .simple_value => unreachable,33670 .simple_value => unreachable,
...@@ -33628,20 +33697,12 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -33628,20 +33697,12 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33628 .c_ulong,33697 .c_ulong,
33629 .c_longlong,33698 .c_longlong,
33630 .c_ulonglong,33699 .c_ulonglong,
33631 .c_longdouble,
33632 .f16,
33633 .f32,
33634 .f64,
33635 .f80,
33636 .f128,
33637 .anyopaque,33700 .anyopaque,
33638 .bool,33701 .bool,
33639 .void,33702 .void,
33640 .anyerror,33703 .anyerror,
33641 .noreturn,33704 .noreturn,
33642 .@"anyframe",33705 .@"anyframe",
33643 .null,
33644 .undefined,
33645 .atomic_order,33706 .atomic_order,
33646 .atomic_rmw_op,33707 .atomic_rmw_op,
33647 .calling_convention,33708 .calling_convention,
...@@ -33674,8 +33735,9 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -33674,8 +33735,9 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33674 .single_const_pointer_to_comptime_int,33735 .single_const_pointer_to_comptime_int,
33675 .type,33736 .type,
33676 .comptime_int,33737 .comptime_int,
33677 .comptime_float,
33678 .enum_literal,33738 .enum_literal,
33739 .null,
33740 .undefined,
33679 .type_info,33741 .type_info,
33680 .function,33742 .function,
33681 => true,33743 => true,
src/arch/wasm/CodeGen.zig+1-1
...@@ -3594,7 +3594,7 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn...@@ -3594,7 +3594,7 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn
3594 const mod = func.bin_file.base.options.module.?;3594 const mod = func.bin_file.base.options.module.?;
3595 // if we bitcast a float to or from an integer we must use the 'reinterpret' instruction3595 // if we bitcast a float to or from an integer we must use the 'reinterpret' instruction
3596 if (!(wanted_ty.isAnyFloat() or given_ty.isAnyFloat())) return operand;3596 if (!(wanted_ty.isAnyFloat() or given_ty.isAnyFloat())) return operand;
3597 if (wanted_ty.tag() == .f16 or given_ty.tag() == .f16) return operand;3597 if (wanted_ty.ip_index == .f16_type or given_ty.ip_index == .f16_type) return operand;
3598 if (wanted_ty.bitSize(mod) > 64) return operand;3598 if (wanted_ty.bitSize(mod) > 64) return operand;
3599 assert((wanted_ty.isInt(mod) and given_ty.isAnyFloat()) or (wanted_ty.isAnyFloat() and given_ty.isInt(mod)));3599 assert((wanted_ty.isInt(mod) and given_ty.isAnyFloat()) or (wanted_ty.isAnyFloat() and given_ty.isInt(mod)));
36003600
src/codegen/c/type.zig+7-7
...@@ -1412,13 +1412,13 @@ pub const CType = extern union {...@@ -1412,13 +1412,13 @@ pub const CType = extern union {
14121412
1413 .Bool => self.init(.bool),1413 .Bool => self.init(.bool),
14141414
1415 .Float => self.init(switch (ty.tag()) {1415 .Float => self.init(switch (ty.ip_index) {
1416 .f16 => .zig_f16,1416 .f16_type => .zig_f16,
1417 .f32 => .zig_f32,1417 .f32_type => .zig_f32,
1418 .f64 => .zig_f64,1418 .f64_type => .zig_f64,
1419 .f80 => .zig_f80,1419 .f80_type => .zig_f80,
1420 .f128 => .zig_f128,1420 .f128_type => .zig_f128,
1421 .c_longdouble => .zig_c_longdouble,1421 .c_longdouble_type => .zig_c_longdouble,
1422 else => unreachable,1422 else => unreachable,
1423 }),1423 }),
14241424
src/codegen/llvm.zig+5-5
...@@ -10932,7 +10932,7 @@ const ParamTypeIterator = struct {...@@ -10932,7 +10932,7 @@ const ParamTypeIterator = struct {
10932 .riscv32, .riscv64 => {10932 .riscv32, .riscv64 => {
10933 it.zig_index += 1;10933 it.zig_index += 1;
10934 it.llvm_index += 1;10934 it.llvm_index += 1;
10935 if (ty.tag() == .f16) {10935 if (ty.ip_index == .f16_type) {
10936 return .as_u16;10936 return .as_u16;
10937 }10937 }
10938 switch (riscv_c_abi.classifyType(ty, mod)) {10938 switch (riscv_c_abi.classifyType(ty, mod)) {
...@@ -11264,10 +11264,10 @@ fn backendSupportsF128(target: std.Target) bool {...@@ -11264,10 +11264,10 @@ fn backendSupportsF128(target: std.Target) bool {
11264/// LLVM does not support all relevant intrinsics for all targets, so we11264/// LLVM does not support all relevant intrinsics for all targets, so we
11265/// may need to manually generate a libc call11265/// may need to manually generate a libc call
11266fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {11266fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {
11267 return switch (scalar_ty.tag()) {11267 return switch (scalar_ty.ip_index) {
11268 .f16 => backendSupportsF16(target),11268 .f16_type => backendSupportsF16(target),
11269 .f80 => (target.c_type_bit_size(.longdouble) == 80) and backendSupportsF80(target),11269 .f80_type => (target.c_type_bit_size(.longdouble) == 80) and backendSupportsF80(target),
11270 .f128 => (target.c_type_bit_size(.longdouble) == 128) and backendSupportsF128(target),11270 .f128_type => (target.c_type_bit_size(.longdouble) == 128) and backendSupportsF128(target),
11271 else => true,11271 else => true,
11272 };11272 };
11273}11273}
src/type.zig+281-196
...@@ -50,6 +50,7 @@ pub const Type = struct {...@@ -50,6 +50,7 @@ pub const Type = struct {
50 .f64,50 .f64,
51 .f80,51 .f80,
52 .f128,52 .f128,
53 .c_longdouble,
53 => return .Float,54 => return .Float,
5455
55 .usize,56 .usize,
...@@ -63,7 +64,6 @@ pub const Type = struct {...@@ -63,7 +64,6 @@ pub const Type = struct {
63 .c_ulong,64 .c_ulong,
64 .c_longlong,65 .c_longlong,
65 .c_ulonglong,66 .c_ulonglong,
66 .c_longdouble,
67 => return .Int,67 => return .Int,
6868
69 .anyopaque => return .Opaque,69 .anyopaque => return .Opaque,
...@@ -134,14 +134,6 @@ pub const Type = struct {...@@ -134,14 +134,6 @@ pub const Type = struct {
134 .c_ulonglong,134 .c_ulonglong,
135 => return .Int,135 => return .Int,
136136
137 .f16,
138 .f32,
139 .f64,
140 .f80,
141 .f128,
142 .c_longdouble,
143 => return .Float,
144
145 .error_set,137 .error_set,
146 .error_set_single,138 .error_set_single,
147 .anyerror,139 .anyerror,
...@@ -154,7 +146,6 @@ pub const Type = struct {...@@ -154,7 +146,6 @@ pub const Type = struct {
154 .void => return .Void,146 .void => return .Void,
155 .type => return .Type,147 .type => return .Type,
156 .comptime_int => return .ComptimeInt,148 .comptime_int => return .ComptimeInt,
157 .comptime_float => return .ComptimeFloat,
158 .noreturn => return .NoReturn,149 .noreturn => return .NoReturn,
159 .null => return .Null,150 .null => return .Null,
160 .undefined => return .Undefined,151 .undefined => return .Undefined,
...@@ -618,10 +609,13 @@ pub const Type = struct {...@@ -618,10 +609,13 @@ pub const Type = struct {
618 }609 }
619610
620 pub fn eql(a: Type, b: Type, mod: *Module) bool {611 pub fn eql(a: Type, b: Type, mod: *Module) bool {
621 // As a shortcut, if the small tags / addresses match, we're done.
622 if (a.ip_index != .none or b.ip_index != .none) {612 if (a.ip_index != .none or b.ip_index != .none) {
613 // The InternPool data structure hashes based on Key to make interned objects
614 // unique. An Index can be treated simply as u32 value for the
615 // purpose of Type/Value hashing and equality.
623 return a.ip_index == b.ip_index;616 return a.ip_index == b.ip_index;
624 }617 }
618 // As a shortcut, if the small tags / addresses match, we're done.
625 if (a.legacy.tag_if_small_enough == b.legacy.tag_if_small_enough) return true;619 if (a.legacy.tag_if_small_enough == b.legacy.tag_if_small_enough) return true;
626620
627 switch (a.tag()) {621 switch (a.tag()) {
...@@ -640,18 +634,10 @@ pub const Type = struct {...@@ -640,18 +634,10 @@ pub const Type = struct {
640 .c_longlong,634 .c_longlong,
641 .c_ulonglong,635 .c_ulonglong,
642636
643 .f16,
644 .f32,
645 .f64,
646 .f80,
647 .f128,
648 .c_longdouble,
649
650 .bool,637 .bool,
651 .void,638 .void,
652 .type,639 .type,
653 .comptime_int,640 .comptime_int,
654 .comptime_float,
655 .noreturn,641 .noreturn,
656 .null,642 .null,
657 .undefined,643 .undefined,
...@@ -1018,7 +1004,11 @@ pub const Type = struct {...@@ -1018,7 +1004,11 @@ pub const Type = struct {
10181004
1019 pub fn hashWithHasher(ty: Type, hasher: *std.hash.Wyhash, mod: *Module) void {1005 pub fn hashWithHasher(ty: Type, hasher: *std.hash.Wyhash, mod: *Module) void {
1020 if (ty.ip_index != .none) {1006 if (ty.ip_index != .none) {
1021 return mod.intern_pool.indexToKey(ty.ip_index).hashWithHasher(hasher);1007 // The InternPool data structure hashes based on Key to make interned objects
1008 // unique. An Index can be treated simply as u32 value for the
1009 // purpose of Type/Value hashing and equality.
1010 std.hash.autoHash(hasher, ty.ip_index);
1011 return;
1022 }1012 }
1023 switch (ty.tag()) {1013 switch (ty.tag()) {
1024 .generic_poison => unreachable,1014 .generic_poison => unreachable,
...@@ -1039,22 +1029,10 @@ pub const Type = struct {...@@ -1039,22 +1029,10 @@ pub const Type = struct {
1039 std.hash.autoHash(hasher, ty_tag);1029 std.hash.autoHash(hasher, ty_tag);
1040 },1030 },
10411031
1042 .f16,
1043 .f32,
1044 .f64,
1045 .f80,
1046 .f128,
1047 .c_longdouble,
1048 => |ty_tag| {
1049 std.hash.autoHash(hasher, std.builtin.TypeId.Float);
1050 std.hash.autoHash(hasher, ty_tag);
1051 },
1052
1053 .bool => std.hash.autoHash(hasher, std.builtin.TypeId.Bool),1032 .bool => std.hash.autoHash(hasher, std.builtin.TypeId.Bool),
1054 .void => std.hash.autoHash(hasher, std.builtin.TypeId.Void),1033 .void => std.hash.autoHash(hasher, std.builtin.TypeId.Void),
1055 .type => std.hash.autoHash(hasher, std.builtin.TypeId.Type),1034 .type => std.hash.autoHash(hasher, std.builtin.TypeId.Type),
1056 .comptime_int => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeInt),1035 .comptime_int => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeInt),
1057 .comptime_float => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeFloat),
1058 .noreturn => std.hash.autoHash(hasher, std.builtin.TypeId.NoReturn),1036 .noreturn => std.hash.autoHash(hasher, std.builtin.TypeId.NoReturn),
1059 .null => std.hash.autoHash(hasher, std.builtin.TypeId.Null),1037 .null => std.hash.autoHash(hasher, std.builtin.TypeId.Null),
1060 .undefined => std.hash.autoHash(hasher, std.builtin.TypeId.Undefined),1038 .undefined => std.hash.autoHash(hasher, std.builtin.TypeId.Undefined),
...@@ -1378,19 +1356,12 @@ pub const Type = struct {...@@ -1378,19 +1356,12 @@ pub const Type = struct {
1378 .c_ulong,1356 .c_ulong,
1379 .c_longlong,1357 .c_longlong,
1380 .c_ulonglong,1358 .c_ulonglong,
1381 .c_longdouble,
1382 .anyopaque,1359 .anyopaque,
1383 .f16,
1384 .f32,
1385 .f64,
1386 .f80,
1387 .f128,
1388 .bool,1360 .bool,
1389 .void,1361 .void,
1390 .type,1362 .type,
1391 .anyerror,1363 .anyerror,
1392 .comptime_int,1364 .comptime_int,
1393 .comptime_float,
1394 .noreturn,1365 .noreturn,
1395 .null,1366 .null,
1396 .undefined,1367 .undefined,
...@@ -1671,20 +1642,13 @@ pub const Type = struct {...@@ -1671,20 +1642,13 @@ pub const Type = struct {
1671 .c_ulong,1642 .c_ulong,
1672 .c_longlong,1643 .c_longlong,
1673 .c_ulonglong,1644 .c_ulonglong,
1674 .c_longdouble,
1675 .anyopaque,1645 .anyopaque,
1676 .f16,
1677 .f32,
1678 .f64,
1679 .f80,
1680 .f128,
1681 .bool,1646 .bool,
1682 .void,1647 .void,
1683 .type,1648 .type,
1684 .anyerror,1649 .anyerror,
1685 .@"anyframe",1650 .@"anyframe",
1686 .comptime_int,1651 .comptime_int,
1687 .comptime_float,
1688 .noreturn,1652 .noreturn,
1689 => return writer.writeAll(@tagName(t)),1653 => return writer.writeAll(@tagName(t)),
16901654
...@@ -2067,20 +2031,13 @@ pub const Type = struct {...@@ -2067,20 +2031,13 @@ pub const Type = struct {
2067 .c_ulong,2031 .c_ulong,
2068 .c_longlong,2032 .c_longlong,
2069 .c_ulonglong,2033 .c_ulonglong,
2070 .c_longdouble,
2071 .anyopaque,2034 .anyopaque,
2072 .f16,
2073 .f32,
2074 .f64,
2075 .f80,
2076 .f128,
2077 .bool,2035 .bool,
2078 .void,2036 .void,
2079 .type,2037 .type,
2080 .anyerror,2038 .anyerror,
2081 .@"anyframe",2039 .@"anyframe",
2082 .comptime_int,2040 .comptime_int,
2083 .comptime_float,
2084 .noreturn,2041 .noreturn,
2085 => try writer.writeAll(@tagName(t)),2042 => try writer.writeAll(@tagName(t)),
20862043
...@@ -2353,6 +2310,7 @@ pub const Type = struct {...@@ -2353,6 +2310,7 @@ pub const Type = struct {
2353 }2310 }
23542311
2355 pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value {2312 pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value {
2313 if (self.ip_index != .none) return self.ip_index.toValue();
2356 switch (self.tag()) {2314 switch (self.tag()) {
2357 .u1 => return Value.initTag(.u1_type),2315 .u1 => return Value.initTag(.u1_type),
2358 .u8 => return Value.initTag(.u8_type),2316 .u8 => return Value.initTag(.u8_type),
...@@ -2375,20 +2333,13 @@ pub const Type = struct {...@@ -2375,20 +2333,13 @@ pub const Type = struct {
2375 .c_ulong => return Value.initTag(.c_ulong_type),2333 .c_ulong => return Value.initTag(.c_ulong_type),
2376 .c_longlong => return Value.initTag(.c_longlong_type),2334 .c_longlong => return Value.initTag(.c_longlong_type),
2377 .c_ulonglong => return Value.initTag(.c_ulonglong_type),2335 .c_ulonglong => return Value.initTag(.c_ulonglong_type),
2378 .c_longdouble => return Value.initTag(.c_longdouble_type),
2379 .anyopaque => return Value.initTag(.anyopaque_type),2336 .anyopaque => return Value.initTag(.anyopaque_type),
2380 .f16 => return Value.initTag(.f16_type),
2381 .f32 => return Value.initTag(.f32_type),
2382 .f64 => return Value.initTag(.f64_type),
2383 .f80 => return Value.initTag(.f80_type),
2384 .f128 => return Value.initTag(.f128_type),
2385 .bool => return Value.initTag(.bool_type),2337 .bool => return Value.initTag(.bool_type),
2386 .void => return Value.initTag(.void_type),2338 .void => return Value.initTag(.void_type),
2387 .type => return Value.initTag(.type_type),2339 .type => return Value.initTag(.type_type),
2388 .anyerror => return Value.initTag(.anyerror_type),2340 .anyerror => return Value.initTag(.anyerror_type),
2389 .@"anyframe" => return Value.initTag(.anyframe_type),2341 .@"anyframe" => return Value.initTag(.anyframe_type),
2390 .comptime_int => return Value.initTag(.comptime_int_type),2342 .comptime_int => return Value.initTag(.comptime_int_type),
2391 .comptime_float => return Value.initTag(.comptime_float_type),
2392 .noreturn => return Value.initTag(.noreturn_type),2343 .noreturn => return Value.initTag(.noreturn_type),
2393 .null => return Value.initTag(.null_type),2344 .null => return Value.initTag(.null_type),
2394 .undefined => return Value.initTag(.undefined_type),2345 .undefined => return Value.initTag(.undefined_type),
...@@ -2522,12 +2473,6 @@ pub const Type = struct {...@@ -2522,12 +2473,6 @@ pub const Type = struct {
2522 .c_ulong,2473 .c_ulong,
2523 .c_longlong,2474 .c_longlong,
2524 .c_ulonglong,2475 .c_ulonglong,
2525 .c_longdouble,
2526 .f16,
2527 .f32,
2528 .f64,
2529 .f80,
2530 .f128,
2531 .bool,2476 .bool,
2532 .anyerror,2477 .anyerror,
2533 .const_slice_u8,2478 .const_slice_u8,
...@@ -2588,7 +2533,6 @@ pub const Type = struct {...@@ -2588,7 +2533,6 @@ pub const Type = struct {
2588 .void,2533 .void,
2589 .type,2534 .type,
2590 .comptime_int,2535 .comptime_int,
2591 .comptime_float,
2592 .noreturn,2536 .noreturn,
2593 .null,2537 .null,
2594 .undefined,2538 .undefined,
...@@ -2801,12 +2745,6 @@ pub const Type = struct {...@@ -2801,12 +2745,6 @@ pub const Type = struct {
2801 .c_ulong,2745 .c_ulong,
2802 .c_longlong,2746 .c_longlong,
2803 .c_ulonglong,2747 .c_ulonglong,
2804 .c_longdouble,
2805 .f16,
2806 .f32,
2807 .f64,
2808 .f80,
2809 .f128,
2810 .bool,2748 .bool,
2811 .void,2749 .void,
2812 .manyptr_u8,2750 .manyptr_u8,
...@@ -2852,7 +2790,6 @@ pub const Type = struct {...@@ -2852,7 +2790,6 @@ pub const Type = struct {
2852 .generic_poison,2790 .generic_poison,
2853 .type,2791 .type,
2854 .comptime_int,2792 .comptime_int,
2855 .comptime_float,
2856 .enum_literal,2793 .enum_literal,
2857 .type_info,2794 .type_info,
2858 // These are function bodies, not function pointers.2795 // These are function bodies, not function pointers.
...@@ -3085,7 +3022,74 @@ pub const Type = struct {...@@ -3085,7 +3022,74 @@ pub const Type = struct {
3085 .vector_type => @panic("TODO"),3022 .vector_type => @panic("TODO"),
3086 .optional_type => @panic("TODO"),3023 .optional_type => @panic("TODO"),
3087 .error_union_type => @panic("TODO"),3024 .error_union_type => @panic("TODO"),
3088 .simple_type => @panic("TODO"),3025 .simple_type => |t| switch (t) {
3026 .bool,
3027 .atomic_order,
3028 .atomic_rmw_op,
3029 .calling_convention,
3030 .address_space,
3031 .float_mode,
3032 .reduce_op,
3033 .call_modifier,
3034 .prefetch_options,
3035 .anyopaque,
3036 => return AbiAlignmentAdvanced{ .scalar = 1 },
3037
3038 .usize,
3039 .isize,
3040 .export_options,
3041 .extern_options,
3042 .@"anyframe",
3043 => return AbiAlignmentAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) },
3044
3045 .c_char => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.char) },
3046 .c_short => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.short) },
3047 .c_ushort => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ushort) },
3048 .c_int => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.int) },
3049 .c_uint => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.uint) },
3050 .c_long => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.long) },
3051 .c_ulong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ulong) },
3052 .c_longlong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longlong) },
3053 .c_ulonglong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ulonglong) },
3054 .c_longdouble => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longdouble) },
3055
3056 .f16 => return AbiAlignmentAdvanced{ .scalar = 2 },
3057 .f32 => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.float) },
3058 .f64 => switch (target.c_type_bit_size(.double)) {
3059 64 => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.double) },
3060 else => return AbiAlignmentAdvanced{ .scalar = 8 },
3061 },
3062 .f80 => switch (target.c_type_bit_size(.longdouble)) {
3063 80 => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longdouble) },
3064 else => {
3065 const u80_ty: Type = .{
3066 .ip_index = .u80_type,
3067 .legacy = undefined,
3068 };
3069 return AbiAlignmentAdvanced{ .scalar = abiAlignment(u80_ty, mod) };
3070 },
3071 },
3072 .f128 => switch (target.c_type_bit_size(.longdouble)) {
3073 128 => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longdouble) },
3074 else => return AbiAlignmentAdvanced{ .scalar = 16 },
3075 },
3076
3077 // TODO revisit this when we have the concept of the error tag type
3078 .anyerror => return AbiAlignmentAdvanced{ .scalar = 2 },
3079
3080 .void,
3081 .type,
3082 .comptime_int,
3083 .comptime_float,
3084 .null,
3085 .undefined,
3086 .enum_literal,
3087 .type_info,
3088 => return AbiAlignmentAdvanced{ .scalar = 0 },
3089
3090 .noreturn => unreachable,
3091 .generic_poison => unreachable,
3092 },
3089 .struct_type => @panic("TODO"),3093 .struct_type => @panic("TODO"),
3090 .union_type => @panic("TODO"),3094 .union_type => @panic("TODO"),
3091 .simple_value => unreachable,3095 .simple_value => unreachable,
...@@ -3158,28 +3162,6 @@ pub const Type = struct {...@@ -3158,28 +3162,6 @@ pub const Type = struct {
3158 .c_ulong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ulong) },3162 .c_ulong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ulong) },
3159 .c_longlong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longlong) },3163 .c_longlong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longlong) },
3160 .c_ulonglong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ulonglong) },3164 .c_ulonglong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ulonglong) },
3161 .c_longdouble => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longdouble) },
3162
3163 .f16 => return AbiAlignmentAdvanced{ .scalar = 2 },
3164 .f32 => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.float) },
3165 .f64 => switch (target.c_type_bit_size(.double)) {
3166 64 => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.double) },
3167 else => return AbiAlignmentAdvanced{ .scalar = 8 },
3168 },
3169 .f80 => switch (target.c_type_bit_size(.longdouble)) {
3170 80 => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longdouble) },
3171 else => {
3172 const u80_ty: Type = .{
3173 .ip_index = .u80_type,
3174 .legacy = undefined,
3175 };
3176 return AbiAlignmentAdvanced{ .scalar = abiAlignment(u80_ty, mod) };
3177 },
3178 },
3179 .f128 => switch (target.c_type_bit_size(.longdouble)) {
3180 128 => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longdouble) },
3181 else => return AbiAlignmentAdvanced{ .scalar = 16 },
3182 },
31833165
3184 // TODO revisit this when we have the concept of the error tag type3166 // TODO revisit this when we have the concept of the error tag type
3185 .anyerror_void_error_union,3167 .anyerror_void_error_union,
...@@ -3366,7 +3348,6 @@ pub const Type = struct {...@@ -3366,7 +3348,6 @@ pub const Type = struct {
3366 .empty_struct_literal,3348 .empty_struct_literal,
3367 .type,3349 .type,
3368 .comptime_int,3350 .comptime_int,
3369 .comptime_float,
3370 .null,3351 .null,
3371 .undefined,3352 .undefined,
3372 .enum_literal,3353 .enum_literal,
...@@ -3481,7 +3462,69 @@ pub const Type = struct {...@@ -3481,7 +3462,69 @@ pub const Type = struct {
3481 .vector_type => @panic("TODO"),3462 .vector_type => @panic("TODO"),
3482 .optional_type => @panic("TODO"),3463 .optional_type => @panic("TODO"),
3483 .error_union_type => @panic("TODO"),3464 .error_union_type => @panic("TODO"),
3484 .simple_type => @panic("TODO"),3465 .simple_type => |t| switch (t) {
3466 .bool,
3467 .atomic_order,
3468 .atomic_rmw_op,
3469 .calling_convention,
3470 .address_space,
3471 .float_mode,
3472 .reduce_op,
3473 .call_modifier,
3474 => return AbiSizeAdvanced{ .scalar = 1 },
3475
3476 .f16 => return AbiSizeAdvanced{ .scalar = 2 },
3477 .f32 => return AbiSizeAdvanced{ .scalar = 4 },
3478 .f64 => return AbiSizeAdvanced{ .scalar = 8 },
3479 .f128 => return AbiSizeAdvanced{ .scalar = 16 },
3480 .f80 => switch (target.c_type_bit_size(.longdouble)) {
3481 80 => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longdouble) },
3482 else => {
3483 const u80_ty: Type = .{
3484 .ip_index = .u80_type,
3485 .legacy = undefined,
3486 };
3487 return AbiSizeAdvanced{ .scalar = abiSize(u80_ty, mod) };
3488 },
3489 },
3490
3491 .usize,
3492 .isize,
3493 .@"anyframe",
3494 => return AbiSizeAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) },
3495
3496 .c_char => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.char) },
3497 .c_short => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.short) },
3498 .c_ushort => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ushort) },
3499 .c_int => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.int) },
3500 .c_uint => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.uint) },
3501 .c_long => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.long) },
3502 .c_ulong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ulong) },
3503 .c_longlong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longlong) },
3504 .c_ulonglong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ulonglong) },
3505 .c_longdouble => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longdouble) },
3506
3507 .anyopaque,
3508 .void,
3509 .type,
3510 .comptime_int,
3511 .comptime_float,
3512 .null,
3513 .undefined,
3514 .enum_literal,
3515 => return AbiSizeAdvanced{ .scalar = 0 },
3516
3517 // TODO revisit this when we have the concept of the error tag type
3518 .anyerror => return AbiSizeAdvanced{ .scalar = 2 },
3519
3520 .prefetch_options => unreachable, // missing call to resolveTypeFields
3521 .export_options => unreachable, // missing call to resolveTypeFields
3522 .extern_options => unreachable, // missing call to resolveTypeFields
3523
3524 .type_info => unreachable,
3525 .noreturn => unreachable,
3526 .generic_poison => unreachable,
3527 },
3485 .struct_type => @panic("TODO"),3528 .struct_type => @panic("TODO"),
3486 .union_type => @panic("TODO"),3529 .union_type => @panic("TODO"),
3487 .simple_value => unreachable,3530 .simple_value => unreachable,
...@@ -3506,7 +3549,6 @@ pub const Type = struct {...@@ -3506,7 +3549,6 @@ pub const Type = struct {
3506 .anyopaque,3549 .anyopaque,
3507 .type,3550 .type,
3508 .comptime_int,3551 .comptime_int,
3509 .comptime_float,
3510 .null,3552 .null,
3511 .undefined,3553 .undefined,
3512 .enum_literal,3554 .enum_literal,
...@@ -3661,22 +3703,6 @@ pub const Type = struct {...@@ -3661,22 +3703,6 @@ pub const Type = struct {
3661 .c_ulong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ulong) },3703 .c_ulong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ulong) },
3662 .c_longlong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longlong) },3704 .c_longlong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longlong) },
3663 .c_ulonglong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ulonglong) },3705 .c_ulonglong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ulonglong) },
3664 .c_longdouble => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longdouble) },
3665
3666 .f16 => return AbiSizeAdvanced{ .scalar = 2 },
3667 .f32 => return AbiSizeAdvanced{ .scalar = 4 },
3668 .f64 => return AbiSizeAdvanced{ .scalar = 8 },
3669 .f128 => return AbiSizeAdvanced{ .scalar = 16 },
3670 .f80 => switch (target.c_type_bit_size(.longdouble)) {
3671 80 => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longdouble) },
3672 else => {
3673 const u80_ty: Type = .{
3674 .ip_index = .u80_type,
3675 .legacy = undefined,
3676 };
3677 return AbiSizeAdvanced{ .scalar = abiSize(u80_ty, mod) };
3678 },
3679 },
36803706
3681 // TODO revisit this when we have the concept of the error tag type3707 // TODO revisit this when we have the concept of the error tag type
3682 .anyerror_void_error_union,3708 .anyerror_void_error_union,
...@@ -3820,7 +3846,57 @@ pub const Type = struct {...@@ -3820,7 +3846,57 @@ pub const Type = struct {
3820 .vector_type => @panic("TODO"),3846 .vector_type => @panic("TODO"),
3821 .optional_type => @panic("TODO"),3847 .optional_type => @panic("TODO"),
3822 .error_union_type => @panic("TODO"),3848 .error_union_type => @panic("TODO"),
3823 .simple_type => @panic("TODO"),3849 .simple_type => |t| switch (t) {
3850 .f16 => return 16,
3851 .f32 => return 32,
3852 .f64 => return 64,
3853 .f80 => return 80,
3854 .f128 => return 128,
3855
3856 .usize,
3857 .isize,
3858 .@"anyframe",
3859 => return target.cpu.arch.ptrBitWidth(),
3860
3861 .c_char => return target.c_type_bit_size(.char),
3862 .c_short => return target.c_type_bit_size(.short),
3863 .c_ushort => return target.c_type_bit_size(.ushort),
3864 .c_int => return target.c_type_bit_size(.int),
3865 .c_uint => return target.c_type_bit_size(.uint),
3866 .c_long => return target.c_type_bit_size(.long),
3867 .c_ulong => return target.c_type_bit_size(.ulong),
3868 .c_longlong => return target.c_type_bit_size(.longlong),
3869 .c_ulonglong => return target.c_type_bit_size(.ulonglong),
3870 .c_longdouble => return target.c_type_bit_size(.longdouble),
3871
3872 .bool => return 1,
3873 .void => return 0,
3874
3875 // TODO revisit this when we have the concept of the error tag type
3876 .anyerror => return 16,
3877
3878 .anyopaque => unreachable,
3879 .type => unreachable,
3880 .comptime_int => unreachable,
3881 .comptime_float => unreachable,
3882 .noreturn => unreachable,
3883 .null => unreachable,
3884 .undefined => unreachable,
3885 .enum_literal => unreachable,
3886 .generic_poison => unreachable,
3887
3888 .atomic_order => unreachable, // missing call to resolveTypeFields
3889 .atomic_rmw_op => unreachable, // missing call to resolveTypeFields
3890 .calling_convention => unreachable, // missing call to resolveTypeFields
3891 .address_space => unreachable, // missing call to resolveTypeFields
3892 .float_mode => unreachable, // missing call to resolveTypeFields
3893 .reduce_op => unreachable, // missing call to resolveTypeFields
3894 .call_modifier => unreachable, // missing call to resolveTypeFields
3895 .prefetch_options => unreachable, // missing call to resolveTypeFields
3896 .export_options => unreachable, // missing call to resolveTypeFields
3897 .extern_options => unreachable, // missing call to resolveTypeFields
3898 .type_info => unreachable, // missing call to resolveTypeFields
3899 },
3824 .struct_type => @panic("TODO"),3900 .struct_type => @panic("TODO"),
3825 .union_type => @panic("TODO"),3901 .union_type => @panic("TODO"),
3826 .simple_value => unreachable,3902 .simple_value => unreachable,
...@@ -3836,7 +3912,6 @@ pub const Type = struct {...@@ -3836,7 +3912,6 @@ pub const Type = struct {
3836 .anyopaque => unreachable,3912 .anyopaque => unreachable,
3837 .type => unreachable,3913 .type => unreachable,
3838 .comptime_int => unreachable,3914 .comptime_int => unreachable,
3839 .comptime_float => unreachable,
3840 .noreturn => unreachable,3915 .noreturn => unreachable,
3841 .null => unreachable,3916 .null => unreachable,
3842 .undefined => unreachable,3917 .undefined => unreachable,
...@@ -3852,12 +3927,11 @@ pub const Type = struct {...@@ -3852,12 +3927,11 @@ pub const Type = struct {
3852 .void => return 0,3927 .void => return 0,
3853 .bool, .u1 => return 1,3928 .bool, .u1 => return 1,
3854 .u8, .i8 => return 8,3929 .u8, .i8 => return 8,
3855 .i16, .u16, .f16 => return 16,3930 .i16, .u16 => return 16,
3856 .u29 => return 29,3931 .u29 => return 29,
3857 .i32, .u32, .f32 => return 32,3932 .i32, .u32 => return 32,
3858 .i64, .u64, .f64 => return 64,3933 .i64, .u64 => return 64,
3859 .f80 => return 80,3934 .u128, .i128 => return 128,
3860 .u128, .i128, .f128 => return 128,
38613935
3862 .@"struct" => {3936 .@"struct" => {
3863 const struct_obj = ty.castTag(.@"struct").?.data;3937 const struct_obj = ty.castTag(.@"struct").?.data;
...@@ -3975,7 +4049,6 @@ pub const Type = struct {...@@ -3975,7 +4049,6 @@ pub const Type = struct {
3975 .c_ulong => return target.c_type_bit_size(.ulong),4049 .c_ulong => return target.c_type_bit_size(.ulong),
3976 .c_longlong => return target.c_type_bit_size(.longlong),4050 .c_longlong => return target.c_type_bit_size(.longlong),
3977 .c_ulonglong => return target.c_type_bit_size(.ulonglong),4051 .c_ulonglong => return target.c_type_bit_size(.ulonglong),
3978 .c_longdouble => return target.c_type_bit_size(.longdouble),
39794052
3980 .error_set,4053 .error_set,
3981 .error_set_single,4054 .error_set_single,
...@@ -4950,14 +5023,14 @@ pub const Type = struct {...@@ -4950,14 +5023,14 @@ pub const Type = struct {
4950 }5023 }
49515024
4952 /// Returns `false` for `comptime_float`.5025 /// Returns `false` for `comptime_float`.
4953 pub fn isRuntimeFloat(self: Type) bool {5026 pub fn isRuntimeFloat(ty: Type) bool {
4954 return switch (self.tag()) {5027 return switch (ty.ip_index) {
4955 .f16,5028 .f16_type,
4956 .f32,5029 .f32_type,
4957 .f64,5030 .f64_type,
4958 .f80,5031 .f80_type,
4959 .f128,5032 .f128_type,
4960 .c_longdouble,5033 .c_longdouble_type,
4961 => true,5034 => true,
49625035
4963 else => false,5036 else => false,
...@@ -4965,15 +5038,15 @@ pub const Type = struct {...@@ -4965,15 +5038,15 @@ pub const Type = struct {
4965 }5038 }
49665039
4967 /// Returns `true` for `comptime_float`.5040 /// Returns `true` for `comptime_float`.
4968 pub fn isAnyFloat(self: Type) bool {5041 pub fn isAnyFloat(ty: Type) bool {
4969 return switch (self.tag()) {5042 return switch (ty.ip_index) {
4970 .f16,5043 .f16_type,
4971 .f32,5044 .f32_type,
4972 .f64,5045 .f64_type,
4973 .f80,5046 .f80_type,
4974 .f128,5047 .f128_type,
4975 .c_longdouble,5048 .c_longdouble_type,
4976 .comptime_float,5049 .comptime_float_type,
4977 => true,5050 => true,
49785051
4979 else => false,5052 else => false,
...@@ -4982,14 +5055,14 @@ pub const Type = struct {...@@ -4982,14 +5055,14 @@ pub const Type = struct {
49825055
4983 /// Asserts the type is a fixed-size float or comptime_float.5056 /// Asserts the type is a fixed-size float or comptime_float.
4984 /// Returns 128 for comptime_float types.5057 /// Returns 128 for comptime_float types.
4985 pub fn floatBits(self: Type, target: Target) u16 {5058 pub fn floatBits(ty: Type, target: Target) u16 {
4986 return switch (self.tag()) {5059 return switch (ty.ip_index) {
4987 .f16 => 16,5060 .f16_type => 16,
4988 .f32 => 32,5061 .f32_type => 32,
4989 .f64 => 64,5062 .f64_type => 64,
4990 .f80 => 80,5063 .f80_type => 80,
4991 .f128, .comptime_float => 128,5064 .f128_type, .comptime_float_type => 128,
4992 .c_longdouble => target.c_type_bit_size(.longdouble),5065 .c_longdouble_type => target.c_type_bit_size(.longdouble),
49935066
4994 else => unreachable,5067 else => unreachable,
4995 };5068 };
...@@ -5094,14 +5167,7 @@ pub const Type = struct {...@@ -5094,14 +5167,7 @@ pub const Type = struct {
5094 else => false,5167 else => false,
5095 };5168 };
5096 return switch (ty.tag()) {5169 return switch (ty.tag()) {
5097 .f16,
5098 .f32,
5099 .f64,
5100 .f80,
5101 .f128,
5102 .c_longdouble,
5103 .comptime_int,5170 .comptime_int,
5104 .comptime_float,
5105 .u1,5171 .u1,
5106 .u8,5172 .u8,
5107 .i8,5173 .i8,
...@@ -5205,14 +5271,7 @@ pub const Type = struct {...@@ -5205,14 +5271,7 @@ pub const Type = struct {
5205 };5271 };
52065272
5207 while (true) switch (ty.tag()) {5273 while (true) switch (ty.tag()) {
5208 .f16,
5209 .f32,
5210 .f64,
5211 .f80,
5212 .f128,
5213 .c_longdouble,
5214 .comptime_int,5274 .comptime_int,
5215 .comptime_float,
5216 .u1,5275 .u1,
5217 .u8,5276 .u8,
5218 .i8,5277 .i8,
...@@ -5391,14 +5450,59 @@ pub const Type = struct {...@@ -5391,14 +5450,59 @@ pub const Type = struct {
5391 /// TODO merge these implementations together with the "advanced" pattern seen5450 /// TODO merge these implementations together with the "advanced" pattern seen
5392 /// elsewhere in this file.5451 /// elsewhere in this file.
5393 pub fn comptimeOnly(ty: Type, mod: *const Module) bool {5452 pub fn comptimeOnly(ty: Type, mod: *const Module) bool {
5394 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {5453 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
5395 .int_type => return false,5454 .int_type => false,
5396 .ptr_type => @panic("TODO"),5455 .ptr_type => @panic("TODO"),
5397 .array_type => @panic("TODO"),5456 .array_type => @panic("TODO"),
5398 .vector_type => @panic("TODO"),5457 .vector_type => @panic("TODO"),
5399 .optional_type => @panic("TODO"),5458 .optional_type => @panic("TODO"),
5400 .error_union_type => @panic("TODO"),5459 .error_union_type => @panic("TODO"),
5401 .simple_type => @panic("TODO"),5460 .simple_type => |t| switch (t) {
5461 .f16,
5462 .f32,
5463 .f64,
5464 .f80,
5465 .f128,
5466 .usize,
5467 .isize,
5468 .c_char,
5469 .c_short,
5470 .c_ushort,
5471 .c_int,
5472 .c_uint,
5473 .c_long,
5474 .c_ulong,
5475 .c_longlong,
5476 .c_ulonglong,
5477 .c_longdouble,
5478 .anyopaque,
5479 .bool,
5480 .void,
5481 .anyerror,
5482 .@"anyframe",
5483 .noreturn,
5484 .generic_poison,
5485 .atomic_order,
5486 .atomic_rmw_op,
5487 .calling_convention,
5488 .address_space,
5489 .float_mode,
5490 .reduce_op,
5491 .call_modifier,
5492 .prefetch_options,
5493 .export_options,
5494 .extern_options,
5495 => false,
5496
5497 .type,
5498 .comptime_int,
5499 .comptime_float,
5500 .null,
5501 .undefined,
5502 .enum_literal,
5503 .type_info,
5504 => true,
5505 },
5402 .struct_type => @panic("TODO"),5506 .struct_type => @panic("TODO"),
5403 .union_type => @panic("TODO"),5507 .union_type => @panic("TODO"),
5404 .simple_value => unreachable,5508 .simple_value => unreachable,
...@@ -5431,20 +5535,12 @@ pub const Type = struct {...@@ -5431,20 +5535,12 @@ pub const Type = struct {
5431 .c_ulong,5535 .c_ulong,
5432 .c_longlong,5536 .c_longlong,
5433 .c_ulonglong,5537 .c_ulonglong,
5434 .c_longdouble,
5435 .f16,
5436 .f32,
5437 .f64,
5438 .f80,
5439 .f128,
5440 .anyopaque,5538 .anyopaque,
5441 .bool,5539 .bool,
5442 .void,5540 .void,
5443 .anyerror,5541 .anyerror,
5444 .noreturn,5542 .noreturn,
5445 .@"anyframe",5543 .@"anyframe",
5446 .null,
5447 .undefined,
5448 .atomic_order,5544 .atomic_order,
5449 .atomic_rmw_op,5545 .atomic_rmw_op,
5450 .calling_convention,5546 .calling_convention,
...@@ -5477,11 +5573,12 @@ pub const Type = struct {...@@ -5477,11 +5573,12 @@ pub const Type = struct {
5477 .single_const_pointer_to_comptime_int,5573 .single_const_pointer_to_comptime_int,
5478 .type,5574 .type,
5479 .comptime_int,5575 .comptime_int,
5480 .comptime_float,
5481 .enum_literal,5576 .enum_literal,
5482 .type_info,5577 .type_info,
5483 // These are function bodies, not function pointers.5578 // These are function bodies, not function pointers.
5484 .function,5579 .function,
5580 .null,
5581 .undefined,
5485 => true,5582 => true,
54865583
5487 .inferred_alloc_mut => unreachable,5584 .inferred_alloc_mut => unreachable,
...@@ -6286,19 +6383,12 @@ pub const Type = struct {...@@ -6286,19 +6383,12 @@ pub const Type = struct {
6286 c_ulong,6383 c_ulong,
6287 c_longlong,6384 c_longlong,
6288 c_ulonglong,6385 c_ulonglong,
6289 c_longdouble,
6290 f16,
6291 f32,
6292 f64,
6293 f80,
6294 f128,
6295 anyopaque,6386 anyopaque,
6296 bool,6387 bool,
6297 void,6388 void,
6298 type,6389 type,
6299 anyerror,6390 anyerror,
6300 comptime_int,6391 comptime_int,
6301 comptime_float,
6302 noreturn,6392 noreturn,
6303 @"anyframe",6393 @"anyframe",
6304 null,6394 null,
...@@ -6377,7 +6467,6 @@ pub const Type = struct {...@@ -6377,7 +6467,6 @@ pub const Type = struct {
6377 pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;6467 pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;
63786468
6379 pub fn Type(comptime t: Tag) type {6469 pub fn Type(comptime t: Tag) type {
6380 // Keep in sync with tools/stage2_pretty_printers_common.py
6381 return switch (t) {6470 return switch (t) {
6382 .u1,6471 .u1,
6383 .u8,6472 .u8,
...@@ -6402,19 +6491,12 @@ pub const Type = struct {...@@ -6402,19 +6491,12 @@ pub const Type = struct {
6402 .c_ulong,6491 .c_ulong,
6403 .c_longlong,6492 .c_longlong,
6404 .c_ulonglong,6493 .c_ulonglong,
6405 .c_longdouble,
6406 .f16,
6407 .f32,
6408 .f64,
6409 .f80,
6410 .f128,
6411 .anyopaque,6494 .anyopaque,
6412 .bool,6495 .bool,
6413 .void,6496 .void,
6414 .type,6497 .type,
6415 .anyerror,6498 .anyerror,
6416 .comptime_int,6499 .comptime_int,
6417 .comptime_float,
6418 .noreturn,6500 .noreturn,
6419 .enum_literal,6501 .enum_literal,
6420 .null,6502 .null,
...@@ -6781,16 +6863,17 @@ pub const Type = struct {...@@ -6781,16 +6863,17 @@ pub const Type = struct {
6781 pub const @"i32" = initTag(.i32);6863 pub const @"i32" = initTag(.i32);
6782 pub const @"i64" = initTag(.i64);6864 pub const @"i64" = initTag(.i64);
67836865
6784 pub const @"f16" = initTag(.f16);6866 pub const @"f16": Type = .{ .ip_index = .f16_type, .legacy = undefined };
6785 pub const @"f32" = initTag(.f32);6867 pub const @"f32": Type = .{ .ip_index = .f32_type, .legacy = undefined };
6786 pub const @"f64" = initTag(.f64);6868 pub const @"f64": Type = .{ .ip_index = .f64_type, .legacy = undefined };
6787 pub const @"f80" = initTag(.f80);6869 pub const @"f80": Type = .{ .ip_index = .f80_type, .legacy = undefined };
6788 pub const @"f128" = initTag(.f128);6870 pub const @"f128": Type = .{ .ip_index = .f128_type, .legacy = undefined };
67896871
6790 pub const @"bool" = initTag(.bool);6872 pub const @"bool" = initTag(.bool);
6791 pub const @"usize" = initTag(.usize);6873 pub const @"usize" = initTag(.usize);
6792 pub const @"isize" = initTag(.isize);6874 pub const @"isize" = initTag(.isize);
6793 pub const @"comptime_int" = initTag(.comptime_int);6875 pub const @"comptime_int": Type = .{ .ip_index = .comptime_int_type, .legacy = undefined };
6876 pub const @"comptime_float": Type = .{ .ip_index = .comptime_float_type, .legacy = undefined };
6794 pub const @"void" = initTag(.void);6877 pub const @"void" = initTag(.void);
6795 pub const @"type" = initTag(.type);6878 pub const @"type" = initTag(.type);
6796 pub const @"anyerror" = initTag(.anyerror);6879 pub const @"anyerror" = initTag(.anyerror);
...@@ -6798,6 +6881,8 @@ pub const Type = struct {...@@ -6798,6 +6881,8 @@ pub const Type = struct {
6798 pub const @"null" = initTag(.null);6881 pub const @"null" = initTag(.null);
6799 pub const @"noreturn" = initTag(.noreturn);6882 pub const @"noreturn" = initTag(.noreturn);
68006883
6884 pub const @"c_longdouble": Type = .{ .ip_index = .c_longdouble_type, .legacy = undefined };
6885
6801 pub const err_int = Type.u16;6886 pub const err_int = Type.u16;
68026887
6803 pub fn ptr(arena: Allocator, mod: *Module, data: Payload.Pointer.Data) !Type {6888 pub fn ptr(arena: Allocator, mod: *Module, data: Payload.Pointer.Data) !Type {
src/value.zig+7-7
...@@ -974,19 +974,19 @@ pub const Value = struct {...@@ -974,19 +974,19 @@ pub const Value = struct {
974 .c_ulong_type => Type.initTag(.c_ulong),974 .c_ulong_type => Type.initTag(.c_ulong),
975 .c_longlong_type => Type.initTag(.c_longlong),975 .c_longlong_type => Type.initTag(.c_longlong),
976 .c_ulonglong_type => Type.initTag(.c_ulonglong),976 .c_ulonglong_type => Type.initTag(.c_ulonglong),
977 .c_longdouble_type => Type.initTag(.c_longdouble),977 .c_longdouble_type => Type.c_longdouble,
978 .f16_type => Type.initTag(.f16),978 .f16_type => Type.f16,
979 .f32_type => Type.initTag(.f32),979 .f32_type => Type.f32,
980 .f64_type => Type.initTag(.f64),980 .f64_type => Type.f64,
981 .f80_type => Type.initTag(.f80),981 .f80_type => Type.f80,
982 .f128_type => Type.initTag(.f128),982 .f128_type => Type.f128,
983 .anyopaque_type => Type.initTag(.anyopaque),983 .anyopaque_type => Type.initTag(.anyopaque),
984 .bool_type => Type.initTag(.bool),984 .bool_type => Type.initTag(.bool),
985 .void_type => Type.initTag(.void),985 .void_type => Type.initTag(.void),
986 .type_type => Type.initTag(.type),986 .type_type => Type.initTag(.type),
987 .anyerror_type => Type.initTag(.anyerror),987 .anyerror_type => Type.initTag(.anyerror),
988 .comptime_int_type => Type.initTag(.comptime_int),988 .comptime_int_type => Type.initTag(.comptime_int),
989 .comptime_float_type => Type.initTag(.comptime_float),989 .comptime_float_type => Type.comptime_float,
990 .noreturn_type => Type.initTag(.noreturn),990 .noreturn_type => Type.initTag(.noreturn),
991 .null_type => Type.initTag(.null),991 .null_type => Type.initTag(.null),
992 .undefined_type => Type.initTag(.undefined),992 .undefined_type => Type.initTag(.undefined),