| ... | ... | @@ -105,7 +105,7 @@ pub const OptionalMapIndex = enum(u32) { |
| 105 | 105 | |
| 106 | 106 | pub fn unwrap(oi: OptionalMapIndex) ?MapIndex { |
| 107 | 107 | if (oi == .none) return null; |
| 108 | | return @as(MapIndex, @enumFromInt(@intFromEnum(oi))); |
| 108 | return @enumFromInt(@intFromEnum(oi)); |
| 109 | 109 | } |
| 110 | 110 | }; |
| 111 | 111 | |
| ... | ... | @@ -114,7 +114,7 @@ pub const MapIndex = enum(u32) { |
| 114 | 114 | _, |
| 115 | 115 | |
| 116 | 116 | pub fn toOptional(i: MapIndex) OptionalMapIndex { |
| 117 | | return @as(OptionalMapIndex, @enumFromInt(@intFromEnum(i))); |
| 117 | return @enumFromInt(@intFromEnum(i)); |
| 118 | 118 | } |
| 119 | 119 | }; |
| 120 | 120 | |
| ... | ... | @@ -218,7 +218,7 @@ pub const OptionalNullTerminatedString = enum(u32) { |
| 218 | 218 | |
| 219 | 219 | pub fn unwrap(oi: OptionalNullTerminatedString) ?NullTerminatedString { |
| 220 | 220 | if (oi == .none) return null; |
| 221 | | return @as(NullTerminatedString, @enumFromInt(@intFromEnum(oi))); |
| 221 | return @enumFromInt(@intFromEnum(oi)); |
| 222 | 222 | } |
| 223 | 223 | }; |
| 224 | 224 | |
| ... | ... | @@ -415,11 +415,11 @@ pub const Key = union(enum) { |
| 415 | 415 | /// explicitly provided tag type or auto-numbered. |
| 416 | 416 | tag_ty: Index, |
| 417 | 417 | /// Set of field names in declaration order. |
| 418 | | names: []const NullTerminatedString, |
| 418 | names: NullTerminatedString.Slice, |
| 419 | 419 | /// Maps integer tag value to field index. |
| 420 | 420 | /// Entries are in declaration order, same as `fields`. |
| 421 | 421 | /// If this is empty, it means the enum tags are auto-numbered. |
| 422 | | values: []const Index, |
| 422 | values: Index.Slice, |
| 423 | 423 | tag_mode: TagMode, |
| 424 | 424 | /// This is ignored by `get` but will always be provided by `indexToKey`. |
| 425 | 425 | names_map: OptionalMapIndex = .none, |
| ... | ... | @@ -441,9 +441,9 @@ pub const Key = union(enum) { |
| 441 | 441 | /// Look up field index based on field name. |
| 442 | 442 | pub fn nameIndex(self: EnumType, ip: *const InternPool, name: NullTerminatedString) ?u32 { |
| 443 | 443 | const map = &ip.maps.items[@intFromEnum(self.names_map.unwrap().?)]; |
| 444 | | const adapter: NullTerminatedString.Adapter = .{ .strings = self.names }; |
| 444 | const adapter: NullTerminatedString.Adapter = .{ .strings = self.names.get(ip) }; |
| 445 | 445 | const field_index = map.getIndexAdapted(name, adapter) orelse return null; |
| 446 | | return @as(u32, @intCast(field_index)); |
| 446 | return @intCast(field_index); |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /// Look up field index based on tag value. |
| ... | ... | @@ -461,9 +461,9 @@ pub const Key = union(enum) { |
| 461 | 461 | }; |
| 462 | 462 | if (self.values_map.unwrap()) |values_map| { |
| 463 | 463 | const map = &ip.maps.items[@intFromEnum(values_map)]; |
| 464 | | const adapter: Index.Adapter = .{ .indexes = self.values }; |
| 464 | const adapter: Index.Adapter = .{ .indexes = self.values.get(ip) }; |
| 465 | 465 | const field_index = map.getIndexAdapted(int_tag_val, adapter) orelse return null; |
| 466 | | return @as(u32, @intCast(field_index)); |
| 466 | return @intCast(field_index); |
| 467 | 467 | } |
| 468 | 468 | // Auto-numbered enum. Convert `int_tag_val` to field index. |
| 469 | 469 | const field_index = switch (ip.indexToKey(int_tag_val).int.storage) { |
| ... | ... | @@ -497,8 +497,8 @@ pub const Key = union(enum) { |
| 497 | 497 | .namespace = self.namespace, |
| 498 | 498 | .tag_ty = self.tag_ty, |
| 499 | 499 | .tag_mode = self.tag_mode, |
| 500 | | .names = &.{}, |
| 501 | | .values = &.{}, |
| 500 | .names = .{ .start = 0, .len = 0 }, |
| 501 | .values = .{ .start = 0, .len = 0 }, |
| 502 | 502 | }; |
| 503 | 503 | } |
| 504 | 504 | |
| ... | ... | @@ -2570,7 +2570,7 @@ pub const Alignment = enum(u6) { |
| 2570 | 2570 | pub fn fromByteUnits(n: u64) Alignment { |
| 2571 | 2571 | if (n == 0) return .none; |
| 2572 | 2572 | assert(std.math.isPowerOfTwo(n)); |
| 2573 | | return @as(Alignment, @enumFromInt(@ctz(n))); |
| 2573 | return @enumFromInt(@ctz(n)); |
| 2574 | 2574 | } |
| 2575 | 2575 | |
| 2576 | 2576 | pub fn fromNonzeroByteUnits(n: u64) Alignment { |
| ... | ... | @@ -2647,11 +2647,11 @@ pub const PackedU64 = packed struct(u64) { |
| 2647 | 2647 | b: u32, |
| 2648 | 2648 | |
| 2649 | 2649 | pub fn get(x: PackedU64) u64 { |
| 2650 | | return @as(u64, @bitCast(x)); |
| 2650 | return @bitCast(x); |
| 2651 | 2651 | } |
| 2652 | 2652 | |
| 2653 | 2653 | pub fn init(x: u64) PackedU64 { |
| 2654 | | return @as(PackedU64, @bitCast(x)); |
| 2654 | return @bitCast(x); |
| 2655 | 2655 | } |
| 2656 | 2656 | }; |
| 2657 | 2657 | |
| ... | ... | @@ -2714,7 +2714,7 @@ pub const Float64 = struct { |
| 2714 | 2714 | |
| 2715 | 2715 | pub fn get(self: Float64) f64 { |
| 2716 | 2716 | const int_bits = @as(u64, self.piece0) | (@as(u64, self.piece1) << 32); |
| 2717 | | return @as(f64, @bitCast(int_bits)); |
| 2717 | return @bitCast(int_bits); |
| 2718 | 2718 | } |
| 2719 | 2719 | |
| 2720 | 2720 | fn pack(val: f64) Float64 { |
| ... | ... | @@ -2736,7 +2736,7 @@ pub const Float80 = struct { |
| 2736 | 2736 | const int_bits = @as(u80, self.piece0) | |
| 2737 | 2737 | (@as(u80, self.piece1) << 32) | |
| 2738 | 2738 | (@as(u80, self.piece2) << 64); |
| 2739 | | return @as(f80, @bitCast(int_bits)); |
| 2739 | return @bitCast(int_bits); |
| 2740 | 2740 | } |
| 2741 | 2741 | |
| 2742 | 2742 | fn pack(val: f80) Float80 { |
| ... | ... | @@ -2761,7 +2761,7 @@ pub const Float128 = struct { |
| 2761 | 2761 | (@as(u128, self.piece1) << 32) | |
| 2762 | 2762 | (@as(u128, self.piece2) << 64) | |
| 2763 | 2763 | (@as(u128, self.piece3) << 96); |
| 2764 | | return @as(f128, @bitCast(int_bits)); |
| 2764 | return @bitCast(int_bits); |
| 2765 | 2765 | } |
| 2766 | 2766 | |
| 2767 | 2767 | fn pack(val: f128) Float128 { |
| ... | ... | @@ -2968,16 +2968,18 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 2968 | 2968 | |
| 2969 | 2969 | .type_enum_auto => { |
| 2970 | 2970 | const enum_auto = ip.extraDataTrail(EnumAuto, data); |
| 2971 | | const names = @as( |
| 2972 | | []const NullTerminatedString, |
| 2973 | | @ptrCast(ip.extra.items[enum_auto.end..][0..enum_auto.data.fields_len]), |
| 2974 | | ); |
| 2975 | 2971 | return .{ .enum_type = .{ |
| 2976 | 2972 | .decl = enum_auto.data.decl, |
| 2977 | 2973 | .namespace = enum_auto.data.namespace, |
| 2978 | 2974 | .tag_ty = enum_auto.data.int_tag_type, |
| 2979 | | .names = names, |
| 2980 | | .values = &.{}, |
| 2975 | .names = .{ |
| 2976 | .start = @intCast(enum_auto.end), |
| 2977 | .len = enum_auto.data.fields_len, |
| 2978 | }, |
| 2979 | .values = .{ |
| 2980 | .start = 0, |
| 2981 | .len = 0, |
| 2982 | }, |
| 2981 | 2983 | .tag_mode = .auto, |
| 2982 | 2984 | .names_map = enum_auto.data.names_map.toOptional(), |
| 2983 | 2985 | .values_map = .none, |
| ... | ... | @@ -3443,21 +3445,19 @@ fn extraFuncCoerced(ip: *const InternPool, extra_index: u32) Key.Func { |
| 3443 | 3445 | |
| 3444 | 3446 | fn indexToKeyEnum(ip: *const InternPool, data: u32, tag_mode: Key.EnumType.TagMode) Key { |
| 3445 | 3447 | const enum_explicit = ip.extraDataTrail(EnumExplicit, data); |
| 3446 | | const names = @as( |
| 3447 | | []const NullTerminatedString, |
| 3448 | | @ptrCast(ip.extra.items[enum_explicit.end..][0..enum_explicit.data.fields_len]), |
| 3449 | | ); |
| 3450 | | const values = if (enum_explicit.data.values_map != .none) @as( |
| 3451 | | []const Index, |
| 3452 | | @ptrCast(ip.extra.items[enum_explicit.end + names.len ..][0..enum_explicit.data.fields_len]), |
| 3453 | | ) else &[0]Index{}; |
| 3454 | | |
| 3448 | const fields_len = enum_explicit.data.fields_len; |
| 3455 | 3449 | return .{ .enum_type = .{ |
| 3456 | 3450 | .decl = enum_explicit.data.decl, |
| 3457 | 3451 | .namespace = enum_explicit.data.namespace, |
| 3458 | 3452 | .tag_ty = enum_explicit.data.int_tag_type, |
| 3459 | | .names = names, |
| 3460 | | .values = values, |
| 3453 | .names = .{ |
| 3454 | .start = @intCast(enum_explicit.end), |
| 3455 | .len = fields_len, |
| 3456 | }, |
| 3457 | .values = .{ |
| 3458 | .start = @intCast(enum_explicit.end + fields_len), |
| 3459 | .len = if (enum_explicit.data.values_map != .none) fields_len else 0, |
| 3460 | }, |
| 3461 | 3461 | .tag_mode = tag_mode, |
| 3462 | 3462 | .names_map = enum_explicit.data.names_map.toOptional(), |
| 3463 | 3463 | .values_map = enum_explicit.data.values_map, |
| ... | ... | @@ -3506,7 +3506,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3506 | 3506 | .tag = .type_slice, |
| 3507 | 3507 | .data = @intFromEnum(ptr_type_index), |
| 3508 | 3508 | }); |
| 3509 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 3509 | return @enumFromInt(ip.items.len - 1); |
| 3510 | 3510 | } |
| 3511 | 3511 | |
| 3512 | 3512 | var ptr_type_adjusted = ptr_type; |
| ... | ... | @@ -3530,7 +3530,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3530 | 3530 | .child = array_type.child, |
| 3531 | 3531 | }), |
| 3532 | 3532 | }); |
| 3533 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 3533 | return @enumFromInt(ip.items.len - 1); |
| 3534 | 3534 | } |
| 3535 | 3535 | } |
| 3536 | 3536 | |
| ... | ... | @@ -3643,7 +3643,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3643 | 3643 | assert(anon_struct_type.types.len == anon_struct_type.values.len); |
| 3644 | 3644 | for (anon_struct_type.types) |elem| assert(elem != .none); |
| 3645 | 3645 | |
| 3646 | | const fields_len = @as(u32, @intCast(anon_struct_type.types.len)); |
| 3646 | const fields_len: u32 = @intCast(anon_struct_type.types.len); |
| 3647 | 3647 | if (anon_struct_type.names.len == 0) { |
| 3648 | 3648 | try ip.extra.ensureUnusedCapacity( |
| 3649 | 3649 | gpa, |
| ... | ... | @@ -3655,9 +3655,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3655 | 3655 | .fields_len = fields_len, |
| 3656 | 3656 | }), |
| 3657 | 3657 | }); |
| 3658 | | ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.types))); |
| 3659 | | ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.values))); |
| 3660 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 3658 | ip.extra.appendSliceAssumeCapacity(@ptrCast(anon_struct_type.types)); |
| 3659 | ip.extra.appendSliceAssumeCapacity(@ptrCast(anon_struct_type.values)); |
| 3660 | return @enumFromInt(ip.items.len - 1); |
| 3661 | 3661 | } |
| 3662 | 3662 | |
| 3663 | 3663 | assert(anon_struct_type.names.len == anon_struct_type.types.len); |
| ... | ... | @@ -3672,10 +3672,10 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3672 | 3672 | .fields_len = fields_len, |
| 3673 | 3673 | }), |
| 3674 | 3674 | }); |
| 3675 | | ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.types))); |
| 3676 | | ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.values))); |
| 3677 | | ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(anon_struct_type.names))); |
| 3678 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 3675 | ip.extra.appendSliceAssumeCapacity(@ptrCast(anon_struct_type.types)); |
| 3676 | ip.extra.appendSliceAssumeCapacity(@ptrCast(anon_struct_type.values)); |
| 3677 | ip.extra.appendSliceAssumeCapacity(@ptrCast(anon_struct_type.names)); |
| 3678 | return @enumFromInt(ip.items.len - 1); |
| 3679 | 3679 | }, |
| 3680 | 3680 | |
| 3681 | 3681 | .union_type => |union_type| { |
| ... | ... | @@ -3696,38 +3696,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3696 | 3696 | }); |
| 3697 | 3697 | }, |
| 3698 | 3698 | |
| 3699 | | .enum_type => |enum_type| { |
| 3700 | | assert(enum_type.tag_ty == .noreturn_type or ip.isIntegerType(enum_type.tag_ty)); |
| 3701 | | for (enum_type.values) |value| assert(ip.typeOf(value) == enum_type.tag_ty); |
| 3702 | | assert(enum_type.names_map == .none); |
| 3703 | | assert(enum_type.values_map == .none); |
| 3704 | | |
| 3705 | | switch (enum_type.tag_mode) { |
| 3706 | | .auto => { |
| 3707 | | const names_map = try ip.addMap(gpa); |
| 3708 | | try addStringsToMap(ip, gpa, names_map, enum_type.names); |
| 3709 | | |
| 3710 | | const fields_len = @as(u32, @intCast(enum_type.names.len)); |
| 3711 | | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumAuto).Struct.fields.len + |
| 3712 | | fields_len); |
| 3713 | | ip.items.appendAssumeCapacity(.{ |
| 3714 | | .tag = .type_enum_auto, |
| 3715 | | .data = ip.addExtraAssumeCapacity(EnumAuto{ |
| 3716 | | .decl = enum_type.decl, |
| 3717 | | .namespace = enum_type.namespace, |
| 3718 | | .int_tag_type = enum_type.tag_ty, |
| 3719 | | .names_map = names_map, |
| 3720 | | .fields_len = fields_len, |
| 3721 | | }), |
| 3722 | | }); |
| 3723 | | ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(enum_type.names))); |
| 3724 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 3725 | | }, |
| 3726 | | .explicit => return finishGetEnum(ip, gpa, enum_type, .type_enum_explicit), |
| 3727 | | .nonexhaustive => return finishGetEnum(ip, gpa, enum_type, .type_enum_nonexhaustive), |
| 3728 | | } |
| 3729 | | }, |
| 3730 | | |
| 3699 | .enum_type => unreachable, // use getEnum() or getIncompleteEnum() instead |
| 3731 | 3700 | .func_type => unreachable, // use getFuncType() instead |
| 3732 | 3701 | .extern_func => unreachable, // use getExternFunc() instead |
| 3733 | 3702 | .func => unreachable, // use getFuncInstance() or getFuncDecl() instead |
| ... | ... | @@ -3915,7 +3884,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 3915 | 3884 | .lazy_ty = lazy_ty, |
| 3916 | 3885 | }), |
| 3917 | 3886 | }); |
| 3918 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 3887 | return @enumFromInt(ip.items.len - 1); |
| 3919 | 3888 | }, |
| 3920 | 3889 | } |
| 3921 | 3890 | switch (int.ty) { |
| ... | ... | @@ -4056,7 +4025,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4056 | 4025 | .value = casted, |
| 4057 | 4026 | }), |
| 4058 | 4027 | }); |
| 4059 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 4028 | return @enumFromInt(ip.items.len - 1); |
| 4060 | 4029 | } else |_| {} |
| 4061 | 4030 | |
| 4062 | 4031 | const tag: Tag = if (big_int.positive) .int_positive else .int_negative; |
| ... | ... | @@ -4071,7 +4040,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4071 | 4040 | .value = casted, |
| 4072 | 4041 | }), |
| 4073 | 4042 | }); |
| 4074 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 4043 | return @enumFromInt(ip.items.len - 1); |
| 4075 | 4044 | } |
| 4076 | 4045 | |
| 4077 | 4046 | var buf: [2]Limb = undefined; |
| ... | ... | @@ -4234,7 +4203,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4234 | 4203 | .tag = .only_possible_value, |
| 4235 | 4204 | .data = @intFromEnum(aggregate.ty), |
| 4236 | 4205 | }); |
| 4237 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 4206 | return @enumFromInt(ip.items.len - 1); |
| 4238 | 4207 | } |
| 4239 | 4208 | |
| 4240 | 4209 | switch (ty_key) { |
| ... | ... | @@ -4262,7 +4231,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4262 | 4231 | .tag = .only_possible_value, |
| 4263 | 4232 | .data = @intFromEnum(aggregate.ty), |
| 4264 | 4233 | }); |
| 4265 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 4234 | return @enumFromInt(ip.items.len - 1); |
| 4266 | 4235 | }, |
| 4267 | 4236 | else => {}, |
| 4268 | 4237 | } |
| ... | ... | @@ -4301,7 +4270,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4301 | 4270 | .elem_val = elem, |
| 4302 | 4271 | }), |
| 4303 | 4272 | }); |
| 4304 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 4273 | return @enumFromInt(ip.items.len - 1); |
| 4305 | 4274 | } |
| 4306 | 4275 | |
| 4307 | 4276 | if (child == .u8_type) bytes: { |
| ... | ... | @@ -4345,7 +4314,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4345 | 4314 | .bytes = string, |
| 4346 | 4315 | }), |
| 4347 | 4316 | }); |
| 4348 | | return @as(Index, @enumFromInt(ip.items.len - 1)); |
| 4317 | return @enumFromInt(ip.items.len - 1); |
| 4349 | 4318 | } |
| 4350 | 4319 | |
| 4351 | 4320 | try ip.extra.ensureUnusedCapacity( |
| ... | ... | @@ -4358,7 +4327,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4358 | 4327 | .ty = aggregate.ty, |
| 4359 | 4328 | }), |
| 4360 | 4329 | }); |
| 4361 | | ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(aggregate.storage.elems))); |
| 4330 | ip.extra.appendSliceAssumeCapacity(@ptrCast(aggregate.storage.elems)); |
| 4362 | 4331 | if (sentinel != .none) ip.extra.appendAssumeCapacity(@intFromEnum(sentinel)); |
| 4363 | 4332 | }, |
| 4364 | 4333 | |
| ... | ... | @@ -4384,7 +4353,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4384 | 4353 | .result = memoized_call.result, |
| 4385 | 4354 | }), |
| 4386 | 4355 | }); |
| 4387 | | ip.extra.appendSliceAssumeCapacity(@as([]const u32, @ptrCast(memoized_call.arg_values))); |
| 4356 | ip.extra.appendSliceAssumeCapacity(@ptrCast(memoized_call.arg_values)); |
| 4388 | 4357 | }, |
| 4389 | 4358 | } |
| 4390 | 4359 | return @enumFromInt(ip.items.len - 1); |
| ... | ... | @@ -5017,7 +4986,7 @@ pub const IncompleteEnumType = struct { |
| 5017 | 4986 | .strings = @as([]const NullTerminatedString, @ptrCast(strings)), |
| 5018 | 4987 | }; |
| 5019 | 4988 | const gop = try map.getOrPutAdapted(gpa, name, adapter); |
| 5020 | | if (gop.found_existing) return @as(u32, @intCast(gop.index)); |
| 4989 | if (gop.found_existing) return @intCast(gop.index); |
| 5021 | 4990 | ip.extra.items[self.names_start + field_index] = @intFromEnum(name); |
| 5022 | 4991 | return null; |
| 5023 | 4992 | } |
| ... | ... | @@ -5038,7 +5007,7 @@ pub const IncompleteEnumType = struct { |
| 5038 | 5007 | .indexes = @as([]const Index, @ptrCast(indexes)), |
| 5039 | 5008 | }; |
| 5040 | 5009 | const gop = try map.getOrPutAdapted(gpa, value, adapter); |
| 5041 | | if (gop.found_existing) return @as(u32, @intCast(gop.index)); |
| 5010 | if (gop.found_existing) return @intCast(gop.index); |
| 5042 | 5011 | ip.extra.items[self.values_start + field_index] = @intFromEnum(value); |
| 5043 | 5012 | return null; |
| 5044 | 5013 | } |
| ... | ... | @@ -5158,36 +5127,94 @@ fn getIncompleteEnumExplicit( |
| 5158 | 5127 | }; |
| 5159 | 5128 | } |
| 5160 | 5129 | |
| 5130 | pub const GetEnumInit = struct { |
| 5131 | decl: Module.Decl.Index, |
| 5132 | namespace: Module.Namespace.OptionalIndex, |
| 5133 | tag_ty: Index, |
| 5134 | names: []const NullTerminatedString, |
| 5135 | values: []const Index, |
| 5136 | tag_mode: Key.EnumType.TagMode, |
| 5137 | }; |
| 5138 | |
| 5139 | pub fn getEnum(ip: *InternPool, gpa: Allocator, ini: GetEnumInit) Allocator.Error!Index { |
| 5140 | const adapter: KeyAdapter = .{ .intern_pool = ip }; |
| 5141 | const gop = try ip.map.getOrPutAdapted(gpa, Key{ |
| 5142 | .enum_type = .{ |
| 5143 | // Only the decl is used for hashing and equality. |
| 5144 | .decl = ini.decl, |
| 5145 | |
| 5146 | .namespace = undefined, |
| 5147 | .tag_ty = undefined, |
| 5148 | .names = undefined, |
| 5149 | .values = undefined, |
| 5150 | .tag_mode = undefined, |
| 5151 | .names_map = undefined, |
| 5152 | .values_map = undefined, |
| 5153 | }, |
| 5154 | }, adapter); |
| 5155 | if (gop.found_existing) return @enumFromInt(gop.index); |
| 5156 | errdefer _ = ip.map.pop(); |
| 5157 | try ip.items.ensureUnusedCapacity(gpa, 1); |
| 5158 | |
| 5159 | assert(ini.tag_ty == .noreturn_type or ip.isIntegerType(ini.tag_ty)); |
| 5160 | for (ini.values) |value| assert(ip.typeOf(value) == ini.tag_ty); |
| 5161 | |
| 5162 | switch (ini.tag_mode) { |
| 5163 | .auto => { |
| 5164 | const names_map = try ip.addMap(gpa); |
| 5165 | try addStringsToMap(ip, gpa, names_map, ini.names); |
| 5166 | |
| 5167 | const fields_len: u32 = @intCast(ini.names.len); |
| 5168 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumAuto).Struct.fields.len + |
| 5169 | fields_len); |
| 5170 | ip.items.appendAssumeCapacity(.{ |
| 5171 | .tag = .type_enum_auto, |
| 5172 | .data = ip.addExtraAssumeCapacity(EnumAuto{ |
| 5173 | .decl = ini.decl, |
| 5174 | .namespace = ini.namespace, |
| 5175 | .int_tag_type = ini.tag_ty, |
| 5176 | .names_map = names_map, |
| 5177 | .fields_len = fields_len, |
| 5178 | }), |
| 5179 | }); |
| 5180 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.names)); |
| 5181 | return @enumFromInt(ip.items.len - 1); |
| 5182 | }, |
| 5183 | .explicit => return finishGetEnum(ip, gpa, ini, .type_enum_explicit), |
| 5184 | .nonexhaustive => return finishGetEnum(ip, gpa, ini, .type_enum_nonexhaustive), |
| 5185 | } |
| 5186 | } |
| 5187 | |
| 5161 | 5188 | pub fn finishGetEnum( |
| 5162 | 5189 | ip: *InternPool, |
| 5163 | 5190 | gpa: Allocator, |
| 5164 | | enum_type: Key.EnumType, |
| 5191 | ini: GetEnumInit, |
| 5165 | 5192 | tag: Tag, |
| 5166 | 5193 | ) Allocator.Error!Index { |
| 5167 | 5194 | const names_map = try ip.addMap(gpa); |
| 5168 | | try addStringsToMap(ip, gpa, names_map, enum_type.names); |
| 5195 | try addStringsToMap(ip, gpa, names_map, ini.names); |
| 5169 | 5196 | |
| 5170 | | const values_map: OptionalMapIndex = if (enum_type.values.len == 0) .none else m: { |
| 5197 | const values_map: OptionalMapIndex = if (ini.values.len == 0) .none else m: { |
| 5171 | 5198 | const values_map = try ip.addMap(gpa); |
| 5172 | | try addIndexesToMap(ip, gpa, values_map, enum_type.values); |
| 5199 | try addIndexesToMap(ip, gpa, values_map, ini.values); |
| 5173 | 5200 | break :m values_map.toOptional(); |
| 5174 | 5201 | }; |
| 5175 | | const fields_len = @as(u32, @intCast(enum_type.names.len)); |
| 5202 | const fields_len: u32 = @intCast(ini.names.len); |
| 5176 | 5203 | try ip.extra.ensureUnusedCapacity(gpa, @typeInfo(EnumExplicit).Struct.fields.len + |
| 5177 | 5204 | fields_len); |
| 5178 | 5205 | ip.items.appendAssumeCapacity(.{ |
| 5179 | 5206 | .tag = tag, |
| 5180 | 5207 | .data = ip.addExtraAssumeCapacity(EnumExplicit{ |
| 5181 | | .decl = enum_type.decl, |
| 5182 | | .namespace = enum_type.namespace, |
| 5183 | | .int_tag_type = enum_type.tag_ty, |
| 5208 | .decl = ini.decl, |
| 5209 | .namespace = ini.namespace, |
| 5210 | .int_tag_type = ini.tag_ty, |
| 5184 | 5211 | .fields_len = fields_len, |
| 5185 | 5212 | .names_map = names_map, |
| 5186 | 5213 | .values_map = values_map, |
| 5187 | 5214 | }), |
| 5188 | 5215 | }); |
| 5189 | | ip.extra.appendSliceAssumeCapacity(@ptrCast(enum_type.names)); |
| 5190 | | ip.extra.appendSliceAssumeCapacity(@ptrCast(enum_type.values)); |
| 5216 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.names)); |
| 5217 | ip.extra.appendSliceAssumeCapacity(@ptrCast(ini.values)); |
| 5191 | 5218 | return @enumFromInt(ip.items.len - 1); |
| 5192 | 5219 | } |
| 5193 | 5220 | |
| ... | ... | @@ -5486,7 +5513,7 @@ pub fn slicePtrType(ip: *const InternPool, i: Index) Index { |
| 5486 | 5513 | } |
| 5487 | 5514 | const item = ip.items.get(@intFromEnum(i)); |
| 5488 | 5515 | switch (item.tag) { |
| 5489 | | .type_slice => return @as(Index, @enumFromInt(item.data)), |
| 5516 | .type_slice => return @enumFromInt(item.data), |
| 5490 | 5517 | else => unreachable, // not a slice type |
| 5491 | 5518 | } |
| 5492 | 5519 | } |
| ... | ... | @@ -5618,7 +5645,7 @@ pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Al |
| 5618 | 5645 | return ip.get(gpa, .{ .enum_tag = .{ |
| 5619 | 5646 | .ty = new_ty, |
| 5620 | 5647 | .int = if (enum_type.values.len != 0) |
| 5621 | | enum_type.values[index] |
| 5648 | enum_type.values.get(ip)[index] |
| 5622 | 5649 | else |
| 5623 | 5650 | try ip.get(gpa, .{ .int = .{ |
| 5624 | 5651 | .ty = enum_type.tag_ty, |
| ... | ... | @@ -6362,7 +6389,7 @@ pub fn createStruct( |
| 6362 | 6389 | } |
| 6363 | 6390 | const ptr = try ip.allocated_structs.addOne(gpa); |
| 6364 | 6391 | ptr.* = initialization; |
| 6365 | | return @as(Module.Struct.Index, @enumFromInt(ip.allocated_structs.len - 1)); |
| 6392 | return @enumFromInt(ip.allocated_structs.len - 1); |
| 6366 | 6393 | } |
| 6367 | 6394 | |
| 6368 | 6395 | pub fn destroyStruct(ip: *InternPool, gpa: Allocator, index: Module.Struct.Index) void { |
| ... | ... | @@ -6384,7 +6411,7 @@ pub fn createUnion( |
| 6384 | 6411 | } |
| 6385 | 6412 | const ptr = try ip.allocated_unions.addOne(gpa); |
| 6386 | 6413 | ptr.* = initialization; |
| 6387 | | return @as(Module.Union.Index, @enumFromInt(ip.allocated_unions.len - 1)); |
| 6414 | return @enumFromInt(ip.allocated_unions.len - 1); |
| 6388 | 6415 | } |
| 6389 | 6416 | |
| 6390 | 6417 | pub fn destroyUnion(ip: *InternPool, gpa: Allocator, index: Module.Union.Index) void { |
| ... | ... | @@ -6406,7 +6433,7 @@ pub fn createDecl( |
| 6406 | 6433 | } |
| 6407 | 6434 | const ptr = try ip.allocated_decls.addOne(gpa); |
| 6408 | 6435 | ptr.* = initialization; |
| 6409 | | return @as(Module.Decl.Index, @enumFromInt(ip.allocated_decls.len - 1)); |
| 6436 | return @enumFromInt(ip.allocated_decls.len - 1); |
| 6410 | 6437 | } |
| 6411 | 6438 | |
| 6412 | 6439 | pub fn destroyDecl(ip: *InternPool, gpa: Allocator, index: Module.Decl.Index) void { |
| ... | ... | @@ -6428,7 +6455,7 @@ pub fn createNamespace( |
| 6428 | 6455 | } |
| 6429 | 6456 | const ptr = try ip.allocated_namespaces.addOne(gpa); |
| 6430 | 6457 | ptr.* = initialization; |
| 6431 | | return @as(Module.Namespace.Index, @enumFromInt(ip.allocated_namespaces.len - 1)); |
| 6458 | return @enumFromInt(ip.allocated_namespaces.len - 1); |
| 6432 | 6459 | } |
| 6433 | 6460 | |
| 6434 | 6461 | pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: Module.Namespace.Index) void { |
| ... | ... | @@ -6495,11 +6522,11 @@ pub fn getOrPutTrailingString( |
| 6495 | 6522 | }); |
| 6496 | 6523 | if (gop.found_existing) { |
| 6497 | 6524 | string_bytes.shrinkRetainingCapacity(str_index); |
| 6498 | | return @as(NullTerminatedString, @enumFromInt(gop.key_ptr.*)); |
| 6525 | return @enumFromInt(gop.key_ptr.*); |
| 6499 | 6526 | } else { |
| 6500 | 6527 | gop.key_ptr.* = str_index; |
| 6501 | 6528 | string_bytes.appendAssumeCapacity(0); |
| 6502 | | return @as(NullTerminatedString, @enumFromInt(str_index)); |
| 6529 | return @enumFromInt(str_index); |
| 6503 | 6530 | } |
| 6504 | 6531 | } |
| 6505 | 6532 | |
| ... | ... | @@ -6725,7 +6752,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { |
| 6725 | 6752 | /// Assumes that the enum's field indexes equal its value tags. |
| 6726 | 6753 | pub fn toEnum(ip: *const InternPool, comptime E: type, i: Index) E { |
| 6727 | 6754 | const int = ip.indexToKey(i).enum_tag.int; |
| 6728 | | return @as(E, @enumFromInt(ip.indexToKey(int).int.storage.u64)); |
| 6755 | return @enumFromInt(ip.indexToKey(int).int.storage.u64); |
| 6729 | 6756 | } |
| 6730 | 6757 | |
| 6731 | 6758 | pub fn aggregateTypeLen(ip: *const InternPool, ty: Index) u64 { |
| ... | ... | @@ -6758,9 +6785,9 @@ pub fn funcTypeReturnType(ip: *const InternPool, ty: Index) Index { |
| 6758 | 6785 | else => unreachable, |
| 6759 | 6786 | }; |
| 6760 | 6787 | assert(child_item.tag == .type_function); |
| 6761 | | return @as(Index, @enumFromInt(ip.extra.items[ |
| 6788 | return @enumFromInt(ip.extra.items[ |
| 6762 | 6789 | child_item.data + std.meta.fieldIndex(Tag.TypeFunction, "return_type").? |
| 6763 | | ])); |
| 6790 | ]); |
| 6764 | 6791 | } |
| 6765 | 6792 | |
| 6766 | 6793 | pub fn isNoReturn(ip: *const InternPool, ty: Index) bool { |
| ... | ... | @@ -6791,9 +6818,9 @@ pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalInd |
| 6791 | 6818 | switch (ip.items.items(.tag)[base]) { |
| 6792 | 6819 | inline .ptr_decl, |
| 6793 | 6820 | .ptr_mut_decl, |
| 6794 | | => |tag| return @as(Module.Decl.OptionalIndex, @enumFromInt(ip.extra.items[ |
| 6821 | => |tag| return @enumFromInt(ip.extra.items[ |
| 6795 | 6822 | ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "decl").? |
| 6796 | | ])), |
| 6823 | ]), |
| 6797 | 6824 | inline .ptr_eu_payload, |
| 6798 | 6825 | .ptr_opt_payload, |
| 6799 | 6826 | .ptr_elem, |