| ... | ... | @@ -4729,7 +4729,9 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey) |
| 4729 | 4729 | .addrspace_is_generic = false, |
| 4730 | 4730 | }); |
| 4731 | 4731 | |
| 4732 | | assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(arg.generic_owner))); |
| 4732 | const generic_owner = unwrapCoercedFunc(ip, arg.generic_owner); |
| 4733 | |
| 4734 | assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(generic_owner))); |
| 4733 | 4735 | |
| 4734 | 4736 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.FuncInstance).Struct.fields.len + |
| 4735 | 4737 | arg.comptime_args.len); |
| ... | ... | @@ -4750,7 +4752,7 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey) |
| 4750 | 4752 | .owner_decl = undefined, |
| 4751 | 4753 | .ty = func_ty, |
| 4752 | 4754 | .branch_quota = 0, |
| 4753 | | .generic_owner = arg.generic_owner, |
| 4755 | .generic_owner = generic_owner, |
| 4754 | 4756 | }); |
| 4755 | 4757 | ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.comptime_args)); |
| 4756 | 4758 | |
| ... | ... | @@ -4775,7 +4777,7 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey) |
| 4775 | 4777 | return finishFuncInstance( |
| 4776 | 4778 | ip, |
| 4777 | 4779 | gpa, |
| 4778 | | arg.generic_owner, |
| 4780 | generic_owner, |
| 4779 | 4781 | func_index, |
| 4780 | 4782 | func_extra_index, |
| 4781 | 4783 | arg.generation, |
| ... | ... | @@ -5673,7 +5675,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al |
| 5673 | 5675 | } }); |
| 5674 | 5676 | }, |
| 5675 | 5677 | .elems => |elems| { |
| 5676 | | const elems_copy = try gpa.dupe(InternPool.Index, elems[0..new_len]); |
| 5678 | const elems_copy = try gpa.dupe(Index, elems[0..new_len]); |
| 5677 | 5679 | defer gpa.free(elems_copy); |
| 5678 | 5680 | return ip.get(gpa, .{ .aggregate = .{ |
| 5679 | 5681 | .ty = new_ty, |
| ... | ... | @@ -5689,7 +5691,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al |
| 5689 | 5691 | } |
| 5690 | 5692 | } |
| 5691 | 5693 | // Direct approach failed - we must recursively coerce elems |
| 5692 | | const agg_elems = try gpa.alloc(InternPool.Index, new_len); |
| 5694 | const agg_elems = try gpa.alloc(Index, new_len); |
| 5693 | 5695 | defer gpa.free(agg_elems); |
| 5694 | 5696 | // First, fill the vector with the uncoerced elements. We do this to avoid key |
| 5695 | 5697 | // lifetime issues, since it'll allow us to avoid referencing `aggregate` after we |
| ... | ... | @@ -6042,7 +6044,10 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 6042 | 6044 | |
| 6043 | 6045 | .type_function => b: { |
| 6044 | 6046 | const info = ip.extraData(Tag.TypeFunction, data); |
| 6045 | | break :b @sizeOf(Tag.TypeFunction) + (@sizeOf(Index) * info.params_len); |
| 6047 | break :b @sizeOf(Tag.TypeFunction) + |
| 6048 | (@sizeOf(Index) * info.params_len) + |
| 6049 | (@as(u32, 4) * @intFromBool(info.flags.has_comptime_bits)) + |
| 6050 | (@as(u32, 4) * @intFromBool(info.flags.has_noalias_bits)); |
| 6046 | 6051 | }, |
| 6047 | 6052 | |
| 6048 | 6053 | .undef => 0, |
| ... | ... | @@ -6996,7 +7001,7 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index { |
| 6996 | 7001 | return ip.extra.items[extra_index]; |
| 6997 | 7002 | } |
| 6998 | 7003 | |
| 6999 | | pub fn iesFuncIndex(ip: *const InternPool, ies_index: InternPool.Index) InternPool.Index { |
| 7004 | pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index { |
| 7000 | 7005 | assert(ies_index != .none); |
| 7001 | 7006 | const tags = ip.items.items(.tag); |
| 7002 | 7007 | assert(tags[@intFromEnum(ies_index)] == .type_inferred_error_set); |
| ... | ... | @@ -7011,7 +7016,7 @@ pub fn iesFuncIndex(ip: *const InternPool, ies_index: InternPool.Index) InternPo |
| 7011 | 7016 | /// Returns a mutable pointer to the resolved error set type of an inferred |
| 7012 | 7017 | /// error set function. The returned pointer is invalidated when anything is |
| 7013 | 7018 | /// added to `ip`. |
| 7014 | | pub fn iesResolved(ip: *const InternPool, ies_index: InternPool.Index) *InternPool.Index { |
| 7019 | pub fn iesResolved(ip: *const InternPool, ies_index: Index) *Index { |
| 7015 | 7020 | assert(ies_index != .none); |
| 7016 | 7021 | const tags = ip.items.items(.tag); |
| 7017 | 7022 | const datas = ip.items.items(.data); |
| ... | ... | @@ -7023,7 +7028,7 @@ pub fn iesResolved(ip: *const InternPool, ies_index: InternPool.Index) *InternPo |
| 7023 | 7028 | /// Returns a mutable pointer to the resolved error set type of an inferred |
| 7024 | 7029 | /// error set function. The returned pointer is invalidated when anything is |
| 7025 | 7030 | /// added to `ip`. |
| 7026 | | pub fn funcIesResolved(ip: *const InternPool, func_index: InternPool.Index) *InternPool.Index { |
| 7031 | pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index { |
| 7027 | 7032 | const tags = ip.items.items(.tag); |
| 7028 | 7033 | const datas = ip.items.items(.data); |
| 7029 | 7034 | assert(funcHasInferredErrorSet(ip, func_index)); |
| ... | ... | @@ -7036,21 +7041,35 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: InternPool.Index) *Int |
| 7036 | 7041 | return @ptrCast(&ip.extra.items[extra_index]); |
| 7037 | 7042 | } |
| 7038 | 7043 | |
| 7039 | | pub fn funcDeclInfo(ip: *const InternPool, i: InternPool.Index) Key.Func { |
| 7044 | pub fn funcDeclInfo(ip: *const InternPool, i: Index) Key.Func { |
| 7040 | 7045 | const tags = ip.items.items(.tag); |
| 7041 | 7046 | const datas = ip.items.items(.data); |
| 7042 | 7047 | assert(tags[@intFromEnum(i)] == .func_decl); |
| 7043 | 7048 | return extraFuncDecl(ip, datas[@intFromEnum(i)]); |
| 7044 | 7049 | } |
| 7045 | 7050 | |
| 7046 | | pub fn funcDeclOwner(ip: *const InternPool, i: InternPool.Index) Module.Decl.Index { |
| 7051 | pub fn funcDeclOwner(ip: *const InternPool, i: Index) Module.Decl.Index { |
| 7047 | 7052 | return funcDeclInfo(ip, i).owner_decl; |
| 7048 | 7053 | } |
| 7049 | 7054 | |
| 7050 | | pub fn funcTypeParamsLen(ip: *const InternPool, i: InternPool.Index) u32 { |
| 7055 | pub fn funcTypeParamsLen(ip: *const InternPool, i: Index) u32 { |
| 7051 | 7056 | const tags = ip.items.items(.tag); |
| 7052 | 7057 | const datas = ip.items.items(.data); |
| 7053 | 7058 | assert(tags[@intFromEnum(i)] == .type_function); |
| 7054 | 7059 | const start = datas[@intFromEnum(i)]; |
| 7055 | 7060 | return ip.extra.items[start + std.meta.fieldIndex(Tag.TypeFunction, "params_len").?]; |
| 7056 | 7061 | } |
| 7062 | |
| 7063 | fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index { |
| 7064 | const tags = ip.items.items(.tag); |
| 7065 | return switch (tags[@intFromEnum(i)]) { |
| 7066 | .func_coerced => { |
| 7067 | const datas = ip.items.items(.data); |
| 7068 | return @enumFromInt(ip.extra.items[ |
| 7069 | datas[@intFromEnum(i)] + std.meta.fieldIndex(Tag.FuncCoerced, "func").? |
| 7070 | ]); |
| 7071 | }, |
| 7072 | .func_instance, .func_decl => i, |
| 7073 | else => unreachable, |
| 7074 | }; |
| 7075 | } |