authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-07 15:38:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:29-07:00
log4d88f825bc5eb14aa00446f046ab4714a4fdce70
tree4729946dff1e6ae200426418f4f6653003468d4f
parenta5fb16959423005de999fb541d5d5e9aebb8e09e

stage2: implement intTagType logic

This commit changes a lot of `*const Module` to `*Module` to make it work, since accessing the integer tag type of an enum might need to mutate the InternPool by adding a new integer type into it. An alternate strategy would be to pre-heat the InternPool with the integer tag type when creating an enum type, which would make it so that intTagType could accept a const Module instead of a mutable one, asserting that the InternPool already had the integer tag type.

19 files changed, 136 insertions(+), 137 deletions(-)

src/Module.zig+15-14
......@@ -944,7 +944,7 @@ pub const Decl = struct {
944944 };
945945 }
946946
947 pub fn getAlignment(decl: Decl, mod: *const Module) u32 {
947 pub fn getAlignment(decl: Decl, mod: *Module) u32 {
948948 assert(decl.has_tv);
949949 if (decl.@"align" != 0) {
950950 // Explicit alignment.
......@@ -1053,7 +1053,7 @@ pub const Struct = struct {
10531053 /// Returns the field alignment. If the struct is packed, returns 0.
10541054 pub fn alignment(
10551055 field: Field,
1056 mod: *const Module,
1056 mod: *Module,
10571057 layout: std.builtin.Type.ContainerLayout,
10581058 ) u32 {
10591059 if (field.abi_align != 0) {
......@@ -1076,7 +1076,7 @@ pub const Struct = struct {
10761076 }
10771077 }
10781078
1079 pub fn alignmentExtern(field: Field, mod: *const Module) u32 {
1079 pub fn alignmentExtern(field: Field, mod: *Module) u32 {
10801080 // This logic is duplicated in Type.abiAlignmentAdvanced.
10811081 const ty_abi_align = field.ty.abiAlignment(mod);
10821082
......@@ -1157,7 +1157,7 @@ pub const Struct = struct {
11571157 };
11581158 }
11591159
1160 pub fn packedFieldBitOffset(s: Struct, mod: *const Module, index: usize) u16 {
1160 pub fn packedFieldBitOffset(s: Struct, mod: *Module, index: usize) u16 {
11611161 assert(s.layout == .Packed);
11621162 assert(s.haveLayout());
11631163 var bit_sum: u64 = 0;
......@@ -1171,7 +1171,7 @@ pub const Struct = struct {
11711171 }
11721172
11731173 pub const RuntimeFieldIterator = struct {
1174 module: *const Module,
1174 module: *Module,
11751175 struct_obj: *const Struct,
11761176 index: u32 = 0,
11771177
......@@ -1201,7 +1201,7 @@ pub const Struct = struct {
12011201 }
12021202 };
12031203
1204 pub fn runtimeFieldIterator(s: *const Struct, module: *const Module) RuntimeFieldIterator {
1204 pub fn runtimeFieldIterator(s: *const Struct, module: *Module) RuntimeFieldIterator {
12051205 return .{
12061206 .struct_obj = s,
12071207 .module = module,
......@@ -1353,7 +1353,7 @@ pub const Union = struct {
13531353 /// Returns the field alignment, assuming the union is not packed.
13541354 /// Keep implementation in sync with `Sema.unionFieldAlignment`.
13551355 /// Prefer to call that function instead of this one during Sema.
1356 pub fn normalAlignment(field: Field, mod: *const Module) u32 {
1356 pub fn normalAlignment(field: Field, mod: *Module) u32 {
13571357 if (field.abi_align == 0) {
13581358 return field.ty.abiAlignment(mod);
13591359 } else {
......@@ -1413,7 +1413,7 @@ pub const Union = struct {
14131413 };
14141414 }
14151415
1416 pub fn hasAllZeroBitFieldTypes(u: Union, mod: *const Module) bool {
1416 pub fn hasAllZeroBitFieldTypes(u: Union, mod: *Module) bool {
14171417 assert(u.haveFieldTypes());
14181418 for (u.fields.values()) |field| {
14191419 if (field.ty.hasRuntimeBits(mod)) return false;
......@@ -1421,7 +1421,7 @@ pub const Union = struct {
14211421 return true;
14221422 }
14231423
1424 pub fn mostAlignedField(u: Union, mod: *const Module) u32 {
1424 pub fn mostAlignedField(u: Union, mod: *Module) u32 {
14251425 assert(u.haveFieldTypes());
14261426 var most_alignment: u32 = 0;
14271427 var most_index: usize = undefined;
......@@ -1438,7 +1438,7 @@ pub const Union = struct {
14381438 }
14391439
14401440 /// Returns 0 if the union is represented with 0 bits at runtime.
1441 pub fn abiAlignment(u: Union, mod: *const Module, have_tag: bool) u32 {
1441 pub fn abiAlignment(u: Union, mod: *Module, have_tag: bool) u32 {
14421442 var max_align: u32 = 0;
14431443 if (have_tag) max_align = u.tag_ty.abiAlignment(mod);
14441444 for (u.fields.values()) |field| {
......@@ -1450,7 +1450,7 @@ pub const Union = struct {
14501450 return max_align;
14511451 }
14521452
1453 pub fn abiSize(u: Union, mod: *const Module, have_tag: bool) u64 {
1453 pub fn abiSize(u: Union, mod: *Module, have_tag: bool) u64 {
14541454 return u.getLayout(mod, have_tag).abi_size;
14551455 }
14561456
......@@ -1481,7 +1481,7 @@ pub const Union = struct {
14811481 };
14821482 }
14831483
1484 pub fn getLayout(u: Union, mod: *const Module, have_tag: bool) Layout {
1484 pub fn getLayout(u: Union, mod: *Module, have_tag: bool) Layout {
14851485 assert(u.haveLayout());
14861486 var most_aligned_field: u32 = undefined;
14871487 var most_aligned_field_size: u64 = undefined;
......@@ -6988,6 +6988,7 @@ pub const AtomicPtrAlignmentError = error{
69886988 FloatTooBig,
69896989 IntTooBig,
69906990 BadType,
6991 OutOfMemory,
69916992};
69926993
69936994pub const AtomicPtrAlignmentDiagnostics = struct {
......@@ -7001,7 +7002,7 @@ pub const AtomicPtrAlignmentDiagnostics = struct {
70017002// TODO this function does not take into account CPU features, which can affect
70027003// this value. Audit this!
70037004pub fn atomicPtrAlignment(
7004 mod: *const Module,
7005 mod: *Module,
70057006 ty: Type,
70067007 diags: *AtomicPtrAlignmentDiagnostics,
70077008) AtomicPtrAlignmentError!u32 {
......@@ -7080,7 +7081,7 @@ pub fn atomicPtrAlignment(
70807081
70817082 const int_ty = switch (ty.zigTypeTag(mod)) {
70827083 .Int => ty,
7083 .Enum => ty.intTagType(),
7084 .Enum => try ty.intTagType(mod),
70847085 .Float => {
70857086 const bit_count = ty.floatBits(target);
70867087 if (bit_count > max_atomic_bits) {
src/Sema.zig+7-7
......@@ -8249,7 +8249,6 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
82498249
82508250fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
82518251 const mod = sema.mod;
8252 const arena = sema.arena;
82538252 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
82548253 const src = inst_data.src();
82558254 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
......@@ -8278,7 +8277,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
82788277 };
82798278 const enum_tag_ty = sema.typeOf(enum_tag);
82808279
8281 const int_tag_ty = try enum_tag_ty.intTagType().copy(arena);
8280 const int_tag_ty = try enum_tag_ty.intTagType(mod);
82828281
82838282 if (try sema.typeHasOnePossibleValue(enum_tag_ty)) |opv| {
82848283 return sema.addConstant(int_tag_ty, opv);
......@@ -8310,7 +8309,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
83108309
83118310 if (try sema.resolveMaybeUndefVal(operand)) |int_val| {
83128311 if (dest_ty.isNonexhaustiveEnum()) {
8313 const int_tag_ty = dest_ty.intTagType();
8312 const int_tag_ty = try dest_ty.intTagType(mod);
83148313 if (try sema.intFitsInType(int_val, int_tag_ty, null)) {
83158314 return sema.addConstant(dest_ty, int_val);
83168315 }
......@@ -16268,7 +16267,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1626816267 },
1626916268 .Enum => {
1627016269 // TODO: look into memoizing this result.
16271 const int_tag_ty = try ty.intTagType().copy(sema.arena);
16270 const int_tag_ty = try ty.intTagType(mod);
1627216271
1627316272 const is_exhaustive = Value.makeBool(!ty.isNonexhaustiveEnum());
1627416273
......@@ -20354,7 +20353,7 @@ fn zirBitCount(
2035420353 block: *Block,
2035520354 inst: Zir.Inst.Index,
2035620355 air_tag: Air.Inst.Tag,
20357 comptime comptimeOp: fn (val: Value, ty: Type, mod: *const Module) u64,
20356 comptime comptimeOp: fn (val: Value, ty: Type, mod: *Module) u64,
2035820357) CompileError!Air.Inst.Ref {
2035920358 const mod = sema.mod;
2036020359 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
......@@ -20755,6 +20754,7 @@ fn checkAtomicPtrOperand(
2075520754 const mod = sema.mod;
2075620755 var diag: Module.AtomicPtrAlignmentDiagnostics = .{};
2075720756 const alignment = mod.atomicPtrAlignment(elem_ty, &diag) catch |err| switch (err) {
20757 error.OutOfMemory => return error.OutOfMemory,
2075820758 error.FloatTooBig => return sema.fail(
2075920759 block,
2076020760 elem_ty_src,
......@@ -23462,7 +23462,7 @@ fn validateExternType(
2346223462 return !Type.fnCallingConventionAllowsZigTypes(target, ty.fnCallingConvention());
2346323463 },
2346423464 .Enum => {
23465 return sema.validateExternType(ty.intTagType(), position);
23465 return sema.validateExternType(try ty.intTagType(mod), position);
2346623466 },
2346723467 .Struct, .Union => switch (ty.containerLayout()) {
2346823468 .Extern => return true,
......@@ -23540,7 +23540,7 @@ fn explainWhyTypeIsNotExtern(
2354023540 }
2354123541 },
2354223542 .Enum => {
23543 const tag_ty = ty.intTagType();
23543 const tag_ty = try ty.intTagType(mod);
2354423544 try mod.errNoteNonLazy(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)});
2354523545 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);
2354623546 },
src/arch/aarch64/CodeGen.zig+1-1
......@@ -4533,7 +4533,7 @@ fn cmp(
45334533 }
45344534 },
45354535 .Float => return self.fail("TODO ARM cmp floats", .{}),
4536 .Enum => lhs_ty.intTagType(),
4536 .Enum => try lhs_ty.intTagType(mod),
45374537 .Int => lhs_ty,
45384538 .Bool => Type.u1,
45394539 .Pointer => Type.usize,
src/arch/aarch64/abi.zig+3-3
......@@ -15,7 +15,7 @@ pub const Class = union(enum) {
1515};
1616
1717/// For `float_array` the second element will be the amount of floats.
18pub fn classifyType(ty: Type, mod: *const Module) Class {
18pub fn classifyType(ty: Type, mod: *Module) Class {
1919 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(mod));
2020
2121 var maybe_float_bits: ?u16 = null;
......@@ -74,7 +74,7 @@ pub fn classifyType(ty: Type, mod: *const Module) Class {
7474}
7575
7676const sret_float_count = 4;
77fn countFloats(ty: Type, mod: *const Module, maybe_float_bits: *?u16) u8 {
77fn countFloats(ty: Type, mod: *Module, maybe_float_bits: *?u16) u8 {
7878 const target = mod.getTarget();
7979 const invalid = std.math.maxInt(u8);
8080 switch (ty.zigTypeTag(mod)) {
......@@ -115,7 +115,7 @@ fn countFloats(ty: Type, mod: *const Module, maybe_float_bits: *?u16) u8 {
115115 }
116116}
117117
118pub fn getFloatArrayType(ty: Type, mod: *const Module) ?Type {
118pub fn getFloatArrayType(ty: Type, mod: *Module) ?Type {
119119 switch (ty.zigTypeTag(mod)) {
120120 .Union => {
121121 const fields = ty.unionFields();
src/arch/arm/CodeGen.zig+1-1
......@@ -4480,7 +4480,7 @@ fn cmp(
44804480 }
44814481 },
44824482 .Float => return self.fail("TODO ARM cmp floats", .{}),
4483 .Enum => lhs_ty.intTagType(),
4483 .Enum => try lhs_ty.intTagType(mod),
44844484 .Int => lhs_ty,
44854485 .Bool => Type.u1,
44864486 .Pointer => Type.usize,
src/arch/arm/abi.zig+2-2
......@@ -24,7 +24,7 @@ pub const Class = union(enum) {
2424
2525pub const Context = enum { ret, arg };
2626
27pub fn classifyType(ty: Type, mod: *const Module, ctx: Context) Class {
27pub fn classifyType(ty: Type, mod: *Module, ctx: Context) Class {
2828 assert(ty.hasRuntimeBitsIgnoreComptime(mod));
2929
3030 var maybe_float_bits: ?u16 = null;
......@@ -116,7 +116,7 @@ pub fn classifyType(ty: Type, mod: *const Module, ctx: Context) Class {
116116}
117117
118118const byval_float_count = 4;
119fn countFloats(ty: Type, mod: *const Module, maybe_float_bits: *?u16) u32 {
119fn countFloats(ty: Type, mod: *Module, maybe_float_bits: *?u16) u32 {
120120 const target = mod.getTarget();
121121 const invalid = std.math.maxInt(u32);
122122 switch (ty.zigTypeTag(mod)) {
src/arch/riscv64/abi.zig+1-1
......@@ -7,7 +7,7 @@ const Module = @import("../../Module.zig");
77
88pub const Class = enum { memory, byval, integer, double_integer };
99
10pub fn classifyType(ty: Type, mod: *const Module) Class {
10pub fn classifyType(ty: Type, mod: *Module) Class {
1111 const target = mod.getTarget();
1212 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(mod));
1313
src/arch/sparc64/CodeGen.zig+1-1
......@@ -1436,7 +1436,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
14361436
14371437 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {
14381438 .Vector => unreachable, // Handled by cmp_vector.
1439 .Enum => lhs_ty.intTagType(),
1439 .Enum => try lhs_ty.intTagType(mod),
14401440 .Int => lhs_ty,
14411441 .Bool => Type.u1,
14421442 .Pointer => Type.usize,
src/arch/wasm/CodeGen.zig+8-8
......@@ -1393,7 +1393,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
13931393 return result;
13941394}
13951395
1396fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, mod: *const Module) bool {
1396fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, mod: *Module) bool {
13971397 switch (cc) {
13981398 .Unspecified, .Inline => return isByRef(return_type, mod),
13991399 .C => {
......@@ -1713,7 +1713,7 @@ fn arch(func: *const CodeGen) std.Target.Cpu.Arch {
17131713
17141714/// For a given `Type`, will return true when the type will be passed
17151715/// by reference, rather than by value
1716fn isByRef(ty: Type, mod: *const Module) bool {
1716fn isByRef(ty: Type, mod: *Module) bool {
17171717 const target = mod.getTarget();
17181718 switch (ty.zigTypeTag(mod)) {
17191719 .Type,
......@@ -1787,7 +1787,7 @@ const SimdStoreStrategy = enum {
17871787/// This means when a given type is 128 bits and either the simd128 or relaxed-simd
17881788/// features are enabled, the function will return `.direct`. This would allow to store
17891789/// it using a instruction, rather than an unrolled version.
1790fn determineSimdStoreStrategy(ty: Type, mod: *const Module) SimdStoreStrategy {
1790fn determineSimdStoreStrategy(ty: Type, mod: *Module) SimdStoreStrategy {
17911791 std.debug.assert(ty.zigTypeTag(mod) == .Vector);
17921792 if (ty.bitSize(mod) != 128) return .unrolled;
17931793 const hasFeature = std.Target.wasm.featureSetHas;
......@@ -3121,7 +3121,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
31213121 else => return func.fail("TODO: lowerConstant for enum tag: {}", .{ty.tag()}),
31223122 }
31233123 } else {
3124 const int_tag_ty = ty.intTagType();
3124 const int_tag_ty = try ty.intTagType(mod);
31253125 return func.lowerConstant(val, int_tag_ty);
31263126 }
31273127 },
......@@ -3235,7 +3235,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
32353235/// Returns a `Value` as a signed 32 bit value.
32363236/// It's illegal to provide a value with a type that cannot be represented
32373237/// as an integer value.
3238fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
3238fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) !i32 {
32393239 const mod = func.bin_file.base.options.module.?;
32403240 switch (ty.zigTypeTag(mod)) {
32413241 .Enum => {
......@@ -3257,7 +3257,7 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
32573257 else => unreachable,
32583258 }
32593259 } else {
3260 const int_tag_ty = ty.intTagType();
3260 const int_tag_ty = try ty.intTagType(mod);
32613261 return func.valueAsI32(val, int_tag_ty);
32623262 }
32633263 },
......@@ -3793,7 +3793,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37933793
37943794 for (items, 0..) |ref, i| {
37953795 const item_val = (try func.air.value(ref, mod)).?;
3796 const int_val = func.valueAsI32(item_val, target_ty);
3796 const int_val = try func.valueAsI32(item_val, target_ty);
37973797 if (lowest_maybe == null or int_val < lowest_maybe.?) {
37983798 lowest_maybe = int_val;
37993799 }
......@@ -6814,7 +6814,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
68146814 return loc.index;
68156815 }
68166816
6817 const int_tag_ty = enum_ty.intTagType();
6817 const int_tag_ty = try enum_ty.intTagType(mod);
68186818
68196819 if (int_tag_ty.bitSize(mod) > 64) {
68206820 return func.fail("TODO: Implement @tagName for enums with tag size larger than 64 bits", .{});
src/arch/wasm/abi.zig+2-2
......@@ -21,7 +21,7 @@ const direct: [2]Class = .{ .direct, .none };
2121/// Classifies a given Zig type to determine how they must be passed
2222/// or returned as value within a wasm function.
2323/// When all elements result in `.none`, no value must be passed in or returned.
24pub fn classifyType(ty: Type, mod: *const Module) [2]Class {
24pub fn classifyType(ty: Type, mod: *Module) [2]Class {
2525 const target = mod.getTarget();
2626 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return none;
2727 switch (ty.zigTypeTag(mod)) {
......@@ -93,7 +93,7 @@ pub fn classifyType(ty: Type, mod: *const Module) [2]Class {
9393/// Returns the scalar type a given type can represent.
9494/// Asserts given type can be represented as scalar, such as
9595/// a struct with a single scalar field.
96pub fn scalarType(ty: Type, mod: *const Module) Type {
96pub fn scalarType(ty: Type, mod: *Module) Type {
9797 switch (ty.zigTypeTag(mod)) {
9898 .Struct => {
9999 switch (ty.containerLayout()) {
src/arch/x86_64/CodeGen.zig+2-2
......@@ -605,7 +605,7 @@ const FrameAlloc = struct {
605605 .ref_count = 0,
606606 };
607607 }
608 fn initType(ty: Type, mod: *const Module) FrameAlloc {
608 fn initType(ty: Type, mod: *Module) FrameAlloc {
609609 return init(.{ .size = ty.abiSize(mod), .alignment = ty.abiAlignment(mod) });
610610 }
611611};
......@@ -2309,7 +2309,7 @@ fn allocRegOrMemAdvanced(self: *Self, ty: Type, inst: ?Air.Inst.Index, reg_ok: b
23092309 return .{ .load_frame = .{ .index = frame_index } };
23102310}
23112311
2312fn regClassForType(ty: Type, mod: *const Module) RegisterManager.RegisterBitSet {
2312fn regClassForType(ty: Type, mod: *Module) RegisterManager.RegisterBitSet {
23132313 return switch (ty.zigTypeTag(mod)) {
23142314 .Float, .Vector => sse,
23152315 else => gp,
src/arch/x86_64/abi.zig+2-2
......@@ -12,7 +12,7 @@ pub const Class = enum {
1212 float_combine,
1313};
1414
15pub fn classifyWindows(ty: Type, mod: *const Module) Class {
15pub fn classifyWindows(ty: Type, mod: *Module) Class {
1616 // https://docs.microsoft.com/en-gb/cpp/build/x64-calling-convention?view=vs-2017
1717 // "There's a strict one-to-one correspondence between a function call's arguments
1818 // and the registers used for those arguments. Any argument that doesn't fit in 8
......@@ -68,7 +68,7 @@ pub const Context = enum { ret, arg, other };
6868
6969/// There are a maximum of 8 possible return slots. Returned values are in
7070/// the beginning of the array; unused slots are filled with .none.
71pub fn classifySystemV(ty: Type, mod: *const Module, ctx: Context) [8]Class {
71pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
7272 const target = mod.getTarget();
7373 const memory_class = [_]Class{
7474 .memory, .none, .none, .none,
src/codegen.zig+4-4
......@@ -1241,7 +1241,7 @@ pub fn genTypedValue(
12411241 if (enum_values.count() != 0) {
12421242 const tag_val = enum_values.keys()[field_index.data];
12431243 return genTypedValue(bin_file, src_loc, .{
1244 .ty = typed_value.ty.intTagType(),
1244 .ty = try typed_value.ty.intTagType(mod),
12451245 .val = tag_val,
12461246 }, owner_decl_index);
12471247 } else {
......@@ -1251,7 +1251,7 @@ pub fn genTypedValue(
12511251 else => unreachable,
12521252 }
12531253 } else {
1254 const int_tag_ty = typed_value.ty.intTagType();
1254 const int_tag_ty = try typed_value.ty.intTagType(mod);
12551255 return genTypedValue(bin_file, src_loc, .{
12561256 .ty = int_tag_ty,
12571257 .val = typed_value.val,
......@@ -1303,7 +1303,7 @@ pub fn genTypedValue(
13031303 return genUnnamedConst(bin_file, src_loc, typed_value, owner_decl_index);
13041304}
13051305
1306pub fn errUnionPayloadOffset(payload_ty: Type, mod: *const Module) u64 {
1306pub fn errUnionPayloadOffset(payload_ty: Type, mod: *Module) u64 {
13071307 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) return 0;
13081308 const payload_align = payload_ty.abiAlignment(mod);
13091309 const error_align = Type.anyerror.abiAlignment(mod);
......@@ -1314,7 +1314,7 @@ pub fn errUnionPayloadOffset(payload_ty: Type, mod: *const Module) u64 {
13141314 }
13151315}
13161316
1317pub fn errUnionErrorOffset(payload_ty: Type, mod: *const Module) u64 {
1317pub fn errUnionErrorOffset(payload_ty: Type, mod: *Module) u64 {
13181318 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) return 0;
13191319 const payload_align = payload_ty.abiAlignment(mod);
13201320 const error_align = Type.anyerror.abiAlignment(mod);
src/codegen/c.zig+4-4
......@@ -1300,7 +1300,7 @@ pub const DeclGen = struct {
13001300 }
13011301 },
13021302 else => {
1303 const int_tag_ty = ty.intTagType();
1303 const int_tag_ty = try ty.intTagType(mod);
13041304 return dg.renderValue(writer, int_tag_ty, val, location);
13051305 },
13061306 }
......@@ -5198,7 +5198,7 @@ fn fieldLocation(
51985198 container_ty: Type,
51995199 field_ptr_ty: Type,
52005200 field_index: u32,
5201 mod: *const Module,
5201 mod: *Module,
52025202) union(enum) {
52035203 begin: void,
52045204 field: CValue,
......@@ -7722,7 +7722,7 @@ const LowerFnRetTyBuffer = struct {
77227722 values: [1]Value,
77237723 payload: Type.Payload.AnonStruct,
77247724};
7725fn lowerFnRetTy(ret_ty: Type, buffer: *LowerFnRetTyBuffer, mod: *const Module) Type {
7725fn lowerFnRetTy(ret_ty: Type, buffer: *LowerFnRetTyBuffer, mod: *Module) Type {
77267726 if (ret_ty.zigTypeTag(mod) == .NoReturn) return Type.noreturn;
77277727
77287728 if (lowersToArray(ret_ty, mod)) {
......@@ -7740,7 +7740,7 @@ fn lowerFnRetTy(ret_ty: Type, buffer: *LowerFnRetTyBuffer, mod: *const Module) T
77407740 return if (ret_ty.hasRuntimeBitsIgnoreComptime(mod)) ret_ty else Type.void;
77417741}
77427742
7743fn lowersToArray(ty: Type, mod: *const Module) bool {
7743fn lowersToArray(ty: Type, mod: *Module) bool {
77447744 return switch (ty.zigTypeTag(mod)) {
77457745 .Array, .Vector => return true,
77467746 else => return ty.isAbiInt(mod) and toCIntBits(@intCast(u32, ty.bitSize(mod))) == null,
src/codegen/c/type.zig+4-4
......@@ -292,17 +292,17 @@ pub const CType = extern union {
292292 .abi = std.math.log2_int(u32, abi_alignment),
293293 };
294294 }
295 pub fn abiAlign(ty: Type, mod: *const Module) AlignAs {
295 pub fn abiAlign(ty: Type, mod: *Module) AlignAs {
296296 const abi_align = ty.abiAlignment(mod);
297297 return init(abi_align, abi_align);
298298 }
299 pub fn fieldAlign(struct_ty: Type, field_i: usize, mod: *const Module) AlignAs {
299 pub fn fieldAlign(struct_ty: Type, field_i: usize, mod: *Module) AlignAs {
300300 return init(
301301 struct_ty.structFieldAlign(field_i, mod),
302302 struct_ty.structFieldType(field_i).abiAlignment(mod),
303303 );
304304 }
305 pub fn unionPayloadAlign(union_ty: Type, mod: *const Module) AlignAs {
305 pub fn unionPayloadAlign(union_ty: Type, mod: *Module) AlignAs {
306306 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
307307 const union_payload_align = union_obj.abiAlignment(mod, false);
308308 return init(union_payload_align, union_payload_align);
......@@ -1897,7 +1897,7 @@ pub const CType = extern union {
18971897 }
18981898 }
18991899
1900 fn createFromType(store: *Store.Promoted, ty: Type, mod: *const Module, kind: Kind) !CType {
1900 fn createFromType(store: *Store.Promoted, ty: Type, mod: *Module, kind: Kind) !CType {
19011901 var convert: Convert = undefined;
19021902 try convert.initType(ty, kind, .{ .imm = .{ .set = &store.set, .mod = mod } });
19031903 return createFromConvert(store, ty, mod, kind, &convert);
src/codegen/llvm.zig+16-14
......@@ -1527,7 +1527,7 @@ pub const Object = struct {
15271527 };
15281528 const field_index_val = Value.initPayload(&buf_field_index.base);
15291529
1530 const int_ty = ty.intTagType();
1530 const int_ty = try ty.intTagType(mod);
15311531 const int_info = ty.intInfo(mod);
15321532 assert(int_info.bits != 0);
15331533
......@@ -2805,7 +2805,7 @@ pub const DeclGen = struct {
28052805 return dg.context.intType(info.bits);
28062806 },
28072807 .Enum => {
2808 const int_ty = t.intTagType();
2808 const int_ty = try t.intTagType(mod);
28092809 const bit_count = int_ty.intInfo(mod).bits;
28102810 assert(bit_count != 0);
28112811 return dg.context.intType(bit_count);
......@@ -4334,7 +4334,9 @@ pub const DeclGen = struct {
43344334 const mod = dg.module;
43354335 const int_ty = switch (ty.zigTypeTag(mod)) {
43364336 .Int => ty,
4337 .Enum => ty.intTagType(),
4337 .Enum => ty.intTagType(mod) catch |err| switch (err) {
4338 error.OutOfMemory => @panic("OOM"),
4339 },
43384340 .Float => {
43394341 if (!is_rmw_xchg) return null;
43404342 return dg.context.intType(@intCast(c_uint, ty.abiSize(mod) * 8));
......@@ -5286,7 +5288,7 @@ pub const FuncGen = struct {
52865288 const mod = self.dg.module;
52875289 const scalar_ty = operand_ty.scalarType(mod);
52885290 const int_ty = switch (scalar_ty.zigTypeTag(mod)) {
5289 .Enum => scalar_ty.intTagType(),
5291 .Enum => try scalar_ty.intTagType(mod),
52905292 .Int, .Bool, .Pointer, .ErrorSet => scalar_ty,
52915293 .Optional => blk: {
52925294 const payload_ty = operand_ty.optionalChild(mod);
......@@ -8867,7 +8869,7 @@ pub const FuncGen = struct {
88678869 defer self.gpa.free(fqn);
88688870 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_is_named_enum_value_{s}", .{fqn});
88698871
8870 const int_tag_ty = enum_ty.intTagType();
8872 const int_tag_ty = try enum_ty.intTagType(mod);
88718873 const param_types = [_]*llvm.Type{try self.dg.lowerType(int_tag_ty)};
88728874
88738875 const llvm_ret_ty = try self.dg.lowerType(Type.bool);
......@@ -8950,7 +8952,7 @@ pub const FuncGen = struct {
89508952 const usize_llvm_ty = try self.dg.lowerType(Type.usize);
89518953 const slice_alignment = slice_ty.abiAlignment(mod);
89528954
8953 const int_tag_ty = enum_ty.intTagType();
8955 const int_tag_ty = try enum_ty.intTagType(mod);
89548956 const param_types = [_]*llvm.Type{try self.dg.lowerType(int_tag_ty)};
89558957
89568958 const fn_type = llvm.functionType(llvm_ret_ty, &param_types, param_types.len, .False);
......@@ -10487,7 +10489,7 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ
1048710489fn llvmFieldIndex(
1048810490 ty: Type,
1048910491 field_index: usize,
10490 mod: *const Module,
10492 mod: *Module,
1049110493 ptr_pl_buf: *Type.Payload.Pointer,
1049210494) ?c_uint {
1049310495 // Detects where we inserted extra padding fields so that we can skip
......@@ -10564,7 +10566,7 @@ fn llvmFieldIndex(
1056410566 }
1056510567}
1056610568
10567fn firstParamSRet(fn_info: Type.Payload.Function.Data, mod: *const Module) bool {
10569fn firstParamSRet(fn_info: Type.Payload.Function.Data, mod: *Module) bool {
1056810570 if (!fn_info.return_type.hasRuntimeBitsIgnoreComptime(mod)) return false;
1056910571
1057010572 const target = mod.getTarget();
......@@ -10593,7 +10595,7 @@ fn firstParamSRet(fn_info: Type.Payload.Function.Data, mod: *const Module) bool
1059310595 }
1059410596}
1059510597
10596fn firstParamSRetSystemV(ty: Type, mod: *const Module) bool {
10598fn firstParamSRetSystemV(ty: Type, mod: *Module) bool {
1059710599 const class = x86_64_abi.classifySystemV(ty, mod, .ret);
1059810600 if (class[0] == .memory) return true;
1059910601 if (class[0] == .x87 and class[2] != .none) return true;
......@@ -11041,7 +11043,7 @@ fn iterateParamTypes(dg: *DeclGen, fn_info: Type.Payload.Function.Data) ParamTyp
1104111043
1104211044fn ccAbiPromoteInt(
1104311045 cc: std.builtin.CallingConvention,
11044 mod: *const Module,
11046 mod: *Module,
1104511047 ty: Type,
1104611048) ?std.builtin.Signedness {
1104711049 const target = mod.getTarget();
......@@ -11080,7 +11082,7 @@ fn ccAbiPromoteInt(
1108011082
1108111083/// This is the one source of truth for whether a type is passed around as an LLVM pointer,
1108211084/// or as an LLVM value.
11083fn isByRef(ty: Type, mod: *const Module) bool {
11085fn isByRef(ty: Type, mod: *Module) bool {
1108411086 // For tuples and structs, if there are more than this many non-void
1108511087 // fields, then we make it byref, otherwise byval.
1108611088 const max_fields_byval = 0;
......@@ -11159,7 +11161,7 @@ fn isByRef(ty: Type, mod: *const Module) bool {
1115911161 }
1116011162}
1116111163
11162fn isScalar(mod: *const Module, ty: Type) bool {
11164fn isScalar(mod: *Module, ty: Type) bool {
1116311165 return switch (ty.zigTypeTag(mod)) {
1116411166 .Void,
1116511167 .Bool,
......@@ -11344,11 +11346,11 @@ fn buildAllocaInner(
1134411346 return alloca;
1134511347}
1134611348
11347fn errUnionPayloadOffset(payload_ty: Type, mod: *const Module) u1 {
11349fn errUnionPayloadOffset(payload_ty: Type, mod: *Module) u1 {
1134811350 return @boolToInt(Type.anyerror.abiAlignment(mod) > payload_ty.abiAlignment(mod));
1134911351}
1135011352
11351fn errUnionErrorOffset(payload_ty: Type, mod: *const Module) u1 {
11353fn errUnionErrorOffset(payload_ty: Type, mod: *Module) u1 {
1135211354 return @boolToInt(Type.anyerror.abiAlignment(mod) <= payload_ty.abiAlignment(mod));
1135311355}
1135411356
src/codegen/spirv.zig+3-3
......@@ -745,7 +745,7 @@ pub const DeclGen = struct {
745745 .Enum => {
746746 const int_val = try val.enumToInt(ty, mod);
747747
748 const int_ty = ty.intTagType();
748 const int_ty = try ty.intTagType(mod);
749749
750750 try self.lower(int_ty, int_val);
751751 },
......@@ -1195,7 +1195,7 @@ pub const DeclGen = struct {
11951195 return try self.intType(int_info.signedness, int_info.bits);
11961196 },
11971197 .Enum => {
1198 const tag_ty = ty.intTagType();
1198 const tag_ty = try ty.intTagType(mod);
11991199 return self.resolveType(tag_ty, repr);
12001200 },
12011201 .Float => {
......@@ -3090,7 +3090,7 @@ pub const DeclGen = struct {
30903090 break :blk if (backing_bits <= 32) @as(u32, 1) else 2;
30913091 },
30923092 .Enum => blk: {
3093 const int_ty = cond_ty.intTagType();
3093 const int_ty = try cond_ty.intTagType(mod);
30943094 const int_info = int_ty.intInfo(mod);
30953095 const backing_bits = self.backingIntBits(int_info.bits) orelse {
30963096 return self.todo("implement composite int switch", .{});
src/type.zig+37-43
......@@ -1606,7 +1606,7 @@ pub const Type = struct {
16061606 /// may return false positives.
16071607 pub fn hasRuntimeBitsAdvanced(
16081608 ty: Type,
1609 mod: *const Module,
1609 mod: *Module,
16101610 ignore_comptime_only: bool,
16111611 strat: AbiAlignmentAdvancedStrat,
16121612 ) RuntimeBitsError!bool {
......@@ -1785,7 +1785,7 @@ pub const Type = struct {
17851785 return enum_simple.fields.count() >= 2;
17861786 },
17871787 .enum_numbered, .enum_nonexhaustive => {
1788 const int_tag_ty = ty.intTagType();
1788 const int_tag_ty = try ty.intTagType(mod);
17891789 return int_tag_ty.hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
17901790 },
17911791
......@@ -1850,7 +1850,7 @@ pub const Type = struct {
18501850 /// true if and only if the type has a well-defined memory layout
18511851 /// readFrom/writeToMemory are supported only for types with a well-
18521852 /// defined memory layout
1853 pub fn hasWellDefinedLayout(ty: Type, mod: *const Module) bool {
1853 pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
18541854 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
18551855 .int_type => true,
18561856 .ptr_type => true,
......@@ -1952,15 +1952,15 @@ pub const Type = struct {
19521952 };
19531953 }
19541954
1955 pub fn hasRuntimeBits(ty: Type, mod: *const Module) bool {
1955 pub fn hasRuntimeBits(ty: Type, mod: *Module) bool {
19561956 return hasRuntimeBitsAdvanced(ty, mod, false, .eager) catch unreachable;
19571957 }
19581958
1959 pub fn hasRuntimeBitsIgnoreComptime(ty: Type, mod: *const Module) bool {
1959 pub fn hasRuntimeBitsIgnoreComptime(ty: Type, mod: *Module) bool {
19601960 return hasRuntimeBitsAdvanced(ty, mod, true, .eager) catch unreachable;
19611961 }
19621962
1963 pub fn isFnOrHasRuntimeBits(ty: Type, mod: *const Module) bool {
1963 pub fn isFnOrHasRuntimeBits(ty: Type, mod: *Module) bool {
19641964 switch (ty.zigTypeTag(mod)) {
19651965 .Fn => {
19661966 const fn_info = ty.fnInfo();
......@@ -1980,7 +1980,7 @@ pub const Type = struct {
19801980 }
19811981
19821982 /// Same as `isFnOrHasRuntimeBits` but comptime-only types may return a false positive.
1983 pub fn isFnOrHasRuntimeBitsIgnoreComptime(ty: Type, mod: *const Module) bool {
1983 pub fn isFnOrHasRuntimeBitsIgnoreComptime(ty: Type, mod: *Module) bool {
19841984 return switch (ty.zigTypeTag(mod)) {
19851985 .Fn => true,
19861986 else => return ty.hasRuntimeBitsIgnoreComptime(mod),
......@@ -2019,11 +2019,11 @@ pub const Type = struct {
20192019 }
20202020
20212021 /// Returns 0 if the pointer is naturally aligned and the element type is 0-bit.
2022 pub fn ptrAlignment(ty: Type, mod: *const Module) u32 {
2022 pub fn ptrAlignment(ty: Type, mod: *Module) u32 {
20232023 return ptrAlignmentAdvanced(ty, mod, null) catch unreachable;
20242024 }
20252025
2026 pub fn ptrAlignmentAdvanced(ty: Type, mod: *const Module, opt_sema: ?*Sema) !u32 {
2026 pub fn ptrAlignmentAdvanced(ty: Type, mod: *Module, opt_sema: ?*Sema) !u32 {
20272027 switch (ty.ip_index) {
20282028 .none => switch (ty.tag()) {
20292029 .pointer => {
......@@ -2072,7 +2072,7 @@ pub const Type = struct {
20722072 }
20732073
20742074 /// Returns 0 for 0-bit types.
2075 pub fn abiAlignment(ty: Type, mod: *const Module) u32 {
2075 pub fn abiAlignment(ty: Type, mod: *Module) u32 {
20762076 return (ty.abiAlignmentAdvanced(mod, .eager) catch unreachable).scalar;
20772077 }
20782078
......@@ -2103,7 +2103,7 @@ pub const Type = struct {
21032103 /// necessary, possibly returning a CompileError.
21042104 pub fn abiAlignmentAdvanced(
21052105 ty: Type,
2106 mod: *const Module,
2106 mod: *Module,
21072107 strat: AbiAlignmentAdvancedStrat,
21082108 ) Module.CompileError!AbiAlignmentAdvanced {
21092109 const target = mod.getTarget();
......@@ -2320,7 +2320,7 @@ pub const Type = struct {
23202320 },
23212321
23222322 .enum_full, .enum_nonexhaustive, .enum_simple, .enum_numbered => {
2323 const int_tag_ty = ty.intTagType();
2323 const int_tag_ty = try ty.intTagType(mod);
23242324 return AbiAlignmentAdvanced{ .scalar = int_tag_ty.abiAlignment(mod) };
23252325 },
23262326 .@"union" => {
......@@ -2344,7 +2344,7 @@ pub const Type = struct {
23442344
23452345 fn abiAlignmentAdvancedErrorUnion(
23462346 ty: Type,
2347 mod: *const Module,
2347 mod: *Module,
23482348 strat: AbiAlignmentAdvancedStrat,
23492349 ) Module.CompileError!AbiAlignmentAdvanced {
23502350 // This code needs to be kept in sync with the equivalent switch prong
......@@ -2380,7 +2380,7 @@ pub const Type = struct {
23802380
23812381 fn abiAlignmentAdvancedOptional(
23822382 ty: Type,
2383 mod: *const Module,
2383 mod: *Module,
23842384 strat: AbiAlignmentAdvancedStrat,
23852385 ) Module.CompileError!AbiAlignmentAdvanced {
23862386 const target = mod.getTarget();
......@@ -2412,7 +2412,7 @@ pub const Type = struct {
24122412
24132413 pub fn abiAlignmentAdvancedUnion(
24142414 ty: Type,
2415 mod: *const Module,
2415 mod: *Module,
24162416 strat: AbiAlignmentAdvancedStrat,
24172417 union_obj: *Module.Union,
24182418 have_tag: bool,
......@@ -2477,7 +2477,7 @@ pub const Type = struct {
24772477
24782478 /// Asserts the type has the ABI size already resolved.
24792479 /// Types that return false for hasRuntimeBits() return 0.
2480 pub fn abiSize(ty: Type, mod: *const Module) u64 {
2480 pub fn abiSize(ty: Type, mod: *Module) u64 {
24812481 return (abiSizeAdvanced(ty, mod, .eager) catch unreachable).scalar;
24822482 }
24832483
......@@ -2494,7 +2494,7 @@ pub const Type = struct {
24942494 /// necessary, possibly returning a CompileError.
24952495 pub fn abiSizeAdvanced(
24962496 ty: Type,
2497 mod: *const Module,
2497 mod: *Module,
24982498 strat: AbiAlignmentAdvancedStrat,
24992499 ) Module.CompileError!AbiSizeAdvanced {
25002500 const target = mod.getTarget();
......@@ -2661,7 +2661,7 @@ pub const Type = struct {
26612661 },
26622662
26632663 .enum_simple, .enum_full, .enum_nonexhaustive, .enum_numbered => {
2664 const int_tag_ty = ty.intTagType();
2664 const int_tag_ty = try ty.intTagType(mod);
26652665 return AbiSizeAdvanced{ .scalar = int_tag_ty.abiSize(mod) };
26662666 },
26672667 .@"union" => {
......@@ -2754,7 +2754,7 @@ pub const Type = struct {
27542754
27552755 pub fn abiSizeAdvancedUnion(
27562756 ty: Type,
2757 mod: *const Module,
2757 mod: *Module,
27582758 strat: AbiAlignmentAdvancedStrat,
27592759 union_obj: *Module.Union,
27602760 have_tag: bool,
......@@ -2773,7 +2773,7 @@ pub const Type = struct {
27732773
27742774 fn abiSizeAdvancedOptional(
27752775 ty: Type,
2776 mod: *const Module,
2776 mod: *Module,
27772777 strat: AbiAlignmentAdvancedStrat,
27782778 ) Module.CompileError!AbiSizeAdvanced {
27792779 const child_ty = ty.optionalChild(mod);
......@@ -2821,7 +2821,7 @@ pub const Type = struct {
28212821 );
28222822 }
28232823
2824 pub fn bitSize(ty: Type, mod: *const Module) u64 {
2824 pub fn bitSize(ty: Type, mod: *Module) u64 {
28252825 return bitSizeAdvanced(ty, mod, null) catch unreachable;
28262826 }
28272827
......@@ -2830,7 +2830,7 @@ pub const Type = struct {
28302830 /// the type is fully resolved, and there will be no error, guaranteed.
28312831 pub fn bitSizeAdvanced(
28322832 ty: Type,
2833 mod: *const Module,
2833 mod: *Module,
28342834 opt_sema: ?*Sema,
28352835 ) Module.CompileError!u64 {
28362836 const target = mod.getTarget();
......@@ -2950,7 +2950,7 @@ pub const Type = struct {
29502950 },
29512951
29522952 .enum_simple, .enum_full, .enum_nonexhaustive, .enum_numbered => {
2953 const int_tag_ty = ty.intTagType();
2953 const int_tag_ty = try ty.intTagType(mod);
29542954 return try bitSizeAdvanced(int_tag_ty, mod, opt_sema);
29552955 },
29562956
......@@ -3464,11 +3464,11 @@ pub const Type = struct {
34643464 return union_obj.fields.getIndex(name);
34653465 }
34663466
3467 pub fn unionHasAllZeroBitFieldTypes(ty: Type, mod: *const Module) bool {
3467 pub fn unionHasAllZeroBitFieldTypes(ty: Type, mod: *Module) bool {
34683468 return ty.cast(Payload.Union).?.data.hasAllZeroBitFieldTypes(mod);
34693469 }
34703470
3471 pub fn unionGetLayout(ty: Type, mod: *const Module) Module.Union.Layout {
3471 pub fn unionGetLayout(ty: Type, mod: *Module) Module.Union.Layout {
34723472 switch (ty.tag()) {
34733473 .@"union" => {
34743474 const union_obj = ty.castTag(.@"union").?.data;
......@@ -4428,24 +4428,18 @@ pub const Type = struct {
44284428 }
44294429
44304430 /// Asserts the type is an enum or a union.
4431 pub fn intTagType(ty: Type) Type {
4431 pub fn intTagType(ty: Type, mod: *Module) !Type {
44324432 switch (ty.tag()) {
44334433 .enum_full, .enum_nonexhaustive => return ty.cast(Payload.EnumFull).?.data.tag_ty,
44344434 .enum_numbered => return ty.castTag(.enum_numbered).?.data.tag_ty,
44354435 .enum_simple => {
4436 @panic("TODO move enum_simple to use the intern pool");
4437 //const enum_simple = ty.castTag(.enum_simple).?.data;
4438 //const field_count = enum_simple.fields.count();
4439 //const bits: u16 = if (field_count == 0) 0 else std.math.log2_int_ceil(usize, field_count);
4440 //buffer.* = .{
4441 // .base = .{ .tag = .int_unsigned },
4442 // .data = bits,
4443 //};
4444 //return Type.initPayload(&buffer.base);
4436 const enum_simple = ty.castTag(.enum_simple).?.data;
4437 const field_count = enum_simple.fields.count();
4438 const bits: u16 = if (field_count == 0) 0 else std.math.log2_int_ceil(usize, field_count);
4439 return mod.intType(.unsigned, bits);
44454440 },
44464441 .union_tagged => {
4447 @panic("TODO move union_tagged to use the intern pool");
4448 //return ty.castTag(.union_tagged).?.data.tag_ty.intTagType(buffer),
4442 return ty.castTag(.union_tagged).?.data.tag_ty.intTagType(mod);
44494443 },
44504444 else => unreachable,
44514445 }
......@@ -4628,7 +4622,7 @@ pub const Type = struct {
46284622 }
46294623 }
46304624
4631 pub fn structFieldAlign(ty: Type, index: usize, mod: *const Module) u32 {
4625 pub fn structFieldAlign(ty: Type, index: usize, mod: *Module) u32 {
46324626 switch (ty.tag()) {
46334627 .@"struct" => {
46344628 const struct_obj = ty.castTag(.@"struct").?.data;
......@@ -4718,7 +4712,7 @@ pub const Type = struct {
47184712 }
47194713 }
47204714
4721 pub fn packedStructFieldByteOffset(ty: Type, field_index: usize, mod: *const Module) u32 {
4715 pub fn packedStructFieldByteOffset(ty: Type, field_index: usize, mod: *Module) u32 {
47224716 const struct_obj = ty.castTag(.@"struct").?.data;
47234717 assert(struct_obj.layout == .Packed);
47244718 comptime assert(Type.packed_struct_layout_version == 2);
......@@ -4750,7 +4744,7 @@ pub const Type = struct {
47504744 offset: u64 = 0,
47514745 big_align: u32 = 0,
47524746 struct_obj: *Module.Struct,
4753 module: *const Module,
4747 module: *Module,
47544748
47554749 pub fn next(it: *StructOffsetIterator) ?FieldOffset {
47564750 const mod = it.module;
......@@ -4779,7 +4773,7 @@ pub const Type = struct {
47794773
47804774 /// Get an iterator that iterates over all the struct field, returning the field and
47814775 /// offset of that field. Asserts that the type is a non-packed struct.
4782 pub fn iterateStructOffsets(ty: Type, mod: *const Module) StructOffsetIterator {
4776 pub fn iterateStructOffsets(ty: Type, mod: *Module) StructOffsetIterator {
47834777 const struct_obj = ty.castTag(.@"struct").?.data;
47844778 assert(struct_obj.haveLayout());
47854779 assert(struct_obj.layout != .Packed);
......@@ -4787,7 +4781,7 @@ pub const Type = struct {
47874781 }
47884782
47894783 /// Supports structs and unions.
4790 pub fn structFieldOffset(ty: Type, index: usize, mod: *const Module) u64 {
4784 pub fn structFieldOffset(ty: Type, index: usize, mod: *Module) u64 {
47914785 switch (ty.tag()) {
47924786 .@"struct" => {
47934787 const struct_obj = ty.castTag(.@"struct").?.data;
......@@ -5226,7 +5220,7 @@ pub const Type = struct {
52265220
52275221 pub const VectorIndex = InternPool.Key.PtrType.VectorIndex;
52285222
5229 pub fn alignment(data: Data, mod: *const Module) u32 {
5223 pub fn alignment(data: Data, mod: *Module) u32 {
52305224 if (data.@"align" != 0) return data.@"align";
52315225 return abiAlignment(data.pointee_type, mod);
52325226 }
src/value.zig+23-21
......@@ -694,7 +694,7 @@ pub const Value = struct {
694694 },
695695 .enum_simple => {
696696 // Field index and integer values are the same.
697 const tag_ty = ty.intTagType();
697 const tag_ty = try ty.intTagType(mod);
698698 return mod.intValue(tag_ty, field_index);
699699 },
700700 else => unreachable,
......@@ -722,7 +722,9 @@ pub const Value = struct {
722722 // auto-numbered enum
723723 break :field_index @intCast(u32, val.toUnsignedInt(mod));
724724 }
725 const int_tag_ty = ty.intTagType();
725 const int_tag_ty = ty.intTagType(mod) catch |err| switch (err) {
726 error.OutOfMemory => @panic("OOM"), // TODO handle this failure
727 };
726728 break :field_index @intCast(u32, values.getIndexContext(val, .{ .ty = int_tag_ty, .mod = mod }).?);
727729 },
728730 };
......@@ -737,7 +739,7 @@ pub const Value = struct {
737739 }
738740
739741 /// Asserts the value is an integer.
740 pub fn toBigInt(val: Value, space: *BigIntSpace, mod: *const Module) BigIntConst {
742 pub fn toBigInt(val: Value, space: *BigIntSpace, mod: *Module) BigIntConst {
741743 return val.toBigIntAdvanced(space, mod, null) catch unreachable;
742744 }
743745
......@@ -745,7 +747,7 @@ pub const Value = struct {
745747 pub fn toBigIntAdvanced(
746748 val: Value,
747749 space: *BigIntSpace,
748 mod: *const Module,
750 mod: *Module,
749751 opt_sema: ?*Sema,
750752 ) Module.CompileError!BigIntConst {
751753 return switch (val.ip_index) {
......@@ -801,13 +803,13 @@ pub const Value = struct {
801803
802804 /// If the value fits in a u64, return it, otherwise null.
803805 /// Asserts not undefined.
804 pub fn getUnsignedInt(val: Value, mod: *const Module) ?u64 {
806 pub fn getUnsignedInt(val: Value, mod: *Module) ?u64 {
805807 return getUnsignedIntAdvanced(val, mod, null) catch unreachable;
806808 }
807809
808810 /// If the value fits in a u64, return it, otherwise null.
809811 /// Asserts not undefined.
810 pub fn getUnsignedIntAdvanced(val: Value, mod: *const Module, opt_sema: ?*Sema) !?u64 {
812 pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64 {
811813 switch (val.ip_index) {
812814 .bool_false => return 0,
813815 .bool_true => return 1,
......@@ -847,12 +849,12 @@ pub const Value = struct {
847849 }
848850
849851 /// Asserts the value is an integer and it fits in a u64
850 pub fn toUnsignedInt(val: Value, mod: *const Module) u64 {
852 pub fn toUnsignedInt(val: Value, mod: *Module) u64 {
851853 return getUnsignedInt(val, mod).?;
852854 }
853855
854856 /// Asserts the value is an integer and it fits in a i64
855 pub fn toSignedInt(val: Value, mod: *const Module) i64 {
857 pub fn toSignedInt(val: Value, mod: *Module) i64 {
856858 switch (val.ip_index) {
857859 .bool_false => return 0,
858860 .bool_true => return 1,
......@@ -1405,7 +1407,7 @@ pub const Value = struct {
14051407 }
14061408 }
14071409
1408 pub fn clz(val: Value, ty: Type, mod: *const Module) u64 {
1410 pub fn clz(val: Value, ty: Type, mod: *Module) u64 {
14091411 const ty_bits = ty.intInfo(mod).bits;
14101412 return switch (val.ip_index) {
14111413 .bool_false => ty_bits,
......@@ -1435,7 +1437,7 @@ pub const Value = struct {
14351437 };
14361438 }
14371439
1438 pub fn ctz(val: Value, ty: Type, mod: *const Module) u64 {
1440 pub fn ctz(val: Value, ty: Type, mod: *Module) u64 {
14391441 const ty_bits = ty.intInfo(mod).bits;
14401442 return switch (val.ip_index) {
14411443 .bool_false => ty_bits,
......@@ -1468,7 +1470,7 @@ pub const Value = struct {
14681470 };
14691471 }
14701472
1471 pub fn popCount(val: Value, ty: Type, mod: *const Module) u64 {
1473 pub fn popCount(val: Value, ty: Type, mod: *Module) u64 {
14721474 assert(!val.isUndef());
14731475 switch (val.ip_index) {
14741476 .bool_false => return 0,
......@@ -1527,7 +1529,7 @@ pub const Value = struct {
15271529
15281530 /// Asserts the value is an integer and not undefined.
15291531 /// Returns the number of bits the value requires to represent stored in twos complement form.
1530 pub fn intBitCountTwosComp(self: Value, mod: *const Module) usize {
1532 pub fn intBitCountTwosComp(self: Value, mod: *Module) usize {
15311533 const target = mod.getTarget();
15321534 return switch (self.ip_index) {
15331535 .bool_false => 0,
......@@ -1593,13 +1595,13 @@ pub const Value = struct {
15931595 };
15941596 }
15951597
1596 pub fn orderAgainstZero(lhs: Value, mod: *const Module) std.math.Order {
1598 pub fn orderAgainstZero(lhs: Value, mod: *Module) std.math.Order {
15971599 return orderAgainstZeroAdvanced(lhs, mod, null) catch unreachable;
15981600 }
15991601
16001602 pub fn orderAgainstZeroAdvanced(
16011603 lhs: Value,
1602 mod: *const Module,
1604 mod: *Module,
16031605 opt_sema: ?*Sema,
16041606 ) Module.CompileError!std.math.Order {
16051607 switch (lhs.ip_index) {
......@@ -1683,13 +1685,13 @@ pub const Value = struct {
16831685 }
16841686
16851687 /// Asserts the value is comparable.
1686 pub fn order(lhs: Value, rhs: Value, mod: *const Module) std.math.Order {
1688 pub fn order(lhs: Value, rhs: Value, mod: *Module) std.math.Order {
16871689 return orderAdvanced(lhs, rhs, mod, null) catch unreachable;
16881690 }
16891691
16901692 /// Asserts the value is comparable.
16911693 /// If opt_sema is null then this function asserts things are resolved and cannot fail.
1692 pub fn orderAdvanced(lhs: Value, rhs: Value, mod: *const Module, opt_sema: ?*Sema) !std.math.Order {
1694 pub fn orderAdvanced(lhs: Value, rhs: Value, mod: *Module, opt_sema: ?*Sema) !std.math.Order {
16931695 const lhs_against_zero = try lhs.orderAgainstZeroAdvanced(mod, opt_sema);
16941696 const rhs_against_zero = try rhs.orderAgainstZeroAdvanced(mod, opt_sema);
16951697 switch (lhs_against_zero) {
......@@ -1734,7 +1736,7 @@ pub const Value = struct {
17341736
17351737 /// Asserts the value is comparable. Does not take a type parameter because it supports
17361738 /// comparisons between heterogeneous types.
1737 pub fn compareHetero(lhs: Value, op: std.math.CompareOperator, rhs: Value, mod: *const Module) bool {
1739 pub fn compareHetero(lhs: Value, op: std.math.CompareOperator, rhs: Value, mod: *Module) bool {
17381740 return compareHeteroAdvanced(lhs, op, rhs, mod, null) catch unreachable;
17391741 }
17401742
......@@ -1742,7 +1744,7 @@ pub const Value = struct {
17421744 lhs: Value,
17431745 op: std.math.CompareOperator,
17441746 rhs: Value,
1745 mod: *const Module,
1747 mod: *Module,
17461748 opt_sema: ?*Sema,
17471749 ) !bool {
17481750 if (lhs.pointerDecl()) |lhs_decl| {
......@@ -2047,7 +2049,7 @@ pub const Value = struct {
20472049 .Enum => {
20482050 const a_val = try a.enumToInt(ty, mod);
20492051 const b_val = try b.enumToInt(ty, mod);
2050 const int_ty = ty.intTagType();
2052 const int_ty = try ty.intTagType(mod);
20512053 return eqlAdvanced(a_val, int_ty, b_val, int_ty, mod, opt_sema);
20522054 },
20532055 .Array, .Vector => {
......@@ -2462,7 +2464,7 @@ pub const Value = struct {
24622464 };
24632465 }
24642466
2465 fn hashInt(int_val: Value, hasher: *std.hash.Wyhash, mod: *const Module) void {
2467 fn hashInt(int_val: Value, hasher: *std.hash.Wyhash, mod: *Module) void {
24662468 var buffer: BigIntSpace = undefined;
24672469 const big = int_val.toBigInt(&buffer, mod);
24682470 std.hash.autoHash(hasher, big.positive);
......@@ -2471,7 +2473,7 @@ pub const Value = struct {
24712473 }
24722474 }
24732475
2474 fn hashPtr(ptr_val: Value, hasher: *std.hash.Wyhash, mod: *const Module) void {
2476 fn hashPtr(ptr_val: Value, hasher: *std.hash.Wyhash, mod: *Module) void {
24752477 switch (ptr_val.tag()) {
24762478 .decl_ref,
24772479 .decl_ref_mut,