Commit 6aee07c144

Veikka Tuominen <git@vexu.eu>
2022-09-02 18:49:11
Sema: remove unused src param from typeRequiresComptime
1 parent f281f3d
Changed files (3)
src/Module.zig
@@ -4635,7 +4635,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
             decl.analysis = .complete;
             decl.generation = mod.generation;
 
-            const has_runtime_bits = try sema.fnHasRuntimeBits(&block_scope, ty_src, decl.ty);
+            const has_runtime_bits = try sema.fnHasRuntimeBits(decl.ty);
 
             if (has_runtime_bits) {
                 // We don't fully codegen the decl until later, but we do need to reserve a global
src/Sema.zig
@@ -2865,7 +2865,7 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
     const inst_data = sema.code.instructions.items(.data)[inst].node;
     const src = LazySrcLoc.nodeOffset(inst_data);
 
-    if (block.is_comptime or try sema.typeRequiresComptime(block, src, sema.fn_ret_ty)) {
+    if (block.is_comptime or try sema.typeRequiresComptime(sema.fn_ret_ty)) {
         const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty);
         return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src);
     }
@@ -5788,7 +5788,7 @@ fn analyzeCall(
     var is_comptime_call = block.is_comptime or modifier == .compile_time;
     var comptime_only_ret_ty = false;
     if (!is_comptime_call) {
-        if (sema.typeRequiresComptime(block, func_src, func_ty_info.return_type)) |ct| {
+        if (sema.typeRequiresComptime(func_ty_info.return_type)) |ct| {
             is_comptime_call = ct;
             comptime_only_ret_ty = ct;
         } else |err| switch (err) {
@@ -6226,7 +6226,7 @@ fn analyzeInlineCallArg(
             const param_ty = try sema.analyzeAsType(param_block, param_src, param_ty_inst);
             new_fn_info.param_types[arg_i.*] = param_ty;
             const uncasted_arg = uncasted_args[arg_i.*];
-            if (try sema.typeRequiresComptime(arg_block, arg_src, param_ty)) {
+            if (try sema.typeRequiresComptime(param_ty)) {
                 _ = sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to parameter with comptime only type must be comptime known") catch |err| {
                     if (err == error.AnalysisFail and sema.err != null) {
                         try sema.addComptimeReturnTypeNote(arg_block, func, func_src, ret_ty, sema.err.?, comptime_only_ret_ty);
@@ -6328,7 +6328,7 @@ fn analyzeGenericCallArg(
 ) !void {
     const is_runtime = comptime_arg.val.tag() == .generic_poison and
         comptime_arg.ty.hasRuntimeBits() and
-        !(try sema.typeRequiresComptime(block, arg_src, comptime_arg.ty));
+        !(try sema.typeRequiresComptime(comptime_arg.ty));
     if (is_runtime) {
         const param_ty = new_fn_info.param_types[runtime_i.*];
         const casted_arg = try sema.coerce(block, param_ty, uncasted_arg, arg_src);
@@ -6593,7 +6593,7 @@ fn instantiateGenericCall(
                 }
             } else if (is_anytype) {
                 const arg_ty = sema.typeOf(arg);
-                if (try sema.typeRequiresComptime(block, .unneeded, arg_ty)) {
+                if (try sema.typeRequiresComptime(arg_ty)) {
                     const arg_val = try sema.resolveConstValue(block, .unneeded, arg, undefined);
                     const child_arg = try child_sema.addConstant(arg_ty, arg_val);
                     child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg);
@@ -6646,7 +6646,7 @@ fn instantiateGenericCall(
             const arg = child_sema.inst_map.get(inst).?;
             const copied_arg_ty = try child_sema.typeOf(arg).copy(new_decl_arena_allocator);
 
-            if (try sema.typeRequiresComptime(block, .unneeded, copied_arg_ty)) {
+            if (try sema.typeRequiresComptime(copied_arg_ty)) {
                 is_comptime = true;
             }
 
@@ -6677,7 +6677,7 @@ fn instantiateGenericCall(
         // If the call evaluated to a return type that requires comptime, never mind
         // our generic instantiation. Instead we need to perform a comptime call.
         const new_fn_info = new_decl.ty.fnInfo();
-        if (try sema.typeRequiresComptime(block, call_src, new_fn_info.return_type)) {
+        if (try sema.typeRequiresComptime(new_fn_info.return_type)) {
             return error.ComptimeReturn;
         }
         // Similarly, if the call evaluated to a generic type we need to instead
@@ -7858,7 +7858,7 @@ fn funcCommon(
         }
 
         var ret_ty_requires_comptime = false;
-        const ret_poison = if (sema.typeRequiresComptime(block, ret_ty_src, bare_return_type)) |ret_comptime| rp: {
+        const ret_poison = if (sema.typeRequiresComptime(bare_return_type)) |ret_comptime| rp: {
             ret_ty_requires_comptime = ret_comptime;
             break :rp bare_return_type.tag() == .generic_poison;
         } else |err| switch (err) {
@@ -8092,7 +8092,7 @@ fn analyzeParameter(
     cc: std.builtin.CallingConvention,
     has_body: bool,
 ) !void {
-    const requires_comptime = try sema.typeRequiresComptime(block, param_src, param.ty);
+    const requires_comptime = try sema.typeRequiresComptime(param.ty);
     comptime_params[i] = param.is_comptime or requires_comptime;
     const this_generic = param.ty.tag() == .generic_poison;
     is_generic.* = is_generic.* or this_generic;
@@ -8197,7 +8197,7 @@ fn zirParam(
         }
     };
     const is_comptime = comptime_syntax or
-        try sema.typeRequiresComptime(block, src, param_ty);
+        try sema.typeRequiresComptime(param_ty);
     if (sema.inst_map.get(inst)) |arg| {
         if (is_comptime) {
             // We have a comptime value for this parameter so it should be elided from the
@@ -8257,7 +8257,7 @@ fn zirParamAnytype(
 
     if (sema.inst_map.get(inst)) |air_ref| {
         const param_ty = sema.typeOf(air_ref);
-        if (comptime_syntax or try sema.typeRequiresComptime(block, src, param_ty)) {
+        if (comptime_syntax or try sema.typeRequiresComptime(param_ty)) {
             // We have a comptime value for this parameter so it should be elided from the
             // function type of the function instruction in this block.
             return;
@@ -20368,7 +20368,7 @@ fn validateRunTimeType(
         .Void,
         => return true,
 
-        .Enum => return !(try sema.typeRequiresComptime(block, src, ty)),
+        .Enum => return !(try sema.typeRequiresComptime(ty)),
 
         .BoundFn,
         .ComptimeFloat,
@@ -20402,7 +20402,7 @@ fn validateRunTimeType(
 
         .Struct, .Union => {
             const resolved_ty = try sema.resolveTypeFields(block, src, ty);
-            const needs_comptime = try sema.typeRequiresComptime(block, src, resolved_ty);
+            const needs_comptime = try sema.typeRequiresComptime(resolved_ty);
             return !needs_comptime;
         },
     };
@@ -20510,7 +20510,7 @@ fn explainWhyTypeIsComptimeInner(
                         .range = .type,
                     });
 
-                    if (try sema.typeRequiresComptime(block, src, field.ty)) {
+                    if (try sema.typeRequiresComptime(field.ty)) {
                         try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{});
                         try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set);
                     }
@@ -20530,7 +20530,7 @@ fn explainWhyTypeIsComptimeInner(
                         .range = .type,
                     });
 
-                    if (try sema.typeRequiresComptime(block, src, field.ty)) {
+                    if (try sema.typeRequiresComptime(field.ty)) {
                         try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{});
                         try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set);
                     }
@@ -27627,7 +27627,7 @@ pub fn resolveTypeLayout(
             // In case of querying the ABI alignment of this optional, we will ask
             // for hasRuntimeBits() of the payload type, so we need "requires comptime"
             // to be known already before this function returns.
-            _ = try sema.typeRequiresComptime(block, src, payload_ty);
+            _ = try sema.typeRequiresComptime(payload_ty);
             return sema.resolveTypeLayout(block, src, payload_ty);
         },
         .ErrorUnion => {
@@ -27682,7 +27682,7 @@ fn resolveStructLayout(
         // for hasRuntimeBits() of each field, so we need "requires comptime"
         // to be known already before this function returns.
         for (struct_obj.fields.values()) |field, i| {
-            _ = sema.typeRequiresComptime(block, src, field.ty) catch |err| switch (err) {
+            _ = sema.typeRequiresComptime(field.ty) catch |err| switch (err) {
                 error.AnalysisFail => {
                     const msg = sema.err orelse return err;
                     try sema.addFieldErrNote(block, ty, i, msg, "while checking this field", .{});
@@ -27914,7 +27914,7 @@ fn resolveStructFully(
     }
 
     // And let's not forget comptime-only status.
-    _ = try sema.typeRequiresComptime(block, src, ty);
+    _ = try sema.typeRequiresComptime(ty);
 }
 
 fn resolveUnionFully(
@@ -27947,7 +27947,7 @@ fn resolveUnionFully(
     }
 
     // And let's not forget comptime-only status.
-    _ = try sema.typeRequiresComptime(block, src, ty);
+    _ = try sema.typeRequiresComptime(ty);
 }
 
 pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {
@@ -29582,7 +29582,7 @@ fn typePtrOrOptionalPtrTy(
 /// TODO assert the return value matches `ty.comptimeOnly`
 /// TODO merge these implementations together with the "advanced"/sema_kit pattern seen
 /// elsewhere in value.zig
-pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
+pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
     return switch (ty.tag()) {
         .u1,
         .u8,
@@ -29673,7 +29673,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
         .array,
         .array_sentinel,
         .vector,
-        => return sema.typeRequiresComptime(block, src, ty.childType()),
+        => return sema.typeRequiresComptime(ty.childType()),
 
         .pointer,
         .single_const_pointer,
@@ -29689,7 +29689,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
             if (child_ty.zigTypeTag() == .Fn) {
                 return child_ty.fnInfo().is_generic;
             } else {
-                return sema.typeRequiresComptime(block, src, child_ty);
+                return sema.typeRequiresComptime(child_ty);
             }
         },
 
@@ -29698,14 +29698,14 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
         .optional_single_const_pointer,
         => {
             var buf: Type.Payload.ElemType = undefined;
-            return sema.typeRequiresComptime(block, src, ty.optionalChild(&buf));
+            return sema.typeRequiresComptime(ty.optionalChild(&buf));
         },
 
         .tuple, .anon_struct => {
             const tuple = ty.tupleFields();
             for (tuple.types) |field_ty, i| {
                 const have_comptime_val = tuple.values[i].tag() != .unreachable_value;
-                if (!have_comptime_val and try sema.typeRequiresComptime(block, src, field_ty)) {
+                if (!have_comptime_val and try sema.typeRequiresComptime(field_ty)) {
                     return true;
                 }
             }
@@ -29726,7 +29726,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
                     struct_obj.requires_comptime = .wip;
                     for (struct_obj.fields.values()) |field| {
                         if (field.is_comptime) continue;
-                        if (try sema.typeRequiresComptime(block, src, field.ty)) {
+                        if (try sema.typeRequiresComptime(field.ty)) {
                             struct_obj.requires_comptime = .yes;
                             return true;
                         }
@@ -29750,7 +29750,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
 
                     union_obj.requires_comptime = .wip;
                     for (union_obj.fields.values()) |field| {
-                        if (try sema.typeRequiresComptime(block, src, field.ty)) {
+                        if (try sema.typeRequiresComptime(field.ty)) {
                             union_obj.requires_comptime = .yes;
                             return true;
                         }
@@ -29761,18 +29761,18 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
             }
         },
 
-        .error_union => return sema.typeRequiresComptime(block, src, ty.errorUnionPayload()),
+        .error_union => return sema.typeRequiresComptime(ty.errorUnionPayload()),
         .anyframe_T => {
             const child_ty = ty.castTag(.anyframe_T).?.data;
-            return sema.typeRequiresComptime(block, src, child_ty);
+            return sema.typeRequiresComptime(child_ty);
         },
         .enum_numbered => {
             const tag_ty = ty.castTag(.enum_numbered).?.data.tag_ty;
-            return sema.typeRequiresComptime(block, src, tag_ty);
+            return sema.typeRequiresComptime(tag_ty);
         },
         .enum_full, .enum_nonexhaustive => {
             const tag_ty = ty.cast(Type.Payload.EnumFull).?.data.tag_ty;
-            return sema.typeRequiresComptime(block, src, tag_ty);
+            return sema.typeRequiresComptime(tag_ty);
         },
     };
 }
@@ -29810,7 +29810,7 @@ fn unionFieldAlignment(
 }
 
 /// Synchronize logic with `Type.isFnOrHasRuntimeBits`.
-pub fn fnHasRuntimeBits(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
+pub fn fnHasRuntimeBits(sema: *Sema, ty: Type) CompileError!bool {
     const fn_info = ty.fnInfo();
     if (fn_info.is_generic) return false;
     if (fn_info.is_var_args) return true;
@@ -29819,7 +29819,7 @@ pub fn fnHasRuntimeBits(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) C
         .Inline => return false,
         else => {},
     }
-    if (try sema.typeRequiresComptime(block, src, fn_info.return_type)) {
+    if (try sema.typeRequiresComptime(fn_info.return_type)) {
         return false;
     }
     return true;
src/type.zig
@@ -2401,7 +2401,7 @@ pub const Type = extern union {
                 } else if (ty.childType().zigTypeTag() == .Fn) {
                     return !ty.childType().fnInfo().is_generic;
                 } else if (sema_kit) |sk| {
-                    return !(try sk.sema.typeRequiresComptime(sk.block, sk.src, ty));
+                    return !(try sk.sema.typeRequiresComptime(ty));
                 } else {
                     return !comptimeOnly(ty);
                 }
@@ -2440,7 +2440,7 @@ pub const Type = extern union {
                 if (ignore_comptime_only) {
                     return true;
                 } else if (sema_kit) |sk| {
-                    return !(try sk.sema.typeRequiresComptime(sk.block, sk.src, child_ty));
+                    return !(try sk.sema.typeRequiresComptime(child_ty));
                 } else {
                     return !comptimeOnly(child_ty);
                 }