authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-07-15 16:18:41+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-07-16 11:38:20+01:00
logb1d3d48f687a3a73be1d9ab85035cbdc58e2bb1b
treed81f3d9705ba2bf164ed6468ae18315c7a7ffe89
parent9356cb1475606a7afd2e722af60f87ce2b39f9f8
signaturelock-open Commit is signed but in an unrecognized format.

Type,Value: mark `ResolveStrat` parameter of type queries as `comptime`

This eliminates the statically-reachable recursion loop between code generation backends and Sema. This is beneficial for optimizers (although I do not measure any performance improvement for this change), and for profilers.

3 files changed, 22 insertions(+), 22 deletions(-)

src/Type.zig+12-12
......@@ -478,7 +478,7 @@ pub fn hasRuntimeBitsAdvanced(
478478 ty: Type,
479479 pt: Zcu.PerThread,
480480 ignore_comptime_only: bool,
481 strat: ResolveStratLazy,
481 comptime strat: ResolveStratLazy,
482482) RuntimeBitsError!bool {
483483 const mod = pt.zcu;
484484 const ip = &mod.intern_pool;
......@@ -792,7 +792,7 @@ pub fn fnHasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool {
792792/// Determines whether a function type has runtime bits, i.e. whether a
793793/// function with this type can exist at runtime.
794794/// Asserts that `ty` is a function type.
795pub fn fnHasRuntimeBitsAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) SemaError!bool {
795pub fn fnHasRuntimeBitsAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) SemaError!bool {
796796 const fn_info = pt.zcu.typeToFunc(ty).?;
797797 if (fn_info.is_generic) return false;
798798 if (fn_info.is_var_args) return true;
......@@ -824,7 +824,7 @@ pub fn ptrAlignment(ty: Type, pt: Zcu.PerThread) Alignment {
824824 return ptrAlignmentAdvanced(ty, pt, .normal) catch unreachable;
825825}
826826
827pub fn ptrAlignmentAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) !Alignment {
827pub fn ptrAlignmentAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Alignment {
828828 return switch (pt.zcu.intern_pool.indexToKey(ty.toIntern())) {
829829 .ptr_type => |ptr_type| {
830830 if (ptr_type.flags.alignment != .none)
......@@ -891,7 +891,7 @@ pub const ResolveStrat = enum {
891891 /// This should typically be used from semantic analysis.
892892 sema,
893893
894 pub fn toLazy(strat: ResolveStrat) ResolveStratLazy {
894 pub inline fn toLazy(strat: ResolveStrat) ResolveStratLazy {
895895 return switch (strat) {
896896 .normal => .eager,
897897 .sema => .sema,
......@@ -908,7 +908,7 @@ pub const ResolveStrat = enum {
908908pub fn abiAlignmentAdvanced(
909909 ty: Type,
910910 pt: Zcu.PerThread,
911 strat: ResolveStratLazy,
911 comptime strat: ResolveStratLazy,
912912) SemaError!AbiAlignmentAdvanced {
913913 const mod = pt.zcu;
914914 const target = mod.getTarget();
......@@ -1130,7 +1130,7 @@ pub fn abiAlignmentAdvanced(
11301130fn abiAlignmentAdvancedErrorUnion(
11311131 ty: Type,
11321132 pt: Zcu.PerThread,
1133 strat: ResolveStratLazy,
1133 comptime strat: ResolveStratLazy,
11341134 payload_ty: Type,
11351135) SemaError!AbiAlignmentAdvanced {
11361136 // This code needs to be kept in sync with the equivalent switch prong
......@@ -1167,7 +1167,7 @@ fn abiAlignmentAdvancedErrorUnion(
11671167fn abiAlignmentAdvancedOptional(
11681168 ty: Type,
11691169 pt: Zcu.PerThread,
1170 strat: ResolveStratLazy,
1170 comptime strat: ResolveStratLazy,
11711171) SemaError!AbiAlignmentAdvanced {
11721172 const mod = pt.zcu;
11731173 const target = mod.getTarget();
......@@ -1231,7 +1231,7 @@ const AbiSizeAdvanced = union(enum) {
12311231pub fn abiSizeAdvanced(
12321232 ty: Type,
12331233 pt: Zcu.PerThread,
1234 strat: ResolveStratLazy,
1234 comptime strat: ResolveStratLazy,
12351235) SemaError!AbiSizeAdvanced {
12361236 const mod = pt.zcu;
12371237 const target = mod.getTarget();
......@@ -1505,7 +1505,7 @@ pub fn abiSizeAdvanced(
15051505fn abiSizeAdvancedOptional(
15061506 ty: Type,
15071507 pt: Zcu.PerThread,
1508 strat: ResolveStratLazy,
1508 comptime strat: ResolveStratLazy,
15091509) SemaError!AbiSizeAdvanced {
15101510 const mod = pt.zcu;
15111511 const child_ty = ty.optionalChild(mod);
......@@ -1680,7 +1680,7 @@ pub fn bitSize(ty: Type, pt: Zcu.PerThread) u64 {
16801680pub fn bitSizeAdvanced(
16811681 ty: Type,
16821682 pt: Zcu.PerThread,
1683 strat: ResolveStrat,
1683 comptime strat: ResolveStrat,
16841684) SemaError!u64 {
16851685 const mod = pt.zcu;
16861686 const target = mod.getTarget();
......@@ -2739,7 +2739,7 @@ pub fn comptimeOnly(ty: Type, pt: Zcu.PerThread) bool {
27392739
27402740/// `generic_poison` will return false.
27412741/// May return false negatives when structs and unions are having their field types resolved.
2742pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) SemaError!bool {
2742pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) SemaError!bool {
27432743 const mod = pt.zcu;
27442744 const ip = &mod.intern_pool;
27452745 return switch (ty.toIntern()) {
......@@ -3198,7 +3198,7 @@ pub fn structFieldAlign(ty: Type, index: usize, pt: Zcu.PerThread) Alignment {
31983198 return ty.structFieldAlignAdvanced(index, pt, .normal) catch unreachable;
31993199}
32003200
3201pub fn structFieldAlignAdvanced(ty: Type, index: usize, pt: Zcu.PerThread, strat: ResolveStrat) !Alignment {
3201pub fn structFieldAlignAdvanced(ty: Type, index: usize, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Alignment {
32023202 const ip = &pt.zcu.intern_pool;
32033203 switch (ip.indexToKey(ty.toIntern())) {
32043204 .struct_type => {
src/Value.zig+8-8
......@@ -178,7 +178,7 @@ pub fn toBigIntAdvanced(
178178 val: Value,
179179 space: *BigIntSpace,
180180 pt: Zcu.PerThread,
181 strat: ResolveStrat,
181 comptime strat: ResolveStrat,
182182) Module.CompileError!BigIntConst {
183183 return switch (val.toIntern()) {
184184 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),
......@@ -240,7 +240,7 @@ pub fn getUnsignedInt(val: Value, pt: Zcu.PerThread) ?u64 {
240240
241241/// If the value fits in a u64, return it, otherwise null.
242242/// Asserts not undefined.
243pub fn getUnsignedIntAdvanced(val: Value, pt: Zcu.PerThread, strat: ResolveStrat) !?u64 {
243pub fn getUnsignedIntAdvanced(val: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !?u64 {
244244 const mod = pt.zcu;
245245 return switch (val.toIntern()) {
246246 .undef => unreachable,
......@@ -1042,7 +1042,7 @@ pub fn orderAgainstZero(lhs: Value, pt: Zcu.PerThread) std.math.Order {
10421042pub fn orderAgainstZeroAdvanced(
10431043 lhs: Value,
10441044 pt: Zcu.PerThread,
1045 strat: ResolveStrat,
1045 comptime strat: ResolveStrat,
10461046) Module.CompileError!std.math.Order {
10471047 return switch (lhs.toIntern()) {
10481048 .bool_false => .eq,
......@@ -1081,7 +1081,7 @@ pub fn order(lhs: Value, rhs: Value, pt: Zcu.PerThread) std.math.Order {
10811081}
10821082
10831083/// Asserts the value is comparable.
1084pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, strat: ResolveStrat) !std.math.Order {
1084pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !std.math.Order {
10851085 const lhs_against_zero = try lhs.orderAgainstZeroAdvanced(pt, strat);
10861086 const rhs_against_zero = try rhs.orderAgainstZeroAdvanced(pt, strat);
10871087 switch (lhs_against_zero) {
......@@ -1119,7 +1119,7 @@ pub fn compareHeteroAdvanced(
11191119 op: std.math.CompareOperator,
11201120 rhs: Value,
11211121 pt: Zcu.PerThread,
1122 strat: ResolveStrat,
1122 comptime strat: ResolveStrat,
11231123) !bool {
11241124 if (lhs.pointerDecl(pt.zcu)) |lhs_decl| {
11251125 if (rhs.pointerDecl(pt.zcu)) |rhs_decl| {
......@@ -1199,7 +1199,7 @@ pub fn compareAllWithZeroAdvancedExtra(
11991199 lhs: Value,
12001200 op: std.math.CompareOperator,
12011201 pt: Zcu.PerThread,
1202 strat: ResolveStrat,
1202 comptime strat: ResolveStrat,
12031203) Module.CompileError!bool {
12041204 const mod = pt.zcu;
12051205 if (lhs.isInf(mod)) {
......@@ -1505,7 +1505,7 @@ pub fn floatFromIntAdvanced(
15051505 int_ty: Type,
15061506 float_ty: Type,
15071507 pt: Zcu.PerThread,
1508 strat: ResolveStrat,
1508 comptime strat: ResolveStrat,
15091509) !Value {
15101510 const mod = pt.zcu;
15111511 if (int_ty.zigTypeTag(mod) == .Vector) {
......@@ -1523,7 +1523,7 @@ pub fn floatFromIntAdvanced(
15231523 return floatFromIntScalar(val, float_ty, pt, strat);
15241524}
15251525
1526pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) !Value {
1526pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Value {
15271527 const mod = pt.zcu;
15281528 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
15291529 .undef => try pt.undefValue(float_ty),
src/Zcu/PerThread.zig+2-2
......@@ -3145,7 +3145,7 @@ pub fn unionFieldNormalAlignmentAdvanced(
31453145 pt: Zcu.PerThread,
31463146 loaded_union: InternPool.LoadedUnionType,
31473147 field_index: u32,
3148 strat: Type.ResolveStrat,
3148 comptime strat: Type.ResolveStrat,
31493149) Zcu.SemaError!InternPool.Alignment {
31503150 const ip = &pt.zcu.intern_pool;
31513151 assert(loaded_union.flagsUnordered(ip).layout != .@"packed");
......@@ -3173,7 +3173,7 @@ pub fn structFieldAlignmentAdvanced(
31733173 explicit_alignment: InternPool.Alignment,
31743174 field_ty: Type,
31753175 layout: std.builtin.Type.ContainerLayout,
3176 strat: Type.ResolveStrat,
3176 comptime strat: Type.ResolveStrat,
31773177) Zcu.SemaError!InternPool.Alignment {
31783178 assert(layout != .@"packed");
31793179 if (explicit_alignment != .none) return explicit_alignment;