authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-03-29 20:18:09-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-03-30 20:50:48-04:00
logfb192df4f2d12dda5019e14bf6cab2693432cb36
tree4965e60a86a7d46b38f9618884153e5e6b0b5a2e
parent7580879e8bed9b0c670df110dbdaed76b2c3baf5

cbe: fix uncovered bugs


4 files changed, 102 insertions(+), 79 deletions(-)

lib/zig.h+7-11
...@@ -130,22 +130,18 @@ typedef char bool;...@@ -130,22 +130,18 @@ typedef char bool;
130#define zig_restrict130#define zig_restrict
131#endif131#endif
132132
133#if __STDC_VERSION__ >= 201112L133#if zig_has_attribute(aligned)
134#define zig_align(alignment) _Alignas(alignment)134#define zig_under_align(alignment) __attribute__((aligned(alignment)))
135#elif zig_has_attribute(aligned)
136#define zig_align(alignment) __attribute__((aligned(alignment)))
137#elif _MSC_VER135#elif _MSC_VER
138#define zig_align(alignment) __declspec(align(alignment))136#define zig_under_align(alignment) __declspec(align(alignment))
139#else137#else
140#define zig_align zig_align_unavailable138#define zig_under_align zig_align_unavailable
141#endif139#endif
142140
143#if zig_has_attribute(aligned)141#if __STDC_VERSION__ >= 201112L
144#define zig_under_align(alignment) __attribute__((aligned(alignment)))142#define zig_align(alignment) _Alignas(alignment)
145#elif _MSC_VER
146#define zig_under_align(alignment) zig_align(alignment)
147#else143#else
148#define zig_align zig_align_unavailable144#define zig_align(alignment) zig_under_align(alignment)
149#endif145#endif
150146
151#if zig_has_attribute(aligned)147#if zig_has_attribute(aligned)
src/Sema.zig+5-2
...@@ -36125,7 +36125,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -36125,7 +36125,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
36125 // alignment is greater.36125 // alignment is greater.
36126 var size: u64 = 0;36126 var size: u64 = 0;
36127 var padding: u32 = 0;36127 var padding: u32 = 0;
36128 if (tag_align.compare(.gte, max_align)) {36128 if (tag_align.order(max_align).compare(.gte)) {
36129 // {Tag, Payload}36129 // {Tag, Payload}
36130 size += tag_size;36130 size += tag_size;
36131 size = max_align.forward(size);36131 size = max_align.forward(size);
...@@ -36136,7 +36136,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -36136,7 +36136,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
36136 } else {36136 } else {
36137 // {Payload, Tag}36137 // {Payload, Tag}
36138 size += max_size;36138 size += max_size;
36139 size = tag_align.forward(size);36139 size = switch (mod.getTarget().ofmt) {
36140 .c => max_align,
36141 else => tag_align,
36142 }.forward(size);
36140 size += tag_size;36143 size += tag_size;
36141 const prev_size = size;36144 const prev_size = size;
36142 size = max_align.forward(size);36145 size = max_align.forward(size);
src/codegen/c.zig+42-37
...@@ -2475,14 +2475,20 @@ pub fn genTypeDecl(...@@ -2475,14 +2475,20 @@ pub fn genTypeDecl(
2475 .basic, .pointer, .array, .vector, .function => {},2475 .basic, .pointer, .array, .vector, .function => {},
2476 .aligned => |aligned_info| {2476 .aligned => |aligned_info| {
2477 if (!found_existing) {2477 if (!found_existing) {
2478 try writer.writeAll("typedef ");
2479 try writer.print("{}", .{
2480 try renderTypePrefix(pass, global_ctype_pool, zcu, writer, aligned_info.ctype, .suffix, .{}),
2481 });
2482 try renderAlignedTypeName(writer, global_ctype);
2483 try renderTypeSuffix(pass, global_ctype_pool, zcu, writer, aligned_info.ctype, .suffix, .{});
2484 std.debug.assert(aligned_info.alignas.abiOrder().compare(.lt));2478 std.debug.assert(aligned_info.alignas.abiOrder().compare(.lt));
2485 try writer.print(" zig_under_align({d});\n", .{aligned_info.alignas.toByteUnits()});2479 try writer.print("typedef zig_under_align({d}) ", .{aligned_info.alignas.toByteUnits()});
2480 try writer.print("{}", .{try renderTypePrefix(
2481 .flush,
2482 global_ctype_pool,
2483 zcu,
2484 writer,
2485 aligned_info.ctype,
2486 .suffix,
2487 .{},
2488 )});
2489 try renderAlignedTypeName(writer, global_ctype);
2490 try renderTypeSuffix(.flush, global_ctype_pool, zcu, writer, aligned_info.ctype, .suffix, .{});
2491 try writer.writeAll(";\n");
2486 }2492 }
2487 switch (pass) {2493 switch (pass) {
2488 .decl, .anon => {2494 .decl, .anon => {
...@@ -5032,15 +5038,18 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5032,15 +5038,18 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5032 const result = result: {5038 const result = result: {
5033 const writer = f.object.writer();5039 const writer = f.object.writer();
5034 const inst_ty = f.typeOfIndex(inst);5040 const inst_ty = f.typeOfIndex(inst);
5035 const local = if (inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) local: {5041 const inst_local = if (inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) local: {
5036 const local = try f.allocLocal(inst, inst_ty);5042 const inst_local = try f.allocLocalValue(.{
5043 .ctype = try f.ctypeFromType(inst_ty, .complete),
5044 .alignas = CType.AlignAs.fromAbiAlignment(inst_ty.abiAlignment(zcu)),
5045 });
5037 if (f.wantSafety()) {5046 if (f.wantSafety()) {
5038 try f.writeCValue(writer, local, .Other);5047 try f.writeCValue(writer, inst_local, .Other);
5039 try writer.writeAll(" = ");5048 try writer.writeAll(" = ");
5040 try f.writeCValue(writer, .{ .undef = inst_ty }, .Other);5049 try f.writeCValue(writer, .{ .undef = inst_ty }, .Other);
5041 try writer.writeAll(";\n");5050 try writer.writeAll(";\n");
5042 }5051 }
5043 break :local local;5052 break :local inst_local;
5044 } else .none;5053 } else .none;
50455054
5046 const locals_begin = @as(LocalIndex, @intCast(f.locals.items.len));5055 const locals_begin = @as(LocalIndex, @intCast(f.locals.items.len));
...@@ -5063,9 +5072,12 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5063,9 +5072,12 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5063 if (is_reg) {5072 if (is_reg) {
5064 const output_ty = if (output == .none) inst_ty else f.typeOf(output).childType(zcu);5073 const output_ty = if (output == .none) inst_ty else f.typeOf(output).childType(zcu);
5065 try writer.writeAll("register ");5074 try writer.writeAll("register ");
5066 const local_value = try f.allocLocal(inst, output_ty);5075 const output_local = try f.allocLocalValue(.{
5067 try f.allocs.put(gpa, local_value.new_local, false);5076 .ctype = try f.ctypeFromType(output_ty, .complete),
5068 try f.object.dg.renderTypeAndName(writer, output_ty, local_value, .{}, .none, .complete);5077 .alignas = CType.AlignAs.fromAbiAlignment(output_ty.abiAlignment(zcu)),
5078 });
5079 try f.allocs.put(gpa, output_local.new_local, false);
5080 try f.object.dg.renderTypeAndName(writer, output_ty, output_local, .{}, .none, .complete);
5069 try writer.writeAll(" __asm(\"");5081 try writer.writeAll(" __asm(\"");
5070 try writer.writeAll(constraint["={".len .. constraint.len - "}".len]);5082 try writer.writeAll(constraint["={".len .. constraint.len - "}".len]);
5071 try writer.writeAll("\")");5083 try writer.writeAll("\")");
...@@ -5095,9 +5107,12 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5095,9 +5107,12 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5095 if (asmInputNeedsLocal(f, constraint, input_val)) {5107 if (asmInputNeedsLocal(f, constraint, input_val)) {
5096 const input_ty = f.typeOf(input);5108 const input_ty = f.typeOf(input);
5097 if (is_reg) try writer.writeAll("register ");5109 if (is_reg) try writer.writeAll("register ");
5098 const local_value = try f.allocLocal(inst, input_ty);5110 const input_local = try f.allocLocalValue(.{
5099 try f.allocs.put(gpa, local_value.new_local, false);5111 .ctype = try f.ctypeFromType(input_ty, .complete),
5100 try f.object.dg.renderTypeAndName(writer, input_ty, local_value, Const, .none, .complete);5112 .alignas = CType.AlignAs.fromAbiAlignment(input_ty.abiAlignment(zcu)),
5113 });
5114 try f.allocs.put(gpa, input_local.new_local, false);
5115 try f.object.dg.renderTypeAndName(writer, input_ty, input_local, Const, .none, .complete);
5101 if (is_reg) {5116 if (is_reg) {
5102 try writer.writeAll(" __asm(\"");5117 try writer.writeAll(" __asm(\"");
5103 try writer.writeAll(constraint["{".len .. constraint.len - "}".len]);5118 try writer.writeAll(constraint["{".len .. constraint.len - "}".len]);
...@@ -5190,7 +5205,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5190,7 +5205,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5190 try f.writeCValue(writer, .{ .local = locals_index }, .Other);5205 try f.writeCValue(writer, .{ .local = locals_index }, .Other);
5191 locals_index += 1;5206 locals_index += 1;
5192 } else if (output == .none) {5207 } else if (output == .none) {
5193 try f.writeCValue(writer, local, .FunctionArgument);5208 try f.writeCValue(writer, inst_local, .FunctionArgument);
5194 } else {5209 } else {
5195 try f.writeCValueDeref(writer, try f.resolveInst(output));5210 try f.writeCValueDeref(writer, try f.resolveInst(output));
5196 }5211 }
...@@ -5246,7 +5261,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5246,7 +5261,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5246 const is_reg = constraint[1] == '{';5261 const is_reg = constraint[1] == '{';
5247 if (is_reg) {5262 if (is_reg) {
5248 try f.writeCValueDeref(writer, if (output == .none)5263 try f.writeCValueDeref(writer, if (output == .none)
5249 .{ .local_ref = local.new_local }5264 .{ .local_ref = inst_local.new_local }
5250 else5265 else
5251 try f.resolveInst(output));5266 try f.resolveInst(output));
5252 try writer.writeAll(" = ");5267 try writer.writeAll(" = ");
...@@ -5256,7 +5271,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5256,7 +5271,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5256 }5271 }
5257 }5272 }
52585273
5259 break :result if (f.liveness.isUnused(inst)) .none else local;5274 break :result if (f.liveness.isUnused(inst)) .none else inst_local;
5260 };5275 };
52615276
5262 var bt = iterateBigTomb(f, inst);5277 var bt = iterateBigTomb(f, inst);
...@@ -6690,25 +6705,15 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6690,25 +6705,15 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
6690 try writeSliceOrPtr(f, writer, src_ptr, src_ty);6705 try writeSliceOrPtr(f, writer, src_ptr, src_ty);
6691 try writer.writeAll(", ");6706 try writer.writeAll(", ");
6692 switch (dest_ty.ptrSize(zcu)) {6707 switch (dest_ty.ptrSize(zcu)) {
6693 .Slice => {6708 .One => try writer.print("{}", .{
6694 const elem_ty = dest_ty.childType(zcu);6709 try f.fmtIntLiteral(try zcu.intValue(Type.usize, dest_ty.childType(zcu).arrayLen(zcu))),
6695 const elem_abi_size = elem_ty.abiSize(zcu);6710 }),
6696 try f.writeCValueMember(writer, dest_ptr, .{ .identifier = "len" });
6697 if (elem_abi_size > 1) {
6698 try writer.print(" * {d});\n", .{elem_abi_size});
6699 } else {
6700 try writer.writeAll(");\n");
6701 }
6702 },
6703 .One => {
6704 const array_ty = dest_ty.childType(zcu);
6705 const elem_ty = array_ty.childType(zcu);
6706 const elem_abi_size = elem_ty.abiSize(zcu);
6707 const len = array_ty.arrayLen(zcu) * elem_abi_size;
6708 try writer.print("{d});\n", .{len});
6709 },
6710 .Many, .C => unreachable,6711 .Many, .C => unreachable,
6712 .Slice => try f.writeCValueMember(writer, dest_ptr, .{ .identifier = "len" }),
6711 }6713 }
6714 try writer.writeAll(" * sizeof(");
6715 try f.renderType(writer, dest_ty.elemType2(zcu));
6716 try writer.writeAll("));\n");
67126717
6713 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6718 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
6714 return .none;6719 return .none;
src/codegen/c/Type.zig+48-29
...@@ -734,6 +734,8 @@ pub const Info = union(enum) {...@@ -734,6 +734,8 @@ pub const Info = union(enum) {
734 aggregate: Aggregate,734 aggregate: Aggregate,
735 function: Function,735 function: Function,
736736
737 const Tag = @typeInfo(Info).Union.tag_type.?;
738
737 pub const Pointer = struct {739 pub const Pointer = struct {
738 elem_ctype: CType,740 elem_ctype: CType,
739 @"const": bool = false,741 @"const": bool = false,
...@@ -761,7 +763,7 @@ pub const Info = union(enum) {...@@ -761,7 +763,7 @@ pub const Info = union(enum) {
761 len: u64,763 len: u64,
762 };764 };
763765
764 pub const Tag = enum { @"enum", @"struct", @"union" };766 pub const AggregateTag = enum { @"enum", @"struct", @"union" };
765767
766 pub const Field = struct {768 pub const Field = struct {
767 name: String,769 name: String,
...@@ -820,7 +822,7 @@ pub const Info = union(enum) {...@@ -820,7 +822,7 @@ pub const Info = union(enum) {
820 };822 };
821823
822 pub const FwdDecl = struct {824 pub const FwdDecl = struct {
823 tag: Tag,825 tag: AggregateTag,
824 name: union(enum) {826 name: union(enum) {
825 anon: Field.Slice,827 anon: Field.Slice,
826 owner_decl: DeclIndex,828 owner_decl: DeclIndex,
...@@ -828,7 +830,7 @@ pub const Info = union(enum) {...@@ -828,7 +830,7 @@ pub const Info = union(enum) {
828 };830 };
829831
830 pub const Aggregate = struct {832 pub const Aggregate = struct {
831 tag: Tag,833 tag: AggregateTag,
832 @"packed": bool = false,834 @"packed": bool = false,
833 name: union(enum) {835 name: union(enum) {
834 anon: struct {836 anon: struct {
...@@ -853,9 +855,8 @@ pub const Info = union(enum) {...@@ -853,9 +855,8 @@ pub const Info = union(enum) {
853 rhs_pool: *const Pool,855 rhs_pool: *const Pool,
854 pool_adapter: anytype,856 pool_adapter: anytype,
855 ) bool {857 ) bool {
856 const InfoTag = @typeInfo(Info).Union.tag_type.?;
857 const rhs_info = rhs_ctype.info(rhs_pool);858 const rhs_info = rhs_ctype.info(rhs_pool);
858 if (@as(InfoTag, lhs_info) != @as(InfoTag, rhs_info)) return false;859 if (@as(Info.Tag, lhs_info) != @as(Info.Tag, rhs_info)) return false;
859 return switch (lhs_info) {860 return switch (lhs_info) {
860 .basic => |lhs_basic_info| lhs_basic_info == rhs_info.basic,861 .basic => |lhs_basic_info| lhs_basic_info == rhs_info.basic,
861 .pointer => |lhs_pointer_info| lhs_pointer_info.@"const" == rhs_info.pointer.@"const" and862 .pointer => |lhs_pointer_info| lhs_pointer_info.@"const" == rhs_info.pointer.@"const" and
...@@ -1012,7 +1013,7 @@ pub const Pool = struct {...@@ -1012,7 +1013,7 @@ pub const Pool = struct {
1012 pool: *Pool,1013 pool: *Pool,
1013 allocator: std.mem.Allocator,1014 allocator: std.mem.Allocator,
1014 fwd_decl_info: struct {1015 fwd_decl_info: struct {
1015 tag: Info.Tag,1016 tag: Info.AggregateTag,
1016 name: union(enum) {1017 name: union(enum) {
1017 anon: []const Info.Field,1018 anon: []const Info.Field,
1018 owner_decl: DeclIndex,1019 owner_decl: DeclIndex,
...@@ -1070,7 +1071,7 @@ pub const Pool = struct {...@@ -1070,7 +1071,7 @@ pub const Pool = struct {
1070 pool: *Pool,1071 pool: *Pool,
1071 allocator: std.mem.Allocator,1072 allocator: std.mem.Allocator,
1072 aggregate_info: struct {1073 aggregate_info: struct {
1073 tag: Info.Tag,1074 tag: Info.AggregateTag,
1074 @"packed": bool = false,1075 @"packed": bool = false,
1075 name: union(enum) {1076 name: union(enum) {
1076 anon: struct {1077 anon: struct {
...@@ -1175,7 +1176,7 @@ pub const Pool = struct {...@@ -1175,7 +1176,7 @@ pub const Pool = struct {
1175 pub fn fromFields(1176 pub fn fromFields(
1176 pool: *Pool,1177 pool: *Pool,
1177 allocator: std.mem.Allocator,1178 allocator: std.mem.Allocator,
1178 tag: Info.Tag,1179 tag: Info.AggregateTag,
1179 fields: []Info.Field,1180 fields: []Info.Field,
1180 kind: Kind,1181 kind: Kind,
1181 ) !CType {1182 ) !CType {
...@@ -1390,8 +1391,8 @@ pub const Pool = struct {...@@ -1390,8 +1391,8 @@ pub const Pool = struct {
1390 else => |ip_index| switch (ip.indexToKey(ip_index)) {1391 else => |ip_index| switch (ip.indexToKey(ip_index)) {
1391 .int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),1392 .int_type => |int_info| return pool.fromIntInfo(allocator, int_info, mod, kind),
1392 .ptr_type => |ptr_info| switch (ptr_info.flags.size) {1393 .ptr_type => |ptr_info| switch (ptr_info.flags.size) {
1393 .One, .Many, .C => return pool.getPointer(allocator, .{1394 .One, .Many, .C => {
1394 .elem_ctype = elem_ctype: {1395 const elem_ctype = elem_ctype: {
1395 if (ptr_info.packed_offset.host_size > 0 and1396 if (ptr_info.packed_offset.host_size > 0 and
1396 ptr_info.flags.vector_index == .none)1397 ptr_info.flags.vector_index == .none)
1397 break :elem_ctype try pool.fromIntInfo(allocator, .{1398 break :elem_ctype try pool.fromIntInfo(allocator, .{
...@@ -1412,13 +1413,31 @@ pub const Pool = struct {...@@ -1412,13 +1413,31 @@ pub const Pool = struct {
1412 .abi = Type.fromInterned(ptr_info.child).abiAlignment(zcu),1413 .abi = Type.fromInterned(ptr_info.child).abiAlignment(zcu),
1413 }),1414 }),
1414 };1415 };
1415 if (elem.alignas.abiOrder().compare(.gte))1416 break :elem_ctype if (elem.alignas.abiOrder().compare(.gte))
1416 break :elem_ctype elem.ctype;1417 elem.ctype
1417 break :elem_ctype try pool.getAligned(allocator, elem);1418 else
1418 },1419 try pool.getAligned(allocator, elem);
1419 .@"const" = ptr_info.flags.is_const,1420 };
1420 .@"volatile" = ptr_info.flags.is_volatile,1421 const elem_tag: Info.Tag = switch (elem_ctype.info(pool)) {
1421 }),1422 .aligned => |aligned_info| aligned_info.ctype.info(pool),
1423 else => |elem_tag| elem_tag,
1424 };
1425 return pool.getPointer(allocator, .{
1426 .elem_ctype = elem_ctype,
1427 .@"const" = switch (elem_tag) {
1428 .basic,
1429 .pointer,
1430 .aligned,
1431 .array,
1432 .vector,
1433 .fwd_decl,
1434 .aggregate,
1435 => ptr_info.flags.is_const,
1436 .function => false,
1437 },
1438 .@"volatile" = ptr_info.flags.is_volatile,
1439 });
1440 },
1422 .Slice => {1441 .Slice => {
1423 const target = &mod.resolved_target.result;1442 const target = &mod.resolved_target.result;
1424 var fields = [_]Info.Field{1443 var fields = [_]Info.Field{
...@@ -1589,7 +1608,7 @@ pub const Pool = struct {...@@ -1589,7 +1608,7 @@ pub const Pool = struct {
1589 loaded_struct.field_types.len * @typeInfo(Field).Struct.fields.len,1608 loaded_struct.field_types.len * @typeInfo(Field).Struct.fields.len,
1590 );1609 );
1591 var hasher = Hasher.init;1610 var hasher = Hasher.init;
1592 var tag: Tag = .aggregate_struct;1611 var tag: Pool.Tag = .aggregate_struct;
1593 var field_it = loaded_struct.iterateRuntimeOrder(ip);1612 var field_it = loaded_struct.iterateRuntimeOrder(ip);
1594 while (field_it.next()) |field_index| {1613 while (field_it.next()) |field_index| {
1595 const field_type = Type.fromInterned(1614 const field_type = Type.fromInterned(
...@@ -1729,7 +1748,7 @@ pub const Pool = struct {...@@ -1729,7 +1748,7 @@ pub const Pool = struct {
1729 loaded_union.field_types.len * @typeInfo(Field).Struct.fields.len,1748 loaded_union.field_types.len * @typeInfo(Field).Struct.fields.len,
1730 );1749 );
1731 var hasher = Hasher.init;1750 var hasher = Hasher.init;
1732 var tag: Tag = .aggregate_union;1751 var tag: Pool.Tag = .aggregate_union;
1733 var payload_align: Alignment = .@"1";1752 var payload_align: Alignment = .@"1";
1734 for (0..loaded_union.field_types.len) |field_index| {1753 for (0..loaded_union.field_types.len) |field_index| {
1735 const field_type = Type.fromInterned(1754 const field_type = Type.fromInterned(
...@@ -2093,7 +2112,7 @@ pub const Pool = struct {...@@ -2093,7 +2112,7 @@ pub const Pool = struct {
2093 inline for (@typeInfo(Extra).Struct.fields) |field| {2112 inline for (@typeInfo(Extra).Struct.fields) |field| {
2094 const value = @field(extra, field.name);2113 const value = @field(extra, field.name);
2095 hasher.update(switch (field.type) {2114 hasher.update(switch (field.type) {
2096 Tag, String, CType => unreachable,2115 Pool.Tag, String, CType => unreachable,
2097 CType.Index => (CType{ .index = value }).hash(pool),2116 CType.Index => (CType{ .index = value }).hash(pool),
2098 String.Index => (String{ .index = value }).slice(pool),2117 String.Index => (String{ .index = value }).slice(pool),
2099 else => value,2118 else => value,
...@@ -2102,7 +2121,7 @@ pub const Pool = struct {...@@ -2102,7 +2121,7 @@ pub const Pool = struct {
2102 }2121 }
2103 fn update(hasher: *Hasher, data: anytype) void {2122 fn update(hasher: *Hasher, data: anytype) void {
2104 switch (@TypeOf(data)) {2123 switch (@TypeOf(data)) {
2105 Tag => @compileError("pass tag to final"),2124 Pool.Tag => @compileError("pass tag to final"),
2106 CType, CType.Index => @compileError("hash ctype.hash(pool) instead"),2125 CType, CType.Index => @compileError("hash ctype.hash(pool) instead"),
2107 String, String.Index => @compileError("hash string.slice(pool) instead"),2126 String, String.Index => @compileError("hash string.slice(pool) instead"),
2108 u32, DeclIndex, Aligned.Flags => hasher.impl.update(std.mem.asBytes(&data)),2127 u32, DeclIndex, Aligned.Flags => hasher.impl.update(std.mem.asBytes(&data)),
...@@ -2111,7 +2130,7 @@ pub const Pool = struct {...@@ -2111,7 +2130,7 @@ pub const Pool = struct {
2111 }2130 }
2112 }2131 }
21132132
2114 fn final(hasher: Hasher, tag: Tag) Map.Hash {2133 fn final(hasher: Hasher, tag: Pool.Tag) Map.Hash {
2115 var impl = hasher.impl;2134 var impl = hasher.impl;
2116 impl.update(std.mem.asBytes(&tag));2135 impl.update(std.mem.asBytes(&tag));
2117 return @truncate(impl.final());2136 return @truncate(impl.final());
...@@ -2122,11 +2141,11 @@ pub const Pool = struct {...@@ -2122,11 +2141,11 @@ pub const Pool = struct {
2122 pool: *Pool,2141 pool: *Pool,
2123 allocator: std.mem.Allocator,2142 allocator: std.mem.Allocator,
2124 hasher: Hasher,2143 hasher: Hasher,
2125 tag: Tag,2144 tag: Pool.Tag,
2126 data: u32,2145 data: u32,
2127 ) !CType {2146 ) !CType {
2128 try pool.ensureUnusedCapacity(allocator, 1);2147 try pool.ensureUnusedCapacity(allocator, 1);
2129 const Key = struct { hash: Map.Hash, tag: Tag, data: u32 };2148 const Key = struct { hash: Map.Hash, tag: Pool.Tag, data: u32 };
2130 const CTypeAdapter = struct {2149 const CTypeAdapter = struct {
2131 pool: *const Pool,2150 pool: *const Pool,
2132 pub fn hash(_: @This(), key: Key) Map.Hash {2151 pub fn hash(_: @This(), key: Key) Map.Hash {
...@@ -2148,7 +2167,7 @@ pub const Pool = struct {...@@ -2148,7 +2167,7 @@ pub const Pool = struct {
2148 fn tagExtra(2167 fn tagExtra(
2149 pool: *Pool,2168 pool: *Pool,
2150 allocator: std.mem.Allocator,2169 allocator: std.mem.Allocator,
2151 tag: Tag,2170 tag: Pool.Tag,
2152 comptime Extra: type,2171 comptime Extra: type,
2153 extra: Extra,2172 extra: Extra,
2154 ) !CType {2173 ) !CType {
...@@ -2166,7 +2185,7 @@ pub const Pool = struct {...@@ -2166,7 +2185,7 @@ pub const Pool = struct {
2166 pool: *Pool,2185 pool: *Pool,
2167 allocator: std.mem.Allocator,2186 allocator: std.mem.Allocator,
2168 hasher: Hasher,2187 hasher: Hasher,
2169 tag: Tag,2188 tag: Pool.Tag,
2170 extra_index: ExtraIndex,2189 extra_index: ExtraIndex,
2171 ) !CType {2190 ) !CType {
2172 try pool.ensureUnusedCapacity(allocator, 1);2191 try pool.ensureUnusedCapacity(allocator, 1);
...@@ -2176,10 +2195,10 @@ pub const Pool = struct {...@@ -2176,10 +2195,10 @@ pub const Pool = struct {
2176 fn tagTrailingExtraAssumeCapacity(2195 fn tagTrailingExtraAssumeCapacity(
2177 pool: *Pool,2196 pool: *Pool,
2178 hasher: Hasher,2197 hasher: Hasher,
2179 tag: Tag,2198 tag: Pool.Tag,
2180 extra_index: ExtraIndex,2199 extra_index: ExtraIndex,
2181 ) CType {2200 ) CType {
2182 const Key = struct { hash: Map.Hash, tag: Tag, extra: []const u32 };2201 const Key = struct { hash: Map.Hash, tag: Pool.Tag, extra: []const u32 };
2183 const CTypeAdapter = struct {2202 const CTypeAdapter = struct {
2184 pool: *const Pool,2203 pool: *const Pool,
2185 pub fn hash(_: @This(), key: Key) Map.Hash {2204 pub fn hash(_: @This(), key: Key) Map.Hash {
...@@ -2239,7 +2258,7 @@ pub const Pool = struct {...@@ -2239,7 +2258,7 @@ pub const Pool = struct {
2239 }2258 }
22402259
2241 const Item = struct {2260 const Item = struct {
2242 tag: Tag,2261 tag: Pool.Tag,
2243 data: u32,2262 data: u32,
2244 };2263 };
22452264