stage2: implement zirCoerceResultPtr

and remove Module.simplePtrType and Module.ptrType in favor of `Type.ptr`.
This commit is contained in:
Andrew Kelley
2021-09-25 22:18:43 -07:00
parent 04366576ea
commit 1f2f9f05c2
5 changed files with 239 additions and 271 deletions

View File

@@ -4460,82 +4460,6 @@ pub fn failWithOwnedErrorMsg(mod: *Module, scope: *Scope, err_msg: *ErrorMsg) Co
return error.AnalysisFail;
}
pub fn simplePtrType(
arena: *Allocator,
elem_ty: Type,
mutable: bool,
size: std.builtin.TypeInfo.Pointer.Size,
@"addrspace": std.builtin.AddressSpace,
) Allocator.Error!Type {
return ptrType(
arena,
elem_ty,
null,
0,
@"addrspace",
0,
0,
mutable,
false,
false,
size,
);
}
pub fn ptrType(
arena: *Allocator,
elem_ty: Type,
sentinel: ?Value,
@"align": u32,
@"addrspace": std.builtin.AddressSpace,
bit_offset: u16,
host_size: u16,
mutable: bool,
@"allowzero": bool,
@"volatile": bool,
size: std.builtin.TypeInfo.Pointer.Size,
) Allocator.Error!Type {
assert(host_size == 0 or bit_offset < host_size * 8);
if (sentinel != null or @"align" != 0 or @"addrspace" != .generic or
bit_offset != 0 or host_size != 0 or @"allowzero" or @"volatile")
{
return Type.Tag.pointer.create(arena, .{
.pointee_type = elem_ty,
.sentinel = sentinel,
.@"align" = @"align",
.@"addrspace" = @"addrspace",
.bit_offset = bit_offset,
.host_size = host_size,
.@"allowzero" = @"allowzero",
.mutable = mutable,
.@"volatile" = @"volatile",
.size = size,
});
}
if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) {
return Type.initTag(.const_slice_u8);
}
// TODO stage1 type inference bug
const T = Type.Tag;
const type_payload = try arena.create(Type.Payload.ElemType);
type_payload.* = .{
.base = .{
.tag = switch (size) {
.One => if (mutable) T.single_mut_pointer else T.single_const_pointer,
.Many => if (mutable) T.many_mut_pointer else T.many_const_pointer,
.C => if (mutable) T.c_mut_pointer else T.c_const_pointer,
.Slice => if (mutable) T.mut_slice else T.const_slice,
},
},
.data = elem_ty,
};
return Type.initPayload(&type_payload.base);
}
pub fn optionalType(arena: *Allocator, child_type: Type) Allocator.Error!Type {
switch (child_type.tag()) {
.single_const_pointer => return Type.Tag.optional_single_const_pointer.create(