| ... | ... | @@ -50,6 +50,7 @@ pub const Type = struct { |
| 50 | 50 | .f64, |
| 51 | 51 | .f80, |
| 52 | 52 | .f128, |
| 53 | .c_longdouble, |
| 53 | 54 | => return .Float, |
| 54 | 55 | |
| 55 | 56 | .usize, |
| ... | ... | @@ -63,7 +64,6 @@ pub const Type = struct { |
| 63 | 64 | .c_ulong, |
| 64 | 65 | .c_longlong, |
| 65 | 66 | .c_ulonglong, |
| 66 | | .c_longdouble, |
| 67 | 67 | => return .Int, |
| 68 | 68 | |
| 69 | 69 | .anyopaque => return .Opaque, |
| ... | ... | @@ -134,14 +134,6 @@ pub const Type = struct { |
| 134 | 134 | .c_ulonglong, |
| 135 | 135 | => return .Int, |
| 136 | 136 | |
| 137 | | .f16, |
| 138 | | .f32, |
| 139 | | .f64, |
| 140 | | .f80, |
| 141 | | .f128, |
| 142 | | .c_longdouble, |
| 143 | | => return .Float, |
| 144 | | |
| 145 | 137 | .error_set, |
| 146 | 138 | .error_set_single, |
| 147 | 139 | .anyerror, |
| ... | ... | @@ -154,7 +146,6 @@ pub const Type = struct { |
| 154 | 146 | .void => return .Void, |
| 155 | 147 | .type => return .Type, |
| 156 | 148 | .comptime_int => return .ComptimeInt, |
| 157 | | .comptime_float => return .ComptimeFloat, |
| 158 | 149 | .noreturn => return .NoReturn, |
| 159 | 150 | .null => return .Null, |
| 160 | 151 | .undefined => return .Undefined, |
| ... | ... | @@ -618,10 +609,13 @@ pub const Type = struct { |
| 618 | 609 | } |
| 619 | 610 | |
| 620 | 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 | 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 | 616 | return a.ip_index == b.ip_index; |
| 624 | 617 | } |
| 618 | // As a shortcut, if the small tags / addresses match, we're done. |
| 625 | 619 | if (a.legacy.tag_if_small_enough == b.legacy.tag_if_small_enough) return true; |
| 626 | 620 | |
| 627 | 621 | switch (a.tag()) { |
| ... | ... | @@ -640,18 +634,10 @@ pub const Type = struct { |
| 640 | 634 | .c_longlong, |
| 641 | 635 | .c_ulonglong, |
| 642 | 636 | |
| 643 | | .f16, |
| 644 | | .f32, |
| 645 | | .f64, |
| 646 | | .f80, |
| 647 | | .f128, |
| 648 | | .c_longdouble, |
| 649 | | |
| 650 | 637 | .bool, |
| 651 | 638 | .void, |
| 652 | 639 | .type, |
| 653 | 640 | .comptime_int, |
| 654 | | .comptime_float, |
| 655 | 641 | .noreturn, |
| 656 | 642 | .null, |
| 657 | 643 | .undefined, |
| ... | ... | @@ -1018,7 +1004,11 @@ pub const Type = struct { |
| 1018 | 1004 | |
| 1019 | 1005 | pub fn hashWithHasher(ty: Type, hasher: *std.hash.Wyhash, mod: *Module) void { |
| 1020 | 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 | 1013 | switch (ty.tag()) { |
| 1024 | 1014 | .generic_poison => unreachable, |
| ... | ... | @@ -1039,22 +1029,10 @@ pub const Type = struct { |
| 1039 | 1029 | std.hash.autoHash(hasher, ty_tag); |
| 1040 | 1030 | }, |
| 1041 | 1031 | |
| 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 | 1032 | .bool => std.hash.autoHash(hasher, std.builtin.TypeId.Bool), |
| 1054 | 1033 | .void => std.hash.autoHash(hasher, std.builtin.TypeId.Void), |
| 1055 | 1034 | .type => std.hash.autoHash(hasher, std.builtin.TypeId.Type), |
| 1056 | 1035 | .comptime_int => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeInt), |
| 1057 | | .comptime_float => std.hash.autoHash(hasher, std.builtin.TypeId.ComptimeFloat), |
| 1058 | 1036 | .noreturn => std.hash.autoHash(hasher, std.builtin.TypeId.NoReturn), |
| 1059 | 1037 | .null => std.hash.autoHash(hasher, std.builtin.TypeId.Null), |
| 1060 | 1038 | .undefined => std.hash.autoHash(hasher, std.builtin.TypeId.Undefined), |
| ... | ... | @@ -1378,19 +1356,12 @@ pub const Type = struct { |
| 1378 | 1356 | .c_ulong, |
| 1379 | 1357 | .c_longlong, |
| 1380 | 1358 | .c_ulonglong, |
| 1381 | | .c_longdouble, |
| 1382 | 1359 | .anyopaque, |
| 1383 | | .f16, |
| 1384 | | .f32, |
| 1385 | | .f64, |
| 1386 | | .f80, |
| 1387 | | .f128, |
| 1388 | 1360 | .bool, |
| 1389 | 1361 | .void, |
| 1390 | 1362 | .type, |
| 1391 | 1363 | .anyerror, |
| 1392 | 1364 | .comptime_int, |
| 1393 | | .comptime_float, |
| 1394 | 1365 | .noreturn, |
| 1395 | 1366 | .null, |
| 1396 | 1367 | .undefined, |
| ... | ... | @@ -1671,20 +1642,13 @@ pub const Type = struct { |
| 1671 | 1642 | .c_ulong, |
| 1672 | 1643 | .c_longlong, |
| 1673 | 1644 | .c_ulonglong, |
| 1674 | | .c_longdouble, |
| 1675 | 1645 | .anyopaque, |
| 1676 | | .f16, |
| 1677 | | .f32, |
| 1678 | | .f64, |
| 1679 | | .f80, |
| 1680 | | .f128, |
| 1681 | 1646 | .bool, |
| 1682 | 1647 | .void, |
| 1683 | 1648 | .type, |
| 1684 | 1649 | .anyerror, |
| 1685 | 1650 | .@"anyframe", |
| 1686 | 1651 | .comptime_int, |
| 1687 | | .comptime_float, |
| 1688 | 1652 | .noreturn, |
| 1689 | 1653 | => return writer.writeAll(@tagName(t)), |
| 1690 | 1654 | |
| ... | ... | @@ -2067,20 +2031,13 @@ pub const Type = struct { |
| 2067 | 2031 | .c_ulong, |
| 2068 | 2032 | .c_longlong, |
| 2069 | 2033 | .c_ulonglong, |
| 2070 | | .c_longdouble, |
| 2071 | 2034 | .anyopaque, |
| 2072 | | .f16, |
| 2073 | | .f32, |
| 2074 | | .f64, |
| 2075 | | .f80, |
| 2076 | | .f128, |
| 2077 | 2035 | .bool, |
| 2078 | 2036 | .void, |
| 2079 | 2037 | .type, |
| 2080 | 2038 | .anyerror, |
| 2081 | 2039 | .@"anyframe", |
| 2082 | 2040 | .comptime_int, |
| 2083 | | .comptime_float, |
| 2084 | 2041 | .noreturn, |
| 2085 | 2042 | => try writer.writeAll(@tagName(t)), |
| 2086 | 2043 | |
| ... | ... | @@ -2353,6 +2310,7 @@ pub const Type = struct { |
| 2353 | 2310 | } |
| 2354 | 2311 | |
| 2355 | 2312 | pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value { |
| 2313 | if (self.ip_index != .none) return self.ip_index.toValue(); |
| 2356 | 2314 | switch (self.tag()) { |
| 2357 | 2315 | .u1 => return Value.initTag(.u1_type), |
| 2358 | 2316 | .u8 => return Value.initTag(.u8_type), |
| ... | ... | @@ -2375,20 +2333,13 @@ pub const Type = struct { |
| 2375 | 2333 | .c_ulong => return Value.initTag(.c_ulong_type), |
| 2376 | 2334 | .c_longlong => return Value.initTag(.c_longlong_type), |
| 2377 | 2335 | .c_ulonglong => return Value.initTag(.c_ulonglong_type), |
| 2378 | | .c_longdouble => return Value.initTag(.c_longdouble_type), |
| 2379 | 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 | 2337 | .bool => return Value.initTag(.bool_type), |
| 2386 | 2338 | .void => return Value.initTag(.void_type), |
| 2387 | 2339 | .type => return Value.initTag(.type_type), |
| 2388 | 2340 | .anyerror => return Value.initTag(.anyerror_type), |
| 2389 | 2341 | .@"anyframe" => return Value.initTag(.anyframe_type), |
| 2390 | 2342 | .comptime_int => return Value.initTag(.comptime_int_type), |
| 2391 | | .comptime_float => return Value.initTag(.comptime_float_type), |
| 2392 | 2343 | .noreturn => return Value.initTag(.noreturn_type), |
| 2393 | 2344 | .null => return Value.initTag(.null_type), |
| 2394 | 2345 | .undefined => return Value.initTag(.undefined_type), |
| ... | ... | @@ -2522,12 +2473,6 @@ pub const Type = struct { |
| 2522 | 2473 | .c_ulong, |
| 2523 | 2474 | .c_longlong, |
| 2524 | 2475 | .c_ulonglong, |
| 2525 | | .c_longdouble, |
| 2526 | | .f16, |
| 2527 | | .f32, |
| 2528 | | .f64, |
| 2529 | | .f80, |
| 2530 | | .f128, |
| 2531 | 2476 | .bool, |
| 2532 | 2477 | .anyerror, |
| 2533 | 2478 | .const_slice_u8, |
| ... | ... | @@ -2588,7 +2533,6 @@ pub const Type = struct { |
| 2588 | 2533 | .void, |
| 2589 | 2534 | .type, |
| 2590 | 2535 | .comptime_int, |
| 2591 | | .comptime_float, |
| 2592 | 2536 | .noreturn, |
| 2593 | 2537 | .null, |
| 2594 | 2538 | .undefined, |
| ... | ... | @@ -2801,12 +2745,6 @@ pub const Type = struct { |
| 2801 | 2745 | .c_ulong, |
| 2802 | 2746 | .c_longlong, |
| 2803 | 2747 | .c_ulonglong, |
| 2804 | | .c_longdouble, |
| 2805 | | .f16, |
| 2806 | | .f32, |
| 2807 | | .f64, |
| 2808 | | .f80, |
| 2809 | | .f128, |
| 2810 | 2748 | .bool, |
| 2811 | 2749 | .void, |
| 2812 | 2750 | .manyptr_u8, |
| ... | ... | @@ -2852,7 +2790,6 @@ pub const Type = struct { |
| 2852 | 2790 | .generic_poison, |
| 2853 | 2791 | .type, |
| 2854 | 2792 | .comptime_int, |
| 2855 | | .comptime_float, |
| 2856 | 2793 | .enum_literal, |
| 2857 | 2794 | .type_info, |
| 2858 | 2795 | // These are function bodies, not function pointers. |
| ... | ... | @@ -3085,7 +3022,74 @@ pub const Type = struct { |
| 3085 | 3022 | .vector_type => @panic("TODO"), |
| 3086 | 3023 | .optional_type => @panic("TODO"), |
| 3087 | 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 | 3093 | .struct_type => @panic("TODO"), |
| 3090 | 3094 | .union_type => @panic("TODO"), |
| 3091 | 3095 | .simple_value => unreachable, |
| ... | ... | @@ -3158,28 +3162,6 @@ pub const Type = struct { |
| 3158 | 3162 | .c_ulong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.ulong) }, |
| 3159 | 3163 | .c_longlong => return AbiAlignmentAdvanced{ .scalar = target.c_type_alignment(.longlong) }, |
| 3160 | 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 | | }, |
| 3183 | 3165 | |
| 3184 | 3166 | // TODO revisit this when we have the concept of the error tag type |
| 3185 | 3167 | .anyerror_void_error_union, |
| ... | ... | @@ -3366,7 +3348,6 @@ pub const Type = struct { |
| 3366 | 3348 | .empty_struct_literal, |
| 3367 | 3349 | .type, |
| 3368 | 3350 | .comptime_int, |
| 3369 | | .comptime_float, |
| 3370 | 3351 | .null, |
| 3371 | 3352 | .undefined, |
| 3372 | 3353 | .enum_literal, |
| ... | ... | @@ -3481,7 +3462,69 @@ pub const Type = struct { |
| 3481 | 3462 | .vector_type => @panic("TODO"), |
| 3482 | 3463 | .optional_type => @panic("TODO"), |
| 3483 | 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 | 3528 | .struct_type => @panic("TODO"), |
| 3486 | 3529 | .union_type => @panic("TODO"), |
| 3487 | 3530 | .simple_value => unreachable, |
| ... | ... | @@ -3506,7 +3549,6 @@ pub const Type = struct { |
| 3506 | 3549 | .anyopaque, |
| 3507 | 3550 | .type, |
| 3508 | 3551 | .comptime_int, |
| 3509 | | .comptime_float, |
| 3510 | 3552 | .null, |
| 3511 | 3553 | .undefined, |
| 3512 | 3554 | .enum_literal, |
| ... | ... | @@ -3661,22 +3703,6 @@ pub const Type = struct { |
| 3661 | 3703 | .c_ulong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.ulong) }, |
| 3662 | 3704 | .c_longlong => return AbiSizeAdvanced{ .scalar = target.c_type_byte_size(.longlong) }, |
| 3663 | 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 | | }, |
| 3680 | 3706 | |
| 3681 | 3707 | // TODO revisit this when we have the concept of the error tag type |
| 3682 | 3708 | .anyerror_void_error_union, |
| ... | ... | @@ -3820,7 +3846,57 @@ pub const Type = struct { |
| 3820 | 3846 | .vector_type => @panic("TODO"), |
| 3821 | 3847 | .optional_type => @panic("TODO"), |
| 3822 | 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 | 3900 | .struct_type => @panic("TODO"), |
| 3825 | 3901 | .union_type => @panic("TODO"), |
| 3826 | 3902 | .simple_value => unreachable, |
| ... | ... | @@ -3836,7 +3912,6 @@ pub const Type = struct { |
| 3836 | 3912 | .anyopaque => unreachable, |
| 3837 | 3913 | .type => unreachable, |
| 3838 | 3914 | .comptime_int => unreachable, |
| 3839 | | .comptime_float => unreachable, |
| 3840 | 3915 | .noreturn => unreachable, |
| 3841 | 3916 | .null => unreachable, |
| 3842 | 3917 | .undefined => unreachable, |
| ... | ... | @@ -3852,12 +3927,11 @@ pub const Type = struct { |
| 3852 | 3927 | .void => return 0, |
| 3853 | 3928 | .bool, .u1 => return 1, |
| 3854 | 3929 | .u8, .i8 => return 8, |
| 3855 | | .i16, .u16, .f16 => return 16, |
| 3930 | .i16, .u16 => return 16, |
| 3856 | 3931 | .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, |
| 3861 | 3935 | |
| 3862 | 3936 | .@"struct" => { |
| 3863 | 3937 | const struct_obj = ty.castTag(.@"struct").?.data; |
| ... | ... | @@ -3975,7 +4049,6 @@ pub const Type = struct { |
| 3975 | 4049 | .c_ulong => return target.c_type_bit_size(.ulong), |
| 3976 | 4050 | .c_longlong => return target.c_type_bit_size(.longlong), |
| 3977 | 4051 | .c_ulonglong => return target.c_type_bit_size(.ulonglong), |
| 3978 | | .c_longdouble => return target.c_type_bit_size(.longdouble), |
| 3979 | 4052 | |
| 3980 | 4053 | .error_set, |
| 3981 | 4054 | .error_set_single, |
| ... | ... | @@ -4950,14 +5023,14 @@ pub const Type = struct { |
| 4950 | 5023 | } |
| 4951 | 5024 | |
| 4952 | 5025 | /// 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, |
| 4961 | 5034 | => true, |
| 4962 | 5035 | |
| 4963 | 5036 | else => false, |
| ... | ... | @@ -4965,15 +5038,15 @@ pub const Type = struct { |
| 4965 | 5038 | } |
| 4966 | 5039 | |
| 4967 | 5040 | /// 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, |
| 4977 | 5050 | => true, |
| 4978 | 5051 | |
| 4979 | 5052 | else => false, |
| ... | ... | @@ -4982,14 +5055,14 @@ pub const Type = struct { |
| 4982 | 5055 | |
| 4983 | 5056 | /// Asserts the type is a fixed-size float or comptime_float. |
| 4984 | 5057 | /// 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), |
| 4993 | 5066 | |
| 4994 | 5067 | else => unreachable, |
| 4995 | 5068 | }; |
| ... | ... | @@ -5094,14 +5167,7 @@ pub const Type = struct { |
| 5094 | 5167 | else => false, |
| 5095 | 5168 | }; |
| 5096 | 5169 | return switch (ty.tag()) { |
| 5097 | | .f16, |
| 5098 | | .f32, |
| 5099 | | .f64, |
| 5100 | | .f80, |
| 5101 | | .f128, |
| 5102 | | .c_longdouble, |
| 5103 | 5170 | .comptime_int, |
| 5104 | | .comptime_float, |
| 5105 | 5171 | .u1, |
| 5106 | 5172 | .u8, |
| 5107 | 5173 | .i8, |
| ... | ... | @@ -5205,14 +5271,7 @@ pub const Type = struct { |
| 5205 | 5271 | }; |
| 5206 | 5272 | |
| 5207 | 5273 | while (true) switch (ty.tag()) { |
| 5208 | | .f16, |
| 5209 | | .f32, |
| 5210 | | .f64, |
| 5211 | | .f80, |
| 5212 | | .f128, |
| 5213 | | .c_longdouble, |
| 5214 | 5274 | .comptime_int, |
| 5215 | | .comptime_float, |
| 5216 | 5275 | .u1, |
| 5217 | 5276 | .u8, |
| 5218 | 5277 | .i8, |
| ... | ... | @@ -5391,14 +5450,59 @@ pub const Type = struct { |
| 5391 | 5450 | /// TODO merge these implementations together with the "advanced" pattern seen |
| 5392 | 5451 | /// elsewhere in this file. |
| 5393 | 5452 | 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, |
| 5396 | 5455 | .ptr_type => @panic("TODO"), |
| 5397 | 5456 | .array_type => @panic("TODO"), |
| 5398 | 5457 | .vector_type => @panic("TODO"), |
| 5399 | 5458 | .optional_type => @panic("TODO"), |
| 5400 | 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 | 5506 | .struct_type => @panic("TODO"), |
| 5403 | 5507 | .union_type => @panic("TODO"), |
| 5404 | 5508 | .simple_value => unreachable, |
| ... | ... | @@ -5431,20 +5535,12 @@ pub const Type = struct { |
| 5431 | 5535 | .c_ulong, |
| 5432 | 5536 | .c_longlong, |
| 5433 | 5537 | .c_ulonglong, |
| 5434 | | .c_longdouble, |
| 5435 | | .f16, |
| 5436 | | .f32, |
| 5437 | | .f64, |
| 5438 | | .f80, |
| 5439 | | .f128, |
| 5440 | 5538 | .anyopaque, |
| 5441 | 5539 | .bool, |
| 5442 | 5540 | .void, |
| 5443 | 5541 | .anyerror, |
| 5444 | 5542 | .noreturn, |
| 5445 | 5543 | .@"anyframe", |
| 5446 | | .null, |
| 5447 | | .undefined, |
| 5448 | 5544 | .atomic_order, |
| 5449 | 5545 | .atomic_rmw_op, |
| 5450 | 5546 | .calling_convention, |
| ... | ... | @@ -5477,11 +5573,12 @@ pub const Type = struct { |
| 5477 | 5573 | .single_const_pointer_to_comptime_int, |
| 5478 | 5574 | .type, |
| 5479 | 5575 | .comptime_int, |
| 5480 | | .comptime_float, |
| 5481 | 5576 | .enum_literal, |
| 5482 | 5577 | .type_info, |
| 5483 | 5578 | // These are function bodies, not function pointers. |
| 5484 | 5579 | .function, |
| 5580 | .null, |
| 5581 | .undefined, |
| 5485 | 5582 | => true, |
| 5486 | 5583 | |
| 5487 | 5584 | .inferred_alloc_mut => unreachable, |
| ... | ... | @@ -6286,19 +6383,12 @@ pub const Type = struct { |
| 6286 | 6383 | c_ulong, |
| 6287 | 6384 | c_longlong, |
| 6288 | 6385 | c_ulonglong, |
| 6289 | | c_longdouble, |
| 6290 | | f16, |
| 6291 | | f32, |
| 6292 | | f64, |
| 6293 | | f80, |
| 6294 | | f128, |
| 6295 | 6386 | anyopaque, |
| 6296 | 6387 | bool, |
| 6297 | 6388 | void, |
| 6298 | 6389 | type, |
| 6299 | 6390 | anyerror, |
| 6300 | 6391 | comptime_int, |
| 6301 | | comptime_float, |
| 6302 | 6392 | noreturn, |
| 6303 | 6393 | @"anyframe", |
| 6304 | 6394 | null, |
| ... | ... | @@ -6377,7 +6467,6 @@ pub const Type = struct { |
| 6377 | 6467 | pub const no_payload_count = @enumToInt(last_no_payload_tag) + 1; |
| 6378 | 6468 | |
| 6379 | 6469 | pub fn Type(comptime t: Tag) type { |
| 6380 | | // Keep in sync with tools/stage2_pretty_printers_common.py |
| 6381 | 6470 | return switch (t) { |
| 6382 | 6471 | .u1, |
| 6383 | 6472 | .u8, |
| ... | ... | @@ -6402,19 +6491,12 @@ pub const Type = struct { |
| 6402 | 6491 | .c_ulong, |
| 6403 | 6492 | .c_longlong, |
| 6404 | 6493 | .c_ulonglong, |
| 6405 | | .c_longdouble, |
| 6406 | | .f16, |
| 6407 | | .f32, |
| 6408 | | .f64, |
| 6409 | | .f80, |
| 6410 | | .f128, |
| 6411 | 6494 | .anyopaque, |
| 6412 | 6495 | .bool, |
| 6413 | 6496 | .void, |
| 6414 | 6497 | .type, |
| 6415 | 6498 | .anyerror, |
| 6416 | 6499 | .comptime_int, |
| 6417 | | .comptime_float, |
| 6418 | 6500 | .noreturn, |
| 6419 | 6501 | .enum_literal, |
| 6420 | 6502 | .null, |
| ... | ... | @@ -6781,16 +6863,17 @@ pub const Type = struct { |
| 6781 | 6863 | pub const @"i32" = initTag(.i32); |
| 6782 | 6864 | pub const @"i64" = initTag(.i64); |
| 6783 | 6865 | |
| 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 }; |
| 6789 | 6871 | |
| 6790 | 6872 | pub const @"bool" = initTag(.bool); |
| 6791 | 6873 | pub const @"usize" = initTag(.usize); |
| 6792 | 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 | 6877 | pub const @"void" = initTag(.void); |
| 6795 | 6878 | pub const @"type" = initTag(.type); |
| 6796 | 6879 | pub const @"anyerror" = initTag(.anyerror); |
| ... | ... | @@ -6798,6 +6881,8 @@ pub const Type = struct { |
| 6798 | 6881 | pub const @"null" = initTag(.null); |
| 6799 | 6882 | pub const @"noreturn" = initTag(.noreturn); |
| 6800 | 6883 | |
| 6884 | pub const @"c_longdouble": Type = .{ .ip_index = .c_longdouble_type, .legacy = undefined }; |
| 6885 | |
| 6801 | 6886 | pub const err_int = Type.u16; |
| 6802 | 6887 | |
| 6803 | 6888 | pub fn ptr(arena: Allocator, mod: *Module, data: Payload.Pointer.Data) !Type { |