| ... | ... | @@ -501,6 +501,42 @@ pub const OptionalNullTerminatedString = enum(u32) { |
| 501 | 501 | } |
| 502 | 502 | }; |
| 503 | 503 | |
| 504 | /// A single value captured in the closure of a namespace type. This is not a plain |
| 505 | /// `Index` because we must differentiate between runtime-known values (where we |
| 506 | /// store the type) and comptime-known values (where we store the value). |
| 507 | pub const CaptureValue = packed struct(u32) { |
| 508 | tag: enum { @"comptime", runtime }, |
| 509 | idx: u31, |
| 510 | |
| 511 | pub fn wrap(val: Unwrapped) CaptureValue { |
| 512 | return switch (val) { |
| 513 | .@"comptime" => |i| .{ .tag = .@"comptime", .idx = @intCast(@intFromEnum(i)) }, |
| 514 | .runtime => |i| .{ .tag = .runtime, .idx = @intCast(@intFromEnum(i)) }, |
| 515 | }; |
| 516 | } |
| 517 | pub fn unwrap(val: CaptureValue) Unwrapped { |
| 518 | return switch (val.tag) { |
| 519 | .@"comptime" => .{ .@"comptime" = @enumFromInt(val.idx) }, |
| 520 | .runtime => .{ .runtime = @enumFromInt(val.idx) }, |
| 521 | }; |
| 522 | } |
| 523 | |
| 524 | pub const Unwrapped = union(enum) { |
| 525 | /// Index refers to the value. |
| 526 | @"comptime": Index, |
| 527 | /// Index refers to the type. |
| 528 | runtime: Index, |
| 529 | }; |
| 530 | |
| 531 | pub const Slice = struct { |
| 532 | start: u32, |
| 533 | len: u32, |
| 534 | pub fn get(slice: Slice, ip: *const InternPool) []CaptureValue { |
| 535 | return @ptrCast(ip.extra.items[slice.start..][0..slice.len]); |
| 536 | } |
| 537 | }; |
| 538 | }; |
| 539 | |
| 504 | 540 | pub const Key = union(enum) { |
| 505 | 541 | int_type: IntType, |
| 506 | 542 | ptr_type: PtrType, |
| ... | ... | @@ -707,6 +743,7 @@ pub const Key = union(enum) { |
| 707 | 743 | /// This may be updated via `setTagType` later. |
| 708 | 744 | tag_ty: Index = .none, |
| 709 | 745 | zir_index: TrackedInst.Index.Optional, |
| 746 | captures: []const CaptureValue, |
| 710 | 747 | |
| 711 | 748 | pub fn toEnumType(self: @This()) LoadedEnumType { |
| 712 | 749 | if (true) @compileError("AHHHH"); |
| ... | ... | @@ -1660,6 +1697,7 @@ pub const LoadedUnionType = struct { |
| 1660 | 1697 | field_aligns: Alignment.Slice, |
| 1661 | 1698 | /// Index of the union_decl ZIR instruction. |
| 1662 | 1699 | zir_index: TrackedInst.Index.Optional, |
| 1700 | captures: CaptureValue.Slice, |
| 1663 | 1701 | |
| 1664 | 1702 | pub const RuntimeTag = enum(u2) { |
| 1665 | 1703 | none, |
| ... | ... | @@ -1791,24 +1829,47 @@ pub const LoadedUnionType = struct { |
| 1791 | 1829 | }; |
| 1792 | 1830 | |
| 1793 | 1831 | pub fn loadUnionType(ip: *const InternPool, index: Index) LoadedUnionType { |
| 1794 | | const extra_index = ip.items.items(.data)[@intFromEnum(index)]; |
| 1795 | | const type_union = ip.extraDataTrail(Tag.TypeUnion, extra_index); |
| 1832 | const data = ip.items.items(.data)[@intFromEnum(index)]; |
| 1833 | const type_union = ip.extraDataTrail(Tag.TypeUnion, data); |
| 1796 | 1834 | const fields_len = type_union.data.fields_len; |
| 1797 | 1835 | |
| 1836 | var extra_index = type_union.end; |
| 1837 | const captures_len = if (type_union.data.flags.any_captures) c: { |
| 1838 | const len = ip.extra.items[extra_index]; |
| 1839 | extra_index += 1; |
| 1840 | break :c len; |
| 1841 | } else 0; |
| 1842 | |
| 1843 | const captures: CaptureValue.Slice = .{ |
| 1844 | .start = extra_index, |
| 1845 | .len = captures_len, |
| 1846 | }; |
| 1847 | extra_index += captures_len; |
| 1848 | |
| 1849 | const field_types: Index.Slice = .{ |
| 1850 | .start = extra_index, |
| 1851 | .len = fields_len, |
| 1852 | }; |
| 1853 | extra_index += fields_len; |
| 1854 | |
| 1855 | const field_aligns: Alignment.Slice = if (type_union.data.flags.any_aligned_fields) a: { |
| 1856 | const a: Alignment.Slice = .{ |
| 1857 | .start = extra_index, |
| 1858 | .len = fields_len, |
| 1859 | }; |
| 1860 | extra_index += std.math.divCeil(u32, fields_len, 4) catch unreachable; |
| 1861 | break :a a; |
| 1862 | } else .{ .start = 0, .len = 0 }; |
| 1863 | |
| 1798 | 1864 | return .{ |
| 1799 | | .extra_index = extra_index, |
| 1865 | .extra_index = data, |
| 1800 | 1866 | .decl = type_union.data.decl, |
| 1801 | 1867 | .namespace = type_union.data.namespace, |
| 1802 | 1868 | .enum_tag_ty = type_union.data.tag_ty, |
| 1803 | | .field_types = .{ |
| 1804 | | .start = type_union.end, |
| 1805 | | .len = fields_len, |
| 1806 | | }, |
| 1807 | | .field_aligns = .{ |
| 1808 | | .start = type_union.end + fields_len, |
| 1809 | | .len = if (type_union.data.flags.any_aligned_fields) fields_len else 0, |
| 1810 | | }, |
| 1869 | .field_types = field_types, |
| 1870 | .field_aligns = field_aligns, |
| 1811 | 1871 | .zir_index = type_union.data.zir_index, |
| 1872 | .captures = captures, |
| 1812 | 1873 | }; |
| 1813 | 1874 | } |
| 1814 | 1875 | |
| ... | ... | @@ -1830,6 +1891,7 @@ pub const LoadedStructType = struct { |
| 1830 | 1891 | comptime_bits: ComptimeBits, |
| 1831 | 1892 | offsets: Offsets, |
| 1832 | 1893 | names_map: OptionalMapIndex, |
| 1894 | captures: CaptureValue.Slice, |
| 1833 | 1895 | |
| 1834 | 1896 | pub const ComptimeBits = struct { |
| 1835 | 1897 | start: u32, |
| ... | ... | @@ -2162,10 +2224,26 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { |
| 2162 | 2224 | .comptime_bits = .{ .start = 0, .len = 0 }, |
| 2163 | 2225 | .offsets = .{ .start = 0, .len = 0 }, |
| 2164 | 2226 | .names_map = .none, |
| 2227 | .captures = .{ .start = 0, .len = 0 }, |
| 2165 | 2228 | }; |
| 2166 | 2229 | const extra = ip.extraDataTrail(Tag.TypeStruct, item.data); |
| 2167 | 2230 | const fields_len = extra.data.fields_len; |
| 2168 | | var extra_index = extra.end + fields_len; // skip field types |
| 2231 | var extra_index = extra.end; |
| 2232 | const captures_len = if (extra.data.flags.any_captures) c: { |
| 2233 | const len = ip.extra.items[extra_index]; |
| 2234 | extra_index += 1; |
| 2235 | break :c len; |
| 2236 | } else 0; |
| 2237 | const captures: CaptureValue.Slice = .{ |
| 2238 | .start = extra_index, |
| 2239 | .len = captures_len, |
| 2240 | }; |
| 2241 | extra_index += captures_len; |
| 2242 | const field_types: Index.Slice = .{ |
| 2243 | .start = extra_index, |
| 2244 | .len = fields_len, |
| 2245 | }; |
| 2246 | extra_index += fields_len; |
| 2169 | 2247 | const names_map: OptionalMapIndex, const names: NullTerminatedString.Slice = if (!extra.data.flags.is_tuple) n: { |
| 2170 | 2248 | const names_map: OptionalMapIndex = @enumFromInt(ip.extra.items[extra_index]); |
| 2171 | 2249 | extra_index += 1; |
| ... | ... | @@ -2211,42 +2289,64 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { |
| 2211 | 2289 | .zir_index = extra.data.zir_index, |
| 2212 | 2290 | .layout = if (extra.data.flags.is_extern) .Extern else .Auto, |
| 2213 | 2291 | .field_names = names, |
| 2214 | | .field_types = .{ .start = extra.end, .len = fields_len }, |
| 2292 | .field_types = field_types, |
| 2215 | 2293 | .field_inits = inits, |
| 2216 | 2294 | .field_aligns = aligns, |
| 2217 | 2295 | .runtime_order = runtime_order, |
| 2218 | 2296 | .comptime_bits = comptime_bits, |
| 2219 | 2297 | .offsets = offsets, |
| 2220 | 2298 | .names_map = names_map, |
| 2299 | .captures = captures, |
| 2221 | 2300 | }; |
| 2222 | 2301 | }, |
| 2223 | 2302 | .type_struct_packed, .type_struct_packed_inits => { |
| 2224 | 2303 | const extra = ip.extraDataTrail(Tag.TypeStructPacked, item.data); |
| 2225 | 2304 | const has_inits = item.tag == .type_struct_packed_inits; |
| 2226 | 2305 | const fields_len = extra.data.fields_len; |
| 2306 | var extra_index = extra.end; |
| 2307 | const captures_len = if (extra.data.flags.any_captures) c: { |
| 2308 | const len = ip.extra.items[extra_index]; |
| 2309 | extra_index += 1; |
| 2310 | break :c len; |
| 2311 | } else 0; |
| 2312 | const captures: CaptureValue.Slice = .{ |
| 2313 | .start = extra_index, |
| 2314 | .len = captures_len, |
| 2315 | }; |
| 2316 | extra_index += captures_len; |
| 2317 | const field_types: Index.Slice = .{ |
| 2318 | .start = extra_index, |
| 2319 | .len = fields_len, |
| 2320 | }; |
| 2321 | extra_index += fields_len; |
| 2322 | const field_names: NullTerminatedString.Slice = .{ |
| 2323 | .start = extra_index, |
| 2324 | .len = fields_len, |
| 2325 | }; |
| 2326 | extra_index += fields_len; |
| 2327 | const field_inits: Index.Slice = if (has_inits) inits: { |
| 2328 | const i: Index.Slice = .{ |
| 2329 | .start = extra_index, |
| 2330 | .len = fields_len, |
| 2331 | }; |
| 2332 | extra_index += fields_len; |
| 2333 | break :inits i; |
| 2334 | } else .{ .start = 0, .len = 0 }; |
| 2227 | 2335 | return .{ |
| 2228 | 2336 | .extra_index = item.data, |
| 2229 | 2337 | .decl = extra.data.decl.toOptional(), |
| 2230 | 2338 | .namespace = extra.data.namespace, |
| 2231 | 2339 | .zir_index = extra.data.zir_index, |
| 2232 | 2340 | .layout = .Packed, |
| 2233 | | .field_names = .{ |
| 2234 | | .start = extra.end + fields_len, |
| 2235 | | .len = fields_len, |
| 2236 | | }, |
| 2237 | | .field_types = .{ |
| 2238 | | .start = extra.end, |
| 2239 | | .len = fields_len, |
| 2240 | | }, |
| 2241 | | .field_inits = if (has_inits) .{ |
| 2242 | | .start = extra.end + 2 * fields_len, |
| 2243 | | .len = fields_len, |
| 2244 | | } else .{ .start = 0, .len = 0 }, |
| 2341 | .field_names = field_names, |
| 2342 | .field_types = field_types, |
| 2343 | .field_inits = field_inits, |
| 2245 | 2344 | .field_aligns = .{ .start = 0, .len = 0 }, |
| 2246 | 2345 | .runtime_order = .{ .start = 0, .len = 0 }, |
| 2247 | 2346 | .comptime_bits = .{ .start = 0, .len = 0 }, |
| 2248 | 2347 | .offsets = .{ .start = 0, .len = 0 }, |
| 2249 | 2348 | .names_map = extra.data.names_map.toOptional(), |
| 2349 | .captures = captures, |
| 2250 | 2350 | }; |
| 2251 | 2351 | }, |
| 2252 | 2352 | else => unreachable, |
| ... | ... | @@ -2273,6 +2373,7 @@ const LoadedEnumType = struct { |
| 2273 | 2373 | /// This is guaranteed to not be `.none` if explicit values are provided. |
| 2274 | 2374 | values_map: OptionalMapIndex, |
| 2275 | 2375 | zir_index: TrackedInst.Index.Optional, |
| 2376 | captures: CaptureValue.Slice, |
| 2276 | 2377 | |
| 2277 | 2378 | pub const TagMode = enum { |
| 2278 | 2379 | /// The integer tag type was auto-numbered by zig. |
| ... | ... | @@ -2332,7 +2433,7 @@ pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType { |
| 2332 | 2433 | .namespace = extra.data.namespace, |
| 2333 | 2434 | .tag_ty = extra.data.int_tag_type, |
| 2334 | 2435 | .names = .{ |
| 2335 | | .start = @intCast(extra.end), |
| 2436 | .start = @intCast(extra.end + extra.data.captures_len), |
| 2336 | 2437 | .len = extra.data.fields_len, |
| 2337 | 2438 | }, |
| 2338 | 2439 | .values = .{ .start = 0, .len = 0 }, |
| ... | ... | @@ -2340,6 +2441,10 @@ pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType { |
| 2340 | 2441 | .names_map = extra.data.names_map, |
| 2341 | 2442 | .values_map = .none, |
| 2342 | 2443 | .zir_index = extra.data.zir_index, |
| 2444 | .captures = .{ |
| 2445 | .start = @intCast(extra.end), |
| 2446 | .len = extra.data.captures_len, |
| 2447 | }, |
| 2343 | 2448 | }; |
| 2344 | 2449 | }, |
| 2345 | 2450 | .type_enum_explicit, .type_enum_nonexhaustive => { |
| ... | ... | @@ -2349,11 +2454,11 @@ pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType { |
| 2349 | 2454 | .namespace = extra.data.namespace, |
| 2350 | 2455 | .tag_ty = extra.data.int_tag_type, |
| 2351 | 2456 | .names = .{ |
| 2352 | | .start = @intCast(extra.end), |
| 2457 | .start = @intCast(extra.end + extra.data.captures_len), |
| 2353 | 2458 | .len = extra.data.fields_len, |
| 2354 | 2459 | }, |
| 2355 | 2460 | .values = .{ |
| 2356 | | .start = @intCast(extra.end + extra.data.fields_len), |
| 2461 | .start = @intCast(extra.end + extra.data.captures_len + extra.data.fields_len), |
| 2357 | 2462 | .len = if (extra.data.values_map != .none) extra.data.fields_len else 0, |
| 2358 | 2463 | }, |
| 2359 | 2464 | .tag_mode = switch (item.tag) { |
| ... | ... | @@ -2364,6 +2469,10 @@ pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType { |
| 2364 | 2469 | .names_map = extra.data.names_map, |
| 2365 | 2470 | .values_map = extra.data.values_map, |
| 2366 | 2471 | .zir_index = extra.data.zir_index, |
| 2472 | .captures = .{ |
| 2473 | .start = @intCast(extra.end), |
| 2474 | .len = extra.data.captures_len, |
| 2475 | }, |
| 2367 | 2476 | }; |
| 2368 | 2477 | }, |
| 2369 | 2478 | else => unreachable, |
| ... | ... | @@ -2378,12 +2487,22 @@ pub const LoadedOpaqueType = struct { |
| 2378 | 2487 | namespace: NamespaceIndex, |
| 2379 | 2488 | /// The index of the `opaque_decl` instruction. |
| 2380 | 2489 | zir_index: TrackedInst.Index.Optional, |
| 2490 | captures: CaptureValue.Slice, |
| 2381 | 2491 | }; |
| 2382 | 2492 | |
| 2383 | 2493 | pub fn loadOpaqueType(ip: *const InternPool, index: Index) LoadedOpaqueType { |
| 2384 | 2494 | assert(ip.items.items(.tag)[@intFromEnum(index)] == .type_opaque); |
| 2385 | 2495 | const extra_index = ip.items.items(.data)[@intFromEnum(index)]; |
| 2386 | | return ip.extraData(LoadedOpaqueType, extra_index); |
| 2496 | const extra = ip.extraDataTrail(Tag.TypeOpaque, extra_index); |
| 2497 | return .{ |
| 2498 | .decl = extra.data.decl, |
| 2499 | .namespace = extra.data.namespace, |
| 2500 | .zir_index = extra.data.zir_index, |
| 2501 | .captures = .{ |
| 2502 | .start = extra.end, |
| 2503 | .len = extra.data.captures_len, |
| 2504 | }, |
| 2505 | }; |
| 2387 | 2506 | } |
| 2388 | 2507 | |
| 2389 | 2508 | pub const Item = struct { |
| ... | ... | @@ -2601,7 +2720,7 @@ pub const Index = enum(u32) { |
| 2601 | 2720 | type_enum_explicit: DataIsExtraIndexOfEnumExplicit, |
| 2602 | 2721 | type_enum_nonexhaustive: DataIsExtraIndexOfEnumExplicit, |
| 2603 | 2722 | simple_type: struct { data: SimpleType }, |
| 2604 | | type_opaque: struct { data: *Key.OpaqueType }, |
| 2723 | type_opaque: struct { data: *Tag.TypeOpaque }, |
| 2605 | 2724 | type_struct: struct { data: *Tag.TypeStruct }, |
| 2606 | 2725 | type_struct_anon: DataIsExtraIndexOfTypeStructAnon, |
| 2607 | 2726 | type_struct_packed: struct { data: *Tag.TypeStructPacked }, |
| ... | ... | @@ -3036,7 +3155,7 @@ pub const Tag = enum(u8) { |
| 3036 | 3155 | /// data is SimpleType enum value. |
| 3037 | 3156 | simple_type, |
| 3038 | 3157 | /// An opaque type. |
| 3039 | | /// data is index of Key.OpaqueType in extra. |
| 3158 | /// data is index of Tag.TypeOpaque in extra. |
| 3040 | 3159 | type_opaque, |
| 3041 | 3160 | /// A non-packed struct type. |
| 3042 | 3161 | /// data is 0 or extra index of `TypeStruct`. |
| ... | ... | @@ -3239,7 +3358,6 @@ pub const Tag = enum(u8) { |
| 3239 | 3358 | memoized_call, |
| 3240 | 3359 | |
| 3241 | 3360 | const ErrorUnionType = Key.ErrorUnionType; |
| 3242 | | const OpaqueType = LoadedOpaqueType; |
| 3243 | 3361 | const TypeValue = Key.TypeValue; |
| 3244 | 3362 | const Error = Key.Error; |
| 3245 | 3363 | const EnumTag = Key.EnumTag; |
| ... | ... | @@ -3266,7 +3384,7 @@ pub const Tag = enum(u8) { |
| 3266 | 3384 | .type_enum_explicit => EnumExplicit, |
| 3267 | 3385 | .type_enum_nonexhaustive => EnumExplicit, |
| 3268 | 3386 | .simple_type => unreachable, |
| 3269 | | .type_opaque => OpaqueType, |
| 3387 | .type_opaque => TypeOpaque, |
| 3270 | 3388 | .type_struct => TypeStruct, |
| 3271 | 3389 | .type_struct_anon => TypeStructAnon, |
| 3272 | 3390 | .type_struct_packed, .type_struct_packed_inits => TypeStructPacked, |
| ... | ... | @@ -3424,8 +3542,10 @@ pub const Tag = enum(u8) { |
| 3424 | 3542 | }; |
| 3425 | 3543 | |
| 3426 | 3544 | /// Trailing: |
| 3427 | | /// 0. field type: Index for each field; declaration order |
| 3428 | | /// 1. field align: Alignment for each field; declaration order |
| 3545 | /// 0. captures_len: u32 // if `any_captures` |
| 3546 | /// 1. capture: CaptureValue // for each `captures_len` |
| 3547 | /// 2. field type: Index for each field; declaration order |
| 3548 | /// 3. field align: Alignment for each field; declaration order |
| 3429 | 3549 | pub const TypeUnion = struct { |
| 3430 | 3550 | flags: Flags, |
| 3431 | 3551 | /// This could be provided through the tag type, but it is more convenient |
| ... | ... | @@ -3443,6 +3563,7 @@ pub const Tag = enum(u8) { |
| 3443 | 3563 | zir_index: TrackedInst.Index.Optional, |
| 3444 | 3564 | |
| 3445 | 3565 | pub const Flags = packed struct(u32) { |
| 3566 | any_captures: bool, |
| 3446 | 3567 | runtime_tag: LoadedUnionType.RuntimeTag, |
| 3447 | 3568 | /// If false, the field alignment trailing data is omitted. |
| 3448 | 3569 | any_aligned_fields: bool, |
| ... | ... | @@ -3452,14 +3573,16 @@ pub const Tag = enum(u8) { |
| 3452 | 3573 | assumed_runtime_bits: bool, |
| 3453 | 3574 | assumed_pointer_aligned: bool, |
| 3454 | 3575 | alignment: Alignment, |
| 3455 | | _: u14 = 0, |
| 3576 | _: u13 = 0, |
| 3456 | 3577 | }; |
| 3457 | 3578 | }; |
| 3458 | 3579 | |
| 3459 | 3580 | /// Trailing: |
| 3460 | | /// 0. type: Index for each fields_len |
| 3461 | | /// 1. name: NullTerminatedString for each fields_len |
| 3462 | | /// 2. init: Index for each fields_len // if tag is type_struct_packed_inits |
| 3581 | /// 0. captures_len: u32 // if `any_captures` |
| 3582 | /// 1. capture: CaptureValue // for each `captures_len` |
| 3583 | /// 2. type: Index for each fields_len |
| 3584 | /// 3. name: NullTerminatedString for each fields_len |
| 3585 | /// 4. init: Index for each fields_len // if tag is type_struct_packed_inits |
| 3463 | 3586 | pub const TypeStructPacked = struct { |
| 3464 | 3587 | decl: DeclIndex, |
| 3465 | 3588 | zir_index: TrackedInst.Index.Optional, |
| ... | ... | @@ -3470,10 +3593,11 @@ pub const Tag = enum(u8) { |
| 3470 | 3593 | flags: Flags, |
| 3471 | 3594 | |
| 3472 | 3595 | pub const Flags = packed struct(u32) { |
| 3596 | any_captures: bool, |
| 3473 | 3597 | /// Dependency loop detection when resolving field inits. |
| 3474 | 3598 | field_inits_wip: bool, |
| 3475 | 3599 | inits_resolved: bool, |
| 3476 | | _: u30 = 0, |
| 3600 | _: u29 = 0, |
| 3477 | 3601 | }; |
| 3478 | 3602 | }; |
| 3479 | 3603 | |
| ... | ... | @@ -3492,21 +3616,23 @@ pub const Tag = enum(u8) { |
| 3492 | 3616 | /// than coming up with some other scheme for the data. |
| 3493 | 3617 | /// |
| 3494 | 3618 | /// Trailing: |
| 3495 | | /// 0. type: Index for each field in declared order |
| 3496 | | /// 1. if not is_tuple: |
| 3619 | /// 0. captures_len: u32 // if `any_captures` |
| 3620 | /// 1. capture: CaptureValue // for each `captures_len` |
| 3621 | /// 2. type: Index for each field in declared order |
| 3622 | /// 3. if not is_tuple: |
| 3497 | 3623 | /// names_map: MapIndex, |
| 3498 | 3624 | /// name: NullTerminatedString // for each field in declared order |
| 3499 | | /// 2. if any_default_inits: |
| 3625 | /// 4. if any_default_inits: |
| 3500 | 3626 | /// init: Index // for each field in declared order |
| 3501 | | /// 3. if has_namespace: |
| 3627 | /// 5. if has_namespace: |
| 3502 | 3628 | /// namespace: NamespaceIndex |
| 3503 | | /// 4. if any_aligned_fields: |
| 3629 | /// 6. if any_aligned_fields: |
| 3504 | 3630 | /// align: Alignment // for each field in declared order |
| 3505 | | /// 5. if any_comptime_fields: |
| 3631 | /// 7. if any_comptime_fields: |
| 3506 | 3632 | /// field_is_comptime_bits: u32 // minimal number of u32s needed, LSB is field 0 |
| 3507 | | /// 6. if not is_extern: |
| 3633 | /// 8. if not is_extern: |
| 3508 | 3634 | /// field_index: RuntimeOrder // for each field in runtime order |
| 3509 | | /// 7. field_offset: u32 // for each field in declared order, undef until layout_resolved |
| 3635 | /// 9. field_offset: u32 // for each field in declared order, undef until layout_resolved |
| 3510 | 3636 | pub const TypeStruct = struct { |
| 3511 | 3637 | decl: DeclIndex, |
| 3512 | 3638 | zir_index: TrackedInst.Index.Optional, |
| ... | ... | @@ -3515,6 +3641,7 @@ pub const Tag = enum(u8) { |
| 3515 | 3641 | size: u32, |
| 3516 | 3642 | |
| 3517 | 3643 | pub const Flags = packed struct(u32) { |
| 3644 | any_captures: bool, |
| 3518 | 3645 | is_extern: bool, |
| 3519 | 3646 | known_non_opv: bool, |
| 3520 | 3647 | requires_comptime: RequiresComptime, |
| ... | ... | @@ -3544,9 +3671,21 @@ pub const Tag = enum(u8) { |
| 3544 | 3671 | // which `layout_resolved` does not ensure. |
| 3545 | 3672 | fully_resolved: bool, |
| 3546 | 3673 | |
| 3547 | | _: u8 = 0, |
| 3674 | _: u7 = 0, |
| 3548 | 3675 | }; |
| 3549 | 3676 | }; |
| 3677 | |
| 3678 | /// Trailing: |
| 3679 | /// 0. capture: CaptureValue // for each `captures_len` |
| 3680 | pub const TypeOpaque = struct { |
| 3681 | /// The opaque's owner Decl. |
| 3682 | decl: DeclIndex, |
| 3683 | /// Contains the declarations inside this opaque. |
| 3684 | namespace: NamespaceIndex, |
| 3685 | /// The index of the `opaque_decl` instruction. |
| 3686 | zir_index: TrackedInst.Index.Optional, |
| 3687 | captures_len: u32, |
| 3688 | }; |
| 3550 | 3689 | }; |
| 3551 | 3690 | |
| 3552 | 3691 | /// State that is mutable during semantic analysis. This data is not used for |
| ... | ... | @@ -3853,11 +3992,13 @@ pub const Array = struct { |
| 3853 | 3992 | }; |
| 3854 | 3993 | |
| 3855 | 3994 | /// Trailing: |
| 3856 | | /// 0. field name: NullTerminatedString for each fields_len; declaration order |
| 3857 | | /// 1. tag value: Index for each fields_len; declaration order |
| 3995 | /// 0. capture: CaptureValue // for each `captures_len` |
| 3996 | /// 1. field name: NullTerminatedString for each fields_len; declaration order |
| 3997 | /// 2. tag value: Index for each fields_len; declaration order |
| 3858 | 3998 | pub const EnumExplicit = struct { |
| 3859 | 3999 | /// The Decl that corresponds to the enum itself. |
| 3860 | 4000 | decl: DeclIndex, |
| 4001 | captures_len: u32, |
| 3861 | 4002 | /// This may be `none` if there are no declarations. |
| 3862 | 4003 | namespace: OptionalNamespaceIndex, |
| 3863 | 4004 | /// An integer type which is used for the numerical value of the enum, which |
| ... | ... | @@ -3874,10 +4015,12 @@ pub const EnumExplicit = struct { |
| 3874 | 4015 | }; |
| 3875 | 4016 | |
| 3876 | 4017 | /// Trailing: |
| 3877 | | /// 0. field name: NullTerminatedString for each fields_len; declaration order |
| 4018 | /// 0. capture: CaptureValue // for each `captures_len` |
| 4019 | /// 1. field name: NullTerminatedString for each fields_len; declaration order |
| 3878 | 4020 | pub const EnumAuto = struct { |
| 3879 | 4021 | /// The Decl that corresponds to the enum itself. |
| 3880 | 4022 | decl: DeclIndex, |
| 4023 | captures_len: u32, |
| 3881 | 4024 | /// This may be `none` if there are no declarations. |
| 3882 | 4025 | namespace: OptionalNamespaceIndex, |
| 3883 | 4026 | /// An integer type which is used for the numerical value of the enum, which |
| ... | ... | @@ -4187,7 +4330,9 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 4187 | 4330 | .inferred_error_set_type = @enumFromInt(data), |
| 4188 | 4331 | }, |
| 4189 | 4332 | |
| 4190 | | .type_opaque => .{ .opaque_type = ip.extraData(Key.OpaqueType, data) }, |
| 4333 | .type_opaque => .{ .opaque_type = .{ |
| 4334 | .decl = ip.extraData(Tag.TypeOpaque, data).decl, |
| 4335 | } }, |
| 4191 | 4336 | |
| 4192 | 4337 | .type_struct => .{ .struct_type = if (data == 0) .{ |
| 4193 | 4338 | .decl = .none, |
| ... | ... | @@ -5497,7 +5642,16 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 5497 | 5642 | } |
| 5498 | 5643 | |
| 5499 | 5644 | pub const UnionTypeInit = struct { |
| 5500 | | flags: Tag.TypeUnion.Flags, |
| 5645 | flags: packed struct { |
| 5646 | runtime_tag: LoadedUnionType.RuntimeTag, |
| 5647 | any_aligned_fields: bool, |
| 5648 | layout: std.builtin.Type.ContainerLayout, |
| 5649 | status: LoadedUnionType.Status, |
| 5650 | requires_comptime: RequiresComptime, |
| 5651 | assumed_runtime_bits: bool, |
| 5652 | assumed_pointer_aligned: bool, |
| 5653 | alignment: Alignment, |
| 5654 | }, |
| 5501 | 5655 | decl: DeclIndex, |
| 5502 | 5656 | namespace: NamespaceIndex, |
| 5503 | 5657 | zir_index: TrackedInst.Index.Optional, |
| ... | ... | @@ -5509,6 +5663,7 @@ pub const UnionTypeInit = struct { |
| 5509 | 5663 | /// The logic for `any_aligned_fields` is asserted to have been done before |
| 5510 | 5664 | /// calling this function. |
| 5511 | 5665 | field_aligns: []const Alignment, |
| 5666 | captures: []const CaptureValue, |
| 5512 | 5667 | }; |
| 5513 | 5668 | |
| 5514 | 5669 | pub fn getUnionType(ip: *InternPool, gpa: Allocator, ini: UnionTypeInit) Allocator.Error!Index { |
| ... | ... | @@ -5516,12 +5671,24 @@ pub fn getUnionType(ip: *InternPool, gpa: Allocator, ini: UnionTypeInit) Allocat |
| 5516 | 5671 | const align_elements_len = if (ini.flags.any_aligned_fields) (ini.fields_len + 3) / 4 else 0; |
| 5517 | 5672 | const align_element: u32 = @bitCast([1]u8{@intFromEnum(Alignment.none)} ** 4); |
| 5518 | 5673 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.TypeUnion).Struct.fields.len + |
| 5674 | @intFromBool(ini.captures.len != 0) + // captures_len |
| 5675 | ini.captures.len + // captures |
| 5519 | 5676 | ini.fields_len + // field types |
| 5520 | 5677 | align_elements_len); |
| 5521 | 5678 | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 5522 | 5679 | |
| 5523 | 5680 | const union_type_extra_index = ip.addExtraAssumeCapacity(Tag.TypeUnion{ |
| 5524 | | .flags = ini.flags, |
| 5681 | .flags = .{ |
| 5682 | .any_captures = ini.captures.len != 0, |
| 5683 | .runtime_tag = ini.flags.runtime_tag, |
| 5684 | .any_aligned_fields = ini.flags.any_aligned_fields, |
| 5685 | .layout = ini.flags.layout, |
| 5686 | .status = ini.flags.status, |
| 5687 | .requires_comptime = ini.flags.requires_comptime, |
| 5688 | .assumed_runtime_bits = ini.flags.assumed_runtime_bits, |
| 5689 | .assumed_pointer_aligned = ini.flags.assumed_pointer_aligned, |
| 5690 | .alignment = ini.flags.alignment, |
| 5691 | }, |
| 5525 | 5692 | .fields_len = ini.fields_len, |
| 5526 | 5693 | .size = std.math.maxInt(u32), |
| 5527 | 5694 | .padding = std.math.maxInt(u32), |
| ... | ... | @@ -5531,6 +5698,11 @@ pub fn getUnionType(ip: *InternPool, gpa: Allocator, ini: UnionTypeInit) Allocat |
| 5531 | 5698 | .zir_index = ini.zir_index, |
| 5532 | 5699 | }); |
| 5533 | 5700 | |
| 5701 | if (ini.captures.len != 0) { |
| 5702 | ip.extra.appendAssumeCapacity(@intCast(ini.captures.len)); |
| 5703 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.captures)); |
| 5704 | } |
| 5705 | |
| 5534 | 5706 | // field types |
| 5535 | 5707 | if (ini.field_types.len > 0) { |
| 5536 | 5708 | assert(ini.field_types.len == ini.fields_len); |
| ... | ... | @@ -5582,6 +5754,7 @@ pub const StructTypeInit = struct { |
| 5582 | 5754 | any_default_inits: bool, |
| 5583 | 5755 | inits_resolved: bool, |
| 5584 | 5756 | any_aligned_fields: bool, |
| 5757 | captures: []const CaptureValue, |
| 5585 | 5758 | }; |
| 5586 | 5759 | |
| 5587 | 5760 | pub fn getStructType( |
| ... | ... | @@ -5605,6 +5778,8 @@ pub fn getStructType( |
| 5605 | 5778 | .Extern => true, |
| 5606 | 5779 | .Packed => { |
| 5607 | 5780 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.TypeStructPacked).Struct.fields.len + |
| 5781 | @intFromBool(ini.captures.len != 0) + // captures_len |
| 5782 | ini.captures.len + // captures |
| 5608 | 5783 | ini.fields_len + // types |
| 5609 | 5784 | ini.fields_len + // names |
| 5610 | 5785 | ini.fields_len); // inits |
| ... | ... | @@ -5618,11 +5793,16 @@ pub fn getStructType( |
| 5618 | 5793 | .backing_int_ty = .none, |
| 5619 | 5794 | .names_map = names_map, |
| 5620 | 5795 | .flags = .{ |
| 5796 | .any_captures = ini.captures.len != 0, |
| 5621 | 5797 | .field_inits_wip = false, |
| 5622 | 5798 | .inits_resolved = ini.inits_resolved, |
| 5623 | 5799 | }, |
| 5624 | 5800 | }), |
| 5625 | 5801 | }); |
| 5802 | if (ini.captures.len != 0) { |
| 5803 | ip.extra.appendAssumeCapacity(@intCast(ini.captures.len)); |
| 5804 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.captures)); |
| 5805 | } |
| 5626 | 5806 | ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), ini.fields_len); |
| 5627 | 5807 | ip.extra.appendNTimesAssumeCapacity(@intFromEnum(OptionalNullTerminatedString.none), ini.fields_len); |
| 5628 | 5808 | if (ini.any_default_inits) { |
| ... | ... | @@ -5637,6 +5817,8 @@ pub fn getStructType( |
| 5637 | 5817 | const comptime_elements_len = if (ini.any_comptime_fields) (ini.fields_len + 31) / 32 else 0; |
| 5638 | 5818 | |
| 5639 | 5819 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.TypeStruct).Struct.fields.len + |
| 5820 | @intFromBool(ini.captures.len != 0) + // captures_len |
| 5821 | ini.captures.len + // captures |
| 5640 | 5822 | (ini.fields_len * 5) + // types, names, inits, runtime order, offsets |
| 5641 | 5823 | align_elements_len + comptime_elements_len + |
| 5642 | 5824 | 2); // names_map + namespace |
| ... | ... | @@ -5648,6 +5830,7 @@ pub fn getStructType( |
| 5648 | 5830 | .fields_len = ini.fields_len, |
| 5649 | 5831 | .size = std.math.maxInt(u32), |
| 5650 | 5832 | .flags = .{ |
| 5833 | .any_captures = ini.captures.len != 0, |
| 5651 | 5834 | .is_extern = is_extern, |
| 5652 | 5835 | .known_non_opv = ini.known_non_opv, |
| 5653 | 5836 | .requires_comptime = ini.requires_comptime, |
| ... | ... | @@ -5669,6 +5852,10 @@ pub fn getStructType( |
| 5669 | 5852 | }, |
| 5670 | 5853 | }), |
| 5671 | 5854 | }); |
| 5855 | if (ini.captures.len != 0) { |
| 5856 | ip.extra.appendAssumeCapacity(@intCast(ini.captures.len)); |
| 5857 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.captures)); |
| 5858 | } |
| 5672 | 5859 | ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), ini.fields_len); |
| 5673 | 5860 | if (!ini.is_tuple) { |
| 5674 | 5861 | ip.extra.appendAssumeCapacity(@intFromEnum(names_map)); |
| ... | ... | @@ -6405,11 +6592,12 @@ fn getIncompleteEnumAuto( |
| 6405 | 6592 | const names_map = try ip.addMap(gpa, enum_type.fields_len); |
| 6406 | 6593 | |
| 6407 | 6594 | const extra_fields_len: u32 = @typeInfo(EnumAuto).Struct.fields.len; |
| 6408 | | try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + enum_type.fields_len); |
| 6595 | try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + enum_type.captures.len + enum_type.fields_len); |
| 6409 | 6596 | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 6410 | 6597 | |
| 6411 | 6598 | const extra_index = ip.addExtraAssumeCapacity(EnumAuto{ |
| 6412 | 6599 | .decl = enum_type.decl, |
| 6600 | .captures_len = @intCast(enum_type.captures.len), |
| 6413 | 6601 | .namespace = enum_type.namespace, |
| 6414 | 6602 | .int_tag_type = int_tag_type, |
| 6415 | 6603 | .names_map = names_map, |
| ... | ... | @@ -6421,6 +6609,7 @@ fn getIncompleteEnumAuto( |
| 6421 | 6609 | .tag = .type_enum_auto, |
| 6422 | 6610 | .data = extra_index, |
| 6423 | 6611 | }); |
| 6612 | ip.extra.appendSliceAssumeCapacity(@ptrCast(enum_type.captures)); |
| 6424 | 6613 | ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), enum_type.fields_len); |
| 6425 | 6614 | return .{ |
| 6426 | 6615 | .index = @enumFromInt(ip.items.len - 1), |
| ... | ... | @@ -6455,11 +6644,12 @@ fn getIncompleteEnumExplicit( |
| 6455 | 6644 | if (enum_type.has_values) enum_type.fields_len else 0; |
| 6456 | 6645 | |
| 6457 | 6646 | const extra_fields_len: u32 = @typeInfo(EnumExplicit).Struct.fields.len; |
| 6458 | | try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + reserved_len); |
| 6647 | try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + enum_type.captures.len + reserved_len); |
| 6459 | 6648 | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 6460 | 6649 | |
| 6461 | 6650 | const extra_index = ip.addExtraAssumeCapacity(EnumExplicit{ |
| 6462 | 6651 | .decl = enum_type.decl, |
| 6652 | .captures_len = @intCast(enum_type.captures.len), |
| 6463 | 6653 | .namespace = enum_type.namespace, |
| 6464 | 6654 | .int_tag_type = enum_type.tag_ty, |
| 6465 | 6655 | .fields_len = enum_type.fields_len, |
| ... | ... | @@ -6472,6 +6662,7 @@ fn getIncompleteEnumExplicit( |
| 6472 | 6662 | .tag = tag, |
| 6473 | 6663 | .data = extra_index, |
| 6474 | 6664 | }); |
| 6665 | ip.extra.appendSliceAssumeCapacity(@ptrCast(enum_type.captures)); |
| 6475 | 6666 | // This is both fields and values (if present). |
| 6476 | 6667 | ip.extra.appendNTimesAssumeCapacity(@intFromEnum(Index.none), reserved_len); |
| 6477 | 6668 | return .{ |
| ... | ... | @@ -6492,6 +6683,7 @@ pub const GetEnumInit = struct { |
| 6492 | 6683 | values: []const Index, |
| 6493 | 6684 | tag_mode: LoadedEnumType.TagMode, |
| 6494 | 6685 | zir_index: TrackedInst.Index.Optional, |
| 6686 | captures: []const CaptureValue, |
| 6495 | 6687 | }; |
| 6496 | 6688 | |
| 6497 | 6689 | pub fn getEnum(ip: *InternPool, gpa: Allocator, ini: GetEnumInit) Allocator.Error!Index { |
| ... | ... | @@ -6513,11 +6705,12 @@ pub fn getEnum(ip: *InternPool, gpa: Allocator, ini: GetEnumInit) Allocator.Erro |
| 6513 | 6705 | |
| 6514 | 6706 | const fields_len: u32 = @intCast(ini.names.len); |
| 6515 | 6707 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumAuto).Struct.fields.len + |
| 6516 | | fields_len); |
| 6708 | ini.captures.len + fields_len); |
| 6517 | 6709 | ip.items.appendAssumeCapacity(.{ |
| 6518 | 6710 | .tag = .type_enum_auto, |
| 6519 | 6711 | .data = ip.addExtraAssumeCapacity(EnumAuto{ |
| 6520 | 6712 | .decl = ini.decl, |
| 6713 | .captures_len = @intCast(ini.captures.len), |
| 6521 | 6714 | .namespace = ini.namespace, |
| 6522 | 6715 | .int_tag_type = ini.tag_ty, |
| 6523 | 6716 | .names_map = names_map, |
| ... | ... | @@ -6525,6 +6718,7 @@ pub fn getEnum(ip: *InternPool, gpa: Allocator, ini: GetEnumInit) Allocator.Erro |
| 6525 | 6718 | .zir_index = ini.zir_index, |
| 6526 | 6719 | }), |
| 6527 | 6720 | }); |
| 6721 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.captures)); |
| 6528 | 6722 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.names)); |
| 6529 | 6723 | return @enumFromInt(ip.items.len - 1); |
| 6530 | 6724 | }, |
| ... | ... | @@ -6533,7 +6727,7 @@ pub fn getEnum(ip: *InternPool, gpa: Allocator, ini: GetEnumInit) Allocator.Erro |
| 6533 | 6727 | } |
| 6534 | 6728 | } |
| 6535 | 6729 | |
| 6536 | | pub fn finishGetEnum( |
| 6730 | fn finishGetEnum( |
| 6537 | 6731 | ip: *InternPool, |
| 6538 | 6732 | gpa: Allocator, |
| 6539 | 6733 | ini: GetEnumInit, |
| ... | ... | @@ -6549,11 +6743,12 @@ pub fn finishGetEnum( |
| 6549 | 6743 | }; |
| 6550 | 6744 | const fields_len: u32 = @intCast(ini.names.len); |
| 6551 | 6745 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumExplicit).Struct.fields.len + |
| 6552 | | fields_len); |
| 6746 | ini.captures.len + fields_len); |
| 6553 | 6747 | ip.items.appendAssumeCapacity(.{ |
| 6554 | 6748 | .tag = tag, |
| 6555 | 6749 | .data = ip.addExtraAssumeCapacity(EnumExplicit{ |
| 6556 | 6750 | .decl = ini.decl, |
| 6751 | .captures_len = @intCast(ini.captures.len), |
| 6557 | 6752 | .namespace = ini.namespace, |
| 6558 | 6753 | .int_tag_type = ini.tag_ty, |
| 6559 | 6754 | .fields_len = fields_len, |
| ... | ... | @@ -6562,23 +6757,37 @@ pub fn finishGetEnum( |
| 6562 | 6757 | .zir_index = ini.zir_index, |
| 6563 | 6758 | }), |
| 6564 | 6759 | }); |
| 6760 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.captures)); |
| 6565 | 6761 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.names)); |
| 6566 | 6762 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.values)); |
| 6567 | 6763 | return @enumFromInt(ip.items.len - 1); |
| 6568 | 6764 | } |
| 6569 | 6765 | |
| 6570 | | pub fn getOpaqueType(ip: *InternPool, gpa: Allocator, key: LoadedOpaqueType) Allocator.Error!Index { |
| 6766 | pub const OpaqueTypeIni = struct { |
| 6767 | decl: DeclIndex, |
| 6768 | namespace: NamespaceIndex, |
| 6769 | zir_index: TrackedInst.Index.Optional, |
| 6770 | captures: []const CaptureValue, |
| 6771 | }; |
| 6772 | |
| 6773 | pub fn getOpaqueType(ip: *InternPool, gpa: Allocator, ini: OpaqueTypeIni) Allocator.Error!Index { |
| 6571 | 6774 | const adapter: KeyAdapter = .{ .intern_pool = ip }; |
| 6572 | | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(LoadedOpaqueType).Struct.fields.len); |
| 6775 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(LoadedOpaqueType).Struct.fields.len + ini.captures.len); |
| 6573 | 6776 | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 6574 | 6777 | const gop = try ip.map.getOrPutAdapted(gpa, Key{ |
| 6575 | | .opaque_type = .{ .decl = key.decl }, |
| 6778 | .opaque_type = .{ .decl = ini.decl }, |
| 6576 | 6779 | }, adapter); |
| 6577 | 6780 | if (gop.found_existing) return @enumFromInt(gop.index); |
| 6578 | 6781 | ip.items.appendAssumeCapacity(.{ |
| 6579 | 6782 | .tag = .type_opaque, |
| 6580 | | .data = ip.addExtraAssumeCapacity(key), |
| 6783 | .data = ip.addExtraAssumeCapacity(Tag.TypeOpaque{ |
| 6784 | .decl = ini.decl, |
| 6785 | .namespace = ini.namespace, |
| 6786 | .zir_index = ini.zir_index, |
| 6787 | .captures_len = @intCast(ini.captures.len), |
| 6788 | }), |
| 6581 | 6789 | }); |
| 6790 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.captures)); |
| 6582 | 6791 | return @enumFromInt(gop.index); |
| 6583 | 6792 | } |
| 6584 | 6793 | |
| ... | ... | @@ -7442,12 +7651,31 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 7442 | 7651 | break :b @sizeOf(Tag.ErrorSet) + (@sizeOf(u32) * info.names_len); |
| 7443 | 7652 | }, |
| 7444 | 7653 | .type_inferred_error_set => 0, |
| 7445 | | .type_enum_explicit, .type_enum_nonexhaustive => @sizeOf(EnumExplicit), |
| 7446 | | .type_enum_auto => @sizeOf(EnumAuto), |
| 7447 | | .type_opaque => @sizeOf(Key.OpaqueType), |
| 7654 | .type_enum_explicit, .type_enum_nonexhaustive => b: { |
| 7655 | const info = ip.extraData(EnumExplicit, data); |
| 7656 | var ints = @typeInfo(EnumExplicit).Struct.fields.len + info.captures_len + info.fields_len; |
| 7657 | if (info.values_map != .none) ints += info.fields_len; |
| 7658 | break :b @sizeOf(u32) * ints; |
| 7659 | }, |
| 7660 | .type_enum_auto => b: { |
| 7661 | const info = ip.extraData(EnumAuto, data); |
| 7662 | const ints = @typeInfo(EnumAuto).Struct.fields.len + info.captures_len + info.fields_len; |
| 7663 | break :b @sizeOf(u32) * ints; |
| 7664 | }, |
| 7665 | .type_opaque => b: { |
| 7666 | const info = ip.extraData(Tag.TypeOpaque, data); |
| 7667 | const ints = @typeInfo(Tag.TypeOpaque).Struct.fields.len + info.captures_len; |
| 7668 | break :b @sizeOf(u32) * ints; |
| 7669 | }, |
| 7448 | 7670 | .type_struct => b: { |
| 7449 | | const info = ip.extraData(Tag.TypeStruct, data); |
| 7671 | if (data == 0) break :b 0; |
| 7672 | const extra = ip.extraDataTrail(Tag.TypeStruct, data); |
| 7673 | const info = extra.data; |
| 7450 | 7674 | var ints: usize = @typeInfo(Tag.TypeStruct).Struct.fields.len; |
| 7675 | if (info.flags.any_captures) { |
| 7676 | const captures_len = ip.extra.items[extra.end]; |
| 7677 | ints += 1 + captures_len; |
| 7678 | } |
| 7451 | 7679 | ints += info.fields_len; // types |
| 7452 | 7680 | if (!info.flags.is_tuple) { |
| 7453 | 7681 | ints += 1; // names_map |
| ... | ... | @@ -7470,14 +7698,24 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 7470 | 7698 | break :b @sizeOf(TypeStructAnon) + (@sizeOf(u32) * 3 * info.fields_len); |
| 7471 | 7699 | }, |
| 7472 | 7700 | .type_struct_packed => b: { |
| 7473 | | const info = ip.extraData(Tag.TypeStructPacked, data); |
| 7701 | const extra = ip.extraDataTrail(Tag.TypeStructPacked, data); |
| 7702 | const captures_len = if (extra.data.flags.any_captures) |
| 7703 | ip.extra.items[extra.end] |
| 7704 | else |
| 7705 | 0; |
| 7474 | 7706 | break :b @sizeOf(u32) * (@typeInfo(Tag.TypeStructPacked).Struct.fields.len + |
| 7475 | | info.fields_len + info.fields_len); |
| 7707 | @intFromBool(extra.data.flags.any_captures) + captures_len + |
| 7708 | extra.data.fields_len * 2); |
| 7476 | 7709 | }, |
| 7477 | 7710 | .type_struct_packed_inits => b: { |
| 7478 | | const info = ip.extraData(Tag.TypeStructPacked, data); |
| 7711 | const extra = ip.extraDataTrail(Tag.TypeStructPacked, data); |
| 7712 | const captures_len = if (extra.data.flags.any_captures) |
| 7713 | ip.extra.items[extra.end] |
| 7714 | else |
| 7715 | 0; |
| 7479 | 7716 | break :b @sizeOf(u32) * (@typeInfo(Tag.TypeStructPacked).Struct.fields.len + |
| 7480 | | info.fields_len + info.fields_len + info.fields_len); |
| 7717 | @intFromBool(extra.data.flags.any_captures) + captures_len + |
| 7718 | extra.data.fields_len * 3); |
| 7481 | 7719 | }, |
| 7482 | 7720 | .type_tuple_anon => b: { |
| 7483 | 7721 | const info = ip.extraData(TypeStructAnon, data); |
| ... | ... | @@ -7485,16 +7723,20 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 7485 | 7723 | }, |
| 7486 | 7724 | |
| 7487 | 7725 | .type_union => b: { |
| 7488 | | const info = ip.extraData(Tag.TypeUnion, data); |
| 7489 | | const enum_info = ip.loadEnumType(info.tag_ty); |
| 7490 | | const fields_len: u32 = @intCast(enum_info.names.len); |
| 7726 | const extra = ip.extraDataTrail(Tag.TypeUnion, data); |
| 7727 | const captures_len = if (extra.data.flags.any_captures) |
| 7728 | ip.extra.items[extra.end] |
| 7729 | else |
| 7730 | 0; |
| 7491 | 7731 | const per_field = @sizeOf(u32); // field type |
| 7492 | 7732 | // 1 byte per field for alignment, rounded up to the nearest 4 bytes |
| 7493 | | const alignments = if (info.flags.any_aligned_fields) |
| 7494 | | ((fields_len + 3) / 4) * 4 |
| 7733 | const alignments = if (extra.data.flags.any_aligned_fields) |
| 7734 | ((extra.data.fields_len + 3) / 4) * 4 |
| 7495 | 7735 | else |
| 7496 | 7736 | 0; |
| 7497 | | break :b @sizeOf(Tag.TypeUnion) + (fields_len * per_field) + alignments; |
| 7737 | break :b @sizeOf(Tag.TypeUnion) + |
| 7738 | 4 * (@intFromBool(extra.data.flags.any_captures) + captures_len) + |
| 7739 | (extra.data.fields_len * per_field) + alignments; |
| 7498 | 7740 | }, |
| 7499 | 7741 | |
| 7500 | 7742 | .type_function => b: { |
| ... | ... | @@ -7802,7 +8044,6 @@ pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex) |
| 7802 | 8044 | .parent = undefined, |
| 7803 | 8045 | .file_scope = undefined, |
| 7804 | 8046 | .decl_index = undefined, |
| 7805 | | .captures = undefined, |
| 7806 | 8047 | }; |
| 7807 | 8048 | ip.namespaces_free_list.append(gpa, index) catch { |
| 7808 | 8049 | // In order to keep `destroyNamespace` a non-fallible function, we ignore memory |