| ... | ... | @@ -44,10 +44,6 @@ pub const Type = struct { |
| 44 | 44 | |
| 45 | 45 | .function => return .Fn, |
| 46 | 46 | |
| 47 | | .array, |
| 48 | | .array_sentinel, |
| 49 | | => return .Array, |
| 50 | | |
| 51 | 47 | .pointer, |
| 52 | 48 | .inferred_alloc_const, |
| 53 | 49 | .inferred_alloc_mut, |
| ... | ... | @@ -398,29 +394,6 @@ pub const Type = struct { |
| 398 | 394 | return true; |
| 399 | 395 | }, |
| 400 | 396 | |
| 401 | | .array, |
| 402 | | .array_sentinel, |
| 403 | | => { |
| 404 | | if (a.zigTypeTag(mod) != b.zigTypeTag(mod)) return false; |
| 405 | | |
| 406 | | if (a.arrayLen(mod) != b.arrayLen(mod)) |
| 407 | | return false; |
| 408 | | const elem_ty = a.childType(mod); |
| 409 | | if (!elem_ty.eql(b.childType(mod), mod)) |
| 410 | | return false; |
| 411 | | const sentinel_a = a.sentinel(mod); |
| 412 | | const sentinel_b = b.sentinel(mod); |
| 413 | | if (sentinel_a) |sa| { |
| 414 | | if (sentinel_b) |sb| { |
| 415 | | return sa.eql(sb, elem_ty, mod); |
| 416 | | } else { |
| 417 | | return false; |
| 418 | | } |
| 419 | | } else { |
| 420 | | return sentinel_b == null; |
| 421 | | } |
| 422 | | }, |
| 423 | | |
| 424 | 397 | .pointer, |
| 425 | 398 | .inferred_alloc_const, |
| 426 | 399 | .inferred_alloc_mut, |
| ... | ... | @@ -627,17 +600,6 @@ pub const Type = struct { |
| 627 | 600 | } |
| 628 | 601 | }, |
| 629 | 602 | |
| 630 | | .array, |
| 631 | | .array_sentinel, |
| 632 | | => { |
| 633 | | std.hash.autoHash(hasher, std.builtin.TypeId.Array); |
| 634 | | |
| 635 | | const elem_ty = ty.childType(mod); |
| 636 | | std.hash.autoHash(hasher, ty.arrayLen(mod)); |
| 637 | | hashWithHasher(elem_ty, hasher, mod); |
| 638 | | hashSentinel(ty.sentinel(mod), elem_ty, hasher, mod); |
| 639 | | }, |
| 640 | | |
| 641 | 603 | .pointer, |
| 642 | 604 | .inferred_alloc_const, |
| 643 | 605 | .inferred_alloc_mut, |
| ... | ... | @@ -770,21 +732,6 @@ pub const Type = struct { |
| 770 | 732 | }; |
| 771 | 733 | }, |
| 772 | 734 | |
| 773 | | .array => { |
| 774 | | const payload = self.castTag(.array).?.data; |
| 775 | | return Tag.array.create(allocator, .{ |
| 776 | | .len = payload.len, |
| 777 | | .elem_type = try payload.elem_type.copy(allocator), |
| 778 | | }); |
| 779 | | }, |
| 780 | | .array_sentinel => { |
| 781 | | const payload = self.castTag(.array_sentinel).?.data; |
| 782 | | return Tag.array_sentinel.create(allocator, .{ |
| 783 | | .len = payload.len, |
| 784 | | .sentinel = try payload.sentinel.copy(allocator), |
| 785 | | .elem_type = try payload.elem_type.copy(allocator), |
| 786 | | }); |
| 787 | | }, |
| 788 | 735 | .tuple => { |
| 789 | 736 | const payload = self.castTag(.tuple).?.data; |
| 790 | 737 | const types = try allocator.alloc(Type, payload.types.len); |
| ... | ... | @@ -987,21 +934,6 @@ pub const Type = struct { |
| 987 | 934 | ty = return_type; |
| 988 | 935 | continue; |
| 989 | 936 | }, |
| 990 | | .array => { |
| 991 | | const payload = ty.castTag(.array).?.data; |
| 992 | | try writer.print("[{d}]", .{payload.len}); |
| 993 | | ty = payload.elem_type; |
| 994 | | continue; |
| 995 | | }, |
| 996 | | .array_sentinel => { |
| 997 | | const payload = ty.castTag(.array_sentinel).?.data; |
| 998 | | try writer.print("[{d}:{}]", .{ |
| 999 | | payload.len, |
| 1000 | | payload.sentinel.fmtDebug(), |
| 1001 | | }); |
| 1002 | | ty = payload.elem_type; |
| 1003 | | continue; |
| 1004 | | }, |
| 1005 | 937 | .tuple => { |
| 1006 | 938 | const tuple = ty.castTag(.tuple).?.data; |
| 1007 | 939 | try writer.writeAll("tuple{"); |
| ... | ... | @@ -1198,19 +1130,6 @@ pub const Type = struct { |
| 1198 | 1130 | try print(error_union.payload, writer, mod); |
| 1199 | 1131 | }, |
| 1200 | 1132 | |
| 1201 | | .array => { |
| 1202 | | const payload = ty.castTag(.array).?.data; |
| 1203 | | try writer.print("[{d}]", .{payload.len}); |
| 1204 | | try print(payload.elem_type, writer, mod); |
| 1205 | | }, |
| 1206 | | .array_sentinel => { |
| 1207 | | const payload = ty.castTag(.array_sentinel).?.data; |
| 1208 | | try writer.print("[{d}:{}]", .{ |
| 1209 | | payload.len, |
| 1210 | | payload.sentinel.fmtValue(payload.elem_type, mod), |
| 1211 | | }); |
| 1212 | | try print(payload.elem_type, writer, mod); |
| 1213 | | }, |
| 1214 | 1133 | .tuple => { |
| 1215 | 1134 | const tuple = ty.castTag(.tuple).?.data; |
| 1216 | 1135 | |
| ... | ... | @@ -1522,10 +1441,6 @@ pub const Type = struct { |
| 1522 | 1441 | } |
| 1523 | 1442 | }, |
| 1524 | 1443 | |
| 1525 | | .array => return ty.arrayLen(mod) != 0 and |
| 1526 | | try ty.childType(mod).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat), |
| 1527 | | .array_sentinel => return ty.childType(mod).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat), |
| 1528 | | |
| 1529 | 1444 | .tuple, .anon_struct => { |
| 1530 | 1445 | const tuple = ty.tupleFields(); |
| 1531 | 1446 | for (tuple.types, 0..) |field_ty, i| { |
| ... | ... | @@ -1723,10 +1638,6 @@ pub const Type = struct { |
| 1723 | 1638 | .inferred_alloc_mut => unreachable, |
| 1724 | 1639 | .inferred_alloc_const => unreachable, |
| 1725 | 1640 | |
| 1726 | | .array, |
| 1727 | | .array_sentinel, |
| 1728 | | => ty.childType(mod).hasWellDefinedLayout(mod), |
| 1729 | | |
| 1730 | 1641 | .optional => ty.isPtrLikeOptional(mod), |
| 1731 | 1642 | }, |
| 1732 | 1643 | else => switch (mod.intern_pool.indexToKey(ty.ip_index)) { |
| ... | ... | @@ -2005,8 +1916,6 @@ pub const Type = struct { |
| 2005 | 1916 | .error_set_merged, |
| 2006 | 1917 | => return AbiAlignmentAdvanced{ .scalar = 2 }, |
| 2007 | 1918 | |
| 2008 | | .array, .array_sentinel => return ty.childType(mod).abiAlignmentAdvanced(mod, strat), |
| 2009 | | |
| 2010 | 1919 | .optional => return abiAlignmentAdvancedOptional(ty, mod, strat), |
| 2011 | 1920 | .error_union => return abiAlignmentAdvancedErrorUnion(ty, mod, strat), |
| 2012 | 1921 | |
| ... | ... | @@ -2385,29 +2294,6 @@ pub const Type = struct { |
| 2385 | 2294 | return AbiSizeAdvanced{ .scalar = ty.structFieldOffset(field_count, mod) }; |
| 2386 | 2295 | }, |
| 2387 | 2296 | |
| 2388 | | .array => { |
| 2389 | | const payload = ty.castTag(.array).?.data; |
| 2390 | | switch (try payload.elem_type.abiSizeAdvanced(mod, strat)) { |
| 2391 | | .scalar => |elem_size| return AbiSizeAdvanced{ .scalar = payload.len * elem_size }, |
| 2392 | | .val => switch (strat) { |
| 2393 | | .sema => unreachable, |
| 2394 | | .eager => unreachable, |
| 2395 | | .lazy => |arena| return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) }, |
| 2396 | | }, |
| 2397 | | } |
| 2398 | | }, |
| 2399 | | .array_sentinel => { |
| 2400 | | const payload = ty.castTag(.array_sentinel).?.data; |
| 2401 | | switch (try payload.elem_type.abiSizeAdvanced(mod, strat)) { |
| 2402 | | .scalar => |elem_size| return AbiSizeAdvanced{ .scalar = (payload.len + 1) * elem_size }, |
| 2403 | | .val => switch (strat) { |
| 2404 | | .sema => unreachable, |
| 2405 | | .eager => unreachable, |
| 2406 | | .lazy => |arena| return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) }, |
| 2407 | | }, |
| 2408 | | } |
| 2409 | | }, |
| 2410 | | |
| 2411 | 2297 | .anyframe_T => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) }, |
| 2412 | 2298 | |
| 2413 | 2299 | .pointer => switch (ty.castTag(.pointer).?.data.size) { |
| ... | ... | @@ -2729,24 +2615,6 @@ pub const Type = struct { |
| 2729 | 2615 | return total; |
| 2730 | 2616 | }, |
| 2731 | 2617 | |
| 2732 | | .array => { |
| 2733 | | const payload = ty.castTag(.array).?.data; |
| 2734 | | const elem_size = std.math.max(payload.elem_type.abiAlignment(mod), payload.elem_type.abiSize(mod)); |
| 2735 | | if (elem_size == 0 or payload.len == 0) |
| 2736 | | return @as(u64, 0); |
| 2737 | | const elem_bit_size = try bitSizeAdvanced(payload.elem_type, mod, opt_sema); |
| 2738 | | return (payload.len - 1) * 8 * elem_size + elem_bit_size; |
| 2739 | | }, |
| 2740 | | .array_sentinel => { |
| 2741 | | const payload = ty.castTag(.array_sentinel).?.data; |
| 2742 | | const elem_size = std.math.max( |
| 2743 | | payload.elem_type.abiAlignment(mod), |
| 2744 | | payload.elem_type.abiSize(mod), |
| 2745 | | ); |
| 2746 | | const elem_bit_size = try bitSizeAdvanced(payload.elem_type, mod, opt_sema); |
| 2747 | | return payload.len * 8 * elem_size + elem_bit_size; |
| 2748 | | }, |
| 2749 | | |
| 2750 | 2618 | .anyframe_T => return target.ptrBitWidth(), |
| 2751 | 2619 | |
| 2752 | 2620 | .pointer => switch (ty.castTag(.pointer).?.data.size) { |
| ... | ... | @@ -3188,9 +3056,6 @@ pub const Type = struct { |
| 3188 | 3056 | pub fn childTypeIp(ty: Type, ip: InternPool) Type { |
| 3189 | 3057 | return switch (ty.ip_index) { |
| 3190 | 3058 | .none => switch (ty.tag()) { |
| 3191 | | .array => ty.castTag(.array).?.data.elem_type, |
| 3192 | | .array_sentinel => ty.castTag(.array_sentinel).?.data.elem_type, |
| 3193 | | |
| 3194 | 3059 | .pointer => ty.castTag(.pointer).?.data.pointee_type, |
| 3195 | 3060 | |
| 3196 | 3061 | else => unreachable, |
| ... | ... | @@ -3211,9 +3076,6 @@ pub const Type = struct { |
| 3211 | 3076 | pub fn elemType2(ty: Type, mod: *const Module) Type { |
| 3212 | 3077 | return switch (ty.ip_index) { |
| 3213 | 3078 | .none => switch (ty.tag()) { |
| 3214 | | .array => ty.castTag(.array).?.data.elem_type, |
| 3215 | | .array_sentinel => ty.castTag(.array_sentinel).?.data.elem_type, |
| 3216 | | |
| 3217 | 3079 | .pointer => { |
| 3218 | 3080 | const info = ty.castTag(.pointer).?.data; |
| 3219 | 3081 | const child_ty = info.pointee_type; |
| ... | ... | @@ -3483,8 +3345,6 @@ pub const Type = struct { |
| 3483 | 3345 | return switch (ty.ip_index) { |
| 3484 | 3346 | .empty_struct_type => 0, |
| 3485 | 3347 | .none => switch (ty.tag()) { |
| 3486 | | .array => ty.castTag(.array).?.data.len, |
| 3487 | | .array_sentinel => ty.castTag(.array_sentinel).?.data.len, |
| 3488 | 3348 | .tuple => ty.castTag(.tuple).?.data.types.len, |
| 3489 | 3349 | .anon_struct => ty.castTag(.anon_struct).?.data.types.len, |
| 3490 | 3350 | |
| ... | ... | @@ -3524,12 +3384,9 @@ pub const Type = struct { |
| 3524 | 3384 | pub fn sentinel(ty: Type, mod: *const Module) ?Value { |
| 3525 | 3385 | return switch (ty.ip_index) { |
| 3526 | 3386 | .none => switch (ty.tag()) { |
| 3527 | | .array, |
| 3528 | | .tuple, |
| 3529 | | => null, |
| 3387 | .tuple => null, |
| 3530 | 3388 | |
| 3531 | 3389 | .pointer => ty.castTag(.pointer).?.data.sentinel, |
| 3532 | | .array_sentinel => ty.castTag(.array_sentinel).?.data.sentinel, |
| 3533 | 3390 | |
| 3534 | 3391 | else => unreachable, |
| 3535 | 3392 | }, |
| ... | ... | @@ -3832,7 +3689,6 @@ pub const Type = struct { |
| 3832 | 3689 | .error_set, |
| 3833 | 3690 | .error_set_merged, |
| 3834 | 3691 | .function, |
| 3835 | | .array_sentinel, |
| 3836 | 3692 | .error_set_inferred, |
| 3837 | 3693 | .anyframe_T, |
| 3838 | 3694 | .pointer, |
| ... | ... | @@ -3858,14 +3714,6 @@ pub const Type = struct { |
| 3858 | 3714 | return Value.empty_struct; |
| 3859 | 3715 | }, |
| 3860 | 3716 | |
| 3861 | | .array => { |
| 3862 | | if (ty.arrayLen(mod) == 0) |
| 3863 | | return Value.initTag(.empty_array); |
| 3864 | | if ((try ty.childType(mod).onePossibleValue(mod)) != null) |
| 3865 | | return Value.initTag(.the_only_possible_value); |
| 3866 | | return null; |
| 3867 | | }, |
| 3868 | | |
| 3869 | 3717 | .inferred_alloc_const => unreachable, |
| 3870 | 3718 | .inferred_alloc_mut => unreachable, |
| 3871 | 3719 | }, |
| ... | ... | @@ -4034,10 +3882,6 @@ pub const Type = struct { |
| 4034 | 3882 | .inferred_alloc_mut => unreachable, |
| 4035 | 3883 | .inferred_alloc_const => unreachable, |
| 4036 | 3884 | |
| 4037 | | .array, |
| 4038 | | .array_sentinel, |
| 4039 | | => return ty.childType(mod).comptimeOnly(mod), |
| 4040 | | |
| 4041 | 3885 | .pointer => { |
| 4042 | 3886 | const child_ty = ty.childType(mod); |
| 4043 | 3887 | if (child_ty.zigTypeTag(mod) == .Fn) { |
| ... | ... | @@ -4804,8 +4648,6 @@ pub const Type = struct { |
| 4804 | 4648 | inferred_alloc_const, // See last_no_payload_tag below. |
| 4805 | 4649 | // After this, the tag requires a payload. |
| 4806 | 4650 | |
| 4807 | | array, |
| 4808 | | array_sentinel, |
| 4809 | 4651 | /// Possible Value tags for this: @"struct" |
| 4810 | 4652 | tuple, |
| 4811 | 4653 | /// Possible Value tags for this: @"struct" |
| ... | ... | @@ -4838,8 +4680,6 @@ pub const Type = struct { |
| 4838 | 4680 | .error_set_inferred => Payload.ErrorSetInferred, |
| 4839 | 4681 | .error_set_merged => Payload.ErrorSetMerged, |
| 4840 | 4682 | |
| 4841 | | .array => Payload.Array, |
| 4842 | | .array_sentinel => Payload.ArraySentinel, |
| 4843 | 4683 | .pointer => Payload.Pointer, |
| 4844 | 4684 | .function => Payload.Function, |
| 4845 | 4685 | .error_union => Payload.ErrorUnion, |
| ... | ... | @@ -4965,25 +4805,6 @@ pub const Type = struct { |
| 4965 | 4805 | data: u64, |
| 4966 | 4806 | }; |
| 4967 | 4807 | |
| 4968 | | pub const Array = struct { |
| 4969 | | base: Payload, |
| 4970 | | data: struct { |
| 4971 | | len: u64, |
| 4972 | | elem_type: Type, |
| 4973 | | }, |
| 4974 | | }; |
| 4975 | | |
| 4976 | | pub const ArraySentinel = struct { |
| 4977 | | pub const base_tag = Tag.array_sentinel; |
| 4978 | | |
| 4979 | | base: Payload = Payload{ .tag = base_tag }, |
| 4980 | | data: struct { |
| 4981 | | len: u64, |
| 4982 | | sentinel: Value, |
| 4983 | | elem_type: Type, |
| 4984 | | }, |
| 4985 | | }; |
| 4986 | | |
| 4987 | 4808 | pub const ElemType = struct { |
| 4988 | 4809 | base: Payload, |
| 4989 | 4810 | data: Type, |
| ... | ... | @@ -5269,35 +5090,14 @@ pub const Type = struct { |
| 5269 | 5090 | elem_type: Type, |
| 5270 | 5091 | mod: *Module, |
| 5271 | 5092 | ) Allocator.Error!Type { |
| 5272 | | if (elem_type.ip_index != .none) { |
| 5273 | | if (sent) |s| { |
| 5274 | | if (s.ip_index != .none) { |
| 5275 | | return mod.arrayType(.{ |
| 5276 | | .len = len, |
| 5277 | | .child = elem_type.ip_index, |
| 5278 | | .sentinel = s.ip_index, |
| 5279 | | }); |
| 5280 | | } |
| 5281 | | } else { |
| 5282 | | return mod.arrayType(.{ |
| 5283 | | .len = len, |
| 5284 | | .child = elem_type.ip_index, |
| 5285 | | .sentinel = .none, |
| 5286 | | }); |
| 5287 | | } |
| 5288 | | } |
| 5289 | | |
| 5290 | | if (sent) |some| { |
| 5291 | | return Tag.array_sentinel.create(arena, .{ |
| 5292 | | .len = len, |
| 5293 | | .sentinel = some, |
| 5294 | | .elem_type = elem_type, |
| 5295 | | }); |
| 5296 | | } |
| 5093 | // TODO: update callsites of this function to directly call mod.arrayType |
| 5094 | // and then delete this function. |
| 5095 | _ = arena; |
| 5297 | 5096 | |
| 5298 | | return Tag.array.create(arena, .{ |
| 5097 | return mod.arrayType(.{ |
| 5299 | 5098 | .len = len, |
| 5300 | | .elem_type = elem_type, |
| 5099 | .child = elem_type.ip_index, |
| 5100 | .sentinel = if (sent) |s| s.ip_index else .none, |
| 5301 | 5101 | }); |
| 5302 | 5102 | } |
| 5303 | 5103 | |