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) {
629629 /// A vector type.
630630 /// data is payload to Vector.
631631 type_vector,
632 /// A pointer type along with all its bells and whistles.
632 /// A fully explicitly specified pointer type.
633633 /// data is payload to Pointer.
634634 type_pointer,
635635 /// An optional type.
......@@ -682,13 +682,13 @@ pub const Tag = enum(u8) {
682682 /// An enum tag identified by a negative integer value.
683683 /// data is a limbs index to Int.
684684 enum_tag_negative,
685 /// A float value that can be represented by f32.
685 /// An f32 value.
686686 /// data is float value bitcasted to u32.
687687 float_f32,
688 /// A float value that can be represented by f64.
688 /// An f64 value.
689689 /// data is payload index to Float64.
690690 float_f64,
691 /// A float value that can be represented by f128.
691 /// An f128 value.
692692 /// data is payload index to Float128.
693693 float_f128,
694694 /// An extern function.
......@@ -871,7 +871,47 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
871871 .simple_type => .{ .simple_type = @intToEnum(SimpleType, data) },
872872 .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"),
875915 };
876916}
877917
src/Sema.zig+28-28
......@@ -2030,7 +2030,7 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty
20302030 ty.fmt(mod),
20312031 });
20322032 errdefer msg.destroy(sema.gpa);
2033 if (ty.isSlice()) {
2033 if (ty.isSlice(mod)) {
20342034 try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});
20352035 }
20362036 break :msg msg;
......@@ -10359,7 +10359,7 @@ fn zirSwitchCond(
1035910359 .ErrorSet,
1036010360 .Enum,
1036110361 => {
10362 if (operand_ty.isSlice()) {
10362 if (operand_ty.isSlice(mod)) {
1036310363 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)});
1036410364 }
1036510365 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {
......@@ -12017,7 +12017,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1201712017 const ty = try sema.resolveTypeFields(unresolved_ty);
1201812018
1201912019 const has_field = hf: {
12020 if (ty.isSlice()) {
12020 if (ty.isSlice(mod)) {
1202112021 if (mem.eql(u8, field_name, "ptr")) break :hf true;
1202212022 if (mem.eql(u8, field_name, "len")) break :hf true;
1202312023 break :hf false;
......@@ -20020,8 +20020,8 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2002020020 return sema.failWithOwnedErrorMsg(msg);
2002120021 }
2002220022
20023 const dest_is_slice = dest_ty.isSlice();
20024 const operand_is_slice = operand_ty.isSlice();
20023 const dest_is_slice = dest_ty.isSlice(mod);
20024 const operand_is_slice = operand_ty.isSlice(mod);
2002520025 if (dest_is_slice and !operand_is_slice) {
2002620026 return sema.fail(block, dest_ty_src, "illegal pointer cast to slice", .{});
2002720027 }
......@@ -20274,14 +20274,14 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2027420274 Type.usize,
2027520275 Value.initPayload(&val_payload.base),
2027620276 );
20277 const actual_ptr = if (ptr_ty.isSlice())
20277 const actual_ptr = if (ptr_ty.isSlice(mod))
2027820278 try sema.analyzeSlicePtr(block, ptr_src, ptr, ptr_ty)
2027920279 else
2028020280 ptr;
2028120281 const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr);
2028220282 const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1);
2028320283 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: {
2028520285 const len = try sema.analyzeSliceLen(block, ptr_src, ptr);
2028620286 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
2028720287 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
2233622336 // Change the src from slice to a many pointer, to avoid multiple ptr
2233722337 // slice extractions in AIR instructions.
2233822338 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)) {
2234022340 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
2234122341 }
2234222342 } 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
2234422344 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
2234522345 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false);
2234622346 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)) {
2234822348 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
2234922349 }
2235022350 }
......@@ -22363,7 +22363,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2236322363 // Extract raw pointer from dest slice. The AIR instructions could support them, but
2236422364 // it would cause redundant machine code instructions.
2236522365 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))
2236722367 try sema.analyzeSlicePtr(block, dest_src, new_dest_ptr, new_dest_ptr_ty)
2236822368 else
2236922369 new_dest_ptr;
......@@ -23383,7 +23383,7 @@ fn validateExternType(
2338323383 .Float,
2338423384 .AnyFrame,
2338523385 => return true,
23386 .Pointer => return !(ty.isSlice() or try sema.typeRequiresComptime(ty)),
23386 .Pointer => return !(ty.isSlice(mod) or try sema.typeRequiresComptime(ty)),
2338723387 .Int => switch (ty.intInfo(mod).bits) {
2338823388 8, 16, 32, 64, 128 => return true,
2338923389 else => return false,
......@@ -23448,7 +23448,7 @@ fn explainWhyTypeIsNotExtern(
2344823448 => return,
2344923449
2345023450 .Pointer => {
23451 if (ty.isSlice()) {
23451 if (ty.isSlice(mod)) {
2345223452 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2345323453 } else {
2345423454 const pointee_ty = ty.childType();
......@@ -23523,7 +23523,7 @@ fn validatePackedType(ty: Type, mod: *const Module) bool {
2352323523 .Vector,
2352423524 .Enum,
2352523525 => return true,
23526 .Pointer => return !ty.isSlice(),
23526 .Pointer => return !ty.isSlice(mod),
2352723527 .Struct, .Union => return ty.containerLayout() == .Packed,
2352823528 }
2352923529}
......@@ -23803,7 +23803,7 @@ fn panicSentinelMismatch(
2380323803 const expected_sentinel = try sema.addConstant(sentinel_ty, expected_sentinel_val);
2380423804
2380523805 const ptr_ty = sema.typeOf(ptr);
23806 const actual_sentinel = if (ptr_ty.isSlice())
23806 const actual_sentinel = if (ptr_ty.isSlice(mod))
2380723807 try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index)
2380823808 else blk: {
2380923809 const elem_ptr_ty = try sema.elemPtrType(ptr_ty, null);
......@@ -24064,7 +24064,7 @@ fn fieldVal(
2406424064 const msg = msg: {
2406524065 const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)});
2406624066 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", .{});
2406824068 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{});
2406924069 break :msg msg;
2407024070 };
......@@ -24140,7 +24140,7 @@ fn fieldPtr(
2414024140 );
2414124141 }
2414224142 },
24143 .Pointer => if (inner_ty.isSlice()) {
24143 .Pointer => if (inner_ty.isSlice(mod)) {
2414424144 const inner_ptr = if (is_pointer_to)
2414524145 try sema.analyzeLoad(block, src, object_ptr, object_ptr_src)
2414624146 else
......@@ -25743,8 +25743,8 @@ fn coerceExtra(
2574325743 } };
2574425744 break :pointer;
2574525745 }
25746 if (dest_ty.isSlice()) break :to_anyopaque;
25747 if (inst_ty.isSlice()) {
25746 if (dest_ty.isSlice(mod)) break :to_anyopaque;
25747 if (inst_ty.isSlice(mod)) {
2574825748 in_memory_result = .{ .slice_to_anyopaque = .{
2574925749 .actual = inst_ty,
2575025750 .wanted = dest_ty,
......@@ -25885,7 +25885,7 @@ fn coerceExtra(
2588525885 return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src);
2588625886 },
2588725887 .Many => p: {
25888 if (!inst_ty.isSlice()) break :p;
25888 if (!inst_ty.isSlice(mod)) break :p;
2588925889 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :p;
2589025890 const inst_info = inst_ty.ptrInfo().data;
2589125891
......@@ -26651,7 +26651,7 @@ fn coerceInMemoryAllowed(
2665126651 }
2665226652
2665326653 // Slices
26654 if (dest_ty.isSlice() and src_ty.isSlice()) {
26654 if (dest_ty.isSlice(mod) and src_ty.isSlice(mod)) {
2665526655 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ty, src_ty, dest_is_mut, target, dest_src, src_src);
2665626656 }
2665726657
......@@ -27744,7 +27744,7 @@ fn beginComptimePtrMutation(
2774427744 );
2774527745 },
2774627746 .Pointer => {
27747 assert(parent.ty.isSlice());
27747 assert(parent.ty.isSlice(mod));
2774827748 val_ptr.* = try Value.Tag.slice.create(arena, .{
2774927749 .ptr = Value.undef,
2775027750 .len = Value.undef,
......@@ -28187,7 +28187,7 @@ fn beginComptimePtrLoad(
2818728187 break :blk deref;
2818828188 }
2818928189
28190 if (field_ptr.container_ty.isSlice()) {
28190 if (field_ptr.container_ty.isSlice(mod)) {
2819128191 const slice_val = tv.val.castTag(.slice).?.data;
2819228192 deref.pointee = switch (field_index) {
2819328193 Value.Payload.Slice.ptr_index => TypedValue{
......@@ -28442,13 +28442,13 @@ fn coerceCompatiblePtrs(
2844228442 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(mod) and
2844328443 (try sema.typeHasRuntimeBits(dest_ty.elemType2(mod)) or dest_ty.elemType2(mod).zigTypeTag(mod) == .Fn))
2844428444 {
28445 const actual_ptr = if (inst_ty.isSlice())
28445 const actual_ptr = if (inst_ty.isSlice(mod))
2844628446 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
2844728447 else
2844828448 inst;
2844928449 const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr);
2845028450 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: {
2845228452 const len = try sema.analyzeSliceLen(block, inst_src, inst);
2845328453 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
2845428454 break :ok try block.addBinOp(.bit_or, len_zero, is_non_zero);
......@@ -29548,7 +29548,7 @@ fn analyzeSlice(
2954829548 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}),
2954929549 }
2955029550
29551 const ptr = if (slice_ty.isSlice())
29551 const ptr = if (slice_ty.isSlice(mod))
2955229552 try sema.analyzeSlicePtr(block, ptr_src, ptr_or_slice, slice_ty)
2955329553 else
2955429554 ptr_or_slice;
......@@ -29605,7 +29605,7 @@ fn analyzeSlice(
2960529605 }
2960629606
2960729607 break :e try sema.addConstant(Type.usize, len_val);
29608 } else if (slice_ty.isSlice()) {
29608 } else if (slice_ty.isSlice(mod)) {
2960929609 if (!end_is_len) {
2961029610 const end = if (by_length) end: {
2961129611 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
......@@ -29778,7 +29778,7 @@ fn analyzeSlice(
2977829778 try sema.addSafetyCheck(block, is_non_null, .unwrap_null);
2977929779 }
2978029780
29781 if (slice_ty.isSlice()) {
29781 if (slice_ty.isSlice(mod)) {
2978229782 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
2978329783 const actual_len = if (slice_ty.sentinel() == null)
2978429784 slice_len_inst
......@@ -29840,7 +29840,7 @@ fn analyzeSlice(
2984029840 // requirement: end <= len
2984129841 const opt_len_inst = if (array_ty.zigTypeTag(mod) == .Array)
2984229842 try sema.addIntUnsigned(Type.usize, array_ty.arrayLenIncludingSentinel())
29843 else if (slice_ty.isSlice()) blk: {
29843 else if (slice_ty.isSlice(mod)) blk: {
2984429844 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {
2984529845 // we don't need to add one for sentinels because the
2984629846 // underlying value data includes the sentinel
src/TypedValue.zig+1-1
......@@ -259,7 +259,7 @@ pub fn print(
259259 } else if (field_ptr.container_ty.zigTypeTag(mod) == .Union) {
260260 const field_name = field_ptr.container_ty.unionFields().keys()[field_ptr.field_index];
261261 return writer.print(".{s}", .{field_name});
262 } else if (field_ptr.container_ty.isSlice()) {
262 } else if (field_ptr.container_ty.isSlice(mod)) {
263263 switch (field_ptr.field_index) {
264264 Value.Payload.Slice.ptr_index => return writer.writeAll(".ptr"),
265265 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 {
5252 return .byval;
5353 },
5454 .Pointer => {
55 std.debug.assert(!ty.isSlice());
55 std.debug.assert(!ty.isSlice(mod));
5656 return .byval;
5757 },
5858 .ErrorUnion,
src/arch/arm/abi.zig+1-1
......@@ -94,7 +94,7 @@ pub fn classifyType(ty: Type, mod: *const Module, ctx: Context) Class {
9494 return .byval;
9595 },
9696 .Pointer => {
97 assert(!ty.isSlice());
97 assert(!ty.isSlice(mod));
9898 return .byval;
9999 },
100100 .ErrorUnion,
src/arch/riscv64/abi.zig+1-1
......@@ -52,7 +52,7 @@ pub fn classifyType(ty: Type, mod: *const Module) Class {
5252 return .byval;
5353 },
5454 .Pointer => {
55 std.debug.assert(!ty.isSlice());
55 std.debug.assert(!ty.isSlice(mod));
5656 return .byval;
5757 },
5858 .ErrorUnion,
src/arch/wasm/CodeGen.zig+11-9
......@@ -1773,7 +1773,7 @@ fn isByRef(ty: Type, mod: *const Module) bool {
17731773 },
17741774 .Pointer => {
17751775 // Slices act like struct and will be passed by reference
1776 if (ty.isSlice()) return true;
1776 if (ty.isSlice(mod)) return true;
17771777 return false;
17781778 },
17791779 }
......@@ -2396,7 +2396,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
23962396 },
23972397 },
23982398 .Pointer => {
2399 if (ty.isSlice()) {
2399 if (ty.isSlice(mod)) {
24002400 // store pointer first
24012401 // lower it to the stack so we do not have to store rhs into a local first
24022402 try func.emitWValue(lhs);
......@@ -3010,11 +3010,11 @@ fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: Module.Decl.In
30103010}
30113011
30123012fn 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)) {
30143015 return WValue{ .memory = try func.bin_file.lowerUnnamedConst(tv, decl_index) };
30153016 }
30163017
3017 const mod = func.bin_file.base.options.module.?;
30183018 const decl = mod.declPtr(decl_index);
30193019 if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) {
30203020 return WValue{ .imm32 = 0xaaaaaaaa };
......@@ -4182,7 +4182,7 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod
41824182 };
41834183 try func.addMemArg(.i32_load8_u, .{ .offset = operand.offset() + offset, .alignment = 1 });
41844184 }
4185 } else if (payload_ty.isSlice()) {
4185 } else if (payload_ty.isSlice(mod)) {
41864186 switch (func.arch()) {
41874187 .wasm32 => try func.addMemArg(.i32_load, .{ .offset = operand.offset(), .alignment = 4 }),
41884188 .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 {
44554455}
44564456
44574457fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4458 const mod = func.bin_file.base.options.module.?;
44584459 const un_op = func.air.instructions.items(.data)[inst].un_op;
44594460 const operand = try func.resolveInst(un_op);
44604461 const ptr_ty = func.typeOf(un_op);
4461 const result = if (ptr_ty.isSlice())
4462 const result = if (ptr_ty.isSlice(mod))
44624463 try func.slicePtr(operand)
44634464 else switch (operand) {
44644465 // for stack offset, return a pointer to this offset.
......@@ -4479,7 +4480,7 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44794480 const elem_size = elem_ty.abiSize(mod);
44804481
44814482 // load pointer onto the stack
4482 if (ptr_ty.isSlice()) {
4483 if (ptr_ty.isSlice(mod)) {
44834484 _ = try func.load(ptr, Type.usize, 0);
44844485 } else {
44854486 try func.lowerToStack(ptr);
......@@ -4518,7 +4519,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45184519 const index = try func.resolveInst(bin_op.rhs);
45194520
45204521 // load pointer onto the stack
4521 if (ptr_ty.isSlice()) {
4522 if (ptr_ty.isSlice(mod)) {
45224523 _ = try func.load(ptr, Type.usize, 0);
45234524 } else {
45244525 try func.lowerToStack(ptr);
......@@ -5441,7 +5442,8 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54415442}
54425443
54435444fn 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)) {
54455447 return func.slicePtr(ptr);
54465448 } else {
54475449 return ptr;
src/arch/wasm/abi.zig+1-1
......@@ -60,7 +60,7 @@ pub fn classifyType(ty: Type, mod: *const Module) [2]Class {
6060 return direct;
6161 },
6262 .Pointer => {
63 std.debug.assert(!ty.isSlice());
63 std.debug.assert(!ty.isSlice(mod));
6464 return direct;
6565 },
6666 .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
86888688
86898689 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
86908690 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 }
86928692 else
86938693 .{ .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)
87818781
87828782 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
87838783 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 }
87858785 else
87868786 .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool };
87878787
src/codegen.zig+5-5
......@@ -317,11 +317,11 @@ pub fn generateSymbol(
317317 switch (target.ptrBitWidth()) {
318318 32 => {
319319 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);
321321 },
322322 64 => {
323323 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);
325325 },
326326 else => unreachable,
327327 }
......@@ -845,7 +845,7 @@ fn lowerParentPtr(
845845 debug_output,
846846 reloc_info.offset(@intCast(u32, switch (field_ptr.container_ty.zigTypeTag(mod)) {
847847 .Pointer => offset: {
848 assert(field_ptr.container_ty.isSlice());
848 assert(field_ptr.container_ty.isSlice(mod));
849849 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
850850 break :offset switch (field_ptr.field_index) {
851851 0 => 0,
......@@ -946,7 +946,7 @@ fn lowerDeclRef(
946946) CodeGenError!Result {
947947 const target = bin_file.options.target;
948948 const mod = bin_file.options.module.?;
949 if (typed_value.ty.isSlice()) {
949 if (typed_value.ty.isSlice(mod)) {
950950 // generate ptr
951951 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
952952 const slice_ptr_field_type = typed_value.ty.slicePtrFieldType(&buf);
......@@ -1174,7 +1174,7 @@ pub fn genTypedValue(
11741174 const target = bin_file.options.target;
11751175 const ptr_bits = target.ptrBitWidth();
11761176
1177 if (!typed_value.ty.isSlice()) {
1177 if (!typed_value.ty.isSlice(mod)) {
11781178 if (typed_value.val.castTag(.variable)) |payload| {
11791179 return genDeclRef(bin_file, src_loc, typed_value, payload.data.owner_decl);
11801180 }
src/codegen/c.zig+9-7
......@@ -556,7 +556,7 @@ pub const DeclGen = struct {
556556 if (decl.val.castTag(.variable)) |var_payload|
557557 try dg.renderFwdDecl(decl_index, var_payload.data);
558558
559 if (ty.isSlice()) {
559 if (ty.isSlice(mod)) {
560560 if (location == .StaticInitializer) {
561561 try writer.writeByte('{');
562562 } else {
......@@ -603,7 +603,7 @@ pub const DeclGen = struct {
603603 fn renderParentPtr(dg: *DeclGen, writer: anytype, ptr_val: Value, ptr_ty: Type, location: ValueRenderLocation) error{ OutOfMemory, AnalysisFail }!void {
604604 const mod = dg.module;
605605
606 if (!ptr_ty.isSlice()) {
606 if (!ptr_ty.isSlice(mod)) {
607607 try writer.writeByte('(');
608608 try dg.renderType(writer, ptr_ty);
609609 try writer.writeByte(')');
......@@ -776,7 +776,7 @@ pub const DeclGen = struct {
776776 try dg.renderValue(writer, repr_ty, Value.undef, .FunctionArgument);
777777 return writer.writeByte(')');
778778 },
779 .Pointer => if (ty.isSlice()) {
779 .Pointer => if (ty.isSlice(mod)) {
780780 if (!location.isInitializer()) {
781781 try writer.writeByte('(');
782782 try dg.renderType(writer, ty);
......@@ -1045,7 +1045,7 @@ pub const DeclGen = struct {
10451045 return;
10461046 },
10471047 .Pointer => switch (val.tag()) {
1048 .null_value, .zero => if (ty.isSlice()) {
1048 .null_value, .zero => if (ty.isSlice(mod)) {
10491049 var slice_pl = Value.Payload.Slice{
10501050 .base = .{ .tag = .slice },
10511051 .data = .{ .ptr = val, .len = Value.undef },
......@@ -5073,7 +5073,7 @@ fn airIsNull(
50735073 TypedValue{ .ty = optional_ty, .val = Value.null }
50745074 else if (payload_ty.zigTypeTag(mod) == .ErrorSet)
50755075 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: {
50775077 try writer.writeAll(".ptr");
50785078 const slice_ptr_ty = payload_ty.slicePtrFieldType(&slice_ptr_buf);
50795079 break :rhs TypedValue{ .ty = slice_ptr_ty, .val = Value.null };
......@@ -5864,6 +5864,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
58645864}
58655865
58665866fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {
5867 const mod = f.object.dg.module;
58675868 const un_op = f.air.instructions.items(.data)[inst].un_op;
58685869
58695870 const operand = try f.resolveInst(un_op);
......@@ -5877,7 +5878,7 @@ fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {
58775878 try writer.writeAll(" = (");
58785879 try f.renderType(writer, inst_ty);
58795880 try writer.writeByte(')');
5880 if (operand_ty.isSlice()) {
5881 if (operand_ty.isSlice(mod)) {
58815882 try f.writeCValueMember(writer, operand, .{ .identifier = "len" });
58825883 } else {
58835884 try f.writeCValue(writer, operand, .Other);
......@@ -6272,7 +6273,8 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
62726273}
62736274
62746275fn 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)) {
62766278 try f.writeCValueMember(writer, ptr, .{ .identifier = "ptr" });
62776279 } else {
62786280 try f.writeCValue(writer, ptr, .FunctionArgument);
src/codegen/llvm.zig+8-7
......@@ -1636,7 +1636,7 @@ pub const Object = struct {
16361636 return ptr_di_ty;
16371637 }
16381638
1639 if (ty.isSlice()) {
1639 if (ty.isSlice(mod)) {
16401640 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
16411641 const ptr_ty = ty.slicePtrFieldType(&buf);
16421642 const len_ty = Type.usize;
......@@ -2833,7 +2833,7 @@ pub const DeclGen = struct {
28332833 },
28342834 .Bool => return dg.context.intType(1),
28352835 .Pointer => {
2836 if (t.isSlice()) {
2836 if (t.isSlice(mod)) {
28372837 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
28382838 const ptr_type = t.slicePtrFieldType(&buf);
28392839
......@@ -4110,7 +4110,7 @@ pub const DeclGen = struct {
41104110 }
41114111 },
41124112 .Pointer => {
4113 assert(parent_ty.isSlice());
4113 assert(parent_ty.isSlice(mod));
41144114 const indices: [2]*llvm.Value = .{
41154115 llvm_u32.constInt(0, .False),
41164116 llvm_u32.constInt(field_index, .False),
......@@ -4184,7 +4184,7 @@ pub const DeclGen = struct {
41844184 decl_index: Module.Decl.Index,
41854185 ) Error!*llvm.Value {
41864186 const mod = self.module;
4187 if (tv.ty.isSlice()) {
4187 if (tv.ty.isSlice(mod)) {
41884188 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
41894189 const ptr_ty = tv.ty.slicePtrFieldType(&buf);
41904190 var slice_len: Value.Payload.U64 = .{
......@@ -5794,7 +5794,8 @@ pub const FuncGen = struct {
57945794 }
57955795
57965796 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)) {
57985799 return fg.builder.buildExtractValue(ptr, 0, "");
57995800 } else {
58005801 return ptr;
......@@ -6669,7 +6670,7 @@ pub const FuncGen = struct {
66696670 self.builder.buildLoad(optional_llvm_ty, operand, "")
66706671 else
66716672 operand;
6672 if (payload_ty.isSlice()) {
6673 if (payload_ty.isSlice(mod)) {
66736674 const slice_ptr = self.builder.buildExtractValue(loaded, 0, "");
66746675 var slice_buf: Type.SlicePtrFieldTypeBuffer = undefined;
66756676 const ptr_ty = try self.dg.lowerType(payload_ty.slicePtrFieldType(&slice_buf));
......@@ -10864,7 +10865,7 @@ const ParamTypeIterator = struct {
1086410865 it.zig_index += 1;
1086510866 it.llvm_index += 1;
1086610867 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))) {
1086810869 it.llvm_index += 1;
1086910870 return .slice;
1087010871 } else if (isByRef(ty, mod)) {
src/codegen/spirv.zig+2-2
......@@ -2980,12 +2980,12 @@ pub const DeclGen = struct {
29802980 // Pointer payload represents nullability: pointer or slice.
29812981
29822982 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
2983 const ptr_ty = if (payload_ty.isSlice())
2983 const ptr_ty = if (payload_ty.isSlice(mod))
29842984 payload_ty.slicePtrFieldType(&ptr_buf)
29852985 else
29862986 payload_ty;
29872987
2988 const ptr_id = if (payload_ty.isSlice())
2988 const ptr_id = if (payload_ty.isSlice(mod))
29892989 try self.extractField(Type.bool, operand_id, 0)
29902990 else
29912991 operand_id;
src/link/Dwarf.zig+1-1
......@@ -258,7 +258,7 @@ pub const DeclState = struct {
258258 }
259259 },
260260 .Pointer => {
261 if (ty.isSlice()) {
261 if (ty.isSlice(mod)) {
262262 // Slices are structs: struct { .ptr = *, .len = N }
263263 const ptr_bits = target.ptrBitWidth();
264264 const ptr_bytes = @intCast(u8, @divExact(ptr_bits, 8));
src/type.zig+221-212
......@@ -229,7 +229,7 @@ pub const Type = struct {
229229 .Frame,
230230 => 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()),
233233 .Optional => {
234234 if (!is_equality_cmp) return false;
235235 var buf: Payload.ElemType = undefined;
......@@ -369,209 +369,212 @@ pub const Type = struct {
369369 }
370370
371371 pub fn ptrInfo(self: Type) Payload.Pointer {
372 switch (self.tag()) {
373 .single_const_pointer_to_comptime_int => return .{ .data = .{
374 .pointee_type = Type.comptime_int,
375 .sentinel = null,
376 .@"align" = 0,
377 .@"addrspace" = .generic,
378 .bit_offset = 0,
379 .host_size = 0,
380 .@"allowzero" = false,
381 .mutable = false,
382 .@"volatile" = false,
383 .size = .One,
384 } },
385 .const_slice_u8 => return .{ .data = .{
386 .pointee_type = Type.u8,
387 .sentinel = null,
388 .@"align" = 0,
389 .@"addrspace" = .generic,
390 .bit_offset = 0,
391 .host_size = 0,
392 .@"allowzero" = false,
393 .mutable = false,
394 .@"volatile" = false,
395 .size = .Slice,
396 } },
397 .const_slice_u8_sentinel_0 => return .{ .data = .{
398 .pointee_type = Type.u8,
399 .sentinel = Value.zero,
400 .@"align" = 0,
401 .@"addrspace" = .generic,
402 .bit_offset = 0,
403 .host_size = 0,
404 .@"allowzero" = false,
405 .mutable = false,
406 .@"volatile" = false,
407 .size = .Slice,
408 } },
409 .single_const_pointer => return .{ .data = .{
410 .pointee_type = self.castPointer().?.data,
411 .sentinel = null,
412 .@"align" = 0,
413 .@"addrspace" = .generic,
414 .bit_offset = 0,
415 .host_size = 0,
416 .@"allowzero" = false,
417 .mutable = false,
418 .@"volatile" = false,
419 .size = .One,
420 } },
421 .single_mut_pointer => return .{ .data = .{
422 .pointee_type = self.castPointer().?.data,
423 .sentinel = null,
424 .@"align" = 0,
425 .@"addrspace" = .generic,
426 .bit_offset = 0,
427 .host_size = 0,
428 .@"allowzero" = false,
429 .mutable = true,
430 .@"volatile" = false,
431 .size = .One,
432 } },
433 .many_const_pointer => return .{ .data = .{
434 .pointee_type = self.castPointer().?.data,
435 .sentinel = null,
436 .@"align" = 0,
437 .@"addrspace" = .generic,
438 .bit_offset = 0,
439 .host_size = 0,
440 .@"allowzero" = false,
441 .mutable = false,
442 .@"volatile" = false,
443 .size = .Many,
444 } },
445 .manyptr_const_u8 => return .{ .data = .{
446 .pointee_type = Type.u8,
447 .sentinel = null,
448 .@"align" = 0,
449 .@"addrspace" = .generic,
450 .bit_offset = 0,
451 .host_size = 0,
452 .@"allowzero" = false,
453 .mutable = false,
454 .@"volatile" = false,
455 .size = .Many,
456 } },
457 .manyptr_const_u8_sentinel_0 => return .{ .data = .{
458 .pointee_type = Type.u8,
459 .sentinel = Value.zero,
460 .@"align" = 0,
461 .@"addrspace" = .generic,
462 .bit_offset = 0,
463 .host_size = 0,
464 .@"allowzero" = false,
465 .mutable = false,
466 .@"volatile" = false,
467 .size = .Many,
468 } },
469 .many_mut_pointer => return .{ .data = .{
470 .pointee_type = self.castPointer().?.data,
471 .sentinel = null,
472 .@"align" = 0,
473 .@"addrspace" = .generic,
474 .bit_offset = 0,
475 .host_size = 0,
476 .@"allowzero" = false,
477 .mutable = true,
478 .@"volatile" = false,
479 .size = .Many,
480 } },
481 .manyptr_u8 => return .{ .data = .{
482 .pointee_type = Type.u8,
483 .sentinel = null,
484 .@"align" = 0,
485 .@"addrspace" = .generic,
486 .bit_offset = 0,
487 .host_size = 0,
488 .@"allowzero" = false,
489 .mutable = true,
490 .@"volatile" = false,
491 .size = .Many,
492 } },
493 .c_const_pointer => return .{ .data = .{
494 .pointee_type = self.castPointer().?.data,
495 .sentinel = null,
496 .@"align" = 0,
497 .@"addrspace" = .generic,
498 .bit_offset = 0,
499 .host_size = 0,
500 .@"allowzero" = true,
501 .mutable = false,
502 .@"volatile" = false,
503 .size = .C,
504 } },
505 .c_mut_pointer => return .{ .data = .{
506 .pointee_type = self.castPointer().?.data,
507 .sentinel = null,
508 .@"align" = 0,
509 .@"addrspace" = .generic,
510 .bit_offset = 0,
511 .host_size = 0,
512 .@"allowzero" = true,
513 .mutable = true,
514 .@"volatile" = false,
515 .size = .C,
516 } },
517 .const_slice => return .{ .data = .{
518 .pointee_type = self.castPointer().?.data,
519 .sentinel = null,
520 .@"align" = 0,
521 .@"addrspace" = .generic,
522 .bit_offset = 0,
523 .host_size = 0,
524 .@"allowzero" = false,
525 .mutable = false,
526 .@"volatile" = false,
527 .size = .Slice,
528 } },
529 .mut_slice => return .{ .data = .{
530 .pointee_type = self.castPointer().?.data,
531 .sentinel = null,
532 .@"align" = 0,
533 .@"addrspace" = .generic,
534 .bit_offset = 0,
535 .host_size = 0,
536 .@"allowzero" = false,
537 .mutable = true,
538 .@"volatile" = false,
539 .size = .Slice,
540 } },
541
542 .pointer => return self.castTag(.pointer).?.*,
543
544 .optional_single_mut_pointer => return .{ .data = .{
545 .pointee_type = self.castPointer().?.data,
546 .sentinel = null,
547 .@"align" = 0,
548 .@"addrspace" = .generic,
549 .bit_offset = 0,
550 .host_size = 0,
551 .@"allowzero" = false,
552 .mutable = true,
553 .@"volatile" = false,
554 .size = .One,
555 } },
556 .optional_single_const_pointer => return .{ .data = .{
557 .pointee_type = self.castPointer().?.data,
558 .sentinel = null,
559 .@"align" = 0,
560 .@"addrspace" = .generic,
561 .bit_offset = 0,
562 .host_size = 0,
563 .@"allowzero" = false,
564 .mutable = false,
565 .@"volatile" = false,
566 .size = .One,
567 } },
568 .optional => {
569 var buf: Payload.ElemType = undefined;
570 const child_type = self.optionalChild(&buf);
571 return child_type.ptrInfo();
572 },
372 switch (self.ip_index) {
373 .none => switch (self.tag()) {
374 .single_const_pointer_to_comptime_int => return .{ .data = .{
375 .pointee_type = Type.comptime_int,
376 .sentinel = null,
377 .@"align" = 0,
378 .@"addrspace" = .generic,
379 .bit_offset = 0,
380 .host_size = 0,
381 .@"allowzero" = false,
382 .mutable = false,
383 .@"volatile" = false,
384 .size = .One,
385 } },
386 .const_slice_u8 => return .{ .data = .{
387 .pointee_type = Type.u8,
388 .sentinel = null,
389 .@"align" = 0,
390 .@"addrspace" = .generic,
391 .bit_offset = 0,
392 .host_size = 0,
393 .@"allowzero" = false,
394 .mutable = false,
395 .@"volatile" = false,
396 .size = .Slice,
397 } },
398 .const_slice_u8_sentinel_0 => return .{ .data = .{
399 .pointee_type = Type.u8,
400 .sentinel = Value.zero,
401 .@"align" = 0,
402 .@"addrspace" = .generic,
403 .bit_offset = 0,
404 .host_size = 0,
405 .@"allowzero" = false,
406 .mutable = false,
407 .@"volatile" = false,
408 .size = .Slice,
409 } },
410 .single_const_pointer => return .{ .data = .{
411 .pointee_type = self.castPointer().?.data,
412 .sentinel = null,
413 .@"align" = 0,
414 .@"addrspace" = .generic,
415 .bit_offset = 0,
416 .host_size = 0,
417 .@"allowzero" = false,
418 .mutable = false,
419 .@"volatile" = false,
420 .size = .One,
421 } },
422 .single_mut_pointer => return .{ .data = .{
423 .pointee_type = self.castPointer().?.data,
424 .sentinel = null,
425 .@"align" = 0,
426 .@"addrspace" = .generic,
427 .bit_offset = 0,
428 .host_size = 0,
429 .@"allowzero" = false,
430 .mutable = true,
431 .@"volatile" = false,
432 .size = .One,
433 } },
434 .many_const_pointer => return .{ .data = .{
435 .pointee_type = self.castPointer().?.data,
436 .sentinel = null,
437 .@"align" = 0,
438 .@"addrspace" = .generic,
439 .bit_offset = 0,
440 .host_size = 0,
441 .@"allowzero" = false,
442 .mutable = false,
443 .@"volatile" = false,
444 .size = .Many,
445 } },
446 .manyptr_const_u8 => return .{ .data = .{
447 .pointee_type = Type.u8,
448 .sentinel = null,
449 .@"align" = 0,
450 .@"addrspace" = .generic,
451 .bit_offset = 0,
452 .host_size = 0,
453 .@"allowzero" = false,
454 .mutable = false,
455 .@"volatile" = false,
456 .size = .Many,
457 } },
458 .manyptr_const_u8_sentinel_0 => return .{ .data = .{
459 .pointee_type = Type.u8,
460 .sentinel = Value.zero,
461 .@"align" = 0,
462 .@"addrspace" = .generic,
463 .bit_offset = 0,
464 .host_size = 0,
465 .@"allowzero" = false,
466 .mutable = false,
467 .@"volatile" = false,
468 .size = .Many,
469 } },
470 .many_mut_pointer => return .{ .data = .{
471 .pointee_type = self.castPointer().?.data,
472 .sentinel = null,
473 .@"align" = 0,
474 .@"addrspace" = .generic,
475 .bit_offset = 0,
476 .host_size = 0,
477 .@"allowzero" = false,
478 .mutable = true,
479 .@"volatile" = false,
480 .size = .Many,
481 } },
482 .manyptr_u8 => return .{ .data = .{
483 .pointee_type = Type.u8,
484 .sentinel = null,
485 .@"align" = 0,
486 .@"addrspace" = .generic,
487 .bit_offset = 0,
488 .host_size = 0,
489 .@"allowzero" = false,
490 .mutable = true,
491 .@"volatile" = false,
492 .size = .Many,
493 } },
494 .c_const_pointer => return .{ .data = .{
495 .pointee_type = self.castPointer().?.data,
496 .sentinel = null,
497 .@"align" = 0,
498 .@"addrspace" = .generic,
499 .bit_offset = 0,
500 .host_size = 0,
501 .@"allowzero" = true,
502 .mutable = false,
503 .@"volatile" = false,
504 .size = .C,
505 } },
506 .c_mut_pointer => return .{ .data = .{
507 .pointee_type = self.castPointer().?.data,
508 .sentinel = null,
509 .@"align" = 0,
510 .@"addrspace" = .generic,
511 .bit_offset = 0,
512 .host_size = 0,
513 .@"allowzero" = true,
514 .mutable = true,
515 .@"volatile" = false,
516 .size = .C,
517 } },
518 .const_slice => return .{ .data = .{
519 .pointee_type = self.castPointer().?.data,
520 .sentinel = null,
521 .@"align" = 0,
522 .@"addrspace" = .generic,
523 .bit_offset = 0,
524 .host_size = 0,
525 .@"allowzero" = false,
526 .mutable = false,
527 .@"volatile" = false,
528 .size = .Slice,
529 } },
530 .mut_slice => return .{ .data = .{
531 .pointee_type = self.castPointer().?.data,
532 .sentinel = null,
533 .@"align" = 0,
534 .@"addrspace" = .generic,
535 .bit_offset = 0,
536 .host_size = 0,
537 .@"allowzero" = false,
538 .mutable = true,
539 .@"volatile" = false,
540 .size = .Slice,
541 } },
542
543 .pointer => return self.castTag(.pointer).?.*,
544
545 .optional_single_mut_pointer => return .{ .data = .{
546 .pointee_type = self.castPointer().?.data,
547 .sentinel = null,
548 .@"align" = 0,
549 .@"addrspace" = .generic,
550 .bit_offset = 0,
551 .host_size = 0,
552 .@"allowzero" = false,
553 .mutable = true,
554 .@"volatile" = false,
555 .size = .One,
556 } },
557 .optional_single_const_pointer => return .{ .data = .{
558 .pointee_type = self.castPointer().?.data,
559 .sentinel = null,
560 .@"align" = 0,
561 .@"addrspace" = .generic,
562 .bit_offset = 0,
563 .host_size = 0,
564 .@"allowzero" = false,
565 .mutable = false,
566 .@"volatile" = false,
567 .size = .One,
568 } },
569 .optional => {
570 var buf: Payload.ElemType = undefined;
571 const child_type = self.optionalChild(&buf);
572 return child_type.ptrInfo();
573 },
573574
574 else => unreachable,
575 else => unreachable,
576 },
577 else => @panic("TODO"),
575578 }
576579 }
577580
......@@ -3712,17 +3715,23 @@ pub const Type = struct {
37123715 };
37133716 }
37143717
3715 pub fn isSlice(self: Type) bool {
3716 return switch (self.tag()) {
3717 .const_slice,
3718 .mut_slice,
3719 .const_slice_u8,
3720 .const_slice_u8_sentinel_0,
3721 => true,
3718 pub fn isSlice(ty: Type, mod: *const Module) bool {
3719 return switch (ty.ip_index) {
3720 .none => switch (ty.tag()) {
3721 .const_slice,
3722 .mut_slice,
3723 .const_slice_u8,
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 },
37263735 };
37273736 }
37283737
src/value.zig+4-4
......@@ -1144,7 +1144,7 @@ pub const Value = struct {
11441144 },
11451145 },
11461146 .Pointer => {
1147 if (ty.isSlice()) return error.IllDefinedMemoryLayout;
1147 if (ty.isSlice(mod)) return error.IllDefinedMemoryLayout;
11481148 if (val.isDeclRef()) return error.ReinterpretDeclRef;
11491149 return val.writeToMemory(Type.usize, mod, buffer);
11501150 },
......@@ -1261,7 +1261,7 @@ pub const Value = struct {
12611261 },
12621262 },
12631263 .Pointer => {
1264 assert(!ty.isSlice()); // No well defined layout.
1264 assert(!ty.isSlice(mod)); // No well defined layout.
12651265 if (val.isDeclRef()) return error.ReinterpretDeclRef;
12661266 return val.writeToPackedMemory(Type.usize, mod, buffer, bit_offset);
12671267 },
......@@ -1381,7 +1381,7 @@ pub const Value = struct {
13811381 return Value.initPayload(&payload.base);
13821382 },
13831383 .Pointer => {
1384 assert(!ty.isSlice()); // No well defined layout.
1384 assert(!ty.isSlice(mod)); // No well defined layout.
13851385 return readFromMemory(Type.usize, mod, buffer, arena);
13861386 },
13871387 .Optional => {
......@@ -1478,7 +1478,7 @@ pub const Value = struct {
14781478 },
14791479 },
14801480 .Pointer => {
1481 assert(!ty.isSlice()); // No well defined layout.
1481 assert(!ty.isSlice(mod)); // No well defined layout.
14821482 return readFromPackedMemory(Type.usize, mod, buffer, bit_offset, arena);
14831483 },
14841484 .Optional => {