diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-05-25 07:08:48 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:47:55 -0700 |
| commit | 72e4ea38216aab7e7ed05978d04c5d32de44b5ce (patch) | |
| tree | 9b11f31d39590a767d420dd036682438a6ede634 /src/InternPool.zig | |
| parent | 1a4626d2cf8b9985833f97b6fea6ea03011ada4e (diff) | |
| download | zig-72e4ea38216aab7e7ed05978d04c5d32de44b5ce.tar.gz zig-72e4ea38216aab7e7ed05978d04c5d32de44b5ce.zip | |
InternPool: fix crashes up to in progress comptime mutation
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index 1dc43a467d..429b86a8a6 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -730,21 +730,11 @@ pub const Key = union(enum) { switch (aggregate.storage) { .bytes => unreachable, - .elems => |elems| { - var buffer: Key.Int.Storage.BigIntSpace = undefined; - for (elems) |elem| std.hash.autoHash( - hasher, - ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch - unreachable, - ); - }, + .elems => |elems| for (elems) |elem| std.hash.autoHash(hasher, elem), .repeated_elem => |elem| { const len = ip.aggregateTypeLen(aggregate.ty); - var buffer: Key.Int.Storage.BigIntSpace = undefined; - const byte = ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch - unreachable; var i: u64 = 0; - while (i < len) : (i += 1) std.hash.autoHash(hasher, byte); + while (i < len) : (i += 1) std.hash.autoHash(hasher, elem); }, } }, @@ -2044,6 +2034,10 @@ pub const Alignment = enum(u6) { assert(n != 0); return fromByteUnits(n); } + + pub fn min(a: Alignment, b: Alignment) Alignment { + return @intToEnum(Alignment, @min(@enumToInt(a), @enumToInt(b))); + } }; /// Used for non-sentineled arrays that have length fitting in u32, as well as @@ -3514,16 +3508,35 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { const ty_key = ip.indexToKey(aggregate.ty); const aggregate_len = ip.aggregateTypeLen(aggregate.ty); switch (aggregate.storage) { - .bytes => { + .bytes => |bytes| { assert(ty_key.array_type.child == .u8_type); + assert(bytes.len == aggregate_len); }, .elems => |elems| { assert(elems.len == aggregate_len); - for (elems) |elem| assert(elem != .none); }, - .repeated_elem => |elem| { - assert(elem != .none); + .repeated_elem => {}, + } + switch (ty_key) { + inline .array_type, .vector_type => |seq_type| { + for (aggregate.storage.values()) |elem| { + assert(ip.typeOf(elem) == seq_type.child); + } + }, + .struct_type => |struct_type| { + for ( + aggregate.storage.values(), + ip.structPtrUnwrapConst(struct_type.index).?.fields.values(), + ) |elem, field| { + assert(ip.typeOf(elem) == field.ty.toIntern()); + } + }, + .anon_struct_type => |anon_struct_type| { + for (aggregate.storage.values(), anon_struct_type.types) |elem, ty| { + assert(ip.typeOf(elem) == ty); + } }, + else => unreachable, } if (aggregate_len == 0) { |
