authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-29 08:21:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:56-07:00
loga702af062bb65673ba554dba330b4c5ca8d50f3e
tree042542e3bc6359b739e70af5b8bd3f2a3b9b0932
parent4f70863a55e699c13731325f8c52870119479c02

x86_64: fix InternPool regressions


3 files changed, 61 insertions(+), 48 deletions(-)

src/Sema.zig+8-2
......@@ -24311,7 +24311,10 @@ fn fieldVal(
2431124311 .inferred_error_set_type => {
2431224312 return sema.fail(block, src, "TODO handle inferred error sets here", .{});
2431324313 },
24314 .simple_type => |t| assert(t == .anyerror),
24314 .simple_type => |t| {
24315 assert(t == .anyerror);
24316 _ = try mod.getErrorValue(field_name);
24317 },
2431524318 else => unreachable,
2431624319 }
2431724320
......@@ -24529,7 +24532,10 @@ fn fieldPtr(
2452924532 .inferred_error_set_type => {
2453024533 return sema.fail(block, src, "TODO handle inferred error sets here", .{});
2453124534 },
24532 .simple_type => |t| assert(t == .anyerror),
24535 .simple_type => |t| {
24536 assert(t == .anyerror);
24537 _ = try mod.getErrorValue(field_name);
24538 },
2453324539 else => unreachable,
2453424540 }
2453524541
src/arch/x86_64/CodeGen.zig+1-4
......@@ -2128,10 +2128,7 @@ fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Live
21282128 const dies = @truncate(u1, tomb_bits) != 0;
21292129 tomb_bits >>= 1;
21302130 if (!dies) continue;
2131 const op_int = @enumToInt(op);
2132 if (op_int < Air.ref_start_index) continue;
2133 const op_index = @intCast(Air.Inst.Index, op_int - Air.ref_start_index);
2134 self.processDeath(op_index);
2131 self.processDeath(Air.refToIndexAllowNone(op) orelse continue);
21352132 }
21362133 self.finishAirResult(inst, result);
21372134}
src/codegen.zig+52-42
......@@ -387,22 +387,24 @@ pub fn generateSymbol(
387387 },
388388 .aggregate => |aggregate| switch (mod.intern_pool.indexToKey(typed_value.ty.toIntern())) {
389389 .array_type => |array_type| {
390 var index: u64 = 0;
391 while (index < array_type.len) : (index += 1) {
392 switch (aggregate.storage) {
393 .bytes => |bytes| try code.appendSlice(bytes),
394 .elems, .repeated_elem => switch (try generateSymbol(bin_file, src_loc, .{
395 .ty = array_type.child.toType(),
396 .val = switch (aggregate.storage) {
397 .bytes => unreachable,
398 .elems => |elems| elems[@intCast(usize, index)],
399 .repeated_elem => |elem| elem,
400 }.toValue(),
401 }, code, debug_output, reloc_info)) {
402 .ok => {},
403 .fail => |em| return .{ .fail = em },
404 },
405 }
390 switch (aggregate.storage) {
391 .bytes => |bytes| try code.appendSlice(bytes),
392 .elems, .repeated_elem => {
393 var index: u64 = 0;
394 while (index < array_type.len) : (index += 1) {
395 switch (try generateSymbol(bin_file, src_loc, .{
396 .ty = array_type.child.toType(),
397 .val = switch (aggregate.storage) {
398 .bytes => unreachable,
399 .elems => |elems| elems[@intCast(usize, index)],
400 .repeated_elem => |elem| elem,
401 }.toValue(),
402 }, code, debug_output, reloc_info)) {
403 .ok => {},
404 .fail => |em| return .{ .fail = em },
405 }
406 }
407 },
406408 }
407409
408410 if (array_type.sentinel != .none) {
......@@ -416,22 +418,24 @@ pub fn generateSymbol(
416418 }
417419 },
418420 .vector_type => |vector_type| {
419 var index: u32 = 0;
420 while (index < vector_type.len) : (index += 1) {
421 switch (aggregate.storage) {
422 .bytes => |bytes| try code.appendSlice(bytes),
423 .elems, .repeated_elem => switch (try generateSymbol(bin_file, src_loc, .{
424 .ty = vector_type.child.toType(),
425 .val = switch (aggregate.storage) {
426 .bytes => unreachable,
427 .elems => |elems| elems[@intCast(usize, index)],
428 .repeated_elem => |elem| elem,
429 }.toValue(),
430 }, code, debug_output, reloc_info)) {
431 .ok => {},
432 .fail => |em| return .{ .fail = em },
433 },
434 }
421 switch (aggregate.storage) {
422 .bytes => |bytes| try code.appendSlice(bytes),
423 .elems, .repeated_elem => {
424 var index: u64 = 0;
425 while (index < vector_type.len) : (index += 1) {
426 switch (try generateSymbol(bin_file, src_loc, .{
427 .ty = vector_type.child.toType(),
428 .val = switch (aggregate.storage) {
429 .bytes => unreachable,
430 .elems => |elems| elems[@intCast(usize, index)],
431 .repeated_elem => |elem| elem,
432 }.toValue(),
433 }, code, debug_output, reloc_info)) {
434 .ok => {},
435 .fail => |em| return .{ .fail = em },
436 }
437 }
438 },
435439 }
436440
437441 const padding = math.cast(usize, typed_value.ty.abiSize(mod) -
......@@ -669,7 +673,7 @@ fn lowerParentPtr(
669673 mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod))),
670674 ),
671675 .field => |field| {
672 const base_type = mod.intern_pool.typeOf(field.base);
676 const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.elem_type;
673677 return lowerParentPtr(
674678 bin_file,
675679 src_loc,
......@@ -688,7 +692,7 @@ fn lowerParentPtr(
688692 .struct_type,
689693 .anon_struct_type,
690694 .union_type,
691 => @intCast(u32, base_type.toType().childType(mod).structFieldOffset(
695 => @intCast(u32, base_type.toType().structFieldOffset(
692696 @intCast(u32, field.index),
693697 mod,
694698 )),
......@@ -989,17 +993,23 @@ pub fn genTypedValue(
989993 return GenResult.mcv(.{ .immediate = error_index });
990994 },
991995 .ErrorUnion => {
992 const error_type = typed_value.ty.errorUnionSet(mod);
996 const err_type = typed_value.ty.errorUnionSet(mod);
993997 const payload_type = typed_value.ty.errorUnionPayload(mod);
994 const is_pl = typed_value.val.errorUnionIsPayload(mod);
995
996998 if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) {
997999 // We use the error type directly as the type.
998 const err_val = if (!is_pl) typed_value.val else try mod.intValue(error_type, 0);
999 return genTypedValue(bin_file, src_loc, .{
1000 .ty = error_type,
1001 .val = err_val,
1002 }, owner_decl_index);
1000 switch (mod.intern_pool.indexToKey(typed_value.val.toIntern()).error_union.val) {
1001 .err_name => |err_name| return genTypedValue(bin_file, src_loc, .{
1002 .ty = err_type,
1003 .val = (try mod.intern(.{ .err = .{
1004 .ty = err_type.toIntern(),
1005 .name = err_name,
1006 } })).toValue(),
1007 }, owner_decl_index),
1008 .payload => return genTypedValue(bin_file, src_loc, .{
1009 .ty = Type.err_int,
1010 .val = try mod.intValue(Type.err_int, 0),
1011 }, owner_decl_index),
1012 }
10031013 }
10041014 },
10051015