authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-03 20:40:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:40:04-07:00
log9d422bff18dbb92d3a6b8705c3dae7404a34bba6
treea8ddd594c5e334ecea3f0c9fb2822b57016c7201
parent85c69c51945d7fb5d4cd2dea03fdb7915ecc55fa

stage2: move all integer types to InternPool


8 files changed, 106 insertions(+), 399 deletions(-)

src/AstGen.zig+22-1
......@@ -10271,6 +10271,8 @@ fn rvalue(
1027110271 as_ty | @enumToInt(Zir.Inst.Ref.i32_type),
1027210272 as_ty | @enumToInt(Zir.Inst.Ref.u64_type),
1027310273 as_ty | @enumToInt(Zir.Inst.Ref.i64_type),
10274 as_ty | @enumToInt(Zir.Inst.Ref.u128_type),
10275 as_ty | @enumToInt(Zir.Inst.Ref.i128_type),
1027410276 as_ty | @enumToInt(Zir.Inst.Ref.usize_type),
1027510277 as_ty | @enumToInt(Zir.Inst.Ref.isize_type),
1027610278 as_ty | @enumToInt(Zir.Inst.Ref.c_char_type),
......@@ -10296,11 +10298,30 @@ fn rvalue(
1029610298 as_ty | @enumToInt(Zir.Inst.Ref.comptime_int_type),
1029710299 as_ty | @enumToInt(Zir.Inst.Ref.comptime_float_type),
1029810300 as_ty | @enumToInt(Zir.Inst.Ref.noreturn_type),
10301 as_ty | @enumToInt(Zir.Inst.Ref.anyframe_type),
1029910302 as_ty | @enumToInt(Zir.Inst.Ref.null_type),
1030010303 as_ty | @enumToInt(Zir.Inst.Ref.undefined_type),
10304 as_ty | @enumToInt(Zir.Inst.Ref.enum_literal_type),
10305 as_ty | @enumToInt(Zir.Inst.Ref.atomic_order_type),
10306 as_ty | @enumToInt(Zir.Inst.Ref.atomic_rmw_op_type),
10307 as_ty | @enumToInt(Zir.Inst.Ref.calling_convention_type),
10308 as_ty | @enumToInt(Zir.Inst.Ref.address_space_type),
10309 as_ty | @enumToInt(Zir.Inst.Ref.float_mode_type),
10310 as_ty | @enumToInt(Zir.Inst.Ref.reduce_op_type),
10311 as_ty | @enumToInt(Zir.Inst.Ref.call_modifier_type),
10312 as_ty | @enumToInt(Zir.Inst.Ref.prefetch_options_type),
10313 as_ty | @enumToInt(Zir.Inst.Ref.export_options_type),
10314 as_ty | @enumToInt(Zir.Inst.Ref.extern_options_type),
10315 as_ty | @enumToInt(Zir.Inst.Ref.type_info_type),
10316 as_ty | @enumToInt(Zir.Inst.Ref.manyptr_u8_type),
10317 as_ty | @enumToInt(Zir.Inst.Ref.manyptr_const_u8_type),
10318 as_ty | @enumToInt(Zir.Inst.Ref.manyptr_const_u8_sentinel_0_type),
1030110319 as_ty | @enumToInt(Zir.Inst.Ref.single_const_pointer_to_comptime_int_type),
1030210320 as_ty | @enumToInt(Zir.Inst.Ref.const_slice_u8_type),
10303 as_ty | @enumToInt(Zir.Inst.Ref.enum_literal_type),
10321 as_ty | @enumToInt(Zir.Inst.Ref.const_slice_u8_sentinel_0_type),
10322 as_ty | @enumToInt(Zir.Inst.Ref.anyerror_void_error_union_type),
10323 as_ty | @enumToInt(Zir.Inst.Ref.generic_poison_type),
10324 as_ty | @enumToInt(Zir.Inst.Ref.empty_struct_type),
1030410325 as_comptime_int | @enumToInt(Zir.Inst.Ref.zero),
1030510326 as_comptime_int | @enumToInt(Zir.Inst.Ref.one),
1030610327 as_bool | @enumToInt(Zir.Inst.Ref.bool_true),
src/Sema.zig-52
......@@ -31478,19 +31478,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3147831478 };
3147931479
3148031480 return switch (ty.tag()) {
31481 .u1,
31482 .u8,
31483 .i8,
31484 .u16,
31485 .i16,
31486 .u29,
31487 .u32,
31488 .i32,
31489 .u64,
31490 .i64,
31491 .u128,
31492 .i128,
31493
3149431481 .manyptr_u8,
3149531482 .manyptr_const_u8,
3149631483 .manyptr_const_u8_sentinel_0,
......@@ -32971,19 +32958,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3297132958 };
3297232959
3297332960 switch (ty.tag()) {
32974 .u1,
32975 .u8,
32976 .i8,
32977 .u16,
32978 .i16,
32979 .u29,
32980 .u32,
32981 .i32,
32982 .u64,
32983 .i64,
32984 .u128,
32985 .i128,
32986
3298732961 .error_set_single,
3298832962 .error_set,
3298932963 .error_set_merged,
......@@ -33175,19 +33149,6 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
3317533149 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3317633150 }
3317733151 switch (ty.tag()) {
33178 .u1 => return .u1_type,
33179 .u8 => return .u8_type,
33180 .i8 => return .i8_type,
33181 .u16 => return .u16_type,
33182 .u29 => return .u29_type,
33183 .i16 => return .i16_type,
33184 .u32 => return .u32_type,
33185 .i32 => return .i32_type,
33186 .u64 => return .u64_type,
33187 .i64 => return .i64_type,
33188 .u128 => return .u128_type,
33189 .i128 => return .i128_type,
33190
3319133152 .manyptr_u8 => return .manyptr_u8_type,
3319233153 .manyptr_const_u8 => return .manyptr_const_u8_type,
3319333154 .single_const_pointer_to_comptime_int => return .single_const_pointer_to_comptime_int_type,
......@@ -33617,19 +33578,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3361733578 }
3361833579 }
3361933580 return switch (ty.tag()) {
33620 .u1,
33621 .u8,
33622 .i8,
33623 .u16,
33624 .i16,
33625 .u29,
33626 .u32,
33627 .i32,
33628 .u64,
33629 .i64,
33630 .u128,
33631 .i128,
33632
3363333581 .manyptr_u8,
3363433582 .manyptr_const_u8,
3363533583 .manyptr_const_u8_sentinel_0,
src/arch/aarch64/CodeGen.zig+11-11
......@@ -2577,7 +2577,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
25772577 });
25782578
25792579 try self.genSetStack(lhs_ty, stack_offset, .{ .register = truncated_reg });
2580 try self.genSetStack(Type.initTag(.u1), stack_offset - overflow_bit_offset, .{ .compare_flags = .ne });
2580 try self.genSetStack(Type.u1, stack_offset - overflow_bit_offset, .{ .compare_flags = .ne });
25812581
25822582 break :result MCValue{ .stack_offset = stack_offset };
25832583 },
......@@ -2720,7 +2720,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
27202720 }
27212721
27222722 try self.genSetStack(lhs_ty, stack_offset, .{ .register = truncated_reg });
2723 try self.genSetStack(Type.initTag(.u1), stack_offset - overflow_bit_offset, .{ .compare_flags = .ne });
2723 try self.genSetStack(Type.u1, stack_offset - overflow_bit_offset, .{ .compare_flags = .ne });
27242724
27252725 break :result MCValue{ .stack_offset = stack_offset };
27262726 } else if (int_info.bits <= 64) {
......@@ -2860,7 +2860,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
28602860 try self.truncRegister(dest_reg, truncated_reg, int_info.signedness, int_info.bits);
28612861
28622862 try self.genSetStack(lhs_ty, stack_offset, .{ .register = truncated_reg });
2863 try self.genSetStack(Type.initTag(.u1), stack_offset - overflow_bit_offset, .{ .compare_flags = .ne });
2863 try self.genSetStack(Type.u1, stack_offset - overflow_bit_offset, .{ .compare_flags = .ne });
28642864
28652865 break :result MCValue{ .stack_offset = stack_offset };
28662866 } else return self.fail("TODO implement mul_with_overflow for integers > u64/i64", .{});
......@@ -2993,7 +2993,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
29932993 });
29942994
29952995 try self.genSetStack(lhs_ty, stack_offset, .{ .register = dest_reg });
2996 try self.genSetStack(Type.initTag(.u1), stack_offset - overflow_bit_offset, .{ .compare_flags = .ne });
2996 try self.genSetStack(Type.u1, stack_offset - overflow_bit_offset, .{ .compare_flags = .ne });
29972997
29982998 break :result MCValue{ .stack_offset = stack_offset };
29992999 } else {
......@@ -3780,7 +3780,7 @@ fn genInlineMemset(
37803780
37813781 const val_reg = switch (val) {
37823782 .register => |r| r,
3783 else => try self.copyToTmpRegister(Type.initTag(.u8), val),
3783 else => try self.copyToTmpRegister(Type.u8, val),
37843784 };
37853785 const val_reg_lock = self.register_manager.lockReg(val_reg);
37863786 defer if (val_reg_lock) |lock| self.register_manager.unlockReg(lock);
......@@ -4330,7 +4330,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43304330 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {
43314331 const atom = try macho_file.getOrCreateAtomForDecl(func.owner_decl);
43324332 const sym_index = macho_file.getAtom(atom).getSymbolIndex().?;
4333 try self.genSetReg(Type.initTag(.u64), .x30, .{
4333 try self.genSetReg(Type.u64, .x30, .{
43344334 .linker_load = .{
43354335 .type = .got,
43364336 .sym_index = sym_index,
......@@ -4339,7 +4339,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43394339 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
43404340 const atom = try coff_file.getOrCreateAtomForDecl(func.owner_decl);
43414341 const sym_index = coff_file.getAtom(atom).getSymbolIndex().?;
4342 try self.genSetReg(Type.initTag(.u64), .x30, .{
4342 try self.genSetReg(Type.u64, .x30, .{
43434343 .linker_load = .{
43444344 .type = .got,
43454345 .sym_index = sym_index,
......@@ -4379,7 +4379,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43794379 });
43804380 } else if (self.bin_file.cast(link.File.Coff)) |coff_file| {
43814381 const sym_index = try coff_file.getGlobalSymbol(decl_name, lib_name);
4382 try self.genSetReg(Type.initTag(.u64), .x30, .{
4382 try self.genSetReg(Type.u64, .x30, .{
43834383 .linker_load = .{
43844384 .type = .import,
43854385 .sym_index = sym_index,
......@@ -4536,7 +4536,7 @@ fn cmp(
45364536 var opt_buffer: Type.Payload.ElemType = undefined;
45374537 const payload_ty = lhs_ty.optionalChild(&opt_buffer);
45384538 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
4539 break :blk Type.initTag(.u1);
4539 break :blk Type.u1;
45404540 } else if (lhs_ty.isPtrLikeOptional(mod)) {
45414541 break :blk Type.usize;
45424542 } else {
......@@ -4546,9 +4546,9 @@ fn cmp(
45464546 .Float => return self.fail("TODO ARM cmp floats", .{}),
45474547 .Enum => lhs_ty.intTagType(),
45484548 .Int => lhs_ty,
4549 .Bool => Type.initTag(.u1),
4549 .Bool => Type.u1,
45504550 .Pointer => Type.usize,
4551 .ErrorSet => Type.initTag(.u16),
4551 .ErrorSet => Type.u16,
45524552 else => unreachable,
45534553 };
45544554
src/arch/arm/CodeGen.zig+12-12
......@@ -1637,7 +1637,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
16371637 });
16381638
16391639 try self.genSetStack(lhs_ty, stack_offset, .{ .register = truncated_reg });
1640 try self.genSetStack(Type.initTag(.u1), stack_offset - overflow_bit_offset, .{ .cpsr_flags = .ne });
1640 try self.genSetStack(Type.u1, stack_offset - overflow_bit_offset, .{ .cpsr_flags = .ne });
16411641
16421642 break :result MCValue{ .stack_offset = stack_offset };
16431643 } else if (int_info.bits == 32) {
......@@ -1750,7 +1750,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
17501750 });
17511751
17521752 try self.genSetStack(lhs_ty, stack_offset, .{ .register = truncated_reg });
1753 try self.genSetStack(Type.initTag(.u1), stack_offset - overflow_bit_offset, .{ .cpsr_flags = .ne });
1753 try self.genSetStack(Type.u1, stack_offset - overflow_bit_offset, .{ .cpsr_flags = .ne });
17541754
17551755 break :result MCValue{ .stack_offset = stack_offset };
17561756 } else if (int_info.bits <= 32) {
......@@ -1848,7 +1848,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
18481848 });
18491849
18501850 // strb rdlo, [...]
1851 try self.genSetStack(Type.initTag(.u1), stack_offset - overflow_bit_offset, .{ .register = rdlo });
1851 try self.genSetStack(Type.u1, stack_offset - overflow_bit_offset, .{ .register = rdlo });
18521852
18531853 break :result MCValue{ .stack_offset = stack_offset };
18541854 } else {
......@@ -1983,7 +1983,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
19831983 });
19841984
19851985 try self.genSetStack(lhs_ty, stack_offset, .{ .register = dest_reg });
1986 try self.genSetStack(Type.initTag(.u1), stack_offset - overflow_bit_offset, .{ .cpsr_flags = .ne });
1986 try self.genSetStack(Type.u1, stack_offset - overflow_bit_offset, .{ .cpsr_flags = .ne });
19871987
19881988 break :result MCValue{ .stack_offset = stack_offset };
19891989 } else {
......@@ -4086,7 +4086,7 @@ fn genInlineMemset(
40864086
40874087 const val_reg = switch (val) {
40884088 .register => |r| r,
4089 else => try self.copyToTmpRegister(Type.initTag(.u8), val),
4089 else => try self.copyToTmpRegister(Type.u8, val),
40904090 };
40914091 const val_reg_lock = self.register_manager.lockReg(val_reg);
40924092 defer if (val_reg_lock) |lock| self.register_manager.unlockReg(lock);
......@@ -4485,7 +4485,7 @@ fn cmp(
44854485 var opt_buffer: Type.Payload.ElemType = undefined;
44864486 const payload_ty = lhs_ty.optionalChild(&opt_buffer);
44874487 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
4488 break :blk Type.initTag(.u1);
4488 break :blk Type.u1;
44894489 } else if (lhs_ty.isPtrLikeOptional(mod)) {
44904490 break :blk Type.usize;
44914491 } else {
......@@ -4495,9 +4495,9 @@ fn cmp(
44954495 .Float => return self.fail("TODO ARM cmp floats", .{}),
44964496 .Enum => lhs_ty.intTagType(),
44974497 .Int => lhs_ty,
4498 .Bool => Type.initTag(.u1),
4498 .Bool => Type.u1,
44994499 .Pointer => Type.usize,
4500 .ErrorSet => Type.initTag(.u16),
4500 .ErrorSet => Type.u16,
45014501 else => unreachable,
45024502 };
45034503
......@@ -5367,7 +5367,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
53675367 1, 4 => {
53685368 const offset = if (math.cast(u12, stack_offset)) |imm| blk: {
53695369 break :blk Instruction.Offset.imm(imm);
5370 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.initTag(.u32), MCValue{ .immediate = stack_offset }), .none);
5370 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }), .none);
53715371
53725372 const tag: Mir.Inst.Tag = switch (abi_size) {
53735373 1 => .strb,
......@@ -5390,7 +5390,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
53905390 2 => {
53915391 const offset = if (stack_offset <= math.maxInt(u8)) blk: {
53925392 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(u8, stack_offset));
5393 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.initTag(.u32), MCValue{ .immediate = stack_offset }));
5393 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
53945394
53955395 _ = try self.addInst(.{
53965396 .tag = .strh,
......@@ -5769,7 +5769,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
57695769 1, 4 => {
57705770 const offset = if (math.cast(u12, stack_offset)) |imm| blk: {
57715771 break :blk Instruction.Offset.imm(imm);
5772 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.initTag(.u32), MCValue{ .immediate = stack_offset }), .none);
5772 } else Instruction.Offset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }), .none);
57735773
57745774 const tag: Mir.Inst.Tag = switch (abi_size) {
57755775 1 => .strb,
......@@ -5789,7 +5789,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
57895789 2 => {
57905790 const offset = if (stack_offset <= math.maxInt(u8)) blk: {
57915791 break :blk Instruction.ExtraLoadStoreOffset.imm(@intCast(u8, stack_offset));
5792 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.initTag(.u32), MCValue{ .immediate = stack_offset }));
5792 } else Instruction.ExtraLoadStoreOffset.reg(try self.copyToTmpRegister(Type.u32, MCValue{ .immediate = stack_offset }));
57935793
57945794 _ = try self.addInst(.{
57955795 .tag = .strh,
src/arch/sparc64/CodeGen.zig+3-3
......@@ -1436,14 +1436,14 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
14361436 .Vector => unreachable, // Handled by cmp_vector.
14371437 .Enum => lhs_ty.intTagType(),
14381438 .Int => lhs_ty,
1439 .Bool => Type.initTag(.u1),
1439 .Bool => Type.u1,
14401440 .Pointer => Type.usize,
1441 .ErrorSet => Type.initTag(.u16),
1441 .ErrorSet => Type.u16,
14421442 .Optional => blk: {
14431443 var opt_buffer: Type.Payload.ElemType = undefined;
14441444 const payload_ty = lhs_ty.optionalChild(&opt_buffer);
14451445 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
1446 break :blk Type.initTag(.u1);
1446 break :blk Type.u1;
14471447 } else if (lhs_ty.isPtrLikeOptional(mod)) {
14481448 break :blk Type.usize;
14491449 } else {
src/arch/wasm/CodeGen.zig+9-9
......@@ -4272,7 +4272,7 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42724272
42734273 const result = result: {
42744274 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
4275 const non_null_bit = try func.allocStack(Type.initTag(.u1));
4275 const non_null_bit = try func.allocStack(Type.u1);
42764276 try func.emitWValue(non_null_bit);
42774277 try func.addImm32(1);
42784278 try func.addMemArg(.i32_store8, .{ .offset = non_null_bit.offset(), .alignment = 1 });
......@@ -5195,7 +5195,7 @@ fn cmpOptionals(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op:
51955195
51965196 // We store the final result in here that will be validated
51975197 // if the optional is truly equal.
5198 var result = try func.ensureAllocLocal(Type.initTag(.i32));
5198 var result = try func.ensureAllocLocal(Type.i32);
51995199 defer result.free(func);
52005200
52015201 try func.startBlock(.block, wasm.block_empty);
......@@ -5658,7 +5658,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
56585658 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
56595659 try func.store(result_ptr, result, lhs_ty, 0);
56605660 const offset = @intCast(u32, lhs_ty.abiSize(mod));
5661 try func.store(result_ptr, overflow_local, Type.initTag(.u1), offset);
5661 try func.store(result_ptr, overflow_local, Type.u1, offset);
56625662
56635663 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
56645664}
......@@ -5717,13 +5717,13 @@ fn addSubWithOverflowBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type,
57175717
57185718 break :blk WValue{ .stack = {} };
57195719 };
5720 var overflow_local = try overflow_bit.toLocal(func, Type.initTag(.u1));
5720 var overflow_local = try overflow_bit.toLocal(func, Type.u1);
57215721 defer overflow_local.free(func);
57225722
57235723 const result_ptr = try func.allocStack(result_ty);
57245724 try func.store(result_ptr, high_op_res, Type.u64, 0);
57255725 try func.store(result_ptr, tmp_op, Type.u64, 8);
5726 try func.store(result_ptr, overflow_local, Type.initTag(.u1), 16);
5726 try func.store(result_ptr, overflow_local, Type.u1, 16);
57275727
57285728 return result_ptr;
57295729}
......@@ -5774,13 +5774,13 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57745774 const shr = try func.binOp(result, rhs_final, lhs_ty, .shr);
57755775 break :blk try func.cmp(.{ .stack = {} }, shr, lhs_ty, .neq);
57765776 };
5777 var overflow_local = try overflow_bit.toLocal(func, Type.initTag(.u1));
5777 var overflow_local = try overflow_bit.toLocal(func, Type.u1);
57785778 defer overflow_local.free(func);
57795779
57805780 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
57815781 try func.store(result_ptr, result, lhs_ty, 0);
57825782 const offset = @intCast(u32, lhs_ty.abiSize(mod));
5783 try func.store(result_ptr, overflow_local, Type.initTag(.u1), offset);
5783 try func.store(result_ptr, overflow_local, Type.u1, offset);
57845784
57855785 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
57865786}
......@@ -5800,7 +5800,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58005800
58015801 // We store the bit if it's overflowed or not in this. As it's zero-initialized
58025802 // we only need to update it if an overflow (or underflow) occurred.
5803 var overflow_bit = try func.ensureAllocLocal(Type.initTag(.u1));
5803 var overflow_bit = try func.ensureAllocLocal(Type.u1);
58045804 defer overflow_bit.free(func);
58055805
58065806 const int_info = lhs_ty.intInfo(mod);
......@@ -5955,7 +5955,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59555955 const result_ptr = try func.allocStack(func.typeOfIndex(inst));
59565956 try func.store(result_ptr, bin_op_local, lhs_ty, 0);
59575957 const offset = @intCast(u32, lhs_ty.abiSize(mod));
5958 try func.store(result_ptr, overflow_bit, Type.initTag(.u1), offset);
5958 try func.store(result_ptr, overflow_bit, Type.u1, offset);
59595959
59605960 func.finishAir(inst, result_ptr, &.{ extra.lhs, extra.rhs });
59615961}
src/codegen/c/type.zig+1-1
......@@ -1471,7 +1471,7 @@ pub const CType = extern union {
14711471 else
14721472 info.pointee_type;
14731473
1474 if (if (info.size == .C and pointee_ty.tag() == .u8)
1474 if (if (info.size == .C and pointee_ty.ip_index == .u8_type)
14751475 Tag.char.toIndex()
14761476 else
14771477 try lookup.typeToIndex(pointee_ty, .forward)) |child_idx|
src/type.zig+48-310
......@@ -107,20 +107,6 @@ pub const Type = struct {
107107 }
108108 }
109109 switch (ty.tag()) {
110 .u1,
111 .u8,
112 .i8,
113 .u16,
114 .i16,
115 .u29,
116 .u32,
117 .i32,
118 .u64,
119 .i64,
120 .u128,
121 .i128,
122 => return .Int,
123
124110 .error_set,
125111 .error_set_single,
126112 .error_set_inferred,
......@@ -589,26 +575,6 @@ pub const Type = struct {
589575 if (a.legacy.tag_if_small_enough == b.legacy.tag_if_small_enough) return true;
590576
591577 switch (a.tag()) {
592 .u1,
593 .u8,
594 .i8,
595 .u16,
596 .i16,
597 .u29,
598 .u32,
599 .i32,
600 .u64,
601 .i64,
602 .u128,
603 .i128,
604 => {
605 if (b.zigTypeTag(mod) != .Int) return false;
606 if (b.isNamedInt()) return false;
607 const info_a = a.intInfo(mod);
608 const info_b = b.intInfo(mod);
609 return info_a.signedness == info_b.signedness and info_a.bits == info_b.bits;
610 },
611
612578 .error_set_inferred => {
613579 // Inferred error sets are only equal if both are inferred
614580 // and they share the same pointer.
......@@ -926,26 +892,6 @@ pub const Type = struct {
926892 return;
927893 }
928894 switch (ty.tag()) {
929 .u1,
930 .u8,
931 .i8,
932 .u16,
933 .i16,
934 .u29,
935 .u32,
936 .i32,
937 .u64,
938 .i64,
939 .u128,
940 .i128,
941 => {
942 // Arbitrary sized integers.
943 std.hash.autoHash(hasher, std.builtin.TypeId.Int);
944 const info = ty.intInfo(mod);
945 std.hash.autoHash(hasher, info.signedness);
946 std.hash.autoHash(hasher, info.bits);
947 },
948
949895 .error_set,
950896 .error_set_single,
951897 .error_set_merged,
......@@ -1183,18 +1129,6 @@ pub const Type = struct {
11831129 .legacy = .{ .tag_if_small_enough = self.legacy.tag_if_small_enough },
11841130 };
11851131 } else switch (self.legacy.ptr_otherwise.tag) {
1186 .u1,
1187 .u8,
1188 .i8,
1189 .u16,
1190 .i16,
1191 .u29,
1192 .u32,
1193 .i32,
1194 .u64,
1195 .i64,
1196 .u128,
1197 .i128,
11981132 .single_const_pointer_to_comptime_int,
11991133 .const_slice_u8,
12001134 .const_slice_u8_sentinel_0,
......@@ -1435,20 +1369,6 @@ pub const Type = struct {
14351369 while (true) {
14361370 const t = ty.tag();
14371371 switch (t) {
1438 .u1,
1439 .u8,
1440 .i8,
1441 .u16,
1442 .i16,
1443 .u29,
1444 .u32,
1445 .i32,
1446 .u64,
1447 .i64,
1448 .u128,
1449 .i128,
1450 => return writer.writeAll(@tagName(t)),
1451
14521372 .empty_struct, .empty_struct_literal => return writer.writeAll("struct {}"),
14531373
14541374 .@"struct" => {
......@@ -1775,20 +1695,6 @@ pub const Type = struct {
17751695 .inferred_alloc_const => unreachable,
17761696 .inferred_alloc_mut => unreachable,
17771697
1778 .u1,
1779 .u8,
1780 .i8,
1781 .u16,
1782 .i16,
1783 .u29,
1784 .u32,
1785 .i32,
1786 .u64,
1787 .i64,
1788 .u128,
1789 .i128,
1790 => try writer.writeAll(@tagName(t)),
1791
17921698 .empty_struct_literal => try writer.writeAll("@TypeOf(.{})"),
17931699
17941700 .empty_struct => {
......@@ -2057,16 +1963,6 @@ pub const Type = struct {
20571963 pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value {
20581964 if (self.ip_index != .none) return self.ip_index.toValue();
20591965 switch (self.tag()) {
2060 .u1 => return Value{ .ip_index = .u1_type, .legacy = undefined },
2061 .u8 => return Value{ .ip_index = .u8_type, .legacy = undefined },
2062 .i8 => return Value{ .ip_index = .i8_type, .legacy = undefined },
2063 .u16 => return Value{ .ip_index = .u16_type, .legacy = undefined },
2064 .u29 => return Value{ .ip_index = .u29_type, .legacy = undefined },
2065 .i16 => return Value{ .ip_index = .i16_type, .legacy = undefined },
2066 .u32 => return Value{ .ip_index = .u32_type, .legacy = undefined },
2067 .i32 => return Value{ .ip_index = .i32_type, .legacy = undefined },
2068 .u64 => return Value{ .ip_index = .u64_type, .legacy = undefined },
2069 .i64 => return Value{ .ip_index = .i64_type, .legacy = undefined },
20701966 .single_const_pointer_to_comptime_int => return Value{ .ip_index = .single_const_pointer_to_comptime_int_type, .legacy = undefined },
20711967 .const_slice_u8 => return Value{ .ip_index = .const_slice_u8_type, .legacy = undefined },
20721968 .const_slice_u8_sentinel_0 => return Value{ .ip_index = .const_slice_u8_sentinel_0_type, .legacy = undefined },
......@@ -2162,19 +2058,6 @@ pub const Type = struct {
21622058 .enum_tag => unreachable, // it's a value, not a type
21632059 };
21642060 switch (ty.tag()) {
2165 .u1,
2166 .u8,
2167 .i8,
2168 .u16,
2169 .i16,
2170 .u29,
2171 .u32,
2172 .i32,
2173 .u64,
2174 .i64,
2175 .u128,
2176 .i128,
2177
21782061 .const_slice_u8,
21792062 .const_slice_u8_sentinel_0,
21802063 .array_u8_sentinel_0,
......@@ -2404,19 +2287,6 @@ pub const Type = struct {
24042287 .enum_tag => unreachable, // it's a value, not a type
24052288 };
24062289 return switch (ty.tag()) {
2407 .u1,
2408 .u8,
2409 .i8,
2410 .u16,
2411 .i16,
2412 .u29,
2413 .u32,
2414 .i32,
2415 .u64,
2416 .i64,
2417 .u128,
2418 .i128,
2419
24202290 .manyptr_u8,
24212291 .manyptr_const_u8,
24222292 .manyptr_const_u8_sentinel_0,
......@@ -2752,10 +2622,6 @@ pub const Type = struct {
27522622 else => null,
27532623 };
27542624 switch (ty.tag()) {
2755 .u1,
2756 .u8,
2757 .i8,
2758
27592625 .array_u8_sentinel_0,
27602626 .array_u8,
27612627 .@"opaque",
......@@ -2806,12 +2672,6 @@ pub const Type = struct {
28062672 return AbiAlignmentAdvanced{ .scalar = @intCast(u32, alignment) };
28072673 },
28082674
2809 .i16, .u16 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(16, target) },
2810 .u29 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(29, target) },
2811 .i32, .u32 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(32, target) },
2812 .i64, .u64 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(64, target) },
2813 .u128, .i128 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(128, target) },
2814
28152675 .optional => {
28162676 var buf: Payload.ElemType = undefined;
28172677 const child_type = ty.optionalChild(&buf);
......@@ -3208,11 +3068,6 @@ pub const Type = struct {
32083068 return abiSizeAdvancedUnion(ty, mod, strat, union_obj, true);
32093069 },
32103070
3211 .u1,
3212 .u8,
3213 .i8,
3214 => return AbiSizeAdvanced{ .scalar = 1 },
3215
32163071 .array_u8 => return AbiSizeAdvanced{ .scalar = ty.castTag(.array_u8).?.data },
32173072 .array_u8_sentinel_0 => return AbiSizeAdvanced{ .scalar = ty.castTag(.array_u8_sentinel_0).?.data + 1 },
32183073 .array => {
......@@ -3293,12 +3148,6 @@ pub const Type = struct {
32933148 .error_set_single,
32943149 => return AbiSizeAdvanced{ .scalar = 2 },
32953150
3296 .i16, .u16 => return AbiSizeAdvanced{ .scalar = intAbiSize(16, target) },
3297 .u29 => return AbiSizeAdvanced{ .scalar = intAbiSize(29, target) },
3298 .i32, .u32 => return AbiSizeAdvanced{ .scalar = intAbiSize(32, target) },
3299 .i64, .u64 => return AbiSizeAdvanced{ .scalar = intAbiSize(64, target) },
3300 .u128, .i128 => return AbiSizeAdvanced{ .scalar = intAbiSize(128, target) },
3301
33023151 .optional => {
33033152 var buf: Payload.ElemType = undefined;
33043153 const child_type = ty.optionalChild(&buf);
......@@ -3497,14 +3346,6 @@ pub const Type = struct {
34973346 .inferred_alloc_mut => unreachable,
34983347 .@"opaque" => unreachable,
34993348
3500 .u1 => return 1,
3501 .u8, .i8 => return 8,
3502 .i16, .u16 => return 16,
3503 .u29 => return 29,
3504 .i32, .u32 => return 32,
3505 .i64, .u64 => return 64,
3506 .u128, .i128 => return 128,
3507
35083349 .@"struct" => {
35093350 const struct_obj = ty.castTag(.@"struct").?.data;
35103351 if (struct_obj.layout != .Packed) {
......@@ -4398,47 +4239,25 @@ pub const Type = struct {
43984239
43994240 /// Returns true if and only if the type is a fixed-width, signed integer.
44004241 pub fn isSignedInt(ty: Type, mod: *const Module) bool {
4401 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4402 .int_type => |int_type| return int_type.signedness == .signed,
4403 .simple_type => |s| return switch (s) {
4404 .c_char, .isize, .c_short, .c_int, .c_long, .c_longlong => true,
4242 return switch (ty.ip_index) {
4243 .c_char_type, .isize_type, .c_short_type, .c_int_type, .c_long_type, .c_longlong_type => true,
4244 .none => false,
4245 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4246 .int_type => |int_type| int_type.signedness == .signed,
44054247 else => false,
44064248 },
4407 else => return false,
4408 };
4409 return switch (ty.tag()) {
4410 .i8,
4411 .i16,
4412 .i32,
4413 .i64,
4414 .i128,
4415 => true,
4416
4417 else => false,
44184249 };
44194250 }
44204251
44214252 /// Returns true if and only if the type is a fixed-width, unsigned integer.
44224253 pub fn isUnsignedInt(ty: Type, mod: *const Module) bool {
4423 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4424 .int_type => |int_type| return int_type.signedness == .unsigned,
4425 .simple_type => |s| return switch (s) {
4426 .usize, .c_ushort, .c_uint, .c_ulong, .c_ulonglong => true,
4254 return switch (ty.ip_index) {
4255 .usize_type, .c_ushort_type, .c_uint_type, .c_ulong_type, .c_ulonglong_type => true,
4256 .none => false,
4257 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4258 .int_type => |int_type| int_type.signedness == .unsigned,
44274259 else => false,
44284260 },
4429 else => return false,
4430 };
4431 return switch (ty.tag()) {
4432 .u1,
4433 .u8,
4434 .u16,
4435 .u29,
4436 .u32,
4437 .u64,
4438 .u128,
4439 => true,
4440
4441 else => false,
44424261 };
44434262 }
44444263
......@@ -4459,19 +4278,6 @@ pub const Type = struct {
44594278
44604279 while (true) switch (ty.ip_index) {
44614280 .none => switch (ty.tag()) {
4462 .u1 => return .{ .signedness = .unsigned, .bits = 1 },
4463 .u8 => return .{ .signedness = .unsigned, .bits = 8 },
4464 .i8 => return .{ .signedness = .signed, .bits = 8 },
4465 .u16 => return .{ .signedness = .unsigned, .bits = 16 },
4466 .i16 => return .{ .signedness = .signed, .bits = 16 },
4467 .u29 => return .{ .signedness = .unsigned, .bits = 29 },
4468 .u32 => return .{ .signedness = .unsigned, .bits = 32 },
4469 .i32 => return .{ .signedness = .signed, .bits = 32 },
4470 .u64 => return .{ .signedness = .unsigned, .bits = 64 },
4471 .i64 => return .{ .signedness = .signed, .bits = 64 },
4472 .u128 => return .{ .signedness = .unsigned, .bits = 128 },
4473 .i128 => return .{ .signedness = .signed, .bits = 128 },
4474
44754281 .enum_full, .enum_nonexhaustive => ty = ty.cast(Payload.EnumFull).?.data.tag_ty,
44764282 .enum_numbered => ty = ty.castTag(.enum_numbered).?.data.tag_ty,
44774283 .enum_simple => {
......@@ -4664,50 +4470,34 @@ pub const Type = struct {
46644470 }
46654471
46664472 pub fn isNumeric(ty: Type, mod: *const Module) bool {
4667 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4668 .int_type => true,
4669 .simple_type => |s| return switch (s) {
4670 .f16,
4671 .f32,
4672 .f64,
4673 .f80,
4674 .f128,
4675 .c_longdouble,
4676 .comptime_int,
4677 .comptime_float,
4678 .usize,
4679 .isize,
4680 .c_char,
4681 .c_short,
4682 .c_ushort,
4683 .c_int,
4684 .c_uint,
4685 .c_long,
4686 .c_ulong,
4687 .c_longlong,
4688 .c_ulonglong,
4689 => true,
4473 return switch (ty.ip_index) {
4474 .f16_type,
4475 .f32_type,
4476 .f64_type,
4477 .f80_type,
4478 .f128_type,
4479 .c_longdouble_type,
4480 .comptime_int_type,
4481 .comptime_float_type,
4482 .usize_type,
4483 .isize_type,
4484 .c_char_type,
4485 .c_short_type,
4486 .c_ushort_type,
4487 .c_int_type,
4488 .c_uint_type,
4489 .c_long_type,
4490 .c_ulong_type,
4491 .c_longlong_type,
4492 .c_ulonglong_type,
4493 => true,
4494
4495 .none => false,
46904496
4497 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
4498 .int_type => true,
46914499 else => false,
46924500 },
4693 else => false,
4694 };
4695 return switch (ty.tag()) {
4696 .u1,
4697 .u8,
4698 .i8,
4699 .u16,
4700 .i16,
4701 .u29,
4702 .u32,
4703 .i32,
4704 .u64,
4705 .i64,
4706 .u128,
4707 .i128,
4708 => true,
4709
4710 else => false,
47114501 };
47124502 }
47134503
......@@ -4785,19 +4575,6 @@ pub const Type = struct {
47854575 };
47864576
47874577 while (true) switch (ty.tag()) {
4788 .u1,
4789 .u8,
4790 .i8,
4791 .u16,
4792 .i16,
4793 .u29,
4794 .u32,
4795 .i32,
4796 .u64,
4797 .i64,
4798 .u128,
4799 .i128,
4800
48014578 .error_union,
48024579 .error_set_single,
48034580 .error_set,
......@@ -4995,19 +4772,6 @@ pub const Type = struct {
49954772 };
49964773
49974774 return switch (ty.tag()) {
4998 .u1,
4999 .u8,
5000 .i8,
5001 .u16,
5002 .i16,
5003 .u29,
5004 .u32,
5005 .i32,
5006 .u64,
5007 .i64,
5008 .u128,
5009 .i128,
5010
50114775 .manyptr_u8,
50124776 .manyptr_const_u8,
50134777 .manyptr_const_u8_sentinel_0,
......@@ -5764,19 +5528,6 @@ pub const Type = struct {
57645528 /// See `zigTypeTag` for the function that corresponds to `std.builtin.TypeId`.
57655529 pub const Tag = enum(usize) {
57665530 // The first section of this enum are tags that require no payload.
5767 u1,
5768 u8,
5769 i8,
5770 u16,
5771 i16,
5772 u29,
5773 u32,
5774 i32,
5775 u64,
5776 i64,
5777 u128,
5778 i128,
5779
57805531 manyptr_u8,
57815532 manyptr_const_u8,
57825533 manyptr_const_u8_sentinel_0,
......@@ -5839,19 +5590,6 @@ pub const Type = struct {
58395590
58405591 pub fn Type(comptime t: Tag) type {
58415592 return switch (t) {
5842 .u1,
5843 .u8,
5844 .i8,
5845 .u16,
5846 .i16,
5847 .u29,
5848 .u32,
5849 .i32,
5850 .u64,
5851 .i64,
5852 .u128,
5853 .i128,
5854
58555593 .single_const_pointer_to_comptime_int,
58565594 .anyerror_void_error_union,
58575595 .const_slice_u8,
......@@ -6203,19 +5941,19 @@ pub const Type = struct {
62035941 };
62045942 };
62055943
6206 pub const @"u1" = initTag(.u1);
6207 pub const @"u8" = initTag(.u8);
6208 pub const @"u16" = initTag(.u16);
6209 pub const @"u29" = initTag(.u29);
6210 pub const @"u32" = initTag(.u32);
6211 pub const @"u64" = initTag(.u64);
6212 pub const @"u128" = initTag(.u128);
6213
6214 pub const @"i8" = initTag(.i8);
6215 pub const @"i16" = initTag(.i16);
6216 pub const @"i32" = initTag(.i32);
6217 pub const @"i64" = initTag(.i64);
6218 pub const @"i128" = initTag(.i128);
5944 pub const @"u1": Type = .{ .ip_index = .u1_type, .legacy = undefined };
5945 pub const @"u8": Type = .{ .ip_index = .u8_type, .legacy = undefined };
5946 pub const @"u16": Type = .{ .ip_index = .u16_type, .legacy = undefined };
5947 pub const @"u29": Type = .{ .ip_index = .u29_type, .legacy = undefined };
5948 pub const @"u32": Type = .{ .ip_index = .u32_type, .legacy = undefined };
5949 pub const @"u64": Type = .{ .ip_index = .u64_type, .legacy = undefined };
5950 pub const @"u128": Type = .{ .ip_index = .u128_type, .legacy = undefined };
5951
5952 pub const @"i8": Type = .{ .ip_index = .i8_type, .legacy = undefined };
5953 pub const @"i16": Type = .{ .ip_index = .i16_type, .legacy = undefined };
5954 pub const @"i32": Type = .{ .ip_index = .i32_type, .legacy = undefined };
5955 pub const @"i64": Type = .{ .ip_index = .i64_type, .legacy = undefined };
5956 pub const @"i128": Type = .{ .ip_index = .i128_type, .legacy = undefined };
62195957
62205958 pub const @"f16": Type = .{ .ip_index = .f16_type, .legacy = undefined };
62215959 pub const @"f32": Type = .{ .ip_index = .f32_type, .legacy = undefined };