authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-03 20:04:47-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:40:04-07:00
log85c69c51945d7fb5d4cd2dea03fdb7915ecc55fa
tree2705f666129a04e8100861d056f6df9bb89fd582
parentfb16ad3add77eff23f9c5dbaf802fdecfb4c8cc0

Type.isSlice: make it InternPool aware


16 files changed, 341 insertions(+), 287 deletions(-)

src/InternPool.zig+45-5
...@@ -629,7 +629,7 @@ pub const Tag = enum(u8) {...@@ -629,7 +629,7 @@ pub const Tag = enum(u8) {
629 /// A vector type.629 /// A vector type.
630 /// data is payload to Vector.630 /// data is payload to Vector.
631 type_vector,631 type_vector,
632 /// A pointer type along with all its bells and whistles.632 /// A fully explicitly specified pointer type.
633 /// data is payload to Pointer.633 /// data is payload to Pointer.
634 type_pointer,634 type_pointer,
635 /// An optional type.635 /// An optional type.
...@@ -682,13 +682,13 @@ pub const Tag = enum(u8) {...@@ -682,13 +682,13 @@ pub const Tag = enum(u8) {
682 /// An enum tag identified by a negative integer value.682 /// An enum tag identified by a negative integer value.
683 /// data is a limbs index to Int.683 /// data is a limbs index to Int.
684 enum_tag_negative,684 enum_tag_negative,
685 /// A float value that can be represented by f32.685 /// An f32 value.
686 /// data is float value bitcasted to u32.686 /// data is float value bitcasted to u32.
687 float_f32,687 float_f32,
688 /// A float value that can be represented by f64.688 /// An f64 value.
689 /// data is payload index to Float64.689 /// data is payload index to Float64.
690 float_f64,690 float_f64,
691 /// A float value that can be represented by f128.691 /// An f128 value.
692 /// data is payload index to Float128.692 /// data is payload index to Float128.
693 float_f128,693 float_f128,
694 /// An extern function.694 /// An extern function.
...@@ -871,7 +871,47 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {...@@ -871,7 +871,47 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
871 .simple_type => .{ .simple_type = @intToEnum(SimpleType, data) },871 .simple_type => .{ .simple_type = @intToEnum(SimpleType, data) },
872 .simple_value => .{ .simple_value = @intToEnum(SimpleValue, data) },872 .simple_value => .{ .simple_value = @intToEnum(SimpleValue, data) },
873873
874 else => @panic("TODO"),874 .type_vector => {
875 const vector_info = ip.extraData(Vector, data);
876 return .{ .vector_type = .{
877 .len = vector_info.len,
878 .child = vector_info.child,
879 } };
880 },
881
882 .type_pointer => {
883 const ptr_info = ip.extraData(Pointer, data);
884 return .{ .ptr_type = .{
885 .elem_type = ptr_info.child,
886 .sentinel = ptr_info.sentinel,
887 .alignment = ptr_info.flags.alignment,
888 .size = ptr_info.flags.size,
889 .is_const = ptr_info.flags.is_const,
890 .is_volatile = ptr_info.flags.is_volatile,
891 .is_allowzero = ptr_info.flags.is_allowzero,
892 .address_space = ptr_info.flags.address_space,
893 } };
894 },
895
896 .type_optional => .{ .optional_type = .{ .payload_type = @intToEnum(Index, data) } },
897
898 .type_error_union => @panic("TODO"),
899 .type_enum_simple => @panic("TODO"),
900 .simple_internal => @panic("TODO"),
901 .int_small_u32 => @panic("TODO"),
902 .int_small_i32 => @panic("TODO"),
903 .int_small_usize => @panic("TODO"),
904 .int_small_comptime_unsigned => @panic("TODO"),
905 .int_small_comptime_signed => @panic("TODO"),
906 .int_positive => @panic("TODO"),
907 .int_negative => @panic("TODO"),
908 .enum_tag_positive => @panic("TODO"),
909 .enum_tag_negative => @panic("TODO"),
910 .float_f32 => @panic("TODO"),
911 .float_f64 => @panic("TODO"),
912 .float_f128 => @panic("TODO"),
913 .extern_func => @panic("TODO"),
914 .func => @panic("TODO"),
875 };915 };
876}916}
877917
src/Sema.zig+28-28
...@@ -2030,7 +2030,7 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty...@@ -2030,7 +2030,7 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty
2030 ty.fmt(mod),2030 ty.fmt(mod),
2031 });2031 });
2032 errdefer msg.destroy(sema.gpa);2032 errdefer msg.destroy(sema.gpa);
2033 if (ty.isSlice()) {2033 if (ty.isSlice(mod)) {
2034 try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});2034 try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});
2035 }2035 }
2036 break :msg msg;2036 break :msg msg;
...@@ -10359,7 +10359,7 @@ fn zirSwitchCond(...@@ -10359,7 +10359,7 @@ fn zirSwitchCond(
10359 .ErrorSet,10359 .ErrorSet,
10360 .Enum,10360 .Enum,
10361 => {10361 => {
10362 if (operand_ty.isSlice()) {10362 if (operand_ty.isSlice(mod)) {
10363 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)});10363 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)});
10364 }10364 }
10365 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {10365 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {
...@@ -12017,7 +12017,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12017,7 +12017,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12017 const ty = try sema.resolveTypeFields(unresolved_ty);12017 const ty = try sema.resolveTypeFields(unresolved_ty);
1201812018
12019 const has_field = hf: {12019 const has_field = hf: {
12020 if (ty.isSlice()) {12020 if (ty.isSlice(mod)) {
12021 if (mem.eql(u8, field_name, "ptr")) break :hf true;12021 if (mem.eql(u8, field_name, "ptr")) break :hf true;
12022 if (mem.eql(u8, field_name, "len")) break :hf true;12022 if (mem.eql(u8, field_name, "len")) break :hf true;
12023 break :hf false;12023 break :hf false;
...@@ -20020,8 +20020,8 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -20020,8 +20020,8 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20020 return sema.failWithOwnedErrorMsg(msg);20020 return sema.failWithOwnedErrorMsg(msg);
20021 }20021 }
2002220022
20023 const dest_is_slice = dest_ty.isSlice();20023 const dest_is_slice = dest_ty.isSlice(mod);
20024 const operand_is_slice = operand_ty.isSlice();20024 const operand_is_slice = operand_ty.isSlice(mod);
20025 if (dest_is_slice and !operand_is_slice) {20025 if (dest_is_slice and !operand_is_slice) {
20026 return sema.fail(block, dest_ty_src, "illegal pointer cast to slice", .{});20026 return sema.fail(block, dest_ty_src, "illegal pointer cast to slice", .{});
20027 }20027 }
...@@ -20274,14 +20274,14 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -20274,14 +20274,14 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
20274 Type.usize,20274 Type.usize,
20275 Value.initPayload(&val_payload.base),20275 Value.initPayload(&val_payload.base),
20276 );20276 );
20277 const actual_ptr = if (ptr_ty.isSlice())20277 const actual_ptr = if (ptr_ty.isSlice(mod))
20278 try sema.analyzeSlicePtr(block, ptr_src, ptr, ptr_ty)20278 try sema.analyzeSlicePtr(block, ptr_src, ptr, ptr_ty)
20279 else20279 else
20280 ptr;20280 ptr;
20281 const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr);20281 const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr);
20282 const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1);20282 const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1);
20283 const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize);20283 const is_aligned = try block.addBinOp(.cmp_eq, remainder, .zero_usize);
20284 const ok = if (ptr_ty.isSlice()) ok: {20284 const ok = if (ptr_ty.isSlice(mod)) ok: {
20285 const len = try sema.analyzeSliceLen(block, ptr_src, ptr);20285 const len = try sema.analyzeSliceLen(block, ptr_src, ptr);
20286 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);20286 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
20287 break :ok try block.addBinOp(.bit_or, len_zero, is_aligned);20287 break :ok try block.addBinOp(.bit_or, len_zero, is_aligned);
...@@ -22336,7 +22336,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -22336,7 +22336,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
22336 // Change the src from slice to a many pointer, to avoid multiple ptr22336 // Change the src from slice to a many pointer, to avoid multiple ptr
22337 // slice extractions in AIR instructions.22337 // slice extractions in AIR instructions.
22338 const new_src_ptr_ty = sema.typeOf(new_src_ptr);22338 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
22339 if (new_src_ptr_ty.isSlice()) {22339 if (new_src_ptr_ty.isSlice(mod)) {
22340 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);22340 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
22341 }22341 }
22342 } else if (dest_len == .none and len_val == null) {22342 } else if (dest_len == .none and len_val == null) {
...@@ -22344,7 +22344,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -22344,7 +22344,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
22344 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);22344 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
22345 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false);22345 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false);
22346 const new_src_ptr_ty = sema.typeOf(new_src_ptr);22346 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
22347 if (new_src_ptr_ty.isSlice()) {22347 if (new_src_ptr_ty.isSlice(mod)) {
22348 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);22348 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
22349 }22349 }
22350 }22350 }
...@@ -22363,7 +22363,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -22363,7 +22363,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
22363 // Extract raw pointer from dest slice. The AIR instructions could support them, but22363 // Extract raw pointer from dest slice. The AIR instructions could support them, but
22364 // it would cause redundant machine code instructions.22364 // it would cause redundant machine code instructions.
22365 const new_dest_ptr_ty = sema.typeOf(new_dest_ptr);22365 const new_dest_ptr_ty = sema.typeOf(new_dest_ptr);
22366 const raw_dest_ptr = if (new_dest_ptr_ty.isSlice())22366 const raw_dest_ptr = if (new_dest_ptr_ty.isSlice(mod))
22367 try sema.analyzeSlicePtr(block, dest_src, new_dest_ptr, new_dest_ptr_ty)22367 try sema.analyzeSlicePtr(block, dest_src, new_dest_ptr, new_dest_ptr_ty)
22368 else22368 else
22369 new_dest_ptr;22369 new_dest_ptr;
...@@ -23383,7 +23383,7 @@ fn validateExternType(...@@ -23383,7 +23383,7 @@ fn validateExternType(
23383 .Float,23383 .Float,
23384 .AnyFrame,23384 .AnyFrame,
23385 => return true,23385 => return true,
23386 .Pointer => return !(ty.isSlice() or try sema.typeRequiresComptime(ty)),23386 .Pointer => return !(ty.isSlice(mod) or try sema.typeRequiresComptime(ty)),
23387 .Int => switch (ty.intInfo(mod).bits) {23387 .Int => switch (ty.intInfo(mod).bits) {
23388 8, 16, 32, 64, 128 => return true,23388 8, 16, 32, 64, 128 => return true,
23389 else => return false,23389 else => return false,
...@@ -23448,7 +23448,7 @@ fn explainWhyTypeIsNotExtern(...@@ -23448,7 +23448,7 @@ fn explainWhyTypeIsNotExtern(
23448 => return,23448 => return,
2344923449
23450 .Pointer => {23450 .Pointer => {
23451 if (ty.isSlice()) {23451 if (ty.isSlice(mod)) {
23452 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});23452 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
23453 } else {23453 } else {
23454 const pointee_ty = ty.childType();23454 const pointee_ty = ty.childType();
...@@ -23523,7 +23523,7 @@ fn validatePackedType(ty: Type, mod: *const Module) bool {...@@ -23523,7 +23523,7 @@ fn validatePackedType(ty: Type, mod: *const Module) bool {
23523 .Vector,23523 .Vector,
23524 .Enum,23524 .Enum,
23525 => return true,23525 => return true,
23526 .Pointer => return !ty.isSlice(),23526 .Pointer => return !ty.isSlice(mod),
23527 .Struct, .Union => return ty.containerLayout() == .Packed,23527 .Struct, .Union => return ty.containerLayout() == .Packed,
23528 }23528 }
23529}23529}
...@@ -23803,7 +23803,7 @@ fn panicSentinelMismatch(...@@ -23803,7 +23803,7 @@ fn panicSentinelMismatch(
23803 const expected_sentinel = try sema.addConstant(sentinel_ty, expected_sentinel_val);23803 const expected_sentinel = try sema.addConstant(sentinel_ty, expected_sentinel_val);
2380423804
23805 const ptr_ty = sema.typeOf(ptr);23805 const ptr_ty = sema.typeOf(ptr);
23806 const actual_sentinel = if (ptr_ty.isSlice())23806 const actual_sentinel = if (ptr_ty.isSlice(mod))
23807 try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index)23807 try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index)
23808 else blk: {23808 else blk: {
23809 const elem_ptr_ty = try sema.elemPtrType(ptr_ty, null);23809 const elem_ptr_ty = try sema.elemPtrType(ptr_ty, null);
...@@ -24064,7 +24064,7 @@ fn fieldVal(...@@ -24064,7 +24064,7 @@ fn fieldVal(
24064 const msg = msg: {24064 const msg = msg: {
24065 const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)});24065 const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)});
24066 errdefer msg.destroy(sema.gpa);24066 errdefer msg.destroy(sema.gpa);
24067 if (child_type.isSlice()) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{});24067 if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{});
24068 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{});24068 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{});
24069 break :msg msg;24069 break :msg msg;
24070 };24070 };
...@@ -24140,7 +24140,7 @@ fn fieldPtr(...@@ -24140,7 +24140,7 @@ fn fieldPtr(
24140 );24140 );
24141 }24141 }
24142 },24142 },
24143 .Pointer => if (inner_ty.isSlice()) {24143 .Pointer => if (inner_ty.isSlice(mod)) {
24144 const inner_ptr = if (is_pointer_to)24144 const inner_ptr = if (is_pointer_to)
24145 try sema.analyzeLoad(block, src, object_ptr, object_ptr_src)24145 try sema.analyzeLoad(block, src, object_ptr, object_ptr_src)
24146 else24146 else
...@@ -25743,8 +25743,8 @@ fn coerceExtra(...@@ -25743,8 +25743,8 @@ fn coerceExtra(
25743 } };25743 } };
25744 break :pointer;25744 break :pointer;
25745 }25745 }
25746 if (dest_ty.isSlice()) break :to_anyopaque;25746 if (dest_ty.isSlice(mod)) break :to_anyopaque;
25747 if (inst_ty.isSlice()) {25747 if (inst_ty.isSlice(mod)) {
25748 in_memory_result = .{ .slice_to_anyopaque = .{25748 in_memory_result = .{ .slice_to_anyopaque = .{
25749 .actual = inst_ty,25749 .actual = inst_ty,
25750 .wanted = dest_ty,25750 .wanted = dest_ty,
...@@ -25885,7 +25885,7 @@ fn coerceExtra(...@@ -25885,7 +25885,7 @@ fn coerceExtra(
25885 return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src);25885 return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src);
25886 },25886 },
25887 .Many => p: {25887 .Many => p: {
25888 if (!inst_ty.isSlice()) break :p;25888 if (!inst_ty.isSlice(mod)) break :p;
25889 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :p;25889 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :p;
25890 const inst_info = inst_ty.ptrInfo().data;25890 const inst_info = inst_ty.ptrInfo().data;
2589125891
...@@ -26651,7 +26651,7 @@ fn coerceInMemoryAllowed(...@@ -26651,7 +26651,7 @@ fn coerceInMemoryAllowed(
26651 }26651 }
2665226652
26653 // Slices26653 // Slices
26654 if (dest_ty.isSlice() and src_ty.isSlice()) {26654 if (dest_ty.isSlice(mod) and src_ty.isSlice(mod)) {
26655 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ty, src_ty, dest_is_mut, target, dest_src, src_src);26655 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ty, src_ty, dest_is_mut, target, dest_src, src_src);
26656 }26656 }
2665726657
...@@ -27744,7 +27744,7 @@ fn beginComptimePtrMutation(...@@ -27744,7 +27744,7 @@ fn beginComptimePtrMutation(
27744 );27744 );
27745 },27745 },
27746 .Pointer => {27746 .Pointer => {
27747 assert(parent.ty.isSlice());27747 assert(parent.ty.isSlice(mod));
27748 val_ptr.* = try Value.Tag.slice.create(arena, .{27748 val_ptr.* = try Value.Tag.slice.create(arena, .{
27749 .ptr = Value.undef,27749 .ptr = Value.undef,
27750 .len = Value.undef,27750 .len = Value.undef,
...@@ -28187,7 +28187,7 @@ fn beginComptimePtrLoad(...@@ -28187,7 +28187,7 @@ fn beginComptimePtrLoad(
28187 break :blk deref;28187 break :blk deref;
28188 }28188 }
2818928189
28190 if (field_ptr.container_ty.isSlice()) {28190 if (field_ptr.container_ty.isSlice(mod)) {
28191 const slice_val = tv.val.castTag(.slice).?.data;28191 const slice_val = tv.val.castTag(.slice).?.data;
28192 deref.pointee = switch (field_index) {28192 deref.pointee = switch (field_index) {
28193 Value.Payload.Slice.ptr_index => TypedValue{28193 Value.Payload.Slice.ptr_index => TypedValue{
...@@ -28442,13 +28442,13 @@ fn coerceCompatiblePtrs(...@@ -28442,13 +28442,13 @@ fn coerceCompatiblePtrs(
28442 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(mod) and28442 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(mod) and
28443 (try sema.typeHasRuntimeBits(dest_ty.elemType2(mod)) or dest_ty.elemType2(mod).zigTypeTag(mod) == .Fn))28443 (try sema.typeHasRuntimeBits(dest_ty.elemType2(mod)) or dest_ty.elemType2(mod).zigTypeTag(mod) == .Fn))
28444 {28444 {
28445 const actual_ptr = if (inst_ty.isSlice())28445 const actual_ptr = if (inst_ty.isSlice(mod))
28446 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)28446 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
28447 else28447 else
28448 inst;28448 inst;
28449 const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr);28449 const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr);
28450 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);28450 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
28451 const ok = if (inst_ty.isSlice()) ok: {28451 const ok = if (inst_ty.isSlice(mod)) ok: {
28452 const len = try sema.analyzeSliceLen(block, inst_src, inst);28452 const len = try sema.analyzeSliceLen(block, inst_src, inst);
28453 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);28453 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
28454 break :ok try block.addBinOp(.bit_or, len_zero, is_non_zero);28454 break :ok try block.addBinOp(.bit_or, len_zero, is_non_zero);
...@@ -29548,7 +29548,7 @@ fn analyzeSlice(...@@ -29548,7 +29548,7 @@ fn analyzeSlice(
29548 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}),29548 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}),
29549 }29549 }
2955029550
29551 const ptr = if (slice_ty.isSlice())29551 const ptr = if (slice_ty.isSlice(mod))
29552 try sema.analyzeSlicePtr(block, ptr_src, ptr_or_slice, slice_ty)29552 try sema.analyzeSlicePtr(block, ptr_src, ptr_or_slice, slice_ty)
29553 else29553 else
29554 ptr_or_slice;29554 ptr_or_slice;
...@@ -29605,7 +29605,7 @@ fn analyzeSlice(...@@ -29605,7 +29605,7 @@ fn analyzeSlice(
29605 }29605 }
2960629606
29607 break :e try sema.addConstant(Type.usize, len_val);29607 break :e try sema.addConstant(Type.usize, len_val);
29608 } else if (slice_ty.isSlice()) {29608 } else if (slice_ty.isSlice(mod)) {
29609 if (!end_is_len) {29609 if (!end_is_len) {
29610 const end = if (by_length) end: {29610 const end = if (by_length) end: {
29611 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);29611 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
...@@ -29778,7 +29778,7 @@ fn analyzeSlice(...@@ -29778,7 +29778,7 @@ fn analyzeSlice(
29778 try sema.addSafetyCheck(block, is_non_null, .unwrap_null);29778 try sema.addSafetyCheck(block, is_non_null, .unwrap_null);
29779 }29779 }
2978029780
29781 if (slice_ty.isSlice()) {29781 if (slice_ty.isSlice(mod)) {
29782 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);29782 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
29783 const actual_len = if (slice_ty.sentinel() == null)29783 const actual_len = if (slice_ty.sentinel() == null)
29784 slice_len_inst29784 slice_len_inst
...@@ -29840,7 +29840,7 @@ fn analyzeSlice(...@@ -29840,7 +29840,7 @@ fn analyzeSlice(
29840 // requirement: end <= len29840 // requirement: end <= len
29841 const opt_len_inst = if (array_ty.zigTypeTag(mod) == .Array)29841 const opt_len_inst = if (array_ty.zigTypeTag(mod) == .Array)
29842 try sema.addIntUnsigned(Type.usize, array_ty.arrayLenIncludingSentinel())29842 try sema.addIntUnsigned(Type.usize, array_ty.arrayLenIncludingSentinel())
29843 else if (slice_ty.isSlice()) blk: {29843 else if (slice_ty.isSlice(mod)) blk: {
29844 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {29844 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {
29845 // we don't need to add one for sentinels because the29845 // we don't need to add one for sentinels because the
29846 // underlying value data includes the sentinel29846 // underlying value data includes the sentinel
src/TypedValue.zig+1-1
...@@ -259,7 +259,7 @@ pub fn print(...@@ -259,7 +259,7 @@ pub fn print(
259 } else if (field_ptr.container_ty.zigTypeTag(mod) == .Union) {259 } else if (field_ptr.container_ty.zigTypeTag(mod) == .Union) {
260 const field_name = field_ptr.container_ty.unionFields().keys()[field_ptr.field_index];260 const field_name = field_ptr.container_ty.unionFields().keys()[field_ptr.field_index];
261 return writer.print(".{s}", .{field_name});261 return writer.print(".{s}", .{field_name});
262 } else if (field_ptr.container_ty.isSlice()) {262 } else if (field_ptr.container_ty.isSlice(mod)) {
263 switch (field_ptr.field_index) {263 switch (field_ptr.field_index) {
264 Value.Payload.Slice.ptr_index => return writer.writeAll(".ptr"),264 Value.Payload.Slice.ptr_index => return writer.writeAll(".ptr"),
265 Value.Payload.Slice.len_index => return writer.writeAll(".len"),265 Value.Payload.Slice.len_index => return writer.writeAll(".len"),
src/arch/aarch64/abi.zig+1-1
...@@ -52,7 +52,7 @@ pub fn classifyType(ty: Type, mod: *const Module) Class {...@@ -52,7 +52,7 @@ pub fn classifyType(ty: Type, mod: *const Module) Class {
52 return .byval;52 return .byval;
53 },53 },
54 .Pointer => {54 .Pointer => {
55 std.debug.assert(!ty.isSlice());55 std.debug.assert(!ty.isSlice(mod));
56 return .byval;56 return .byval;
57 },57 },
58 .ErrorUnion,58 .ErrorUnion,
src/arch/arm/abi.zig+1-1
...@@ -94,7 +94,7 @@ pub fn classifyType(ty: Type, mod: *const Module, ctx: Context) Class {...@@ -94,7 +94,7 @@ pub fn classifyType(ty: Type, mod: *const Module, ctx: Context) Class {
94 return .byval;94 return .byval;
95 },95 },
96 .Pointer => {96 .Pointer => {
97 assert(!ty.isSlice());97 assert(!ty.isSlice(mod));
98 return .byval;98 return .byval;
99 },99 },
100 .ErrorUnion,100 .ErrorUnion,
src/arch/riscv64/abi.zig+1-1
...@@ -52,7 +52,7 @@ pub fn classifyType(ty: Type, mod: *const Module) Class {...@@ -52,7 +52,7 @@ pub fn classifyType(ty: Type, mod: *const Module) Class {
52 return .byval;52 return .byval;
53 },53 },
54 .Pointer => {54 .Pointer => {
55 std.debug.assert(!ty.isSlice());55 std.debug.assert(!ty.isSlice(mod));
56 return .byval;56 return .byval;
57 },57 },
58 .ErrorUnion,58 .ErrorUnion,
src/arch/wasm/CodeGen.zig+11-9
...@@ -1773,7 +1773,7 @@ fn isByRef(ty: Type, mod: *const Module) bool {...@@ -1773,7 +1773,7 @@ fn isByRef(ty: Type, mod: *const Module) bool {
1773 },1773 },
1774 .Pointer => {1774 .Pointer => {
1775 // Slices act like struct and will be passed by reference1775 // Slices act like struct and will be passed by reference
1776 if (ty.isSlice()) return true;1776 if (ty.isSlice(mod)) return true;
1777 return false;1777 return false;
1778 },1778 },
1779 }1779 }
...@@ -2396,7 +2396,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2396,7 +2396,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2396 },2396 },
2397 },2397 },
2398 .Pointer => {2398 .Pointer => {
2399 if (ty.isSlice()) {2399 if (ty.isSlice(mod)) {
2400 // store pointer first2400 // store pointer first
2401 // lower it to the stack so we do not have to store rhs into a local first2401 // lower it to the stack so we do not have to store rhs into a local first
2402 try func.emitWValue(lhs);2402 try func.emitWValue(lhs);
...@@ -3010,11 +3010,11 @@ fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: Module.Decl.In...@@ -3010,11 +3010,11 @@ fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: Module.Decl.In
3010}3010}
30113011
3012fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: Module.Decl.Index, offset: u32) InnerError!WValue {3012fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: Module.Decl.Index, offset: u32) InnerError!WValue {
3013 if (tv.ty.isSlice()) {3013 const mod = func.bin_file.base.options.module.?;
3014 if (tv.ty.isSlice(mod)) {
3014 return WValue{ .memory = try func.bin_file.lowerUnnamedConst(tv, decl_index) };3015 return WValue{ .memory = try func.bin_file.lowerUnnamedConst(tv, decl_index) };
3015 }3016 }
30163017
3017 const mod = func.bin_file.base.options.module.?;
3018 const decl = mod.declPtr(decl_index);3018 const decl = mod.declPtr(decl_index);
3019 if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) {3019 if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) {
3020 return WValue{ .imm32 = 0xaaaaaaaa };3020 return WValue{ .imm32 = 0xaaaaaaaa };
...@@ -4182,7 +4182,7 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod...@@ -4182,7 +4182,7 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod
4182 };4182 };
4183 try func.addMemArg(.i32_load8_u, .{ .offset = operand.offset() + offset, .alignment = 1 });4183 try func.addMemArg(.i32_load8_u, .{ .offset = operand.offset() + offset, .alignment = 1 });
4184 }4184 }
4185 } else if (payload_ty.isSlice()) {4185 } else if (payload_ty.isSlice(mod)) {
4186 switch (func.arch()) {4186 switch (func.arch()) {
4187 .wasm32 => try func.addMemArg(.i32_load, .{ .offset = operand.offset(), .alignment = 4 }),4187 .wasm32 => try func.addMemArg(.i32_load, .{ .offset = operand.offset(), .alignment = 4 }),
4188 .wasm64 => try func.addMemArg(.i64_load, .{ .offset = operand.offset(), .alignment = 8 }),4188 .wasm64 => try func.addMemArg(.i64_load, .{ .offset = operand.offset(), .alignment = 8 }),
...@@ -4455,10 +4455,11 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4455,10 +4455,11 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4455}4455}
44564456
4457fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4457fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4458 const mod = func.bin_file.base.options.module.?;
4458 const un_op = func.air.instructions.items(.data)[inst].un_op;4459 const un_op = func.air.instructions.items(.data)[inst].un_op;
4459 const operand = try func.resolveInst(un_op);4460 const operand = try func.resolveInst(un_op);
4460 const ptr_ty = func.typeOf(un_op);4461 const ptr_ty = func.typeOf(un_op);
4461 const result = if (ptr_ty.isSlice())4462 const result = if (ptr_ty.isSlice(mod))
4462 try func.slicePtr(operand)4463 try func.slicePtr(operand)
4463 else switch (operand) {4464 else switch (operand) {
4464 // for stack offset, return a pointer to this offset.4465 // for stack offset, return a pointer to this offset.
...@@ -4479,7 +4480,7 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4479,7 +4480,7 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4479 const elem_size = elem_ty.abiSize(mod);4480 const elem_size = elem_ty.abiSize(mod);
44804481
4481 // load pointer onto the stack4482 // load pointer onto the stack
4482 if (ptr_ty.isSlice()) {4483 if (ptr_ty.isSlice(mod)) {
4483 _ = try func.load(ptr, Type.usize, 0);4484 _ = try func.load(ptr, Type.usize, 0);
4484 } else {4485 } else {
4485 try func.lowerToStack(ptr);4486 try func.lowerToStack(ptr);
...@@ -4518,7 +4519,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4518,7 +4519,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4518 const index = try func.resolveInst(bin_op.rhs);4519 const index = try func.resolveInst(bin_op.rhs);
45194520
4520 // load pointer onto the stack4521 // load pointer onto the stack
4521 if (ptr_ty.isSlice()) {4522 if (ptr_ty.isSlice(mod)) {
4522 _ = try func.load(ptr, Type.usize, 0);4523 _ = try func.load(ptr, Type.usize, 0);
4523 } else {4524 } else {
4524 try func.lowerToStack(ptr);4525 try func.lowerToStack(ptr);
...@@ -5441,7 +5442,8 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5441,7 +5442,8 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5441}5442}
54425443
5443fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue {5444fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue {
5444 if (ptr_ty.isSlice()) {5445 const mod = func.bin_file.base.options.module.?;
5446 if (ptr_ty.isSlice(mod)) {
5445 return func.slicePtr(ptr);5447 return func.slicePtr(ptr);
5446 } else {5448 } else {
5447 return ptr;5449 return ptr;
src/arch/wasm/abi.zig+1-1
...@@ -60,7 +60,7 @@ pub fn classifyType(ty: Type, mod: *const Module) [2]Class {...@@ -60,7 +60,7 @@ pub fn classifyType(ty: Type, mod: *const Module) [2]Class {
60 return direct;60 return direct;
61 },61 },
62 .Pointer => {62 .Pointer => {
63 std.debug.assert(!ty.isSlice());63 std.debug.assert(!ty.isSlice(mod));
64 return direct;64 return direct;
65 },65 },
66 .Union => {66 .Union => {
src/arch/x86_64/CodeGen.zig+2-2
...@@ -8688,7 +8688,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -8688,7 +8688,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
86888688
8689 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;8689 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
8690 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))8690 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
8691 .{ .off = 0, .ty = if (pl_ty.isSlice()) pl_ty.slicePtrFieldType(&ptr_buf) else pl_ty }8691 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(&ptr_buf) else pl_ty }
8692 else8692 else
8693 .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool };8693 .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool };
86948694
...@@ -8781,7 +8781,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)...@@ -8781,7 +8781,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
87818781
8782 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;8782 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
8783 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))8783 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
8784 .{ .off = 0, .ty = if (pl_ty.isSlice()) pl_ty.slicePtrFieldType(&ptr_buf) else pl_ty }8784 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(&ptr_buf) else pl_ty }
8785 else8785 else
8786 .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool };8786 .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool };
87878787
src/codegen.zig+5-5
...@@ -317,11 +317,11 @@ pub fn generateSymbol(...@@ -317,11 +317,11 @@ pub fn generateSymbol(
317 switch (target.ptrBitWidth()) {317 switch (target.ptrBitWidth()) {
318 32 => {318 32 => {
319 mem.writeInt(u32, try code.addManyAsArray(4), 0, endian);319 mem.writeInt(u32, try code.addManyAsArray(4), 0, endian);
320 if (typed_value.ty.isSlice()) try code.appendNTimes(0xaa, 4);320 if (typed_value.ty.isSlice(mod)) try code.appendNTimes(0xaa, 4);
321 },321 },
322 64 => {322 64 => {
323 mem.writeInt(u64, try code.addManyAsArray(8), 0, endian);323 mem.writeInt(u64, try code.addManyAsArray(8), 0, endian);
324 if (typed_value.ty.isSlice()) try code.appendNTimes(0xaa, 8);324 if (typed_value.ty.isSlice(mod)) try code.appendNTimes(0xaa, 8);
325 },325 },
326 else => unreachable,326 else => unreachable,
327 }327 }
...@@ -845,7 +845,7 @@ fn lowerParentPtr(...@@ -845,7 +845,7 @@ fn lowerParentPtr(
845 debug_output,845 debug_output,
846 reloc_info.offset(@intCast(u32, switch (field_ptr.container_ty.zigTypeTag(mod)) {846 reloc_info.offset(@intCast(u32, switch (field_ptr.container_ty.zigTypeTag(mod)) {
847 .Pointer => offset: {847 .Pointer => offset: {
848 assert(field_ptr.container_ty.isSlice());848 assert(field_ptr.container_ty.isSlice(mod));
849 var buf: Type.SlicePtrFieldTypeBuffer = undefined;849 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
850 break :offset switch (field_ptr.field_index) {850 break :offset switch (field_ptr.field_index) {
851 0 => 0,851 0 => 0,
...@@ -946,7 +946,7 @@ fn lowerDeclRef(...@@ -946,7 +946,7 @@ fn lowerDeclRef(
946) CodeGenError!Result {946) CodeGenError!Result {
947 const target = bin_file.options.target;947 const target = bin_file.options.target;
948 const mod = bin_file.options.module.?;948 const mod = bin_file.options.module.?;
949 if (typed_value.ty.isSlice()) {949 if (typed_value.ty.isSlice(mod)) {
950 // generate ptr950 // generate ptr
951 var buf: Type.SlicePtrFieldTypeBuffer = undefined;951 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
952 const slice_ptr_field_type = typed_value.ty.slicePtrFieldType(&buf);952 const slice_ptr_field_type = typed_value.ty.slicePtrFieldType(&buf);
...@@ -1174,7 +1174,7 @@ pub fn genTypedValue(...@@ -1174,7 +1174,7 @@ pub fn genTypedValue(
1174 const target = bin_file.options.target;1174 const target = bin_file.options.target;
1175 const ptr_bits = target.ptrBitWidth();1175 const ptr_bits = target.ptrBitWidth();
11761176
1177 if (!typed_value.ty.isSlice()) {1177 if (!typed_value.ty.isSlice(mod)) {
1178 if (typed_value.val.castTag(.variable)) |payload| {1178 if (typed_value.val.castTag(.variable)) |payload| {
1179 return genDeclRef(bin_file, src_loc, typed_value, payload.data.owner_decl);1179 return genDeclRef(bin_file, src_loc, typed_value, payload.data.owner_decl);
1180 }1180 }
src/codegen/c.zig+9-7
...@@ -556,7 +556,7 @@ pub const DeclGen = struct {...@@ -556,7 +556,7 @@ pub const DeclGen = struct {
556 if (decl.val.castTag(.variable)) |var_payload|556 if (decl.val.castTag(.variable)) |var_payload|
557 try dg.renderFwdDecl(decl_index, var_payload.data);557 try dg.renderFwdDecl(decl_index, var_payload.data);
558558
559 if (ty.isSlice()) {559 if (ty.isSlice(mod)) {
560 if (location == .StaticInitializer) {560 if (location == .StaticInitializer) {
561 try writer.writeByte('{');561 try writer.writeByte('{');
562 } else {562 } else {
...@@ -603,7 +603,7 @@ pub const DeclGen = struct {...@@ -603,7 +603,7 @@ pub const DeclGen = struct {
603 fn renderParentPtr(dg: *DeclGen, writer: anytype, ptr_val: Value, ptr_ty: Type, location: ValueRenderLocation) error{ OutOfMemory, AnalysisFail }!void {603 fn renderParentPtr(dg: *DeclGen, writer: anytype, ptr_val: Value, ptr_ty: Type, location: ValueRenderLocation) error{ OutOfMemory, AnalysisFail }!void {
604 const mod = dg.module;604 const mod = dg.module;
605605
606 if (!ptr_ty.isSlice()) {606 if (!ptr_ty.isSlice(mod)) {
607 try writer.writeByte('(');607 try writer.writeByte('(');
608 try dg.renderType(writer, ptr_ty);608 try dg.renderType(writer, ptr_ty);
609 try writer.writeByte(')');609 try writer.writeByte(')');
...@@ -776,7 +776,7 @@ pub const DeclGen = struct {...@@ -776,7 +776,7 @@ pub const DeclGen = struct {
776 try dg.renderValue(writer, repr_ty, Value.undef, .FunctionArgument);776 try dg.renderValue(writer, repr_ty, Value.undef, .FunctionArgument);
777 return writer.writeByte(')');777 return writer.writeByte(')');
778 },778 },
779 .Pointer => if (ty.isSlice()) {779 .Pointer => if (ty.isSlice(mod)) {
780 if (!location.isInitializer()) {780 if (!location.isInitializer()) {
781 try writer.writeByte('(');781 try writer.writeByte('(');
782 try dg.renderType(writer, ty);782 try dg.renderType(writer, ty);
...@@ -1045,7 +1045,7 @@ pub const DeclGen = struct {...@@ -1045,7 +1045,7 @@ pub const DeclGen = struct {
1045 return;1045 return;
1046 },1046 },
1047 .Pointer => switch (val.tag()) {1047 .Pointer => switch (val.tag()) {
1048 .null_value, .zero => if (ty.isSlice()) {1048 .null_value, .zero => if (ty.isSlice(mod)) {
1049 var slice_pl = Value.Payload.Slice{1049 var slice_pl = Value.Payload.Slice{
1050 .base = .{ .tag = .slice },1050 .base = .{ .tag = .slice },
1051 .data = .{ .ptr = val, .len = Value.undef },1051 .data = .{ .ptr = val, .len = Value.undef },
...@@ -5073,7 +5073,7 @@ fn airIsNull(...@@ -5073,7 +5073,7 @@ fn airIsNull(
5073 TypedValue{ .ty = optional_ty, .val = Value.null }5073 TypedValue{ .ty = optional_ty, .val = Value.null }
5074 else if (payload_ty.zigTypeTag(mod) == .ErrorSet)5074 else if (payload_ty.zigTypeTag(mod) == .ErrorSet)
5075 TypedValue{ .ty = payload_ty, .val = Value.zero }5075 TypedValue{ .ty = payload_ty, .val = Value.zero }
5076 else if (payload_ty.isSlice() and optional_ty.optionalReprIsPayload(mod)) rhs: {5076 else if (payload_ty.isSlice(mod) and optional_ty.optionalReprIsPayload(mod)) rhs: {
5077 try writer.writeAll(".ptr");5077 try writer.writeAll(".ptr");
5078 const slice_ptr_ty = payload_ty.slicePtrFieldType(&slice_ptr_buf);5078 const slice_ptr_ty = payload_ty.slicePtrFieldType(&slice_ptr_buf);
5079 break :rhs TypedValue{ .ty = slice_ptr_ty, .val = Value.null };5079 break :rhs TypedValue{ .ty = slice_ptr_ty, .val = Value.null };
...@@ -5864,6 +5864,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5864,6 +5864,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
5864}5864}
58655865
5866fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {5866fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {
5867 const mod = f.object.dg.module;
5867 const un_op = f.air.instructions.items(.data)[inst].un_op;5868 const un_op = f.air.instructions.items(.data)[inst].un_op;
58685869
5869 const operand = try f.resolveInst(un_op);5870 const operand = try f.resolveInst(un_op);
...@@ -5877,7 +5878,7 @@ fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5877,7 +5878,7 @@ fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {
5877 try writer.writeAll(" = (");5878 try writer.writeAll(" = (");
5878 try f.renderType(writer, inst_ty);5879 try f.renderType(writer, inst_ty);
5879 try writer.writeByte(')');5880 try writer.writeByte(')');
5880 if (operand_ty.isSlice()) {5881 if (operand_ty.isSlice(mod)) {
5881 try f.writeCValueMember(writer, operand, .{ .identifier = "len" });5882 try f.writeCValueMember(writer, operand, .{ .identifier = "len" });
5882 } else {5883 } else {
5883 try f.writeCValue(writer, operand, .Other);5884 try f.writeCValue(writer, operand, .Other);
...@@ -6272,7 +6273,8 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa...@@ -6272,7 +6273,8 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
6272}6273}
62736274
6274fn writeSliceOrPtr(f: *Function, writer: anytype, ptr: CValue, ptr_ty: Type) !void {6275fn writeSliceOrPtr(f: *Function, writer: anytype, ptr: CValue, ptr_ty: Type) !void {
6275 if (ptr_ty.isSlice()) {6276 const mod = f.object.dg.module;
6277 if (ptr_ty.isSlice(mod)) {
6276 try f.writeCValueMember(writer, ptr, .{ .identifier = "ptr" });6278 try f.writeCValueMember(writer, ptr, .{ .identifier = "ptr" });
6277 } else {6279 } else {
6278 try f.writeCValue(writer, ptr, .FunctionArgument);6280 try f.writeCValue(writer, ptr, .FunctionArgument);
src/codegen/llvm.zig+8-7
...@@ -1636,7 +1636,7 @@ pub const Object = struct {...@@ -1636,7 +1636,7 @@ pub const Object = struct {
1636 return ptr_di_ty;1636 return ptr_di_ty;
1637 }1637 }
16381638
1639 if (ty.isSlice()) {1639 if (ty.isSlice(mod)) {
1640 var buf: Type.SlicePtrFieldTypeBuffer = undefined;1640 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
1641 const ptr_ty = ty.slicePtrFieldType(&buf);1641 const ptr_ty = ty.slicePtrFieldType(&buf);
1642 const len_ty = Type.usize;1642 const len_ty = Type.usize;
...@@ -2833,7 +2833,7 @@ pub const DeclGen = struct {...@@ -2833,7 +2833,7 @@ pub const DeclGen = struct {
2833 },2833 },
2834 .Bool => return dg.context.intType(1),2834 .Bool => return dg.context.intType(1),
2835 .Pointer => {2835 .Pointer => {
2836 if (t.isSlice()) {2836 if (t.isSlice(mod)) {
2837 var buf: Type.SlicePtrFieldTypeBuffer = undefined;2837 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
2838 const ptr_type = t.slicePtrFieldType(&buf);2838 const ptr_type = t.slicePtrFieldType(&buf);
28392839
...@@ -4110,7 +4110,7 @@ pub const DeclGen = struct {...@@ -4110,7 +4110,7 @@ pub const DeclGen = struct {
4110 }4110 }
4111 },4111 },
4112 .Pointer => {4112 .Pointer => {
4113 assert(parent_ty.isSlice());4113 assert(parent_ty.isSlice(mod));
4114 const indices: [2]*llvm.Value = .{4114 const indices: [2]*llvm.Value = .{
4115 llvm_u32.constInt(0, .False),4115 llvm_u32.constInt(0, .False),
4116 llvm_u32.constInt(field_index, .False),4116 llvm_u32.constInt(field_index, .False),
...@@ -4184,7 +4184,7 @@ pub const DeclGen = struct {...@@ -4184,7 +4184,7 @@ pub const DeclGen = struct {
4184 decl_index: Module.Decl.Index,4184 decl_index: Module.Decl.Index,
4185 ) Error!*llvm.Value {4185 ) Error!*llvm.Value {
4186 const mod = self.module;4186 const mod = self.module;
4187 if (tv.ty.isSlice()) {4187 if (tv.ty.isSlice(mod)) {
4188 var buf: Type.SlicePtrFieldTypeBuffer = undefined;4188 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
4189 const ptr_ty = tv.ty.slicePtrFieldType(&buf);4189 const ptr_ty = tv.ty.slicePtrFieldType(&buf);
4190 var slice_len: Value.Payload.U64 = .{4190 var slice_len: Value.Payload.U64 = .{
...@@ -5794,7 +5794,8 @@ pub const FuncGen = struct {...@@ -5794,7 +5794,8 @@ pub const FuncGen = struct {
5794 }5794 }
57955795
5796 fn sliceOrArrayPtr(fg: *FuncGen, ptr: *llvm.Value, ty: Type) *llvm.Value {5796 fn sliceOrArrayPtr(fg: *FuncGen, ptr: *llvm.Value, ty: Type) *llvm.Value {
5797 if (ty.isSlice()) {5797 const mod = fg.dg.module;
5798 if (ty.isSlice(mod)) {
5798 return fg.builder.buildExtractValue(ptr, 0, "");5799 return fg.builder.buildExtractValue(ptr, 0, "");
5799 } else {5800 } else {
5800 return ptr;5801 return ptr;
...@@ -6669,7 +6670,7 @@ pub const FuncGen = struct {...@@ -6669,7 +6670,7 @@ pub const FuncGen = struct {
6669 self.builder.buildLoad(optional_llvm_ty, operand, "")6670 self.builder.buildLoad(optional_llvm_ty, operand, "")
6670 else6671 else
6671 operand;6672 operand;
6672 if (payload_ty.isSlice()) {6673 if (payload_ty.isSlice(mod)) {
6673 const slice_ptr = self.builder.buildExtractValue(loaded, 0, "");6674 const slice_ptr = self.builder.buildExtractValue(loaded, 0, "");
6674 var slice_buf: Type.SlicePtrFieldTypeBuffer = undefined;6675 var slice_buf: Type.SlicePtrFieldTypeBuffer = undefined;
6675 const ptr_ty = try self.dg.lowerType(payload_ty.slicePtrFieldType(&slice_buf));6676 const ptr_ty = try self.dg.lowerType(payload_ty.slicePtrFieldType(&slice_buf));
...@@ -10864,7 +10865,7 @@ const ParamTypeIterator = struct {...@@ -10864,7 +10865,7 @@ const ParamTypeIterator = struct {
10864 it.zig_index += 1;10865 it.zig_index += 1;
10865 it.llvm_index += 1;10866 it.llvm_index += 1;
10866 var buf: Type.Payload.ElemType = undefined;10867 var buf: Type.Payload.ElemType = undefined;
10867 if (ty.isSlice() or (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(&buf).isSlice())) {10868 if (ty.isSlice(mod) or (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(&buf).isSlice(mod))) {
10868 it.llvm_index += 1;10869 it.llvm_index += 1;
10869 return .slice;10870 return .slice;
10870 } else if (isByRef(ty, mod)) {10871 } else if (isByRef(ty, mod)) {
src/codegen/spirv.zig+2-2
...@@ -2980,12 +2980,12 @@ pub const DeclGen = struct {...@@ -2980,12 +2980,12 @@ pub const DeclGen = struct {
2980 // Pointer payload represents nullability: pointer or slice.2980 // Pointer payload represents nullability: pointer or slice.
29812981
2982 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;2982 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
2983 const ptr_ty = if (payload_ty.isSlice())2983 const ptr_ty = if (payload_ty.isSlice(mod))
2984 payload_ty.slicePtrFieldType(&ptr_buf)2984 payload_ty.slicePtrFieldType(&ptr_buf)
2985 else2985 else
2986 payload_ty;2986 payload_ty;
29872987
2988 const ptr_id = if (payload_ty.isSlice())2988 const ptr_id = if (payload_ty.isSlice(mod))
2989 try self.extractField(Type.bool, operand_id, 0)2989 try self.extractField(Type.bool, operand_id, 0)
2990 else2990 else
2991 operand_id;2991 operand_id;
src/link/Dwarf.zig+1-1
...@@ -258,7 +258,7 @@ pub const DeclState = struct {...@@ -258,7 +258,7 @@ pub const DeclState = struct {
258 }258 }
259 },259 },
260 .Pointer => {260 .Pointer => {
261 if (ty.isSlice()) {261 if (ty.isSlice(mod)) {
262 // Slices are structs: struct { .ptr = *, .len = N }262 // Slices are structs: struct { .ptr = *, .len = N }
263 const ptr_bits = target.ptrBitWidth();263 const ptr_bits = target.ptrBitWidth();
264 const ptr_bytes = @intCast(u8, @divExact(ptr_bits, 8));264 const ptr_bytes = @intCast(u8, @divExact(ptr_bits, 8));
src/type.zig+221-212
...@@ -229,7 +229,7 @@ pub const Type = struct {...@@ -229,7 +229,7 @@ pub const Type = struct {
229 .Frame,229 .Frame,
230 => false,230 => false,
231231
232 .Pointer => !ty.isSlice() and (is_equality_cmp or ty.isCPtr()),232 .Pointer => !ty.isSlice(mod) and (is_equality_cmp or ty.isCPtr()),
233 .Optional => {233 .Optional => {
234 if (!is_equality_cmp) return false;234 if (!is_equality_cmp) return false;
235 var buf: Payload.ElemType = undefined;235 var buf: Payload.ElemType = undefined;
...@@ -369,209 +369,212 @@ pub const Type = struct {...@@ -369,209 +369,212 @@ pub const Type = struct {
369 }369 }
370370
371 pub fn ptrInfo(self: Type) Payload.Pointer {371 pub fn ptrInfo(self: Type) Payload.Pointer {
372 switch (self.tag()) {372 switch (self.ip_index) {
373 .single_const_pointer_to_comptime_int => return .{ .data = .{373 .none => switch (self.tag()) {
374 .pointee_type = Type.comptime_int,374 .single_const_pointer_to_comptime_int => return .{ .data = .{
375 .sentinel = null,375 .pointee_type = Type.comptime_int,
376 .@"align" = 0,376 .sentinel = null,
377 .@"addrspace" = .generic,377 .@"align" = 0,
378 .bit_offset = 0,378 .@"addrspace" = .generic,
379 .host_size = 0,379 .bit_offset = 0,
380 .@"allowzero" = false,380 .host_size = 0,
381 .mutable = false,381 .@"allowzero" = false,
382 .@"volatile" = false,382 .mutable = false,
383 .size = .One,383 .@"volatile" = false,
384 } },384 .size = .One,
385 .const_slice_u8 => return .{ .data = .{385 } },
386 .pointee_type = Type.u8,386 .const_slice_u8 => return .{ .data = .{
387 .sentinel = null,387 .pointee_type = Type.u8,
388 .@"align" = 0,388 .sentinel = null,
389 .@"addrspace" = .generic,389 .@"align" = 0,
390 .bit_offset = 0,390 .@"addrspace" = .generic,
391 .host_size = 0,391 .bit_offset = 0,
392 .@"allowzero" = false,392 .host_size = 0,
393 .mutable = false,393 .@"allowzero" = false,
394 .@"volatile" = false,394 .mutable = false,
395 .size = .Slice,395 .@"volatile" = false,
396 } },396 .size = .Slice,
397 .const_slice_u8_sentinel_0 => return .{ .data = .{397 } },
398 .pointee_type = Type.u8,398 .const_slice_u8_sentinel_0 => return .{ .data = .{
399 .sentinel = Value.zero,399 .pointee_type = Type.u8,
400 .@"align" = 0,400 .sentinel = Value.zero,
401 .@"addrspace" = .generic,401 .@"align" = 0,
402 .bit_offset = 0,402 .@"addrspace" = .generic,
403 .host_size = 0,403 .bit_offset = 0,
404 .@"allowzero" = false,404 .host_size = 0,
405 .mutable = false,405 .@"allowzero" = false,
406 .@"volatile" = false,406 .mutable = false,
407 .size = .Slice,407 .@"volatile" = false,
408 } },408 .size = .Slice,
409 .single_const_pointer => return .{ .data = .{409 } },
410 .pointee_type = self.castPointer().?.data,410 .single_const_pointer => return .{ .data = .{
411 .sentinel = null,411 .pointee_type = self.castPointer().?.data,
412 .@"align" = 0,412 .sentinel = null,
413 .@"addrspace" = .generic,413 .@"align" = 0,
414 .bit_offset = 0,414 .@"addrspace" = .generic,
415 .host_size = 0,415 .bit_offset = 0,
416 .@"allowzero" = false,416 .host_size = 0,
417 .mutable = false,417 .@"allowzero" = false,
418 .@"volatile" = false,418 .mutable = false,
419 .size = .One,419 .@"volatile" = false,
420 } },420 .size = .One,
421 .single_mut_pointer => return .{ .data = .{421 } },
422 .pointee_type = self.castPointer().?.data,422 .single_mut_pointer => return .{ .data = .{
423 .sentinel = null,423 .pointee_type = self.castPointer().?.data,
424 .@"align" = 0,424 .sentinel = null,
425 .@"addrspace" = .generic,425 .@"align" = 0,
426 .bit_offset = 0,426 .@"addrspace" = .generic,
427 .host_size = 0,427 .bit_offset = 0,
428 .@"allowzero" = false,428 .host_size = 0,
429 .mutable = true,429 .@"allowzero" = false,
430 .@"volatile" = false,430 .mutable = true,
431 .size = .One,431 .@"volatile" = false,
432 } },432 .size = .One,
433 .many_const_pointer => return .{ .data = .{433 } },
434 .pointee_type = self.castPointer().?.data,434 .many_const_pointer => return .{ .data = .{
435 .sentinel = null,435 .pointee_type = self.castPointer().?.data,
436 .@"align" = 0,436 .sentinel = null,
437 .@"addrspace" = .generic,437 .@"align" = 0,
438 .bit_offset = 0,438 .@"addrspace" = .generic,
439 .host_size = 0,439 .bit_offset = 0,
440 .@"allowzero" = false,440 .host_size = 0,
441 .mutable = false,441 .@"allowzero" = false,
442 .@"volatile" = false,442 .mutable = false,
443 .size = .Many,443 .@"volatile" = false,
444 } },444 .size = .Many,
445 .manyptr_const_u8 => return .{ .data = .{445 } },
446 .pointee_type = Type.u8,446 .manyptr_const_u8 => return .{ .data = .{
447 .sentinel = null,447 .pointee_type = Type.u8,
448 .@"align" = 0,448 .sentinel = null,
449 .@"addrspace" = .generic,449 .@"align" = 0,
450 .bit_offset = 0,450 .@"addrspace" = .generic,
451 .host_size = 0,451 .bit_offset = 0,
452 .@"allowzero" = false,452 .host_size = 0,
453 .mutable = false,453 .@"allowzero" = false,
454 .@"volatile" = false,454 .mutable = false,
455 .size = .Many,455 .@"volatile" = false,
456 } },456 .size = .Many,
457 .manyptr_const_u8_sentinel_0 => return .{ .data = .{457 } },
458 .pointee_type = Type.u8,458 .manyptr_const_u8_sentinel_0 => return .{ .data = .{
459 .sentinel = Value.zero,459 .pointee_type = Type.u8,
460 .@"align" = 0,460 .sentinel = Value.zero,
461 .@"addrspace" = .generic,461 .@"align" = 0,
462 .bit_offset = 0,462 .@"addrspace" = .generic,
463 .host_size = 0,463 .bit_offset = 0,
464 .@"allowzero" = false,464 .host_size = 0,
465 .mutable = false,465 .@"allowzero" = false,
466 .@"volatile" = false,466 .mutable = false,
467 .size = .Many,467 .@"volatile" = false,
468 } },468 .size = .Many,
469 .many_mut_pointer => return .{ .data = .{469 } },
470 .pointee_type = self.castPointer().?.data,470 .many_mut_pointer => return .{ .data = .{
471 .sentinel = null,471 .pointee_type = self.castPointer().?.data,
472 .@"align" = 0,472 .sentinel = null,
473 .@"addrspace" = .generic,473 .@"align" = 0,
474 .bit_offset = 0,474 .@"addrspace" = .generic,
475 .host_size = 0,475 .bit_offset = 0,
476 .@"allowzero" = false,476 .host_size = 0,
477 .mutable = true,477 .@"allowzero" = false,
478 .@"volatile" = false,478 .mutable = true,
479 .size = .Many,479 .@"volatile" = false,
480 } },480 .size = .Many,
481 .manyptr_u8 => return .{ .data = .{481 } },
482 .pointee_type = Type.u8,482 .manyptr_u8 => return .{ .data = .{
483 .sentinel = null,483 .pointee_type = Type.u8,
484 .@"align" = 0,484 .sentinel = null,
485 .@"addrspace" = .generic,485 .@"align" = 0,
486 .bit_offset = 0,486 .@"addrspace" = .generic,
487 .host_size = 0,487 .bit_offset = 0,
488 .@"allowzero" = false,488 .host_size = 0,
489 .mutable = true,489 .@"allowzero" = false,
490 .@"volatile" = false,490 .mutable = true,
491 .size = .Many,491 .@"volatile" = false,
492 } },492 .size = .Many,
493 .c_const_pointer => return .{ .data = .{493 } },
494 .pointee_type = self.castPointer().?.data,494 .c_const_pointer => return .{ .data = .{
495 .sentinel = null,495 .pointee_type = self.castPointer().?.data,
496 .@"align" = 0,496 .sentinel = null,
497 .@"addrspace" = .generic,497 .@"align" = 0,
498 .bit_offset = 0,498 .@"addrspace" = .generic,
499 .host_size = 0,499 .bit_offset = 0,
500 .@"allowzero" = true,500 .host_size = 0,
501 .mutable = false,501 .@"allowzero" = true,
502 .@"volatile" = false,502 .mutable = false,
503 .size = .C,503 .@"volatile" = false,
504 } },504 .size = .C,
505 .c_mut_pointer => return .{ .data = .{505 } },
506 .pointee_type = self.castPointer().?.data,506 .c_mut_pointer => return .{ .data = .{
507 .sentinel = null,507 .pointee_type = self.castPointer().?.data,
508 .@"align" = 0,508 .sentinel = null,
509 .@"addrspace" = .generic,509 .@"align" = 0,
510 .bit_offset = 0,510 .@"addrspace" = .generic,
511 .host_size = 0,511 .bit_offset = 0,
512 .@"allowzero" = true,512 .host_size = 0,
513 .mutable = true,513 .@"allowzero" = true,
514 .@"volatile" = false,514 .mutable = true,
515 .size = .C,515 .@"volatile" = false,
516 } },516 .size = .C,
517 .const_slice => return .{ .data = .{517 } },
518 .pointee_type = self.castPointer().?.data,518 .const_slice => return .{ .data = .{
519 .sentinel = null,519 .pointee_type = self.castPointer().?.data,
520 .@"align" = 0,520 .sentinel = null,
521 .@"addrspace" = .generic,521 .@"align" = 0,
522 .bit_offset = 0,522 .@"addrspace" = .generic,
523 .host_size = 0,523 .bit_offset = 0,
524 .@"allowzero" = false,524 .host_size = 0,
525 .mutable = false,525 .@"allowzero" = false,
526 .@"volatile" = false,526 .mutable = false,
527 .size = .Slice,527 .@"volatile" = false,
528 } },528 .size = .Slice,
529 .mut_slice => return .{ .data = .{529 } },
530 .pointee_type = self.castPointer().?.data,530 .mut_slice => return .{ .data = .{
531 .sentinel = null,531 .pointee_type = self.castPointer().?.data,
532 .@"align" = 0,532 .sentinel = null,
533 .@"addrspace" = .generic,533 .@"align" = 0,
534 .bit_offset = 0,534 .@"addrspace" = .generic,
535 .host_size = 0,535 .bit_offset = 0,
536 .@"allowzero" = false,536 .host_size = 0,
537 .mutable = true,537 .@"allowzero" = false,
538 .@"volatile" = false,538 .mutable = true,
539 .size = .Slice,539 .@"volatile" = false,
540 } },540 .size = .Slice,
541541 } },
542 .pointer => return self.castTag(.pointer).?.*,542
543543 .pointer => return self.castTag(.pointer).?.*,
544 .optional_single_mut_pointer => return .{ .data = .{544
545 .pointee_type = self.castPointer().?.data,545 .optional_single_mut_pointer => return .{ .data = .{
546 .sentinel = null,546 .pointee_type = self.castPointer().?.data,
547 .@"align" = 0,547 .sentinel = null,
548 .@"addrspace" = .generic,548 .@"align" = 0,
549 .bit_offset = 0,549 .@"addrspace" = .generic,
550 .host_size = 0,550 .bit_offset = 0,
551 .@"allowzero" = false,551 .host_size = 0,
552 .mutable = true,552 .@"allowzero" = false,
553 .@"volatile" = false,553 .mutable = true,
554 .size = .One,554 .@"volatile" = false,
555 } },555 .size = .One,
556 .optional_single_const_pointer => return .{ .data = .{556 } },
557 .pointee_type = self.castPointer().?.data,557 .optional_single_const_pointer => return .{ .data = .{
558 .sentinel = null,558 .pointee_type = self.castPointer().?.data,
559 .@"align" = 0,559 .sentinel = null,
560 .@"addrspace" = .generic,560 .@"align" = 0,
561 .bit_offset = 0,561 .@"addrspace" = .generic,
562 .host_size = 0,562 .bit_offset = 0,
563 .@"allowzero" = false,563 .host_size = 0,
564 .mutable = false,564 .@"allowzero" = false,
565 .@"volatile" = false,565 .mutable = false,
566 .size = .One,566 .@"volatile" = false,
567 } },567 .size = .One,
568 .optional => {568 } },
569 var buf: Payload.ElemType = undefined;569 .optional => {
570 const child_type = self.optionalChild(&buf);570 var buf: Payload.ElemType = undefined;
571 return child_type.ptrInfo();571 const child_type = self.optionalChild(&buf);
572 },572 return child_type.ptrInfo();
573 },
573574
574 else => unreachable,575 else => unreachable,
576 },
577 else => @panic("TODO"),
575 }578 }
576 }579 }
577580
...@@ -3712,17 +3715,23 @@ pub const Type = struct {...@@ -3712,17 +3715,23 @@ pub const Type = struct {
3712 };3715 };
3713 }3716 }
37143717
3715 pub fn isSlice(self: Type) bool {3718 pub fn isSlice(ty: Type, mod: *const Module) bool {
3716 return switch (self.tag()) {3719 return switch (ty.ip_index) {
3717 .const_slice,3720 .none => switch (ty.tag()) {
3718 .mut_slice,3721 .const_slice,
3719 .const_slice_u8,3722 .mut_slice,
3720 .const_slice_u8_sentinel_0,3723 .const_slice_u8,
3721 => true,3724 .const_slice_u8_sentinel_0,
3725 => true,
37223726
3723 .pointer => self.castTag(.pointer).?.data.size == .Slice,3727 .pointer => ty.castTag(.pointer).?.data.size == .Slice,
37243728
3725 else => false,3729 else => false,
3730 },
3731 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
3732 .ptr_type => |ptr_type| ptr_type.size == .Slice,
3733 else => false,
3734 },
3726 };3735 };
3727 }3736 }
37283737
src/value.zig+4-4
...@@ -1144,7 +1144,7 @@ pub const Value = struct {...@@ -1144,7 +1144,7 @@ pub const Value = struct {
1144 },1144 },
1145 },1145 },
1146 .Pointer => {1146 .Pointer => {
1147 if (ty.isSlice()) return error.IllDefinedMemoryLayout;1147 if (ty.isSlice(mod)) return error.IllDefinedMemoryLayout;
1148 if (val.isDeclRef()) return error.ReinterpretDeclRef;1148 if (val.isDeclRef()) return error.ReinterpretDeclRef;
1149 return val.writeToMemory(Type.usize, mod, buffer);1149 return val.writeToMemory(Type.usize, mod, buffer);
1150 },1150 },
...@@ -1261,7 +1261,7 @@ pub const Value = struct {...@@ -1261,7 +1261,7 @@ pub const Value = struct {
1261 },1261 },
1262 },1262 },
1263 .Pointer => {1263 .Pointer => {
1264 assert(!ty.isSlice()); // No well defined layout.1264 assert(!ty.isSlice(mod)); // No well defined layout.
1265 if (val.isDeclRef()) return error.ReinterpretDeclRef;1265 if (val.isDeclRef()) return error.ReinterpretDeclRef;
1266 return val.writeToPackedMemory(Type.usize, mod, buffer, bit_offset);1266 return val.writeToPackedMemory(Type.usize, mod, buffer, bit_offset);
1267 },1267 },
...@@ -1381,7 +1381,7 @@ pub const Value = struct {...@@ -1381,7 +1381,7 @@ pub const Value = struct {
1381 return Value.initPayload(&payload.base);1381 return Value.initPayload(&payload.base);
1382 },1382 },
1383 .Pointer => {1383 .Pointer => {
1384 assert(!ty.isSlice()); // No well defined layout.1384 assert(!ty.isSlice(mod)); // No well defined layout.
1385 return readFromMemory(Type.usize, mod, buffer, arena);1385 return readFromMemory(Type.usize, mod, buffer, arena);
1386 },1386 },
1387 .Optional => {1387 .Optional => {
...@@ -1478,7 +1478,7 @@ pub const Value = struct {...@@ -1478,7 +1478,7 @@ pub const Value = struct {
1478 },1478 },
1479 },1479 },
1480 .Pointer => {1480 .Pointer => {
1481 assert(!ty.isSlice()); // No well defined layout.1481 assert(!ty.isSlice(mod)); // No well defined layout.
1482 return readFromPackedMemory(Type.usize, mod, buffer, bit_offset, arena);1482 return readFromPackedMemory(Type.usize, mod, buffer, bit_offset, arena);
1483 },1483 },
1484 .Optional => {1484 .Optional => {