| ... | ... | @@ -8,7 +8,7 @@ tid_width: std.math.Log2Int(u32) = 0, |
| 8 | 8 | tid_shift_31: std.math.Log2Int(u32) = 31, |
| 9 | 9 | tid_shift_32: std.math.Log2Int(u32) = 31, |
| 10 | 10 | |
| 11 | | items: std.MultiArrayList(Item) = .{}, |
| 11 | //items: std.MultiArrayList(Item) = .{}, |
| 12 | 12 | extra: std.ArrayListUnmanaged(u32) = .{}, |
| 13 | 13 | /// On 32-bit systems, this array is ignored and extra is used for everything. |
| 14 | 14 | /// On 64-bit systems, this array is used for big integers and associated metadata. |
| ... | ... | @@ -344,10 +344,12 @@ const Local = struct { |
| 344 | 344 | shared: Shared align(std.atomic.cache_line), |
| 345 | 345 | mutate: struct { |
| 346 | 346 | arena: std.heap.ArenaAllocator.State, |
| 347 | items: Mutate, |
| 347 | 348 | strings: Mutate, |
| 348 | 349 | } align(std.atomic.cache_line), |
| 349 | 350 | |
| 350 | 351 | const Shared = struct { |
| 352 | items: List(Item), |
| 351 | 353 | strings: Strings, |
| 352 | 354 | }; |
| 353 | 355 | |
| ... | ... | @@ -403,6 +405,11 @@ const Local = struct { |
| 403 | 405 | } }); |
| 404 | 406 | } |
| 405 | 407 | |
| 408 | pub fn append(mutable: Mutable, elem: Elem) Allocator.Error!void { |
| 409 | try mutable.ensureUnusedCapacity(1); |
| 410 | mutable.appendAssumeCapacity(elem); |
| 411 | } |
| 412 | |
| 406 | 413 | pub fn appendAssumeCapacity(mutable: Mutable, elem: Elem) void { |
| 407 | 414 | var mutable_view = mutable.view(); |
| 408 | 415 | defer mutable.lenPtr().* = @intCast(mutable_view.len); |
| ... | ... | @@ -417,7 +424,7 @@ const Local = struct { |
| 417 | 424 | const mutable_len = mutable.lenPtr(); |
| 418 | 425 | const start = mutable_len.*; |
| 419 | 426 | const slice_len = @field(slice, @tagName(fields[0])).len; |
| 420 | | assert(slice_len < mutable.capacityPtr().* - start); |
| 427 | assert(slice_len <= mutable.capacityPtr().* - start); |
| 421 | 428 | mutable_len.* = @intCast(start + slice_len); |
| 422 | 429 | const mutable_view = mutable.view(); |
| 423 | 430 | inline for (fields) |field| { |
| ... | ... | @@ -552,6 +559,15 @@ const Local = struct { |
| 552 | 559 | }; |
| 553 | 560 | } |
| 554 | 561 | |
| 562 | pub fn getMutableItems(local: *Local, gpa: std.mem.Allocator) List(Item).Mutable { |
| 563 | return .{ |
| 564 | .gpa = gpa, |
| 565 | .arena = &local.mutate.arena, |
| 566 | .mutate = &local.mutate.items, |
| 567 | .list = &local.shared.items, |
| 568 | }; |
| 569 | } |
| 570 | |
| 555 | 571 | /// In order to store references to strings in fewer bytes, we copy all |
| 556 | 572 | /// string bytes into here. String bytes can be null. It is up to whomever |
| 557 | 573 | /// is referencing the data here whether they want to store both index and length, |
| ... | ... | @@ -566,9 +582,11 @@ const Local = struct { |
| 566 | 582 | }; |
| 567 | 583 | } |
| 568 | 584 | }; |
| 585 | |
| 569 | 586 | pub fn getLocal(ip: *InternPool, tid: Zcu.PerThread.Id) *Local { |
| 570 | 587 | return &ip.locals[@intFromEnum(tid)]; |
| 571 | 588 | } |
| 589 | |
| 572 | 590 | pub fn getLocalShared(ip: *const InternPool, tid: Zcu.PerThread.Id) *const Local.Shared { |
| 573 | 591 | return &ip.locals[@intFromEnum(tid)].shared; |
| 574 | 592 | } |
| ... | ... | @@ -646,6 +664,7 @@ const Shard = struct { |
| 646 | 664 | }; |
| 647 | 665 | } |
| 648 | 666 | }; |
| 667 | |
| 649 | 668 | fn getShard(ip: *InternPool, tid: Zcu.PerThread.Id) *Shard { |
| 650 | 669 | return &ip.shards[@intFromEnum(tid)]; |
| 651 | 670 | } |
| ... | ... | @@ -654,6 +673,7 @@ fn getTidMask(ip: *const InternPool) u32 { |
| 654 | 673 | assert(std.math.isPowerOfTwo(ip.shards.len)); |
| 655 | 674 | return @intCast(ip.shards.len - 1); |
| 656 | 675 | } |
| 676 | |
| 657 | 677 | fn getIndexMask(ip: *const InternPool, comptime BackingInt: type) u32 { |
| 658 | 678 | return @as(u32, std.math.maxInt(BackingInt)) >> ip.tid_width; |
| 659 | 679 | } |
| ... | ... | @@ -791,8 +811,7 @@ pub const String = enum(u32) { |
| 791 | 811 | |
| 792 | 812 | fn toOverlongSlice(string: String, ip: *const InternPool) []const u8 { |
| 793 | 813 | const unwrapped = string.unwrap(ip); |
| 794 | | const strings = ip.getLocalShared(unwrapped.tid).strings.acquire(); |
| 795 | | return strings.view().items(.@"0")[unwrapped.index..]; |
| 814 | return ip.getLocalShared(unwrapped.tid).strings.acquire().view().items(.@"0")[unwrapped.index..]; |
| 796 | 815 | } |
| 797 | 816 | }; |
| 798 | 817 | |
| ... | ... | @@ -2309,7 +2328,7 @@ pub const LoadedUnionType = struct { |
| 2309 | 2328 | }; |
| 2310 | 2329 | |
| 2311 | 2330 | pub fn loadUnionType(ip: *const InternPool, index: Index) LoadedUnionType { |
| 2312 | | const data = ip.items.items(.data)[@intFromEnum(index)]; |
| 2331 | const data = index.getData(ip); |
| 2313 | 2332 | const type_union = ip.extraDataTrail(Tag.TypeUnion, data); |
| 2314 | 2333 | const fields_len = type_union.data.fields_len; |
| 2315 | 2334 | |
| ... | ... | @@ -2731,7 +2750,7 @@ pub const LoadedStructType = struct { |
| 2731 | 2750 | }; |
| 2732 | 2751 | |
| 2733 | 2752 | pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { |
| 2734 | | const item = ip.items.get(@intFromEnum(index)); |
| 2753 | const item = index.getItem(ip); |
| 2735 | 2754 | switch (item.tag) { |
| 2736 | 2755 | .type_struct => { |
| 2737 | 2756 | if (item.data == 0) return .{ |
| ... | ... | @@ -2955,7 +2974,7 @@ const LoadedEnumType = struct { |
| 2955 | 2974 | }; |
| 2956 | 2975 | |
| 2957 | 2976 | pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType { |
| 2958 | | const item = ip.items.get(@intFromEnum(index)); |
| 2977 | const item = index.getItem(ip); |
| 2959 | 2978 | const tag_mode: LoadedEnumType.TagMode = switch (item.tag) { |
| 2960 | 2979 | .type_enum_auto => { |
| 2961 | 2980 | const extra = ip.extraDataTrail(EnumAuto, item.data); |
| ... | ... | @@ -3034,9 +3053,9 @@ pub const LoadedOpaqueType = struct { |
| 3034 | 3053 | }; |
| 3035 | 3054 | |
| 3036 | 3055 | pub fn loadOpaqueType(ip: *const InternPool, index: Index) LoadedOpaqueType { |
| 3037 | | assert(ip.items.items(.tag)[@intFromEnum(index)] == .type_opaque); |
| 3038 | | const extra_index = ip.items.items(.data)[@intFromEnum(index)]; |
| 3039 | | const extra = ip.extraDataTrail(Tag.TypeOpaque, extra_index); |
| 3056 | const item = index.getItem(ip); |
| 3057 | assert(item.tag == .type_opaque); |
| 3058 | const extra = ip.extraDataTrail(Tag.TypeOpaque, item.data); |
| 3040 | 3059 | const captures_len = if (extra.data.captures_len == std.math.maxInt(u32)) |
| 3041 | 3060 | 0 |
| 3042 | 3061 | else |
| ... | ... | @@ -3211,6 +3230,38 @@ pub const Index = enum(u32) { |
| 3211 | 3230 | } |
| 3212 | 3231 | }; |
| 3213 | 3232 | |
| 3233 | pub fn getItem(index: Index, ip: *const InternPool) Item { |
| 3234 | const unwrapped = index.unwrap(ip); |
| 3235 | return ip.getLocalShared(unwrapped.tid).items.acquire().view().get(unwrapped.index); |
| 3236 | } |
| 3237 | |
| 3238 | pub fn getTag(index: Index, ip: *const InternPool) Tag { |
| 3239 | const unwrapped = index.unwrap(ip); |
| 3240 | return ip.getLocalShared(unwrapped.tid).items.acquire().view().items(.tag)[unwrapped.index]; |
| 3241 | } |
| 3242 | |
| 3243 | pub fn getData(index: Index, ip: *const InternPool) u32 { |
| 3244 | const unwrapped = index.unwrap(ip); |
| 3245 | return ip.getLocalShared(unwrapped.tid).items.acquire().view().items(.data)[unwrapped.index]; |
| 3246 | } |
| 3247 | |
| 3248 | const Unwrapped = struct { |
| 3249 | tid: Zcu.PerThread.Id, |
| 3250 | index: u32, |
| 3251 | |
| 3252 | fn wrap(unwrapped: Unwrapped, ip: *const InternPool) Index { |
| 3253 | assert(@intFromEnum(unwrapped.tid) <= ip.getTidMask()); |
| 3254 | assert(unwrapped.index <= ip.getIndexMask(u31)); |
| 3255 | return @enumFromInt(@intFromEnum(unwrapped.tid) << ip.tid_shift_31 | unwrapped.index); |
| 3256 | } |
| 3257 | }; |
| 3258 | fn unwrap(index: Index, ip: *const InternPool) Unwrapped { |
| 3259 | return .{ |
| 3260 | .tid = @enumFromInt(@intFromEnum(index) >> ip.tid_shift_31 & ip.getTidMask()), |
| 3261 | .index = @intFromEnum(index) & ip.getIndexMask(u31), |
| 3262 | }; |
| 3263 | } |
| 3264 | |
| 3214 | 3265 | /// This function is used in the debugger pretty formatters in tools/ to fetch the |
| 3215 | 3266 | /// Tag to encoding mapping to facilitate fancy debug printing for this type. |
| 3216 | 3267 | /// TODO merge this with `Tag.Payload`. |
| ... | ... | @@ -4856,15 +4907,17 @@ pub const MemoizedCall = struct { |
| 4856 | 4907 | |
| 4857 | 4908 | pub fn init(ip: *InternPool, gpa: Allocator, total_threads: usize) !void { |
| 4858 | 4909 | errdefer ip.deinit(gpa); |
| 4859 | | assert(ip.items.len == 0); |
| 4910 | assert(ip.locals.len == 0 and ip.shards.len == 0); |
| 4860 | 4911 | |
| 4861 | 4912 | ip.locals = try gpa.alloc(Local, total_threads); |
| 4862 | 4913 | @memset(ip.locals, .{ |
| 4863 | 4914 | .shared = .{ |
| 4915 | .items = Local.List(Item).empty, |
| 4864 | 4916 | .strings = Local.Strings.empty, |
| 4865 | 4917 | }, |
| 4866 | 4918 | .mutate = .{ |
| 4867 | 4919 | .arena = .{}, |
| 4920 | .items = Local.Mutate.empty, |
| 4868 | 4921 | .strings = Local.Mutate.empty, |
| 4869 | 4922 | }, |
| 4870 | 4923 | }); |
| ... | ... | @@ -4918,7 +4971,6 @@ pub fn init(ip: *InternPool, gpa: Allocator, total_threads: usize) !void { |
| 4918 | 4971 | } |
| 4919 | 4972 | |
| 4920 | 4973 | pub fn deinit(ip: *InternPool, gpa: Allocator) void { |
| 4921 | | ip.items.deinit(gpa); |
| 4922 | 4974 | ip.extra.deinit(gpa); |
| 4923 | 4975 | ip.limbs.deinit(gpa); |
| 4924 | 4976 | |
| ... | ... | @@ -4955,7 +5007,7 @@ pub fn deinit(ip: *InternPool, gpa: Allocator) void { |
| 4955 | 5007 | |
| 4956 | 5008 | pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 4957 | 5009 | assert(index != .none); |
| 4958 | | const item = ip.items.get(@intFromEnum(index)); |
| 5010 | const item = index.getItem(ip); |
| 4959 | 5011 | const data = item.data; |
| 4960 | 5012 | return switch (item.tag) { |
| 4961 | 5013 | .removed => unreachable, |
| ... | ... | @@ -5001,8 +5053,10 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 5001 | 5053 | .type_pointer => .{ .ptr_type = ip.extraData(Tag.TypePointer, data) }, |
| 5002 | 5054 | |
| 5003 | 5055 | .type_slice => { |
| 5004 | | assert(ip.items.items(.tag)[data] == .type_pointer); |
| 5005 | | var ptr_info = ip.extraData(Tag.TypePointer, ip.items.items(.data)[data]); |
| 5056 | const many_ptr_index: Index = @enumFromInt(data); |
| 5057 | const many_ptr_item = many_ptr_index.getItem(ip); |
| 5058 | assert(many_ptr_item.tag == .type_pointer); |
| 5059 | var ptr_info = ip.extraData(Tag.TypePointer, many_ptr_item.data); |
| 5006 | 5060 | ptr_info.flags.size = .Slice; |
| 5007 | 5061 | return .{ .ptr_type = ptr_info }; |
| 5008 | 5062 | }, |
| ... | ... | @@ -5196,7 +5250,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 5196 | 5250 | .ptr_elem => { |
| 5197 | 5251 | // Avoid `indexToKey` recursion by asserting the tag encoding. |
| 5198 | 5252 | const info = ip.extraData(PtrBaseIndex, data); |
| 5199 | | const index_item = ip.items.get(@intFromEnum(info.index)); |
| 5253 | const index_item = info.index.getItem(ip); |
| 5200 | 5254 | return switch (index_item.tag) { |
| 5201 | 5255 | .int_usize => .{ .ptr = .{ .ty = info.ty, .base_addr = .{ .arr_elem = .{ |
| 5202 | 5256 | .base = info.base, |
| ... | ... | @@ -5209,7 +5263,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 5209 | 5263 | .ptr_field => { |
| 5210 | 5264 | // Avoid `indexToKey` recursion by asserting the tag encoding. |
| 5211 | 5265 | const info = ip.extraData(PtrBaseIndex, data); |
| 5212 | | const index_item = ip.items.get(@intFromEnum(info.index)); |
| 5266 | const index_item = info.index.getItem(ip); |
| 5213 | 5267 | return switch (index_item.tag) { |
| 5214 | 5268 | .int_usize => .{ .ptr = .{ .ty = info.ty, .base_addr = .{ .field = .{ |
| 5215 | 5269 | .base = info.base, |
| ... | ... | @@ -5326,7 +5380,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 5326 | 5380 | .func_coerced => .{ .func = ip.extraFuncCoerced(data) }, |
| 5327 | 5381 | .only_possible_value => { |
| 5328 | 5382 | const ty: Index = @enumFromInt(data); |
| 5329 | | const ty_item = ip.items.get(@intFromEnum(ty)); |
| 5383 | const ty_item = ty.getItem(ip); |
| 5330 | 5384 | return switch (ty_item.tag) { |
| 5331 | 5385 | .type_array_big => { |
| 5332 | 5386 | const sentinel = @as( |
| ... | ... | @@ -5557,7 +5611,7 @@ fn extraFuncInstance(ip: *const InternPool, extra_index: u32) Key.Func { |
| 5557 | 5611 | |
| 5558 | 5612 | fn extraFuncCoerced(ip: *const InternPool, extra_index: u32) Key.Func { |
| 5559 | 5613 | const func_coerced = ip.extraData(Tag.FuncCoerced, extra_index); |
| 5560 | | const sub_item = ip.items.get(@intFromEnum(func_coerced.func)); |
| 5614 | const sub_item = func_coerced.func.getItem(ip); |
| 5561 | 5615 | var func: Key.Func = switch (sub_item.tag) { |
| 5562 | 5616 | .func_instance => ip.extraFuncInstance(sub_item.data), |
| 5563 | 5617 | .func_decl => ip.extraFuncDecl(sub_item.data), |
| ... | ... | @@ -5581,21 +5635,30 @@ fn indexToKeyBigInt(ip: *const InternPool, limb_index: u32, positive: bool) Key |
| 5581 | 5635 | const GetOrPutKey = union(enum) { |
| 5582 | 5636 | existing: Index, |
| 5583 | 5637 | new: struct { |
| 5638 | ip: *InternPool, |
| 5639 | tid: Zcu.PerThread.Id, |
| 5584 | 5640 | shard: *Shard, |
| 5585 | 5641 | map_index: u32, |
| 5586 | 5642 | }, |
| 5587 | 5643 | |
| 5588 | | fn set(gop: *GetOrPutKey, index: Index) Index { |
| 5644 | fn put(gop: *GetOrPutKey) Index { |
| 5645 | return gop.putAt(0); |
| 5646 | } |
| 5647 | fn putAt(gop: *GetOrPutKey, offset: u32) Index { |
| 5589 | 5648 | switch (gop.*) { |
| 5590 | 5649 | .existing => unreachable, |
| 5591 | 5650 | .new => |info| { |
| 5651 | const index = Index.Unwrapped.wrap(.{ |
| 5652 | .tid = info.tid, |
| 5653 | .index = info.ip.getLocal(info.tid).mutate.items.len - 1 - offset, |
| 5654 | }, info.ip); |
| 5592 | 5655 | info.shard.shared.map.entries[info.map_index].release(index); |
| 5593 | 5656 | info.shard.mutate.map.len += 1; |
| 5594 | 5657 | info.shard.mutate.map.mutex.unlock(); |
| 5658 | gop.* = .{ .existing = index }; |
| 5659 | return index; |
| 5595 | 5660 | }, |
| 5596 | 5661 | } |
| 5597 | | gop.* = .{ .existing = index }; |
| 5598 | | return index; |
| 5599 | 5662 | } |
| 5600 | 5663 | |
| 5601 | 5664 | fn assign(gop: *GetOrPutKey, new_gop: GetOrPutKey) void { |
| ... | ... | @@ -5692,21 +5755,27 @@ fn getOrPutKey( |
| 5692 | 5755 | shard.shared.map.release(new_map); |
| 5693 | 5756 | } |
| 5694 | 5757 | map.entries[map_index].hash = hash; |
| 5695 | | return .{ .new = .{ .shard = shard, .map_index = map_index } }; |
| 5758 | return .{ .new = .{ |
| 5759 | .ip = ip, |
| 5760 | .tid = tid, |
| 5761 | .shard = shard, |
| 5762 | .map_index = map_index, |
| 5763 | } }; |
| 5696 | 5764 | } |
| 5697 | 5765 | |
| 5698 | 5766 | pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) Allocator.Error!Index { |
| 5699 | 5767 | var gop = try ip.getOrPutKey(gpa, tid, key); |
| 5700 | 5768 | defer gop.deinit(); |
| 5701 | 5769 | if (gop == .existing) return gop.existing; |
| 5702 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 5770 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 5771 | try items.ensureUnusedCapacity(1); |
| 5703 | 5772 | switch (key) { |
| 5704 | 5773 | .int_type => |int_type| { |
| 5705 | 5774 | const t: Tag = switch (int_type.signedness) { |
| 5706 | 5775 | .signed => .type_int_signed, |
| 5707 | 5776 | .unsigned => .type_int_unsigned, |
| 5708 | 5777 | }; |
| 5709 | | ip.items.appendAssumeCapacity(.{ |
| 5778 | items.appendAssumeCapacity(.{ |
| 5710 | 5779 | .tag = t, |
| 5711 | 5780 | .data = int_type.bits, |
| 5712 | 5781 | }); |
| ... | ... | @@ -5721,18 +5790,18 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5721 | 5790 | const ptr_type_index = try ip.get(gpa, tid, new_key); |
| 5722 | 5791 | gop.assign(try ip.getOrPutKey(gpa, tid, key)); |
| 5723 | 5792 | |
| 5724 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 5725 | | ip.items.appendAssumeCapacity(.{ |
| 5793 | try items.ensureUnusedCapacity(1); |
| 5794 | items.appendAssumeCapacity(.{ |
| 5726 | 5795 | .tag = .type_slice, |
| 5727 | 5796 | .data = @intFromEnum(ptr_type_index), |
| 5728 | 5797 | }); |
| 5729 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 5798 | return gop.put(); |
| 5730 | 5799 | } |
| 5731 | 5800 | |
| 5732 | 5801 | var ptr_type_adjusted = ptr_type; |
| 5733 | 5802 | if (ptr_type.flags.size == .C) ptr_type_adjusted.flags.is_allowzero = true; |
| 5734 | 5803 | |
| 5735 | | ip.items.appendAssumeCapacity(.{ |
| 5804 | items.appendAssumeCapacity(.{ |
| 5736 | 5805 | .tag = .type_pointer, |
| 5737 | 5806 | .data = try ip.addExtra(gpa, ptr_type_adjusted), |
| 5738 | 5807 | }); |
| ... | ... | @@ -5743,19 +5812,19 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5743 | 5812 | |
| 5744 | 5813 | if (std.math.cast(u32, array_type.len)) |len| { |
| 5745 | 5814 | if (array_type.sentinel == .none) { |
| 5746 | | ip.items.appendAssumeCapacity(.{ |
| 5815 | items.appendAssumeCapacity(.{ |
| 5747 | 5816 | .tag = .type_array_small, |
| 5748 | 5817 | .data = try ip.addExtra(gpa, Vector{ |
| 5749 | 5818 | .len = len, |
| 5750 | 5819 | .child = array_type.child, |
| 5751 | 5820 | }), |
| 5752 | 5821 | }); |
| 5753 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 5822 | return gop.put(); |
| 5754 | 5823 | } |
| 5755 | 5824 | } |
| 5756 | 5825 | |
| 5757 | 5826 | const length = Array.Length.init(array_type.len); |
| 5758 | | ip.items.appendAssumeCapacity(.{ |
| 5827 | items.appendAssumeCapacity(.{ |
| 5759 | 5828 | .tag = .type_array_big, |
| 5760 | 5829 | .data = try ip.addExtra(gpa, Array{ |
| 5761 | 5830 | .len0 = length.a, |
| ... | ... | @@ -5766,7 +5835,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5766 | 5835 | }); |
| 5767 | 5836 | }, |
| 5768 | 5837 | .vector_type => |vector_type| { |
| 5769 | | ip.items.appendAssumeCapacity(.{ |
| 5838 | items.appendAssumeCapacity(.{ |
| 5770 | 5839 | .tag = .type_vector, |
| 5771 | 5840 | .data = try ip.addExtra(gpa, Vector{ |
| 5772 | 5841 | .len = vector_type.len, |
| ... | ... | @@ -5776,20 +5845,20 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5776 | 5845 | }, |
| 5777 | 5846 | .opt_type => |payload_type| { |
| 5778 | 5847 | assert(payload_type != .none); |
| 5779 | | ip.items.appendAssumeCapacity(.{ |
| 5848 | items.appendAssumeCapacity(.{ |
| 5780 | 5849 | .tag = .type_optional, |
| 5781 | 5850 | .data = @intFromEnum(payload_type), |
| 5782 | 5851 | }); |
| 5783 | 5852 | }, |
| 5784 | 5853 | .anyframe_type => |payload_type| { |
| 5785 | 5854 | // payload_type might be none, indicating the type is `anyframe`. |
| 5786 | | ip.items.appendAssumeCapacity(.{ |
| 5855 | items.appendAssumeCapacity(.{ |
| 5787 | 5856 | .tag = .type_anyframe, |
| 5788 | 5857 | .data = @intFromEnum(payload_type), |
| 5789 | 5858 | }); |
| 5790 | 5859 | }, |
| 5791 | 5860 | .error_union_type => |error_union_type| { |
| 5792 | | ip.items.appendAssumeCapacity(if (error_union_type.error_set_type == .anyerror_type) .{ |
| 5861 | items.appendAssumeCapacity(if (error_union_type.error_set_type == .anyerror_type) .{ |
| 5793 | 5862 | .tag = .type_anyerror_union, |
| 5794 | 5863 | .data = @intFromEnum(error_union_type.payload_type), |
| 5795 | 5864 | } else .{ |
| ... | ... | @@ -5805,7 +5874,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5805 | 5874 | addStringsToMap(ip, names_map, names); |
| 5806 | 5875 | const names_len = error_set_type.names.len; |
| 5807 | 5876 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.ErrorSet).Struct.fields.len + names_len); |
| 5808 | | ip.items.appendAssumeCapacity(.{ |
| 5877 | items.appendAssumeCapacity(.{ |
| 5809 | 5878 | .tag = .type_error_set, |
| 5810 | 5879 | .data = ip.addExtraAssumeCapacity(Tag.ErrorSet{ |
| 5811 | 5880 | .names_len = names_len, |
| ... | ... | @@ -5815,26 +5884,26 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5815 | 5884 | ip.extra.appendSliceAssumeCapacity(@ptrCast(error_set_type.names.get(ip))); |
| 5816 | 5885 | }, |
| 5817 | 5886 | .inferred_error_set_type => |ies_index| { |
| 5818 | | ip.items.appendAssumeCapacity(.{ |
| 5887 | items.appendAssumeCapacity(.{ |
| 5819 | 5888 | .tag = .type_inferred_error_set, |
| 5820 | 5889 | .data = @intFromEnum(ies_index), |
| 5821 | 5890 | }); |
| 5822 | 5891 | }, |
| 5823 | 5892 | .simple_type => |simple_type| { |
| 5824 | | ip.items.appendAssumeCapacity(.{ |
| 5893 | items.appendAssumeCapacity(.{ |
| 5825 | 5894 | .tag = .simple_type, |
| 5826 | 5895 | .data = @intFromEnum(simple_type), |
| 5827 | 5896 | }); |
| 5828 | 5897 | }, |
| 5829 | 5898 | .simple_value => |simple_value| { |
| 5830 | | ip.items.appendAssumeCapacity(.{ |
| 5899 | items.appendAssumeCapacity(.{ |
| 5831 | 5900 | .tag = .simple_value, |
| 5832 | 5901 | .data = @intFromEnum(simple_value), |
| 5833 | 5902 | }); |
| 5834 | 5903 | }, |
| 5835 | 5904 | .undef => |ty| { |
| 5836 | 5905 | assert(ty != .none); |
| 5837 | | ip.items.appendAssumeCapacity(.{ |
| 5906 | items.appendAssumeCapacity(.{ |
| 5838 | 5907 | .tag = .undef, |
| 5839 | 5908 | .data = @intFromEnum(ty), |
| 5840 | 5909 | }); |
| ... | ... | @@ -5853,7 +5922,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5853 | 5922 | .variable => |variable| { |
| 5854 | 5923 | const has_init = variable.init != .none; |
| 5855 | 5924 | if (has_init) assert(variable.ty == ip.typeOf(variable.init)); |
| 5856 | | ip.items.appendAssumeCapacity(.{ |
| 5925 | items.appendAssumeCapacity(.{ |
| 5857 | 5926 | .tag = .variable, |
| 5858 | 5927 | .data = try ip.addExtra(gpa, Tag.Variable{ |
| 5859 | 5928 | .ty = variable.ty, |
| ... | ... | @@ -5873,7 +5942,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5873 | 5942 | .slice => |slice| { |
| 5874 | 5943 | assert(ip.indexToKey(slice.ty).ptr_type.flags.size == .Slice); |
| 5875 | 5944 | assert(ip.indexToKey(ip.typeOf(slice.ptr)).ptr_type.flags.size == .Many); |
| 5876 | | ip.items.appendAssumeCapacity(.{ |
| 5945 | items.appendAssumeCapacity(.{ |
| 5877 | 5946 | .tag = .ptr_slice, |
| 5878 | 5947 | .data = try ip.addExtra(gpa, PtrSlice{ |
| 5879 | 5948 | .ty = slice.ty, |
| ... | ... | @@ -5886,7 +5955,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5886 | 5955 | .ptr => |ptr| { |
| 5887 | 5956 | const ptr_type = ip.indexToKey(ptr.ty).ptr_type; |
| 5888 | 5957 | assert(ptr_type.flags.size != .Slice); |
| 5889 | | ip.items.appendAssumeCapacity(switch (ptr.base_addr) { |
| 5958 | items.appendAssumeCapacity(switch (ptr.base_addr) { |
| 5890 | 5959 | .decl => |decl| .{ |
| 5891 | 5960 | .tag = .ptr_decl, |
| 5892 | 5961 | .data = try ip.addExtra(gpa, PtrDecl.init(ptr.ty, decl, ptr.byte_offset)), |
| ... | ... | @@ -5975,8 +6044,8 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5975 | 6044 | .storage = .{ .u64 = base_index.index }, |
| 5976 | 6045 | } }); |
| 5977 | 6046 | gop.assign(try ip.getOrPutKey(gpa, tid, key)); |
| 5978 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 5979 | | ip.items.appendAssumeCapacity(.{ |
| 6047 | try items.ensureUnusedCapacity(1); |
| 6048 | items.appendAssumeCapacity(.{ |
| 5980 | 6049 | .tag = switch (ptr.base_addr) { |
| 5981 | 6050 | .arr_elem => .ptr_elem, |
| 5982 | 6051 | .field => .ptr_field, |
| ... | ... | @@ -5984,7 +6053,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5984 | 6053 | }, |
| 5985 | 6054 | .data = try ip.addExtra(gpa, PtrBaseIndex.init(ptr.ty, base_index.base, index_index, ptr.byte_offset)), |
| 5986 | 6055 | }); |
| 5987 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6056 | return gop.put(); |
| 5988 | 6057 | }, |
| 5989 | 6058 | }); |
| 5990 | 6059 | }, |
| ... | ... | @@ -5992,7 +6061,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 5992 | 6061 | .opt => |opt| { |
| 5993 | 6062 | assert(ip.isOptionalType(opt.ty)); |
| 5994 | 6063 | assert(opt.val == .none or ip.indexToKey(opt.ty).opt_type == ip.typeOf(opt.val)); |
| 5995 | | ip.items.appendAssumeCapacity(if (opt.val == .none) .{ |
| 6064 | items.appendAssumeCapacity(if (opt.val == .none) .{ |
| 5996 | 6065 | .tag = .opt_null, |
| 5997 | 6066 | .data = @intFromEnum(opt.ty), |
| 5998 | 6067 | } else .{ |
| ... | ... | @@ -6009,7 +6078,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6009 | 6078 | switch (int.storage) { |
| 6010 | 6079 | .u64, .i64, .big_int => {}, |
| 6011 | 6080 | .lazy_align, .lazy_size => |lazy_ty| { |
| 6012 | | ip.items.appendAssumeCapacity(.{ |
| 6081 | items.appendAssumeCapacity(.{ |
| 6013 | 6082 | .tag = switch (int.storage) { |
| 6014 | 6083 | else => unreachable, |
| 6015 | 6084 | .lazy_align => .int_lazy_align, |
| ... | ... | @@ -6020,20 +6089,20 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6020 | 6089 | .lazy_ty = lazy_ty, |
| 6021 | 6090 | }), |
| 6022 | 6091 | }); |
| 6023 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6092 | return gop.put(); |
| 6024 | 6093 | }, |
| 6025 | 6094 | } |
| 6026 | 6095 | switch (int.ty) { |
| 6027 | 6096 | .u8_type => switch (int.storage) { |
| 6028 | 6097 | .big_int => |big_int| { |
| 6029 | | ip.items.appendAssumeCapacity(.{ |
| 6098 | items.appendAssumeCapacity(.{ |
| 6030 | 6099 | .tag = .int_u8, |
| 6031 | 6100 | .data = big_int.to(u8) catch unreachable, |
| 6032 | 6101 | }); |
| 6033 | 6102 | break :b; |
| 6034 | 6103 | }, |
| 6035 | 6104 | inline .u64, .i64 => |x| { |
| 6036 | | ip.items.appendAssumeCapacity(.{ |
| 6105 | items.appendAssumeCapacity(.{ |
| 6037 | 6106 | .tag = .int_u8, |
| 6038 | 6107 | .data = @as(u8, @intCast(x)), |
| 6039 | 6108 | }); |
| ... | ... | @@ -6043,14 +6112,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6043 | 6112 | }, |
| 6044 | 6113 | .u16_type => switch (int.storage) { |
| 6045 | 6114 | .big_int => |big_int| { |
| 6046 | | ip.items.appendAssumeCapacity(.{ |
| 6115 | items.appendAssumeCapacity(.{ |
| 6047 | 6116 | .tag = .int_u16, |
| 6048 | 6117 | .data = big_int.to(u16) catch unreachable, |
| 6049 | 6118 | }); |
| 6050 | 6119 | break :b; |
| 6051 | 6120 | }, |
| 6052 | 6121 | inline .u64, .i64 => |x| { |
| 6053 | | ip.items.appendAssumeCapacity(.{ |
| 6122 | items.appendAssumeCapacity(.{ |
| 6054 | 6123 | .tag = .int_u16, |
| 6055 | 6124 | .data = @as(u16, @intCast(x)), |
| 6056 | 6125 | }); |
| ... | ... | @@ -6060,14 +6129,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6060 | 6129 | }, |
| 6061 | 6130 | .u32_type => switch (int.storage) { |
| 6062 | 6131 | .big_int => |big_int| { |
| 6063 | | ip.items.appendAssumeCapacity(.{ |
| 6132 | items.appendAssumeCapacity(.{ |
| 6064 | 6133 | .tag = .int_u32, |
| 6065 | 6134 | .data = big_int.to(u32) catch unreachable, |
| 6066 | 6135 | }); |
| 6067 | 6136 | break :b; |
| 6068 | 6137 | }, |
| 6069 | 6138 | inline .u64, .i64 => |x| { |
| 6070 | | ip.items.appendAssumeCapacity(.{ |
| 6139 | items.appendAssumeCapacity(.{ |
| 6071 | 6140 | .tag = .int_u32, |
| 6072 | 6141 | .data = @as(u32, @intCast(x)), |
| 6073 | 6142 | }); |
| ... | ... | @@ -6078,14 +6147,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6078 | 6147 | .i32_type => switch (int.storage) { |
| 6079 | 6148 | .big_int => |big_int| { |
| 6080 | 6149 | const casted = big_int.to(i32) catch unreachable; |
| 6081 | | ip.items.appendAssumeCapacity(.{ |
| 6150 | items.appendAssumeCapacity(.{ |
| 6082 | 6151 | .tag = .int_i32, |
| 6083 | 6152 | .data = @as(u32, @bitCast(casted)), |
| 6084 | 6153 | }); |
| 6085 | 6154 | break :b; |
| 6086 | 6155 | }, |
| 6087 | 6156 | inline .u64, .i64 => |x| { |
| 6088 | | ip.items.appendAssumeCapacity(.{ |
| 6157 | items.appendAssumeCapacity(.{ |
| 6089 | 6158 | .tag = .int_i32, |
| 6090 | 6159 | .data = @as(u32, @bitCast(@as(i32, @intCast(x)))), |
| 6091 | 6160 | }); |
| ... | ... | @@ -6096,7 +6165,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6096 | 6165 | .usize_type => switch (int.storage) { |
| 6097 | 6166 | .big_int => |big_int| { |
| 6098 | 6167 | if (big_int.to(u32)) |casted| { |
| 6099 | | ip.items.appendAssumeCapacity(.{ |
| 6168 | items.appendAssumeCapacity(.{ |
| 6100 | 6169 | .tag = .int_usize, |
| 6101 | 6170 | .data = casted, |
| 6102 | 6171 | }); |
| ... | ... | @@ -6105,7 +6174,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6105 | 6174 | }, |
| 6106 | 6175 | inline .u64, .i64 => |x| { |
| 6107 | 6176 | if (std.math.cast(u32, x)) |casted| { |
| 6108 | | ip.items.appendAssumeCapacity(.{ |
| 6177 | items.appendAssumeCapacity(.{ |
| 6109 | 6178 | .tag = .int_usize, |
| 6110 | 6179 | .data = casted, |
| 6111 | 6180 | }); |
| ... | ... | @@ -6117,14 +6186,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6117 | 6186 | .comptime_int_type => switch (int.storage) { |
| 6118 | 6187 | .big_int => |big_int| { |
| 6119 | 6188 | if (big_int.to(u32)) |casted| { |
| 6120 | | ip.items.appendAssumeCapacity(.{ |
| 6189 | items.appendAssumeCapacity(.{ |
| 6121 | 6190 | .tag = .int_comptime_int_u32, |
| 6122 | 6191 | .data = casted, |
| 6123 | 6192 | }); |
| 6124 | 6193 | break :b; |
| 6125 | 6194 | } else |_| {} |
| 6126 | 6195 | if (big_int.to(i32)) |casted| { |
| 6127 | | ip.items.appendAssumeCapacity(.{ |
| 6196 | items.appendAssumeCapacity(.{ |
| 6128 | 6197 | .tag = .int_comptime_int_i32, |
| 6129 | 6198 | .data = @as(u32, @bitCast(casted)), |
| 6130 | 6199 | }); |
| ... | ... | @@ -6133,14 +6202,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6133 | 6202 | }, |
| 6134 | 6203 | inline .u64, .i64 => |x| { |
| 6135 | 6204 | if (std.math.cast(u32, x)) |casted| { |
| 6136 | | ip.items.appendAssumeCapacity(.{ |
| 6205 | items.appendAssumeCapacity(.{ |
| 6137 | 6206 | .tag = .int_comptime_int_u32, |
| 6138 | 6207 | .data = casted, |
| 6139 | 6208 | }); |
| 6140 | 6209 | break :b; |
| 6141 | 6210 | } |
| 6142 | 6211 | if (std.math.cast(i32, x)) |casted| { |
| 6143 | | ip.items.appendAssumeCapacity(.{ |
| 6212 | items.appendAssumeCapacity(.{ |
| 6144 | 6213 | .tag = .int_comptime_int_i32, |
| 6145 | 6214 | .data = @as(u32, @bitCast(casted)), |
| 6146 | 6215 | }); |
| ... | ... | @@ -6154,35 +6223,35 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6154 | 6223 | switch (int.storage) { |
| 6155 | 6224 | .big_int => |big_int| { |
| 6156 | 6225 | if (big_int.to(u32)) |casted| { |
| 6157 | | ip.items.appendAssumeCapacity(.{ |
| 6226 | items.appendAssumeCapacity(.{ |
| 6158 | 6227 | .tag = .int_small, |
| 6159 | 6228 | .data = try ip.addExtra(gpa, IntSmall{ |
| 6160 | 6229 | .ty = int.ty, |
| 6161 | 6230 | .value = casted, |
| 6162 | 6231 | }), |
| 6163 | 6232 | }); |
| 6164 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6233 | return gop.put(); |
| 6165 | 6234 | } else |_| {} |
| 6166 | 6235 | |
| 6167 | 6236 | const tag: Tag = if (big_int.positive) .int_positive else .int_negative; |
| 6168 | | try addInt(ip, gpa, int.ty, tag, big_int.limbs); |
| 6237 | try addInt(ip, gpa, tid, int.ty, tag, big_int.limbs); |
| 6169 | 6238 | }, |
| 6170 | 6239 | inline .u64, .i64 => |x| { |
| 6171 | 6240 | if (std.math.cast(u32, x)) |casted| { |
| 6172 | | ip.items.appendAssumeCapacity(.{ |
| 6241 | items.appendAssumeCapacity(.{ |
| 6173 | 6242 | .tag = .int_small, |
| 6174 | 6243 | .data = try ip.addExtra(gpa, IntSmall{ |
| 6175 | 6244 | .ty = int.ty, |
| 6176 | 6245 | .value = casted, |
| 6177 | 6246 | }), |
| 6178 | 6247 | }); |
| 6179 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6248 | return gop.put(); |
| 6180 | 6249 | } |
| 6181 | 6250 | |
| 6182 | 6251 | var buf: [2]Limb = undefined; |
| 6183 | 6252 | const big_int = BigIntMutable.init(&buf, x).toConst(); |
| 6184 | 6253 | const tag: Tag = if (big_int.positive) .int_positive else .int_negative; |
| 6185 | | try addInt(ip, gpa, int.ty, tag, big_int.limbs); |
| 6254 | try addInt(ip, gpa, tid, int.ty, tag, big_int.limbs); |
| 6186 | 6255 | }, |
| 6187 | 6256 | .lazy_align, .lazy_size => unreachable, |
| 6188 | 6257 | } |
| ... | ... | @@ -6190,7 +6259,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6190 | 6259 | |
| 6191 | 6260 | .err => |err| { |
| 6192 | 6261 | assert(ip.isErrorSetType(err.ty)); |
| 6193 | | ip.items.appendAssumeCapacity(.{ |
| 6262 | items.appendAssumeCapacity(.{ |
| 6194 | 6263 | .tag = .error_set_error, |
| 6195 | 6264 | .data = try ip.addExtra(gpa, err), |
| 6196 | 6265 | }); |
| ... | ... | @@ -6198,7 +6267,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6198 | 6267 | |
| 6199 | 6268 | .error_union => |error_union| { |
| 6200 | 6269 | assert(ip.isErrorUnionType(error_union.ty)); |
| 6201 | | ip.items.appendAssumeCapacity(switch (error_union.val) { |
| 6270 | items.appendAssumeCapacity(switch (error_union.val) { |
| 6202 | 6271 | .err_name => |err_name| .{ |
| 6203 | 6272 | .tag = .error_union_error, |
| 6204 | 6273 | .data = try ip.addExtra(gpa, Key.Error{ |
| ... | ... | @@ -6216,7 +6285,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6216 | 6285 | }); |
| 6217 | 6286 | }, |
| 6218 | 6287 | |
| 6219 | | .enum_literal => |enum_literal| ip.items.appendAssumeCapacity(.{ |
| 6288 | .enum_literal => |enum_literal| items.appendAssumeCapacity(.{ |
| 6220 | 6289 | .tag = .enum_literal, |
| 6221 | 6290 | .data = @intFromEnum(enum_literal), |
| 6222 | 6291 | }), |
| ... | ... | @@ -6228,50 +6297,50 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6228 | 6297 | .enum_type => assert(ip.typeOf(enum_tag.int) == ip.loadEnumType(enum_tag.ty).tag_ty), |
| 6229 | 6298 | else => unreachable, |
| 6230 | 6299 | } |
| 6231 | | ip.items.appendAssumeCapacity(.{ |
| 6300 | items.appendAssumeCapacity(.{ |
| 6232 | 6301 | .tag = .enum_tag, |
| 6233 | 6302 | .data = try ip.addExtra(gpa, enum_tag), |
| 6234 | 6303 | }); |
| 6235 | 6304 | }, |
| 6236 | 6305 | |
| 6237 | | .empty_enum_value => |enum_or_union_ty| ip.items.appendAssumeCapacity(.{ |
| 6306 | .empty_enum_value => |enum_or_union_ty| items.appendAssumeCapacity(.{ |
| 6238 | 6307 | .tag = .only_possible_value, |
| 6239 | 6308 | .data = @intFromEnum(enum_or_union_ty), |
| 6240 | 6309 | }), |
| 6241 | 6310 | |
| 6242 | 6311 | .float => |float| { |
| 6243 | 6312 | switch (float.ty) { |
| 6244 | | .f16_type => ip.items.appendAssumeCapacity(.{ |
| 6313 | .f16_type => items.appendAssumeCapacity(.{ |
| 6245 | 6314 | .tag = .float_f16, |
| 6246 | 6315 | .data = @as(u16, @bitCast(float.storage.f16)), |
| 6247 | 6316 | }), |
| 6248 | | .f32_type => ip.items.appendAssumeCapacity(.{ |
| 6317 | .f32_type => items.appendAssumeCapacity(.{ |
| 6249 | 6318 | .tag = .float_f32, |
| 6250 | 6319 | .data = @as(u32, @bitCast(float.storage.f32)), |
| 6251 | 6320 | }), |
| 6252 | | .f64_type => ip.items.appendAssumeCapacity(.{ |
| 6321 | .f64_type => items.appendAssumeCapacity(.{ |
| 6253 | 6322 | .tag = .float_f64, |
| 6254 | 6323 | .data = try ip.addExtra(gpa, Float64.pack(float.storage.f64)), |
| 6255 | 6324 | }), |
| 6256 | | .f80_type => ip.items.appendAssumeCapacity(.{ |
| 6325 | .f80_type => items.appendAssumeCapacity(.{ |
| 6257 | 6326 | .tag = .float_f80, |
| 6258 | 6327 | .data = try ip.addExtra(gpa, Float80.pack(float.storage.f80)), |
| 6259 | 6328 | }), |
| 6260 | | .f128_type => ip.items.appendAssumeCapacity(.{ |
| 6329 | .f128_type => items.appendAssumeCapacity(.{ |
| 6261 | 6330 | .tag = .float_f128, |
| 6262 | 6331 | .data = try ip.addExtra(gpa, Float128.pack(float.storage.f128)), |
| 6263 | 6332 | }), |
| 6264 | 6333 | .c_longdouble_type => switch (float.storage) { |
| 6265 | | .f80 => |x| ip.items.appendAssumeCapacity(.{ |
| 6334 | .f80 => |x| items.appendAssumeCapacity(.{ |
| 6266 | 6335 | .tag = .float_c_longdouble_f80, |
| 6267 | 6336 | .data = try ip.addExtra(gpa, Float80.pack(x)), |
| 6268 | 6337 | }), |
| 6269 | | inline .f16, .f32, .f64, .f128 => |x| ip.items.appendAssumeCapacity(.{ |
| 6338 | inline .f16, .f32, .f64, .f128 => |x| items.appendAssumeCapacity(.{ |
| 6270 | 6339 | .tag = .float_c_longdouble_f128, |
| 6271 | 6340 | .data = try ip.addExtra(gpa, Float128.pack(x)), |
| 6272 | 6341 | }), |
| 6273 | 6342 | }, |
| 6274 | | .comptime_float_type => ip.items.appendAssumeCapacity(.{ |
| 6343 | .comptime_float_type => items.appendAssumeCapacity(.{ |
| 6275 | 6344 | .tag = .float_comptime_float, |
| 6276 | 6345 | .data = try ip.addExtra(gpa, Float128.pack(float.storage.f128)), |
| 6277 | 6346 | }), |
| ... | ... | @@ -6331,11 +6400,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6331 | 6400 | } |
| 6332 | 6401 | |
| 6333 | 6402 | if (len == 0) { |
| 6334 | | ip.items.appendAssumeCapacity(.{ |
| 6403 | items.appendAssumeCapacity(.{ |
| 6335 | 6404 | .tag = .only_possible_value, |
| 6336 | 6405 | .data = @intFromEnum(aggregate.ty), |
| 6337 | 6406 | }); |
| 6338 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6407 | return gop.put(); |
| 6339 | 6408 | } |
| 6340 | 6409 | |
| 6341 | 6410 | switch (ty_key) { |
| ... | ... | @@ -6364,11 +6433,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6364 | 6433 | // This encoding works thanks to the fact that, as we just verified, |
| 6365 | 6434 | // the type itself contains a slice of values that can be provided |
| 6366 | 6435 | // in the aggregate fields. |
| 6367 | | ip.items.appendAssumeCapacity(.{ |
| 6436 | items.appendAssumeCapacity(.{ |
| 6368 | 6437 | .tag = .only_possible_value, |
| 6369 | 6438 | .data = @intFromEnum(aggregate.ty), |
| 6370 | 6439 | }); |
| 6371 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6440 | return gop.put(); |
| 6372 | 6441 | }, |
| 6373 | 6442 | else => {}, |
| 6374 | 6443 | } |
| ... | ... | @@ -6388,7 +6457,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6388 | 6457 | .storage = .{ .u64 = bytes.at(0, ip) }, |
| 6389 | 6458 | } }); |
| 6390 | 6459 | gop.assign(try ip.getOrPutKey(gpa, tid, key)); |
| 6391 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 6460 | try items.ensureUnusedCapacity(1); |
| 6392 | 6461 | break :elem elem; |
| 6393 | 6462 | }, |
| 6394 | 6463 | .elems => |elems| elems[0], |
| ... | ... | @@ -6399,14 +6468,14 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6399 | 6468 | gpa, |
| 6400 | 6469 | @typeInfo(Repeated).Struct.fields.len, |
| 6401 | 6470 | ); |
| 6402 | | ip.items.appendAssumeCapacity(.{ |
| 6471 | items.appendAssumeCapacity(.{ |
| 6403 | 6472 | .tag = .repeated, |
| 6404 | 6473 | .data = ip.addExtraAssumeCapacity(Repeated{ |
| 6405 | 6474 | .ty = aggregate.ty, |
| 6406 | 6475 | .elem_val = elem, |
| 6407 | 6476 | }), |
| 6408 | 6477 | }); |
| 6409 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6478 | return gop.put(); |
| 6410 | 6479 | } |
| 6411 | 6480 | |
| 6412 | 6481 | if (child == .u8_type) bytes: { |
| ... | ... | @@ -6442,21 +6511,21 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6442 | 6511 | @intCast(len_including_sentinel), |
| 6443 | 6512 | .maybe_embedded_nulls, |
| 6444 | 6513 | ); |
| 6445 | | ip.items.appendAssumeCapacity(.{ |
| 6514 | items.appendAssumeCapacity(.{ |
| 6446 | 6515 | .tag = .bytes, |
| 6447 | 6516 | .data = ip.addExtraAssumeCapacity(Bytes{ |
| 6448 | 6517 | .ty = aggregate.ty, |
| 6449 | 6518 | .bytes = string, |
| 6450 | 6519 | }), |
| 6451 | 6520 | }); |
| 6452 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6521 | return gop.put(); |
| 6453 | 6522 | } |
| 6454 | 6523 | |
| 6455 | 6524 | try ip.extra.ensureUnusedCapacity( |
| 6456 | 6525 | gpa, |
| 6457 | 6526 | @typeInfo(Tag.Aggregate).Struct.fields.len + @as(usize, @intCast(len_including_sentinel + 1)), |
| 6458 | 6527 | ); |
| 6459 | | ip.items.appendAssumeCapacity(.{ |
| 6528 | items.appendAssumeCapacity(.{ |
| 6460 | 6529 | .tag = .aggregate, |
| 6461 | 6530 | .data = ip.addExtraAssumeCapacity(Tag.Aggregate{ |
| 6462 | 6531 | .ty = aggregate.ty, |
| ... | ... | @@ -6469,7 +6538,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6469 | 6538 | .un => |un| { |
| 6470 | 6539 | assert(un.ty != .none); |
| 6471 | 6540 | assert(un.val != .none); |
| 6472 | | ip.items.appendAssumeCapacity(.{ |
| 6541 | items.appendAssumeCapacity(.{ |
| 6473 | 6542 | .tag = .union_value, |
| 6474 | 6543 | .data = try ip.addExtra(gpa, un), |
| 6475 | 6544 | }); |
| ... | ... | @@ -6479,7 +6548,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6479 | 6548 | for (memoized_call.arg_values) |arg| assert(arg != .none); |
| 6480 | 6549 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(MemoizedCall).Struct.fields.len + |
| 6481 | 6550 | memoized_call.arg_values.len); |
| 6482 | | ip.items.appendAssumeCapacity(.{ |
| 6551 | items.appendAssumeCapacity(.{ |
| 6483 | 6552 | .tag = .memoized_call, |
| 6484 | 6553 | .data = ip.addExtraAssumeCapacity(MemoizedCall{ |
| 6485 | 6554 | .func = memoized_call.func, |
| ... | ... | @@ -6490,7 +6559,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All |
| 6490 | 6559 | ip.extra.appendSliceAssumeCapacity(@ptrCast(memoized_call.arg_values)); |
| 6491 | 6560 | }, |
| 6492 | 6561 | } |
| 6493 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6562 | return gop.put(); |
| 6494 | 6563 | } |
| 6495 | 6564 | |
| 6496 | 6565 | pub const UnionTypeInit = struct { |
| ... | ... | @@ -6544,6 +6613,8 @@ pub fn getUnionType( |
| 6544 | 6613 | defer gop.deinit(); |
| 6545 | 6614 | if (gop == .existing) return .{ .existing = gop.existing }; |
| 6546 | 6615 | |
| 6616 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 6617 | |
| 6547 | 6618 | const align_elements_len = if (ini.flags.any_aligned_fields) (ini.fields_len + 3) / 4 else 0; |
| 6548 | 6619 | const align_element: u32 = @bitCast([1]u8{@intFromEnum(Alignment.none)} ** 4); |
| 6549 | 6620 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.TypeUnion).Struct.fields.len + |
| ... | ... | @@ -6556,7 +6627,7 @@ pub fn getUnionType( |
| 6556 | 6627 | // zig fmt: on |
| 6557 | 6628 | ini.fields_len + // field types |
| 6558 | 6629 | align_elements_len); |
| 6559 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 6630 | try items.ensureUnusedCapacity(1); |
| 6560 | 6631 | |
| 6561 | 6632 | const extra_index = ip.addExtraAssumeCapacity(Tag.TypeUnion{ |
| 6562 | 6633 | .flags = .{ |
| ... | ... | @@ -6582,7 +6653,7 @@ pub fn getUnionType( |
| 6582 | 6653 | }, |
| 6583 | 6654 | }); |
| 6584 | 6655 | |
| 6585 | | ip.items.appendAssumeCapacity(.{ |
| 6656 | items.appendAssumeCapacity(.{ |
| 6586 | 6657 | .tag = .type_union, |
| 6587 | 6658 | .data = extra_index, |
| 6588 | 6659 | }); |
| ... | ... | @@ -6618,7 +6689,7 @@ pub fn getUnionType( |
| 6618 | 6689 | } |
| 6619 | 6690 | |
| 6620 | 6691 | return .{ .wip = .{ |
| 6621 | | .index = gop.set(@enumFromInt(ip.items.len - 1)), |
| 6692 | .index = gop.put(), |
| 6622 | 6693 | .decl_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "decl").?, |
| 6623 | 6694 | .namespace_extra_index = if (ini.has_namespace) |
| 6624 | 6695 | extra_index + std.meta.fieldIndex(Tag.TypeUnion, "namespace").? |
| ... | ... | @@ -6640,8 +6711,8 @@ pub const WipNamespaceType = struct { |
| 6640 | 6711 | } |
| 6641 | 6712 | return wip.index; |
| 6642 | 6713 | } |
| 6643 | | pub fn cancel(wip: WipNamespaceType, ip: *InternPool) void { |
| 6644 | | ip.remove(wip.index); |
| 6714 | pub fn cancel(wip: WipNamespaceType, ip: *InternPool, tid: Zcu.PerThread.Id) void { |
| 6715 | ip.remove(tid, wip.index); |
| 6645 | 6716 | } |
| 6646 | 6717 | |
| 6647 | 6718 | pub const Result = union(enum) { |
| ... | ... | @@ -6692,6 +6763,8 @@ pub fn getStructType( |
| 6692 | 6763 | defer gop.deinit(); |
| 6693 | 6764 | if (gop == .existing) return .{ .existing = gop.existing }; |
| 6694 | 6765 | |
| 6766 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 6767 | |
| 6695 | 6768 | const names_map = try ip.addMap(gpa, ini.fields_len); |
| 6696 | 6769 | errdefer _ = ip.maps.pop(); |
| 6697 | 6770 | |
| ... | ... | @@ -6728,7 +6801,7 @@ pub fn getStructType( |
| 6728 | 6801 | .is_reified = ini.key == .reified, |
| 6729 | 6802 | }, |
| 6730 | 6803 | }); |
| 6731 | | try ip.items.append(gpa, .{ |
| 6804 | try items.append(.{ |
| 6732 | 6805 | .tag = if (ini.any_default_inits) .type_struct_packed_inits else .type_struct_packed, |
| 6733 | 6806 | .data = extra_index, |
| 6734 | 6807 | }); |
| ... | ... | @@ -6747,7 +6820,7 @@ pub fn getStructType( |
| 6747 | 6820 | ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), ini.fields_len); |
| 6748 | 6821 | } |
| 6749 | 6822 | return .{ .wip = .{ |
| 6750 | | .index = gop.set(@enumFromInt(ip.items.len - 1)), |
| 6823 | .index = gop.put(), |
| 6751 | 6824 | .decl_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "decl").?, |
| 6752 | 6825 | .namespace_extra_index = if (ini.has_namespace) |
| 6753 | 6826 | extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").? |
| ... | ... | @@ -6800,7 +6873,7 @@ pub fn getStructType( |
| 6800 | 6873 | .is_reified = ini.key == .reified, |
| 6801 | 6874 | }, |
| 6802 | 6875 | }); |
| 6803 | | try ip.items.append(gpa, .{ |
| 6876 | try items.append(.{ |
| 6804 | 6877 | .tag = .type_struct, |
| 6805 | 6878 | .data = extra_index, |
| 6806 | 6879 | }); |
| ... | ... | @@ -6836,7 +6909,7 @@ pub fn getStructType( |
| 6836 | 6909 | } |
| 6837 | 6910 | ip.extra.appendNTimesAssumeCapacity(std.math.maxInt(u32), ini.fields_len); |
| 6838 | 6911 | return .{ .wip = .{ |
| 6839 | | .index = gop.set(@enumFromInt(ip.items.len - 1)), |
| 6912 | .index = gop.put(), |
| 6840 | 6913 | .decl_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "decl").?, |
| 6841 | 6914 | .namespace_extra_index = namespace_extra_index, |
| 6842 | 6915 | } }; |
| ... | ... | @@ -6859,6 +6932,8 @@ pub fn getAnonStructType( |
| 6859 | 6932 | assert(ini.types.len == ini.values.len); |
| 6860 | 6933 | for (ini.types) |elem| assert(elem != .none); |
| 6861 | 6934 | |
| 6935 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 6936 | |
| 6862 | 6937 | const prev_extra_len = ip.extra.items.len; |
| 6863 | 6938 | const fields_len: u32 = @intCast(ini.types.len); |
| 6864 | 6939 | |
| ... | ... | @@ -6866,7 +6941,7 @@ pub fn getAnonStructType( |
| 6866 | 6941 | gpa, |
| 6867 | 6942 | @typeInfo(TypeStructAnon).Struct.fields.len + (fields_len * 3), |
| 6868 | 6943 | ); |
| 6869 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 6944 | try items.ensureUnusedCapacity(1); |
| 6870 | 6945 | |
| 6871 | 6946 | const extra_index = ip.addExtraAssumeCapacity(TypeStructAnon{ |
| 6872 | 6947 | .fields_len = fields_len, |
| ... | ... | @@ -6888,11 +6963,11 @@ pub fn getAnonStructType( |
| 6888 | 6963 | return gop.existing; |
| 6889 | 6964 | } |
| 6890 | 6965 | |
| 6891 | | ip.items.appendAssumeCapacity(.{ |
| 6966 | items.appendAssumeCapacity(.{ |
| 6892 | 6967 | .tag = if (ini.names.len == 0) .type_tuple_anon else .type_struct_anon, |
| 6893 | 6968 | .data = extra_index, |
| 6894 | 6969 | }); |
| 6895 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 6970 | return gop.put(); |
| 6896 | 6971 | } |
| 6897 | 6972 | |
| 6898 | 6973 | /// This is equivalent to `Key.FuncType` but adjusted to have a slice for `param_types`. |
| ... | ... | @@ -6930,7 +7005,9 @@ pub fn getFuncType( |
| 6930 | 7005 | @intFromBool(key.comptime_bits != 0) + |
| 6931 | 7006 | @intFromBool(key.noalias_bits != 0) + |
| 6932 | 7007 | params_len); |
| 6933 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 7008 | |
| 7009 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7010 | try items.ensureUnusedCapacity(1); |
| 6934 | 7011 | |
| 6935 | 7012 | const func_type_extra_index = ip.addExtraAssumeCapacity(Tag.TypeFunction{ |
| 6936 | 7013 | .params_len = params_len, |
| ... | ... | @@ -6962,11 +7039,11 @@ pub fn getFuncType( |
| 6962 | 7039 | return gop.existing; |
| 6963 | 7040 | } |
| 6964 | 7041 | |
| 6965 | | ip.items.appendAssumeCapacity(.{ |
| 7042 | items.appendAssumeCapacity(.{ |
| 6966 | 7043 | .tag = .type_function, |
| 6967 | 7044 | .data = func_type_extra_index, |
| 6968 | 7045 | }); |
| 6969 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 7046 | return gop.put(); |
| 6970 | 7047 | } |
| 6971 | 7048 | |
| 6972 | 7049 | pub fn getExternFunc( |
| ... | ... | @@ -6981,12 +7058,13 @@ pub fn getExternFunc( |
| 6981 | 7058 | const prev_extra_len = ip.extra.items.len; |
| 6982 | 7059 | const extra_index = try ip.addExtra(gpa, @as(Tag.ExternFunc, key)); |
| 6983 | 7060 | errdefer ip.extra.items.len = prev_extra_len; |
| 6984 | | try ip.items.append(gpa, .{ |
| 7061 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7062 | try items.append(.{ |
| 6985 | 7063 | .tag = .extern_func, |
| 6986 | 7064 | .data = extra_index, |
| 6987 | 7065 | }); |
| 6988 | | errdefer ip.items.len -= 1; |
| 6989 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 7066 | errdefer ip.items.lenPtr().* -= 1; |
| 7067 | return gop.put(); |
| 6990 | 7068 | } |
| 6991 | 7069 | |
| 6992 | 7070 | pub const GetFuncDeclKey = struct { |
| ... | ... | @@ -7013,7 +7091,9 @@ pub fn getFuncDecl( |
| 7013 | 7091 | const prev_extra_len = ip.extra.items.len; |
| 7014 | 7092 | |
| 7015 | 7093 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.FuncDecl).Struct.fields.len); |
| 7016 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 7094 | |
| 7095 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7096 | try items.ensureUnusedCapacity(1); |
| 7017 | 7097 | |
| 7018 | 7098 | const func_decl_extra_index = ip.addExtraAssumeCapacity(Tag.FuncDecl{ |
| 7019 | 7099 | .analysis = .{ |
| ... | ... | @@ -7043,11 +7123,11 @@ pub fn getFuncDecl( |
| 7043 | 7123 | return gop.existing; |
| 7044 | 7124 | } |
| 7045 | 7125 | |
| 7046 | | ip.items.appendAssumeCapacity(.{ |
| 7126 | items.appendAssumeCapacity(.{ |
| 7047 | 7127 | .tag = .func_decl, |
| 7048 | 7128 | .data = func_decl_extra_index, |
| 7049 | 7129 | }); |
| 7050 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 7130 | return gop.put(); |
| 7051 | 7131 | } |
| 7052 | 7132 | |
| 7053 | 7133 | pub const GetFuncDeclIesKey = struct { |
| ... | ... | @@ -7095,7 +7175,26 @@ pub fn getFuncDeclIes( |
| 7095 | 7175 | @intFromBool(key.comptime_bits != 0) + |
| 7096 | 7176 | @intFromBool(key.noalias_bits != 0) + |
| 7097 | 7177 | params_len); |
| 7098 | | try ip.items.ensureUnusedCapacity(gpa, 4); |
| 7178 | |
| 7179 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7180 | try items.ensureUnusedCapacity(4); |
| 7181 | |
| 7182 | const func_index = Index.Unwrapped.wrap(.{ |
| 7183 | .tid = tid, |
| 7184 | .index = items.lenPtr().* + 0, |
| 7185 | }, ip); |
| 7186 | const error_union_type = Index.Unwrapped.wrap(.{ |
| 7187 | .tid = tid, |
| 7188 | .index = items.lenPtr().* + 1, |
| 7189 | }, ip); |
| 7190 | const error_set_type = Index.Unwrapped.wrap(.{ |
| 7191 | .tid = tid, |
| 7192 | .index = items.lenPtr().* + 2, |
| 7193 | }, ip); |
| 7194 | const func_ty = Index.Unwrapped.wrap(.{ |
| 7195 | .tid = tid, |
| 7196 | .index = items.lenPtr().* + 3, |
| 7197 | }, ip); |
| 7099 | 7198 | |
| 7100 | 7199 | const func_decl_extra_index = ip.addExtraAssumeCapacity(Tag.FuncDecl{ |
| 7101 | 7200 | .analysis = .{ |
| ... | ... | @@ -7107,36 +7206,18 @@ pub fn getFuncDeclIes( |
| 7107 | 7206 | .inferred_error_set = true, |
| 7108 | 7207 | }, |
| 7109 | 7208 | .owner_decl = key.owner_decl, |
| 7110 | | .ty = @enumFromInt(ip.items.len + 3), |
| 7209 | .ty = func_ty, |
| 7111 | 7210 | .zir_body_inst = key.zir_body_inst, |
| 7112 | 7211 | .lbrace_line = key.lbrace_line, |
| 7113 | 7212 | .rbrace_line = key.rbrace_line, |
| 7114 | 7213 | .lbrace_column = key.lbrace_column, |
| 7115 | 7214 | .rbrace_column = key.rbrace_column, |
| 7116 | 7215 | }); |
| 7117 | | |
| 7118 | | ip.items.appendAssumeCapacity(.{ |
| 7119 | | .tag = .func_decl, |
| 7120 | | .data = func_decl_extra_index, |
| 7121 | | }); |
| 7122 | 7216 | ip.extra.appendAssumeCapacity(@intFromEnum(Index.none)); |
| 7123 | 7217 | |
| 7124 | | ip.items.appendAssumeCapacity(.{ |
| 7125 | | .tag = .type_error_union, |
| 7126 | | .data = ip.addExtraAssumeCapacity(Tag.ErrorUnionType{ |
| 7127 | | .error_set_type = @enumFromInt(ip.items.len + 1), |
| 7128 | | .payload_type = key.bare_return_type, |
| 7129 | | }), |
| 7130 | | }); |
| 7131 | | |
| 7132 | | ip.items.appendAssumeCapacity(.{ |
| 7133 | | .tag = .type_inferred_error_set, |
| 7134 | | .data = @intCast(ip.items.len - 2), |
| 7135 | | }); |
| 7136 | | |
| 7137 | 7218 | const func_type_extra_index = ip.addExtraAssumeCapacity(Tag.TypeFunction{ |
| 7138 | 7219 | .params_len = params_len, |
| 7139 | | .return_type = @enumFromInt(ip.items.len - 2), |
| 7220 | .return_type = error_union_type, |
| 7140 | 7221 | .flags = .{ |
| 7141 | 7222 | .cc = key.cc orelse .Unspecified, |
| 7142 | 7223 | .is_var_args = key.is_var_args, |
| ... | ... | @@ -7152,45 +7233,57 @@ pub fn getFuncDeclIes( |
| 7152 | 7233 | if (key.comptime_bits != 0) ip.extra.appendAssumeCapacity(key.comptime_bits); |
| 7153 | 7234 | if (key.noalias_bits != 0) ip.extra.appendAssumeCapacity(key.noalias_bits); |
| 7154 | 7235 | ip.extra.appendSliceAssumeCapacity(@ptrCast(key.param_types)); |
| 7236 | |
| 7237 | items.appendSliceAssumeCapacity(.{ |
| 7238 | .tag = &.{ |
| 7239 | .func_decl, |
| 7240 | .type_error_union, |
| 7241 | .type_inferred_error_set, |
| 7242 | .type_function, |
| 7243 | }, |
| 7244 | .data = &.{ |
| 7245 | func_decl_extra_index, |
| 7246 | ip.addExtraAssumeCapacity(Tag.ErrorUnionType{ |
| 7247 | .error_set_type = error_set_type, |
| 7248 | .payload_type = key.bare_return_type, |
| 7249 | }), |
| 7250 | @intFromEnum(func_index), |
| 7251 | func_type_extra_index, |
| 7252 | }, |
| 7253 | }); |
| 7155 | 7254 | errdefer { |
| 7156 | | ip.items.len -= 4; |
| 7255 | items.lenPtr().* -= 4; |
| 7157 | 7256 | ip.extra.items.len = prev_extra_len; |
| 7158 | 7257 | } |
| 7159 | 7258 | |
| 7160 | | ip.items.appendAssumeCapacity(.{ |
| 7161 | | .tag = .type_function, |
| 7162 | | .data = func_type_extra_index, |
| 7163 | | }); |
| 7164 | | |
| 7165 | | var gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7259 | var func_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7166 | 7260 | .func = extraFuncDecl(ip, func_decl_extra_index), |
| 7167 | 7261 | }); |
| 7168 | | defer gop.deinit(); |
| 7169 | | if (gop == .existing) { |
| 7262 | defer func_gop.deinit(); |
| 7263 | if (func_gop == .existing) { |
| 7170 | 7264 | // An existing function type was found; undo the additions to our two arrays. |
| 7171 | | ip.items.len -= 4; |
| 7265 | items.lenPtr().* -= 4; |
| 7172 | 7266 | ip.extra.items.len = prev_extra_len; |
| 7173 | | return gop.existing; |
| 7267 | return func_gop.existing; |
| 7174 | 7268 | } |
| 7175 | | |
| 7176 | | var eu_gop = try ip.getOrPutKey(gpa, tid, .{ .error_union_type = .{ |
| 7177 | | .error_set_type = @enumFromInt(ip.items.len - 2), |
| 7269 | var error_union_type_gop = try ip.getOrPutKey(gpa, tid, .{ .error_union_type = .{ |
| 7270 | .error_set_type = error_set_type, |
| 7178 | 7271 | .payload_type = key.bare_return_type, |
| 7179 | 7272 | } }); |
| 7180 | | defer eu_gop.deinit(); |
| 7181 | | var ies_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7182 | | .inferred_error_set_type = @enumFromInt(ip.items.len - 4), |
| 7273 | defer error_union_type_gop.deinit(); |
| 7274 | var error_set_type_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7275 | .inferred_error_set_type = func_index, |
| 7183 | 7276 | }); |
| 7184 | | defer ies_gop.deinit(); |
| 7185 | | var ty_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7277 | defer error_set_type_gop.deinit(); |
| 7278 | var func_ty_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7186 | 7279 | .func_type = extraFuncType(ip, func_type_extra_index), |
| 7187 | 7280 | }); |
| 7188 | | defer ty_gop.deinit(); |
| 7189 | | const index = gop.set(@enumFromInt(ip.items.len - 4)); |
| 7190 | | _ = eu_gop.set(@enumFromInt(@intFromEnum(index) + 1)); |
| 7191 | | _ = ies_gop.set(@enumFromInt(@intFromEnum(index) + 2)); |
| 7192 | | _ = ty_gop.set(@enumFromInt(@intFromEnum(index) + 3)); |
| 7193 | | return index; |
| 7281 | defer func_ty_gop.deinit(); |
| 7282 | assert(func_gop.putAt(3) == func_index); |
| 7283 | assert(error_union_type_gop.putAt(2) == error_union_type); |
| 7284 | assert(error_set_type_gop.putAt(1) == error_set_type); |
| 7285 | assert(func_ty_gop.putAt(0) == func_ty); |
| 7286 | return func_index; |
| 7194 | 7287 | } |
| 7195 | 7288 | |
| 7196 | 7289 | pub fn getErrorSetType( |
| ... | ... | @@ -7227,11 +7320,12 @@ pub fn getErrorSetType( |
| 7227 | 7320 | return gop.existing; |
| 7228 | 7321 | } |
| 7229 | 7322 | |
| 7230 | | try ip.items.append(gpa, .{ |
| 7323 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7324 | try items.append(.{ |
| 7231 | 7325 | .tag = .type_error_set, |
| 7232 | 7326 | .data = error_set_extra_index, |
| 7233 | 7327 | }); |
| 7234 | | errdefer ip.items.len -= 1; |
| 7328 | errdefer items.lenPtr().* -= 1; |
| 7235 | 7329 | |
| 7236 | 7330 | const names_map = try ip.addMap(gpa, names.len); |
| 7237 | 7331 | assert(names_map == predicted_names_map); |
| ... | ... | @@ -7239,7 +7333,7 @@ pub fn getErrorSetType( |
| 7239 | 7333 | |
| 7240 | 7334 | addStringsToMap(ip, names_map, names); |
| 7241 | 7335 | |
| 7242 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 7336 | return gop.put(); |
| 7243 | 7337 | } |
| 7244 | 7338 | |
| 7245 | 7339 | pub const GetFuncInstanceKey = struct { |
| ... | ... | @@ -7312,15 +7406,14 @@ pub fn getFuncInstance( |
| 7312 | 7406 | return gop.existing; |
| 7313 | 7407 | } |
| 7314 | 7408 | |
| 7315 | | const func_index: Index = @enumFromInt(ip.items.len); |
| 7316 | | |
| 7317 | | try ip.items.append(gpa, .{ |
| 7409 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7410 | const func_index = Index.Unwrapped.wrap(.{ .tid = tid, .index = items.lenPtr().* }, ip); |
| 7411 | try items.append(.{ |
| 7318 | 7412 | .tag = .func_instance, |
| 7319 | 7413 | .data = func_extra_index, |
| 7320 | 7414 | }); |
| 7321 | | errdefer ip.items.len -= 1; |
| 7322 | | |
| 7323 | | return gop.set(try finishFuncInstance( |
| 7415 | errdefer items.lenPtr().* -= 1; |
| 7416 | try finishFuncInstance( |
| 7324 | 7417 | ip, |
| 7325 | 7418 | gpa, |
| 7326 | 7419 | tid, |
| ... | ... | @@ -7329,7 +7422,8 @@ pub fn getFuncInstance( |
| 7329 | 7422 | func_extra_index, |
| 7330 | 7423 | arg.alignment, |
| 7331 | 7424 | arg.section, |
| 7332 | | )); |
| 7425 | ); |
| 7426 | return gop.put(); |
| 7333 | 7427 | } |
| 7334 | 7428 | |
| 7335 | 7429 | /// This function exists separately than `getFuncInstance` because it needs to |
| ... | ... | @@ -7361,12 +7455,26 @@ pub fn getFuncInstanceIes( |
| 7361 | 7455 | @typeInfo(Tag.TypeFunction).Struct.fields.len + |
| 7362 | 7456 | @intFromBool(arg.noalias_bits != 0) + |
| 7363 | 7457 | params_len); |
| 7364 | | try ip.items.ensureUnusedCapacity(gpa, 4); |
| 7365 | 7458 | |
| 7366 | | const func_index: Index = @enumFromInt(ip.items.len); |
| 7367 | | const error_union_type: Index = @enumFromInt(ip.items.len + 1); |
| 7368 | | const error_set_type: Index = @enumFromInt(ip.items.len + 2); |
| 7369 | | const func_ty: Index = @enumFromInt(ip.items.len + 3); |
| 7459 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7460 | try items.ensureUnusedCapacity(4); |
| 7461 | |
| 7462 | const func_index = Index.Unwrapped.wrap(.{ |
| 7463 | .tid = tid, |
| 7464 | .index = items.lenPtr().* + 0, |
| 7465 | }, ip); |
| 7466 | const error_union_type = Index.Unwrapped.wrap(.{ |
| 7467 | .tid = tid, |
| 7468 | .index = items.lenPtr().* + 1, |
| 7469 | }, ip); |
| 7470 | const error_set_type = Index.Unwrapped.wrap(.{ |
| 7471 | .tid = tid, |
| 7472 | .index = items.lenPtr().* + 2, |
| 7473 | }, ip); |
| 7474 | const func_ty = Index.Unwrapped.wrap(.{ |
| 7475 | .tid = tid, |
| 7476 | .index = items.lenPtr().* + 3, |
| 7477 | }, ip); |
| 7370 | 7478 | |
| 7371 | 7479 | const func_extra_index = ip.addExtraAssumeCapacity(Tag.FuncInstance{ |
| 7372 | 7480 | .analysis = .{ |
| ... | ... | @@ -7406,57 +7514,52 @@ pub fn getFuncInstanceIes( |
| 7406 | 7514 | if (arg.noalias_bits != 0) ip.extra.appendAssumeCapacity(arg.noalias_bits); |
| 7407 | 7515 | ip.extra.appendSliceAssumeCapacity(@ptrCast(arg.param_types)); |
| 7408 | 7516 | |
| 7409 | | // TODO: add appendSliceAssumeCapacity to MultiArrayList. |
| 7410 | | ip.items.appendAssumeCapacity(.{ |
| 7411 | | .tag = .func_instance, |
| 7412 | | .data = func_extra_index, |
| 7413 | | }); |
| 7414 | | ip.items.appendAssumeCapacity(.{ |
| 7415 | | .tag = .type_error_union, |
| 7416 | | .data = ip.addExtraAssumeCapacity(Tag.ErrorUnionType{ |
| 7417 | | .error_set_type = error_set_type, |
| 7418 | | .payload_type = arg.bare_return_type, |
| 7419 | | }), |
| 7420 | | }); |
| 7421 | | ip.items.appendAssumeCapacity(.{ |
| 7422 | | .tag = .type_inferred_error_set, |
| 7423 | | .data = @intFromEnum(func_index), |
| 7424 | | }); |
| 7425 | | ip.items.appendAssumeCapacity(.{ |
| 7426 | | .tag = .type_function, |
| 7427 | | .data = func_type_extra_index, |
| 7517 | items.appendSliceAssumeCapacity(.{ |
| 7518 | .tag = &.{ |
| 7519 | .func_instance, |
| 7520 | .type_error_union, |
| 7521 | .type_inferred_error_set, |
| 7522 | .type_function, |
| 7523 | }, |
| 7524 | .data = &.{ |
| 7525 | func_extra_index, |
| 7526 | ip.addExtraAssumeCapacity(Tag.ErrorUnionType{ |
| 7527 | .error_set_type = error_set_type, |
| 7528 | .payload_type = arg.bare_return_type, |
| 7529 | }), |
| 7530 | @intFromEnum(func_index), |
| 7531 | func_type_extra_index, |
| 7532 | }, |
| 7428 | 7533 | }); |
| 7429 | 7534 | errdefer { |
| 7430 | | ip.items.len -= 4; |
| 7535 | items.lenPtr().* -= 4; |
| 7431 | 7536 | ip.extra.items.len = prev_extra_len; |
| 7432 | 7537 | } |
| 7433 | 7538 | |
| 7434 | | var gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7539 | var func_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7435 | 7540 | .func = extraFuncInstance(ip, func_extra_index), |
| 7436 | 7541 | }); |
| 7437 | | defer gop.deinit(); |
| 7438 | | if (gop == .existing) { |
| 7542 | defer func_gop.deinit(); |
| 7543 | if (func_gop == .existing) { |
| 7439 | 7544 | // Hot path: undo the additions to our two arrays. |
| 7440 | | ip.items.len -= 4; |
| 7545 | items.lenPtr().* -= 4; |
| 7441 | 7546 | ip.extra.items.len = prev_extra_len; |
| 7442 | | return gop.existing; |
| 7547 | return func_gop.existing; |
| 7443 | 7548 | } |
| 7444 | | |
| 7445 | | // Synchronize the map with items. |
| 7446 | | var eu_gop = try ip.getOrPutKey(gpa, tid, .{ .error_union_type = .{ |
| 7549 | var error_union_type_gop = try ip.getOrPutKey(gpa, tid, .{ .error_union_type = .{ |
| 7447 | 7550 | .error_set_type = error_set_type, |
| 7448 | 7551 | .payload_type = arg.bare_return_type, |
| 7449 | 7552 | } }); |
| 7450 | | defer eu_gop.deinit(); |
| 7451 | | var ies_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7553 | defer error_union_type_gop.deinit(); |
| 7554 | var error_set_type_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7452 | 7555 | .inferred_error_set_type = func_index, |
| 7453 | 7556 | }); |
| 7454 | | defer ies_gop.deinit(); |
| 7455 | | var ty_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7557 | defer error_set_type_gop.deinit(); |
| 7558 | var func_ty_gop = try ip.getOrPutKey(gpa, tid, .{ |
| 7456 | 7559 | .func_type = extraFuncType(ip, func_type_extra_index), |
| 7457 | 7560 | }); |
| 7458 | | defer ty_gop.deinit(); |
| 7459 | | const index = gop.set(try finishFuncInstance( |
| 7561 | defer func_ty_gop.deinit(); |
| 7562 | try finishFuncInstance( |
| 7460 | 7563 | ip, |
| 7461 | 7564 | gpa, |
| 7462 | 7565 | tid, |
| ... | ... | @@ -7465,11 +7568,12 @@ pub fn getFuncInstanceIes( |
| 7465 | 7568 | func_extra_index, |
| 7466 | 7569 | arg.alignment, |
| 7467 | 7570 | arg.section, |
| 7468 | | )); |
| 7469 | | _ = eu_gop.set(@enumFromInt(@intFromEnum(index) + 1)); |
| 7470 | | _ = ies_gop.set(@enumFromInt(@intFromEnum(index) + 2)); |
| 7471 | | _ = ty_gop.set(@enumFromInt(@intFromEnum(index) + 3)); |
| 7472 | | return index; |
| 7571 | ); |
| 7572 | assert(func_gop.putAt(3) == func_index); |
| 7573 | assert(error_union_type_gop.putAt(2) == error_union_type); |
| 7574 | assert(error_set_type_gop.putAt(1) == error_set_type); |
| 7575 | assert(func_ty_gop.putAt(0) == func_ty); |
| 7576 | return func_index; |
| 7473 | 7577 | } |
| 7474 | 7578 | |
| 7475 | 7579 | fn finishFuncInstance( |
| ... | ... | @@ -7481,7 +7585,7 @@ fn finishFuncInstance( |
| 7481 | 7585 | func_extra_index: u32, |
| 7482 | 7586 | alignment: Alignment, |
| 7483 | 7587 | section: OptionalNullTerminatedString, |
| 7484 | | ) Allocator.Error!Index { |
| 7588 | ) Allocator.Error!void { |
| 7485 | 7589 | const fn_owner_decl = ip.declPtr(ip.funcDeclOwner(generic_owner)); |
| 7486 | 7590 | const decl_index = try ip.createDecl(gpa, .{ |
| 7487 | 7591 | .name = undefined, |
| ... | ... | @@ -7510,8 +7614,6 @@ fn finishFuncInstance( |
| 7510 | 7614 | decl.name = try ip.getOrPutStringFmt(gpa, tid, "{}__anon_{d}", .{ |
| 7511 | 7615 | fn_owner_decl.name.fmt(ip), @intFromEnum(decl_index), |
| 7512 | 7616 | }, .no_embedded_nulls); |
| 7513 | | |
| 7514 | | return func_index; |
| 7515 | 7617 | } |
| 7516 | 7618 | |
| 7517 | 7619 | pub const EnumTypeInit = struct { |
| ... | ... | @@ -7589,8 +7691,8 @@ pub const WipEnumType = struct { |
| 7589 | 7691 | return null; |
| 7590 | 7692 | } |
| 7591 | 7693 | |
| 7592 | | pub fn cancel(wip: WipEnumType, ip: *InternPool) void { |
| 7593 | | ip.remove(wip.index); |
| 7694 | pub fn cancel(wip: WipEnumType, ip: *InternPool, tid: Zcu.PerThread.Id) void { |
| 7695 | ip.remove(tid, wip.index); |
| 7594 | 7696 | } |
| 7595 | 7697 | |
| 7596 | 7698 | pub const Result = union(enum) { |
| ... | ... | @@ -7618,7 +7720,8 @@ pub fn getEnumType( |
| 7618 | 7720 | defer gop.deinit(); |
| 7619 | 7721 | if (gop == .existing) return .{ .existing = gop.existing }; |
| 7620 | 7722 | |
| 7621 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 7723 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7724 | try items.ensureUnusedCapacity(1); |
| 7622 | 7725 | |
| 7623 | 7726 | const names_map = try ip.addMap(gpa, ini.fields_len); |
| 7624 | 7727 | errdefer _ = ip.maps.pop(); |
| ... | ... | @@ -7650,7 +7753,7 @@ pub fn getEnumType( |
| 7650 | 7753 | inline else => |x| x.zir_index, |
| 7651 | 7754 | }.toOptional(), |
| 7652 | 7755 | }); |
| 7653 | | ip.items.appendAssumeCapacity(.{ |
| 7756 | items.appendAssumeCapacity(.{ |
| 7654 | 7757 | .tag = .type_enum_auto, |
| 7655 | 7758 | .data = extra_index, |
| 7656 | 7759 | }); |
| ... | ... | @@ -7661,7 +7764,7 @@ pub fn getEnumType( |
| 7661 | 7764 | const names_start = ip.extra.items.len; |
| 7662 | 7765 | ip.extra.appendNTimesAssumeCapacity(undefined, ini.fields_len); |
| 7663 | 7766 | return .{ .wip = .{ |
| 7664 | | .index = gop.set(@enumFromInt(ip.items.len - 1)), |
| 7767 | .index = gop.put(), |
| 7665 | 7768 | .tag_ty_index = extra_index + std.meta.fieldIndex(EnumAuto, "int_tag_type").?, |
| 7666 | 7769 | .decl_index = extra_index + std.meta.fieldIndex(EnumAuto, "decl").?, |
| 7667 | 7770 | .namespace_index = if (ini.has_namespace) extra_index + std.meta.fieldIndex(EnumAuto, "namespace").? else null, |
| ... | ... | @@ -7706,7 +7809,7 @@ pub fn getEnumType( |
| 7706 | 7809 | inline else => |x| x.zir_index, |
| 7707 | 7810 | }.toOptional(), |
| 7708 | 7811 | }); |
| 7709 | | ip.items.appendAssumeCapacity(.{ |
| 7812 | items.appendAssumeCapacity(.{ |
| 7710 | 7813 | .tag = switch (ini.tag_mode) { |
| 7711 | 7814 | .auto => unreachable, |
| 7712 | 7815 | .explicit => .type_enum_explicit, |
| ... | ... | @@ -7725,7 +7828,7 @@ pub fn getEnumType( |
| 7725 | 7828 | ip.extra.appendNTimesAssumeCapacity(undefined, ini.fields_len); |
| 7726 | 7829 | } |
| 7727 | 7830 | return .{ .wip = .{ |
| 7728 | | .index = gop.set(@enumFromInt(ip.items.len - 1)), |
| 7831 | .index = gop.put(), |
| 7729 | 7832 | .tag_ty_index = extra_index + std.meta.fieldIndex(EnumAuto, "int_tag_type").?, |
| 7730 | 7833 | .decl_index = extra_index + std.meta.fieldIndex(EnumAuto, "decl").?, |
| 7731 | 7834 | .namespace_index = if (ini.has_namespace) extra_index + std.meta.fieldIndex(EnumAuto, "namespace").? else null, |
| ... | ... | @@ -7760,7 +7863,8 @@ pub fn getGeneratedTagEnumType( |
| 7760 | 7863 | assert(ip.isIntegerType(ini.tag_ty)); |
| 7761 | 7864 | for (ini.values) |val| assert(ip.typeOf(val) == ini.tag_ty); |
| 7762 | 7865 | |
| 7763 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 7866 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7867 | try items.ensureUnusedCapacity(1); |
| 7764 | 7868 | |
| 7765 | 7869 | const names_map = try ip.addMap(gpa, ini.names.len); |
| 7766 | 7870 | errdefer _ = ip.maps.pop(); |
| ... | ... | @@ -7774,7 +7878,7 @@ pub fn getGeneratedTagEnumType( |
| 7774 | 7878 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumAuto).Struct.fields.len + |
| 7775 | 7879 | 1 + // owner_union |
| 7776 | 7880 | fields_len); // field names |
| 7777 | | ip.items.appendAssumeCapacity(.{ |
| 7881 | items.appendAssumeCapacity(.{ |
| 7778 | 7882 | .tag = .type_enum_auto, |
| 7779 | 7883 | .data = ip.addExtraAssumeCapacity(EnumAuto{ |
| 7780 | 7884 | .decl = ini.decl, |
| ... | ... | @@ -7803,7 +7907,7 @@ pub fn getGeneratedTagEnumType( |
| 7803 | 7907 | // We don't clean up the values map on error! |
| 7804 | 7908 | errdefer @compileError("error path leaks values_map"); |
| 7805 | 7909 | |
| 7806 | | ip.items.appendAssumeCapacity(.{ |
| 7910 | items.appendAssumeCapacity(.{ |
| 7807 | 7911 | .tag = switch (ini.tag_mode) { |
| 7808 | 7912 | .explicit => .type_enum_explicit, |
| 7809 | 7913 | .nonexhaustive => .type_enum_nonexhaustive, |
| ... | ... | @@ -7835,7 +7939,7 @@ pub fn getGeneratedTagEnumType( |
| 7835 | 7939 | .generated_tag = .{ .union_type = ini.owner_union_ty }, |
| 7836 | 7940 | } }); |
| 7837 | 7941 | defer gop.deinit(); |
| 7838 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 7942 | return gop.put(); |
| 7839 | 7943 | } |
| 7840 | 7944 | |
| 7841 | 7945 | pub const OpaqueTypeInit = struct { |
| ... | ... | @@ -7870,7 +7974,10 @@ pub fn getOpaqueType( |
| 7870 | 7974 | } }); |
| 7871 | 7975 | defer gop.deinit(); |
| 7872 | 7976 | if (gop == .existing) return .{ .existing = gop.existing }; |
| 7873 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 7977 | |
| 7978 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 7979 | try items.ensureUnusedCapacity(1); |
| 7980 | |
| 7874 | 7981 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.TypeOpaque).Struct.fields.len + switch (ini.key) { |
| 7875 | 7982 | .declared => |d| d.captures.len, |
| 7876 | 7983 | .reified => 0, |
| ... | ... | @@ -7886,7 +7993,7 @@ pub fn getOpaqueType( |
| 7886 | 7993 | .reified => std.math.maxInt(u32), |
| 7887 | 7994 | }, |
| 7888 | 7995 | }); |
| 7889 | | ip.items.appendAssumeCapacity(.{ |
| 7996 | items.appendAssumeCapacity(.{ |
| 7890 | 7997 | .tag = .type_opaque, |
| 7891 | 7998 | .data = extra_index, |
| 7892 | 7999 | }); |
| ... | ... | @@ -7895,7 +8002,7 @@ pub fn getOpaqueType( |
| 7895 | 8002 | .reified => {}, |
| 7896 | 8003 | } |
| 7897 | 8004 | return .{ .wip = .{ |
| 7898 | | .index = gop.set(@enumFromInt(ip.items.len - 1)), |
| 8005 | .index = gop.put(), |
| 7899 | 8006 | .decl_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "decl").?, |
| 7900 | 8007 | .namespace_extra_index = if (ini.has_namespace) |
| 7901 | 8008 | extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "namespace").? |
| ... | ... | @@ -7958,37 +8065,50 @@ fn addMap(ip: *InternPool, gpa: Allocator, cap: usize) Allocator.Error!MapIndex |
| 7958 | 8065 | /// This operation only happens under compile error conditions. |
| 7959 | 8066 | /// Leak the index until the next garbage collection. |
| 7960 | 8067 | /// Invalidates all references to this index. |
| 7961 | | pub fn remove(ip: *InternPool, index: Index) void { |
| 8068 | pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void { |
| 8069 | const unwrapped = index.unwrap(ip); |
| 7962 | 8070 | if (@intFromEnum(index) < static_keys.len) { |
| 8071 | if (tid != .main or unwrapped.tid != .main) @panic("This operation is impossible to be thread-safe"); |
| 7963 | 8072 | // The item being removed replaced a special index via `InternPool.resolveBuiltinType`. |
| 7964 | 8073 | // Restore the original item at this index. |
| 8074 | var items = ip.getLocalShared(unwrapped.tid).items.view(); |
| 7965 | 8075 | switch (static_keys[@intFromEnum(index)]) { |
| 7966 | | .simple_type => |s| { |
| 7967 | | ip.items.set(@intFromEnum(index), .{ |
| 7968 | | .tag = .simple_type, |
| 7969 | | .data = @intFromEnum(s), |
| 7970 | | }); |
| 7971 | | }, |
| 8076 | .simple_type => |s| items.set(@intFromEnum(index), .{ |
| 8077 | .tag = .simple_type, |
| 8078 | .data = @intFromEnum(s), |
| 8079 | }), |
| 7972 | 8080 | else => unreachable, |
| 7973 | 8081 | } |
| 7974 | 8082 | return; |
| 7975 | 8083 | } |
| 7976 | 8084 | |
| 7977 | | if (@intFromEnum(index) == ip.items.len - 1) { |
| 7978 | | // Happy case - we can just drop the item without affecting any other indices. |
| 7979 | | ip.items.len -= 1; |
| 7980 | | } else { |
| 7981 | | // We must preserve the item so that indices following it remain valid. |
| 7982 | | // Thus, we will rewrite the tag to `removed`, leaking the item until |
| 7983 | | // next GC but causing `KeyAdapter` to ignore it. |
| 7984 | | ip.items.set(@intFromEnum(index), .{ .tag = .removed, .data = undefined }); |
| 8085 | if (unwrapped.tid == tid) { |
| 8086 | const items_len = &ip.getLocal(tid).mutate.items.len; |
| 8087 | if (unwrapped.index == items_len.* - 1) { |
| 8088 | // Happy case - we can just drop the item without affecting any other indices. |
| 8089 | items_len.* -= 1; |
| 8090 | return; |
| 8091 | } |
| 7985 | 8092 | } |
| 8093 | |
| 8094 | // We must preserve the item so that indices following it remain valid. |
| 8095 | // Thus, we will rewrite the tag to `removed`, leaking the item until |
| 8096 | // next GC but causing `KeyAdapter` to ignore it. |
| 8097 | const items = ip.getLocalShared(unwrapped.tid).items.view(); |
| 8098 | @atomicStore(Tag, &items.items(.tag)[unwrapped.index], .removed, .release); |
| 7986 | 8099 | } |
| 7987 | 8100 | |
| 7988 | | fn addInt(ip: *InternPool, gpa: Allocator, ty: Index, tag: Tag, limbs: []const Limb) !void { |
| 8101 | fn addInt( |
| 8102 | ip: *InternPool, |
| 8103 | gpa: Allocator, |
| 8104 | tid: Zcu.PerThread.Id, |
| 8105 | ty: Index, |
| 8106 | tag: Tag, |
| 8107 | limbs: []const Limb, |
| 8108 | ) !void { |
| 7989 | 8109 | const limbs_len: u32 = @intCast(limbs.len); |
| 7990 | 8110 | try ip.reserveLimbs(gpa, @typeInfo(Int).Struct.fields.len + limbs_len); |
| 7991 | | ip.items.appendAssumeCapacity(.{ |
| 8111 | ip.getLocal(tid).getMutableItems(gpa).appendAssumeCapacity(.{ |
| 7992 | 8112 | .tag = tag, |
| 7993 | 8113 | .data = ip.addLimbsExtraAssumeCapacity(Int{ |
| 7994 | 8114 | .ty = ty, |
| ... | ... | @@ -8235,13 +8355,13 @@ pub fn childType(ip: *const InternPool, i: Index) Index { |
| 8235 | 8355 | } |
| 8236 | 8356 | |
| 8237 | 8357 | /// Given a slice type, returns the type of the ptr field. |
| 8238 | | pub fn slicePtrType(ip: *const InternPool, i: Index) Index { |
| 8239 | | switch (i) { |
| 8358 | pub fn slicePtrType(ip: *const InternPool, index: Index) Index { |
| 8359 | switch (index) { |
| 8240 | 8360 | .slice_const_u8_type => return .manyptr_const_u8_type, |
| 8241 | 8361 | .slice_const_u8_sentinel_0_type => return .manyptr_const_u8_sentinel_0_type, |
| 8242 | 8362 | else => {}, |
| 8243 | 8363 | } |
| 8244 | | const item = ip.items.get(@intFromEnum(i)); |
| 8364 | const item = index.getItem(ip); |
| 8245 | 8365 | switch (item.tag) { |
| 8246 | 8366 | .type_slice => return @enumFromInt(item.data), |
| 8247 | 8367 | else => unreachable, // not a slice type |
| ... | ... | @@ -8249,8 +8369,8 @@ pub fn slicePtrType(ip: *const InternPool, i: Index) Index { |
| 8249 | 8369 | } |
| 8250 | 8370 | |
| 8251 | 8371 | /// Given a slice value, returns the value of the ptr field. |
| 8252 | | pub fn slicePtr(ip: *const InternPool, i: Index) Index { |
| 8253 | | const item = ip.items.get(@intFromEnum(i)); |
| 8372 | pub fn slicePtr(ip: *const InternPool, index: Index) Index { |
| 8373 | const item = index.getItem(ip); |
| 8254 | 8374 | switch (item.tag) { |
| 8255 | 8375 | .ptr_slice => return ip.extraData(PtrSlice, item.data).ptr, |
| 8256 | 8376 | else => unreachable, // not a slice value |
| ... | ... | @@ -8258,8 +8378,8 @@ pub fn slicePtr(ip: *const InternPool, i: Index) Index { |
| 8258 | 8378 | } |
| 8259 | 8379 | |
| 8260 | 8380 | /// Given a slice value, returns the value of the len field. |
| 8261 | | pub fn sliceLen(ip: *const InternPool, i: Index) Index { |
| 8262 | | const item = ip.items.get(@intFromEnum(i)); |
| 8381 | pub fn sliceLen(ip: *const InternPool, index: Index) Index { |
| 8382 | const item = index.getItem(ip); |
| 8263 | 8383 | switch (item.tag) { |
| 8264 | 8384 | .ptr_slice => return ip.extraData(PtrSlice, item.data).len, |
| 8265 | 8385 | else => unreachable, // not a slice value |
| ... | ... | @@ -8296,8 +8416,6 @@ pub fn getCoerced( |
| 8296 | 8416 | const old_ty = ip.typeOf(val); |
| 8297 | 8417 | if (old_ty == new_ty) return val; |
| 8298 | 8418 | |
| 8299 | | const tags = ip.items.items(.tag); |
| 8300 | | |
| 8301 | 8419 | switch (val) { |
| 8302 | 8420 | .undef => return ip.get(gpa, tid, .{ .undef = new_ty }), |
| 8303 | 8421 | .null_value => { |
| ... | ... | @@ -8323,15 +8441,14 @@ pub fn getCoerced( |
| 8323 | 8441 | } }), |
| 8324 | 8442 | }; |
| 8325 | 8443 | }, |
| 8326 | | else => switch (tags[@intFromEnum(val)]) { |
| 8444 | else => switch (val.getTag(ip)) { |
| 8327 | 8445 | .func_decl => return getCoercedFuncDecl(ip, gpa, tid, val, new_ty), |
| 8328 | 8446 | .func_instance => return getCoercedFuncInstance(ip, gpa, tid, val, new_ty), |
| 8329 | 8447 | .func_coerced => { |
| 8330 | | const extra_index = ip.items.items(.data)[@intFromEnum(val)]; |
| 8331 | 8448 | const func: Index = @enumFromInt( |
| 8332 | | ip.extra.items[extra_index + std.meta.fieldIndex(Tag.FuncCoerced, "func").?], |
| 8449 | ip.extra.items[val.getData(ip) + std.meta.fieldIndex(Tag.FuncCoerced, "func").?], |
| 8333 | 8450 | ); |
| 8334 | | switch (tags[@intFromEnum(func)]) { |
| 8451 | switch (func.getTag(ip)) { |
| 8335 | 8452 | .func_decl => return getCoercedFuncDecl(ip, gpa, tid, val, new_ty), |
| 8336 | 8453 | .func_instance => return getCoercedFuncInstance(ip, gpa, tid, val, new_ty), |
| 8337 | 8454 | else => unreachable, |
| ... | ... | @@ -8575,10 +8692,8 @@ fn getCoercedFuncDecl( |
| 8575 | 8692 | val: Index, |
| 8576 | 8693 | new_ty: Index, |
| 8577 | 8694 | ) Allocator.Error!Index { |
| 8578 | | const datas = ip.items.items(.data); |
| 8579 | | const extra_index = datas[@intFromEnum(val)]; |
| 8580 | 8695 | const prev_ty: Index = @enumFromInt( |
| 8581 | | ip.extra.items[extra_index + std.meta.fieldIndex(Tag.FuncDecl, "ty").?], |
| 8696 | ip.extra.items[val.getData(ip) + std.meta.fieldIndex(Tag.FuncDecl, "ty").?], |
| 8582 | 8697 | ); |
| 8583 | 8698 | if (new_ty == prev_ty) return val; |
| 8584 | 8699 | return getCoercedFunc(ip, gpa, tid, val, new_ty); |
| ... | ... | @@ -8591,10 +8706,8 @@ fn getCoercedFuncInstance( |
| 8591 | 8706 | val: Index, |
| 8592 | 8707 | new_ty: Index, |
| 8593 | 8708 | ) Allocator.Error!Index { |
| 8594 | | const datas = ip.items.items(.data); |
| 8595 | | const extra_index = datas[@intFromEnum(val)]; |
| 8596 | 8709 | const prev_ty: Index = @enumFromInt( |
| 8597 | | ip.extra.items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?], |
| 8710 | ip.extra.items[val.getData(ip) + std.meta.fieldIndex(Tag.FuncInstance, "ty").?], |
| 8598 | 8711 | ); |
| 8599 | 8712 | if (new_ty == prev_ty) return val; |
| 8600 | 8713 | return getCoercedFunc(ip, gpa, tid, val, new_ty); |
| ... | ... | @@ -8609,7 +8722,9 @@ fn getCoercedFunc( |
| 8609 | 8722 | ) Allocator.Error!Index { |
| 8610 | 8723 | const prev_extra_len = ip.extra.items.len; |
| 8611 | 8724 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.FuncCoerced).Struct.fields.len); |
| 8612 | | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 8725 | |
| 8726 | const items = ip.getLocal(tid).getMutableItems(gpa); |
| 8727 | try items.ensureUnusedCapacity(1); |
| 8613 | 8728 | |
| 8614 | 8729 | const extra_index = ip.addExtraAssumeCapacity(Tag.FuncCoerced{ |
| 8615 | 8730 | .ty = ty, |
| ... | ... | @@ -8626,11 +8741,11 @@ fn getCoercedFunc( |
| 8626 | 8741 | return gop.existing; |
| 8627 | 8742 | } |
| 8628 | 8743 | |
| 8629 | | ip.items.appendAssumeCapacity(.{ |
| 8744 | items.appendAssumeCapacity(.{ |
| 8630 | 8745 | .tag = .func_coerced, |
| 8631 | 8746 | .data = extra_index, |
| 8632 | 8747 | }); |
| 8633 | | return gop.set(@enumFromInt(ip.items.len - 1)); |
| 8748 | return gop.put(); |
| 8634 | 8749 | } |
| 8635 | 8750 | |
| 8636 | 8751 | /// Asserts `val` has an integer type. |
| ... | ... | @@ -8661,11 +8776,9 @@ pub fn getCoercedInts(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, in |
| 8661 | 8776 | } |
| 8662 | 8777 | |
| 8663 | 8778 | pub fn indexToFuncType(ip: *const InternPool, val: Index) ?Key.FuncType { |
| 8664 | | assert(val != .none); |
| 8665 | | const tags = ip.items.items(.tag); |
| 8666 | | const datas = ip.items.items(.data); |
| 8667 | | switch (tags[@intFromEnum(val)]) { |
| 8668 | | .type_function => return extraFuncType(ip, datas[@intFromEnum(val)]), |
| 8779 | const item = val.getItem(ip); |
| 8780 | switch (item.tag) { |
| 8781 | .type_function => return extraFuncType(ip, item.data), |
| 8669 | 8782 | else => return null, |
| 8670 | 8783 | } |
| 8671 | 8784 | } |
| ... | ... | @@ -8686,7 +8799,7 @@ pub fn isIntegerType(ip: *const InternPool, ty: Index) bool { |
| 8686 | 8799 | .c_ulonglong_type, |
| 8687 | 8800 | .comptime_int_type, |
| 8688 | 8801 | => true, |
| 8689 | | else => switch (ip.items.items(.tag)[@intFromEnum(ty)]) { |
| 8802 | else => switch (ty.getTag(ip)) { |
| 8690 | 8803 | .type_int_signed, |
| 8691 | 8804 | .type_int_unsigned, |
| 8692 | 8805 | => true, |
| ... | ... | @@ -8762,7 +8875,7 @@ pub fn errorUnionPayload(ip: *const InternPool, ty: Index) Index { |
| 8762 | 8875 | |
| 8763 | 8876 | /// The is only legal because the initializer is not part of the hash. |
| 8764 | 8877 | pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void { |
| 8765 | | const item = ip.items.get(@intFromEnum(index)); |
| 8878 | const item = index.getItem(ip); |
| 8766 | 8879 | assert(item.tag == .variable); |
| 8767 | 8880 | ip.extra.items[item.data + std.meta.fieldIndex(Tag.Variable, "init").?] = @intFromEnum(init_index); |
| 8768 | 8881 | } |
| ... | ... | @@ -8773,7 +8886,11 @@ pub fn dump(ip: *const InternPool) void { |
| 8773 | 8886 | } |
| 8774 | 8887 | |
| 8775 | 8888 | fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 8776 | | const items_size = (1 + 4) * ip.items.len; |
| 8889 | var items_len: usize = 0; |
| 8890 | for (ip.locals) |*local| { |
| 8891 | items_len += local.mutate.items.len; |
| 8892 | } |
| 8893 | const items_size = (1 + 4) * items_len; |
| 8777 | 8894 | const extra_size = 4 * ip.extra.items.len; |
| 8778 | 8895 | const limbs_size = 8 * ip.limbs.items.len; |
| 8779 | 8896 | const decls_size = ip.allocated_decls.len * @sizeOf(Module.Decl); |
| ... | ... | @@ -8790,7 +8907,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 8790 | 8907 | \\ |
| 8791 | 8908 | , .{ |
| 8792 | 8909 | total_size, |
| 8793 | | ip.items.len, |
| 8910 | items_len, |
| 8794 | 8911 | items_size, |
| 8795 | 8912 | ip.extra.items.len, |
| 8796 | 8913 | extra_size, |
| ... | ... | @@ -8800,217 +8917,221 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 8800 | 8917 | decls_size, |
| 8801 | 8918 | }); |
| 8802 | 8919 | |
| 8803 | | const tags = ip.items.items(.tag); |
| 8804 | | const datas = ip.items.items(.data); |
| 8805 | 8920 | const TagStats = struct { |
| 8806 | 8921 | count: usize = 0, |
| 8807 | 8922 | bytes: usize = 0, |
| 8808 | 8923 | }; |
| 8809 | 8924 | var counts = std.AutoArrayHashMap(Tag, TagStats).init(arena); |
| 8810 | | for (tags, datas) |tag, data| { |
| 8811 | | const gop = try counts.getOrPut(tag); |
| 8812 | | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 8813 | | gop.value_ptr.count += 1; |
| 8814 | | gop.value_ptr.bytes += 1 + 4 + @as(usize, switch (tag) { |
| 8815 | | // Note that in this case, we have technically leaked some extra data |
| 8816 | | // bytes which we do not account for here. |
| 8817 | | .removed => 0, |
| 8818 | | |
| 8819 | | .type_int_signed => 0, |
| 8820 | | .type_int_unsigned => 0, |
| 8821 | | .type_array_small => @sizeOf(Vector), |
| 8822 | | .type_array_big => @sizeOf(Array), |
| 8823 | | .type_vector => @sizeOf(Vector), |
| 8824 | | .type_pointer => @sizeOf(Tag.TypePointer), |
| 8825 | | .type_slice => 0, |
| 8826 | | .type_optional => 0, |
| 8827 | | .type_anyframe => 0, |
| 8828 | | .type_error_union => @sizeOf(Key.ErrorUnionType), |
| 8829 | | .type_anyerror_union => 0, |
| 8830 | | .type_error_set => b: { |
| 8831 | | const info = ip.extraData(Tag.ErrorSet, data); |
| 8832 | | break :b @sizeOf(Tag.ErrorSet) + (@sizeOf(u32) * info.names_len); |
| 8833 | | }, |
| 8834 | | .type_inferred_error_set => 0, |
| 8835 | | .type_enum_explicit, .type_enum_nonexhaustive => b: { |
| 8836 | | const info = ip.extraData(EnumExplicit, data); |
| 8837 | | var ints = @typeInfo(EnumExplicit).Struct.fields.len; |
| 8838 | | if (info.zir_index == .none) ints += 1; |
| 8839 | | ints += if (info.captures_len != std.math.maxInt(u32)) |
| 8840 | | info.captures_len |
| 8841 | | else |
| 8842 | | @typeInfo(PackedU64).Struct.fields.len; |
| 8843 | | ints += info.fields_len; |
| 8844 | | if (info.values_map != .none) ints += info.fields_len; |
| 8845 | | break :b @sizeOf(u32) * ints; |
| 8846 | | }, |
| 8847 | | .type_enum_auto => b: { |
| 8848 | | const info = ip.extraData(EnumAuto, data); |
| 8849 | | const ints = @typeInfo(EnumAuto).Struct.fields.len + info.captures_len + info.fields_len; |
| 8850 | | break :b @sizeOf(u32) * ints; |
| 8851 | | }, |
| 8852 | | .type_opaque => b: { |
| 8853 | | const info = ip.extraData(Tag.TypeOpaque, data); |
| 8854 | | const ints = @typeInfo(Tag.TypeOpaque).Struct.fields.len + info.captures_len; |
| 8855 | | break :b @sizeOf(u32) * ints; |
| 8856 | | }, |
| 8857 | | .type_struct => b: { |
| 8858 | | if (data == 0) break :b 0; |
| 8859 | | const extra = ip.extraDataTrail(Tag.TypeStruct, data); |
| 8860 | | const info = extra.data; |
| 8861 | | var ints: usize = @typeInfo(Tag.TypeStruct).Struct.fields.len; |
| 8862 | | if (info.flags.any_captures) { |
| 8863 | | const captures_len = ip.extra.items[extra.end]; |
| 8864 | | ints += 1 + captures_len; |
| 8865 | | } |
| 8866 | | ints += info.fields_len; // types |
| 8867 | | if (!info.flags.is_tuple) { |
| 8868 | | ints += 1; // names_map |
| 8869 | | ints += info.fields_len; // names |
| 8870 | | } |
| 8871 | | if (info.flags.any_default_inits) |
| 8872 | | ints += info.fields_len; // inits |
| 8873 | | ints += @intFromBool(info.flags.has_namespace); // namespace |
| 8874 | | if (info.flags.any_aligned_fields) |
| 8875 | | ints += (info.fields_len + 3) / 4; // aligns |
| 8876 | | if (info.flags.any_comptime_fields) |
| 8877 | | ints += (info.fields_len + 31) / 32; // comptime bits |
| 8878 | | if (!info.flags.is_extern) |
| 8879 | | ints += info.fields_len; // runtime order |
| 8880 | | ints += info.fields_len; // offsets |
| 8881 | | break :b @sizeOf(u32) * ints; |
| 8882 | | }, |
| 8883 | | .type_struct_anon => b: { |
| 8884 | | const info = ip.extraData(TypeStructAnon, data); |
| 8885 | | break :b @sizeOf(TypeStructAnon) + (@sizeOf(u32) * 3 * info.fields_len); |
| 8886 | | }, |
| 8887 | | .type_struct_packed => b: { |
| 8888 | | const extra = ip.extraDataTrail(Tag.TypeStructPacked, data); |
| 8889 | | const captures_len = if (extra.data.flags.any_captures) |
| 8890 | | ip.extra.items[extra.end] |
| 8891 | | else |
| 8892 | | 0; |
| 8893 | | break :b @sizeOf(u32) * (@typeInfo(Tag.TypeStructPacked).Struct.fields.len + |
| 8894 | | @intFromBool(extra.data.flags.any_captures) + captures_len + |
| 8895 | | extra.data.fields_len * 2); |
| 8896 | | }, |
| 8897 | | .type_struct_packed_inits => b: { |
| 8898 | | const extra = ip.extraDataTrail(Tag.TypeStructPacked, data); |
| 8899 | | const captures_len = if (extra.data.flags.any_captures) |
| 8900 | | ip.extra.items[extra.end] |
| 8901 | | else |
| 8902 | | 0; |
| 8903 | | break :b @sizeOf(u32) * (@typeInfo(Tag.TypeStructPacked).Struct.fields.len + |
| 8904 | | @intFromBool(extra.data.flags.any_captures) + captures_len + |
| 8905 | | extra.data.fields_len * 3); |
| 8906 | | }, |
| 8907 | | .type_tuple_anon => b: { |
| 8908 | | const info = ip.extraData(TypeStructAnon, data); |
| 8909 | | break :b @sizeOf(TypeStructAnon) + (@sizeOf(u32) * 2 * info.fields_len); |
| 8910 | | }, |
| 8911 | | |
| 8912 | | .type_union => b: { |
| 8913 | | const extra = ip.extraDataTrail(Tag.TypeUnion, data); |
| 8914 | | const captures_len = if (extra.data.flags.any_captures) |
| 8915 | | ip.extra.items[extra.end] |
| 8916 | | else |
| 8917 | | 0; |
| 8918 | | const per_field = @sizeOf(u32); // field type |
| 8919 | | // 1 byte per field for alignment, rounded up to the nearest 4 bytes |
| 8920 | | const alignments = if (extra.data.flags.any_aligned_fields) |
| 8921 | | ((extra.data.fields_len + 3) / 4) * 4 |
| 8922 | | else |
| 8923 | | 0; |
| 8924 | | break :b @sizeOf(Tag.TypeUnion) + |
| 8925 | | 4 * (@intFromBool(extra.data.flags.any_captures) + captures_len) + |
| 8926 | | (extra.data.fields_len * per_field) + alignments; |
| 8927 | | }, |
| 8925 | for (ip.locals) |*local| { |
| 8926 | const items = local.shared.items.view(); |
| 8927 | for ( |
| 8928 | items.items(.tag)[0..local.mutate.items.len], |
| 8929 | items.items(.data)[0..local.mutate.items.len], |
| 8930 | ) |tag, data| { |
| 8931 | const gop = try counts.getOrPut(tag); |
| 8932 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 8933 | gop.value_ptr.count += 1; |
| 8934 | gop.value_ptr.bytes += 1 + 4 + @as(usize, switch (tag) { |
| 8935 | // Note that in this case, we have technically leaked some extra data |
| 8936 | // bytes which we do not account for here. |
| 8937 | .removed => 0, |
| 8938 | |
| 8939 | .type_int_signed => 0, |
| 8940 | .type_int_unsigned => 0, |
| 8941 | .type_array_small => @sizeOf(Vector), |
| 8942 | .type_array_big => @sizeOf(Array), |
| 8943 | .type_vector => @sizeOf(Vector), |
| 8944 | .type_pointer => @sizeOf(Tag.TypePointer), |
| 8945 | .type_slice => 0, |
| 8946 | .type_optional => 0, |
| 8947 | .type_anyframe => 0, |
| 8948 | .type_error_union => @sizeOf(Key.ErrorUnionType), |
| 8949 | .type_anyerror_union => 0, |
| 8950 | .type_error_set => b: { |
| 8951 | const info = ip.extraData(Tag.ErrorSet, data); |
| 8952 | break :b @sizeOf(Tag.ErrorSet) + (@sizeOf(u32) * info.names_len); |
| 8953 | }, |
| 8954 | .type_inferred_error_set => 0, |
| 8955 | .type_enum_explicit, .type_enum_nonexhaustive => b: { |
| 8956 | const info = ip.extraData(EnumExplicit, data); |
| 8957 | var ints = @typeInfo(EnumExplicit).Struct.fields.len; |
| 8958 | if (info.zir_index == .none) ints += 1; |
| 8959 | ints += if (info.captures_len != std.math.maxInt(u32)) |
| 8960 | info.captures_len |
| 8961 | else |
| 8962 | @typeInfo(PackedU64).Struct.fields.len; |
| 8963 | ints += info.fields_len; |
| 8964 | if (info.values_map != .none) ints += info.fields_len; |
| 8965 | break :b @sizeOf(u32) * ints; |
| 8966 | }, |
| 8967 | .type_enum_auto => b: { |
| 8968 | const info = ip.extraData(EnumAuto, data); |
| 8969 | const ints = @typeInfo(EnumAuto).Struct.fields.len + info.captures_len + info.fields_len; |
| 8970 | break :b @sizeOf(u32) * ints; |
| 8971 | }, |
| 8972 | .type_opaque => b: { |
| 8973 | const info = ip.extraData(Tag.TypeOpaque, data); |
| 8974 | const ints = @typeInfo(Tag.TypeOpaque).Struct.fields.len + info.captures_len; |
| 8975 | break :b @sizeOf(u32) * ints; |
| 8976 | }, |
| 8977 | .type_struct => b: { |
| 8978 | if (data == 0) break :b 0; |
| 8979 | const extra = ip.extraDataTrail(Tag.TypeStruct, data); |
| 8980 | const info = extra.data; |
| 8981 | var ints: usize = @typeInfo(Tag.TypeStruct).Struct.fields.len; |
| 8982 | if (info.flags.any_captures) { |
| 8983 | const captures_len = ip.extra.items[extra.end]; |
| 8984 | ints += 1 + captures_len; |
| 8985 | } |
| 8986 | ints += info.fields_len; // types |
| 8987 | if (!info.flags.is_tuple) { |
| 8988 | ints += 1; // names_map |
| 8989 | ints += info.fields_len; // names |
| 8990 | } |
| 8991 | if (info.flags.any_default_inits) |
| 8992 | ints += info.fields_len; // inits |
| 8993 | ints += @intFromBool(info.flags.has_namespace); // namespace |
| 8994 | if (info.flags.any_aligned_fields) |
| 8995 | ints += (info.fields_len + 3) / 4; // aligns |
| 8996 | if (info.flags.any_comptime_fields) |
| 8997 | ints += (info.fields_len + 31) / 32; // comptime bits |
| 8998 | if (!info.flags.is_extern) |
| 8999 | ints += info.fields_len; // runtime order |
| 9000 | ints += info.fields_len; // offsets |
| 9001 | break :b @sizeOf(u32) * ints; |
| 9002 | }, |
| 9003 | .type_struct_anon => b: { |
| 9004 | const info = ip.extraData(TypeStructAnon, data); |
| 9005 | break :b @sizeOf(TypeStructAnon) + (@sizeOf(u32) * 3 * info.fields_len); |
| 9006 | }, |
| 9007 | .type_struct_packed => b: { |
| 9008 | const extra = ip.extraDataTrail(Tag.TypeStructPacked, data); |
| 9009 | const captures_len = if (extra.data.flags.any_captures) |
| 9010 | ip.extra.items[extra.end] |
| 9011 | else |
| 9012 | 0; |
| 9013 | break :b @sizeOf(u32) * (@typeInfo(Tag.TypeStructPacked).Struct.fields.len + |
| 9014 | @intFromBool(extra.data.flags.any_captures) + captures_len + |
| 9015 | extra.data.fields_len * 2); |
| 9016 | }, |
| 9017 | .type_struct_packed_inits => b: { |
| 9018 | const extra = ip.extraDataTrail(Tag.TypeStructPacked, data); |
| 9019 | const captures_len = if (extra.data.flags.any_captures) |
| 9020 | ip.extra.items[extra.end] |
| 9021 | else |
| 9022 | 0; |
| 9023 | break :b @sizeOf(u32) * (@typeInfo(Tag.TypeStructPacked).Struct.fields.len + |
| 9024 | @intFromBool(extra.data.flags.any_captures) + captures_len + |
| 9025 | extra.data.fields_len * 3); |
| 9026 | }, |
| 9027 | .type_tuple_anon => b: { |
| 9028 | const info = ip.extraData(TypeStructAnon, data); |
| 9029 | break :b @sizeOf(TypeStructAnon) + (@sizeOf(u32) * 2 * info.fields_len); |
| 9030 | }, |
| 8928 | 9031 | |
| 8929 | | .type_function => b: { |
| 8930 | | const info = ip.extraData(Tag.TypeFunction, data); |
| 8931 | | break :b @sizeOf(Tag.TypeFunction) + |
| 8932 | | (@sizeOf(Index) * info.params_len) + |
| 8933 | | (@as(u32, 4) * @intFromBool(info.flags.has_comptime_bits)) + |
| 8934 | | (@as(u32, 4) * @intFromBool(info.flags.has_noalias_bits)); |
| 8935 | | }, |
| 9032 | .type_union => b: { |
| 9033 | const extra = ip.extraDataTrail(Tag.TypeUnion, data); |
| 9034 | const captures_len = if (extra.data.flags.any_captures) |
| 9035 | ip.extra.items[extra.end] |
| 9036 | else |
| 9037 | 0; |
| 9038 | const per_field = @sizeOf(u32); // field type |
| 9039 | // 1 byte per field for alignment, rounded up to the nearest 4 bytes |
| 9040 | const alignments = if (extra.data.flags.any_aligned_fields) |
| 9041 | ((extra.data.fields_len + 3) / 4) * 4 |
| 9042 | else |
| 9043 | 0; |
| 9044 | break :b @sizeOf(Tag.TypeUnion) + |
| 9045 | 4 * (@intFromBool(extra.data.flags.any_captures) + captures_len) + |
| 9046 | (extra.data.fields_len * per_field) + alignments; |
| 9047 | }, |
| 8936 | 9048 | |
| 8937 | | .undef => 0, |
| 8938 | | .simple_type => 0, |
| 8939 | | .simple_value => 0, |
| 8940 | | .ptr_decl => @sizeOf(PtrDecl), |
| 8941 | | .ptr_comptime_alloc => @sizeOf(PtrComptimeAlloc), |
| 8942 | | .ptr_anon_decl => @sizeOf(PtrAnonDecl), |
| 8943 | | .ptr_anon_decl_aligned => @sizeOf(PtrAnonDeclAligned), |
| 8944 | | .ptr_comptime_field => @sizeOf(PtrComptimeField), |
| 8945 | | .ptr_int => @sizeOf(PtrInt), |
| 8946 | | .ptr_eu_payload => @sizeOf(PtrBase), |
| 8947 | | .ptr_opt_payload => @sizeOf(PtrBase), |
| 8948 | | .ptr_elem => @sizeOf(PtrBaseIndex), |
| 8949 | | .ptr_field => @sizeOf(PtrBaseIndex), |
| 8950 | | .ptr_slice => @sizeOf(PtrSlice), |
| 8951 | | .opt_null => 0, |
| 8952 | | .opt_payload => @sizeOf(Tag.TypeValue), |
| 8953 | | .int_u8 => 0, |
| 8954 | | .int_u16 => 0, |
| 8955 | | .int_u32 => 0, |
| 8956 | | .int_i32 => 0, |
| 8957 | | .int_usize => 0, |
| 8958 | | .int_comptime_int_u32 => 0, |
| 8959 | | .int_comptime_int_i32 => 0, |
| 8960 | | .int_small => @sizeOf(IntSmall), |
| 9049 | .type_function => b: { |
| 9050 | const info = ip.extraData(Tag.TypeFunction, data); |
| 9051 | break :b @sizeOf(Tag.TypeFunction) + |
| 9052 | (@sizeOf(Index) * info.params_len) + |
| 9053 | (@as(u32, 4) * @intFromBool(info.flags.has_comptime_bits)) + |
| 9054 | (@as(u32, 4) * @intFromBool(info.flags.has_noalias_bits)); |
| 9055 | }, |
| 8961 | 9056 | |
| 8962 | | .int_positive, |
| 8963 | | .int_negative, |
| 8964 | | => b: { |
| 8965 | | const int = ip.limbData(Int, data); |
| 8966 | | break :b @sizeOf(Int) + int.limbs_len * 8; |
| 8967 | | }, |
| 9057 | .undef => 0, |
| 9058 | .simple_type => 0, |
| 9059 | .simple_value => 0, |
| 9060 | .ptr_decl => @sizeOf(PtrDecl), |
| 9061 | .ptr_comptime_alloc => @sizeOf(PtrComptimeAlloc), |
| 9062 | .ptr_anon_decl => @sizeOf(PtrAnonDecl), |
| 9063 | .ptr_anon_decl_aligned => @sizeOf(PtrAnonDeclAligned), |
| 9064 | .ptr_comptime_field => @sizeOf(PtrComptimeField), |
| 9065 | .ptr_int => @sizeOf(PtrInt), |
| 9066 | .ptr_eu_payload => @sizeOf(PtrBase), |
| 9067 | .ptr_opt_payload => @sizeOf(PtrBase), |
| 9068 | .ptr_elem => @sizeOf(PtrBaseIndex), |
| 9069 | .ptr_field => @sizeOf(PtrBaseIndex), |
| 9070 | .ptr_slice => @sizeOf(PtrSlice), |
| 9071 | .opt_null => 0, |
| 9072 | .opt_payload => @sizeOf(Tag.TypeValue), |
| 9073 | .int_u8 => 0, |
| 9074 | .int_u16 => 0, |
| 9075 | .int_u32 => 0, |
| 9076 | .int_i32 => 0, |
| 9077 | .int_usize => 0, |
| 9078 | .int_comptime_int_u32 => 0, |
| 9079 | .int_comptime_int_i32 => 0, |
| 9080 | .int_small => @sizeOf(IntSmall), |
| 9081 | |
| 9082 | .int_positive, |
| 9083 | .int_negative, |
| 9084 | => b: { |
| 9085 | const int = ip.limbData(Int, data); |
| 9086 | break :b @sizeOf(Int) + int.limbs_len * 8; |
| 9087 | }, |
| 8968 | 9088 | |
| 8969 | | .int_lazy_align, .int_lazy_size => @sizeOf(IntLazy), |
| 9089 | .int_lazy_align, .int_lazy_size => @sizeOf(IntLazy), |
| 8970 | 9090 | |
| 8971 | | .error_set_error, .error_union_error => @sizeOf(Key.Error), |
| 8972 | | .error_union_payload => @sizeOf(Tag.TypeValue), |
| 8973 | | .enum_literal => 0, |
| 8974 | | .enum_tag => @sizeOf(Tag.EnumTag), |
| 9091 | .error_set_error, .error_union_error => @sizeOf(Key.Error), |
| 9092 | .error_union_payload => @sizeOf(Tag.TypeValue), |
| 9093 | .enum_literal => 0, |
| 9094 | .enum_tag => @sizeOf(Tag.EnumTag), |
| 8975 | 9095 | |
| 8976 | | .bytes => b: { |
| 8977 | | const info = ip.extraData(Bytes, data); |
| 8978 | | const len: usize = @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)); |
| 8979 | | break :b @sizeOf(Bytes) + len + @intFromBool(info.bytes.at(len - 1, ip) != 0); |
| 8980 | | }, |
| 8981 | | .aggregate => b: { |
| 8982 | | const info = ip.extraData(Tag.Aggregate, data); |
| 8983 | | const fields_len: u32 = @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)); |
| 8984 | | break :b @sizeOf(Tag.Aggregate) + (@sizeOf(Index) * fields_len); |
| 8985 | | }, |
| 8986 | | .repeated => @sizeOf(Repeated), |
| 8987 | | |
| 8988 | | .float_f16 => 0, |
| 8989 | | .float_f32 => 0, |
| 8990 | | .float_f64 => @sizeOf(Float64), |
| 8991 | | .float_f80 => @sizeOf(Float80), |
| 8992 | | .float_f128 => @sizeOf(Float128), |
| 8993 | | .float_c_longdouble_f80 => @sizeOf(Float80), |
| 8994 | | .float_c_longdouble_f128 => @sizeOf(Float128), |
| 8995 | | .float_comptime_float => @sizeOf(Float128), |
| 8996 | | .variable => @sizeOf(Tag.Variable), |
| 8997 | | .extern_func => @sizeOf(Tag.ExternFunc), |
| 8998 | | .func_decl => @sizeOf(Tag.FuncDecl), |
| 8999 | | .func_instance => b: { |
| 9000 | | const info = ip.extraData(Tag.FuncInstance, data); |
| 9001 | | const ty = ip.typeOf(info.generic_owner); |
| 9002 | | const params_len = ip.indexToKey(ty).func_type.param_types.len; |
| 9003 | | break :b @sizeOf(Tag.FuncInstance) + @sizeOf(Index) * params_len; |
| 9004 | | }, |
| 9005 | | .func_coerced => @sizeOf(Tag.FuncCoerced), |
| 9006 | | .only_possible_value => 0, |
| 9007 | | .union_value => @sizeOf(Key.Union), |
| 9096 | .bytes => b: { |
| 9097 | const info = ip.extraData(Bytes, data); |
| 9098 | const len: usize = @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)); |
| 9099 | break :b @sizeOf(Bytes) + len + @intFromBool(info.bytes.at(len - 1, ip) != 0); |
| 9100 | }, |
| 9101 | .aggregate => b: { |
| 9102 | const info = ip.extraData(Tag.Aggregate, data); |
| 9103 | const fields_len: u32 = @intCast(ip.aggregateTypeLenIncludingSentinel(info.ty)); |
| 9104 | break :b @sizeOf(Tag.Aggregate) + (@sizeOf(Index) * fields_len); |
| 9105 | }, |
| 9106 | .repeated => @sizeOf(Repeated), |
| 9107 | |
| 9108 | .float_f16 => 0, |
| 9109 | .float_f32 => 0, |
| 9110 | .float_f64 => @sizeOf(Float64), |
| 9111 | .float_f80 => @sizeOf(Float80), |
| 9112 | .float_f128 => @sizeOf(Float128), |
| 9113 | .float_c_longdouble_f80 => @sizeOf(Float80), |
| 9114 | .float_c_longdouble_f128 => @sizeOf(Float128), |
| 9115 | .float_comptime_float => @sizeOf(Float128), |
| 9116 | .variable => @sizeOf(Tag.Variable), |
| 9117 | .extern_func => @sizeOf(Tag.ExternFunc), |
| 9118 | .func_decl => @sizeOf(Tag.FuncDecl), |
| 9119 | .func_instance => b: { |
| 9120 | const info = ip.extraData(Tag.FuncInstance, data); |
| 9121 | const ty = ip.typeOf(info.generic_owner); |
| 9122 | const params_len = ip.indexToKey(ty).func_type.param_types.len; |
| 9123 | break :b @sizeOf(Tag.FuncInstance) + @sizeOf(Index) * params_len; |
| 9124 | }, |
| 9125 | .func_coerced => @sizeOf(Tag.FuncCoerced), |
| 9126 | .only_possible_value => 0, |
| 9127 | .union_value => @sizeOf(Key.Union), |
| 9008 | 9128 | |
| 9009 | | .memoized_call => b: { |
| 9010 | | const info = ip.extraData(MemoizedCall, data); |
| 9011 | | break :b @sizeOf(MemoizedCall) + (@sizeOf(Index) * info.args_len); |
| 9012 | | }, |
| 9013 | | }); |
| 9129 | .memoized_call => b: { |
| 9130 | const info = ip.extraData(MemoizedCall, data); |
| 9131 | break :b @sizeOf(MemoizedCall) + (@sizeOf(Index) * info.args_len); |
| 9132 | }, |
| 9133 | }); |
| 9134 | } |
| 9014 | 9135 | } |
| 9015 | 9136 | const SortContext = struct { |
| 9016 | 9137 | map: *std.AutoArrayHashMap(Tag, TagStats), |
| ... | ... | @@ -9031,97 +9152,103 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 9031 | 9152 | } |
| 9032 | 9153 | |
| 9033 | 9154 | fn dumpAllFallible(ip: *const InternPool) anyerror!void { |
| 9034 | | const tags = ip.items.items(.tag); |
| 9035 | | const datas = ip.items.items(.data); |
| 9036 | 9155 | var bw = std.io.bufferedWriter(std.io.getStdErr().writer()); |
| 9037 | 9156 | const w = bw.writer(); |
| 9038 | | for (tags, datas, 0..) |tag, data, i| { |
| 9039 | | try w.print("${d} = {s}(", .{ i, @tagName(tag) }); |
| 9040 | | switch (tag) { |
| 9041 | | .removed => {}, |
| 9042 | | |
| 9043 | | .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(data)))}), |
| 9044 | | .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(data)))}), |
| 9045 | | |
| 9046 | | .type_int_signed, |
| 9047 | | .type_int_unsigned, |
| 9048 | | .type_array_small, |
| 9049 | | .type_array_big, |
| 9050 | | .type_vector, |
| 9051 | | .type_pointer, |
| 9052 | | .type_optional, |
| 9053 | | .type_anyframe, |
| 9054 | | .type_error_union, |
| 9055 | | .type_anyerror_union, |
| 9056 | | .type_error_set, |
| 9057 | | .type_inferred_error_set, |
| 9058 | | .type_enum_explicit, |
| 9059 | | .type_enum_nonexhaustive, |
| 9060 | | .type_enum_auto, |
| 9061 | | .type_opaque, |
| 9062 | | .type_struct, |
| 9063 | | .type_struct_anon, |
| 9064 | | .type_struct_packed, |
| 9065 | | .type_struct_packed_inits, |
| 9066 | | .type_tuple_anon, |
| 9067 | | .type_union, |
| 9068 | | .type_function, |
| 9069 | | .undef, |
| 9070 | | .ptr_decl, |
| 9071 | | .ptr_comptime_alloc, |
| 9072 | | .ptr_anon_decl, |
| 9073 | | .ptr_anon_decl_aligned, |
| 9074 | | .ptr_comptime_field, |
| 9075 | | .ptr_int, |
| 9076 | | .ptr_eu_payload, |
| 9077 | | .ptr_opt_payload, |
| 9078 | | .ptr_elem, |
| 9079 | | .ptr_field, |
| 9080 | | .ptr_slice, |
| 9081 | | .opt_payload, |
| 9082 | | .int_u8, |
| 9083 | | .int_u16, |
| 9084 | | .int_u32, |
| 9085 | | .int_i32, |
| 9086 | | .int_usize, |
| 9087 | | .int_comptime_int_u32, |
| 9088 | | .int_comptime_int_i32, |
| 9089 | | .int_small, |
| 9090 | | .int_positive, |
| 9091 | | .int_negative, |
| 9092 | | .int_lazy_align, |
| 9093 | | .int_lazy_size, |
| 9094 | | .error_set_error, |
| 9095 | | .error_union_error, |
| 9096 | | .error_union_payload, |
| 9097 | | .enum_literal, |
| 9098 | | .enum_tag, |
| 9099 | | .bytes, |
| 9100 | | .aggregate, |
| 9101 | | .repeated, |
| 9102 | | .float_f16, |
| 9103 | | .float_f32, |
| 9104 | | .float_f64, |
| 9105 | | .float_f80, |
| 9106 | | .float_f128, |
| 9107 | | .float_c_longdouble_f80, |
| 9108 | | .float_c_longdouble_f128, |
| 9109 | | .float_comptime_float, |
| 9110 | | .variable, |
| 9111 | | .extern_func, |
| 9112 | | .func_decl, |
| 9113 | | .func_instance, |
| 9114 | | .func_coerced, |
| 9115 | | .union_value, |
| 9116 | | .memoized_call, |
| 9117 | | => try w.print("{d}", .{data}), |
| 9118 | | |
| 9119 | | .opt_null, |
| 9120 | | .type_slice, |
| 9121 | | .only_possible_value, |
| 9122 | | => try w.print("${d}", .{data}), |
| 9157 | for (ip.locals, 0..) |*local, tid| { |
| 9158 | const items = local.shared.items.view(); |
| 9159 | for ( |
| 9160 | items.items(.tag)[0..local.mutate.items.len], |
| 9161 | items.items(.data)[0..local.mutate.items.len], |
| 9162 | 0.., |
| 9163 | ) |tag, data, index| { |
| 9164 | const i = Index.Unwrapped.wrap(.{ .tid = @enumFromInt(tid), .index = @intCast(index) }, ip); |
| 9165 | try w.print("${d} = {s}(", .{ i, @tagName(tag) }); |
| 9166 | switch (tag) { |
| 9167 | .removed => {}, |
| 9168 | |
| 9169 | .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(data)))}), |
| 9170 | .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(data)))}), |
| 9171 | |
| 9172 | .type_int_signed, |
| 9173 | .type_int_unsigned, |
| 9174 | .type_array_small, |
| 9175 | .type_array_big, |
| 9176 | .type_vector, |
| 9177 | .type_pointer, |
| 9178 | .type_optional, |
| 9179 | .type_anyframe, |
| 9180 | .type_error_union, |
| 9181 | .type_anyerror_union, |
| 9182 | .type_error_set, |
| 9183 | .type_inferred_error_set, |
| 9184 | .type_enum_explicit, |
| 9185 | .type_enum_nonexhaustive, |
| 9186 | .type_enum_auto, |
| 9187 | .type_opaque, |
| 9188 | .type_struct, |
| 9189 | .type_struct_anon, |
| 9190 | .type_struct_packed, |
| 9191 | .type_struct_packed_inits, |
| 9192 | .type_tuple_anon, |
| 9193 | .type_union, |
| 9194 | .type_function, |
| 9195 | .undef, |
| 9196 | .ptr_decl, |
| 9197 | .ptr_comptime_alloc, |
| 9198 | .ptr_anon_decl, |
| 9199 | .ptr_anon_decl_aligned, |
| 9200 | .ptr_comptime_field, |
| 9201 | .ptr_int, |
| 9202 | .ptr_eu_payload, |
| 9203 | .ptr_opt_payload, |
| 9204 | .ptr_elem, |
| 9205 | .ptr_field, |
| 9206 | .ptr_slice, |
| 9207 | .opt_payload, |
| 9208 | .int_u8, |
| 9209 | .int_u16, |
| 9210 | .int_u32, |
| 9211 | .int_i32, |
| 9212 | .int_usize, |
| 9213 | .int_comptime_int_u32, |
| 9214 | .int_comptime_int_i32, |
| 9215 | .int_small, |
| 9216 | .int_positive, |
| 9217 | .int_negative, |
| 9218 | .int_lazy_align, |
| 9219 | .int_lazy_size, |
| 9220 | .error_set_error, |
| 9221 | .error_union_error, |
| 9222 | .error_union_payload, |
| 9223 | .enum_literal, |
| 9224 | .enum_tag, |
| 9225 | .bytes, |
| 9226 | .aggregate, |
| 9227 | .repeated, |
| 9228 | .float_f16, |
| 9229 | .float_f32, |
| 9230 | .float_f64, |
| 9231 | .float_f80, |
| 9232 | .float_f128, |
| 9233 | .float_c_longdouble_f80, |
| 9234 | .float_c_longdouble_f128, |
| 9235 | .float_comptime_float, |
| 9236 | .variable, |
| 9237 | .extern_func, |
| 9238 | .func_decl, |
| 9239 | .func_instance, |
| 9240 | .func_coerced, |
| 9241 | .union_value, |
| 9242 | .memoized_call, |
| 9243 | => try w.print("{d}", .{data}), |
| 9244 | |
| 9245 | .opt_null, |
| 9246 | .type_slice, |
| 9247 | .only_possible_value, |
| 9248 | => try w.print("${d}", .{data}), |
| 9249 | } |
| 9250 | try w.writeAll(")\n"); |
| 9123 | 9251 | } |
| 9124 | | try w.writeAll(")\n"); |
| 9125 | 9252 | } |
| 9126 | 9253 | try bw.flush(); |
| 9127 | 9254 | } |
| ... | ... | @@ -9139,15 +9266,24 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator) |
| 9139 | 9266 | const w = bw.writer(); |
| 9140 | 9267 | |
| 9141 | 9268 | var instances: std.AutoArrayHashMapUnmanaged(Index, std.ArrayListUnmanaged(Index)) = .{}; |
| 9142 | | const datas = ip.items.items(.data); |
| 9143 | | for (ip.items.items(.tag), 0..) |tag, i| { |
| 9144 | | if (tag != .func_instance) continue; |
| 9145 | | const info = ip.extraData(Tag.FuncInstance, datas[i]); |
| 9146 | | |
| 9147 | | const gop = try instances.getOrPut(arena, info.generic_owner); |
| 9148 | | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 9149 | | |
| 9150 | | try gop.value_ptr.append(arena, @enumFromInt(i)); |
| 9269 | for (ip.locals, 0..) |*local, tid| { |
| 9270 | const items = local.shared.items.view(); |
| 9271 | for ( |
| 9272 | items.items(.tag)[0..local.mutate.items.len], |
| 9273 | items.items(.data)[0..local.mutate.items.len], |
| 9274 | 0.., |
| 9275 | ) |tag, data, index| { |
| 9276 | if (tag != .func_instance) continue; |
| 9277 | const info = ip.extraData(Tag.FuncInstance, data); |
| 9278 | |
| 9279 | const gop = try instances.getOrPut(arena, info.generic_owner); |
| 9280 | if (!gop.found_existing) gop.value_ptr.* = .{}; |
| 9281 | |
| 9282 | try gop.value_ptr.append( |
| 9283 | arena, |
| 9284 | Index.Unwrapped.wrap(.{ .tid = @enumFromInt(tid), .index = @intCast(index) }, ip), |
| 9285 | ); |
| 9286 | } |
| 9151 | 9287 | } |
| 9152 | 9288 | |
| 9153 | 9289 | const SortContext = struct { |
| ... | ... | @@ -9163,7 +9299,7 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator) |
| 9163 | 9299 | const generic_fn_owner_decl = ip.declPtrConst(ip.funcDeclOwner(entry.key_ptr.*)); |
| 9164 | 9300 | try w.print("{} ({}): \n", .{ generic_fn_owner_decl.name.fmt(ip), entry.value_ptr.items.len }); |
| 9165 | 9301 | for (entry.value_ptr.items) |index| { |
| 9166 | | const func = ip.extraFuncInstance(datas[@intFromEnum(index)]); |
| 9302 | const func = ip.extraFuncInstance(index.getData(ip)); |
| 9167 | 9303 | const owner_decl = ip.declPtrConst(func.owner_decl); |
| 9168 | 9304 | try w.print(" {}: (", .{owner_decl.name.fmt(ip)}); |
| 9169 | 9305 | for (func.comptime_args.get(ip)) |arg| { |
| ... | ... | @@ -9518,7 +9654,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { |
| 9518 | 9654 | |
| 9519 | 9655 | // This optimization on tags is needed so that indexToKey can call |
| 9520 | 9656 | // typeOf without being recursive. |
| 9521 | | _ => switch (ip.items.items(.tag)[@intFromEnum(index)]) { |
| 9657 | _ => switch (index.getTag(ip)) { |
| 9522 | 9658 | .removed => unreachable, |
| 9523 | 9659 | |
| 9524 | 9660 | .type_int_signed, |
| ... | ... | @@ -9551,7 +9687,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { |
| 9551 | 9687 | .undef, |
| 9552 | 9688 | .opt_null, |
| 9553 | 9689 | .only_possible_value, |
| 9554 | | => @enumFromInt(ip.items.items(.data)[@intFromEnum(index)]), |
| 9690 | => @enumFromInt(index.getData(ip)), |
| 9555 | 9691 | |
| 9556 | 9692 | .simple_value => unreachable, // handled via Index above |
| 9557 | 9693 | |
| ... | ... | @@ -9584,7 +9720,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { |
| 9584 | 9720 | .aggregate, |
| 9585 | 9721 | .repeated, |
| 9586 | 9722 | => |t| { |
| 9587 | | const extra_index = ip.items.items(.data)[@intFromEnum(index)]; |
| 9723 | const extra_index = index.getData(ip); |
| 9588 | 9724 | const field_index = std.meta.fieldIndex(t.Payload(), "ty").?; |
| 9589 | 9725 | return @enumFromInt(ip.extra.items[extra_index + field_index]); |
| 9590 | 9726 | }, |
| ... | ... | @@ -9602,7 +9738,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { |
| 9602 | 9738 | // Note these are stored in limbs data, not extra data. |
| 9603 | 9739 | .int_positive, |
| 9604 | 9740 | .int_negative, |
| 9605 | | => ip.limbData(Int, ip.items.items(.data)[@intFromEnum(index)]).ty, |
| 9741 | => ip.limbData(Int, index.getData(ip)).ty, |
| 9606 | 9742 | |
| 9607 | 9743 | .enum_literal => .enum_literal_type, |
| 9608 | 9744 | .float_f16 => .f16_type, |
| ... | ... | @@ -9651,11 +9787,11 @@ pub fn aggregateTypeLenIncludingSentinel(ip: *const InternPool, ty: Index) u64 { |
| 9651 | 9787 | } |
| 9652 | 9788 | |
| 9653 | 9789 | pub fn funcTypeReturnType(ip: *const InternPool, ty: Index) Index { |
| 9654 | | const item = ip.items.get(@intFromEnum(ty)); |
| 9790 | const item = ty.getItem(ip); |
| 9655 | 9791 | const child_item = switch (item.tag) { |
| 9656 | | .type_pointer => ip.items.get(ip.extra.items[ |
| 9792 | .type_pointer => @as(Index, @enumFromInt(ip.extra.items[ |
| 9657 | 9793 | item.data + std.meta.fieldIndex(Tag.TypePointer, "child").? |
| 9658 | | ]), |
| 9794 | ])).getItem(ip), |
| 9659 | 9795 | .type_function => item, |
| 9660 | 9796 | else => unreachable, |
| 9661 | 9797 | }; |
| ... | ... | @@ -9668,47 +9804,47 @@ pub fn funcTypeReturnType(ip: *const InternPool, ty: Index) Index { |
| 9668 | 9804 | pub fn isNoReturn(ip: *const InternPool, ty: Index) bool { |
| 9669 | 9805 | return switch (ty) { |
| 9670 | 9806 | .noreturn_type => true, |
| 9671 | | else => switch (ip.items.items(.tag)[@intFromEnum(ty)]) { |
| 9672 | | .type_error_set => ip.extra.items[ip.items.items(.data)[@intFromEnum(ty)] + std.meta.fieldIndex(Tag.ErrorSet, "names_len").?] == 0, |
| 9807 | else => switch (ty.getTag(ip)) { |
| 9808 | .type_error_set => ip.extra.items[ty.getData(ip) + std.meta.fieldIndex(Tag.ErrorSet, "names_len").?] == 0, |
| 9673 | 9809 | else => false, |
| 9674 | 9810 | }, |
| 9675 | 9811 | }; |
| 9676 | 9812 | } |
| 9677 | 9813 | |
| 9678 | 9814 | pub fn isUndef(ip: *const InternPool, val: Index) bool { |
| 9679 | | return val == .undef or ip.items.items(.tag)[@intFromEnum(val)] == .undef; |
| 9815 | return val == .undef or val.getTag(ip) == .undef; |
| 9680 | 9816 | } |
| 9681 | 9817 | |
| 9682 | 9818 | pub fn isVariable(ip: *const InternPool, val: Index) bool { |
| 9683 | | return ip.items.items(.tag)[@intFromEnum(val)] == .variable; |
| 9819 | return val.getTag(ip) == .variable; |
| 9684 | 9820 | } |
| 9685 | 9821 | |
| 9686 | 9822 | pub fn getBackingDecl(ip: *const InternPool, val: Index) OptionalDeclIndex { |
| 9687 | | var base = @intFromEnum(val); |
| 9823 | var base = val; |
| 9688 | 9824 | while (true) { |
| 9689 | | switch (ip.items.items(.tag)[base]) { |
| 9825 | switch (base.getTag(ip)) { |
| 9690 | 9826 | .ptr_decl => return @enumFromInt(ip.extra.items[ |
| 9691 | | ip.items.items(.data)[base] + std.meta.fieldIndex(PtrDecl, "decl").? |
| 9827 | base.getData(ip) + std.meta.fieldIndex(PtrDecl, "decl").? |
| 9692 | 9828 | ]), |
| 9693 | 9829 | inline .ptr_eu_payload, |
| 9694 | 9830 | .ptr_opt_payload, |
| 9695 | 9831 | .ptr_elem, |
| 9696 | 9832 | .ptr_field, |
| 9697 | | => |tag| base = ip.extra.items[ |
| 9698 | | ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "base").? |
| 9699 | | ], |
| 9700 | | .ptr_slice => base = ip.extra.items[ |
| 9701 | | ip.items.items(.data)[base] + std.meta.fieldIndex(PtrSlice, "ptr").? |
| 9702 | | ], |
| 9833 | => |tag| base = @enumFromInt(ip.extra.items[ |
| 9834 | base.getData(ip) + std.meta.fieldIndex(tag.Payload(), "base").? |
| 9835 | ]), |
| 9836 | .ptr_slice => base = @enumFromInt(ip.extra.items[ |
| 9837 | base.getData(ip) + std.meta.fieldIndex(PtrSlice, "ptr").? |
| 9838 | ]), |
| 9703 | 9839 | else => return .none, |
| 9704 | 9840 | } |
| 9705 | 9841 | } |
| 9706 | 9842 | } |
| 9707 | 9843 | |
| 9708 | 9844 | pub fn getBackingAddrTag(ip: *const InternPool, val: Index) ?Key.Ptr.BaseAddr.Tag { |
| 9709 | | var base = @intFromEnum(val); |
| 9845 | var base = val; |
| 9710 | 9846 | while (true) { |
| 9711 | | switch (ip.items.items(.tag)[base]) { |
| 9847 | switch (base.getTag(ip)) { |
| 9712 | 9848 | .ptr_decl => return .decl, |
| 9713 | 9849 | .ptr_comptime_alloc => return .comptime_alloc, |
| 9714 | 9850 | .ptr_anon_decl, |
| ... | ... | @@ -9720,12 +9856,12 @@ pub fn getBackingAddrTag(ip: *const InternPool, val: Index) ?Key.Ptr.BaseAddr.Ta |
| 9720 | 9856 | .ptr_opt_payload, |
| 9721 | 9857 | .ptr_elem, |
| 9722 | 9858 | .ptr_field, |
| 9723 | | => |tag| base = ip.extra.items[ |
| 9724 | | ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "base").? |
| 9725 | | ], |
| 9726 | | inline .ptr_slice => |tag| base = ip.extra.items[ |
| 9727 | | ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "ptr").? |
| 9728 | | ], |
| 9859 | => |tag| base = @enumFromInt(ip.extra.items[ |
| 9860 | base.getData(ip) + std.meta.fieldIndex(tag.Payload(), "base").? |
| 9861 | ]), |
| 9862 | inline .ptr_slice => |tag| base = @enumFromInt(ip.extra.items[ |
| 9863 | base.getData(ip) + std.meta.fieldIndex(tag.Payload(), "ptr").? |
| 9864 | ]), |
| 9729 | 9865 | else => return null, |
| 9730 | 9866 | } |
| 9731 | 9867 | } |
| ... | ... | @@ -9834,7 +9970,7 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois |
| 9834 | 9970 | .empty_struct => unreachable, |
| 9835 | 9971 | .generic_poison => unreachable, |
| 9836 | 9972 | |
| 9837 | | _ => switch (ip.items.items(.tag)[@intFromEnum(index)]) { |
| 9973 | _ => switch (index.getTag(ip)) { |
| 9838 | 9974 | .removed => unreachable, |
| 9839 | 9975 | |
| 9840 | 9976 | .type_int_signed, |
| ... | ... | @@ -9941,24 +10077,22 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois |
| 9941 | 10077 | }; |
| 9942 | 10078 | } |
| 9943 | 10079 | |
| 9944 | | pub fn isFuncBody(ip: *const InternPool, i: Index) bool { |
| 9945 | | assert(i != .none); |
| 9946 | | return switch (ip.items.items(.tag)[@intFromEnum(i)]) { |
| 10080 | pub fn isFuncBody(ip: *const InternPool, index: Index) bool { |
| 10081 | return switch (index.getTag(ip)) { |
| 9947 | 10082 | .func_decl, .func_instance, .func_coerced => true, |
| 9948 | 10083 | else => false, |
| 9949 | 10084 | }; |
| 9950 | 10085 | } |
| 9951 | 10086 | |
| 9952 | | pub fn funcAnalysis(ip: *const InternPool, i: Index) *FuncAnalysis { |
| 9953 | | assert(i != .none); |
| 9954 | | const item = ip.items.get(@intFromEnum(i)); |
| 10087 | pub fn funcAnalysis(ip: *const InternPool, index: Index) *FuncAnalysis { |
| 10088 | const item = index.getItem(ip); |
| 9955 | 10089 | const extra_index = switch (item.tag) { |
| 9956 | 10090 | .func_decl => item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?, |
| 9957 | 10091 | .func_instance => item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?, |
| 9958 | 10092 | .func_coerced => i: { |
| 9959 | 10093 | const extra_index = item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").?; |
| 9960 | 10094 | const func_index: Index = @enumFromInt(ip.extra.items[extra_index]); |
| 9961 | | const sub_item = ip.items.get(@intFromEnum(func_index)); |
| 10095 | const sub_item = func_index.getItem(ip); |
| 9962 | 10096 | break :i switch (sub_item.tag) { |
| 9963 | 10097 | .func_decl => sub_item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?, |
| 9964 | 10098 | .func_instance => sub_item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?, |
| ... | ... | @@ -9974,22 +10108,21 @@ pub fn funcHasInferredErrorSet(ip: *const InternPool, i: Index) bool { |
| 9974 | 10108 | return funcAnalysis(ip, i).inferred_error_set; |
| 9975 | 10109 | } |
| 9976 | 10110 | |
| 9977 | | pub fn funcZirBodyInst(ip: *const InternPool, i: Index) TrackedInst.Index { |
| 9978 | | assert(i != .none); |
| 9979 | | const item = ip.items.get(@intFromEnum(i)); |
| 10111 | pub fn funcZirBodyInst(ip: *const InternPool, index: Index) TrackedInst.Index { |
| 10112 | const item = index.getItem(ip); |
| 9980 | 10113 | const zir_body_inst_field_index = std.meta.fieldIndex(Tag.FuncDecl, "zir_body_inst").?; |
| 9981 | 10114 | const extra_index = switch (item.tag) { |
| 9982 | 10115 | .func_decl => item.data + zir_body_inst_field_index, |
| 9983 | | .func_instance => b: { |
| 10116 | .func_instance => ei: { |
| 9984 | 10117 | const generic_owner_field_index = std.meta.fieldIndex(Tag.FuncInstance, "generic_owner").?; |
| 9985 | | const func_decl_index = ip.extra.items[item.data + generic_owner_field_index]; |
| 9986 | | assert(ip.items.items(.tag)[func_decl_index] == .func_decl); |
| 9987 | | break :b ip.items.items(.data)[func_decl_index] + zir_body_inst_field_index; |
| 10118 | const func_decl_index: Index = @enumFromInt(ip.extra.items[item.data + generic_owner_field_index]); |
| 10119 | const func_decl_item = func_decl_index.getItem(ip); |
| 10120 | assert(func_decl_item.tag == .func_decl); |
| 10121 | break :ei func_decl_item.data + zir_body_inst_field_index; |
| 9988 | 10122 | }, |
| 9989 | 10123 | .func_coerced => { |
| 9990 | | const datas = ip.items.items(.data); |
| 9991 | 10124 | const uncoerced_func_index: Index = @enumFromInt(ip.extra.items[ |
| 9992 | | datas[@intFromEnum(i)] + std.meta.fieldIndex(Tag.FuncCoerced, "func").? |
| 10125 | item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").? |
| 9993 | 10126 | ]); |
| 9994 | 10127 | return ip.funcZirBodyInst(uncoerced_func_index); |
| 9995 | 10128 | }, |
| ... | ... | @@ -9999,15 +10132,14 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) TrackedInst.Index { |
| 9999 | 10132 | } |
| 10000 | 10133 | |
| 10001 | 10134 | pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index { |
| 10002 | | assert(ies_index != .none); |
| 10003 | | const tags = ip.items.items(.tag); |
| 10004 | | assert(tags[@intFromEnum(ies_index)] == .type_inferred_error_set); |
| 10005 | | const func_index = ip.items.items(.data)[@intFromEnum(ies_index)]; |
| 10006 | | switch (tags[func_index]) { |
| 10135 | const item = ies_index.getItem(ip); |
| 10136 | assert(item.tag == .type_inferred_error_set); |
| 10137 | const func_index: Index = @enumFromInt(item.data); |
| 10138 | switch (func_index.getTag(ip)) { |
| 10007 | 10139 | .func_decl, .func_instance => {}, |
| 10008 | 10140 | else => unreachable, // assertion failed |
| 10009 | 10141 | } |
| 10010 | | return @enumFromInt(func_index); |
| 10142 | return func_index; |
| 10011 | 10143 | } |
| 10012 | 10144 | |
| 10013 | 10145 | /// Returns a mutable pointer to the resolved error set type of an inferred |
| ... | ... | @@ -10026,21 +10158,19 @@ pub fn iesResolved(ip: *const InternPool, ies_index: Index) *Index { |
| 10026 | 10158 | /// error set function. The returned pointer is invalidated when anything is |
| 10027 | 10159 | /// added to `ip`. |
| 10028 | 10160 | pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index { |
| 10029 | | const tags = ip.items.items(.tag); |
| 10030 | | const datas = ip.items.items(.data); |
| 10031 | 10161 | assert(funcHasInferredErrorSet(ip, func_index)); |
| 10032 | | const func_start = datas[@intFromEnum(func_index)]; |
| 10033 | | const extra_index = switch (tags[@intFromEnum(func_index)]) { |
| 10034 | | .func_decl => func_start + @typeInfo(Tag.FuncDecl).Struct.fields.len, |
| 10035 | | .func_instance => func_start + @typeInfo(Tag.FuncInstance).Struct.fields.len, |
| 10162 | const func_item = func_index.getItem(ip); |
| 10163 | const extra_index = switch (func_item.tag) { |
| 10164 | .func_decl => func_item.data + @typeInfo(Tag.FuncDecl).Struct.fields.len, |
| 10165 | .func_instance => func_item.data + @typeInfo(Tag.FuncInstance).Struct.fields.len, |
| 10036 | 10166 | .func_coerced => i: { |
| 10037 | 10167 | const uncoerced_func_index: Index = @enumFromInt(ip.extra.items[ |
| 10038 | | func_start + std.meta.fieldIndex(Tag.FuncCoerced, "func").? |
| 10168 | func_item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").? |
| 10039 | 10169 | ]); |
| 10040 | | const uncoerced_func_start = datas[@intFromEnum(uncoerced_func_index)]; |
| 10041 | | break :i switch (tags[@intFromEnum(uncoerced_func_index)]) { |
| 10042 | | .func_decl => uncoerced_func_start + @typeInfo(Tag.FuncDecl).Struct.fields.len, |
| 10043 | | .func_instance => uncoerced_func_start + @typeInfo(Tag.FuncInstance).Struct.fields.len, |
| 10170 | const uncoerced_func_item = uncoerced_func_index.getItem(ip); |
| 10171 | break :i switch (uncoerced_func_item.tag) { |
| 10172 | .func_decl => uncoerced_func_item.data + @typeInfo(Tag.FuncDecl).Struct.fields.len, |
| 10173 | .func_instance => uncoerced_func_item.data + @typeInfo(Tag.FuncInstance).Struct.fields.len, |
| 10044 | 10174 | else => unreachable, |
| 10045 | 10175 | }; |
| 10046 | 10176 | }, |
| ... | ... | @@ -10049,35 +10179,28 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index { |
| 10049 | 10179 | return @ptrCast(&ip.extra.items[extra_index]); |
| 10050 | 10180 | } |
| 10051 | 10181 | |
| 10052 | | pub fn funcDeclInfo(ip: *const InternPool, i: Index) Key.Func { |
| 10053 | | const tags = ip.items.items(.tag); |
| 10054 | | const datas = ip.items.items(.data); |
| 10055 | | assert(tags[@intFromEnum(i)] == .func_decl); |
| 10056 | | return extraFuncDecl(ip, datas[@intFromEnum(i)]); |
| 10182 | pub fn funcDeclInfo(ip: *const InternPool, index: Index) Key.Func { |
| 10183 | const item = index.getItem(ip); |
| 10184 | assert(item.tag == .func_decl); |
| 10185 | return extraFuncDecl(ip, item.data); |
| 10057 | 10186 | } |
| 10058 | 10187 | |
| 10059 | | pub fn funcDeclOwner(ip: *const InternPool, i: Index) DeclIndex { |
| 10060 | | return funcDeclInfo(ip, i).owner_decl; |
| 10188 | pub fn funcDeclOwner(ip: *const InternPool, index: Index) DeclIndex { |
| 10189 | return funcDeclInfo(ip, index).owner_decl; |
| 10061 | 10190 | } |
| 10062 | 10191 | |
| 10063 | | pub fn funcTypeParamsLen(ip: *const InternPool, i: Index) u32 { |
| 10064 | | const tags = ip.items.items(.tag); |
| 10065 | | const datas = ip.items.items(.data); |
| 10066 | | assert(tags[@intFromEnum(i)] == .type_function); |
| 10067 | | const start = datas[@intFromEnum(i)]; |
| 10068 | | return ip.extra.items[start + std.meta.fieldIndex(Tag.TypeFunction, "params_len").?]; |
| 10192 | pub fn funcTypeParamsLen(ip: *const InternPool, index: Index) u32 { |
| 10193 | const item = index.getItem(ip); |
| 10194 | assert(item.tag == .type_function); |
| 10195 | return ip.extra.items[item.data + std.meta.fieldIndex(Tag.TypeFunction, "params_len").?]; |
| 10069 | 10196 | } |
| 10070 | 10197 | |
| 10071 | | pub fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index { |
| 10072 | | const tags = ip.items.items(.tag); |
| 10073 | | return switch (tags[@intFromEnum(i)]) { |
| 10074 | | .func_coerced => { |
| 10075 | | const datas = ip.items.items(.data); |
| 10076 | | return @enumFromInt(ip.extra.items[ |
| 10077 | | datas[@intFromEnum(i)] + std.meta.fieldIndex(Tag.FuncCoerced, "func").? |
| 10078 | | ]); |
| 10079 | | }, |
| 10080 | | .func_instance, .func_decl => i, |
| 10198 | pub fn unwrapCoercedFunc(ip: *const InternPool, index: Index) Index { |
| 10199 | return switch (index.getTag(ip)) { |
| 10200 | .func_coerced => @enumFromInt(ip.extra.items[ |
| 10201 | index.getData(ip) + std.meta.fieldIndex(Tag.FuncCoerced, "func").? |
| 10202 | ]), |
| 10203 | .func_instance, .func_decl => index, |
| 10081 | 10204 | else => unreachable, |
| 10082 | 10205 | }; |
| 10083 | 10206 | } |
| ... | ... | @@ -10085,7 +10208,12 @@ pub fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index { |
| 10085 | 10208 | /// Having resolved a builtin type to a real struct/union/enum (which is now at `resolverd_index`), |
| 10086 | 10209 | /// make `want_index` refer to this type instead. This invalidates `resolved_index`, so must be |
| 10087 | 10210 | /// called only when it is guaranteed that no reference to `resolved_index` exists. |
| 10088 | | pub fn resolveBuiltinType(ip: *InternPool, want_index: Index, resolved_index: Index) void { |
| 10211 | pub fn resolveBuiltinType( |
| 10212 | ip: *InternPool, |
| 10213 | tid: Zcu.PerThread.Id, |
| 10214 | want_index: Index, |
| 10215 | resolved_index: Index, |
| 10216 | ) void { |
| 10089 | 10217 | assert(@intFromEnum(want_index) >= @intFromEnum(Index.first_type)); |
| 10090 | 10218 | assert(@intFromEnum(want_index) <= @intFromEnum(Index.last_type)); |
| 10091 | 10219 | |
| ... | ... | @@ -10097,20 +10225,12 @@ pub fn resolveBuiltinType(ip: *InternPool, want_index: Index, resolved_index: In |
| 10097 | 10225 | (ip.zigTypeTagOrPoison(resolved_index) catch unreachable)); |
| 10098 | 10226 | |
| 10099 | 10227 | // Copy the data |
| 10100 | | const item = ip.items.get(@intFromEnum(resolved_index)); |
| 10101 | | ip.items.set(@intFromEnum(want_index), item); |
| 10102 | | |
| 10103 | | if (std.debug.runtime_safety) { |
| 10104 | | // Make the value unreachable - this is a weird value which will make (incorrect) existing |
| 10105 | | // references easier to spot |
| 10106 | | ip.items.set(@intFromEnum(resolved_index), .{ |
| 10107 | | .tag = .simple_value, |
| 10108 | | .data = @intFromEnum(SimpleValue.@"unreachable"), |
| 10109 | | }); |
| 10110 | | } else { |
| 10111 | | // Here we could add the index to a free-list for reuse, but since |
| 10112 | | // there is so little garbage created this way it's not worth it. |
| 10113 | | } |
| 10228 | const resolved_item = resolved_index.getItem(ip); |
| 10229 | const want_unwrapped = want_index.unwrap(ip); |
| 10230 | if (tid != .main or want_unwrapped.tid != .main) @panic("This operation is impossible to be thread-safe"); |
| 10231 | var want_items = ip.getLocalShared(want_unwrapped.tid).items.view(); |
| 10232 | want_items.set(want_unwrapped.index, resolved_item); |
| 10233 | ip.remove(tid, resolved_index); |
| 10114 | 10234 | } |
| 10115 | 10235 | |
| 10116 | 10236 | pub fn anonStructFieldTypes(ip: *const InternPool, i: Index) []const Index { |