authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-14 23:04:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 19:02:06-07:00
log9f61c29bfb8f9a93f737a099ed38f9e0a106d6b6
tree8cb0d38128e1e8412d5d34722982aedff784839a
parent1b70fca534c64a412270897f06938c50f0b7b39c

InternPool: unwrap func_coerced when using it as generic_owner


1 files changed, 31 insertions(+), 12 deletions(-)

src/InternPool.zig+31-12
......@@ -4729,7 +4729,9 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey)
47294729 .addrspace_is_generic = false,
47304730 });
47314731
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)));
47334735
47344736 try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.FuncInstance).Struct.fields.len +
47354737 arg.comptime_args.len);
......@@ -4750,7 +4752,7 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey)
47504752 .owner_decl = undefined,
47514753 .ty = func_ty,
47524754 .branch_quota = 0,
4753 .generic_owner = arg.generic_owner,
4755 .generic_owner = generic_owner,
47544756 });
47554757 ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.comptime_args));
47564758
......@@ -4775,7 +4777,7 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey)
47754777 return finishFuncInstance(
47764778 ip,
47774779 gpa,
4778 arg.generic_owner,
4780 generic_owner,
47794781 func_index,
47804782 func_extra_index,
47814783 arg.generation,
......@@ -5673,7 +5675,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
56735675 } });
56745676 },
56755677 .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]);
56775679 defer gpa.free(elems_copy);
56785680 return ip.get(gpa, .{ .aggregate = .{
56795681 .ty = new_ty,
......@@ -5689,7 +5691,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al
56895691 }
56905692 }
56915693 // 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);
56935695 defer gpa.free(agg_elems);
56945696 // First, fill the vector with the uncoerced elements. We do this to avoid key
56955697 // 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 {
60426044
60436045 .type_function => b: {
60446046 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));
60466051 },
60476052
60486053 .undef => 0,
......@@ -6996,7 +7001,7 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index {
69967001 return ip.extra.items[extra_index];
69977002}
69987003
6999pub fn iesFuncIndex(ip: *const InternPool, ies_index: InternPool.Index) InternPool.Index {
7004pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index {
70007005 assert(ies_index != .none);
70017006 const tags = ip.items.items(.tag);
70027007 assert(tags[@intFromEnum(ies_index)] == .type_inferred_error_set);
......@@ -7011,7 +7016,7 @@ pub fn iesFuncIndex(ip: *const InternPool, ies_index: InternPool.Index) InternPo
70117016/// Returns a mutable pointer to the resolved error set type of an inferred
70127017/// error set function. The returned pointer is invalidated when anything is
70137018/// added to `ip`.
7014pub fn iesResolved(ip: *const InternPool, ies_index: InternPool.Index) *InternPool.Index {
7019pub fn iesResolved(ip: *const InternPool, ies_index: Index) *Index {
70157020 assert(ies_index != .none);
70167021 const tags = ip.items.items(.tag);
70177022 const datas = ip.items.items(.data);
......@@ -7023,7 +7028,7 @@ pub fn iesResolved(ip: *const InternPool, ies_index: InternPool.Index) *InternPo
70237028/// Returns a mutable pointer to the resolved error set type of an inferred
70247029/// error set function. The returned pointer is invalidated when anything is
70257030/// added to `ip`.
7026pub fn funcIesResolved(ip: *const InternPool, func_index: InternPool.Index) *InternPool.Index {
7031pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index {
70277032 const tags = ip.items.items(.tag);
70287033 const datas = ip.items.items(.data);
70297034 assert(funcHasInferredErrorSet(ip, func_index));
......@@ -7036,21 +7041,35 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: InternPool.Index) *Int
70367041 return @ptrCast(&ip.extra.items[extra_index]);
70377042}
70387043
7039pub fn funcDeclInfo(ip: *const InternPool, i: InternPool.Index) Key.Func {
7044pub fn funcDeclInfo(ip: *const InternPool, i: Index) Key.Func {
70407045 const tags = ip.items.items(.tag);
70417046 const datas = ip.items.items(.data);
70427047 assert(tags[@intFromEnum(i)] == .func_decl);
70437048 return extraFuncDecl(ip, datas[@intFromEnum(i)]);
70447049}
70457050
7046pub fn funcDeclOwner(ip: *const InternPool, i: InternPool.Index) Module.Decl.Index {
7051pub fn funcDeclOwner(ip: *const InternPool, i: Index) Module.Decl.Index {
70477052 return funcDeclInfo(ip, i).owner_decl;
70487053}
70497054
7050pub fn funcTypeParamsLen(ip: *const InternPool, i: InternPool.Index) u32 {
7055pub fn funcTypeParamsLen(ip: *const InternPool, i: Index) u32 {
70517056 const tags = ip.items.items(.tag);
70527057 const datas = ip.items.items(.data);
70537058 assert(tags[@intFromEnum(i)] == .type_function);
70547059 const start = datas[@intFromEnum(i)];
70557060 return ip.extra.items[start + std.meta.fieldIndex(Tag.TypeFunction, "params_len").?];
70567061}
7062
7063fn 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}