| author | |
| committer | |
| log | 85c69c51945d7fb5d4cd2dea03fdb7915ecc55fa |
| tree | 2705f666129a04e8100861d056f6df9bb89fd582 |
| parent | fb16ad3add77eff23f9c5dbaf802fdecfb4c8cc0 |
16 files changed, 341 insertions(+), 287 deletions(-)
src/InternPool.zig+45-5| ... | ... | @@ -629,7 +629,7 @@ pub const Tag = enum(u8) { |
| 629 | 629 | /// A vector type. |
| 630 | 630 | /// data is payload to Vector. |
| 631 | 631 | type_vector, |
| 632 | /// A pointer type along with all its bells and whistles. | |
| 632 | /// A fully explicitly specified pointer type. | |
| 633 | 633 | /// data is payload to Pointer. |
| 634 | 634 | type_pointer, |
| 635 | 635 | /// An optional type. |
| ... | ... | @@ -682,13 +682,13 @@ pub const Tag = enum(u8) { |
| 682 | 682 | /// An enum tag identified by a negative integer value. |
| 683 | 683 | /// data is a limbs index to Int. |
| 684 | 684 | enum_tag_negative, |
| 685 | /// A float value that can be represented by f32. | |
| 685 | /// An f32 value. | |
| 686 | 686 | /// data is float value bitcasted to u32. |
| 687 | 687 | float_f32, |
| 688 | /// A float value that can be represented by f64. | |
| 688 | /// An f64 value. | |
| 689 | 689 | /// data is payload index to Float64. |
| 690 | 690 | float_f64, |
| 691 | /// A float value that can be represented by f128. | |
| 691 | /// An f128 value. | |
| 692 | 692 | /// data is payload index to Float128. |
| 693 | 693 | float_f128, |
| 694 | 694 | /// An extern function. |
| ... | ... | @@ -871,7 +871,47 @@ pub fn indexToKey(ip: InternPool, index: Index) Key { |
| 871 | 871 | .simple_type => .{ .simple_type = @intToEnum(SimpleType, data) }, |
| 872 | 872 | .simple_value => .{ .simple_value = @intToEnum(SimpleValue, data) }, |
| 873 | 873 | |
| 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 | } |
| 877 | 917 |
src/Sema.zig+28-28| ... | ... | @@ -2030,7 +2030,7 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty |
| 2030 | 2030 | ty.fmt(mod), |
| 2031 | 2031 | }); |
| 2032 | 2032 | errdefer msg.destroy(sema.gpa); |
| 2033 | if (ty.isSlice()) { | |
| 2033 | if (ty.isSlice(mod)) { | |
| 2034 | 2034 | try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)}); |
| 2035 | 2035 | } |
| 2036 | 2036 | break :msg msg; |
| ... | ... | @@ -10359,7 +10359,7 @@ fn zirSwitchCond( |
| 10359 | 10359 | .ErrorSet, |
| 10360 | 10360 | .Enum, |
| 10361 | 10361 | => { |
| 10362 | if (operand_ty.isSlice()) { | |
| 10362 | if (operand_ty.isSlice(mod)) { | |
| 10363 | 10363 | return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)}); |
| 10364 | 10364 | } |
| 10365 | 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 | 12017 | const ty = try sema.resolveTypeFields(unresolved_ty); |
| 12018 | 12018 | |
| 12019 | 12019 | const has_field = hf: { |
| 12020 | if (ty.isSlice()) { | |
| 12020 | if (ty.isSlice(mod)) { | |
| 12021 | 12021 | if (mem.eql(u8, field_name, "ptr")) break :hf true; |
| 12022 | 12022 | if (mem.eql(u8, field_name, "len")) break :hf true; |
| 12023 | 12023 | break :hf false; |
| ... | ... | @@ -20020,8 +20020,8 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20020 | 20020 | return sema.failWithOwnedErrorMsg(msg); |
| 20021 | 20021 | } |
| 20022 | 20022 | |
| 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); | |
| 20025 | 20025 | if (dest_is_slice and !operand_is_slice) { |
| 20026 | 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 | 20274 | Type.usize, |
| 20275 | 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 | 20278 | try sema.analyzeSlicePtr(block, ptr_src, ptr, ptr_ty) |
| 20279 | 20279 | else |
| 20280 | 20280 | ptr; |
| 20281 | 20281 | const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr); |
| 20282 | 20282 | const remainder = try block.addBinOp(.bit_and, ptr_int, align_minus_1); |
| 20283 | 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 | 20285 | const len = try sema.analyzeSliceLen(block, ptr_src, ptr); |
| 20286 | 20286 | const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize); |
| 20287 | 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 | 22336 | // Change the src from slice to a many pointer, to avoid multiple ptr |
| 22337 | 22337 | // slice extractions in AIR instructions. |
| 22338 | 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 | 22340 | new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty); |
| 22341 | 22341 | } |
| 22342 | 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 | 22344 | const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr); |
| 22345 | 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 | 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 | 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 | 22363 | // Extract raw pointer from dest slice. The AIR instructions could support them, but |
| 22364 | 22364 | // it would cause redundant machine code instructions. |
| 22365 | 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 | 22367 | try sema.analyzeSlicePtr(block, dest_src, new_dest_ptr, new_dest_ptr_ty) |
| 22368 | 22368 | else |
| 22369 | 22369 | new_dest_ptr; |
| ... | ... | @@ -23383,7 +23383,7 @@ fn validateExternType( |
| 23383 | 23383 | .Float, |
| 23384 | 23384 | .AnyFrame, |
| 23385 | 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 | 23387 | .Int => switch (ty.intInfo(mod).bits) { |
| 23388 | 23388 | 8, 16, 32, 64, 128 => return true, |
| 23389 | 23389 | else => return false, |
| ... | ... | @@ -23448,7 +23448,7 @@ fn explainWhyTypeIsNotExtern( |
| 23448 | 23448 | => return, |
| 23449 | 23449 | |
| 23450 | 23450 | .Pointer => { |
| 23451 | if (ty.isSlice()) { | |
| 23451 | if (ty.isSlice(mod)) { | |
| 23452 | 23452 | try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); |
| 23453 | 23453 | } else { |
| 23454 | 23454 | const pointee_ty = ty.childType(); |
| ... | ... | @@ -23523,7 +23523,7 @@ fn validatePackedType(ty: Type, mod: *const Module) bool { |
| 23523 | 23523 | .Vector, |
| 23524 | 23524 | .Enum, |
| 23525 | 23525 | => return true, |
| 23526 | .Pointer => return !ty.isSlice(), | |
| 23526 | .Pointer => return !ty.isSlice(mod), | |
| 23527 | 23527 | .Struct, .Union => return ty.containerLayout() == .Packed, |
| 23528 | 23528 | } |
| 23529 | 23529 | } |
| ... | ... | @@ -23803,7 +23803,7 @@ fn panicSentinelMismatch( |
| 23803 | 23803 | const expected_sentinel = try sema.addConstant(sentinel_ty, expected_sentinel_val); |
| 23804 | 23804 | |
| 23805 | 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 | 23807 | try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index) |
| 23808 | 23808 | else blk: { |
| 23809 | 23809 | const elem_ptr_ty = try sema.elemPtrType(ptr_ty, null); |
| ... | ... | @@ -24064,7 +24064,7 @@ fn fieldVal( |
| 24064 | 24064 | const msg = msg: { |
| 24065 | 24065 | const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)}); |
| 24066 | 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 | 24068 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); |
| 24069 | 24069 | break :msg msg; |
| 24070 | 24070 | }; |
| ... | ... | @@ -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 | 24144 | const inner_ptr = if (is_pointer_to) |
| 24145 | 24145 | try sema.analyzeLoad(block, src, object_ptr, object_ptr_src) |
| 24146 | 24146 | else |
| ... | ... | @@ -25743,8 +25743,8 @@ fn coerceExtra( |
| 25743 | 25743 | } }; |
| 25744 | 25744 | break :pointer; |
| 25745 | 25745 | } |
| 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)) { | |
| 25748 | 25748 | in_memory_result = .{ .slice_to_anyopaque = .{ |
| 25749 | 25749 | .actual = inst_ty, |
| 25750 | 25750 | .wanted = dest_ty, |
| ... | ... | @@ -25885,7 +25885,7 @@ fn coerceExtra( |
| 25885 | 25885 | return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src); |
| 25886 | 25886 | }, |
| 25887 | 25887 | .Many => p: { |
| 25888 | if (!inst_ty.isSlice()) break :p; | |
| 25888 | if (!inst_ty.isSlice(mod)) break :p; | |
| 25889 | 25889 | if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :p; |
| 25890 | 25890 | const inst_info = inst_ty.ptrInfo().data; |
| 25891 | 25891 | |
| ... | ... | @@ -26651,7 +26651,7 @@ fn coerceInMemoryAllowed( |
| 26651 | 26651 | } |
| 26652 | 26652 | |
| 26653 | 26653 | // Slices |
| 26654 | if (dest_ty.isSlice() and src_ty.isSlice()) { | |
| 26654 | if (dest_ty.isSlice(mod) and src_ty.isSlice(mod)) { | |
| 26655 | 26655 | return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ty, src_ty, dest_is_mut, target, dest_src, src_src); |
| 26656 | 26656 | } |
| 26657 | 26657 | |
| ... | ... | @@ -27744,7 +27744,7 @@ fn beginComptimePtrMutation( |
| 27744 | 27744 | ); |
| 27745 | 27745 | }, |
| 27746 | 27746 | .Pointer => { |
| 27747 | assert(parent.ty.isSlice()); | |
| 27747 | assert(parent.ty.isSlice(mod)); | |
| 27748 | 27748 | val_ptr.* = try Value.Tag.slice.create(arena, .{ |
| 27749 | 27749 | .ptr = Value.undef, |
| 27750 | 27750 | .len = Value.undef, |
| ... | ... | @@ -28187,7 +28187,7 @@ fn beginComptimePtrLoad( |
| 28187 | 28187 | break :blk deref; |
| 28188 | 28188 | } |
| 28189 | 28189 | |
| 28190 | if (field_ptr.container_ty.isSlice()) { | |
| 28190 | if (field_ptr.container_ty.isSlice(mod)) { | |
| 28191 | 28191 | const slice_val = tv.val.castTag(.slice).?.data; |
| 28192 | 28192 | deref.pointee = switch (field_index) { |
| 28193 | 28193 | Value.Payload.Slice.ptr_index => TypedValue{ |
| ... | ... | @@ -28442,13 +28442,13 @@ fn coerceCompatiblePtrs( |
| 28442 | 28442 | if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(mod) and |
| 28443 | 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 | 28446 | try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty) |
| 28447 | 28447 | else |
| 28448 | 28448 | inst; |
| 28449 | 28449 | const ptr_int = try block.addUnOp(.ptrtoint, actual_ptr); |
| 28450 | 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 | 28452 | const len = try sema.analyzeSliceLen(block, inst_src, inst); |
| 28453 | 28453 | const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize); |
| 28454 | 28454 | break :ok try block.addBinOp(.bit_or, len_zero, is_non_zero); |
| ... | ... | @@ -29548,7 +29548,7 @@ fn analyzeSlice( |
| 29548 | 29548 | else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}), |
| 29549 | 29549 | } |
| 29550 | 29550 | |
| 29551 | const ptr = if (slice_ty.isSlice()) | |
| 29551 | const ptr = if (slice_ty.isSlice(mod)) | |
| 29552 | 29552 | try sema.analyzeSlicePtr(block, ptr_src, ptr_or_slice, slice_ty) |
| 29553 | 29553 | else |
| 29554 | 29554 | ptr_or_slice; |
| ... | ... | @@ -29605,7 +29605,7 @@ fn analyzeSlice( |
| 29605 | 29605 | } |
| 29606 | 29606 | |
| 29607 | 29607 | break :e try sema.addConstant(Type.usize, len_val); |
| 29608 | } else if (slice_ty.isSlice()) { | |
| 29608 | } else if (slice_ty.isSlice(mod)) { | |
| 29609 | 29609 | if (!end_is_len) { |
| 29610 | 29610 | const end = if (by_length) end: { |
| 29611 | 29611 | const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |
| ... | ... | @@ -29778,7 +29778,7 @@ fn analyzeSlice( |
| 29778 | 29778 | try sema.addSafetyCheck(block, is_non_null, .unwrap_null); |
| 29779 | 29779 | } |
| 29780 | 29780 | |
| 29781 | if (slice_ty.isSlice()) { | |
| 29781 | if (slice_ty.isSlice(mod)) { | |
| 29782 | 29782 | const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice); |
| 29783 | 29783 | const actual_len = if (slice_ty.sentinel() == null) |
| 29784 | 29784 | slice_len_inst |
| ... | ... | @@ -29840,7 +29840,7 @@ fn analyzeSlice( |
| 29840 | 29840 | // requirement: end <= len |
| 29841 | 29841 | const opt_len_inst = if (array_ty.zigTypeTag(mod) == .Array) |
| 29842 | 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 | 29844 | if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| { |
| 29845 | 29845 | // we don't need to add one for sentinels because the |
| 29846 | 29846 | // underlying value data includes the sentinel |
src/TypedValue.zig+1-1| ... | ... | @@ -259,7 +259,7 @@ pub fn print( |
| 259 | 259 | } else if (field_ptr.container_ty.zigTypeTag(mod) == .Union) { |
| 260 | 260 | const field_name = field_ptr.container_ty.unionFields().keys()[field_ptr.field_index]; |
| 261 | 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 | 263 | switch (field_ptr.field_index) { |
| 264 | 264 | Value.Payload.Slice.ptr_index => return writer.writeAll(".ptr"), |
| 265 | 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 | 52 | return .byval; |
| 53 | 53 | }, |
| 54 | 54 | .Pointer => { |
| 55 | std.debug.assert(!ty.isSlice()); | |
| 55 | std.debug.assert(!ty.isSlice(mod)); | |
| 56 | 56 | return .byval; |
| 57 | 57 | }, |
| 58 | 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 | 94 | return .byval; |
| 95 | 95 | }, |
| 96 | 96 | .Pointer => { |
| 97 | assert(!ty.isSlice()); | |
| 97 | assert(!ty.isSlice(mod)); | |
| 98 | 98 | return .byval; |
| 99 | 99 | }, |
| 100 | 100 | .ErrorUnion, |
src/arch/riscv64/abi.zig+1-1| ... | ... | @@ -52,7 +52,7 @@ pub fn classifyType(ty: Type, mod: *const Module) Class { |
| 52 | 52 | return .byval; |
| 53 | 53 | }, |
| 54 | 54 | .Pointer => { |
| 55 | std.debug.assert(!ty.isSlice()); | |
| 55 | std.debug.assert(!ty.isSlice(mod)); | |
| 56 | 56 | return .byval; |
| 57 | 57 | }, |
| 58 | 58 | .ErrorUnion, |
src/arch/wasm/CodeGen.zig+11-9| ... | ... | @@ -1773,7 +1773,7 @@ fn isByRef(ty: Type, mod: *const Module) bool { |
| 1773 | 1773 | }, |
| 1774 | 1774 | .Pointer => { |
| 1775 | 1775 | // Slices act like struct and will be passed by reference |
| 1776 | if (ty.isSlice()) return true; | |
| 1776 | if (ty.isSlice(mod)) return true; | |
| 1777 | 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 | 2396 | }, |
| 2397 | 2397 | }, |
| 2398 | 2398 | .Pointer => { |
| 2399 | if (ty.isSlice()) { | |
| 2399 | if (ty.isSlice(mod)) { | |
| 2400 | 2400 | // store pointer first |
| 2401 | 2401 | // lower it to the stack so we do not have to store rhs into a local first |
| 2402 | 2402 | try func.emitWValue(lhs); |
| ... | ... | @@ -3010,11 +3010,11 @@ fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: Module.Decl.In |
| 3010 | 3010 | } |
| 3011 | 3011 | |
| 3012 | 3012 | fn 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 | 3015 | return WValue{ .memory = try func.bin_file.lowerUnnamedConst(tv, decl_index) }; |
| 3015 | 3016 | } |
| 3016 | 3017 | |
| 3017 | const mod = func.bin_file.base.options.module.?; | |
| 3018 | 3018 | const decl = mod.declPtr(decl_index); |
| 3019 | 3019 | if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 3020 | 3020 | return WValue{ .imm32 = 0xaaaaaaaa }; |
| ... | ... | @@ -4182,7 +4182,7 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod |
| 4182 | 4182 | }; |
| 4183 | 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 | 4186 | switch (func.arch()) { |
| 4187 | 4187 | .wasm32 => try func.addMemArg(.i32_load, .{ .offset = operand.offset(), .alignment = 4 }), |
| 4188 | 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 | 4455 | } |
| 4456 | 4456 | |
| 4457 | 4457 | fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4458 | const mod = func.bin_file.base.options.module.?; | |
| 4458 | 4459 | const un_op = func.air.instructions.items(.data)[inst].un_op; |
| 4459 | 4460 | const operand = try func.resolveInst(un_op); |
| 4460 | 4461 | const ptr_ty = func.typeOf(un_op); |
| 4461 | const result = if (ptr_ty.isSlice()) | |
| 4462 | const result = if (ptr_ty.isSlice(mod)) | |
| 4462 | 4463 | try func.slicePtr(operand) |
| 4463 | 4464 | else switch (operand) { |
| 4464 | 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 | 4480 | const elem_size = elem_ty.abiSize(mod); |
| 4480 | 4481 | |
| 4481 | 4482 | // load pointer onto the stack |
| 4482 | if (ptr_ty.isSlice()) { | |
| 4483 | if (ptr_ty.isSlice(mod)) { | |
| 4483 | 4484 | _ = try func.load(ptr, Type.usize, 0); |
| 4484 | 4485 | } else { |
| 4485 | 4486 | try func.lowerToStack(ptr); |
| ... | ... | @@ -4518,7 +4519,7 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4518 | 4519 | const index = try func.resolveInst(bin_op.rhs); |
| 4519 | 4520 | |
| 4520 | 4521 | // load pointer onto the stack |
| 4521 | if (ptr_ty.isSlice()) { | |
| 4522 | if (ptr_ty.isSlice(mod)) { | |
| 4522 | 4523 | _ = try func.load(ptr, Type.usize, 0); |
| 4523 | 4524 | } else { |
| 4524 | 4525 | try func.lowerToStack(ptr); |
| ... | ... | @@ -5441,7 +5442,8 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5441 | 5442 | } |
| 5442 | 5443 | |
| 5443 | 5444 | fn 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 | 5447 | return func.slicePtr(ptr); |
| 5446 | 5448 | } else { |
| 5447 | 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 | 60 | return direct; |
| 61 | 61 | }, |
| 62 | 62 | .Pointer => { |
| 63 | std.debug.assert(!ty.isSlice()); | |
| 63 | std.debug.assert(!ty.isSlice(mod)); | |
| 64 | 64 | return direct; |
| 65 | 65 | }, |
| 66 | 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 | 8688 | |
| 8689 | 8689 | var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 8690 | 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 | 8692 | else |
| 8693 | 8693 | .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool }; |
| 8694 | 8694 | |
| ... | ... | @@ -8781,7 +8781,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue) |
| 8781 | 8781 | |
| 8782 | 8782 | var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 8783 | 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 | 8785 | else |
| 8786 | 8786 | .{ .off = @intCast(i32, pl_ty.abiSize(mod)), .ty = Type.bool }; |
| 8787 | 8787 |
src/codegen.zig+5-5| ... | ... | @@ -317,11 +317,11 @@ pub fn generateSymbol( |
| 317 | 317 | switch (target.ptrBitWidth()) { |
| 318 | 318 | 32 => { |
| 319 | 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 | 322 | 64 => { |
| 323 | 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 | 326 | else => unreachable, |
| 327 | 327 | } |
| ... | ... | @@ -845,7 +845,7 @@ fn lowerParentPtr( |
| 845 | 845 | debug_output, |
| 846 | 846 | reloc_info.offset(@intCast(u32, switch (field_ptr.container_ty.zigTypeTag(mod)) { |
| 847 | 847 | .Pointer => offset: { |
| 848 | assert(field_ptr.container_ty.isSlice()); | |
| 848 | assert(field_ptr.container_ty.isSlice(mod)); | |
| 849 | 849 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 850 | 850 | break :offset switch (field_ptr.field_index) { |
| 851 | 851 | 0 => 0, |
| ... | ... | @@ -946,7 +946,7 @@ fn lowerDeclRef( |
| 946 | 946 | ) CodeGenError!Result { |
| 947 | 947 | const target = bin_file.options.target; |
| 948 | 948 | const mod = bin_file.options.module.?; |
| 949 | if (typed_value.ty.isSlice()) { | |
| 949 | if (typed_value.ty.isSlice(mod)) { | |
| 950 | 950 | // generate ptr |
| 951 | 951 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 952 | 952 | const slice_ptr_field_type = typed_value.ty.slicePtrFieldType(&buf); |
| ... | ... | @@ -1174,7 +1174,7 @@ pub fn genTypedValue( |
| 1174 | 1174 | const target = bin_file.options.target; |
| 1175 | 1175 | const ptr_bits = target.ptrBitWidth(); |
| 1176 | 1176 | |
| 1177 | if (!typed_value.ty.isSlice()) { | |
| 1177 | if (!typed_value.ty.isSlice(mod)) { | |
| 1178 | 1178 | if (typed_value.val.castTag(.variable)) |payload| { |
| 1179 | 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 | 556 | if (decl.val.castTag(.variable)) |var_payload| |
| 557 | 557 | try dg.renderFwdDecl(decl_index, var_payload.data); |
| 558 | 558 | |
| 559 | if (ty.isSlice()) { | |
| 559 | if (ty.isSlice(mod)) { | |
| 560 | 560 | if (location == .StaticInitializer) { |
| 561 | 561 | try writer.writeByte('{'); |
| 562 | 562 | } else { |
| ... | ... | @@ -603,7 +603,7 @@ pub const DeclGen = struct { |
| 603 | 603 | fn renderParentPtr(dg: *DeclGen, writer: anytype, ptr_val: Value, ptr_ty: Type, location: ValueRenderLocation) error{ OutOfMemory, AnalysisFail }!void { |
| 604 | 604 | const mod = dg.module; |
| 605 | 605 | |
| 606 | if (!ptr_ty.isSlice()) { | |
| 606 | if (!ptr_ty.isSlice(mod)) { | |
| 607 | 607 | try writer.writeByte('('); |
| 608 | 608 | try dg.renderType(writer, ptr_ty); |
| 609 | 609 | try writer.writeByte(')'); |
| ... | ... | @@ -776,7 +776,7 @@ pub const DeclGen = struct { |
| 776 | 776 | try dg.renderValue(writer, repr_ty, Value.undef, .FunctionArgument); |
| 777 | 777 | return writer.writeByte(')'); |
| 778 | 778 | }, |
| 779 | .Pointer => if (ty.isSlice()) { | |
| 779 | .Pointer => if (ty.isSlice(mod)) { | |
| 780 | 780 | if (!location.isInitializer()) { |
| 781 | 781 | try writer.writeByte('('); |
| 782 | 782 | try dg.renderType(writer, ty); |
| ... | ... | @@ -1045,7 +1045,7 @@ pub const DeclGen = struct { |
| 1045 | 1045 | return; |
| 1046 | 1046 | }, |
| 1047 | 1047 | .Pointer => switch (val.tag()) { |
| 1048 | .null_value, .zero => if (ty.isSlice()) { | |
| 1048 | .null_value, .zero => if (ty.isSlice(mod)) { | |
| 1049 | 1049 | var slice_pl = Value.Payload.Slice{ |
| 1050 | 1050 | .base = .{ .tag = .slice }, |
| 1051 | 1051 | .data = .{ .ptr = val, .len = Value.undef }, |
| ... | ... | @@ -5073,7 +5073,7 @@ fn airIsNull( |
| 5073 | 5073 | TypedValue{ .ty = optional_ty, .val = Value.null } |
| 5074 | 5074 | else if (payload_ty.zigTypeTag(mod) == .ErrorSet) |
| 5075 | 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 | 5077 | try writer.writeAll(".ptr"); |
| 5078 | 5078 | const slice_ptr_ty = payload_ty.slicePtrFieldType(&slice_ptr_buf); |
| 5079 | 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 | 5864 | } |
| 5865 | 5865 | |
| 5866 | 5866 | fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5867 | const mod = f.object.dg.module; | |
| 5867 | 5868 | const un_op = f.air.instructions.items(.data)[inst].un_op; |
| 5868 | 5869 | |
| 5869 | 5870 | const operand = try f.resolveInst(un_op); |
| ... | ... | @@ -5877,7 +5878,7 @@ fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5877 | 5878 | try writer.writeAll(" = ("); |
| 5878 | 5879 | try f.renderType(writer, inst_ty); |
| 5879 | 5880 | try writer.writeByte(')'); |
| 5880 | if (operand_ty.isSlice()) { | |
| 5881 | if (operand_ty.isSlice(mod)) { | |
| 5881 | 5882 | try f.writeCValueMember(writer, operand, .{ .identifier = "len" }); |
| 5882 | 5883 | } else { |
| 5883 | 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 | 6273 | } |
| 6273 | 6274 | |
| 6274 | 6275 | fn 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 | 6278 | try f.writeCValueMember(writer, ptr, .{ .identifier = "ptr" }); |
| 6277 | 6279 | } else { |
| 6278 | 6280 | try f.writeCValue(writer, ptr, .FunctionArgument); |
src/codegen/llvm.zig+8-7| ... | ... | @@ -1636,7 +1636,7 @@ pub const Object = struct { |
| 1636 | 1636 | return ptr_di_ty; |
| 1637 | 1637 | } |
| 1638 | 1638 | |
| 1639 | if (ty.isSlice()) { | |
| 1639 | if (ty.isSlice(mod)) { | |
| 1640 | 1640 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 1641 | 1641 | const ptr_ty = ty.slicePtrFieldType(&buf); |
| 1642 | 1642 | const len_ty = Type.usize; |
| ... | ... | @@ -2833,7 +2833,7 @@ pub const DeclGen = struct { |
| 2833 | 2833 | }, |
| 2834 | 2834 | .Bool => return dg.context.intType(1), |
| 2835 | 2835 | .Pointer => { |
| 2836 | if (t.isSlice()) { | |
| 2836 | if (t.isSlice(mod)) { | |
| 2837 | 2837 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 2838 | 2838 | const ptr_type = t.slicePtrFieldType(&buf); |
| 2839 | 2839 | |
| ... | ... | @@ -4110,7 +4110,7 @@ pub const DeclGen = struct { |
| 4110 | 4110 | } |
| 4111 | 4111 | }, |
| 4112 | 4112 | .Pointer => { |
| 4113 | assert(parent_ty.isSlice()); | |
| 4113 | assert(parent_ty.isSlice(mod)); | |
| 4114 | 4114 | const indices: [2]*llvm.Value = .{ |
| 4115 | 4115 | llvm_u32.constInt(0, .False), |
| 4116 | 4116 | llvm_u32.constInt(field_index, .False), |
| ... | ... | @@ -4184,7 +4184,7 @@ pub const DeclGen = struct { |
| 4184 | 4184 | decl_index: Module.Decl.Index, |
| 4185 | 4185 | ) Error!*llvm.Value { |
| 4186 | 4186 | const mod = self.module; |
| 4187 | if (tv.ty.isSlice()) { | |
| 4187 | if (tv.ty.isSlice(mod)) { | |
| 4188 | 4188 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 4189 | 4189 | const ptr_ty = tv.ty.slicePtrFieldType(&buf); |
| 4190 | 4190 | var slice_len: Value.Payload.U64 = .{ |
| ... | ... | @@ -5794,7 +5794,8 @@ pub const FuncGen = struct { |
| 5794 | 5794 | } |
| 5795 | 5795 | |
| 5796 | 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 | 5799 | return fg.builder.buildExtractValue(ptr, 0, ""); |
| 5799 | 5800 | } else { |
| 5800 | 5801 | return ptr; |
| ... | ... | @@ -6669,7 +6670,7 @@ pub const FuncGen = struct { |
| 6669 | 6670 | self.builder.buildLoad(optional_llvm_ty, operand, "") |
| 6670 | 6671 | else |
| 6671 | 6672 | operand; |
| 6672 | if (payload_ty.isSlice()) { | |
| 6673 | if (payload_ty.isSlice(mod)) { | |
| 6673 | 6674 | const slice_ptr = self.builder.buildExtractValue(loaded, 0, ""); |
| 6674 | 6675 | var slice_buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 6675 | 6676 | const ptr_ty = try self.dg.lowerType(payload_ty.slicePtrFieldType(&slice_buf)); |
| ... | ... | @@ -10864,7 +10865,7 @@ const ParamTypeIterator = struct { |
| 10864 | 10865 | it.zig_index += 1; |
| 10865 | 10866 | it.llvm_index += 1; |
| 10866 | 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 | 10869 | it.llvm_index += 1; |
| 10869 | 10870 | return .slice; |
| 10870 | 10871 | } else if (isByRef(ty, mod)) { |
src/codegen/spirv.zig+2-2| ... | ... | @@ -2980,12 +2980,12 @@ pub const DeclGen = struct { |
| 2980 | 2980 | // Pointer payload represents nullability: pointer or slice. |
| 2981 | 2981 | |
| 2982 | 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 | 2984 | payload_ty.slicePtrFieldType(&ptr_buf) |
| 2985 | 2985 | else |
| 2986 | 2986 | payload_ty; |
| 2987 | 2987 | |
| 2988 | const ptr_id = if (payload_ty.isSlice()) | |
| 2988 | const ptr_id = if (payload_ty.isSlice(mod)) | |
| 2989 | 2989 | try self.extractField(Type.bool, operand_id, 0) |
| 2990 | 2990 | else |
| 2991 | 2991 | operand_id; |
src/link/Dwarf.zig+1-1| ... | ... | @@ -258,7 +258,7 @@ pub const DeclState = struct { |
| 258 | 258 | } |
| 259 | 259 | }, |
| 260 | 260 | .Pointer => { |
| 261 | if (ty.isSlice()) { | |
| 261 | if (ty.isSlice(mod)) { | |
| 262 | 262 | // Slices are structs: struct { .ptr = *, .len = N } |
| 263 | 263 | const ptr_bits = target.ptrBitWidth(); |
| 264 | 264 | const ptr_bytes = @intCast(u8, @divExact(ptr_bits, 8)); |
src/type.zig+221-212| ... | ... | @@ -229,7 +229,7 @@ pub const Type = struct { |
| 229 | 229 | .Frame, |
| 230 | 230 | => false, |
| 231 | 231 | |
| 232 | .Pointer => !ty.isSlice() and (is_equality_cmp or ty.isCPtr()), | |
| 232 | .Pointer => !ty.isSlice(mod) and (is_equality_cmp or ty.isCPtr()), | |
| 233 | 233 | .Optional => { |
| 234 | 234 | if (!is_equality_cmp) return false; |
| 235 | 235 | var buf: Payload.ElemType = undefined; |
| ... | ... | @@ -369,209 +369,212 @@ pub const Type = struct { |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | 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 | }, | |
| 573 | 574 | |
| 574 | else => unreachable, | |
| 575 | else => unreachable, | |
| 576 | }, | |
| 577 | else => @panic("TODO"), | |
| 575 | 578 | } |
| 576 | 579 | } |
| 577 | 580 | |
| ... | ... | @@ -3712,17 +3715,23 @@ pub const Type = struct { |
| 3712 | 3715 | }; |
| 3713 | 3716 | } |
| 3714 | 3717 | |
| 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, | |
| 3722 | 3726 | |
| 3723 | .pointer => self.castTag(.pointer).?.data.size == .Slice, | |
| 3727 | .pointer => ty.castTag(.pointer).?.data.size == .Slice, | |
| 3724 | 3728 | |
| 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 | } |
| 3728 | 3737 |
src/value.zig+4-4| ... | ... | @@ -1144,7 +1144,7 @@ pub const Value = struct { |
| 1144 | 1144 | }, |
| 1145 | 1145 | }, |
| 1146 | 1146 | .Pointer => { |
| 1147 | if (ty.isSlice()) return error.IllDefinedMemoryLayout; | |
| 1147 | if (ty.isSlice(mod)) return error.IllDefinedMemoryLayout; | |
| 1148 | 1148 | if (val.isDeclRef()) return error.ReinterpretDeclRef; |
| 1149 | 1149 | return val.writeToMemory(Type.usize, mod, buffer); |
| 1150 | 1150 | }, |
| ... | ... | @@ -1261,7 +1261,7 @@ pub const Value = struct { |
| 1261 | 1261 | }, |
| 1262 | 1262 | }, |
| 1263 | 1263 | .Pointer => { |
| 1264 | assert(!ty.isSlice()); // No well defined layout. | |
| 1264 | assert(!ty.isSlice(mod)); // No well defined layout. | |
| 1265 | 1265 | if (val.isDeclRef()) return error.ReinterpretDeclRef; |
| 1266 | 1266 | return val.writeToPackedMemory(Type.usize, mod, buffer, bit_offset); |
| 1267 | 1267 | }, |
| ... | ... | @@ -1381,7 +1381,7 @@ pub const Value = struct { |
| 1381 | 1381 | return Value.initPayload(&payload.base); |
| 1382 | 1382 | }, |
| 1383 | 1383 | .Pointer => { |
| 1384 | assert(!ty.isSlice()); // No well defined layout. | |
| 1384 | assert(!ty.isSlice(mod)); // No well defined layout. | |
| 1385 | 1385 | return readFromMemory(Type.usize, mod, buffer, arena); |
| 1386 | 1386 | }, |
| 1387 | 1387 | .Optional => { |
| ... | ... | @@ -1478,7 +1478,7 @@ pub const Value = struct { |
| 1478 | 1478 | }, |
| 1479 | 1479 | }, |
| 1480 | 1480 | .Pointer => { |
| 1481 | assert(!ty.isSlice()); // No well defined layout. | |
| 1481 | assert(!ty.isSlice(mod)); // No well defined layout. | |
| 1482 | 1482 | return readFromPackedMemory(Type.usize, mod, buffer, bit_offset, arena); |
| 1483 | 1483 | }, |
| 1484 | 1484 | .Optional => { |