authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-11-25 01:28:38-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-11-25 18:41:36-05:00
loga6af55cc6e81dd09e03d4b87e8079ce1fe57a36c
treeb83d04a7a996ea201c5114b2aeac9d98d826d5a4
parentf4e042a4c3e8e299d273f00b757ec9fce840c3a6

ip: cleanup `@constCast` usages


1 files changed, 33 insertions(+), 37 deletions(-)

src/InternPool.zig+33-37
......@@ -1431,16 +1431,12 @@ pub const OptionalMapIndex = enum(u32) {
14311431pub const MapIndex = enum(u32) {
14321432 _,
14331433
1434 pub fn get(map_index: MapIndex, ip: *InternPool) *FieldMap {
1434 pub fn get(map_index: MapIndex, ip: *const InternPool) *FieldMap {
14351435 const unwrapped_map_index = map_index.unwrap(ip);
14361436 const maps = ip.getLocalShared(unwrapped_map_index.tid).maps.acquire();
14371437 return &maps.view().items(.@"0")[unwrapped_map_index.index];
14381438 }
14391439
1440 pub fn getConst(map_index: MapIndex, ip: *const InternPool) FieldMap {
1441 return map_index.get(@constCast(ip)).*;
1442 }
1443
14441440 pub fn toOptional(i: MapIndex) OptionalMapIndex {
14451441 return @enumFromInt(@intFromEnum(i));
14461442 }
......@@ -1853,7 +1849,7 @@ pub const Key = union(enum) {
18531849
18541850 /// Look up field index based on field name.
18551851 pub fn nameIndex(self: ErrorSetType, ip: *const InternPool, name: NullTerminatedString) ?u32 {
1856 const map = self.names_map.unwrap().?.getConst(ip);
1852 const map = self.names_map.unwrap().?.get(ip);
18571853 const adapter: NullTerminatedString.Adapter = .{ .strings = self.names.get(ip) };
18581854 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
18591855 return @intCast(field_index);
......@@ -2101,13 +2097,13 @@ pub const Key = union(enum) {
21012097 comptime_args: Index.Slice,
21022098
21032099 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
2104 fn analysisPtr(func: Func, ip: *InternPool) *FuncAnalysis {
2100 fn analysisPtr(func: Func, ip: *const InternPool) *FuncAnalysis {
21052101 const extra = ip.getLocalShared(func.tid).extra.acquire();
21062102 return @ptrCast(&extra.view().items(.@"0")[func.analysis_extra_index]);
21072103 }
21082104
21092105 pub fn analysisUnordered(func: Func, ip: *const InternPool) FuncAnalysis {
2110 return @atomicLoad(FuncAnalysis, func.analysisPtr(@constCast(ip)), .unordered);
2106 return @atomicLoad(FuncAnalysis, func.analysisPtr(ip), .unordered);
21112107 }
21122108
21132109 pub fn setAnalysisState(func: Func, ip: *InternPool, state: FuncAnalysis.State) void {
......@@ -2144,23 +2140,23 @@ pub const Key = union(enum) {
21442140 }
21452141
21462142 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
2147 fn zirBodyInstPtr(func: Func, ip: *InternPool) *TrackedInst.Index {
2143 fn zirBodyInstPtr(func: Func, ip: *const InternPool) *TrackedInst.Index {
21482144 const extra = ip.getLocalShared(func.tid).extra.acquire();
21492145 return @ptrCast(&extra.view().items(.@"0")[func.zir_body_inst_extra_index]);
21502146 }
21512147
21522148 pub fn zirBodyInstUnordered(func: Func, ip: *const InternPool) TrackedInst.Index {
2153 return @atomicLoad(TrackedInst.Index, func.zirBodyInstPtr(@constCast(ip)), .unordered);
2149 return @atomicLoad(TrackedInst.Index, func.zirBodyInstPtr(ip), .unordered);
21542150 }
21552151
21562152 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
2157 fn branchQuotaPtr(func: Func, ip: *InternPool) *u32 {
2153 fn branchQuotaPtr(func: Func, ip: *const InternPool) *u32 {
21582154 const extra = ip.getLocalShared(func.tid).extra.acquire();
21592155 return &extra.view().items(.@"0")[func.branch_quota_extra_index];
21602156 }
21612157
21622158 pub fn branchQuotaUnordered(func: Func, ip: *const InternPool) u32 {
2163 return @atomicLoad(u32, func.branchQuotaPtr(@constCast(ip)), .unordered);
2159 return @atomicLoad(u32, func.branchQuotaPtr(ip), .unordered);
21642160 }
21652161
21662162 pub fn maxBranchQuota(func: Func, ip: *InternPool, new_branch_quota: u32) void {
......@@ -2173,14 +2169,14 @@ pub const Key = union(enum) {
21732169 }
21742170
21752171 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
2176 fn resolvedErrorSetPtr(func: Func, ip: *InternPool) *Index {
2172 fn resolvedErrorSetPtr(func: Func, ip: *const InternPool) *Index {
21772173 const extra = ip.getLocalShared(func.tid).extra.acquire();
21782174 assert(func.analysisUnordered(ip).inferred_error_set);
21792175 return @ptrCast(&extra.view().items(.@"0")[func.resolved_error_set_extra_index]);
21802176 }
21812177
21822178 pub fn resolvedErrorSetUnordered(func: Func, ip: *const InternPool) Index {
2183 return @atomicLoad(Index, func.resolvedErrorSetPtr(@constCast(ip)), .unordered);
2179 return @atomicLoad(Index, func.resolvedErrorSetPtr(ip), .unordered);
21842180 }
21852181
21862182 pub fn setResolvedErrorSet(func: Func, ip: *InternPool, ies: Index) void {
......@@ -3135,14 +3131,14 @@ pub const LoadedUnionType = struct {
31353131 /// This accessor is provided so that the tag type can be mutated, and so that
31363132 /// when it is mutated, the mutations are observed.
31373133 /// The returned pointer expires with any addition to the `InternPool`.
3138 fn tagTypePtr(self: LoadedUnionType, ip: *InternPool) *Index {
3134 fn tagTypePtr(self: LoadedUnionType, ip: *const InternPool) *Index {
31393135 const extra = ip.getLocalShared(self.tid).extra.acquire();
31403136 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "tag_ty").?;
31413137 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);
31423138 }
31433139
31443140 pub fn tagTypeUnordered(u: LoadedUnionType, ip: *const InternPool) Index {
3145 return @atomicLoad(Index, u.tagTypePtr(@constCast(ip)), .unordered);
3141 return @atomicLoad(Index, u.tagTypePtr(ip), .unordered);
31463142 }
31473143
31483144 pub fn setTagType(u: LoadedUnionType, ip: *InternPool, tag_type: Index) void {
......@@ -3154,14 +3150,14 @@ pub const LoadedUnionType = struct {
31543150 }
31553151
31563152 /// The returned pointer expires with any addition to the `InternPool`.
3157 fn flagsPtr(self: LoadedUnionType, ip: *InternPool) *Tag.TypeUnion.Flags {
3153 fn flagsPtr(self: LoadedUnionType, ip: *const InternPool) *Tag.TypeUnion.Flags {
31583154 const extra = ip.getLocalShared(self.tid).extra.acquire();
31593155 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "flags").?;
31603156 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);
31613157 }
31623158
31633159 pub fn flagsUnordered(u: LoadedUnionType, ip: *const InternPool) Tag.TypeUnion.Flags {
3164 return @atomicLoad(Tag.TypeUnion.Flags, u.flagsPtr(@constCast(ip)), .unordered);
3160 return @atomicLoad(Tag.TypeUnion.Flags, u.flagsPtr(ip), .unordered);
31653161 }
31663162
31673163 pub fn setStatus(u: LoadedUnionType, ip: *InternPool, status: Status) void {
......@@ -3254,25 +3250,25 @@ pub const LoadedUnionType = struct {
32543250 }
32553251
32563252 /// The returned pointer expires with any addition to the `InternPool`.
3257 fn sizePtr(self: LoadedUnionType, ip: *InternPool) *u32 {
3253 fn sizePtr(self: LoadedUnionType, ip: *const InternPool) *u32 {
32583254 const extra = ip.getLocalShared(self.tid).extra.acquire();
32593255 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "size").?;
32603256 return &extra.view().items(.@"0")[self.extra_index + field_index];
32613257 }
32623258
32633259 pub fn sizeUnordered(u: LoadedUnionType, ip: *const InternPool) u32 {
3264 return @atomicLoad(u32, u.sizePtr(@constCast(ip)), .unordered);
3260 return @atomicLoad(u32, u.sizePtr(ip), .unordered);
32653261 }
32663262
32673263 /// The returned pointer expires with any addition to the `InternPool`.
3268 fn paddingPtr(self: LoadedUnionType, ip: *InternPool) *u32 {
3264 fn paddingPtr(self: LoadedUnionType, ip: *const InternPool) *u32 {
32693265 const extra = ip.getLocalShared(self.tid).extra.acquire();
32703266 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "padding").?;
32713267 return &extra.view().items(.@"0")[self.extra_index + field_index];
32723268 }
32733269
32743270 pub fn paddingUnordered(u: LoadedUnionType, ip: *const InternPool) u32 {
3275 return @atomicLoad(u32, u.paddingPtr(@constCast(ip)), .unordered);
3271 return @atomicLoad(u32, u.paddingPtr(ip), .unordered);
32763272 }
32773273
32783274 pub fn hasTag(self: LoadedUnionType, ip: *const InternPool) bool {
......@@ -3480,7 +3476,7 @@ pub const LoadedStructType = struct {
34803476 if (i >= s.field_types.len) return null;
34813477 return i;
34823478 };
3483 const map = names_map.getConst(ip);
3479 const map = names_map.get(ip);
34843480 const adapter: NullTerminatedString.Adapter = .{ .strings = s.field_names.get(ip) };
34853481 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
34863482 return @intCast(field_index);
......@@ -3523,7 +3519,7 @@ pub const LoadedStructType = struct {
35233519
35243520 /// The returned pointer expires with any addition to the `InternPool`.
35253521 /// Asserts the struct is not packed.
3526 fn flagsPtr(s: LoadedStructType, ip: *InternPool) *Tag.TypeStruct.Flags {
3522 fn flagsPtr(s: LoadedStructType, ip: *const InternPool) *Tag.TypeStruct.Flags {
35273523 assert(s.layout != .@"packed");
35283524 const extra = ip.getLocalShared(s.tid).extra.acquire();
35293525 const flags_field_index = std.meta.fieldIndex(Tag.TypeStruct, "flags").?;
......@@ -3531,12 +3527,12 @@ pub const LoadedStructType = struct {
35313527 }
35323528
35333529 pub fn flagsUnordered(s: LoadedStructType, ip: *const InternPool) Tag.TypeStruct.Flags {
3534 return @atomicLoad(Tag.TypeStruct.Flags, s.flagsPtr(@constCast(ip)), .unordered);
3530 return @atomicLoad(Tag.TypeStruct.Flags, s.flagsPtr(ip), .unordered);
35353531 }
35363532
35373533 /// The returned pointer expires with any addition to the `InternPool`.
35383534 /// Asserts that the struct is packed.
3539 fn packedFlagsPtr(s: LoadedStructType, ip: *InternPool) *Tag.TypeStructPacked.Flags {
3535 fn packedFlagsPtr(s: LoadedStructType, ip: *const InternPool) *Tag.TypeStructPacked.Flags {
35403536 assert(s.layout == .@"packed");
35413537 const extra = ip.getLocalShared(s.tid).extra.acquire();
35423538 const flags_field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?;
......@@ -3544,7 +3540,7 @@ pub const LoadedStructType = struct {
35443540 }
35453541
35463542 pub fn packedFlagsUnordered(s: LoadedStructType, ip: *const InternPool) Tag.TypeStructPacked.Flags {
3547 return @atomicLoad(Tag.TypeStructPacked.Flags, s.packedFlagsPtr(@constCast(ip)), .unordered);
3543 return @atomicLoad(Tag.TypeStructPacked.Flags, s.packedFlagsPtr(ip), .unordered);
35483544 }
35493545
35503546 /// Reads the non-opv flag calculated during AstGen. Used to short-circuit more
......@@ -3794,7 +3790,7 @@ pub const LoadedStructType = struct {
37943790
37953791 /// The returned pointer expires with any addition to the `InternPool`.
37963792 /// Asserts the struct is not packed.
3797 fn sizePtr(s: LoadedStructType, ip: *InternPool) *u32 {
3793 fn sizePtr(s: LoadedStructType, ip: *const InternPool) *u32 {
37983794 assert(s.layout != .@"packed");
37993795 const extra = ip.getLocalShared(s.tid).extra.acquire();
38003796 const size_field_index = std.meta.fieldIndex(Tag.TypeStruct, "size").?;
......@@ -3802,14 +3798,14 @@ pub const LoadedStructType = struct {
38023798 }
38033799
38043800 pub fn sizeUnordered(s: LoadedStructType, ip: *const InternPool) u32 {
3805 return @atomicLoad(u32, s.sizePtr(@constCast(ip)), .unordered);
3801 return @atomicLoad(u32, s.sizePtr(ip), .unordered);
38063802 }
38073803
38083804 /// The backing integer type of the packed struct. Whether zig chooses
38093805 /// this type or the user specifies it, it is stored here. This will be
38103806 /// set to `none` until the layout is resolved.
38113807 /// Asserts the struct is packed.
3812 fn backingIntTypePtr(s: LoadedStructType, ip: *InternPool) *Index {
3808 fn backingIntTypePtr(s: LoadedStructType, ip: *const InternPool) *Index {
38133809 assert(s.layout == .@"packed");
38143810 const extra = ip.getLocalShared(s.tid).extra.acquire();
38153811 const field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "backing_int_ty").?;
......@@ -3817,7 +3813,7 @@ pub const LoadedStructType = struct {
38173813 }
38183814
38193815 pub fn backingIntTypeUnordered(s: LoadedStructType, ip: *const InternPool) Index {
3820 return @atomicLoad(Index, s.backingIntTypePtr(@constCast(ip)), .unordered);
3816 return @atomicLoad(Index, s.backingIntTypePtr(ip), .unordered);
38213817 }
38223818
38233819 pub fn setBackingIntType(s: LoadedStructType, ip: *InternPool, backing_int_ty: Index) void {
......@@ -4190,7 +4186,7 @@ pub const LoadedEnumType = struct {
41904186
41914187 /// Look up field index based on field name.
41924188 pub fn nameIndex(self: LoadedEnumType, ip: *const InternPool, name: NullTerminatedString) ?u32 {
4193 const map = self.names_map.getConst(ip);
4189 const map = self.names_map.get(ip);
41944190 const adapter: NullTerminatedString.Adapter = .{ .strings = self.names.get(ip) };
41954191 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
41964192 return @intCast(field_index);
......@@ -4210,7 +4206,7 @@ pub const LoadedEnumType = struct {
42104206 else => unreachable,
42114207 };
42124208 if (self.values_map.unwrap()) |values_map| {
4213 const map = values_map.getConst(ip);
4209 const map = values_map.get(ip);
42144210 const adapter: Index.Adapter = .{ .indexes = self.values.get(ip) };
42154211 const field_index = map.getIndexAdapted(int_tag_val, adapter) orelse return null;
42164212 return @intCast(field_index);
......@@ -11731,7 +11727,7 @@ pub fn isFuncBody(ip: *const InternPool, func: Index) bool {
1173111727 };
1173211728}
1173311729
11734fn funcAnalysisPtr(ip: *InternPool, func: Index) *FuncAnalysis {
11730fn funcAnalysisPtr(ip: *const InternPool, func: Index) *FuncAnalysis {
1173511731 const unwrapped_func = func.unwrap(ip);
1173611732 const extra = unwrapped_func.getExtra(ip);
1173711733 const item = unwrapped_func.getItem(ip);
......@@ -11757,7 +11753,7 @@ fn funcAnalysisPtr(ip: *InternPool, func: Index) *FuncAnalysis {
1175711753}
1175811754
1175911755pub fn funcAnalysisUnordered(ip: *const InternPool, func: Index) FuncAnalysis {
11760 return @atomicLoad(FuncAnalysis, @constCast(ip).funcAnalysisPtr(func), .unordered);
11756 return @atomicLoad(FuncAnalysis, ip.funcAnalysisPtr(func), .unordered);
1176111757}
1176211758
1176311759pub fn funcSetCallsOrAwaitsErrorableFn(ip: *InternPool, func: Index) void {
......@@ -11833,7 +11829,7 @@ fn iesResolvedPtr(ip: *InternPool, ies_index: Index) *Index {
1183311829/// Returns a mutable pointer to the resolved error set type of an inferred
1183411830/// error set function. The returned pointer is invalidated when anything is
1183511831/// added to `ip`.
11836fn funcIesResolvedPtr(ip: *InternPool, func_index: Index) *Index {
11832fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index {
1183711833 assert(ip.funcAnalysisUnordered(func_index).inferred_error_set);
1183811834 const unwrapped_func = func_index.unwrap(ip);
1183911835 const func_extra = unwrapped_func.getExtra(ip);
......@@ -11861,7 +11857,7 @@ fn funcIesResolvedPtr(ip: *InternPool, func_index: Index) *Index {
1186111857}
1186211858
1186311859pub fn funcIesResolvedUnordered(ip: *const InternPool, index: Index) Index {
11864 return @atomicLoad(Index, @constCast(ip).funcIesResolvedPtr(index), .unordered);
11860 return @atomicLoad(Index, ip.funcIesResolvedPtr(index), .unordered);
1186511861}
1186611862
1186711863pub fn funcSetIesResolved(ip: *InternPool, index: Index, ies: Index) void {