authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-07 16:14:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:29-07:00
log4fe0c583be8890b1cb8059c2daff3bd82c53d2e9
treee491e68236f5c090076459d63d475dce93aa0d84
parent4d88f825bc5eb14aa00446f046ab4714a4fdce70

stage2: more InternPool-related fixes


4 files changed, 57 insertions(+), 24 deletions(-)

src/Module.zig+1
......@@ -6716,6 +6716,7 @@ fn reportRetryableFileError(
67166716}
67176717
67186718pub fn markReferencedDeclsAlive(mod: *Module, val: Value) void {
6719 if (val.ip_index != .none) return;
67196720 switch (val.tag()) {
67206721 .decl_ref_mut => return mod.markDeclIndexAlive(val.castTag(.decl_ref_mut).?.data.decl_index),
67216722 .extern_fn => return mod.markDeclIndexAlive(val.castTag(.extern_fn).?.data.owner_decl),
src/Sema.zig+14-6
......@@ -12307,8 +12307,7 @@ fn zirShl(
1230712307 if (block.wantSafety()) {
1230812308 const bit_count = scalar_ty.intInfo(mod).bits;
1230912309 if (!std.math.isPowerOfTwo(bit_count)) {
12310 const bit_count_val = try mod.intValue(scalar_ty, bit_count);
12311
12310 const bit_count_val = try mod.intValue(scalar_rhs_ty, bit_count);
1231212311 const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: {
1231312312 const bit_count_inst = try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, bit_count_val));
1231412313 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);
......@@ -27391,10 +27390,19 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
2739127390 const prev_ptr = while (air_tags[ptr_inst] == .bitcast) {
2739227391 const prev_ptr = air_datas[ptr_inst].ty_op.operand;
2739327392 const prev_ptr_ty = sema.typeOf(prev_ptr);
27394 const prev_ptr_child_ty = switch (prev_ptr_ty.tag()) {
27395 .pointer => prev_ptr_ty.castTag(.pointer).?.data.pointee_type,
27396 else => return null,
27397 };
27393 if (prev_ptr_ty.zigTypeTag(mod) != .Pointer) return null;
27394
27395 // TODO: I noticed that the behavior tests do not pass if these two
27396 // checks are missing. I don't understand why the presence of inferred
27397 // allocations is relevant to this function, or why it would have
27398 // different behavior depending on whether the types were inferred.
27399 // Something seems wrong here.
27400 if (prev_ptr_ty.ip_index == .none) {
27401 if (prev_ptr_ty.tag() == .inferred_alloc_mut) return null;
27402 if (prev_ptr_ty.tag() == .inferred_alloc_const) return null;
27403 }
27404
27405 const prev_ptr_child_ty = prev_ptr_ty.childType(mod);
2739827406 if (prev_ptr_child_ty.zigTypeTag(mod) == .Vector) break prev_ptr;
2739927407 ptr_inst = Air.refToIndex(prev_ptr) orelse return null;
2740027408 } else return null;
src/type.zig+15-8
......@@ -2058,16 +2058,23 @@ pub const Type = struct {
20582058 }
20592059 }
20602060
2061 pub fn ptrAddressSpace(self: Type, mod: *const Module) std.builtin.AddressSpace {
2062 return switch (self.tag()) {
2063 .pointer => self.castTag(.pointer).?.data.@"addrspace",
2061 pub fn ptrAddressSpace(ty: Type, mod: *const Module) std.builtin.AddressSpace {
2062 return switch (ty.ip_index) {
2063 .none => switch (ty.tag()) {
2064 .pointer => ty.castTag(.pointer).?.data.@"addrspace",
20642065
2065 .optional => {
2066 const child_type = self.optionalChild(mod);
2067 return child_type.ptrAddressSpace(mod);
2068 },
2066 .optional => {
2067 const child_type = ty.optionalChild(mod);
2068 return child_type.ptrAddressSpace(mod);
2069 },
20692070
2070 else => unreachable,
2071 else => unreachable,
2072 },
2073 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
2074 .ptr_type => |ptr_type| ptr_type.address_space,
2075 .opt_type => |child| mod.intern_pool.indexToKey(child).ptr_type.address_space,
2076 else => unreachable,
2077 },
20712078 };
20722079 }
20732080
src/value.zig+27-10
......@@ -644,15 +644,32 @@ pub const Value = struct {
644644
645645 /// Asserts the type is an enum type.
646646 pub fn toEnum(val: Value, comptime E: type) E {
647 switch (val.tag()) {
648 .enum_field_index => {
649 const field_index = val.castTag(.enum_field_index).?.data;
650 return @intToEnum(E, field_index);
647 switch (val.ip_index) {
648 .calling_convention_c => {
649 if (E == std.builtin.CallingConvention) {
650 return .C;
651 } else {
652 unreachable;
653 }
654 },
655 .calling_convention_inline => {
656 if (E == std.builtin.CallingConvention) {
657 return .Inline;
658 } else {
659 unreachable;
660 }
651661 },
652 .the_only_possible_value => {
653 const fields = std.meta.fields(E);
654 assert(fields.len == 1);
655 return @intToEnum(E, fields[0].value);
662 .none => switch (val.tag()) {
663 .enum_field_index => {
664 const field_index = val.castTag(.enum_field_index).?.data;
665 return @intToEnum(E, field_index);
666 },
667 .the_only_possible_value => {
668 const fields = std.meta.fields(E);
669 assert(fields.len == 1);
670 return @intToEnum(E, fields[0].value);
671 },
672 else => unreachable,
656673 },
657674 else => unreachable,
658675 }
......@@ -2177,7 +2194,7 @@ pub const Value = struct {
21772194 std.hash.autoHash(hasher, zig_ty_tag);
21782195 if (val.isUndef()) return;
21792196 // The value is runtime-known and shouldn't affect the hash.
2180 if (val.tag() == .runtime_value) return;
2197 if (val.isRuntimeValue()) return;
21812198
21822199 switch (zig_ty_tag) {
21832200 .Opaque => unreachable, // Cannot hash opaque types
......@@ -2323,7 +2340,7 @@ pub const Value = struct {
23232340 pub fn hashUncoerced(val: Value, ty: Type, hasher: *std.hash.Wyhash, mod: *Module) void {
23242341 if (val.isUndef()) return;
23252342 // The value is runtime-known and shouldn't affect the hash.
2326 if (val.tag() == .runtime_value) return;
2343 if (val.isRuntimeValue()) return;
23272344
23282345 switch (ty.zigTypeTag(mod)) {
23292346 .Opaque => unreachable, // Cannot hash opaque types