| ... | @@ -1374,12 +1374,12 @@ pub const Index = enum(u32) { | ... | @@ -1374,12 +1374,12 @@ pub const Index = enum(u32) { |
| 1374 | undef: DataIsIndex, | 1374 | undef: DataIsIndex, |
| 1375 | runtime_value: DataIsIndex, | 1375 | runtime_value: DataIsIndex, |
| 1376 | simple_value: struct { data: SimpleValue }, | 1376 | simple_value: struct { data: SimpleValue }, |
| 1377 | ptr_mut_decl: struct { data: *PtrMutDecl }, | | |
| 1378 | ptr_decl: struct { data: *PtrDecl }, | 1377 | ptr_decl: struct { data: *PtrDecl }, |
| 1379 | ptr_int: struct { data: *PtrAddr }, | 1378 | ptr_mut_decl: struct { data: *PtrMutDecl }, |
| 1380 | ptr_eu_payload: DataIsIndex, | | |
| 1381 | ptr_opt_payload: DataIsIndex, | | |
| 1382 | ptr_comptime_field: struct { data: *PtrComptimeField }, | 1379 | ptr_comptime_field: struct { data: *PtrComptimeField }, |
| | 1380 | ptr_int: struct { data: *PtrBase }, |
| | 1381 | ptr_eu_payload: struct { data: *PtrBase }, |
| | 1382 | ptr_opt_payload: struct { data: *PtrBase }, |
| 1383 | ptr_elem: struct { data: *PtrBaseIndex }, | 1383 | ptr_elem: struct { data: *PtrBaseIndex }, |
| 1384 | ptr_field: struct { data: *PtrBaseIndex }, | 1384 | ptr_field: struct { data: *PtrBaseIndex }, |
| 1385 | ptr_slice: struct { data: *PtrSlice }, | 1385 | ptr_slice: struct { data: *PtrSlice }, |
| ... | @@ -1774,29 +1774,25 @@ pub const Tag = enum(u8) { | ... | @@ -1774,29 +1774,25 @@ pub const Tag = enum(u8) { |
| 1774 | /// A value that can be represented with only an enum tag. | 1774 | /// A value that can be represented with only an enum tag. |
| 1775 | /// data is SimpleValue enum value. | 1775 | /// data is SimpleValue enum value. |
| 1776 | simple_value, | 1776 | simple_value, |
| 1777 | /// A pointer to a decl that can be mutated at comptime. | | |
| 1778 | /// data is extra index of PtrMutDecl, which contains the type and address. | | |
| 1779 | ptr_mut_decl, | | |
| 1780 | /// A pointer to a decl. | 1777 | /// A pointer to a decl. |
| 1781 | /// data is extra index of PtrDecl, which contains the type and address. | 1778 | /// data is extra index of `PtrDecl`, which contains the type and address. |
| 1782 | ptr_decl, | 1779 | ptr_decl, |
| | 1780 | /// A pointer to a decl that can be mutated at comptime. |
| | 1781 | /// data is extra index of `PtrMutDecl`, which contains the type and address. |
| | 1782 | ptr_mut_decl, |
| | 1783 | /// data is extra index of `PtrComptimeField`, which contains the pointer type and field value. |
| | 1784 | ptr_comptime_field, |
| 1783 | /// A pointer with an integer value. | 1785 | /// A pointer with an integer value. |
| 1784 | /// data is extra index of PtrAddr, which contains the type and address. | 1786 | /// data is extra index of `PtrBase`, which contains the type and address. |
| 1785 | /// Only pointer types are allowed to have this encoding. Optional types must use | 1787 | /// Only pointer types are allowed to have this encoding. Optional types must use |
| 1786 | /// `opt_payload` or `opt_null`. | 1788 | /// `opt_payload` or `opt_null`. |
| 1787 | ptr_int, | 1789 | ptr_int, |
| 1788 | /// A pointer to the payload of an error union. | 1790 | /// A pointer to the payload of an error union. |
| 1789 | /// data is Index of a pointer value to the error union. | 1791 | /// data is extra index of `PtrBase`, which contains the type and base pointer. |
| 1790 | /// In order to use this encoding, one must ensure that the `InternPool` | | |
| 1791 | /// already contains the payload pointer type corresponding to this payload. | | |
| 1792 | ptr_eu_payload, | 1792 | ptr_eu_payload, |
| 1793 | /// A pointer to the payload of an optional. | 1793 | /// A pointer to the payload of an optional. |
| 1794 | /// data is Index of a pointer value to the optional. | 1794 | /// data is extra index of `PtrBase`, which contains the type and base pointer. |
| 1795 | /// In order to use this encoding, one must ensure that the `InternPool` | | |
| 1796 | /// already contains the payload pointer type corresponding to this payload. | | |
| 1797 | ptr_opt_payload, | 1795 | ptr_opt_payload, |
| 1798 | /// data is extra index of PtrComptimeField, which contains the pointer type and field value. | | |
| 1799 | ptr_comptime_field, | | |
| 1800 | /// A pointer to an array element. | 1796 | /// A pointer to an array element. |
| 1801 | /// data is extra index of PtrBaseIndex, which contains the base array and element index. | 1797 | /// data is extra index of PtrBaseIndex, which contains the base array and element index. |
| 1802 | /// In order to use this encoding, one must ensure that the `InternPool` | 1798 | /// In order to use this encoding, one must ensure that the `InternPool` |
| ... | @@ -2224,14 +2220,14 @@ pub const PtrMutDecl = struct { | ... | @@ -2224,14 +2220,14 @@ pub const PtrMutDecl = struct { |
| 2224 | runtime_index: RuntimeIndex, | 2220 | runtime_index: RuntimeIndex, |
| 2225 | }; | 2221 | }; |
| 2226 | | 2222 | |
| 2227 | pub const PtrAddr = struct { | 2223 | pub const PtrComptimeField = struct { |
| 2228 | ty: Index, | 2224 | ty: Index, |
| 2229 | addr: Index, | 2225 | field_val: Index, |
| 2230 | }; | 2226 | }; |
| 2231 | | 2227 | |
| 2232 | pub const PtrComptimeField = struct { | 2228 | pub const PtrBase = struct { |
| 2233 | ty: Index, | 2229 | ty: Index, |
| 2234 | field_val: Index, | 2230 | base: Index, |
| 2235 | }; | 2231 | }; |
| 2236 | | 2232 | |
| 2237 | pub const PtrBaseIndex = struct { | 2233 | pub const PtrBaseIndex = struct { |
| ... | @@ -2598,36 +2594,23 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { | ... | @@ -2598,36 +2594,23 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 2598 | } }, | 2594 | } }, |
| 2599 | } }; | 2595 | } }; |
| 2600 | }, | 2596 | }, |
| 2601 | .ptr_int => { | 2597 | .ptr_comptime_field => { |
| 2602 | const info = ip.extraData(PtrAddr, data); | 2598 | const info = ip.extraData(PtrComptimeField, data); |
| 2603 | return .{ .ptr = .{ | 2599 | return .{ .ptr = .{ |
| 2604 | .ty = info.ty, | 2600 | .ty = info.ty, |
| 2605 | .addr = .{ .int = info.addr }, | 2601 | .addr = .{ .comptime_field = info.field_val }, |
| 2606 | } }; | | |
| 2607 | }, | | |
| 2608 | .ptr_eu_payload => { | | |
| 2609 | const ptr_eu_index = @intToEnum(Index, data); | | |
| 2610 | var ptr_type = ip.indexToKey(ip.typeOf(ptr_eu_index)).ptr_type; | | |
| 2611 | ptr_type.elem_type = ip.indexToKey(ptr_type.elem_type).error_union_type.payload_type; | | |
| 2612 | return .{ .ptr = .{ | | |
| 2613 | .ty = ip.getAssumeExists(.{ .ptr_type = ptr_type }), | | |
| 2614 | .addr = .{ .eu_payload = ptr_eu_index }, | | |
| 2615 | } }; | 2602 | } }; |
| 2616 | }, | 2603 | }, |
| 2617 | .ptr_opt_payload => { | 2604 | .ptr_int, .ptr_eu_payload, .ptr_opt_payload => { |
| 2618 | const ptr_opt_index = @intToEnum(Index, data); | 2605 | const info = ip.extraData(PtrBase, data); |
| 2619 | var ptr_type = ip.indexToKey(ip.typeOf(ptr_opt_index)).ptr_type; | | |
| 2620 | ptr_type.elem_type = ip.indexToKey(ptr_type.elem_type).opt_type; | | |
| 2621 | return .{ .ptr = .{ | | |
| 2622 | .ty = ip.getAssumeExists(.{ .ptr_type = ptr_type }), | | |
| 2623 | .addr = .{ .opt_payload = ptr_opt_index }, | | |
| 2624 | } }; | | |
| 2625 | }, | | |
| 2626 | .ptr_comptime_field => { | | |
| 2627 | const info = ip.extraData(PtrComptimeField, data); | | |
| 2628 | return .{ .ptr = .{ | 2606 | return .{ .ptr = .{ |
| 2629 | .ty = info.ty, | 2607 | .ty = info.ty, |
| 2630 | .addr = .{ .comptime_field = info.field_val }, | 2608 | .addr = switch (item.tag) { |
| | 2609 | .ptr_int => .{ .int = info.base }, |
| | 2610 | .ptr_eu_payload => .{ .eu_payload = info.base }, |
| | 2611 | .ptr_opt_payload => .{ .opt_payload = info.base }, |
| | 2612 | else => unreachable, |
| | 2613 | }, |
| 2631 | } }; | 2614 | } }; |
| 2632 | }, | 2615 | }, |
| 2633 | .ptr_elem => { | 2616 | .ptr_elem => { |
| ... | @@ -3248,39 +3231,67 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -3248,39 +3231,67 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3248 | .runtime_index = mut_decl.runtime_index, | 3231 | .runtime_index = mut_decl.runtime_index, |
| 3249 | }), | 3232 | }), |
| 3250 | }), | 3233 | }), |
| 3251 | .int => |int| { | 3234 | .comptime_field => |field_val| { |
| 3252 | assert(ip.typeOf(int) == .usize_type); | 3235 | assert(field_val != .none); |
| 3253 | ip.items.appendAssumeCapacity(.{ | 3236 | ip.items.appendAssumeCapacity(.{ |
| 3254 | .tag = .ptr_int, | 3237 | .tag = .ptr_comptime_field, |
| 3255 | .data = try ip.addExtra(gpa, PtrAddr{ | 3238 | .data = try ip.addExtra(gpa, PtrComptimeField{ |
| 3256 | .ty = ptr.ty, | 3239 | .ty = ptr.ty, |
| 3257 | .addr = int, | 3240 | .field_val = field_val, |
| 3258 | }), | 3241 | }), |
| 3259 | }); | 3242 | }); |
| 3260 | }, | 3243 | }, |
| 3261 | .eu_payload, .opt_payload => |data| { | 3244 | .int, .eu_payload, .opt_payload => |base| { |
| 3262 | assert(data != .none); | 3245 | switch (ptr.addr) { |
| | 3246 | .int => assert(ip.typeOf(base) == .usize_type), |
| | 3247 | .eu_payload => assert(ip.indexToKey( |
| | 3248 | ip.indexToKey(ip.typeOf(base)).ptr_type.elem_type, |
| | 3249 | ) == .error_union_type), |
| | 3250 | .opt_payload => assert(ip.indexToKey( |
| | 3251 | ip.indexToKey(ip.typeOf(base)).ptr_type.elem_type, |
| | 3252 | ) == .opt_type), |
| | 3253 | else => unreachable, |
| | 3254 | } |
| 3263 | ip.items.appendAssumeCapacity(.{ | 3255 | ip.items.appendAssumeCapacity(.{ |
| 3264 | .tag = switch (ptr.addr) { | 3256 | .tag = switch (ptr.addr) { |
| | 3257 | .int => .ptr_int, |
| 3265 | .eu_payload => .ptr_eu_payload, | 3258 | .eu_payload => .ptr_eu_payload, |
| 3266 | .opt_payload => .ptr_opt_payload, | 3259 | .opt_payload => .ptr_opt_payload, |
| 3267 | else => unreachable, | 3260 | else => unreachable, |
| 3268 | }, | 3261 | }, |
| 3269 | .data = @enumToInt(data), | 3262 | .data = try ip.addExtra(gpa, PtrBase{ |
| 3270 | }); | | |
| 3271 | }, | | |
| 3272 | .comptime_field => |field_val| { | | |
| 3273 | assert(field_val != .none); | | |
| 3274 | ip.items.appendAssumeCapacity(.{ | | |
| 3275 | .tag = .ptr_comptime_field, | | |
| 3276 | .data = try ip.addExtra(gpa, PtrComptimeField{ | | |
| 3277 | .ty = ptr.ty, | 3263 | .ty = ptr.ty, |
| 3278 | .field_val = field_val, | 3264 | .base = base, |
| 3279 | }), | 3265 | }), |
| 3280 | }); | 3266 | }); |
| 3281 | }, | 3267 | }, |
| 3282 | .elem, .field => |base_index| { | 3268 | .elem, .field => |base_index| { |
| 3283 | assert(base_index.base != .none); | 3269 | const base_ptr_type = ip.indexToKey(ip.typeOf(base_index.base)).ptr_type; |
| | 3270 | switch (base_ptr_type.size) { |
| | 3271 | .One => switch (ip.indexToKey(base_ptr_type.elem_type)) { |
| | 3272 | .array_type, .vector_type => assert(ptr.addr == .elem), |
| | 3273 | .anon_struct_type => |anon_struct_type| { |
| | 3274 | assert(ptr.addr == .field); |
| | 3275 | assert(base_index.index < anon_struct_type.types.len); |
| | 3276 | }, |
| | 3277 | .struct_type => |struct_type| { |
| | 3278 | assert(ptr.addr == .field); |
| | 3279 | assert(base_index.index < ip.structPtrUnwrapConst(struct_type.index).?.fields.count()); |
| | 3280 | }, |
| | 3281 | .union_type => |union_type| { |
| | 3282 | assert(ptr.addr == .field); |
| | 3283 | assert(base_index.index < ip.unionPtrConst(union_type.index).fields.count()); |
| | 3284 | }, |
| | 3285 | .ptr_type => |slice_type| { |
| | 3286 | assert(ptr.addr == .field); |
| | 3287 | assert(slice_type.size == .Slice); |
| | 3288 | assert(base_index.index < 2); |
| | 3289 | }, |
| | 3290 | else => unreachable, |
| | 3291 | }, |
| | 3292 | .Many => assert(ptr.addr == .elem), |
| | 3293 | .Slice, .C => unreachable, |
| | 3294 | } |
| 3284 | _ = ip.map.pop(); | 3295 | _ = ip.map.pop(); |
| 3285 | const index_index = try ip.get(gpa, .{ .int = .{ | 3296 | const index_index = try ip.get(gpa, .{ .int = .{ |
| 3286 | .ty = .usize_type, | 3297 | .ty = .usize_type, |
| ... | @@ -4750,10 +4761,10 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { | ... | @@ -4750,10 +4761,10 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { |
| 4750 | .simple_value => 0, | 4761 | .simple_value => 0, |
| 4751 | .ptr_decl => @sizeOf(PtrDecl), | 4762 | .ptr_decl => @sizeOf(PtrDecl), |
| 4752 | .ptr_mut_decl => @sizeOf(PtrMutDecl), | 4763 | .ptr_mut_decl => @sizeOf(PtrMutDecl), |
| 4753 | .ptr_int => @sizeOf(PtrAddr), | | |
| 4754 | .ptr_eu_payload => 0, | | |
| 4755 | .ptr_opt_payload => 0, | | |
| 4756 | .ptr_comptime_field => @sizeOf(PtrComptimeField), | 4764 | .ptr_comptime_field => @sizeOf(PtrComptimeField), |
| | 4765 | .ptr_int => @sizeOf(PtrBase), |
| | 4766 | .ptr_eu_payload => @sizeOf(PtrBase), |
| | 4767 | .ptr_opt_payload => @sizeOf(PtrBase), |
| 4757 | .ptr_elem => @sizeOf(PtrBaseIndex), | 4768 | .ptr_elem => @sizeOf(PtrBaseIndex), |
| 4758 | .ptr_field => @sizeOf(PtrBaseIndex), | 4769 | .ptr_field => @sizeOf(PtrBaseIndex), |
| 4759 | .ptr_slice => @sizeOf(PtrSlice), | 4770 | .ptr_slice => @sizeOf(PtrSlice), |
| ... | @@ -5281,12 +5292,12 @@ pub fn zigTypeTagOrPoison(ip: InternPool, index: Index) error{GenericPoison}!std | ... | @@ -5281,12 +5292,12 @@ pub fn zigTypeTagOrPoison(ip: InternPool, index: Index) error{GenericPoison}!std |
| 5281 | .undef, | 5292 | .undef, |
| 5282 | .runtime_value, | 5293 | .runtime_value, |
| 5283 | .simple_value, | 5294 | .simple_value, |
| 5284 | .ptr_mut_decl, | | |
| 5285 | .ptr_decl, | 5295 | .ptr_decl, |
| | 5296 | .ptr_mut_decl, |
| | 5297 | .ptr_comptime_field, |
| 5286 | .ptr_int, | 5298 | .ptr_int, |
| 5287 | .ptr_eu_payload, | 5299 | .ptr_eu_payload, |
| 5288 | .ptr_opt_payload, | 5300 | .ptr_opt_payload, |
| 5289 | .ptr_comptime_field, | | |
| 5290 | .ptr_elem, | 5301 | .ptr_elem, |
| 5291 | .ptr_field, | 5302 | .ptr_field, |
| 5292 | .ptr_slice, | 5303 | .ptr_slice, |