authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-06-11 13:15:37+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-11 22:03:53-07:00
log63604024f47767b7b0c0deba5c9647cd6c040931
tree1233623946564f1cc87d34705f9fa02d1e2c8014
parent2afc689060e1d14e039f3c439d42f22ba09768a3

stage2: fix InternPool compile errors on 32-bit targets


6 files changed, 28 insertions(+), 24 deletions(-)

src/InternPool.zig+6-6
......@@ -3824,13 +3824,13 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
38243824 assert(child == .u8_type);
38253825 if (bytes.len != len) {
38263826 assert(bytes.len == len_including_sentinel);
3827 assert(bytes[len] == ip.indexToKey(sentinel).int.storage.u64);
3827 assert(bytes[@intCast(usize, len)] == ip.indexToKey(sentinel).int.storage.u64);
38283828 }
38293829 },
38303830 .elems => |elems| {
38313831 if (elems.len != len) {
38323832 assert(elems.len == len_including_sentinel);
3833 assert(elems[len] == sentinel);
3833 assert(elems[@intCast(usize, len)] == sentinel);
38343834 }
38353835 },
38363836 .repeated_elem => |elem| {
......@@ -3936,7 +3936,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
39363936
39373937 if (child == .u8_type) bytes: {
39383938 const string_bytes_index = ip.string_bytes.items.len;
3939 try ip.string_bytes.ensureUnusedCapacity(gpa, len_including_sentinel + 1);
3939 try ip.string_bytes.ensureUnusedCapacity(gpa, @intCast(usize, len_including_sentinel + 1));
39403940 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Bytes).Struct.fields.len);
39413941 switch (aggregate.storage) {
39423942 .bytes => |bytes| ip.string_bytes.appendSliceAssumeCapacity(bytes),
......@@ -3953,7 +3953,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
39533953 .repeated_elem => |elem| switch (ip.indexToKey(elem)) {
39543954 .undef => break :bytes,
39553955 .int => |int| @memset(
3956 ip.string_bytes.addManyAsSliceAssumeCapacity(len),
3956 ip.string_bytes.addManyAsSliceAssumeCapacity(@intCast(usize, len)),
39573957 @intCast(u8, int.storage.u64),
39583958 ),
39593959 else => unreachable,
......@@ -3967,7 +3967,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
39673967 const string = if (has_internal_null)
39683968 @intToEnum(String, string_bytes_index)
39693969 else
3970 (try ip.getOrPutTrailingString(gpa, len_including_sentinel)).toString();
3970 (try ip.getOrPutTrailingString(gpa, @intCast(usize, len_including_sentinel))).toString();
39713971 ip.items.appendAssumeCapacity(.{
39723972 .tag = .bytes,
39733973 .data = ip.addExtraAssumeCapacity(Bytes{
......@@ -3980,7 +3980,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
39803980
39813981 try ip.extra.ensureUnusedCapacity(
39823982 gpa,
3983 @typeInfo(Tag.Aggregate).Struct.fields.len + len_including_sentinel,
3983 @typeInfo(Tag.Aggregate).Struct.fields.len + @intCast(usize, len_including_sentinel),
39843984 );
39853985 ip.items.appendAssumeCapacity(.{
39863986 .tag = .aggregate,
src/Sema.zig+11-8
......@@ -28186,11 +28186,12 @@ fn beginComptimePtrMutation(
2818628186 const elem_abi_size_u64 = try sema.typeAbiSize(base_elem_ty);
2818728187 if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) {
2818828188 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
28189 const elem_idx = try sema.usizeCast(block, src, elem_ptr.index);
2818928190 return .{
2819028191 .mut_decl = parent.mut_decl,
2819128192 .pointee = .{ .reinterpret = .{
2819228193 .val_ptr = val_ptr,
28193 .byte_offset = elem_abi_size * elem_ptr.index,
28194 .byte_offset = elem_abi_size * elem_idx,
2819428195 } },
2819528196 .ty = parent.ty,
2819628197 };
......@@ -28223,7 +28224,7 @@ fn beginComptimePtrMutation(
2822328224 block,
2822428225 src,
2822528226 elem_ty,
28226 &elems[elem_ptr.index],
28227 &elems[@intCast(usize, elem_ptr.index)],
2822728228 ptr_elem_ty,
2822828229 parent.mut_decl,
2822928230 );
......@@ -28254,7 +28255,7 @@ fn beginComptimePtrMutation(
2825428255 block,
2825528256 src,
2825628257 elem_ty,
28257 &elems[elem_ptr.index],
28258 &elems[@intCast(usize, elem_ptr.index)],
2825828259 ptr_elem_ty,
2825928260 parent.mut_decl,
2826028261 );
......@@ -28265,7 +28266,7 @@ fn beginComptimePtrMutation(
2826528266 block,
2826628267 src,
2826728268 elem_ty,
28268 &val_ptr.castTag(.aggregate).?.data[elem_ptr.index],
28269 &val_ptr.castTag(.aggregate).?.data[@intCast(usize, elem_ptr.index)],
2826928270 ptr_elem_ty,
2827028271 parent.mut_decl,
2827128272 ),
......@@ -28291,7 +28292,7 @@ fn beginComptimePtrMutation(
2829128292 block,
2829228293 src,
2829328294 elem_ty,
28294 &elems[elem_ptr.index],
28295 &elems[@intCast(usize, elem_ptr.index)],
2829528296 ptr_elem_ty,
2829628297 parent.mut_decl,
2829728298 );
......@@ -28331,11 +28332,12 @@ fn beginComptimePtrMutation(
2833128332
2833228333 const elem_abi_size_u64 = try sema.typeAbiSize(base_elem_ty);
2833328334 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
28335 const elem_idx = try sema.usizeCast(block, src, elem_ptr.index);
2833428336 return ComptimePtrMutationKit{
2833528337 .mut_decl = parent.mut_decl,
2833628338 .pointee = .{ .reinterpret = .{
2833728339 .val_ptr = reinterpret.val_ptr,
28338 .byte_offset = reinterpret.byte_offset + elem_abi_size * elem_ptr.index,
28340 .byte_offset = reinterpret.byte_offset + elem_abi_size * elem_idx,
2833928341 } },
2834028342 .ty = parent.ty,
2834128343 };
......@@ -28750,9 +28752,10 @@ fn beginComptimePtrLoad(
2875028752 // the pointee array directly from our parent array.
2875128753 if (load_ty.isArrayOrVector(mod) and load_ty.childType(mod).eql(elem_ty, mod)) {
2875228754 const N = try sema.usizeCast(block, src, load_ty.arrayLenIncludingSentinel(mod));
28755 const elem_idx = try sema.usizeCast(block, src, elem_ptr.index);
2875328756 deref.pointee = if (elem_ptr.index + N <= check_len) TypedValue{
2875428757 .ty = try Type.array(sema.arena, N, null, elem_ty, mod),
28755 .val = try array_tv.val.sliceArray(mod, sema.arena, elem_ptr.index, elem_ptr.index + N),
28758 .val = try array_tv.val.sliceArray(mod, sema.arena, elem_idx, elem_idx + N),
2875628759 } else null;
2875728760 break :blk deref;
2875828761 }
......@@ -28773,7 +28776,7 @@ fn beginComptimePtrLoad(
2877328776 }
2877428777 deref.pointee = TypedValue{
2877528778 .ty = elem_ty,
28776 .val = try array_tv.val.elemValue(mod, elem_ptr.index),
28779 .val = try array_tv.val.elemValue(mod, @intCast(usize, elem_ptr.index)),
2877728780 };
2877828781 break :blk deref;
2877928782 },
src/TypedValue.zig+2-2
......@@ -356,12 +356,12 @@ pub fn print(
356356 if (container_ty.isTuple(mod)) {
357357 try writer.print("[{d}]", .{field.index});
358358 }
359 const field_name_ip = container_ty.structFieldName(field.index, mod);
359 const field_name_ip = container_ty.structFieldName(@intCast(usize, field.index), mod);
360360 const field_name = mod.intern_pool.stringToSlice(field_name_ip);
361361 try writer.print(".{}", .{std.zig.fmtId(field_name)});
362362 },
363363 .Union => {
364 const field_name_ip = container_ty.unionFields(mod).keys()[field.index];
364 const field_name_ip = container_ty.unionFields(mod).keys()[@intCast(usize, field.index)];
365365 const field_name = mod.intern_pool.stringToSlice(field_name_ip);
366366 try writer.print(".{}", .{std.zig.fmtId(field_name)});
367367 },
src/arch/wasm/CodeGen.zig+2-2
......@@ -2982,8 +2982,8 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value) InnerError!WValue {
29822982
29832983 const offset = switch (parent_ty.zigTypeTag(mod)) {
29842984 .Struct => switch (parent_ty.containerLayout(mod)) {
2985 .Packed => parent_ty.packedStructFieldByteOffset(field.index, mod),
2986 else => parent_ty.structFieldOffset(field.index, mod),
2985 .Packed => parent_ty.packedStructFieldByteOffset(@intCast(usize, field.index), mod),
2986 else => parent_ty.structFieldOffset(@intCast(usize, field.index), mod),
29872987 },
29882988 .Union => switch (parent_ty.containerLayout(mod)) {
29892989 .Packed => 0,
src/codegen/c.zig+1-1
......@@ -642,7 +642,7 @@ pub const DeclGen = struct {
642642 // Ensure complete type definition is visible before accessing fields.
643643 _ = try dg.typeToIndex(base_ty, .complete);
644644 const field_ty = switch (mod.intern_pool.indexToKey(base_ty.toIntern())) {
645 .anon_struct_type, .struct_type, .union_type => base_ty.structFieldType(field.index, mod),
645 .anon_struct_type, .struct_type, .union_type => base_ty.structFieldType(@intCast(usize, field.index), mod),
646646 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
647647 .One, .Many, .C => unreachable,
648648 .Slice => switch (field.index) {
src/value.zig+6-5
......@@ -395,7 +395,8 @@ pub const Value = struct {
395395 } });
396396 },
397397 .aggregate => {
398 const old_elems = val.castTag(.aggregate).?.data[0..ty.arrayLen(mod)];
398 const len = @intCast(usize, ty.arrayLen(mod));
399 const old_elems = val.castTag(.aggregate).?.data[0..len];
399400 const new_elems = try mod.gpa.alloc(InternPool.Index, old_elems.len);
400401 defer mod.gpa.free(new_elems);
401402 const ty_key = mod.intern_pool.indexToKey(ty.toIntern());
......@@ -642,7 +643,7 @@ pub const Value = struct {
642643 const base_addr = (try field.base.toValue().getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
643644 const struct_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);
644645 if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty);
645 return base_addr + struct_ty.structFieldOffset(field.index, mod);
646 return base_addr + struct_ty.structFieldOffset(@intCast(usize, field.index), mod);
646647 },
647648 else => null,
648649 },
......@@ -1798,10 +1799,10 @@ pub const Value = struct {
17981799 .int, .eu_payload => unreachable,
17991800 .opt_payload => |base| base.toValue().elemValue(mod, index),
18001801 .comptime_field => |field_val| field_val.toValue().elemValue(mod, index),
1801 .elem => |elem| elem.base.toValue().elemValue(mod, index + elem.index),
1802 .elem => |elem| elem.base.toValue().elemValue(mod, index + @intCast(usize, elem.index)),
18021803 .field => |field| if (field.base.toValue().pointerDecl(mod)) |decl_index| {
18031804 const base_decl = mod.declPtr(decl_index);
1804 const field_val = try base_decl.val.fieldValue(mod, field.index);
1805 const field_val = try base_decl.val.fieldValue(mod, @intCast(usize, field.index));
18051806 return field_val.elemValue(mod, index);
18061807 } else unreachable,
18071808 },
......@@ -1921,7 +1922,7 @@ pub const Value = struct {
19211922 .comptime_field => |comptime_field| comptime_field.toValue()
19221923 .sliceArray(mod, arena, start, end),
19231924 .elem => |elem| elem.base.toValue()
1924 .sliceArray(mod, arena, start + elem.index, end + elem.index),
1925 .sliceArray(mod, arena, start + @intCast(usize, elem.index), end + @intCast(usize, elem.index)),
19251926 else => unreachable,
19261927 },
19271928 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{