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
51385138 defer tracy.end();
51395139
51405140 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);
51425142}
51435143
51445144fn 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.
51545154 @memcpy(mem.sliceAsBytes(limbs), limb_bytes);
51555155
51565156 return sema.addConstant(
5157 Type.initTag(.comptime_int),
5157 Type.comptime_int,
51585158 try Value.Tag.int_big_positive.create(arena, limbs),
51595159 );
51605160}
......@@ -5164,7 +5164,7 @@ fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
51645164 const arena = sema.arena;
51655165 const number = sema.code.instructions.items(.data)[inst].float;
51665166 return sema.addConstant(
5167 Type.initTag(.comptime_float),
5167 Type.comptime_float,
51685168 try Value.Tag.float_64.create(arena, number),
51695169 );
51705170}
......@@ -5176,7 +5176,7 @@ fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
51765176 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
51775177 const number = extra.get();
51785178 return sema.addConstant(
5179 Type.initTag(.comptime_float),
5179 Type.comptime_float,
51805180 try Value.Tag.float_128.create(arena, number),
51815181 );
51825182}
......@@ -15152,8 +15152,8 @@ fn zirAsm(
1515215152 const uncasted_arg = try sema.resolveInst(input.data.operand);
1515315153 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
1515415154 switch (uncasted_arg_ty.zigTypeTag(mod)) {
15155 .ComptimeInt => arg.* = try sema.coerce(block, Type.initTag(.usize), uncasted_arg, src),
15156 .ComptimeFloat => arg.* = try sema.coerce(block, Type.initTag(.f64), uncasted_arg, src),
15155 .ComptimeInt => arg.* = try sema.coerce(block, Type.usize, uncasted_arg, src),
15156 .ComptimeFloat => arg.* = try sema.coerce(block, Type.f64, uncasted_arg, src),
1515715157 else => {
1515815158 arg.* = uncasted_arg;
1515915159 try sema.queueFullTypeResolution(uncasted_arg_ty);
......@@ -31369,14 +31369,59 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3136931369pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3137031370 const mod = sema.mod;
3137131371
31372 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
31373 .int_type => return false,
31372 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
31373 .int_type => false,
3137431374 .ptr_type => @panic("TODO"),
3137531375 .array_type => @panic("TODO"),
3137631376 .vector_type => @panic("TODO"),
3137731377 .optional_type => @panic("TODO"),
3137831378 .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 },
3138031425 .struct_type => @panic("TODO"),
3138131426 .union_type => @panic("TODO"),
3138231427 .simple_value => unreachable,
......@@ -31409,12 +31454,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3140931454 .c_ulong,
3141031455 .c_longlong,
3141131456 .c_ulonglong,
31412 .c_longdouble,
31413 .f16,
31414 .f32,
31415 .f64,
31416 .f80,
31417 .f128,
3141831457 .anyopaque,
3141931458 .bool,
3142031459 .void,
......@@ -31455,7 +31494,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3145531494 .single_const_pointer_to_comptime_int,
3145631495 .type,
3145731496 .comptime_int,
31458 .comptime_float,
3145931497 .enum_literal,
3146031498 .type_info,
3146131499 .function,
......@@ -32926,14 +32964,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3292632964 };
3292732965
3292832966 switch (ty.tag()) {
32929 .f16,
32930 .f32,
32931 .f64,
32932 .f80,
32933 .f128,
32934 .c_longdouble,
3293532967 .comptime_int,
32936 .comptime_float,
3293732968 .u1,
3293832969 .u8,
3293932970 .i8,
......@@ -33193,19 +33224,12 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
3319333224 .c_ulong => return .c_ulong_type,
3319433225 .c_longlong => return .c_longlong_type,
3319533226 .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,
3320233227 .anyopaque => return .anyopaque_type,
3320333228 .bool => return .bool_type,
3320433229 .void => return .void_type,
3320533230 .type => return .type_type,
3320633231 .anyerror => return .anyerror_type,
3320733232 .comptime_int => return .comptime_int_type,
33208 .comptime_float => return .comptime_float_type,
3320933233 .noreturn => return .noreturn_type,
3321033234 .@"anyframe" => return .anyframe_type,
3321133235 .null => return .null_type,
......@@ -33595,7 +33619,52 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3359533619 .vector_type => @panic("TODO"),
3359633620 .optional_type => @panic("TODO"),
3359733621 .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 },
3359933668 .struct_type => @panic("TODO"),
3360033669 .union_type => @panic("TODO"),
3360133670 .simple_value => unreachable,
......@@ -33628,20 +33697,12 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3362833697 .c_ulong,
3362933698 .c_longlong,
3363033699 .c_ulonglong,
33631 .c_longdouble,
33632 .f16,
33633 .f32,
33634 .f64,
33635 .f80,
33636 .f128,
3363733700 .anyopaque,
3363833701 .bool,
3363933702 .void,
3364033703 .anyerror,
3364133704 .noreturn,
3364233705 .@"anyframe",
33643 .null,
33644 .undefined,
3364533706 .atomic_order,
3364633707 .atomic_rmw_op,
3364733708 .calling_convention,
......@@ -33674,8 +33735,9 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3367433735 .single_const_pointer_to_comptime_int,
3367533736 .type,
3367633737 .comptime_int,
33677 .comptime_float,
3367833738 .enum_literal,
33739 .null,
33740 .undefined,
3367933741 .type_info,
3368033742 .function,
3368133743 => 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
35943594 const mod = func.bin_file.base.options.module.?;
35953595 // if we bitcast a float to or from an integer we must use the 'reinterpret' instruction
35963596 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;
35983598 if (wanted_ty.bitSize(mod) > 64) return operand;
35993599 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 {
14121412
14131413 .Bool => self.init(.bool),
14141414
1415 .Float => self.init(switch (ty.tag()) {
1416 .f16 => .zig_f16,
1417 .f32 => .zig_f32,
1418 .f64 => .zig_f64,
1419 .f80 => .zig_f80,
1420 .f128 => .zig_f128,
1421 .c_longdouble => .zig_c_longdouble,
1415 .Float => self.init(switch (ty.ip_index) {
1416 .f16_type => .zig_f16,
1417 .f32_type => .zig_f32,
1418 .f64_type => .zig_f64,
1419 .f80_type => .zig_f80,
1420 .f128_type => .zig_f128,
1421 .c_longdouble_type => .zig_c_longdouble,
14221422 else => unreachable,
14231423 }),
14241424
src/codegen/llvm.zig+5-5
......@@ -10932,7 +10932,7 @@ const ParamTypeIterator = struct {
1093210932 .riscv32, .riscv64 => {
1093310933 it.zig_index += 1;
1093410934 it.llvm_index += 1;
10935 if (ty.tag() == .f16) {
10935 if (ty.ip_index == .f16_type) {
1093610936 return .as_u16;
1093710937 }
1093810938 switch (riscv_c_abi.classifyType(ty, mod)) {
......@@ -11264,10 +11264,10 @@ fn backendSupportsF128(target: std.Target) bool {
1126411264/// LLVM does not support all relevant intrinsics for all targets, so we
1126511265/// may need to manually generate a libc call
1126611266fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {
11267 return switch (scalar_ty.tag()) {
11268 .f16 => backendSupportsF16(target),
11269 .f80 => (target.c_type_bit_size(.longdouble) == 80) and backendSupportsF80(target),
11270 .f128 => (target.c_type_bit_size(.longdouble) == 128) and backendSupportsF128(target),
11267 return switch (scalar_ty.ip_index) {
11268 .f16_type => backendSupportsF16(target),
11269 .f80_type => (target.c_type_bit_size(.longdouble) == 80) and backendSupportsF80(target),
11270 .f128_type => (target.c_type_bit_size(.longdouble) == 128) and backendSupportsF128(target),
1127111271 else => true,
1127211272 };
1127311273}
src/type.zig+281-196
......@@ -50,6 +50,7 @@ pub const Type = struct {
5050 .f64,
5151 .f80,
5252 .f128,
53 .c_longdouble,
5354 => return .Float,
5455
5556 .usize,
......@@ -63,7 +64,6 @@ pub const Type = struct {
6364 .c_ulong,
6465 .c_longlong,
6566 .c_ulonglong,
66 .c_longdouble,
6767 => return .Int,
6868
6969 .anyopaque => return .Opaque,
......@@ -134,14 +134,6 @@ pub const Type = struct {
134134 .c_ulonglong,
135135 => return .Int,
136136
137 .f16,
138 .f32,
139 .f64,
140 .f80,
141 .f128,
142 .c_longdouble,
143 => return .Float,
144
145137 .error_set,
146138 .error_set_single,
147139 .anyerror,
......@@ -154,7 +146,6 @@ pub const Type = struct {
154146 .void => return .Void,
155147 .type => return .Type,
156148 .comptime_int => return .ComptimeInt,
157 .comptime_float => return .ComptimeFloat,
158149 .noreturn => return .NoReturn,
159150 .null => return .Null,
160151 .undefined => return .Undefined,
......@@ -618,10 +609,13 @@ pub const Type = struct {
618609 }
619610
620611 pub fn eql(a: Type, b: Type, mod: *Module) bool {
621 // As a shortcut, if the small tags / addresses match, we're done.
622612 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.
623616 return a.ip_index == b.ip_index;
624617 }
618 // As a shortcut, if the small tags / addresses match, we're done.
625619 if (a.legacy.tag_if_small_enough == b.legacy.tag_if_small_enough) return true;
626620
627621 switch (a.tag()) {
......@@ -640,18 +634,10 @@ pub const Type = struct {
640634 .c_longlong,
641635 .c_ulonglong,
642636
643 .f16,
644 .f32,
645 .f64,
646 .f80,
647 .f128,
648 .c_longdouble,
649
650637 .bool,
651638 .void,
652639 .type,
653640 .comptime_int,
654 .comptime_float,
655641 .noreturn,
656642 .null,
657643 .undefined,
......@@ -1018,7 +1004,11 @@ pub const Type = struct {
10181004
10191005 pub fn hashWithHasher(ty: Type, hasher: *std.hash.Wyhash, mod: *Module) void {
10201006 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;
10221012 }
10231013 switch (ty.tag()) {
10241014 .generic_poison => unreachable,
......@@ -1039,22 +1029,10 @@ pub const Type = struct {
10391029 std.hash.autoHash(hasher, ty_tag);
10401030 },
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
10531032 .bool => std.hash.autoHash(hasher, std.builtin.TypeId.Bool),
10541033 .void => std.hash.autoHash(hasher, std.builtin.TypeId.Void),
10551034 .type => std.hash.autoHash(hasher, std.builtin.TypeId.Type),
10561035 .comptime_int => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeInt),
1057 .comptime_float => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeFloat),
10581036 .noreturn => std.hash.autoHash(hasher, std.builtin.TypeId.NoReturn),
10591037 .null => std.hash.autoHash(hasher, std.builtin.TypeId.Null),
10601038 .undefined => std.hash.autoHash(hasher, std.builtin.TypeId.Undefined),
......@@ -1378,19 +1356,12 @@ pub const Type = struct {
13781356 .c_ulong,
13791357 .c_longlong,
13801358 .c_ulonglong,
1381 .c_longdouble,
13821359 .anyopaque,
1383 .f16,
1384 .f32,
1385 .f64,
1386 .f80,
1387 .f128,
13881360 .bool,
13891361 .void,
13901362 .type,
13911363 .anyerror,
13921364 .comptime_int,
1393 .comptime_float,
13941365 .noreturn,
13951366 .null,
13961367 .undefined,
......@@ -1671,20 +1642,13 @@ pub const Type = struct {
16711642 .c_ulong,
16721643 .c_longlong,
16731644 .c_ulonglong,
1674 .c_longdouble,
16751645 .anyopaque,
1676 .f16,
1677 .f32,
1678 .f64,
1679 .f80,
1680 .f128,
16811646 .bool,
16821647 .void,
16831648 .type,
16841649 .anyerror,
16851650 .@"anyframe",
16861651 .comptime_int,
1687 .comptime_float,
16881652 .noreturn,
16891653 => return writer.writeAll(@tagName(t)),
16901654
......@@ -2067,20 +2031,13 @@ pub const Type = struct {
20672031 .c_ulong,
20682032 .c_longlong,
20692033 .c_ulonglong,
2070 .c_longdouble,
20712034 .anyopaque,
2072 .f16,
2073 .f32,
2074 .f64,
2075 .f80,
2076 .f128,
20772035 .bool,
20782036 .void,
20792037 .type,
20802038 .anyerror,
20812039 .@"anyframe",
20822040 .comptime_int,
2083 .comptime_float,
20842041 .noreturn,
20852042 => try writer.writeAll(@tagName(t)),
20862043
......@@ -2353,6 +2310,7 @@ pub const Type = struct {
23532310 }
23542311
23552312 pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value {
2313 if (self.ip_index != .none) return self.ip_index.toValue();
23562314 switch (self.tag()) {
23572315 .u1 => return Value.initTag(.u1_type),
23582316 .u8 => return Value.initTag(.u8_type),
......@@ -2375,20 +2333,13 @@ pub const Type = struct {
23752333 .c_ulong => return Value.initTag(.c_ulong_type),
23762334 .c_longlong => return Value.initTag(.c_longlong_type),
23772335 .c_ulonglong => return Value.initTag(.c_ulonglong_type),
2378 .c_longdouble => return Value.initTag(.c_longdouble_type),
23792336 .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),
23852337 .bool => return Value.initTag(.bool_type),
23862338 .void => return Value.initTag(.void_type),
23872339 .type => return Value.initTag(.type_type),
23882340 .anyerror => return Value.initTag(.anyerror_type),
23892341 .@"anyframe" => return Value.initTag(.anyframe_type),
23902342 .comptime_int => return Value.initTag(.comptime_int_type),
2391 .comptime_float => return Value.initTag(.comptime_float_type),
23922343 .noreturn => return Value.initTag(.noreturn_type),
23932344 .null => return Value.initTag(.null_type),
23942345 .undefined => return Value.initTag(.undefined_type),
......@@ -2522,12 +2473,6 @@ pub const Type = struct {
25222473 .c_ulong,
25232474 .c_longlong,
25242475 .c_ulonglong,
2525 .c_longdouble,
2526 .f16,
2527 .f32,
2528 .f64,
2529 .f80,
2530 .f128,
25312476 .bool,
25322477 .anyerror,
25332478 .const_slice_u8,
......@@ -2588,7 +2533,6 @@ pub const Type = struct {
25882533 .void,
25892534 .type,
25902535 .comptime_int,
2591 .comptime_float,
25922536 .noreturn,
25932537 .null,
25942538 .undefined,
......@@ -2801,12 +2745,6 @@ pub const Type = struct {
28012745 .c_ulong,
28022746 .c_longlong,
28032747 .c_ulonglong,
2804 .c_longdouble,
2805 .f16,
2806 .f32,
2807 .f64,
2808 .f80,
2809 .f128,
28102748 .bool,
28112749 .void,
28122750 .manyptr_u8,
......@@ -2852,7 +2790,6 @@ pub const Type = struct {
28522790 .generic_poison,
28532791 .type,
28542792 .comptime_int,
2855 .comptime_float,
28562793 .enum_literal,
28572794 .type_info,
28582795 // These are function bodies, not function pointers.
......@@ -3085,7 +3022,74 @@ pub const Type = struct {
30853022 .vector_type => @panic("TODO"),
30863023 .optional_type => @panic("TODO"),
30873024 .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 },
30893093 .struct_type => @panic("TODO"),
30903094 .union_type => @panic("TODO"),
30913095 .simple_value => unreachable,
......@@ -3158,28 +3162,6 @@ pub const Type = struct {
31583162 .c_ulong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ulong) },
31593163 .c_longlong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longlong) },
31603164 .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
31843166 // TODO revisit this when we have the concept of the error tag type
31853167 .anyerror_void_error_union,
......@@ -3366,7 +3348,6 @@ pub const Type = struct {
33663348 .empty_struct_literal,
33673349 .type,
33683350 .comptime_int,
3369 .comptime_float,
33703351 .null,
33713352 .undefined,
33723353 .enum_literal,
......@@ -3481,7 +3462,69 @@ pub const Type = struct {
34813462 .vector_type => @panic("TODO"),
34823463 .optional_type => @panic("TODO"),
34833464 .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 },
34853528 .struct_type => @panic("TODO"),
34863529 .union_type => @panic("TODO"),
34873530 .simple_value => unreachable,
......@@ -3506,7 +3549,6 @@ pub const Type = struct {
35063549 .anyopaque,
35073550 .type,
35083551 .comptime_int,
3509 .comptime_float,
35103552 .null,
35113553 .undefined,
35123554 .enum_literal,
......@@ -3661,22 +3703,6 @@ pub const Type = struct {
36613703 .c_ulong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ulong) },
36623704 .c_longlong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longlong) },
36633705 .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
36813707 // TODO revisit this when we have the concept of the error tag type
36823708 .anyerror_void_error_union,
......@@ -3820,7 +3846,57 @@ pub const Type = struct {
38203846 .vector_type => @panic("TODO"),
38213847 .optional_type => @panic("TODO"),
38223848 .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 },
38243900 .struct_type => @panic("TODO"),
38253901 .union_type => @panic("TODO"),
38263902 .simple_value => unreachable,
......@@ -3836,7 +3912,6 @@ pub const Type = struct {
38363912 .anyopaque => unreachable,
38373913 .type => unreachable,
38383914 .comptime_int => unreachable,
3839 .comptime_float => unreachable,
38403915 .noreturn => unreachable,
38413916 .null => unreachable,
38423917 .undefined => unreachable,
......@@ -3852,12 +3927,11 @@ pub const Type = struct {
38523927 .void => return 0,
38533928 .bool, .u1 => return 1,
38543929 .u8, .i8 => return 8,
3855 .i16, .u16, .f16 => return 16,
3930 .i16, .u16 => return 16,
38563931 .u29 => return 29,
3857 .i32, .u32, .f32 => return 32,
3858 .i64, .u64, .f64 => return 64,
3859 .f80 => return 80,
3860 .u128, .i128, .f128 => return 128,
3932 .i32, .u32 => return 32,
3933 .i64, .u64 => return 64,
3934 .u128, .i128 => return 128,
38613935
38623936 .@"struct" => {
38633937 const struct_obj = ty.castTag(.@"struct").?.data;
......@@ -3975,7 +4049,6 @@ pub const Type = struct {
39754049 .c_ulong => return target.c_type_bit_size(.ulong),
39764050 .c_longlong => return target.c_type_bit_size(.longlong),
39774051 .c_ulonglong => return target.c_type_bit_size(.ulonglong),
3978 .c_longdouble => return target.c_type_bit_size(.longdouble),
39794052
39804053 .error_set,
39814054 .error_set_single,
......@@ -4950,14 +5023,14 @@ pub const Type = struct {
49505023 }
49515024
49525025 /// Returns `false` for `comptime_float`.
4953 pub fn isRuntimeFloat(self: Type) bool {
4954 return switch (self.tag()) {
4955 .f16,
4956 .f32,
4957 .f64,
4958 .f80,
4959 .f128,
4960 .c_longdouble,
5026 pub fn isRuntimeFloat(ty: Type) bool {
5027 return switch (ty.ip_index) {
5028 .f16_type,
5029 .f32_type,
5030 .f64_type,
5031 .f80_type,
5032 .f128_type,
5033 .c_longdouble_type,
49615034 => true,
49625035
49635036 else => false,
......@@ -4965,15 +5038,15 @@ pub const Type = struct {
49655038 }
49665039
49675040 /// Returns `true` for `comptime_float`.
4968 pub fn isAnyFloat(self: Type) bool {
4969 return switch (self.tag()) {
4970 .f16,
4971 .f32,
4972 .f64,
4973 .f80,
4974 .f128,
4975 .c_longdouble,
4976 .comptime_float,
5041 pub fn isAnyFloat(ty: Type) bool {
5042 return switch (ty.ip_index) {
5043 .f16_type,
5044 .f32_type,
5045 .f64_type,
5046 .f80_type,
5047 .f128_type,
5048 .c_longdouble_type,
5049 .comptime_float_type,
49775050 => true,
49785051
49795052 else => false,
......@@ -4982,14 +5055,14 @@ pub const Type = struct {
49825055
49835056 /// Asserts the type is a fixed-size float or comptime_float.
49845057 /// Returns 128 for comptime_float types.
4985 pub fn floatBits(self: Type, target: Target) u16 {
4986 return switch (self.tag()) {
4987 .f16 => 16,
4988 .f32 => 32,
4989 .f64 => 64,
4990 .f80 => 80,
4991 .f128, .comptime_float => 128,
4992 .c_longdouble => target.c_type_bit_size(.longdouble),
5058 pub fn floatBits(ty: Type, target: Target) u16 {
5059 return switch (ty.ip_index) {
5060 .f16_type => 16,
5061 .f32_type => 32,
5062 .f64_type => 64,
5063 .f80_type => 80,
5064 .f128_type, .comptime_float_type => 128,
5065 .c_longdouble_type => target.c_type_bit_size(.longdouble),
49935066
49945067 else => unreachable,
49955068 };
......@@ -5094,14 +5167,7 @@ pub const Type = struct {
50945167 else => false,
50955168 };
50965169 return switch (ty.tag()) {
5097 .f16,
5098 .f32,
5099 .f64,
5100 .f80,
5101 .f128,
5102 .c_longdouble,
51035170 .comptime_int,
5104 .comptime_float,
51055171 .u1,
51065172 .u8,
51075173 .i8,
......@@ -5205,14 +5271,7 @@ pub const Type = struct {
52055271 };
52065272
52075273 while (true) switch (ty.tag()) {
5208 .f16,
5209 .f32,
5210 .f64,
5211 .f80,
5212 .f128,
5213 .c_longdouble,
52145274 .comptime_int,
5215 .comptime_float,
52165275 .u1,
52175276 .u8,
52185277 .i8,
......@@ -5391,14 +5450,59 @@ pub const Type = struct {
53915450 /// TODO merge these implementations together with the "advanced" pattern seen
53925451 /// elsewhere in this file.
53935452 pub fn comptimeOnly(ty: Type, mod: *const Module) bool {
5394 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
5395 .int_type => return false,
5453 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
5454 .int_type => false,
53965455 .ptr_type => @panic("TODO"),
53975456 .array_type => @panic("TODO"),
53985457 .vector_type => @panic("TODO"),
53995458 .optional_type => @panic("TODO"),
54005459 .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 },
54025506 .struct_type => @panic("TODO"),
54035507 .union_type => @panic("TODO"),
54045508 .simple_value => unreachable,
......@@ -5431,20 +5535,12 @@ pub const Type = struct {
54315535 .c_ulong,
54325536 .c_longlong,
54335537 .c_ulonglong,
5434 .c_longdouble,
5435 .f16,
5436 .f32,
5437 .f64,
5438 .f80,
5439 .f128,
54405538 .anyopaque,
54415539 .bool,
54425540 .void,
54435541 .anyerror,
54445542 .noreturn,
54455543 .@"anyframe",
5446 .null,
5447 .undefined,
54485544 .atomic_order,
54495545 .atomic_rmw_op,
54505546 .calling_convention,
......@@ -5477,11 +5573,12 @@ pub const Type = struct {
54775573 .single_const_pointer_to_comptime_int,
54785574 .type,
54795575 .comptime_int,
5480 .comptime_float,
54815576 .enum_literal,
54825577 .type_info,
54835578 // These are function bodies, not function pointers.
54845579 .function,
5580 .null,
5581 .undefined,
54855582 => true,
54865583
54875584 .inferred_alloc_mut => unreachable,
......@@ -6286,19 +6383,12 @@ pub const Type = struct {
62866383 c_ulong,
62876384 c_longlong,
62886385 c_ulonglong,
6289 c_longdouble,
6290 f16,
6291 f32,
6292 f64,
6293 f80,
6294 f128,
62956386 anyopaque,
62966387 bool,
62976388 void,
62986389 type,
62996390 anyerror,
63006391 comptime_int,
6301 comptime_float,
63026392 noreturn,
63036393 @"anyframe",
63046394 null,
......@@ -6377,7 +6467,6 @@ pub const Type = struct {
63776467 pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1;
63786468
63796469 pub fn Type(comptime t: Tag) type {
6380 // Keep in sync with tools/stage2_pretty_printers_common.py
63816470 return switch (t) {
63826471 .u1,
63836472 .u8,
......@@ -6402,19 +6491,12 @@ pub const Type = struct {
64026491 .c_ulong,
64036492 .c_longlong,
64046493 .c_ulonglong,
6405 .c_longdouble,
6406 .f16,
6407 .f32,
6408 .f64,
6409 .f80,
6410 .f128,
64116494 .anyopaque,
64126495 .bool,
64136496 .void,
64146497 .type,
64156498 .anyerror,
64166499 .comptime_int,
6417 .comptime_float,
64186500 .noreturn,
64196501 .enum_literal,
64206502 .null,
......@@ -6781,16 +6863,17 @@ pub const Type = struct {
67816863 pub const @"i32" = initTag(.i32);
67826864 pub const @"i64" = initTag(.i64);
67836865
6784 pub const @"f16" = initTag(.f16);
6785 pub const @"f32" = initTag(.f32);
6786 pub const @"f64" = initTag(.f64);
6787 pub const @"f80" = initTag(.f80);
6788 pub const @"f128" = initTag(.f128);
6866 pub const @"f16": Type = .{ .ip_index = .f16_type, .legacy = undefined };
6867 pub const @"f32": Type = .{ .ip_index = .f32_type, .legacy = undefined };
6868 pub const @"f64": Type = .{ .ip_index = .f64_type, .legacy = undefined };
6869 pub const @"f80": Type = .{ .ip_index = .f80_type, .legacy = undefined };
6870 pub const @"f128": Type = .{ .ip_index = .f128_type, .legacy = undefined };
67896871
67906872 pub const @"bool" = initTag(.bool);
67916873 pub const @"usize" = initTag(.usize);
67926874 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 };
67946877 pub const @"void" = initTag(.void);
67956878 pub const @"type" = initTag(.type);
67966879 pub const @"anyerror" = initTag(.anyerror);
......@@ -6798,6 +6881,8 @@ pub const Type = struct {
67986881 pub const @"null" = initTag(.null);
67996882 pub const @"noreturn" = initTag(.noreturn);
68006883
6884 pub const @"c_longdouble": Type = .{ .ip_index = .c_longdouble_type, .legacy = undefined };
6885
68016886 pub const err_int = Type.u16;
68026887
68036888 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 {
974974 .c_ulong_type => Type.initTag(.c_ulong),
975975 .c_longlong_type => Type.initTag(.c_longlong),
976976 .c_ulonglong_type => Type.initTag(.c_ulonglong),
977 .c_longdouble_type => Type.initTag(.c_longdouble),
978 .f16_type => Type.initTag(.f16),
979 .f32_type => Type.initTag(.f32),
980 .f64_type => Type.initTag(.f64),
981 .f80_type => Type.initTag(.f80),
982 .f128_type => Type.initTag(.f128),
977 .c_longdouble_type => Type.c_longdouble,
978 .f16_type => Type.f16,
979 .f32_type => Type.f32,
980 .f64_type => Type.f64,
981 .f80_type => Type.f80,
982 .f128_type => Type.f128,
983983 .anyopaque_type => Type.initTag(.anyopaque),
984984 .bool_type => Type.initTag(.bool),
985985 .void_type => Type.initTag(.void),
986986 .type_type => Type.initTag(.type),
987987 .anyerror_type => Type.initTag(.anyerror),
988988 .comptime_int_type => Type.initTag(.comptime_int),
989 .comptime_float_type => Type.initTag(.comptime_float),
989 .comptime_float_type => Type.comptime_float,
990990 .noreturn_type => Type.initTag(.noreturn),
991991 .null_type => Type.initTag(.null),
992992 .undefined_type => Type.initTag(.undefined),