From 7611d90ba011fb030523e669e85acfb6faae5d19 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Mon, 8 Apr 2024 12:44:42 -0400 Subject: InternPool: remove slice from byte aggregate keys This deletes a ton of lookups and avoids many UAF bugs. Closes #19485 --- src/type.zig | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index 8352552463..264125c6d0 100644 --- a/src/type.zig +++ b/src/type.zig @@ -490,18 +490,10 @@ pub const Type = struct { }; }, .anyframe_type => true, - .array_type => |array_type| { - if (array_type.sentinel != .none) { - return Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat); - } else { - return array_type.len > 0 and - try Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat); - } - }, - .vector_type => |vector_type| { - return vector_type.len > 0 and - try Type.fromInterned(vector_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat); - }, + .array_type => |array_type| return array_type.lenIncludingSentinel() > 0 and + try Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat), + .vector_type => |vector_type| return vector_type.len > 0 and + try Type.fromInterned(vector_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat), .opt_type => |child| { const child_ty = Type.fromInterned(child); if (child_ty.isNoReturn(mod)) { @@ -1240,7 +1232,7 @@ pub const Type = struct { .anyframe_type => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) }, .array_type => |array_type| { - const len = array_type.len + @intFromBool(array_type.sentinel != .none); + const len = array_type.lenIncludingSentinel(); if (len == 0) return .{ .scalar = 0 }; switch (try Type.fromInterned(array_type.child).abiSizeAdvanced(mod, strat)) { .scalar => |elem_size| return .{ .scalar = len * elem_size }, @@ -1577,7 +1569,7 @@ pub const Type = struct { .anyframe_type => return target.ptrBitWidth(), .array_type => |array_type| { - const len = array_type.len + @intFromBool(array_type.sentinel != .none); + const len = array_type.lenIncludingSentinel(); if (len == 0) return 0; const elem_ty = Type.fromInterned(array_type.child); const elem_size = @max( @@ -1731,7 +1723,7 @@ pub const Type = struct { .struct_type => ip.loadStructType(ty.toIntern()).haveLayout(ip), .union_type => ip.loadUnionType(ty.toIntern()).haveLayout(ip), .array_type => |array_type| { - if ((array_type.len + @intFromBool(array_type.sentinel != .none)) == 0) return true; + if (array_type.lenIncludingSentinel() == 0) return true; return Type.fromInterned(array_type.child).layoutIsResolved(mod); }, .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod), -- cgit v1.2.3