| author | |
| committer | |
| log | 153e7d6235a7d74d0c02d51f84edc5c06ab7469d |
| tree | c4b372662b0253de33483225d17a8a79c735ada5 |
| parent | 548a087fafeda5b07d2237d5137906b8d07da699 |
| signature |
Eliding the namespace when a container type has no decls was an
experiment in saving memory, but it ended up causing more trouble than
it was worth in various places. So, take the small memory hit for
reified types, and just give every container type a namespace.5 files changed, 156 insertions(+), 205 deletions(-)
src/InternPool.zig+55-76| ... | @@ -2885,7 +2885,7 @@ pub const LoadedUnionType = struct { | ... | @@ -2885,7 +2885,7 @@ pub const LoadedUnionType = struct { |
| 2885 | /// The `Cau` within which type resolution occurs. | 2885 | /// The `Cau` within which type resolution occurs. |
| 2886 | cau: Cau.Index, | 2886 | cau: Cau.Index, |
| 2887 | /// Represents the declarations inside this union. | 2887 | /// Represents the declarations inside this union. |
| 2888 | namespace: OptionalNamespaceIndex, | 2888 | namespace: NamespaceIndex, |
| 2889 | /// The enum tag type. | 2889 | /// The enum tag type. |
| 2890 | enum_tag_ty: Index, | 2890 | enum_tag_ty: Index, |
| 2891 | /// List of field types in declaration order. | 2891 | /// List of field types in declaration order. |
| ... | @@ -3219,7 +3219,7 @@ pub const LoadedStructType = struct { | ... | @@ -3219,7 +3219,7 @@ pub const LoadedStructType = struct { |
| 3219 | name: NullTerminatedString, | 3219 | name: NullTerminatedString, |
| 3220 | /// The `Cau` within which type resolution occurs. `none` when the struct is `@TypeOf(.{})`. | 3220 | /// The `Cau` within which type resolution occurs. `none` when the struct is `@TypeOf(.{})`. |
| 3221 | cau: Cau.Index.Optional, | 3221 | cau: Cau.Index.Optional, |
| 3222 | /// `none` when the struct has no declarations. | 3222 | /// `none` when the struct is `@TypeOf(.{})`. |
| 3223 | namespace: OptionalNamespaceIndex, | 3223 | namespace: OptionalNamespaceIndex, |
| 3224 | /// Index of the `struct_decl` or `reify` ZIR instruction. | 3224 | /// Index of the `struct_decl` or `reify` ZIR instruction. |
| 3225 | /// Only `none` when the struct is `@TypeOf(.{})`. | 3225 | /// Only `none` when the struct is `@TypeOf(.{})`. |
| ... | @@ -3834,6 +3834,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { | ... | @@ -3834,6 +3834,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { |
| 3834 | }; | 3834 | }; |
| 3835 | const name: NullTerminatedString = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "name").?]); | 3835 | const name: NullTerminatedString = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "name").?]); |
| 3836 | const cau: Cau.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "cau").?]); | 3836 | const cau: Cau.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "cau").?]); |
| 3837 | const namespace: NamespaceIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "namespace").?]); | ||
| 3837 | const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]); | 3838 | const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]); |
| 3838 | const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "fields_len").?]; | 3839 | const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "fields_len").?]; |
| 3839 | const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .unordered)); | 3840 | const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .unordered)); |
| ... | @@ -3878,11 +3879,6 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { | ... | @@ -3878,11 +3879,6 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { |
| 3878 | extra_index += fields_len; | 3879 | extra_index += fields_len; |
| 3879 | break :i inits; | 3880 | break :i inits; |
| 3880 | } else Index.Slice.empty; | 3881 | } else Index.Slice.empty; |
| 3881 | const namespace: OptionalNamespaceIndex = if (flags.has_namespace) n: { | ||
| 3882 | const n: NamespaceIndex = @enumFromInt(extra_list.view().items(.@"0")[extra_index]); | ||
| 3883 | extra_index += 1; | ||
| 3884 | break :n n.toOptional(); | ||
| 3885 | } else .none; | ||
| 3886 | const aligns: Alignment.Slice = if (flags.any_aligned_fields) a: { | 3882 | const aligns: Alignment.Slice = if (flags.any_aligned_fields) a: { |
| 3887 | const a: Alignment.Slice = .{ | 3883 | const a: Alignment.Slice = .{ |
| 3888 | .tid = unwrapped_index.tid, | 3884 | .tid = unwrapped_index.tid, |
| ... | @@ -3925,7 +3921,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { | ... | @@ -3925,7 +3921,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { |
| 3925 | .extra_index = item.data, | 3921 | .extra_index = item.data, |
| 3926 | .name = name, | 3922 | .name = name, |
| 3927 | .cau = cau.toOptional(), | 3923 | .cau = cau.toOptional(), |
| 3928 | .namespace = namespace, | 3924 | .namespace = namespace.toOptional(), |
| 3929 | .zir_index = zir_index.toOptional(), | 3925 | .zir_index = zir_index.toOptional(), |
| 3930 | .layout = if (flags.is_extern) .@"extern" else .auto, | 3926 | .layout = if (flags.is_extern) .@"extern" else .auto, |
| 3931 | .field_names = names, | 3927 | .field_names = names, |
| ... | @@ -3944,7 +3940,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { | ... | @@ -3944,7 +3940,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { |
| 3944 | const cau: Cau.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "cau").?]); | 3940 | const cau: Cau.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "cau").?]); |
| 3945 | const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "zir_index").?]); | 3941 | const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "zir_index").?]); |
| 3946 | const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "fields_len").?]; | 3942 | const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "fields_len").?]; |
| 3947 | const namespace: OptionalNamespaceIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?]); | 3943 | const namespace: NamespaceIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?]); |
| 3948 | const names_map: MapIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "names_map").?]); | 3944 | const names_map: MapIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "names_map").?]); |
| 3949 | const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .unordered)); | 3945 | const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .unordered)); |
| 3950 | var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len); | 3946 | var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len); |
| ... | @@ -3989,7 +3985,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { | ... | @@ -3989,7 +3985,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType { |
| 3989 | .extra_index = item.data, | 3985 | .extra_index = item.data, |
| 3990 | .name = name, | 3986 | .name = name, |
| 3991 | .cau = cau.toOptional(), | 3987 | .cau = cau.toOptional(), |
| 3992 | .namespace = namespace, | 3988 | .namespace = namespace.toOptional(), |
| 3993 | .zir_index = zir_index.toOptional(), | 3989 | .zir_index = zir_index.toOptional(), |
| 3994 | .layout = .@"packed", | 3990 | .layout = .@"packed", |
| 3995 | .field_names = field_names, | 3991 | .field_names = field_names, |
| ... | @@ -4015,7 +4011,7 @@ const LoadedEnumType = struct { | ... | @@ -4015,7 +4011,7 @@ const LoadedEnumType = struct { |
| 4015 | /// `null` if this is a generated tag type. | 4011 | /// `null` if this is a generated tag type. |
| 4016 | cau: Cau.Index.Optional, | 4012 | cau: Cau.Index.Optional, |
| 4017 | /// Represents the declarations inside this enum. | 4013 | /// Represents the declarations inside this enum. |
| 4018 | namespace: OptionalNamespaceIndex, | 4014 | namespace: NamespaceIndex, |
| 4019 | /// An integer type which is used for the numerical value of the enum. | 4015 | /// An integer type which is used for the numerical value of the enum. |
| 4020 | /// This field is present regardless of whether the enum has an | 4016 | /// This field is present regardless of whether the enum has an |
| 4021 | /// explicitly provided tag type or auto-numbered. | 4017 | /// explicitly provided tag type or auto-numbered. |
| ... | @@ -4172,7 +4168,7 @@ pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType { | ... | @@ -4172,7 +4168,7 @@ pub fn loadEnumType(ip: *const InternPool, index: Index) LoadedEnumType { |
| 4172 | /// Note that this type doubles as the payload for `Tag.type_opaque`. | 4168 | /// Note that this type doubles as the payload for `Tag.type_opaque`. |
| 4173 | pub const LoadedOpaqueType = struct { | 4169 | pub const LoadedOpaqueType = struct { |
| 4174 | /// Contains the declarations inside this opaque. | 4170 | /// Contains the declarations inside this opaque. |
| 4175 | namespace: OptionalNamespaceIndex, | 4171 | namespace: NamespaceIndex, |
| 4176 | // TODO: the non-fqn will be needed by the new dwarf structure | 4172 | // TODO: the non-fqn will be needed by the new dwarf structure |
| 4177 | /// The name of this opaque type. | 4173 | /// The name of this opaque type. |
| 4178 | name: NullTerminatedString, | 4174 | name: NullTerminatedString, |
| ... | @@ -5324,7 +5320,7 @@ pub const Tag = enum(u8) { | ... | @@ -5324,7 +5320,7 @@ pub const Tag = enum(u8) { |
| 5324 | /// Only valid after .have_layout | 5320 | /// Only valid after .have_layout |
| 5325 | padding: u32, | 5321 | padding: u32, |
| 5326 | cau: Cau.Index, | 5322 | cau: Cau.Index, |
| 5327 | namespace: OptionalNamespaceIndex, | 5323 | namespace: NamespaceIndex, |
| 5328 | /// The enum that provides the list of field names and values. | 5324 | /// The enum that provides the list of field names and values. |
| 5329 | tag_ty: Index, | 5325 | tag_ty: Index, |
| 5330 | zir_index: TrackedInst.Index, | 5326 | zir_index: TrackedInst.Index, |
| ... | @@ -5357,7 +5353,7 @@ pub const Tag = enum(u8) { | ... | @@ -5357,7 +5353,7 @@ pub const Tag = enum(u8) { |
| 5357 | cau: Cau.Index, | 5353 | cau: Cau.Index, |
| 5358 | zir_index: TrackedInst.Index, | 5354 | zir_index: TrackedInst.Index, |
| 5359 | fields_len: u32, | 5355 | fields_len: u32, |
| 5360 | namespace: OptionalNamespaceIndex, | 5356 | namespace: NamespaceIndex, |
| 5361 | backing_int_ty: Index, | 5357 | backing_int_ty: Index, |
| 5362 | names_map: MapIndex, | 5358 | names_map: MapIndex, |
| 5363 | flags: Flags, | 5359 | flags: Flags, |
| ... | @@ -5396,19 +5392,18 @@ pub const Tag = enum(u8) { | ... | @@ -5396,19 +5392,18 @@ pub const Tag = enum(u8) { |
| 5396 | /// name: NullTerminatedString // for each field in declared order | 5392 | /// name: NullTerminatedString // for each field in declared order |
| 5397 | /// 5. if any_default_inits: | 5393 | /// 5. if any_default_inits: |
| 5398 | /// init: Index // for each field in declared order | 5394 | /// init: Index // for each field in declared order |
| 5399 | /// 6. if has_namespace: | 5395 | /// 6. if any_aligned_fields: |
| 5400 | /// namespace: NamespaceIndex | ||
| 5401 | /// 7. if any_aligned_fields: | ||
| 5402 | /// align: Alignment // for each field in declared order | 5396 | /// align: Alignment // for each field in declared order |
| 5403 | /// 8. if any_comptime_fields: | 5397 | /// 7. if any_comptime_fields: |
| 5404 | /// field_is_comptime_bits: u32 // minimal number of u32s needed, LSB is field 0 | 5398 | /// field_is_comptime_bits: u32 // minimal number of u32s needed, LSB is field 0 |
| 5405 | /// 9. if not is_extern: | 5399 | /// 8. if not is_extern: |
| 5406 | /// field_index: RuntimeOrder // for each field in runtime order | 5400 | /// field_index: RuntimeOrder // for each field in runtime order |
| 5407 | /// 10. field_offset: u32 // for each field in declared order, undef until layout_resolved | 5401 | /// 9. field_offset: u32 // for each field in declared order, undef until layout_resolved |
| 5408 | pub const TypeStruct = struct { | 5402 | pub const TypeStruct = struct { |
| 5409 | name: NullTerminatedString, | 5403 | name: NullTerminatedString, |
| 5410 | cau: Cau.Index, | 5404 | cau: Cau.Index, |
| 5411 | zir_index: TrackedInst.Index, | 5405 | zir_index: TrackedInst.Index, |
| 5406 | namespace: NamespaceIndex, | ||
| 5412 | fields_len: u32, | 5407 | fields_len: u32, |
| 5413 | flags: Flags, | 5408 | flags: Flags, |
| 5414 | size: u32, | 5409 | size: u32, |
| ... | @@ -5421,7 +5416,6 @@ pub const Tag = enum(u8) { | ... | @@ -5421,7 +5416,6 @@ pub const Tag = enum(u8) { |
| 5421 | is_tuple: bool = false, | 5416 | is_tuple: bool = false, |
| 5422 | assumed_runtime_bits: bool = false, | 5417 | assumed_runtime_bits: bool = false, |
| 5423 | assumed_pointer_aligned: bool = false, | 5418 | assumed_pointer_aligned: bool = false, |
| 5424 | has_namespace: bool = false, | ||
| 5425 | any_comptime_fields: bool = false, | 5419 | any_comptime_fields: bool = false, |
| 5426 | any_default_inits: bool = false, | 5420 | any_default_inits: bool = false, |
| 5427 | any_aligned_fields: bool = false, | 5421 | any_aligned_fields: bool = false, |
| ... | @@ -5444,7 +5438,7 @@ pub const Tag = enum(u8) { | ... | @@ -5444,7 +5438,7 @@ pub const Tag = enum(u8) { |
| 5444 | // which `layout_resolved` does not ensure. | 5438 | // which `layout_resolved` does not ensure. |
| 5445 | fully_resolved: bool = false, | 5439 | fully_resolved: bool = false, |
| 5446 | is_reified: bool = false, | 5440 | is_reified: bool = false, |
| 5447 | _: u6 = 0, | 5441 | _: u7 = 0, |
| 5448 | }; | 5442 | }; |
| 5449 | }; | 5443 | }; |
| 5450 | 5444 | ||
| ... | @@ -5453,7 +5447,7 @@ pub const Tag = enum(u8) { | ... | @@ -5453,7 +5447,7 @@ pub const Tag = enum(u8) { |
| 5453 | pub const TypeOpaque = struct { | 5447 | pub const TypeOpaque = struct { |
| 5454 | name: NullTerminatedString, | 5448 | name: NullTerminatedString, |
| 5455 | /// Contains the declarations inside this opaque. | 5449 | /// Contains the declarations inside this opaque. |
| 5456 | namespace: OptionalNamespaceIndex, | 5450 | namespace: NamespaceIndex, |
| 5457 | /// The index of the `opaque_decl` instruction. | 5451 | /// The index of the `opaque_decl` instruction. |
| 5458 | zir_index: TrackedInst.Index, | 5452 | zir_index: TrackedInst.Index, |
| 5459 | /// `std.math.maxInt(u32)` indicates this type is reified. | 5453 | /// `std.math.maxInt(u32)` indicates this type is reified. |
| ... | @@ -5762,8 +5756,7 @@ pub const EnumExplicit = struct { | ... | @@ -5762,8 +5756,7 @@ pub const EnumExplicit = struct { |
| 5762 | name: NullTerminatedString, | 5756 | name: NullTerminatedString, |
| 5763 | /// `std.math.maxInt(u32)` indicates this type is reified. | 5757 | /// `std.math.maxInt(u32)` indicates this type is reified. |
| 5764 | captures_len: u32, | 5758 | captures_len: u32, |
| 5765 | /// This may be `none` if there are no declarations. | 5759 | namespace: NamespaceIndex, |
| 5766 | namespace: OptionalNamespaceIndex, | ||
| 5767 | /// An integer type which is used for the numerical value of the enum, which | 5760 | /// An integer type which is used for the numerical value of the enum, which |
| 5768 | /// has been explicitly provided by the enum declaration. | 5761 | /// has been explicitly provided by the enum declaration. |
| 5769 | int_tag_type: Index, | 5762 | int_tag_type: Index, |
| ... | @@ -5789,8 +5782,7 @@ pub const EnumAuto = struct { | ... | @@ -5789,8 +5782,7 @@ pub const EnumAuto = struct { |
| 5789 | name: NullTerminatedString, | 5782 | name: NullTerminatedString, |
| 5790 | /// `std.math.maxInt(u32)` indicates this type is reified. | 5783 | /// `std.math.maxInt(u32)` indicates this type is reified. |
| 5791 | captures_len: u32, | 5784 | captures_len: u32, |
| 5792 | /// This may be `none` if there are no declarations. | 5785 | namespace: NamespaceIndex, |
| 5793 | namespace: OptionalNamespaceIndex, | ||
| 5794 | /// An integer type which is used for the numerical value of the enum, which | 5786 | /// An integer type which is used for the numerical value of the enum, which |
| 5795 | /// was inferred by Zig based on the number of tags. | 5787 | /// was inferred by Zig based on the number of tags. |
| 5796 | int_tag_type: Index, | 5788 | int_tag_type: Index, |
| ... | @@ -7854,7 +7846,6 @@ pub const UnionTypeInit = struct { | ... | @@ -7854,7 +7846,6 @@ pub const UnionTypeInit = struct { |
| 7854 | assumed_pointer_aligned: bool, | 7846 | assumed_pointer_aligned: bool, |
| 7855 | alignment: Alignment, | 7847 | alignment: Alignment, |
| 7856 | }, | 7848 | }, |
| 7857 | has_namespace: bool, | ||
| 7858 | fields_len: u32, | 7849 | fields_len: u32, |
| 7859 | enum_tag_ty: Index, | 7850 | enum_tag_ty: Index, |
| 7860 | /// May have length 0 which leaves the values unset until later. | 7851 | /// May have length 0 which leaves the values unset until later. |
| ... | @@ -7930,7 +7921,7 @@ pub fn getUnionType( | ... | @@ -7930,7 +7921,7 @@ pub fn getUnionType( |
| 7930 | .padding = std.math.maxInt(u32), | 7921 | .padding = std.math.maxInt(u32), |
| 7931 | .name = undefined, // set by `finish` | 7922 | .name = undefined, // set by `finish` |
| 7932 | .cau = undefined, // set by `finish` | 7923 | .cau = undefined, // set by `finish` |
| 7933 | .namespace = .none, // set by `finish` | 7924 | .namespace = undefined, // set by `finish` |
| 7934 | .tag_ty = ini.enum_tag_ty, | 7925 | .tag_ty = ini.enum_tag_ty, |
| 7935 | .zir_index = switch (ini.key) { | 7926 | .zir_index = switch (ini.key) { |
| 7936 | inline else => |x| x.zir_index, | 7927 | inline else => |x| x.zir_index, |
| ... | @@ -7978,10 +7969,7 @@ pub fn getUnionType( | ... | @@ -7978,10 +7969,7 @@ pub fn getUnionType( |
| 7978 | .index = gop.put(), | 7969 | .index = gop.put(), |
| 7979 | .type_name_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "name").?, | 7970 | .type_name_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "name").?, |
| 7980 | .cau_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "cau").?, | 7971 | .cau_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "cau").?, |
| 7981 | .namespace_extra_index = if (ini.has_namespace) | 7972 | .namespace_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeUnion, "namespace").?, |
| 7982 | extra_index + std.meta.fieldIndex(Tag.TypeUnion, "namespace").? | ||
| 7983 | else | ||
| 7984 | null, | ||
| 7985 | } }; | 7973 | } }; |
| 7986 | } | 7974 | } |
| 7987 | 7975 | ||
| ... | @@ -7990,7 +7978,7 @@ pub const WipNamespaceType = struct { | ... | @@ -7990,7 +7978,7 @@ pub const WipNamespaceType = struct { |
| 7990 | index: Index, | 7978 | index: Index, |
| 7991 | type_name_extra_index: u32, | 7979 | type_name_extra_index: u32, |
| 7992 | cau_extra_index: ?u32, | 7980 | cau_extra_index: ?u32, |
| 7993 | namespace_extra_index: ?u32, | 7981 | namespace_extra_index: u32, |
| 7994 | 7982 | ||
| 7995 | pub fn setName( | 7983 | pub fn setName( |
| 7996 | wip: WipNamespaceType, | 7984 | wip: WipNamespaceType, |
| ... | @@ -8006,7 +7994,7 @@ pub const WipNamespaceType = struct { | ... | @@ -8006,7 +7994,7 @@ pub const WipNamespaceType = struct { |
| 8006 | wip: WipNamespaceType, | 7994 | wip: WipNamespaceType, |
| 8007 | ip: *InternPool, | 7995 | ip: *InternPool, |
| 8008 | analysis_owner: Cau.Index.Optional, | 7996 | analysis_owner: Cau.Index.Optional, |
| 8009 | namespace: OptionalNamespaceIndex, | 7997 | namespace: NamespaceIndex, |
| 8010 | ) Index { | 7998 | ) Index { |
| 8011 | const extra = ip.getLocalShared(wip.tid).extra.acquire(); | 7999 | const extra = ip.getLocalShared(wip.tid).extra.acquire(); |
| 8012 | const extra_items = extra.view().items(.@"0"); | 8000 | const extra_items = extra.view().items(.@"0"); |
| ... | @@ -8017,11 +8005,7 @@ pub const WipNamespaceType = struct { | ... | @@ -8017,11 +8005,7 @@ pub const WipNamespaceType = struct { |
| 8017 | assert(analysis_owner == .none); | 8005 | assert(analysis_owner == .none); |
| 8018 | } | 8006 | } |
| 8019 | 8007 | ||
| 8020 | if (wip.namespace_extra_index) |i| { | 8008 | extra_items[wip.namespace_extra_index] = @intFromEnum(namespace); |
| 8021 | extra_items[i] = @intFromEnum(namespace.unwrap().?); | ||
| 8022 | } else { | ||
| 8023 | assert(namespace == .none); | ||
| 8024 | } | ||
| 8025 | 8009 | ||
| 8026 | return wip.index; | 8010 | return wip.index; |
| 8027 | } | 8011 | } |
| ... | @@ -8046,7 +8030,6 @@ pub const StructTypeInit = struct { | ... | @@ -8046,7 +8030,6 @@ pub const StructTypeInit = struct { |
| 8046 | any_default_inits: bool, | 8030 | any_default_inits: bool, |
| 8047 | inits_resolved: bool, | 8031 | inits_resolved: bool, |
| 8048 | any_aligned_fields: bool, | 8032 | any_aligned_fields: bool, |
| 8049 | has_namespace: bool, | ||
| 8050 | key: union(enum) { | 8033 | key: union(enum) { |
| 8051 | declared: struct { | 8034 | declared: struct { |
| 8052 | zir_index: TrackedInst.Index, | 8035 | zir_index: TrackedInst.Index, |
| ... | @@ -8109,7 +8092,7 @@ pub fn getStructType( | ... | @@ -8109,7 +8092,7 @@ pub fn getStructType( |
| 8109 | .cau = undefined, // set by `finish` | 8092 | .cau = undefined, // set by `finish` |
| 8110 | .zir_index = zir_index, | 8093 | .zir_index = zir_index, |
| 8111 | .fields_len = ini.fields_len, | 8094 | .fields_len = ini.fields_len, |
| 8112 | .namespace = .none, | 8095 | .namespace = undefined, // set by `finish` |
| 8113 | .backing_int_ty = .none, | 8096 | .backing_int_ty = .none, |
| 8114 | .names_map = names_map, | 8097 | .names_map = names_map, |
| 8115 | .flags = .{ | 8098 | .flags = .{ |
| ... | @@ -8142,10 +8125,7 @@ pub fn getStructType( | ... | @@ -8142,10 +8125,7 @@ pub fn getStructType( |
| 8142 | .index = gop.put(), | 8125 | .index = gop.put(), |
| 8143 | .type_name_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "name").?, | 8126 | .type_name_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "name").?, |
| 8144 | .cau_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "cau").?, | 8127 | .cau_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "cau").?, |
| 8145 | .namespace_extra_index = if (ini.has_namespace) | 8128 | .namespace_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?, |
| 8146 | extra_index + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").? | ||
| 8147 | else | ||
| 8148 | null, | ||
| 8149 | } }; | 8129 | } }; |
| 8150 | }, | 8130 | }, |
| 8151 | }; | 8131 | }; |
| ... | @@ -8164,11 +8144,12 @@ pub fn getStructType( | ... | @@ -8164,11 +8144,12 @@ pub fn getStructType( |
| 8164 | // zig fmt: on | 8144 | // zig fmt: on |
| 8165 | (ini.fields_len * 5) + // types, names, inits, runtime order, offsets | 8145 | (ini.fields_len * 5) + // types, names, inits, runtime order, offsets |
| 8166 | align_elements_len + comptime_elements_len + | 8146 | align_elements_len + comptime_elements_len + |
| 8167 | 2); // names_map + namespace | 8147 | 1); // names_map |
| 8168 | const extra_index = addExtraAssumeCapacity(extra, Tag.TypeStruct{ | 8148 | const extra_index = addExtraAssumeCapacity(extra, Tag.TypeStruct{ |
| 8169 | .name = undefined, // set by `finish` | 8149 | .name = undefined, // set by `finish` |
| 8170 | .cau = undefined, // set by `finish` | 8150 | .cau = undefined, // set by `finish` |
| 8171 | .zir_index = zir_index, | 8151 | .zir_index = zir_index, |
| 8152 | .namespace = undefined, // set by `finish` | ||
| 8172 | .fields_len = ini.fields_len, | 8153 | .fields_len = ini.fields_len, |
| 8173 | .size = std.math.maxInt(u32), | 8154 | .size = std.math.maxInt(u32), |
| 8174 | .flags = .{ | 8155 | .flags = .{ |
| ... | @@ -8179,7 +8160,6 @@ pub fn getStructType( | ... | @@ -8179,7 +8160,6 @@ pub fn getStructType( |
| 8179 | .is_tuple = ini.is_tuple, | 8160 | .is_tuple = ini.is_tuple, |
| 8180 | .assumed_runtime_bits = false, | 8161 | .assumed_runtime_bits = false, |
| 8181 | .assumed_pointer_aligned = false, | 8162 | .assumed_pointer_aligned = false, |
| 8182 | .has_namespace = ini.has_namespace, | ||
| 8183 | .any_comptime_fields = ini.any_comptime_fields, | 8163 | .any_comptime_fields = ini.any_comptime_fields, |
| 8184 | .any_default_inits = ini.any_default_inits, | 8164 | .any_default_inits = ini.any_default_inits, |
| 8185 | .any_aligned_fields = ini.any_aligned_fields, | 8165 | .any_aligned_fields = ini.any_aligned_fields, |
| ... | @@ -8215,10 +8195,6 @@ pub fn getStructType( | ... | @@ -8215,10 +8195,6 @@ pub fn getStructType( |
| 8215 | if (ini.any_default_inits) { | 8195 | if (ini.any_default_inits) { |
| 8216 | extra.appendNTimesAssumeCapacity(.{@intFromEnum(Index.none)}, ini.fields_len); | 8196 | extra.appendNTimesAssumeCapacity(.{@intFromEnum(Index.none)}, ini.fields_len); |
| 8217 | } | 8197 | } |
| 8218 | const namespace_extra_index: ?u32 = if (ini.has_namespace) i: { | ||
| 8219 | extra.appendAssumeCapacity(undefined); // set by `finish` | ||
| 8220 | break :i @intCast(extra.mutate.len - 1); | ||
| 8221 | } else null; | ||
| 8222 | if (ini.any_aligned_fields) { | 8198 | if (ini.any_aligned_fields) { |
| 8223 | extra.appendNTimesAssumeCapacity(.{align_element}, align_elements_len); | 8199 | extra.appendNTimesAssumeCapacity(.{align_element}, align_elements_len); |
| 8224 | } | 8200 | } |
| ... | @@ -8234,7 +8210,7 @@ pub fn getStructType( | ... | @@ -8234,7 +8210,7 @@ pub fn getStructType( |
| 8234 | .index = gop.put(), | 8210 | .index = gop.put(), |
| 8235 | .type_name_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "name").?, | 8211 | .type_name_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "name").?, |
| 8236 | .cau_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "cau").?, | 8212 | .cau_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "cau").?, |
| 8237 | .namespace_extra_index = namespace_extra_index, | 8213 | .namespace_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeStruct, "namespace").?, |
| 8238 | } }; | 8214 | } }; |
| 8239 | } | 8215 | } |
| 8240 | 8216 | ||
| ... | @@ -9002,7 +8978,6 @@ fn finishFuncInstance( | ... | @@ -9002,7 +8978,6 @@ fn finishFuncInstance( |
| 9002 | } | 8978 | } |
| 9003 | 8979 | ||
| 9004 | pub const EnumTypeInit = struct { | 8980 | pub const EnumTypeInit = struct { |
| 9005 | has_namespace: bool, | ||
| 9006 | has_values: bool, | 8981 | has_values: bool, |
| 9007 | tag_mode: LoadedEnumType.TagMode, | 8982 | tag_mode: LoadedEnumType.TagMode, |
| 9008 | fields_len: u32, | 8983 | fields_len: u32, |
| ... | @@ -9024,7 +8999,7 @@ pub const WipEnumType = struct { | ... | @@ -9024,7 +8999,7 @@ pub const WipEnumType = struct { |
| 9024 | tag_ty_index: u32, | 8999 | tag_ty_index: u32, |
| 9025 | type_name_extra_index: u32, | 9000 | type_name_extra_index: u32, |
| 9026 | cau_extra_index: u32, | 9001 | cau_extra_index: u32, |
| 9027 | namespace_extra_index: ?u32, | 9002 | namespace_extra_index: u32, |
| 9028 | names_map: MapIndex, | 9003 | names_map: MapIndex, |
| 9029 | names_start: u32, | 9004 | names_start: u32, |
| 9030 | values_map: OptionalMapIndex, | 9005 | values_map: OptionalMapIndex, |
| ... | @@ -9044,18 +9019,13 @@ pub const WipEnumType = struct { | ... | @@ -9044,18 +9019,13 @@ pub const WipEnumType = struct { |
| 9044 | wip: WipEnumType, | 9019 | wip: WipEnumType, |
| 9045 | ip: *InternPool, | 9020 | ip: *InternPool, |
| 9046 | analysis_owner: Cau.Index, | 9021 | analysis_owner: Cau.Index, |
| 9047 | namespace: OptionalNamespaceIndex, | 9022 | namespace: NamespaceIndex, |
| 9048 | ) void { | 9023 | ) void { |
| 9049 | const extra = ip.getLocalShared(wip.tid).extra.acquire(); | 9024 | const extra = ip.getLocalShared(wip.tid).extra.acquire(); |
| 9050 | const extra_items = extra.view().items(.@"0"); | 9025 | const extra_items = extra.view().items(.@"0"); |
| 9051 | 9026 | ||
| 9052 | extra_items[wip.cau_extra_index] = @intFromEnum(analysis_owner); | 9027 | extra_items[wip.cau_extra_index] = @intFromEnum(analysis_owner); |
| 9053 | 9028 | extra_items[wip.namespace_extra_index] = @intFromEnum(namespace); | |
| 9054 | if (wip.namespace_extra_index) |i| { | ||
| 9055 | extra_items[i] = @intFromEnum(namespace.unwrap().?); | ||
| 9056 | } else { | ||
| 9057 | assert(namespace == .none); | ||
| 9058 | } | ||
| 9059 | } | 9029 | } |
| 9060 | 9030 | ||
| 9061 | pub fn setTagTy(wip: WipEnumType, ip: *InternPool, tag_ty: Index) void { | 9031 | pub fn setTagTy(wip: WipEnumType, ip: *InternPool, tag_ty: Index) void { |
| ... | @@ -9153,7 +9123,7 @@ pub fn getEnumType( | ... | @@ -9153,7 +9123,7 @@ pub fn getEnumType( |
| 9153 | .declared => |d| @intCast(d.captures.len), | 9123 | .declared => |d| @intCast(d.captures.len), |
| 9154 | .reified => std.math.maxInt(u32), | 9124 | .reified => std.math.maxInt(u32), |
| 9155 | }, | 9125 | }, |
| 9156 | .namespace = .none, | 9126 | .namespace = undefined, // set by `prepare` |
| 9157 | .int_tag_type = .none, // set by `prepare` | 9127 | .int_tag_type = .none, // set by `prepare` |
| 9158 | .fields_len = ini.fields_len, | 9128 | .fields_len = ini.fields_len, |
| 9159 | .names_map = names_map, | 9129 | .names_map = names_map, |
| ... | @@ -9179,7 +9149,7 @@ pub fn getEnumType( | ... | @@ -9179,7 +9149,7 @@ pub fn getEnumType( |
| 9179 | .tag_ty_index = extra_index + std.meta.fieldIndex(EnumAuto, "int_tag_type").?, | 9149 | .tag_ty_index = extra_index + std.meta.fieldIndex(EnumAuto, "int_tag_type").?, |
| 9180 | .type_name_extra_index = extra_index + std.meta.fieldIndex(EnumAuto, "name").?, | 9150 | .type_name_extra_index = extra_index + std.meta.fieldIndex(EnumAuto, "name").?, |
| 9181 | .cau_extra_index = @intCast(cau_extra_index), | 9151 | .cau_extra_index = @intCast(cau_extra_index), |
| 9182 | .namespace_extra_index = if (ini.has_namespace) extra_index + std.meta.fieldIndex(EnumAuto, "namespace").? else null, | 9152 | .namespace_extra_index = extra_index + std.meta.fieldIndex(EnumAuto, "namespace").?, |
| 9183 | .names_map = names_map, | 9153 | .names_map = names_map, |
| 9184 | .names_start = @intCast(names_start), | 9154 | .names_start = @intCast(names_start), |
| 9185 | .values_map = .none, | 9155 | .values_map = .none, |
| ... | @@ -9213,7 +9183,7 @@ pub fn getEnumType( | ... | @@ -9213,7 +9183,7 @@ pub fn getEnumType( |
| 9213 | .declared => |d| @intCast(d.captures.len), | 9183 | .declared => |d| @intCast(d.captures.len), |
| 9214 | .reified => std.math.maxInt(u32), | 9184 | .reified => std.math.maxInt(u32), |
| 9215 | }, | 9185 | }, |
| 9216 | .namespace = .none, | 9186 | .namespace = undefined, // set by `prepare` |
| 9217 | .int_tag_type = .none, // set by `prepare` | 9187 | .int_tag_type = .none, // set by `prepare` |
| 9218 | .fields_len = ini.fields_len, | 9188 | .fields_len = ini.fields_len, |
| 9219 | .names_map = names_map, | 9189 | .names_map = names_map, |
| ... | @@ -9248,7 +9218,7 @@ pub fn getEnumType( | ... | @@ -9248,7 +9218,7 @@ pub fn getEnumType( |
| 9248 | .tag_ty_index = extra_index + std.meta.fieldIndex(EnumExplicit, "int_tag_type").?, | 9218 | .tag_ty_index = extra_index + std.meta.fieldIndex(EnumExplicit, "int_tag_type").?, |
| 9249 | .type_name_extra_index = extra_index + std.meta.fieldIndex(EnumExplicit, "name").?, | 9219 | .type_name_extra_index = extra_index + std.meta.fieldIndex(EnumExplicit, "name").?, |
| 9250 | .cau_extra_index = @intCast(cau_extra_index), | 9220 | .cau_extra_index = @intCast(cau_extra_index), |
| 9251 | .namespace_extra_index = if (ini.has_namespace) extra_index + std.meta.fieldIndex(EnumExplicit, "namespace").? else null, | 9221 | .namespace_extra_index = extra_index + std.meta.fieldIndex(EnumExplicit, "namespace").?, |
| 9252 | .names_map = names_map, | 9222 | .names_map = names_map, |
| 9253 | .names_start = @intCast(names_start), | 9223 | .names_start = @intCast(names_start), |
| 9254 | .values_map = values_map, | 9224 | .values_map = values_map, |
| ... | @@ -9265,6 +9235,7 @@ const GeneratedTagEnumTypeInit = struct { | ... | @@ -9265,6 +9235,7 @@ const GeneratedTagEnumTypeInit = struct { |
| 9265 | names: []const NullTerminatedString, | 9235 | names: []const NullTerminatedString, |
| 9266 | values: []const Index, | 9236 | values: []const Index, |
| 9267 | tag_mode: LoadedEnumType.TagMode, | 9237 | tag_mode: LoadedEnumType.TagMode, |
| 9238 | parent_namespace: NamespaceIndex, | ||
| 9268 | }; | 9239 | }; |
| 9269 | 9240 | ||
| 9270 | /// Creates an enum type which was automatically-generated as the tag type of a | 9241 | /// Creates an enum type which was automatically-generated as the tag type of a |
| ... | @@ -9291,6 +9262,18 @@ pub fn getGeneratedTagEnumType( | ... | @@ -9291,6 +9262,18 @@ pub fn getGeneratedTagEnumType( |
| 9291 | 9262 | ||
| 9292 | const fields_len: u32 = @intCast(ini.names.len); | 9263 | const fields_len: u32 = @intCast(ini.names.len); |
| 9293 | 9264 | ||
| 9265 | // Predict the index the enum will live at so we can construct the namespace before releasing the shard's mutex. | ||
| 9266 | const enum_index = Index.Unwrapped.wrap(.{ | ||
| 9267 | .tid = tid, | ||
| 9268 | .index = items.mutate.len, | ||
| 9269 | }, ip); | ||
| 9270 | const namespace = try ip.createNamespace(gpa, tid, .{ | ||
| 9271 | .parent = ini.parent_namespace.toOptional(), | ||
| 9272 | .owner_type = enum_index, | ||
| 9273 | .file_scope = ip.namespacePtr(ini.parent_namespace).file_scope, | ||
| 9274 | }); | ||
| 9275 | errdefer ip.destroyNamespace(tid, namespace); | ||
| 9276 | |||
| 9294 | const prev_extra_len = extra.mutate.len; | 9277 | const prev_extra_len = extra.mutate.len; |
| 9295 | switch (ini.tag_mode) { | 9278 | switch (ini.tag_mode) { |
| 9296 | .auto => { | 9279 | .auto => { |
| ... | @@ -9302,7 +9285,7 @@ pub fn getGeneratedTagEnumType( | ... | @@ -9302,7 +9285,7 @@ pub fn getGeneratedTagEnumType( |
| 9302 | .data = addExtraAssumeCapacity(extra, EnumAuto{ | 9285 | .data = addExtraAssumeCapacity(extra, EnumAuto{ |
| 9303 | .name = ini.name, | 9286 | .name = ini.name, |
| 9304 | .captures_len = 0, | 9287 | .captures_len = 0, |
| 9305 | .namespace = .none, | 9288 | .namespace = namespace, |
| 9306 | .int_tag_type = ini.tag_ty, | 9289 | .int_tag_type = ini.tag_ty, |
| 9307 | .fields_len = fields_len, | 9290 | .fields_len = fields_len, |
| 9308 | .names_map = names_map, | 9291 | .names_map = names_map, |
| ... | @@ -9335,7 +9318,7 @@ pub fn getGeneratedTagEnumType( | ... | @@ -9335,7 +9318,7 @@ pub fn getGeneratedTagEnumType( |
| 9335 | .data = addExtraAssumeCapacity(extra, EnumExplicit{ | 9318 | .data = addExtraAssumeCapacity(extra, EnumExplicit{ |
| 9336 | .name = ini.name, | 9319 | .name = ini.name, |
| 9337 | .captures_len = 0, | 9320 | .captures_len = 0, |
| 9338 | .namespace = .none, | 9321 | .namespace = namespace, |
| 9339 | .int_tag_type = ini.tag_ty, | 9322 | .int_tag_type = ini.tag_ty, |
| 9340 | .fields_len = fields_len, | 9323 | .fields_len = fields_len, |
| 9341 | .names_map = names_map, | 9324 | .names_map = names_map, |
| ... | @@ -9360,11 +9343,11 @@ pub fn getGeneratedTagEnumType( | ... | @@ -9360,11 +9343,11 @@ pub fn getGeneratedTagEnumType( |
| 9360 | .generated_tag = .{ .union_type = ini.owner_union_ty }, | 9343 | .generated_tag = .{ .union_type = ini.owner_union_ty }, |
| 9361 | } }); | 9344 | } }); |
| 9362 | defer gop.deinit(); | 9345 | defer gop.deinit(); |
| 9363 | return gop.put(); | 9346 | assert(gop.put() == enum_index); |
| 9347 | return enum_index; | ||
| 9364 | } | 9348 | } |
| 9365 | 9349 | ||
| 9366 | pub const OpaqueTypeInit = struct { | 9350 | pub const OpaqueTypeInit = struct { |
| 9367 | has_namespace: bool, | ||
| 9368 | key: union(enum) { | 9351 | key: union(enum) { |
| 9369 | declared: struct { | 9352 | declared: struct { |
| 9370 | zir_index: TrackedInst.Index, | 9353 | zir_index: TrackedInst.Index, |
| ... | @@ -9407,7 +9390,7 @@ pub fn getOpaqueType( | ... | @@ -9407,7 +9390,7 @@ pub fn getOpaqueType( |
| 9407 | }); | 9390 | }); |
| 9408 | const extra_index = addExtraAssumeCapacity(extra, Tag.TypeOpaque{ | 9391 | const extra_index = addExtraAssumeCapacity(extra, Tag.TypeOpaque{ |
| 9409 | .name = undefined, // set by `finish` | 9392 | .name = undefined, // set by `finish` |
| 9410 | .namespace = .none, | 9393 | .namespace = undefined, // set by `finish` |
| 9411 | .zir_index = switch (ini.key) { | 9394 | .zir_index = switch (ini.key) { |
| 9412 | inline else => |x| x.zir_index, | 9395 | inline else => |x| x.zir_index, |
| 9413 | }, | 9396 | }, |
| ... | @@ -9430,10 +9413,7 @@ pub fn getOpaqueType( | ... | @@ -9430,10 +9413,7 @@ pub fn getOpaqueType( |
| 9430 | .index = gop.put(), | 9413 | .index = gop.put(), |
| 9431 | .type_name_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "name").?, | 9414 | .type_name_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "name").?, |
| 9432 | .cau_extra_index = null, // opaques do not undergo type resolution | 9415 | .cau_extra_index = null, // opaques do not undergo type resolution |
| 9433 | .namespace_extra_index = if (ini.has_namespace) | 9416 | .namespace_extra_index = extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "namespace").?, |
| 9434 | extra_index + std.meta.fieldIndex(Tag.TypeOpaque, "namespace").? | ||
| 9435 | else | ||
| 9436 | null, | ||
| 9437 | }, | 9417 | }, |
| 9438 | }; | 9418 | }; |
| 9439 | } | 9419 | } |
| ... | @@ -10332,7 +10312,6 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { | ... | @@ -10332,7 +10312,6 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 10332 | } | 10312 | } |
| 10333 | if (info.flags.any_default_inits) | 10313 | if (info.flags.any_default_inits) |
| 10334 | ints += info.fields_len; // inits | 10314 | ints += info.fields_len; // inits |
| 10335 | ints += @intFromBool(info.flags.has_namespace); // namespace | ||
| 10336 | if (info.flags.any_aligned_fields) | 10315 | if (info.flags.any_aligned_fields) |
| 10337 | ints += (info.fields_len + 3) / 4; // aligns | 10316 | ints += (info.fields_len + 3) / 4; // aligns |
| 10338 | if (info.flags.any_comptime_fields) | 10317 | if (info.flags.any_comptime_fields) |
src/Sema.zig+79-71| ... | @@ -2802,7 +2802,6 @@ fn zirStructDecl( | ... | @@ -2802,7 +2802,6 @@ fn zirStructDecl( |
| 2802 | .any_default_inits = small.any_default_inits, | 2802 | .any_default_inits = small.any_default_inits, |
| 2803 | .inits_resolved = false, | 2803 | .inits_resolved = false, |
| 2804 | .any_aligned_fields = small.any_aligned_fields, | 2804 | .any_aligned_fields = small.any_aligned_fields, |
| 2805 | .has_namespace = true or decls_len > 0, // TODO: see below | ||
| 2806 | .key = .{ .declared = .{ | 2805 | .key = .{ .declared = .{ |
| 2807 | .zir_index = tracked_inst, | 2806 | .zir_index = tracked_inst, |
| 2808 | .captures = captures, | 2807 | .captures = captures, |
| ... | @@ -2825,15 +2824,14 @@ fn zirStructDecl( | ... | @@ -2825,15 +2824,14 @@ fn zirStructDecl( |
| 2825 | wip_ty.index, | 2824 | wip_ty.index, |
| 2826 | )); | 2825 | )); |
| 2827 | 2826 | ||
| 2828 | // TODO: if AstGen tells us `@This` was not used in the fields, we can elide the namespace. | 2827 | const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{ |
| 2829 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try pt.createNamespace(.{ | ||
| 2830 | .parent = block.namespace.toOptional(), | 2828 | .parent = block.namespace.toOptional(), |
| 2831 | .owner_type = wip_ty.index, | 2829 | .owner_type = wip_ty.index, |
| 2832 | .file_scope = block.getFileScopeIndex(mod), | 2830 | .file_scope = block.getFileScopeIndex(mod), |
| 2833 | })).toOptional() else .none; | 2831 | }); |
| 2834 | errdefer if (new_namespace_index.unwrap()) |ns| pt.destroyNamespace(ns); | 2832 | errdefer pt.destroyNamespace(new_namespace_index); |
| 2835 | 2833 | ||
| 2836 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index.unwrap() orelse block.namespace, wip_ty.index); | 2834 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index); |
| 2837 | 2835 | ||
| 2838 | if (pt.zcu.comp.incremental) { | 2836 | if (pt.zcu.comp.incremental) { |
| 2839 | try ip.addDependency( | 2837 | try ip.addDependency( |
| ... | @@ -2843,10 +2841,8 @@ fn zirStructDecl( | ... | @@ -2843,10 +2841,8 @@ fn zirStructDecl( |
| 2843 | ); | 2841 | ); |
| 2844 | } | 2842 | } |
| 2845 | 2843 | ||
| 2846 | if (new_namespace_index.unwrap()) |ns| { | 2844 | const decls = sema.code.bodySlice(extra_index, decls_len); |
| 2847 | const decls = sema.code.bodySlice(extra_index, decls_len); | 2845 | try pt.scanNamespace(new_namespace_index, decls); |
| 2848 | try pt.scanNamespace(ns, decls); | ||
| 2849 | } | ||
| 2850 | 2846 | ||
| 2851 | try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); | 2847 | try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); |
| 2852 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); | 2848 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); |
| ... | @@ -3015,7 +3011,6 @@ fn zirEnumDecl( | ... | @@ -3015,7 +3011,6 @@ fn zirEnumDecl( |
| 3015 | } else false; | 3011 | } else false; |
| 3016 | 3012 | ||
| 3017 | const enum_init: InternPool.EnumTypeInit = .{ | 3013 | const enum_init: InternPool.EnumTypeInit = .{ |
| 3018 | .has_namespace = true or decls_len > 0, // TODO: see below | ||
| 3019 | .has_values = any_values, | 3014 | .has_values = any_values, |
| 3020 | .tag_mode = if (small.nonexhaustive) | 3015 | .tag_mode = if (small.nonexhaustive) |
| 3021 | .nonexhaustive | 3016 | .nonexhaustive |
| ... | @@ -3052,15 +3047,14 @@ fn zirEnumDecl( | ... | @@ -3052,15 +3047,14 @@ fn zirEnumDecl( |
| 3052 | ); | 3047 | ); |
| 3053 | wip_ty.setName(ip, type_name); | 3048 | wip_ty.setName(ip, type_name); |
| 3054 | 3049 | ||
| 3055 | // TODO: if AstGen tells us `@This` was not used in the fields, we can elide the namespace. | 3050 | const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{ |
| 3056 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try pt.createNamespace(.{ | ||
| 3057 | .parent = block.namespace.toOptional(), | 3051 | .parent = block.namespace.toOptional(), |
| 3058 | .owner_type = wip_ty.index, | 3052 | .owner_type = wip_ty.index, |
| 3059 | .file_scope = block.getFileScopeIndex(mod), | 3053 | .file_scope = block.getFileScopeIndex(mod), |
| 3060 | })).toOptional() else .none; | 3054 | }); |
| 3061 | errdefer if (!done) if (new_namespace_index.unwrap()) |ns| pt.destroyNamespace(ns); | 3055 | errdefer if (!done) pt.destroyNamespace(new_namespace_index); |
| 3062 | 3056 | ||
| 3063 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index.unwrap() orelse block.namespace, wip_ty.index); | 3057 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index); |
| 3064 | 3058 | ||
| 3065 | if (pt.zcu.comp.incremental) { | 3059 | if (pt.zcu.comp.incremental) { |
| 3066 | try mod.intern_pool.addDependency( | 3060 | try mod.intern_pool.addDependency( |
| ... | @@ -3070,9 +3064,7 @@ fn zirEnumDecl( | ... | @@ -3070,9 +3064,7 @@ fn zirEnumDecl( |
| 3070 | ); | 3064 | ); |
| 3071 | } | 3065 | } |
| 3072 | 3066 | ||
| 3073 | if (new_namespace_index.unwrap()) |ns| { | 3067 | try pt.scanNamespace(new_namespace_index, decls); |
| 3074 | try pt.scanNamespace(ns, decls); | ||
| 3075 | } | ||
| 3076 | 3068 | ||
| 3077 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); | 3069 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); |
| 3078 | try sema.declareDependency(.{ .interned = wip_ty.index }); | 3070 | try sema.declareDependency(.{ .interned = wip_ty.index }); |
| ... | @@ -3098,7 +3090,7 @@ fn zirEnumDecl( | ... | @@ -3098,7 +3090,7 @@ fn zirEnumDecl( |
| 3098 | var enum_block: Block = .{ | 3090 | var enum_block: Block = .{ |
| 3099 | .parent = null, | 3091 | .parent = null, |
| 3100 | .sema = sema, | 3092 | .sema = sema, |
| 3101 | .namespace = new_namespace_index.unwrap() orelse block.namespace, | 3093 | .namespace = new_namespace_index, |
| 3102 | .instructions = .{}, | 3094 | .instructions = .{}, |
| 3103 | .inlining = null, | 3095 | .inlining = null, |
| 3104 | .is_comptime = true, | 3096 | .is_comptime = true, |
| ... | @@ -3284,7 +3276,6 @@ fn zirUnionDecl( | ... | @@ -3284,7 +3276,6 @@ fn zirUnionDecl( |
| 3284 | .assumed_pointer_aligned = false, | 3276 | .assumed_pointer_aligned = false, |
| 3285 | .alignment = .none, | 3277 | .alignment = .none, |
| 3286 | }, | 3278 | }, |
| 3287 | .has_namespace = true or decls_len != 0, // TODO: see below | ||
| 3288 | .fields_len = fields_len, | 3279 | .fields_len = fields_len, |
| 3289 | .enum_tag_ty = .none, // set later | 3280 | .enum_tag_ty = .none, // set later |
| 3290 | .field_types = &.{}, // set later | 3281 | .field_types = &.{}, // set later |
| ... | @@ -3311,15 +3302,14 @@ fn zirUnionDecl( | ... | @@ -3311,15 +3302,14 @@ fn zirUnionDecl( |
| 3311 | wip_ty.index, | 3302 | wip_ty.index, |
| 3312 | )); | 3303 | )); |
| 3313 | 3304 | ||
| 3314 | // TODO: if AstGen tells us `@This` was not used in the fields, we can elide the namespace. | 3305 | const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{ |
| 3315 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try pt.createNamespace(.{ | ||
| 3316 | .parent = block.namespace.toOptional(), | 3306 | .parent = block.namespace.toOptional(), |
| 3317 | .owner_type = wip_ty.index, | 3307 | .owner_type = wip_ty.index, |
| 3318 | .file_scope = block.getFileScopeIndex(mod), | 3308 | .file_scope = block.getFileScopeIndex(mod), |
| 3319 | })).toOptional() else .none; | 3309 | }); |
| 3320 | errdefer if (new_namespace_index.unwrap()) |ns| pt.destroyNamespace(ns); | 3310 | errdefer pt.destroyNamespace(new_namespace_index); |
| 3321 | 3311 | ||
| 3322 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index.unwrap() orelse block.namespace, wip_ty.index); | 3312 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index); |
| 3323 | 3313 | ||
| 3324 | if (pt.zcu.comp.incremental) { | 3314 | if (pt.zcu.comp.incremental) { |
| 3325 | try mod.intern_pool.addDependency( | 3315 | try mod.intern_pool.addDependency( |
| ... | @@ -3329,10 +3319,8 @@ fn zirUnionDecl( | ... | @@ -3329,10 +3319,8 @@ fn zirUnionDecl( |
| 3329 | ); | 3319 | ); |
| 3330 | } | 3320 | } |
| 3331 | 3321 | ||
| 3332 | if (new_namespace_index.unwrap()) |ns| { | 3322 | const decls = sema.code.bodySlice(extra_index, decls_len); |
| 3333 | const decls = sema.code.bodySlice(extra_index, decls_len); | 3323 | try pt.scanNamespace(new_namespace_index, decls); |
| 3334 | try pt.scanNamespace(ns, decls); | ||
| 3335 | } | ||
| 3336 | 3324 | ||
| 3337 | try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); | 3325 | try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); |
| 3338 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); | 3326 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); |
| ... | @@ -3377,7 +3365,6 @@ fn zirOpaqueDecl( | ... | @@ -3377,7 +3365,6 @@ fn zirOpaqueDecl( |
| 3377 | extra_index += captures_len; | 3365 | extra_index += captures_len; |
| 3378 | 3366 | ||
| 3379 | const opaque_init: InternPool.OpaqueTypeInit = .{ | 3367 | const opaque_init: InternPool.OpaqueTypeInit = .{ |
| 3380 | .has_namespace = decls_len != 0, | ||
| 3381 | .key = .{ .declared = .{ | 3368 | .key = .{ .declared = .{ |
| 3382 | .zir_index = tracked_inst, | 3369 | .zir_index = tracked_inst, |
| 3383 | .captures = captures, | 3370 | .captures = captures, |
| ... | @@ -3399,17 +3386,15 @@ fn zirOpaqueDecl( | ... | @@ -3399,17 +3386,15 @@ fn zirOpaqueDecl( |
| 3399 | wip_ty.index, | 3386 | wip_ty.index, |
| 3400 | )); | 3387 | )); |
| 3401 | 3388 | ||
| 3402 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (decls_len > 0) (try pt.createNamespace(.{ | 3389 | const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{ |
| 3403 | .parent = block.namespace.toOptional(), | 3390 | .parent = block.namespace.toOptional(), |
| 3404 | .owner_type = wip_ty.index, | 3391 | .owner_type = wip_ty.index, |
| 3405 | .file_scope = block.getFileScopeIndex(mod), | 3392 | .file_scope = block.getFileScopeIndex(mod), |
| 3406 | })).toOptional() else .none; | 3393 | }); |
| 3407 | errdefer if (new_namespace_index.unwrap()) |ns| pt.destroyNamespace(ns); | 3394 | errdefer pt.destroyNamespace(new_namespace_index); |
| 3408 | 3395 | ||
| 3409 | if (new_namespace_index.unwrap()) |ns| { | 3396 | const decls = sema.code.bodySlice(extra_index, decls_len); |
| 3410 | const decls = sema.code.bodySlice(extra_index, decls_len); | 3397 | try pt.scanNamespace(new_namespace_index, decls); |
| 3411 | try pt.scanNamespace(ns, decls); | ||
| 3412 | } | ||
| 3413 | 3398 | ||
| 3414 | return Air.internedToRef(wip_ty.finish(ip, .none, new_namespace_index)); | 3399 | return Air.internedToRef(wip_ty.finish(ip, .none, new_namespace_index)); |
| 3415 | } | 3400 | } |
| ... | @@ -6749,7 +6734,7 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo | ... | @@ -6749,7 +6734,7 @@ fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPoo |
| 6749 | const mod = pt.zcu; | 6734 | const mod = pt.zcu; |
| 6750 | var namespace = block.namespace; | 6735 | var namespace = block.namespace; |
| 6751 | while (true) { | 6736 | while (true) { |
| 6752 | if (try sema.lookupInNamespace(block, src, namespace.toOptional(), name, false)) |lookup| { | 6737 | if (try sema.lookupInNamespace(block, src, namespace, name, false)) |lookup| { |
| 6753 | assert(lookup.accessible); | 6738 | assert(lookup.accessible); |
| 6754 | return lookup.nav; | 6739 | return lookup.nav; |
| 6755 | } | 6740 | } |
| ... | @@ -6764,7 +6749,7 @@ fn lookupInNamespace( | ... | @@ -6764,7 +6749,7 @@ fn lookupInNamespace( |
| 6764 | sema: *Sema, | 6749 | sema: *Sema, |
| 6765 | block: *Block, | 6750 | block: *Block, |
| 6766 | src: LazySrcLoc, | 6751 | src: LazySrcLoc, |
| 6767 | opt_namespace_index: InternPool.OptionalNamespaceIndex, | 6752 | namespace_index: InternPool.NamespaceIndex, |
| 6768 | ident_name: InternPool.NullTerminatedString, | 6753 | ident_name: InternPool.NullTerminatedString, |
| 6769 | observe_usingnamespace: bool, | 6754 | observe_usingnamespace: bool, |
| 6770 | ) CompileError!?struct { | 6755 | ) CompileError!?struct { |
| ... | @@ -6777,7 +6762,6 @@ fn lookupInNamespace( | ... | @@ -6777,7 +6762,6 @@ fn lookupInNamespace( |
| 6777 | const zcu = pt.zcu; | 6762 | const zcu = pt.zcu; |
| 6778 | const ip = &zcu.intern_pool; | 6763 | const ip = &zcu.intern_pool; |
| 6779 | 6764 | ||
| 6780 | const namespace_index = opt_namespace_index.unwrap() orelse return null; | ||
| 6781 | const namespace = zcu.namespacePtr(namespace_index); | 6765 | const namespace = zcu.namespacePtr(namespace_index); |
| 6782 | 6766 | ||
| 6783 | const adapter: Zcu.Namespace.NameAdapter = .{ .zcu = zcu }; | 6767 | const adapter: Zcu.Namespace.NameAdapter = .{ .zcu = zcu }; |
| ... | @@ -6816,7 +6800,7 @@ fn lookupInNamespace( | ... | @@ -6816,7 +6800,7 @@ fn lookupInNamespace( |
| 6816 | for (usingnamespaces.items) |sub_ns_nav| { | 6800 | for (usingnamespaces.items) |sub_ns_nav| { |
| 6817 | try sema.ensureNavResolved(src, sub_ns_nav); | 6801 | try sema.ensureNavResolved(src, sub_ns_nav); |
| 6818 | const sub_ns_ty = Type.fromInterned(ip.getNav(sub_ns_nav).status.resolved.val); | 6802 | const sub_ns_ty = Type.fromInterned(ip.getNav(sub_ns_nav).status.resolved.val); |
| 6819 | const sub_ns = zcu.namespacePtrUnwrap(sub_ns_ty.getNamespaceIndex(zcu)) orelse continue; | 6803 | const sub_ns = zcu.namespacePtr(sub_ns_ty.getNamespaceIndex(zcu)); |
| 6820 | try checked_namespaces.put(gpa, sub_ns, {}); | 6804 | try checked_namespaces.put(gpa, sub_ns, {}); |
| 6821 | } | 6805 | } |
| 6822 | } | 6806 | } |
| ... | @@ -13952,7 +13936,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -13952,7 +13936,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13952 | } }); | 13936 | } }); |
| 13953 | } | 13937 | } |
| 13954 | 13938 | ||
| 13955 | const namespace = container_type.getNamespaceIndex(mod); | 13939 | const namespace = container_type.getNamespace(mod).unwrap() orelse return .bool_false; |
| 13956 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |lookup| { | 13940 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |lookup| { |
| 13957 | if (lookup.accessible) { | 13941 | if (lookup.accessible) { |
| 13958 | return .bool_true; | 13942 | return .bool_true; |
| ... | @@ -18436,7 +18420,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18436,7 +18420,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18436 | } }); | 18420 | } }); |
| 18437 | }; | 18421 | }; |
| 18438 | 18422 | ||
| 18439 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ip.loadEnumType(ty.toIntern()).namespace); | 18423 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ip.loadEnumType(ty.toIntern()).namespace.toOptional()); |
| 18440 | 18424 | ||
| 18441 | const type_enum_ty = t: { | 18425 | const type_enum_ty = t: { |
| 18442 | const nav = try sema.namespaceLookup( | 18426 | const nav = try sema.namespaceLookup( |
| ... | @@ -18577,7 +18561,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18577,7 +18561,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18577 | } }); | 18561 | } }); |
| 18578 | }; | 18562 | }; |
| 18579 | 18563 | ||
| 18580 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(mod)); | 18564 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(mod).toOptional()); |
| 18581 | 18565 | ||
| 18582 | const enum_tag_ty_val = try pt.intern(.{ .opt = .{ | 18566 | const enum_tag_ty_val = try pt.intern(.{ .opt = .{ |
| 18583 | .ty = (try pt.optionalType(.type_type)).toIntern(), | 18567 | .ty = (try pt.optionalType(.type_type)).toIntern(), |
| ... | @@ -18804,7 +18788,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18804,7 +18788,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18804 | } }); | 18788 | } }); |
| 18805 | }; | 18789 | }; |
| 18806 | 18790 | ||
| 18807 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(mod)); | 18791 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(mod)); |
| 18808 | 18792 | ||
| 18809 | const backing_integer_val = try pt.intern(.{ .opt = .{ | 18793 | const backing_integer_val = try pt.intern(.{ .opt = .{ |
| 18810 | .ty = (try pt.optionalType(.type_type)).toIntern(), | 18794 | .ty = (try pt.optionalType(.type_type)).toIntern(), |
| ... | @@ -18861,7 +18845,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -18861,7 +18845,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 18861 | }; | 18845 | }; |
| 18862 | 18846 | ||
| 18863 | try ty.resolveFields(pt); | 18847 | try ty.resolveFields(pt); |
| 18864 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(mod)); | 18848 | const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(mod)); |
| 18865 | 18849 | ||
| 18866 | const field_values = .{ | 18850 | const field_values = .{ |
| 18867 | // decls: []const Declaration, | 18851 | // decls: []const Declaration, |
| ... | @@ -19009,7 +18993,7 @@ fn typeInfoNamespaceDecls( | ... | @@ -19009,7 +18993,7 @@ fn typeInfoNamespaceDecls( |
| 19009 | } | 18993 | } |
| 19010 | try sema.ensureNavResolved(src, nav); | 18994 | try sema.ensureNavResolved(src, nav); |
| 19011 | const namespace_ty = Type.fromInterned(ip.getNav(nav).status.resolved.val); | 18995 | const namespace_ty = Type.fromInterned(ip.getNav(nav).status.resolved.val); |
| 19012 | try sema.typeInfoNamespaceDecls(block, src, namespace_ty.getNamespaceIndex(zcu), declaration_ty, decl_vals, seen_namespaces); | 18996 | try sema.typeInfoNamespaceDecls(block, src, namespace_ty.getNamespaceIndex(zcu).toOptional(), declaration_ty, decl_vals, seen_namespaces); |
| 19013 | } | 18997 | } |
| 19014 | } | 18998 | } |
| 19015 | 18999 | ||
| ... | @@ -21798,7 +21782,6 @@ fn zirReify( | ... | @@ -21798,7 +21782,6 @@ fn zirReify( |
| 21798 | } | 21782 | } |
| 21799 | 21783 | ||
| 21800 | const wip_ty = switch (try ip.getOpaqueType(gpa, pt.tid, .{ | 21784 | const wip_ty = switch (try ip.getOpaqueType(gpa, pt.tid, .{ |
| 21801 | .has_namespace = false, | ||
| 21802 | .key = .{ .reified = .{ | 21785 | .key = .{ .reified = .{ |
| 21803 | .zir_index = try block.trackZir(inst), | 21786 | .zir_index = try block.trackZir(inst), |
| 21804 | } }, | 21787 | } }, |
| ... | @@ -21816,7 +21799,13 @@ fn zirReify( | ... | @@ -21816,7 +21799,13 @@ fn zirReify( |
| 21816 | wip_ty.index, | 21799 | wip_ty.index, |
| 21817 | )); | 21800 | )); |
| 21818 | 21801 | ||
| 21819 | return Air.internedToRef(wip_ty.finish(ip, .none, .none)); | 21802 | const new_namespace_index = try pt.createNamespace(.{ |
| 21803 | .parent = block.namespace.toOptional(), | ||
| 21804 | .owner_type = wip_ty.index, | ||
| 21805 | .file_scope = block.getFileScopeIndex(mod), | ||
| 21806 | }); | ||
| 21807 | |||
| 21808 | return Air.internedToRef(wip_ty.finish(ip, .none, new_namespace_index)); | ||
| 21820 | }, | 21809 | }, |
| 21821 | .Union => { | 21810 | .Union => { |
| 21822 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21811 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| ... | @@ -21988,7 +21977,6 @@ fn reifyEnum( | ... | @@ -21988,7 +21977,6 @@ fn reifyEnum( |
| 21988 | const tracked_inst = try block.trackZir(inst); | 21977 | const tracked_inst = try block.trackZir(inst); |
| 21989 | 21978 | ||
| 21990 | const wip_ty = switch (try ip.getEnumType(gpa, pt.tid, .{ | 21979 | const wip_ty = switch (try ip.getEnumType(gpa, pt.tid, .{ |
| 21991 | .has_namespace = false, | ||
| 21992 | .has_values = true, | 21980 | .has_values = true, |
| 21993 | .tag_mode = if (is_exhaustive) .explicit else .nonexhaustive, | 21981 | .tag_mode = if (is_exhaustive) .explicit else .nonexhaustive, |
| 21994 | .fields_len = fields_len, | 21982 | .fields_len = fields_len, |
| ... | @@ -22014,9 +22002,15 @@ fn reifyEnum( | ... | @@ -22014,9 +22002,15 @@ fn reifyEnum( |
| 22014 | wip_ty.index, | 22002 | wip_ty.index, |
| 22015 | )); | 22003 | )); |
| 22016 | 22004 | ||
| 22017 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, block.namespace, wip_ty.index); | 22005 | const new_namespace_index = try pt.createNamespace(.{ |
| 22006 | .parent = block.namespace.toOptional(), | ||
| 22007 | .owner_type = wip_ty.index, | ||
| 22008 | .file_scope = block.getFileScopeIndex(mod), | ||
| 22009 | }); | ||
| 22010 | |||
| 22011 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index); | ||
| 22018 | 22012 | ||
| 22019 | wip_ty.prepare(ip, new_cau_index, .none); | 22013 | wip_ty.prepare(ip, new_cau_index, new_namespace_index); |
| 22020 | wip_ty.setTagTy(ip, tag_ty.toIntern()); | 22014 | wip_ty.setTagTy(ip, tag_ty.toIntern()); |
| 22021 | 22015 | ||
| 22022 | for (0..fields_len) |field_idx| { | 22016 | for (0..fields_len) |field_idx| { |
| ... | @@ -22139,7 +22133,6 @@ fn reifyUnion( | ... | @@ -22139,7 +22133,6 @@ fn reifyUnion( |
| 22139 | .assumed_pointer_aligned = false, | 22133 | .assumed_pointer_aligned = false, |
| 22140 | .alignment = .none, | 22134 | .alignment = .none, |
| 22141 | }, | 22135 | }, |
| 22142 | .has_namespace = false, | ||
| 22143 | .fields_len = fields_len, | 22136 | .fields_len = fields_len, |
| 22144 | .enum_tag_ty = .none, // set later because not yet validated | 22137 | .enum_tag_ty = .none, // set later because not yet validated |
| 22145 | .field_types = &.{}, // set later | 22138 | .field_types = &.{}, // set later |
| ... | @@ -22254,7 +22247,7 @@ fn reifyUnion( | ... | @@ -22254,7 +22247,7 @@ fn reifyUnion( |
| 22254 | } | 22247 | } |
| 22255 | } | 22248 | } |
| 22256 | 22249 | ||
| 22257 | const enum_tag_ty = try sema.generateUnionTagTypeSimple(field_names.keys(), wip_ty.index, type_name); | 22250 | const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), wip_ty.index, type_name); |
| 22258 | break :tag_ty .{ enum_tag_ty, false }; | 22251 | break :tag_ty .{ enum_tag_ty, false }; |
| 22259 | }; | 22252 | }; |
| 22260 | errdefer if (!has_explicit_tag) ip.remove(pt.tid, enum_tag_ty); // remove generated tag type on error | 22253 | errdefer if (!has_explicit_tag) ip.remove(pt.tid, enum_tag_ty); // remove generated tag type on error |
| ... | @@ -22301,11 +22294,17 @@ fn reifyUnion( | ... | @@ -22301,11 +22294,17 @@ fn reifyUnion( |
| 22301 | loaded_union.setTagType(ip, enum_tag_ty); | 22294 | loaded_union.setTagType(ip, enum_tag_ty); |
| 22302 | loaded_union.setStatus(ip, .have_field_types); | 22295 | loaded_union.setStatus(ip, .have_field_types); |
| 22303 | 22296 | ||
| 22304 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, block.namespace, wip_ty.index); | 22297 | const new_namespace_index = try pt.createNamespace(.{ |
| 22298 | .parent = block.namespace.toOptional(), | ||
| 22299 | .owner_type = wip_ty.index, | ||
| 22300 | .file_scope = block.getFileScopeIndex(mod), | ||
| 22301 | }); | ||
| 22302 | |||
| 22303 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index); | ||
| 22305 | 22304 | ||
| 22306 | try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); | 22305 | try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); |
| 22307 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); | 22306 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); |
| 22308 | return Air.internedToRef(wip_ty.finish(ip, new_cau_index.toOptional(), .none)); | 22307 | return Air.internedToRef(wip_ty.finish(ip, new_cau_index.toOptional(), new_namespace_index)); |
| 22309 | } | 22308 | } |
| 22310 | 22309 | ||
| 22311 | fn reifyStruct( | 22310 | fn reifyStruct( |
| ... | @@ -22398,7 +22397,6 @@ fn reifyStruct( | ... | @@ -22398,7 +22397,6 @@ fn reifyStruct( |
| 22398 | .any_default_inits = any_default_inits, | 22397 | .any_default_inits = any_default_inits, |
| 22399 | .any_aligned_fields = any_aligned_fields, | 22398 | .any_aligned_fields = any_aligned_fields, |
| 22400 | .inits_resolved = true, | 22399 | .inits_resolved = true, |
| 22401 | .has_namespace = false, | ||
| 22402 | .key = .{ .reified = .{ | 22400 | .key = .{ .reified = .{ |
| 22403 | .zir_index = tracked_inst, | 22401 | .zir_index = tracked_inst, |
| 22404 | .type_hash = hasher.final(), | 22402 | .type_hash = hasher.final(), |
| ... | @@ -22569,11 +22567,17 @@ fn reifyStruct( | ... | @@ -22569,11 +22567,17 @@ fn reifyStruct( |
| 22569 | } | 22567 | } |
| 22570 | } | 22568 | } |
| 22571 | 22569 | ||
| 22572 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, block.namespace, wip_ty.index); | 22570 | const new_namespace_index = try pt.createNamespace(.{ |
| 22571 | .parent = block.namespace.toOptional(), | ||
| 22572 | .owner_type = wip_ty.index, | ||
| 22573 | .file_scope = block.getFileScopeIndex(mod), | ||
| 22574 | }); | ||
| 22575 | |||
| 22576 | const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index); | ||
| 22573 | 22577 | ||
| 22574 | try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); | 22578 | try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); |
| 22575 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); | 22579 | try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .cau = new_cau_index })); |
| 22576 | return Air.internedToRef(wip_ty.finish(ip, new_cau_index.toOptional(), .none)); | 22580 | return Air.internedToRef(wip_ty.finish(ip, new_cau_index.toOptional(), new_namespace_index)); |
| 22577 | } | 22581 | } |
| 22578 | 22582 | ||
| 22579 | fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) CompileError!Air.Inst.Ref { | 22583 | fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) CompileError!Air.Inst.Ref { |
| ... | @@ -28022,7 +28026,7 @@ fn fieldCallBind( | ... | @@ -28022,7 +28026,7 @@ fn fieldCallBind( |
| 28022 | 28026 | ||
| 28023 | // If we get here, we need to look for a decl in the struct type instead. | 28027 | // If we get here, we need to look for a decl in the struct type instead. |
| 28024 | const found_nav = found_nav: { | 28028 | const found_nav = found_nav: { |
| 28025 | const namespace = concrete_ty.getNamespace(zcu) orelse | 28029 | const namespace = concrete_ty.getNamespace(zcu).unwrap() orelse |
| 28026 | break :found_nav null; | 28030 | break :found_nav null; |
| 28027 | const nav_index = try sema.namespaceLookup(block, src, namespace, field_name) orelse | 28031 | const nav_index = try sema.namespaceLookup(block, src, namespace, field_name) orelse |
| 28028 | break :found_nav null; | 28032 | break :found_nav null; |
| ... | @@ -28154,13 +28158,13 @@ fn namespaceLookup( | ... | @@ -28154,13 +28158,13 @@ fn namespaceLookup( |
| 28154 | sema: *Sema, | 28158 | sema: *Sema, |
| 28155 | block: *Block, | 28159 | block: *Block, |
| 28156 | src: LazySrcLoc, | 28160 | src: LazySrcLoc, |
| 28157 | opt_namespace: InternPool.OptionalNamespaceIndex, | 28161 | namespace: InternPool.NamespaceIndex, |
| 28158 | decl_name: InternPool.NullTerminatedString, | 28162 | decl_name: InternPool.NullTerminatedString, |
| 28159 | ) CompileError!?InternPool.Nav.Index { | 28163 | ) CompileError!?InternPool.Nav.Index { |
| 28160 | const pt = sema.pt; | 28164 | const pt = sema.pt; |
| 28161 | const zcu = pt.zcu; | 28165 | const zcu = pt.zcu; |
| 28162 | const gpa = sema.gpa; | 28166 | const gpa = sema.gpa; |
| 28163 | if (try sema.lookupInNamespace(block, src, opt_namespace, decl_name, true)) |lookup| { | 28167 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |lookup| { |
| 28164 | if (!lookup.accessible) { | 28168 | if (!lookup.accessible) { |
| 28165 | return sema.failWithOwnedErrorMsg(block, msg: { | 28169 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 28166 | const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{ | 28170 | const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{ |
| ... | @@ -28180,10 +28184,10 @@ fn namespaceLookupRef( | ... | @@ -28180,10 +28184,10 @@ fn namespaceLookupRef( |
| 28180 | sema: *Sema, | 28184 | sema: *Sema, |
| 28181 | block: *Block, | 28185 | block: *Block, |
| 28182 | src: LazySrcLoc, | 28186 | src: LazySrcLoc, |
| 28183 | opt_namespace: InternPool.OptionalNamespaceIndex, | 28187 | namespace: InternPool.NamespaceIndex, |
| 28184 | decl_name: InternPool.NullTerminatedString, | 28188 | decl_name: InternPool.NullTerminatedString, |
| 28185 | ) CompileError!?Air.Inst.Ref { | 28189 | ) CompileError!?Air.Inst.Ref { |
| 28186 | const nav = try sema.namespaceLookup(block, src, opt_namespace, decl_name) orelse return null; | 28190 | const nav = try sema.namespaceLookup(block, src, namespace, decl_name) orelse return null; |
| 28187 | return try sema.analyzeNavRef(src, nav); | 28191 | return try sema.analyzeNavRef(src, nav); |
| 28188 | } | 28192 | } |
| 28189 | 28193 | ||
| ... | @@ -28191,10 +28195,10 @@ fn namespaceLookupVal( | ... | @@ -28191,10 +28195,10 @@ fn namespaceLookupVal( |
| 28191 | sema: *Sema, | 28195 | sema: *Sema, |
| 28192 | block: *Block, | 28196 | block: *Block, |
| 28193 | src: LazySrcLoc, | 28197 | src: LazySrcLoc, |
| 28194 | opt_namespace: InternPool.OptionalNamespaceIndex, | 28198 | namespace: InternPool.NamespaceIndex, |
| 28195 | decl_name: InternPool.NullTerminatedString, | 28199 | decl_name: InternPool.NullTerminatedString, |
| 28196 | ) CompileError!?Air.Inst.Ref { | 28200 | ) CompileError!?Air.Inst.Ref { |
| 28197 | const nav = try sema.namespaceLookup(block, src, opt_namespace, decl_name) orelse return null; | 28201 | const nav = try sema.namespaceLookup(block, src, namespace, decl_name) orelse return null; |
| 28198 | return try sema.analyzeNavVal(block, src, nav); | 28202 | return try sema.analyzeNavVal(block, src, nav); |
| 28199 | } | 28203 | } |
| 28200 | 28204 | ||
| ... | @@ -36422,7 +36426,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind | ... | @@ -36422,7 +36426,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind |
| 36422 | const gpa = zcu.gpa; | 36426 | const gpa = zcu.gpa; |
| 36423 | const ip = &zcu.intern_pool; | 36427 | const ip = &zcu.intern_pool; |
| 36424 | const cau_index = union_type.cau; | 36428 | const cau_index = union_type.cau; |
| 36425 | const zir = zcu.namespacePtr(union_type.namespace.unwrap().?).fileScope(zcu).zir; | 36429 | const zir = zcu.namespacePtr(union_type.namespace).fileScope(zcu).zir; |
| 36426 | const zir_index = union_type.zir_index.resolve(ip); | 36430 | const zir_index = union_type.zir_index.resolve(ip); |
| 36427 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; | 36431 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; |
| 36428 | assert(extended.opcode == .union_decl); | 36432 | assert(extended.opcode == .union_decl); |
| ... | @@ -36486,7 +36490,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind | ... | @@ -36486,7 +36490,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind |
| 36486 | var block_scope: Block = .{ | 36490 | var block_scope: Block = .{ |
| 36487 | .parent = null, | 36491 | .parent = null, |
| 36488 | .sema = &sema, | 36492 | .sema = &sema, |
| 36489 | .namespace = union_type.namespace.unwrap().?, | 36493 | .namespace = union_type.namespace, |
| 36490 | .instructions = .{}, | 36494 | .instructions = .{}, |
| 36491 | .inlining = null, | 36495 | .inlining = null, |
| 36492 | .is_comptime = true, | 36496 | .is_comptime = true, |
| ... | @@ -36778,10 +36782,10 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind | ... | @@ -36778,10 +36782,10 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind |
| 36778 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36782 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36779 | } | 36783 | } |
| 36780 | } else if (enum_field_vals.count() > 0) { | 36784 | } else if (enum_field_vals.count() > 0) { |
| 36781 | const enum_ty = try sema.generateUnionTagTypeNumbered(enum_field_names, enum_field_vals.keys(), union_ty, union_type.name); | 36785 | const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), union_ty, union_type.name); |
| 36782 | union_type.setTagType(ip, enum_ty); | 36786 | union_type.setTagType(ip, enum_ty); |
| 36783 | } else { | 36787 | } else { |
| 36784 | const enum_ty = try sema.generateUnionTagTypeSimple(enum_field_names, union_ty, union_type.name); | 36788 | const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, union_ty, union_type.name); |
| 36785 | union_type.setTagType(ip, enum_ty); | 36789 | union_type.setTagType(ip, enum_ty); |
| 36786 | } | 36790 | } |
| 36787 | 36791 | ||
| ... | @@ -36797,6 +36801,7 @@ fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Ty | ... | @@ -36797,6 +36801,7 @@ fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Ty |
| 36797 | 36801 | ||
| 36798 | fn generateUnionTagTypeNumbered( | 36802 | fn generateUnionTagTypeNumbered( |
| 36799 | sema: *Sema, | 36803 | sema: *Sema, |
| 36804 | block: *Block, | ||
| 36800 | enum_field_names: []const InternPool.NullTerminatedString, | 36805 | enum_field_names: []const InternPool.NullTerminatedString, |
| 36801 | enum_field_vals: []const InternPool.Index, | 36806 | enum_field_vals: []const InternPool.Index, |
| 36802 | union_type: InternPool.Index, | 36807 | union_type: InternPool.Index, |
| ... | @@ -36825,6 +36830,7 @@ fn generateUnionTagTypeNumbered( | ... | @@ -36825,6 +36830,7 @@ fn generateUnionTagTypeNumbered( |
| 36825 | .names = enum_field_names, | 36830 | .names = enum_field_names, |
| 36826 | .values = enum_field_vals, | 36831 | .values = enum_field_vals, |
| 36827 | .tag_mode = .explicit, | 36832 | .tag_mode = .explicit, |
| 36833 | .parent_namespace = block.namespace, | ||
| 36828 | }); | 36834 | }); |
| 36829 | 36835 | ||
| 36830 | return enum_ty; | 36836 | return enum_ty; |
| ... | @@ -36832,6 +36838,7 @@ fn generateUnionTagTypeNumbered( | ... | @@ -36832,6 +36838,7 @@ fn generateUnionTagTypeNumbered( |
| 36832 | 36838 | ||
| 36833 | fn generateUnionTagTypeSimple( | 36839 | fn generateUnionTagTypeSimple( |
| 36834 | sema: *Sema, | 36840 | sema: *Sema, |
| 36841 | block: *Block, | ||
| 36835 | enum_field_names: []const InternPool.NullTerminatedString, | 36842 | enum_field_names: []const InternPool.NullTerminatedString, |
| 36836 | union_type: InternPool.Index, | 36843 | union_type: InternPool.Index, |
| 36837 | union_name: InternPool.NullTerminatedString, | 36844 | union_name: InternPool.NullTerminatedString, |
| ... | @@ -36859,6 +36866,7 @@ fn generateUnionTagTypeSimple( | ... | @@ -36859,6 +36866,7 @@ fn generateUnionTagTypeSimple( |
| 36859 | .names = enum_field_names, | 36866 | .names = enum_field_names, |
| 36860 | .values = &.{}, | 36867 | .values = &.{}, |
| 36861 | .tag_mode = .auto, | 36868 | .tag_mode = .auto, |
| 36869 | .parent_namespace = block.namespace, | ||
| 36862 | }); | 36870 | }); |
| 36863 | 36871 | ||
| 36864 | return enum_ty; | 36872 | return enum_ty; |
src/Type.zig+9-43| ... | @@ -2968,59 +2968,25 @@ pub fn indexableHasLen(ty: Type, mod: *Module) bool { | ... | @@ -2968,59 +2968,25 @@ pub fn indexableHasLen(ty: Type, mod: *Module) bool { |
| 2968 | } | 2968 | } |
| 2969 | 2969 | ||
| 2970 | /// Asserts that the type can have a namespace. | 2970 | /// Asserts that the type can have a namespace. |
| 2971 | pub fn getNamespaceIndex(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex { | 2971 | pub fn getNamespaceIndex(ty: Type, zcu: *Zcu) InternPool.NamespaceIndex { |
| 2972 | return ty.getNamespace(zcu).?; | 2972 | return ty.getNamespace(zcu).unwrap().?; |
| 2973 | } | 2973 | } |
| 2974 | 2974 | ||
| 2975 | /// Returns null if the type has no namespace. | 2975 | /// Returns null if the type has no namespace. |
| 2976 | pub fn getNamespace(ty: Type, zcu: *Zcu) ?InternPool.OptionalNamespaceIndex { | 2976 | pub fn getNamespace(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex { |
| 2977 | const ip = &zcu.intern_pool; | 2977 | const ip = &zcu.intern_pool; |
| 2978 | return switch (ip.indexToKey(ty.toIntern())) { | 2978 | return switch (ip.indexToKey(ty.toIntern())) { |
| 2979 | .opaque_type => ip.loadOpaqueType(ty.toIntern()).namespace, | 2979 | .opaque_type => ip.loadOpaqueType(ty.toIntern()).namespace.toOptional(), |
| 2980 | .struct_type => ip.loadStructType(ty.toIntern()).namespace, | 2980 | .struct_type => ip.loadStructType(ty.toIntern()).namespace, |
| 2981 | .union_type => ip.loadUnionType(ty.toIntern()).namespace, | 2981 | .union_type => ip.loadUnionType(ty.toIntern()).namespace.toOptional(), |
| 2982 | .enum_type => ip.loadEnumType(ty.toIntern()).namespace, | 2982 | .enum_type => ip.loadEnumType(ty.toIntern()).namespace.toOptional(), |
| 2983 | 2983 | else => .none, | |
| 2984 | .anon_struct_type => .none, | ||
| 2985 | .simple_type => |s| switch (s) { | ||
| 2986 | .anyopaque, | ||
| 2987 | .atomic_order, | ||
| 2988 | .atomic_rmw_op, | ||
| 2989 | .calling_convention, | ||
| 2990 | .address_space, | ||
| 2991 | .float_mode, | ||
| 2992 | .reduce_op, | ||
| 2993 | .call_modifier, | ||
| 2994 | .prefetch_options, | ||
| 2995 | .export_options, | ||
| 2996 | .extern_options, | ||
| 2997 | .type_info, | ||
| 2998 | => .none, | ||
| 2999 | else => null, | ||
| 3000 | }, | ||
| 3001 | |||
| 3002 | else => null, | ||
| 3003 | }; | 2984 | }; |
| 3004 | } | 2985 | } |
| 3005 | 2986 | ||
| 3006 | // TODO: new dwarf structure will also need the enclosing code block for types created in imperative scopes | 2987 | // TODO: new dwarf structure will also need the enclosing code block for types created in imperative scopes |
| 3007 | pub fn getParentNamespace(ty: Type, zcu: *Zcu) ?InternPool.OptionalNamespaceIndex { | 2988 | pub fn getParentNamespace(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex { |
| 3008 | const ip = &zcu.intern_pool; | 2989 | return zcu.namespacePtr(ty.getNamespace(zcu).unwrap() orelse return .none).parent; |
| 3009 | const cau = switch (ip.indexToKey(ty.toIntern())) { | ||
| 3010 | .struct_type => ip.loadStructType(ty.toIntern()).cau, | ||
| 3011 | .union_type => ip.loadUnionType(ty.toIntern()).cau.toOptional(), | ||
| 3012 | .enum_type => |e| switch (e) { | ||
| 3013 | .declared, .reified => ip.loadEnumType(ty.toIntern()).cau, | ||
| 3014 | .generated_tag => |gt| ip.loadUnionType(gt.union_type).cau.toOptional(), | ||
| 3015 | .empty_struct => unreachable, | ||
| 3016 | }, | ||
| 3017 | // TODO: this doesn't handle opaque types with empty namespaces | ||
| 3018 | .opaque_type => return ip.namespacePtr(ip.loadOpaqueType(ty.toIntern()).namespace.unwrap().?).parent, | ||
| 3019 | else => return null, | ||
| 3020 | }; | ||
| 3021 | return ip.namespacePtr(ip.getCau(cau.unwrap() orelse return .none).namespace) | ||
| 3022 | // TODO: I thought the cau contained the parent namespace based on "analyzed within" but alas | ||
| 3023 | .parent; | ||
| 3024 | } | 2990 | } |
| 3025 | 2991 | ||
| 3026 | // Works for vectors and vectors of integers. | 2992 | // Works for vectors and vectors of integers. |
src/Zcu/PerThread.zig+8-10| ... | @@ -887,7 +887,6 @@ fn createFileRootStruct( | ... | @@ -887,7 +887,6 @@ fn createFileRootStruct( |
| 887 | .any_default_inits = small.any_default_inits, | 887 | .any_default_inits = small.any_default_inits, |
| 888 | .inits_resolved = false, | 888 | .inits_resolved = false, |
| 889 | .any_aligned_fields = small.any_aligned_fields, | 889 | .any_aligned_fields = small.any_aligned_fields, |
| 890 | .has_namespace = true, | ||
| 891 | .key = .{ .declared = .{ | 890 | .key = .{ .declared = .{ |
| 892 | .zir_index = tracked_inst, | 891 | .zir_index = tracked_inst, |
| 893 | .captures = &.{}, | 892 | .captures = &.{}, |
| ... | @@ -913,7 +912,7 @@ fn createFileRootStruct( | ... | @@ -913,7 +912,7 @@ fn createFileRootStruct( |
| 913 | try pt.scanNamespace(namespace_index, decls); | 912 | try pt.scanNamespace(namespace_index, decls); |
| 914 | try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); | 913 | try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index }); |
| 915 | zcu.setFileRootType(file_index, wip_ty.index); | 914 | zcu.setFileRootType(file_index, wip_ty.index); |
| 916 | return wip_ty.finish(ip, new_cau_index.toOptional(), namespace_index.toOptional()); | 915 | return wip_ty.finish(ip, new_cau_index.toOptional(), namespace_index); |
| 917 | } | 916 | } |
| 918 | 917 | ||
| 919 | /// Re-analyze the root type of a file on an incremental update. | 918 | /// Re-analyze the root type of a file on an incremental update. |
| ... | @@ -926,7 +925,7 @@ fn semaFileUpdate(pt: Zcu.PerThread, file_index: Zcu.File.Index, type_outdated: | ... | @@ -926,7 +925,7 @@ fn semaFileUpdate(pt: Zcu.PerThread, file_index: Zcu.File.Index, type_outdated: |
| 926 | const ip = &zcu.intern_pool; | 925 | const ip = &zcu.intern_pool; |
| 927 | const file = zcu.fileByIndex(file_index); | 926 | const file = zcu.fileByIndex(file_index); |
| 928 | const file_root_type = zcu.fileRootType(file_index); | 927 | const file_root_type = zcu.fileRootType(file_index); |
| 929 | const namespace_index = Type.fromInterned(file_root_type).getNamespaceIndex(zcu).unwrap().?; | 928 | const namespace_index = Type.fromInterned(file_root_type).getNamespaceIndex(zcu); |
| 930 | 929 | ||
| 931 | assert(file_root_type != .none); | 930 | assert(file_root_type != .none); |
| 932 | 931 | ||
| ... | @@ -1083,12 +1082,12 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult { | ... | @@ -1083,12 +1082,12 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult { |
| 1083 | const nav_name = ip.getNav(nav).name; | 1082 | const nav_name = ip.getNav(nav).name; |
| 1084 | const std_file_imported = try pt.importPkg(zcu.std_mod); | 1083 | const std_file_imported = try pt.importPkg(zcu.std_mod); |
| 1085 | const std_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index)); | 1084 | const std_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index)); |
| 1086 | const std_namespace = zcu.namespacePtr(std_type.getNamespace(zcu).?.unwrap().?); | 1085 | const std_namespace = zcu.namespacePtr(std_type.getNamespace(zcu).unwrap().?); |
| 1087 | const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls); | 1086 | const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls); |
| 1088 | const builtin_nav = ip.getNav(std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse break :ip_index .none); | 1087 | const builtin_nav = ip.getNav(std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse break :ip_index .none); |
| 1089 | const builtin_namespace = switch (builtin_nav.status) { | 1088 | const builtin_namespace = switch (builtin_nav.status) { |
| 1090 | .unresolved => break :ip_index .none, | 1089 | .unresolved => break :ip_index .none, |
| 1091 | .resolved => |r| Type.fromInterned(r.val).getNamespace(zcu).?.unwrap().?, | 1090 | .resolved => |r| Type.fromInterned(r.val).getNamespace(zcu).unwrap().?, |
| 1092 | }; | 1091 | }; |
| 1093 | if (cau.namespace != builtin_namespace) break :ip_index .none; | 1092 | if (cau.namespace != builtin_namespace) break :ip_index .none; |
| 1094 | // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index. | 1093 | // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index. |
| ... | @@ -1232,7 +1231,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult { | ... | @@ -1232,7 +1231,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult { |
| 1232 | if (decl_ty.toIntern() != .type_type) { | 1231 | if (decl_ty.toIntern() != .type_type) { |
| 1233 | return sema.fail(&block, ty_src, "expected type, found {}", .{decl_ty.fmt(pt)}); | 1232 | return sema.fail(&block, ty_src, "expected type, found {}", .{decl_ty.fmt(pt)}); |
| 1234 | } | 1233 | } |
| 1235 | if (decl_val.toType().getNamespace(zcu) == null) { | 1234 | if (decl_val.toType().getNamespace(zcu) == .none) { |
| 1236 | return sema.fail(&block, ty_src, "type {} has no namespace", .{decl_val.toType().fmt(pt)}); | 1235 | return sema.fail(&block, ty_src, "type {} has no namespace", .{decl_val.toType().fmt(pt)}); |
| 1237 | } | 1236 | } |
| 1238 | ip.resolveNavValue(nav_index, .{ | 1237 | ip.resolveNavValue(nav_index, .{ |
| ... | @@ -2432,7 +2431,7 @@ pub fn populateTestFunctions( | ... | @@ -2432,7 +2431,7 @@ pub fn populateTestFunctions( |
| 2432 | error.OutOfMemory => |e| return e, | 2431 | error.OutOfMemory => |e| return e, |
| 2433 | }; | 2432 | }; |
| 2434 | const builtin_root_type = Type.fromInterned(zcu.fileRootType(builtin_file_index)); | 2433 | const builtin_root_type = Type.fromInterned(zcu.fileRootType(builtin_file_index)); |
| 2435 | const builtin_namespace = builtin_root_type.getNamespace(zcu).?.unwrap().?; | 2434 | const builtin_namespace = builtin_root_type.getNamespace(zcu).unwrap().?; |
| 2436 | const nav_index = zcu.namespacePtr(builtin_namespace).pub_decls.getKeyAdapted( | 2435 | const nav_index = zcu.namespacePtr(builtin_namespace).pub_decls.getKeyAdapted( |
| 2437 | try ip.getOrPutString(gpa, pt.tid, "test_functions", .no_embedded_nulls), | 2436 | try ip.getOrPutString(gpa, pt.tid, "test_functions", .no_embedded_nulls), |
| 2438 | Zcu.Namespace.NameAdapter{ .zcu = zcu }, | 2437 | Zcu.Namespace.NameAdapter{ .zcu = zcu }, |
| ... | @@ -3196,14 +3195,13 @@ pub fn getBuiltinNav(pt: Zcu.PerThread, name: []const u8) Allocator.Error!Intern | ... | @@ -3196,14 +3195,13 @@ pub fn getBuiltinNav(pt: Zcu.PerThread, name: []const u8) Allocator.Error!Intern |
| 3196 | const ip = &zcu.intern_pool; | 3195 | const ip = &zcu.intern_pool; |
| 3197 | const std_file_imported = pt.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig"); | 3196 | const std_file_imported = pt.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig"); |
| 3198 | const std_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index)); | 3197 | const std_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index)); |
| 3199 | const std_namespace = zcu.namespacePtr(std_type.getNamespace(zcu).?.unwrap().?); | 3198 | const std_namespace = zcu.namespacePtr(std_type.getNamespace(zcu).unwrap().?); |
| 3200 | const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls); | 3199 | const builtin_str = try ip.getOrPutString(gpa, pt.tid, "builtin", .no_embedded_nulls); |
| 3201 | const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse | 3200 | const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse |
| 3202 | @panic("lib/std.zig is corrupt and missing 'builtin'"); | 3201 | @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 3203 | pt.ensureCauAnalyzed(ip.getNav(builtin_nav).analysis_owner.unwrap().?) catch @panic("std.builtin is corrupt"); | 3202 | pt.ensureCauAnalyzed(ip.getNav(builtin_nav).analysis_owner.unwrap().?) catch @panic("std.builtin is corrupt"); |
| 3204 | const builtin_type = Type.fromInterned(ip.getNav(builtin_nav).status.resolved.val); | 3203 | const builtin_type = Type.fromInterned(ip.getNav(builtin_nav).status.resolved.val); |
| 3205 | const builtin_namespace_index = (if (builtin_type.getNamespace(zcu)) |n| n.unwrap() else null) orelse @panic("std.builtin is corrupt"); | 3204 | const builtin_namespace = zcu.namespacePtr(builtin_type.getNamespace(zcu).unwrap() orelse @panic("std.builtin is corrupt")); |
| 3206 | const builtin_namespace = zcu.namespacePtr(builtin_namespace_index); | ||
| 3207 | const name_str = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls); | 3205 | const name_str = try ip.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls); |
| 3208 | return builtin_namespace.pub_decls.getKeyAdapted(name_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse @panic("lib/std/builtin.zig is corrupt"); | 3206 | return builtin_namespace.pub_decls.getKeyAdapted(name_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }) orelse @panic("lib/std/builtin.zig is corrupt"); |
| 3209 | } | 3207 | } |
src/codegen/llvm.zig+5-5| ... | @@ -1958,7 +1958,7 @@ pub const Object = struct { | ... | @@ -1958,7 +1958,7 @@ pub const Object = struct { |
| 1958 | } | 1958 | } |
| 1959 | 1959 | ||
| 1960 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFull(ip).file); | 1960 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFull(ip).file); |
| 1961 | const scope = if (ty.getParentNamespace(zcu).?.unwrap()) |parent_namespace| | 1961 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 1962 | try o.namespaceToDebugScope(parent_namespace) | 1962 | try o.namespaceToDebugScope(parent_namespace) |
| 1963 | else | 1963 | else |
| 1964 | file; | 1964 | file; |
| ... | @@ -2136,7 +2136,7 @@ pub const Object = struct { | ... | @@ -2136,7 +2136,7 @@ pub const Object = struct { |
| 2136 | defer gpa.free(name); | 2136 | defer gpa.free(name); |
| 2137 | 2137 | ||
| 2138 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFull(ip).file); | 2138 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFull(ip).file); |
| 2139 | const scope = if (ty.getParentNamespace(zcu).?.unwrap()) |parent_namespace| | 2139 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 2140 | try o.namespaceToDebugScope(parent_namespace) | 2140 | try o.namespaceToDebugScope(parent_namespace) |
| 2141 | else | 2141 | else |
| 2142 | file; | 2142 | file; |
| ... | @@ -2771,7 +2771,7 @@ pub const Object = struct { | ... | @@ -2771,7 +2771,7 @@ pub const Object = struct { |
| 2771 | const zcu = o.pt.zcu; | 2771 | const zcu = o.pt.zcu; |
| 2772 | const ip = &zcu.intern_pool; | 2772 | const ip = &zcu.intern_pool; |
| 2773 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFull(ip).file); | 2773 | const file = try o.getDebugFile(ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFull(ip).file); |
| 2774 | const scope = if (ty.getParentNamespace(zcu).?.unwrap()) |parent_namespace| | 2774 | const scope = if (ty.getParentNamespace(zcu).unwrap()) |parent_namespace| |
| 2775 | try o.namespaceToDebugScope(parent_namespace) | 2775 | try o.namespaceToDebugScope(parent_namespace) |
| 2776 | else | 2776 | else |
| 2777 | file; | 2777 | file; |
| ... | @@ -2797,13 +2797,13 @@ pub const Object = struct { | ... | @@ -2797,13 +2797,13 @@ pub const Object = struct { |
| 2797 | 2797 | ||
| 2798 | const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls); | 2798 | const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls); |
| 2799 | const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index)); | 2799 | const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index)); |
| 2800 | const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu).unwrap().?); | 2800 | const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu)); |
| 2801 | const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; | 2801 | const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; |
| 2802 | 2802 | ||
| 2803 | const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls); | 2803 | const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls); |
| 2804 | // buffer is only used for int_type, `builtin` is a struct. | 2804 | // buffer is only used for int_type, `builtin` is a struct. |
| 2805 | const builtin_ty = zcu.navValue(builtin_nav).toType(); | 2805 | const builtin_ty = zcu.navValue(builtin_nav).toType(); |
| 2806 | const builtin_namespace = zcu.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(zcu)).?; | 2806 | const builtin_namespace = zcu.namespacePtr(builtin_ty.getNamespaceIndex(zcu)); |
| 2807 | const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; | 2807 | const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?; |
| 2808 | 2808 | ||
| 2809 | // Sema should have ensured that StackTrace was analyzed. | 2809 | // Sema should have ensured that StackTrace was analyzed. |