| ... | @@ -3178,8 +3178,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { | ... | @@ -3178,8 +3178,8 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 3178 | } }; | 3178 | } }; |
| 3179 | }, | 3179 | }, |
| 3180 | .extern_func => .{ .extern_func = ip.extraData(Tag.ExternFunc, data) }, | 3180 | .extern_func => .{ .extern_func = ip.extraData(Tag.ExternFunc, data) }, |
| 3181 | .func_instance => .{ .func = ip.indexToKeyFuncInstance(data) }, | 3181 | .func_instance => .{ .func = ip.extraFuncInstance(data) }, |
| 3182 | .func_decl => .{ .func = ip.extraIndexToFuncDecl(data) }, | 3182 | .func_decl => .{ .func = ip.extraFuncDecl(data) }, |
| 3183 | .only_possible_value => { | 3183 | .only_possible_value => { |
| 3184 | const ty = @as(Index, @enumFromInt(data)); | 3184 | const ty = @as(Index, @enumFromInt(data)); |
| 3185 | const ty_item = ip.items.get(@intFromEnum(ty)); | 3185 | const ty_item = ip.items.get(@intFromEnum(ty)); |
| ... | @@ -3328,16 +3328,48 @@ fn extraFuncType(ip: *const InternPool, extra_index: u32) Key.FuncType { | ... | @@ -3328,16 +3328,48 @@ fn extraFuncType(ip: *const InternPool, extra_index: u32) Key.FuncType { |
| 3328 | }; | 3328 | }; |
| 3329 | } | 3329 | } |
| 3330 | | 3330 | |
| 3331 | fn extraIndexToFuncDecl(ip: *const InternPool, extra_index: u32) Key.Func { | 3331 | fn extraFuncDecl(ip: *const InternPool, extra_index: u32) Key.Func { |
| 3332 | _ = ip; | 3332 | const P = Tag.FuncDecl; |
| 3333 | _ = extra_index; | 3333 | const func_decl = ip.extraDataTrail(P, extra_index); |
| 3334 | @panic("TODO"); | 3334 | return .{ |
| | 3335 | .ty = func_decl.data.ty, |
| | 3336 | .analysis_extra_index = extra_index + std.meta.fieldIndex(P, "analysis").?, |
| | 3337 | .zir_body_inst_extra_index = extra_index + std.meta.fieldIndex(P, "zir_body_inst").?, |
| | 3338 | .resolved_error_set_extra_index = if (func_decl.data.analysis.inferred_error_set) func_decl.end else 0, |
| | 3339 | .branch_quota_extra_index = 0, |
| | 3340 | .owner_decl = func_decl.data.owner_decl, |
| | 3341 | .zir_body_inst = func_decl.data.zir_body_inst, |
| | 3342 | .lbrace_line = func_decl.data.lbrace_line, |
| | 3343 | .rbrace_line = func_decl.data.rbrace_line, |
| | 3344 | .lbrace_column = func_decl.data.lbrace_column, |
| | 3345 | .rbrace_column = func_decl.data.lbrace_column, |
| | 3346 | .generic_owner = .none, |
| | 3347 | .comptime_args = .{ .start = 0, .len = 0 }, |
| | 3348 | }; |
| 3335 | } | 3349 | } |
| 3336 | | 3350 | |
| 3337 | fn indexToKeyFuncInstance(ip: *const InternPool, data: u32) Key.Func { | 3351 | fn extraFuncInstance(ip: *const InternPool, extra_index: u32) Key.Func { |
| 3338 | _ = ip; | 3352 | const P = Tag.FuncInstance; |
| 3339 | _ = data; | 3353 | const fi = ip.extraDataTrail(P, extra_index); |
| 3340 | @panic("TODO"); | 3354 | const func_decl = ip.funcDeclInfo(fi.data.generic_owner); |
| | 3355 | return .{ |
| | 3356 | .ty = fi.data.ty, |
| | 3357 | .analysis_extra_index = extra_index + std.meta.fieldIndex(P, "analysis").?, |
| | 3358 | .zir_body_inst_extra_index = func_decl.zir_body_inst_extra_index, |
| | 3359 | .resolved_error_set_extra_index = if (fi.data.analysis.inferred_error_set) fi.end else 0, |
| | 3360 | .branch_quota_extra_index = extra_index + std.meta.fieldIndex(P, "branch_quota").?, |
| | 3361 | .owner_decl = fi.data.owner_decl, |
| | 3362 | .zir_body_inst = func_decl.zir_body_inst, |
| | 3363 | .lbrace_line = func_decl.lbrace_line, |
| | 3364 | .rbrace_line = func_decl.rbrace_line, |
| | 3365 | .lbrace_column = func_decl.lbrace_column, |
| | 3366 | .rbrace_column = func_decl.lbrace_column, |
| | 3367 | .generic_owner = fi.data.generic_owner, |
| | 3368 | .comptime_args = .{ |
| | 3369 | .start = fi.end + @intFromBool(fi.data.analysis.inferred_error_set), |
| | 3370 | .len = ip.funcTypeParamsLen(func_decl.ty), |
| | 3371 | }, |
| | 3372 | }; |
| 3341 | } | 3373 | } |
| 3342 | | 3374 | |
| 3343 | fn indexToKeyEnum(ip: *const InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key { | 3375 | fn indexToKeyEnum(ip: *const InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key { |
| ... | @@ -4421,7 +4453,7 @@ pub fn getFuncDecl(ip: *InternPool, gpa: Allocator, key: GetFuncDeclKey) Allocat | ... | @@ -4421,7 +4453,7 @@ pub fn getFuncDecl(ip: *InternPool, gpa: Allocator, key: GetFuncDeclKey) Allocat |
| 4421 | | 4453 | |
| 4422 | const adapter: KeyAdapter = .{ .intern_pool = ip }; | 4454 | const adapter: KeyAdapter = .{ .intern_pool = ip }; |
| 4423 | const gop = ip.map.getOrPutAssumeCapacityAdapted(Key{ | 4455 | const gop = ip.map.getOrPutAssumeCapacityAdapted(Key{ |
| 4424 | .func = extraIndexToFuncDecl(ip, func_decl_extra_index), | 4456 | .func = extraFuncDecl(ip, func_decl_extra_index), |
| 4425 | }, adapter); | 4457 | }, adapter); |
| 4426 | | 4458 | |
| 4427 | if (gop.found_existing) { | 4459 | if (gop.found_existing) { |
| ... | @@ -4544,7 +4576,7 @@ pub fn getFuncDeclIes(ip: *InternPool, gpa: Allocator, key: GetFuncDeclIesKey) A | ... | @@ -4544,7 +4576,7 @@ pub fn getFuncDeclIes(ip: *InternPool, gpa: Allocator, key: GetFuncDeclIesKey) A |
| 4544 | | 4576 | |
| 4545 | const adapter: KeyAdapter = .{ .intern_pool = ip }; | 4577 | const adapter: KeyAdapter = .{ .intern_pool = ip }; |
| 4546 | const gop = ip.map.getOrPutAssumeCapacityAdapted(Key{ | 4578 | const gop = ip.map.getOrPutAssumeCapacityAdapted(Key{ |
| 4547 | .func = extraIndexToFuncDecl(ip, func_decl_extra_index), | 4579 | .func = extraFuncDecl(ip, func_decl_extra_index), |
| 4548 | }, adapter); | 4580 | }, adapter); |
| 4549 | if (!gop.found_existing) { | 4581 | if (!gop.found_existing) { |
| 4550 | assert(!ip.map.getOrPutAssumeCapacityAdapted(Key{ .error_union_type = .{ | 4582 | assert(!ip.map.getOrPutAssumeCapacityAdapted(Key{ .error_union_type = .{ |
| ... | @@ -5052,7 +5084,7 @@ fn addLimbsAssumeCapacity(ip: *InternPool, limbs: []const Limb) void { | ... | @@ -5052,7 +5084,7 @@ fn addLimbsAssumeCapacity(ip: *InternPool, limbs: []const Limb) void { |
| 5052 | } | 5084 | } |
| 5053 | } | 5085 | } |
| 5054 | | 5086 | |
| 5055 | fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct { data: T, end: usize } { | 5087 | fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct { data: T, end: u32 } { |
| 5056 | var result: T = undefined; | 5088 | var result: T = undefined; |
| 5057 | const fields = @typeInfo(T).Struct.fields; | 5089 | const fields = @typeInfo(T).Struct.fields; |
| 5058 | inline for (fields, 0..) |field, i| { | 5090 | inline for (fields, 0..) |field, i| { |
| ... | @@ -5085,7 +5117,7 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct | ... | @@ -5085,7 +5117,7 @@ fn extraDataTrail(ip: *const InternPool, comptime T: type, index: usize) struct |
| 5085 | } | 5117 | } |
| 5086 | return .{ | 5118 | return .{ |
| 5087 | .data = result, | 5119 | .data = result, |
| 5088 | .end = index + fields.len, | 5120 | .end = @intCast(index + fields.len), |
| 5089 | }; | 5121 | }; |
| 5090 | } | 5122 | } |
| 5091 | | 5123 | |
| ... | @@ -6713,3 +6745,18 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: InternPool.Index) *Int | ... | @@ -6713,3 +6745,18 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: InternPool.Index) *Int |
| 6713 | }; | 6745 | }; |
| 6714 | return @ptrCast(&ip.extra.items[extra_index]); | 6746 | return @ptrCast(&ip.extra.items[extra_index]); |
| 6715 | } | 6747 | } |
| | 6748 | |
| | 6749 | pub fn funcDeclInfo(ip: *const InternPool, i: InternPool.Index) Key.Func { |
| | 6750 | const tags = ip.items.items(.tag); |
| | 6751 | const datas = ip.items.items(.data); |
| | 6752 | assert(tags[@intFromEnum(i)] == .func_decl); |
| | 6753 | return extraFuncDecl(ip, datas[@intFromEnum(i)]); |
| | 6754 | } |
| | 6755 | |
| | 6756 | pub fn funcTypeParamsLen(ip: *const InternPool, i: InternPool.Index) u32 { |
| | 6757 | const tags = ip.items.items(.tag); |
| | 6758 | const datas = ip.items.items(.data); |
| | 6759 | assert(tags[@intFromEnum(i)] == .type_function); |
| | 6760 | const start = datas[@intFromEnum(i)]; |
| | 6761 | return ip.extra.items[start + std.meta.fieldIndex(Tag.TypeFunction, "params_len").?]; |
| | 6762 | } |