authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-12 10:59:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:31-07:00
logd89807efbb1bd5af0a92544298fc08ad6ba2d255
tree6df53b53276ff7facead371acde63ad68bb0032f
parent466328d1ca29f3f6dd142f74dda13b26687e71e0

stage2: remove legacy Type array and array_sentinel

These are now handled by the InternPool.

4 files changed, 32 insertions(+), 247 deletions(-)

src/Module.zig+3-2
...@@ -6543,9 +6543,10 @@ pub fn populateTestFunctions(...@@ -6543,9 +6543,10 @@ pub fn populateTestFunctions(
65436543
6544 const test_fn_vals = try arena.alloc(Value, mod.test_functions.count());6544 const test_fn_vals = try arena.alloc(Value, mod.test_functions.count());
6545 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, null, .{6545 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, null, .{
6546 .ty = try Type.Tag.array.create(arena, .{6546 .ty = try mod.arrayType(.{
6547 .len = test_fn_vals.len,6547 .len = test_fn_vals.len,
6548 .elem_type = try tmp_test_fn_ty.copy(arena),6548 .child = tmp_test_fn_ty.ip_index,
6549 .sentinel = .none,
6549 }),6550 }),
6550 .val = try Value.Tag.aggregate.create(arena, test_fn_vals),6551 .val = try Value.Tag.aggregate.create(arena, test_fn_vals),
6551 });6552 });
src/Sema.zig+18-34
...@@ -16015,9 +16015,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16015,9 +16015,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16015 const param_info_decl = mod.declPtr(param_info_decl_index);16015 const param_info_decl = mod.declPtr(param_info_decl_index);
16016 const param_ty = param_info_decl.val.toType();16016 const param_ty = param_info_decl.val.toType();
16017 const new_decl = try params_anon_decl.finish(16017 const new_decl = try params_anon_decl.finish(
16018 try Type.Tag.array.create(params_anon_decl.arena(), .{16018 try mod.arrayType(.{
16019 .len = param_vals.len,16019 .len = param_vals.len,
16020 .elem_type = try param_ty.copy(params_anon_decl.arena()),16020 .child = param_ty.ip_index,
16021 .sentinel = .none,
16021 }),16022 }),
16022 try Value.Tag.aggregate.create(16023 try Value.Tag.aggregate.create(
16023 params_anon_decl.arena(),16024 params_anon_decl.arena(),
...@@ -16238,9 +16239,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16238,9 +16239,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16238 // Build our ?[]const Error value16239 // Build our ?[]const Error value
16239 const errors_val = if (error_field_vals) |vals| v: {16240 const errors_val = if (error_field_vals) |vals| v: {
16240 const new_decl = try fields_anon_decl.finish(16241 const new_decl = try fields_anon_decl.finish(
16241 try Type.Tag.array.create(fields_anon_decl.arena(), .{16242 try mod.arrayType(.{
16242 .len = vals.len,16243 .len = vals.len,
16243 .elem_type = error_field_ty,16244 .child = error_field_ty.ip_index,
16245 .sentinel = .none,
16244 }),16246 }),
16245 try Value.Tag.aggregate.create(16247 try Value.Tag.aggregate.create(
16246 fields_anon_decl.arena(),16248 fields_anon_decl.arena(),
...@@ -16332,9 +16334,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16332,9 +16334,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1633216334
16333 const fields_val = v: {16335 const fields_val = v: {
16334 const new_decl = try fields_anon_decl.finish(16336 const new_decl = try fields_anon_decl.finish(
16335 try Type.Tag.array.create(fields_anon_decl.arena(), .{16337 try mod.arrayType(.{
16336 .len = enum_field_vals.len,16338 .len = enum_field_vals.len,
16337 .elem_type = enum_field_ty,16339 .child = enum_field_ty.ip_index,
16340 .sentinel = .none,
16338 }),16341 }),
16339 try Value.Tag.aggregate.create(16342 try Value.Tag.aggregate.create(
16340 fields_anon_decl.arena(),16343 fields_anon_decl.arena(),
...@@ -16427,9 +16430,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16427,9 +16430,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1642716430
16428 const fields_val = v: {16431 const fields_val = v: {
16429 const new_decl = try fields_anon_decl.finish(16432 const new_decl = try fields_anon_decl.finish(
16430 try Type.Tag.array.create(fields_anon_decl.arena(), .{16433 try mod.arrayType(.{
16431 .len = union_field_vals.len,16434 .len = union_field_vals.len,
16432 .elem_type = union_field_ty,16435 .child = union_field_ty.ip_index,
16436 .sentinel = .none,
16433 }),16437 }),
16434 try Value.Tag.aggregate.create(16438 try Value.Tag.aggregate.create(
16435 fields_anon_decl.arena(),16439 fields_anon_decl.arena(),
...@@ -16590,9 +16594,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16590,9 +16594,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1659016594
16591 const fields_val = v: {16595 const fields_val = v: {
16592 const new_decl = try fields_anon_decl.finish(16596 const new_decl = try fields_anon_decl.finish(
16593 try Type.Tag.array.create(fields_anon_decl.arena(), .{16597 try mod.arrayType(.{
16594 .len = struct_field_vals.len,16598 .len = struct_field_vals.len,
16595 .elem_type = struct_field_ty,16599 .child = struct_field_ty.ip_index,
16600 .sentinel = .none,
16596 }),16601 }),
16597 try Value.Tag.aggregate.create(16602 try Value.Tag.aggregate.create(
16598 fields_anon_decl.arena(),16603 fields_anon_decl.arena(),
...@@ -16707,9 +16712,10 @@ fn typeInfoDecls(...@@ -16707,9 +16712,10 @@ fn typeInfoDecls(
16707 }16712 }
1670816713
16709 const new_decl = try decls_anon_decl.finish(16714 const new_decl = try decls_anon_decl.finish(
16710 try Type.Tag.array.create(decls_anon_decl.arena(), .{16715 try mod.arrayType(.{
16711 .len = decl_vals.items.len,16716 .len = decl_vals.items.len,
16712 .elem_type = declaration_ty,16717 .child = declaration_ty.ip_index,
16718 .sentinel = .none,
16713 }),16719 }),
16714 try Value.Tag.aggregate.create(16720 try Value.Tag.aggregate.create(
16715 decls_anon_decl.arena(),16721 decls_anon_decl.arena(),
...@@ -31574,10 +31580,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -31574,10 +31580,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31574 .inferred_alloc_mut => unreachable,31580 .inferred_alloc_mut => unreachable,
31575 .inferred_alloc_const => unreachable,31581 .inferred_alloc_const => unreachable,
3157631582
31577 .array,
31578 .array_sentinel,
31579 => return sema.resolveTypeRequiresComptime(ty.childType(mod)),
31580
31581 .pointer => {31583 .pointer => {
31582 const child_ty = ty.childType(mod);31584 const child_ty = ty.childType(mod);
31583 if (child_ty.zigTypeTag(mod) == .Fn) {31585 if (child_ty.zigTypeTag(mod) == .Fn) {
...@@ -32862,7 +32864,6 @@ fn generateUnionTagTypeNumbered(...@@ -32862,7 +32864,6 @@ fn generateUnionTagTypeNumbered(
32862 new_decl.name_fully_qualified = true;32864 new_decl.name_fully_qualified = true;
32863 new_decl.owns_tv = true;32865 new_decl.owns_tv = true;
32864 new_decl.name_fully_qualified = true;32866 new_decl.name_fully_qualified = true;
32865 errdefer mod.abortAnonDecl(new_decl_index);
3286632867
32867 const enum_ty = try mod.intern(.{ .enum_type = .{32868 const enum_ty = try mod.intern(.{ .enum_type = .{
32868 .decl = new_decl_index,32869 .decl = new_decl_index,
...@@ -32875,7 +32876,6 @@ fn generateUnionTagTypeNumbered(...@@ -32875,7 +32876,6 @@ fn generateUnionTagTypeNumbered(
32875 .values = enum_field_vals,32876 .values = enum_field_vals,
32876 .tag_mode = .explicit,32877 .tag_mode = .explicit,
32877 } });32878 } });
32878 errdefer mod.intern_pool.remove(enum_ty);
3287932879
32880 new_decl.val = enum_ty.toValue();32880 new_decl.val = enum_ty.toValue();
3288132881
...@@ -32924,12 +32924,10 @@ fn generateUnionTagTypeSimple(...@@ -32924,12 +32924,10 @@ fn generateUnionTagTypeSimple(
32924 .values = &.{},32924 .values = &.{},
32925 .tag_mode = .auto,32925 .tag_mode = .auto,
32926 } });32926 } });
32927 errdefer mod.intern_pool.remove(enum_ty);
3292832927
32929 const new_decl = mod.declPtr(new_decl_index);32928 const new_decl = mod.declPtr(new_decl_index);
32930 new_decl.owns_tv = true;32929 new_decl.owns_tv = true;
32931 new_decl.val = enum_ty.toValue();32930 new_decl.val = enum_ty.toValue();
32932 errdefer mod.abortAnonDecl(new_decl_index);
3293332931
32934 return enum_ty.toType();32932 return enum_ty.toType();
32935}32933}
...@@ -33024,7 +33022,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33024,7 +33022,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33024 .error_set_merged,33022 .error_set_merged,
33025 .error_union,33023 .error_union,
33026 .function,33024 .function,
33027 .array_sentinel,
33028 .error_set_inferred,33025 .error_set_inferred,
33029 .anyframe_T,33026 .anyframe_T,
33030 .pointer,33027 .pointer,
...@@ -33050,15 +33047,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33050,15 +33047,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33050 return Value.empty_struct;33047 return Value.empty_struct;
33051 },33048 },
3305233049
33053 .array => {
33054 if (ty.arrayLen(mod) == 0)
33055 return Value.initTag(.empty_array);
33056 if ((try sema.typeHasOnePossibleValue(ty.childType(mod))) != null) {
33057 return Value.initTag(.the_only_possible_value);
33058 }
33059 return null;
33060 },
33061
33062 .inferred_alloc_const => unreachable,33050 .inferred_alloc_const => unreachable,
33063 .inferred_alloc_mut => unreachable,33051 .inferred_alloc_mut => unreachable,
33064 },33052 },
...@@ -33631,10 +33619,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {...@@ -33631,10 +33619,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33631 .inferred_alloc_mut => unreachable,33619 .inferred_alloc_mut => unreachable,
33632 .inferred_alloc_const => unreachable,33620 .inferred_alloc_const => unreachable,
3363333621
33634 .array,
33635 .array_sentinel,
33636 => return sema.typeRequiresComptime(ty.childType(mod)),
33637
33638 .pointer => {33622 .pointer => {
33639 const child_ty = ty.childType(mod);33623 const child_ty = ty.childType(mod);
33640 if (child_ty.zigTypeTag(mod) == .Fn) {33624 if (child_ty.zigTypeTag(mod) == .Fn) {
src/codegen/c.zig+4-4
...@@ -2467,11 +2467,11 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2467,11 +2467,11 @@ pub fn genErrDecls(o: *Object) !void {
2467 try writer.writeAll(";\n");2467 try writer.writeAll(";\n");
2468 }2468 }
24692469
2470 var name_array_ty_pl = Type.Payload.Array{ .base = .{ .tag = .array }, .data = .{2470 const name_array_ty = try mod.arrayType(.{
2471 .len = mod.error_name_list.items.len,2471 .len = mod.error_name_list.items.len,
2472 .elem_type = Type.const_slice_u8_sentinel_0,2472 .child = .const_slice_u8_sentinel_0_type,
2473 } };2473 .sentinel = .zero_u8,
2474 const name_array_ty = Type.initPayload(&name_array_ty_pl.base);2474 });
24752475
2476 try writer.writeAll("static ");2476 try writer.writeAll("static ");
2477 try o.dg.renderTypeAndName(writer, name_array_ty, .{ .identifier = array_identifier }, Const, 0, .complete);2477 try o.dg.renderTypeAndName(writer, name_array_ty, .{ .identifier = array_identifier }, Const, 0, .complete);
src/type.zig+7-207
...@@ -44,10 +44,6 @@ pub const Type = struct {...@@ -44,10 +44,6 @@ pub const Type = struct {
4444
45 .function => return .Fn,45 .function => return .Fn,
4646
47 .array,
48 .array_sentinel,
49 => return .Array,
50
51 .pointer,47 .pointer,
52 .inferred_alloc_const,48 .inferred_alloc_const,
53 .inferred_alloc_mut,49 .inferred_alloc_mut,
...@@ -398,29 +394,6 @@ pub const Type = struct {...@@ -398,29 +394,6 @@ pub const Type = struct {
398 return true;394 return true;
399 },395 },
400396
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 .pointer,397 .pointer,
425 .inferred_alloc_const,398 .inferred_alloc_const,
426 .inferred_alloc_mut,399 .inferred_alloc_mut,
...@@ -627,17 +600,6 @@ pub const Type = struct {...@@ -627,17 +600,6 @@ pub const Type = struct {
627 }600 }
628 },601 },
629602
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 .pointer,603 .pointer,
642 .inferred_alloc_const,604 .inferred_alloc_const,
643 .inferred_alloc_mut,605 .inferred_alloc_mut,
...@@ -770,21 +732,6 @@ pub const Type = struct {...@@ -770,21 +732,6 @@ pub const Type = struct {
770 };732 };
771 },733 },
772734
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 .tuple => {735 .tuple => {
789 const payload = self.castTag(.tuple).?.data;736 const payload = self.castTag(.tuple).?.data;
790 const types = try allocator.alloc(Type, payload.types.len);737 const types = try allocator.alloc(Type, payload.types.len);
...@@ -987,21 +934,6 @@ pub const Type = struct {...@@ -987,21 +934,6 @@ pub const Type = struct {
987 ty = return_type;934 ty = return_type;
988 continue;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 .tuple => {937 .tuple => {
1006 const tuple = ty.castTag(.tuple).?.data;938 const tuple = ty.castTag(.tuple).?.data;
1007 try writer.writeAll("tuple{");939 try writer.writeAll("tuple{");
...@@ -1198,19 +1130,6 @@ pub const Type = struct {...@@ -1198,19 +1130,6 @@ pub const Type = struct {
1198 try print(error_union.payload, writer, mod);1130 try print(error_union.payload, writer, mod);
1199 },1131 },
12001132
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 .tuple => {1133 .tuple => {
1215 const tuple = ty.castTag(.tuple).?.data;1134 const tuple = ty.castTag(.tuple).?.data;
12161135
...@@ -1522,10 +1441,6 @@ pub const Type = struct {...@@ -1522,10 +1441,6 @@ pub const Type = struct {
1522 }1441 }
1523 },1442 },
15241443
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 .tuple, .anon_struct => {1444 .tuple, .anon_struct => {
1530 const tuple = ty.tupleFields();1445 const tuple = ty.tupleFields();
1531 for (tuple.types, 0..) |field_ty, i| {1446 for (tuple.types, 0..) |field_ty, i| {
...@@ -1723,10 +1638,6 @@ pub const Type = struct {...@@ -1723,10 +1638,6 @@ pub const Type = struct {
1723 .inferred_alloc_mut => unreachable,1638 .inferred_alloc_mut => unreachable,
1724 .inferred_alloc_const => unreachable,1639 .inferred_alloc_const => unreachable,
17251640
1726 .array,
1727 .array_sentinel,
1728 => ty.childType(mod).hasWellDefinedLayout(mod),
1729
1730 .optional => ty.isPtrLikeOptional(mod),1641 .optional => ty.isPtrLikeOptional(mod),
1731 },1642 },
1732 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {1643 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
...@@ -2005,8 +1916,6 @@ pub const Type = struct {...@@ -2005,8 +1916,6 @@ pub const Type = struct {
2005 .error_set_merged,1916 .error_set_merged,
2006 => return AbiAlignmentAdvanced{ .scalar = 2 },1917 => return AbiAlignmentAdvanced{ .scalar = 2 },
20071918
2008 .array, .array_sentinel => return ty.childType(mod).abiAlignmentAdvanced(mod, strat),
2009
2010 .optional => return abiAlignmentAdvancedOptional(ty, mod, strat),1919 .optional => return abiAlignmentAdvancedOptional(ty, mod, strat),
2011 .error_union => return abiAlignmentAdvancedErrorUnion(ty, mod, strat),1920 .error_union => return abiAlignmentAdvancedErrorUnion(ty, mod, strat),
20121921
...@@ -2385,29 +2294,6 @@ pub const Type = struct {...@@ -2385,29 +2294,6 @@ pub const Type = struct {
2385 return AbiSizeAdvanced{ .scalar = ty.structFieldOffset(field_count, mod) };2294 return AbiSizeAdvanced{ .scalar = ty.structFieldOffset(field_count, mod) };
2386 },2295 },
23872296
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 .anyframe_T => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },2297 .anyframe_T => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
24122298
2413 .pointer => switch (ty.castTag(.pointer).?.data.size) {2299 .pointer => switch (ty.castTag(.pointer).?.data.size) {
...@@ -2729,24 +2615,6 @@ pub const Type = struct {...@@ -2729,24 +2615,6 @@ pub const Type = struct {
2729 return total;2615 return total;
2730 },2616 },
27312617
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 .anyframe_T => return target.ptrBitWidth(),2618 .anyframe_T => return target.ptrBitWidth(),
27512619
2752 .pointer => switch (ty.castTag(.pointer).?.data.size) {2620 .pointer => switch (ty.castTag(.pointer).?.data.size) {
...@@ -3188,9 +3056,6 @@ pub const Type = struct {...@@ -3188,9 +3056,6 @@ pub const Type = struct {
3188 pub fn childTypeIp(ty: Type, ip: InternPool) Type {3056 pub fn childTypeIp(ty: Type, ip: InternPool) Type {
3189 return switch (ty.ip_index) {3057 return switch (ty.ip_index) {
3190 .none => switch (ty.tag()) {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 .pointer => ty.castTag(.pointer).?.data.pointee_type,3059 .pointer => ty.castTag(.pointer).?.data.pointee_type,
31953060
3196 else => unreachable,3061 else => unreachable,
...@@ -3211,9 +3076,6 @@ pub const Type = struct {...@@ -3211,9 +3076,6 @@ pub const Type = struct {
3211 pub fn elemType2(ty: Type, mod: *const Module) Type {3076 pub fn elemType2(ty: Type, mod: *const Module) Type {
3212 return switch (ty.ip_index) {3077 return switch (ty.ip_index) {
3213 .none => switch (ty.tag()) {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 .pointer => {3079 .pointer => {
3218 const info = ty.castTag(.pointer).?.data;3080 const info = ty.castTag(.pointer).?.data;
3219 const child_ty = info.pointee_type;3081 const child_ty = info.pointee_type;
...@@ -3483,8 +3345,6 @@ pub const Type = struct {...@@ -3483,8 +3345,6 @@ pub const Type = struct {
3483 return switch (ty.ip_index) {3345 return switch (ty.ip_index) {
3484 .empty_struct_type => 0,3346 .empty_struct_type => 0,
3485 .none => switch (ty.tag()) {3347 .none => switch (ty.tag()) {
3486 .array => ty.castTag(.array).?.data.len,
3487 .array_sentinel => ty.castTag(.array_sentinel).?.data.len,
3488 .tuple => ty.castTag(.tuple).?.data.types.len,3348 .tuple => ty.castTag(.tuple).?.data.types.len,
3489 .anon_struct => ty.castTag(.anon_struct).?.data.types.len,3349 .anon_struct => ty.castTag(.anon_struct).?.data.types.len,
34903350
...@@ -3524,12 +3384,9 @@ pub const Type = struct {...@@ -3524,12 +3384,9 @@ pub const Type = struct {
3524 pub fn sentinel(ty: Type, mod: *const Module) ?Value {3384 pub fn sentinel(ty: Type, mod: *const Module) ?Value {
3525 return switch (ty.ip_index) {3385 return switch (ty.ip_index) {
3526 .none => switch (ty.tag()) {3386 .none => switch (ty.tag()) {
3527 .array,3387 .tuple => null,
3528 .tuple,
3529 => null,
35303388
3531 .pointer => ty.castTag(.pointer).?.data.sentinel,3389 .pointer => ty.castTag(.pointer).?.data.sentinel,
3532 .array_sentinel => ty.castTag(.array_sentinel).?.data.sentinel,
35333390
3534 else => unreachable,3391 else => unreachable,
3535 },3392 },
...@@ -3832,7 +3689,6 @@ pub const Type = struct {...@@ -3832,7 +3689,6 @@ pub const Type = struct {
3832 .error_set,3689 .error_set,
3833 .error_set_merged,3690 .error_set_merged,
3834 .function,3691 .function,
3835 .array_sentinel,
3836 .error_set_inferred,3692 .error_set_inferred,
3837 .anyframe_T,3693 .anyframe_T,
3838 .pointer,3694 .pointer,
...@@ -3858,14 +3714,6 @@ pub const Type = struct {...@@ -3858,14 +3714,6 @@ pub const Type = struct {
3858 return Value.empty_struct;3714 return Value.empty_struct;
3859 },3715 },
38603716
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 .inferred_alloc_const => unreachable,3717 .inferred_alloc_const => unreachable,
3870 .inferred_alloc_mut => unreachable,3718 .inferred_alloc_mut => unreachable,
3871 },3719 },
...@@ -4034,10 +3882,6 @@ pub const Type = struct {...@@ -4034,10 +3882,6 @@ pub const Type = struct {
4034 .inferred_alloc_mut => unreachable,3882 .inferred_alloc_mut => unreachable,
4035 .inferred_alloc_const => unreachable,3883 .inferred_alloc_const => unreachable,
40363884
4037 .array,
4038 .array_sentinel,
4039 => return ty.childType(mod).comptimeOnly(mod),
4040
4041 .pointer => {3885 .pointer => {
4042 const child_ty = ty.childType(mod);3886 const child_ty = ty.childType(mod);
4043 if (child_ty.zigTypeTag(mod) == .Fn) {3887 if (child_ty.zigTypeTag(mod) == .Fn) {
...@@ -4804,8 +4648,6 @@ pub const Type = struct {...@@ -4804,8 +4648,6 @@ pub const Type = struct {
4804 inferred_alloc_const, // See last_no_payload_tag below.4648 inferred_alloc_const, // See last_no_payload_tag below.
4805 // After this, the tag requires a payload.4649 // After this, the tag requires a payload.
48064650
4807 array,
4808 array_sentinel,
4809 /// Possible Value tags for this: @"struct"4651 /// Possible Value tags for this: @"struct"
4810 tuple,4652 tuple,
4811 /// Possible Value tags for this: @"struct"4653 /// Possible Value tags for this: @"struct"
...@@ -4838,8 +4680,6 @@ pub const Type = struct {...@@ -4838,8 +4680,6 @@ pub const Type = struct {
4838 .error_set_inferred => Payload.ErrorSetInferred,4680 .error_set_inferred => Payload.ErrorSetInferred,
4839 .error_set_merged => Payload.ErrorSetMerged,4681 .error_set_merged => Payload.ErrorSetMerged,
48404682
4841 .array => Payload.Array,
4842 .array_sentinel => Payload.ArraySentinel,
4843 .pointer => Payload.Pointer,4683 .pointer => Payload.Pointer,
4844 .function => Payload.Function,4684 .function => Payload.Function,
4845 .error_union => Payload.ErrorUnion,4685 .error_union => Payload.ErrorUnion,
...@@ -4965,25 +4805,6 @@ pub const Type = struct {...@@ -4965,25 +4805,6 @@ pub const Type = struct {
4965 data: u64,4805 data: u64,
4966 };4806 };
49674807
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 pub const ElemType = struct {4808 pub const ElemType = struct {
4988 base: Payload,4809 base: Payload,
4989 data: Type,4810 data: Type,
...@@ -5269,35 +5090,14 @@ pub const Type = struct {...@@ -5269,35 +5090,14 @@ pub const Type = struct {
5269 elem_type: Type,5090 elem_type: Type,
5270 mod: *Module,5091 mod: *Module,
5271 ) Allocator.Error!Type {5092 ) Allocator.Error!Type {
5272 if (elem_type.ip_index != .none) {5093 // TODO: update callsites of this function to directly call mod.arrayType
5273 if (sent) |s| {5094 // and then delete this function.
5274 if (s.ip_index != .none) {5095 _ = arena;
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 }
52975096
5298 return Tag.array.create(arena, .{5097 return mod.arrayType(.{
5299 .len = len,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 }
53035103