Type.isSlice: make it InternPool aware
This commit is contained in:
@@ -556,7 +556,7 @@ pub const DeclGen = struct {
|
||||
if (decl.val.castTag(.variable)) |var_payload|
|
||||
try dg.renderFwdDecl(decl_index, var_payload.data);
|
||||
|
||||
if (ty.isSlice()) {
|
||||
if (ty.isSlice(mod)) {
|
||||
if (location == .StaticInitializer) {
|
||||
try writer.writeByte('{');
|
||||
} else {
|
||||
@@ -603,7 +603,7 @@ pub const DeclGen = struct {
|
||||
fn renderParentPtr(dg: *DeclGen, writer: anytype, ptr_val: Value, ptr_ty: Type, location: ValueRenderLocation) error{ OutOfMemory, AnalysisFail }!void {
|
||||
const mod = dg.module;
|
||||
|
||||
if (!ptr_ty.isSlice()) {
|
||||
if (!ptr_ty.isSlice(mod)) {
|
||||
try writer.writeByte('(');
|
||||
try dg.renderType(writer, ptr_ty);
|
||||
try writer.writeByte(')');
|
||||
@@ -776,7 +776,7 @@ pub const DeclGen = struct {
|
||||
try dg.renderValue(writer, repr_ty, Value.undef, .FunctionArgument);
|
||||
return writer.writeByte(')');
|
||||
},
|
||||
.Pointer => if (ty.isSlice()) {
|
||||
.Pointer => if (ty.isSlice(mod)) {
|
||||
if (!location.isInitializer()) {
|
||||
try writer.writeByte('(');
|
||||
try dg.renderType(writer, ty);
|
||||
@@ -1045,7 +1045,7 @@ pub const DeclGen = struct {
|
||||
return;
|
||||
},
|
||||
.Pointer => switch (val.tag()) {
|
||||
.null_value, .zero => if (ty.isSlice()) {
|
||||
.null_value, .zero => if (ty.isSlice(mod)) {
|
||||
var slice_pl = Value.Payload.Slice{
|
||||
.base = .{ .tag = .slice },
|
||||
.data = .{ .ptr = val, .len = Value.undef },
|
||||
@@ -5073,7 +5073,7 @@ fn airIsNull(
|
||||
TypedValue{ .ty = optional_ty, .val = Value.null }
|
||||
else if (payload_ty.zigTypeTag(mod) == .ErrorSet)
|
||||
TypedValue{ .ty = payload_ty, .val = Value.zero }
|
||||
else if (payload_ty.isSlice() and optional_ty.optionalReprIsPayload(mod)) rhs: {
|
||||
else if (payload_ty.isSlice(mod) and optional_ty.optionalReprIsPayload(mod)) rhs: {
|
||||
try writer.writeAll(".ptr");
|
||||
const slice_ptr_ty = payload_ty.slicePtrFieldType(&slice_ptr_buf);
|
||||
break :rhs TypedValue{ .ty = slice_ptr_ty, .val = Value.null };
|
||||
@@ -5864,6 +5864,7 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
}
|
||||
|
||||
fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
const mod = f.object.dg.module;
|
||||
const un_op = f.air.instructions.items(.data)[inst].un_op;
|
||||
|
||||
const operand = try f.resolveInst(un_op);
|
||||
@@ -5877,7 +5878,7 @@ fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
try writer.writeAll(" = (");
|
||||
try f.renderType(writer, inst_ty);
|
||||
try writer.writeByte(')');
|
||||
if (operand_ty.isSlice()) {
|
||||
if (operand_ty.isSlice(mod)) {
|
||||
try f.writeCValueMember(writer, operand, .{ .identifier = "len" });
|
||||
} else {
|
||||
try f.writeCValue(writer, operand, .Other);
|
||||
@@ -6272,7 +6273,8 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
|
||||
}
|
||||
|
||||
fn writeSliceOrPtr(f: *Function, writer: anytype, ptr: CValue, ptr_ty: Type) !void {
|
||||
if (ptr_ty.isSlice()) {
|
||||
const mod = f.object.dg.module;
|
||||
if (ptr_ty.isSlice(mod)) {
|
||||
try f.writeCValueMember(writer, ptr, .{ .identifier = "ptr" });
|
||||
} else {
|
||||
try f.writeCValue(writer, ptr, .FunctionArgument);
|
||||
|
||||
@@ -1636,7 +1636,7 @@ pub const Object = struct {
|
||||
return ptr_di_ty;
|
||||
}
|
||||
|
||||
if (ty.isSlice()) {
|
||||
if (ty.isSlice(mod)) {
|
||||
var buf: Type.SlicePtrFieldTypeBuffer = undefined;
|
||||
const ptr_ty = ty.slicePtrFieldType(&buf);
|
||||
const len_ty = Type.usize;
|
||||
@@ -2833,7 +2833,7 @@ pub const DeclGen = struct {
|
||||
},
|
||||
.Bool => return dg.context.intType(1),
|
||||
.Pointer => {
|
||||
if (t.isSlice()) {
|
||||
if (t.isSlice(mod)) {
|
||||
var buf: Type.SlicePtrFieldTypeBuffer = undefined;
|
||||
const ptr_type = t.slicePtrFieldType(&buf);
|
||||
|
||||
@@ -4110,7 +4110,7 @@ pub const DeclGen = struct {
|
||||
}
|
||||
},
|
||||
.Pointer => {
|
||||
assert(parent_ty.isSlice());
|
||||
assert(parent_ty.isSlice(mod));
|
||||
const indices: [2]*llvm.Value = .{
|
||||
llvm_u32.constInt(0, .False),
|
||||
llvm_u32.constInt(field_index, .False),
|
||||
@@ -4184,7 +4184,7 @@ pub const DeclGen = struct {
|
||||
decl_index: Module.Decl.Index,
|
||||
) Error!*llvm.Value {
|
||||
const mod = self.module;
|
||||
if (tv.ty.isSlice()) {
|
||||
if (tv.ty.isSlice(mod)) {
|
||||
var buf: Type.SlicePtrFieldTypeBuffer = undefined;
|
||||
const ptr_ty = tv.ty.slicePtrFieldType(&buf);
|
||||
var slice_len: Value.Payload.U64 = .{
|
||||
@@ -5794,7 +5794,8 @@ pub const FuncGen = struct {
|
||||
}
|
||||
|
||||
fn sliceOrArrayPtr(fg: *FuncGen, ptr: *llvm.Value, ty: Type) *llvm.Value {
|
||||
if (ty.isSlice()) {
|
||||
const mod = fg.dg.module;
|
||||
if (ty.isSlice(mod)) {
|
||||
return fg.builder.buildExtractValue(ptr, 0, "");
|
||||
} else {
|
||||
return ptr;
|
||||
@@ -6669,7 +6670,7 @@ pub const FuncGen = struct {
|
||||
self.builder.buildLoad(optional_llvm_ty, operand, "")
|
||||
else
|
||||
operand;
|
||||
if (payload_ty.isSlice()) {
|
||||
if (payload_ty.isSlice(mod)) {
|
||||
const slice_ptr = self.builder.buildExtractValue(loaded, 0, "");
|
||||
var slice_buf: Type.SlicePtrFieldTypeBuffer = undefined;
|
||||
const ptr_ty = try self.dg.lowerType(payload_ty.slicePtrFieldType(&slice_buf));
|
||||
@@ -10864,7 +10865,7 @@ const ParamTypeIterator = struct {
|
||||
it.zig_index += 1;
|
||||
it.llvm_index += 1;
|
||||
var buf: Type.Payload.ElemType = undefined;
|
||||
if (ty.isSlice() or (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(&buf).isSlice())) {
|
||||
if (ty.isSlice(mod) or (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(&buf).isSlice(mod))) {
|
||||
it.llvm_index += 1;
|
||||
return .slice;
|
||||
} else if (isByRef(ty, mod)) {
|
||||
|
||||
@@ -2980,12 +2980,12 @@ pub const DeclGen = struct {
|
||||
// Pointer payload represents nullability: pointer or slice.
|
||||
|
||||
var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
|
||||
const ptr_ty = if (payload_ty.isSlice())
|
||||
const ptr_ty = if (payload_ty.isSlice(mod))
|
||||
payload_ty.slicePtrFieldType(&ptr_buf)
|
||||
else
|
||||
payload_ty;
|
||||
|
||||
const ptr_id = if (payload_ty.isSlice())
|
||||
const ptr_id = if (payload_ty.isSlice(mod))
|
||||
try self.extractField(Type.bool, operand_id, 0)
|
||||
else
|
||||
operand_id;
|
||||
|
||||
Reference in New Issue
Block a user