peer type resolution improvements

This commit is contained in:
Techatrix 2023-01-19 19:16:19 +01:00
parent 1e3d9579ca
commit ea608a47ea

View File

@ -1195,11 +1195,11 @@ pub fn resolvePeerTypes(ip: *InternPool, gpa: Allocator, types: []const Index, t
var arena = arena_allocator.allocator(); var arena = arena_allocator.allocator();
var chosen = types[0]; var chosen = types[0];
// // If this is non-null then it does the following thing, depending on the chosen zigTypeTag(). // If this is non-null then it does the following thing, depending on the chosen zigTypeTag().
// // * ErrorSet: this is an override // * ErrorSet: this is an override
// // * ErrorUnion: this is an override of the error set only // * ErrorUnion: this is an override of the error set only
// // * other: at the end we make an ErrorUnion with the other thing and this // * other: at the end we make an ErrorUnion with the other thing and this
// var err_set_ty: Index = Index.none; var err_set_ty: Index = Index.none;
var any_are_null = false; var any_are_null = false;
var seen_const = false; var seen_const = false;
var convert_to_slice = false; var convert_to_slice = false;
@ -1610,12 +1610,11 @@ pub fn resolvePeerTypes(ip: *InternPool, gpa: Allocator, types: []const Index, t
const new_ptr_ty = try ip.get(gpa, .{ .pointer_type = info }); const new_ptr_ty = try ip.get(gpa, .{ .pointer_type = info });
const opt_ptr_ty = if (any_are_null) try ip.get(gpa, .{ .optional_type = .{ .payload_type = new_ptr_ty } }) else new_ptr_ty; const opt_ptr_ty = if (any_are_null) try ip.get(gpa, .{ .optional_type = .{ .payload_type = new_ptr_ty } }) else new_ptr_ty;
return opt_ptr_ty; const set_ty = if (err_set_ty != .none) err_set_ty else return opt_ptr_ty;
// const set_ty = if(err_set_ty != .none) err_set_ty else return opt_ptr_ty; return try ip.get(gpa, .{ .error_union_type = .{
// return try ip.get(gpa, .{ .error_union_type = .{ .error_set_type = set_ty,
// .error_set_type = set_ty, .payload_type = opt_ptr_ty,
// .payload_type = opt_ptr_ty, } });
// } });
} }
if (seen_const) { if (seen_const) {
@ -1627,8 +1626,7 @@ pub fn resolvePeerTypes(ip: *InternPool, gpa: Allocator, types: []const Index, t
const new_ptr_ty = try ip.get(gpa, .{ .pointer_type = info }); const new_ptr_ty = try ip.get(gpa, .{ .pointer_type = info });
const opt_ptr_ty = if (any_are_null) try ip.get(gpa, .{ .optional_type = .{ .payload_type = new_ptr_ty } }) else new_ptr_ty; const opt_ptr_ty = if (any_are_null) try ip.get(gpa, .{ .optional_type = .{ .payload_type = new_ptr_ty } }) else new_ptr_ty;
// const set_ty = if(err_set_ty != .none) err_set_ty else error_union_info.error_set_type; const set_ty = if (err_set_ty != .none) err_set_ty else error_union_info.error_set_type;
const set_ty = error_union_info.error_set_type;
return try ip.get(gpa, .{ .error_union_type = .{ return try ip.get(gpa, .{ .error_union_type = .{
.error_set_type = set_ty, .error_set_type = set_ty,
.payload_type = opt_ptr_ty, .payload_type = opt_ptr_ty,
@ -1640,12 +1638,11 @@ pub fn resolvePeerTypes(ip: *InternPool, gpa: Allocator, types: []const Index, t
const new_ptr_ty = try ip.get(gpa, .{ .pointer_type = info }); const new_ptr_ty = try ip.get(gpa, .{ .pointer_type = info });
const opt_ptr_ty = if (any_are_null) try ip.get(gpa, .{ .optional_type = .{ .payload_type = new_ptr_ty } }) else new_ptr_ty; const opt_ptr_ty = if (any_are_null) try ip.get(gpa, .{ .optional_type = .{ .payload_type = new_ptr_ty } }) else new_ptr_ty;
return opt_ptr_ty; const set_ty = if (err_set_ty != .none) err_set_ty else return opt_ptr_ty;
// const set_ty = if(err_set_ty != .none) err_set_ty else return opt_ptr_ty; return try ip.get(gpa, .{ .error_union_type = .{
// return try ip.get(gpa, .{ .error_union_type = .{ .error_set_type = set_ty,
// .error_set_type = set_ty, .payload_type = opt_ptr_ty,
// .payload_type = opt_ptr_ty, } });
// } });
}, },
else => return chosen, else => return chosen,
} }
@ -1660,12 +1657,11 @@ pub fn resolvePeerTypes(ip: *InternPool, gpa: Allocator, types: []const Index, t
.optional_type => chosen, .optional_type => chosen,
else => try ip.get(gpa, .{ .optional_type = .{ .payload_type = chosen } }), else => try ip.get(gpa, .{ .optional_type = .{ .payload_type = chosen } }),
}; };
return opt_ty; const set_ty = if (err_set_ty != .none) err_set_ty else return opt_ty;
// const set_ty = if(err_set_ty != .none) err_set_ty else return opt_ty; return try ip.get(gpa, .{ .error_union_type = .{
// return try ip.get(gpa, .{ .error_union_type = .{ .error_set_type = set_ty,
// .error_set_type = set_ty, .payload_type = opt_ty,
// .payload_type = opt_ty, } });
// } });
} }
return chosen; return chosen;
@ -2155,36 +2151,35 @@ fn coerceInMemoryAllowedFns(
} }; } };
} }
// TODO if (!dest_info.args_is_noalias.eql(src_info.args_is_noalias)) {
return InMemoryCoercionResult{ .fn_param_noalias = .{
.actual = src_info.args_is_noalias.mask,
.wanted = dest_info.args_is_noalias.mask,
} };
}
// if (dest_info.noalias_bits != src_info.noalias_bits) { for (dest_info.args) |dest_param_ty, i| {
// return InMemoryCoercionResult{ .fn_param_noalias = .{ const src_param_ty = src_info.args[i];
// .actual = src_info.noalias_bits,
// .wanted = dest_info.noalias_bits,
// } };
// }
// for (dest_info.param_types) |dest_param_ty, i| { // TODO move outside of loop
// const src_param_ty = src_info.param_types[i]; if (i < 32 and dest_info.args_is_comptime.isSet(i) != src_info.args_is_comptime.isSet(i)) {
return InMemoryCoercionResult{ .fn_param_comptime = .{
.index = i,
.wanted = dest_info.args_is_comptime.isSet(i),
} };
}
// if (dest_info.comptime_params[i] != src_info.comptime_params[i]) { // Note: Cast direction is reversed here.
// return InMemoryCoercionResult{ .fn_param_comptime = .{ const param = try ip.coerceInMemoryAllowed(gpa, arena, src_param_ty, dest_param_ty, true, target);
// .index = i, if (param != .ok) {
// .wanted = dest_info.comptime_params[i], return InMemoryCoercionResult{ .fn_param = .{
// } }; .child = try param.dupe(arena),
// } .actual = src_param_ty,
.wanted = dest_param_ty,
// // Note: Cast direction is reversed here. .index = i,
// const param = try ip.coerceInMemoryAllowed(gpa, src_param_ty, dest_param_ty, true, target); } };
// if (param != .ok) { }
// return InMemoryCoercionResult{ .fn_param = .{ }
// .child = try param.dupe(arena),
// .actual = src_param_ty,
// .wanted = dest_param_ty,
// .index = i,
// } };
// }
// }
return .ok; return .ok;
} }
@ -2266,8 +2261,8 @@ fn coerceInMemoryAllowedPtrs(
const ok_sent = dest_info.sentinel == .none or src_info.size == .C or dest_info.sentinel == src_info.sentinel; // is this enough for a value equality check? const ok_sent = dest_info.sentinel == .none or src_info.size == .C or dest_info.sentinel == src_info.sentinel; // is this enough for a value equality check?
if (!ok_sent) { if (!ok_sent) {
return InMemoryCoercionResult{ .ptr_sentinel = .{ return InMemoryCoercionResult{ .ptr_sentinel = .{
.actual = if (src_info.sentinel != .none) src_info.sentinel else try ip.get(gpa, .{ .simple = .unreachable_value }), .actual = src_info.sentinel,
.wanted = if (dest_info.sentinel != .none) dest_info.sentinel else try ip.get(gpa, .{ .simple = .unreachable_value }), .wanted = dest_info.sentinel,
.ty = dest_info.elem_type, .ty = dest_info.elem_type,
} }; } };
} }