authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-02 19:49:11+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-02 19:49:11+03:00
log6aee07c1446f3ce98d326998c887fbca3b7fd945
treeba0dbe68453d8ac431c9ba7aabd4f2cd40a18a56
parentf281f3d10e4eaedc7c68afc4fcbbfd35e1f29a0f

Sema: remove unused src param from typeRequiresComptime


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

src/Module.zig+1-1
......@@ -4635,7 +4635,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
46354635 decl.analysis = .complete;
46364636 decl.generation = mod.generation;
46374637
4638 const has_runtime_bits = try sema.fnHasRuntimeBits(&block_scope, ty_src, decl.ty);
4638 const has_runtime_bits = try sema.fnHasRuntimeBits(decl.ty);
46394639
46404640 if (has_runtime_bits) {
46414641 // We don't fully codegen the decl until later, but we do need to reserve a global
src/Sema.zig+32-32
......@@ -2865,7 +2865,7 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
28652865 const inst_data = sema.code.instructions.items(.data)[inst].node;
28662866 const src = LazySrcLoc.nodeOffset(inst_data);
28672867
2868 if (block.is_comptime or try sema.typeRequiresComptime(block, src, sema.fn_ret_ty)) {
2868 if (block.is_comptime or try sema.typeRequiresComptime(sema.fn_ret_ty)) {
28692869 const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty);
28702870 return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src);
28712871 }
......@@ -5788,7 +5788,7 @@ fn analyzeCall(
57885788 var is_comptime_call = block.is_comptime or modifier == .compile_time;
57895789 var comptime_only_ret_ty = false;
57905790 if (!is_comptime_call) {
5791 if (sema.typeRequiresComptime(block, func_src, func_ty_info.return_type)) |ct| {
5791 if (sema.typeRequiresComptime(func_ty_info.return_type)) |ct| {
57925792 is_comptime_call = ct;
57935793 comptime_only_ret_ty = ct;
57945794 } else |err| switch (err) {
......@@ -6226,7 +6226,7 @@ fn analyzeInlineCallArg(
62266226 const param_ty = try sema.analyzeAsType(param_block, param_src, param_ty_inst);
62276227 new_fn_info.param_types[arg_i.*] = param_ty;
62286228 const uncasted_arg = uncasted_args[arg_i.*];
6229 if (try sema.typeRequiresComptime(arg_block, arg_src, param_ty)) {
6229 if (try sema.typeRequiresComptime(param_ty)) {
62306230 _ = sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to parameter with comptime only type must be comptime known") catch |err| {
62316231 if (err == error.AnalysisFail and sema.err != null) {
62326232 try sema.addComptimeReturnTypeNote(arg_block, func, func_src, ret_ty, sema.err.?, comptime_only_ret_ty);
......@@ -6328,7 +6328,7 @@ fn analyzeGenericCallArg(
63286328) !void {
63296329 const is_runtime = comptime_arg.val.tag() == .generic_poison and
63306330 comptime_arg.ty.hasRuntimeBits() and
6331 !(try sema.typeRequiresComptime(block, arg_src, comptime_arg.ty));
6331 !(try sema.typeRequiresComptime(comptime_arg.ty));
63326332 if (is_runtime) {
63336333 const param_ty = new_fn_info.param_types[runtime_i.*];
63346334 const casted_arg = try sema.coerce(block, param_ty, uncasted_arg, arg_src);
......@@ -6593,7 +6593,7 @@ fn instantiateGenericCall(
65936593 }
65946594 } else if (is_anytype) {
65956595 const arg_ty = sema.typeOf(arg);
6596 if (try sema.typeRequiresComptime(block, .unneeded, arg_ty)) {
6596 if (try sema.typeRequiresComptime(arg_ty)) {
65976597 const arg_val = try sema.resolveConstValue(block, .unneeded, arg, undefined);
65986598 const child_arg = try child_sema.addConstant(arg_ty, arg_val);
65996599 child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg);
......@@ -6646,7 +6646,7 @@ fn instantiateGenericCall(
66466646 const arg = child_sema.inst_map.get(inst).?;
66476647 const copied_arg_ty = try child_sema.typeOf(arg).copy(new_decl_arena_allocator);
66486648
6649 if (try sema.typeRequiresComptime(block, .unneeded, copied_arg_ty)) {
6649 if (try sema.typeRequiresComptime(copied_arg_ty)) {
66506650 is_comptime = true;
66516651 }
66526652
......@@ -6677,7 +6677,7 @@ fn instantiateGenericCall(
66776677 // If the call evaluated to a return type that requires comptime, never mind
66786678 // our generic instantiation. Instead we need to perform a comptime call.
66796679 const new_fn_info = new_decl.ty.fnInfo();
6680 if (try sema.typeRequiresComptime(block, call_src, new_fn_info.return_type)) {
6680 if (try sema.typeRequiresComptime(new_fn_info.return_type)) {
66816681 return error.ComptimeReturn;
66826682 }
66836683 // Similarly, if the call evaluated to a generic type we need to instead
......@@ -7858,7 +7858,7 @@ fn funcCommon(
78587858 }
78597859
78607860 var ret_ty_requires_comptime = false;
7861 const ret_poison = if (sema.typeRequiresComptime(block, ret_ty_src, bare_return_type)) |ret_comptime| rp: {
7861 const ret_poison = if (sema.typeRequiresComptime(bare_return_type)) |ret_comptime| rp: {
78627862 ret_ty_requires_comptime = ret_comptime;
78637863 break :rp bare_return_type.tag() == .generic_poison;
78647864 } else |err| switch (err) {
......@@ -8092,7 +8092,7 @@ fn analyzeParameter(
80928092 cc: std.builtin.CallingConvention,
80938093 has_body: bool,
80948094) !void {
8095 const requires_comptime = try sema.typeRequiresComptime(block, param_src, param.ty);
8095 const requires_comptime = try sema.typeRequiresComptime(param.ty);
80968096 comptime_params[i] = param.is_comptime or requires_comptime;
80978097 const this_generic = param.ty.tag() == .generic_poison;
80988098 is_generic.* = is_generic.* or this_generic;
......@@ -8197,7 +8197,7 @@ fn zirParam(
81978197 }
81988198 };
81998199 const is_comptime = comptime_syntax or
8200 try sema.typeRequiresComptime(block, src, param_ty);
8200 try sema.typeRequiresComptime(param_ty);
82018201 if (sema.inst_map.get(inst)) |arg| {
82028202 if (is_comptime) {
82038203 // We have a comptime value for this parameter so it should be elided from the
......@@ -8257,7 +8257,7 @@ fn zirParamAnytype(
82578257
82588258 if (sema.inst_map.get(inst)) |air_ref| {
82598259 const param_ty = sema.typeOf(air_ref);
8260 if (comptime_syntax or try sema.typeRequiresComptime(block, src, param_ty)) {
8260 if (comptime_syntax or try sema.typeRequiresComptime(param_ty)) {
82618261 // We have a comptime value for this parameter so it should be elided from the
82628262 // function type of the function instruction in this block.
82638263 return;
......@@ -20368,7 +20368,7 @@ fn validateRunTimeType(
2036820368 .Void,
2036920369 => return true,
2037020370
20371 .Enum => return !(try sema.typeRequiresComptime(block, src, ty)),
20371 .Enum => return !(try sema.typeRequiresComptime(ty)),
2037220372
2037320373 .BoundFn,
2037420374 .ComptimeFloat,
......@@ -20402,7 +20402,7 @@ fn validateRunTimeType(
2040220402
2040320403 .Struct, .Union => {
2040420404 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
20405 const needs_comptime = try sema.typeRequiresComptime(block, src, resolved_ty);
20405 const needs_comptime = try sema.typeRequiresComptime(resolved_ty);
2040620406 return !needs_comptime;
2040720407 },
2040820408 };
......@@ -20510,7 +20510,7 @@ fn explainWhyTypeIsComptimeInner(
2051020510 .range = .type,
2051120511 });
2051220512
20513 if (try sema.typeRequiresComptime(block, src, field.ty)) {
20513 if (try sema.typeRequiresComptime(field.ty)) {
2051420514 try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{});
2051520515 try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set);
2051620516 }
......@@ -20530,7 +20530,7 @@ fn explainWhyTypeIsComptimeInner(
2053020530 .range = .type,
2053120531 });
2053220532
20533 if (try sema.typeRequiresComptime(block, src, field.ty)) {
20533 if (try sema.typeRequiresComptime(field.ty)) {
2053420534 try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{});
2053520535 try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set);
2053620536 }
......@@ -27627,7 +27627,7 @@ pub fn resolveTypeLayout(
2762727627 // In case of querying the ABI alignment of this optional, we will ask
2762827628 // for hasRuntimeBits() of the payload type, so we need "requires comptime"
2762927629 // to be known already before this function returns.
27630 _ = try sema.typeRequiresComptime(block, src, payload_ty);
27630 _ = try sema.typeRequiresComptime(payload_ty);
2763127631 return sema.resolveTypeLayout(block, src, payload_ty);
2763227632 },
2763327633 .ErrorUnion => {
......@@ -27682,7 +27682,7 @@ fn resolveStructLayout(
2768227682 // for hasRuntimeBits() of each field, so we need "requires comptime"
2768327683 // to be known already before this function returns.
2768427684 for (struct_obj.fields.values()) |field, i| {
27685 _ = sema.typeRequiresComptime(block, src, field.ty) catch |err| switch (err) {
27685 _ = sema.typeRequiresComptime(field.ty) catch |err| switch (err) {
2768627686 error.AnalysisFail => {
2768727687 const msg = sema.err orelse return err;
2768827688 try sema.addFieldErrNote(block, ty, i, msg, "while checking this field", .{});
......@@ -27914,7 +27914,7 @@ fn resolveStructFully(
2791427914 }
2791527915
2791627916 // And let's not forget comptime-only status.
27917 _ = try sema.typeRequiresComptime(block, src, ty);
27917 _ = try sema.typeRequiresComptime(ty);
2791827918}
2791927919
2792027920fn resolveUnionFully(
......@@ -27947,7 +27947,7 @@ fn resolveUnionFully(
2794727947 }
2794827948
2794927949 // And let's not forget comptime-only status.
27950 _ = try sema.typeRequiresComptime(block, src, ty);
27950 _ = try sema.typeRequiresComptime(ty);
2795127951}
2795227952
2795327953pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {
......@@ -29582,7 +29582,7 @@ fn typePtrOrOptionalPtrTy(
2958229582/// TODO assert the return value matches `ty.comptimeOnly`
2958329583/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen
2958429584/// elsewhere in value.zig
29585pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
29585pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
2958629586 return switch (ty.tag()) {
2958729587 .u1,
2958829588 .u8,
......@@ -29673,7 +29673,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2967329673 .array,
2967429674 .array_sentinel,
2967529675 .vector,
29676 => return sema.typeRequiresComptime(block, src, ty.childType()),
29676 => return sema.typeRequiresComptime(ty.childType()),
2967729677
2967829678 .pointer,
2967929679 .single_const_pointer,
......@@ -29689,7 +29689,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2968929689 if (child_ty.zigTypeTag() == .Fn) {
2969029690 return child_ty.fnInfo().is_generic;
2969129691 } else {
29692 return sema.typeRequiresComptime(block, src, child_ty);
29692 return sema.typeRequiresComptime(child_ty);
2969329693 }
2969429694 },
2969529695
......@@ -29698,14 +29698,14 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2969829698 .optional_single_const_pointer,
2969929699 => {
2970029700 var buf: Type.Payload.ElemType = undefined;
29701 return sema.typeRequiresComptime(block, src, ty.optionalChild(&buf));
29701 return sema.typeRequiresComptime(ty.optionalChild(&buf));
2970229702 },
2970329703
2970429704 .tuple, .anon_struct => {
2970529705 const tuple = ty.tupleFields();
2970629706 for (tuple.types) |field_ty, i| {
2970729707 const have_comptime_val = tuple.values[i].tag() != .unreachable_value;
29708 if (!have_comptime_val and try sema.typeRequiresComptime(block, src, field_ty)) {
29708 if (!have_comptime_val and try sema.typeRequiresComptime(field_ty)) {
2970929709 return true;
2971029710 }
2971129711 }
......@@ -29726,7 +29726,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2972629726 struct_obj.requires_comptime = .wip;
2972729727 for (struct_obj.fields.values()) |field| {
2972829728 if (field.is_comptime) continue;
29729 if (try sema.typeRequiresComptime(block, src, field.ty)) {
29729 if (try sema.typeRequiresComptime(field.ty)) {
2973029730 struct_obj.requires_comptime = .yes;
2973129731 return true;
2973229732 }
......@@ -29750,7 +29750,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2975029750
2975129751 union_obj.requires_comptime = .wip;
2975229752 for (union_obj.fields.values()) |field| {
29753 if (try sema.typeRequiresComptime(block, src, field.ty)) {
29753 if (try sema.typeRequiresComptime(field.ty)) {
2975429754 union_obj.requires_comptime = .yes;
2975529755 return true;
2975629756 }
......@@ -29761,18 +29761,18 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ
2976129761 }
2976229762 },
2976329763
29764 .error_union => return sema.typeRequiresComptime(block, src, ty.errorUnionPayload()),
29764 .error_union => return sema.typeRequiresComptime(ty.errorUnionPayload()),
2976529765 .anyframe_T => {
2976629766 const child_ty = ty.castTag(.anyframe_T).?.data;
29767 return sema.typeRequiresComptime(block, src, child_ty);
29767 return sema.typeRequiresComptime(child_ty);
2976829768 },
2976929769 .enum_numbered => {
2977029770 const tag_ty = ty.castTag(.enum_numbered).?.data.tag_ty;
29771 return sema.typeRequiresComptime(block, src, tag_ty);
29771 return sema.typeRequiresComptime(tag_ty);
2977229772 },
2977329773 .enum_full, .enum_nonexhaustive => {
2977429774 const tag_ty = ty.cast(Type.Payload.EnumFull).?.data.tag_ty;
29775 return sema.typeRequiresComptime(block, src, tag_ty);
29775 return sema.typeRequiresComptime(tag_ty);
2977629776 },
2977729777 };
2977829778}
......@@ -29810,7 +29810,7 @@ fn unionFieldAlignment(
2981029810}
2981129811
2981229812/// Synchronize logic with `Type.isFnOrHasRuntimeBits`.
29813pub fn fnHasRuntimeBits(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
29813pub fn fnHasRuntimeBits(sema: *Sema, ty: Type) CompileError!bool {
2981429814 const fn_info = ty.fnInfo();
2981529815 if (fn_info.is_generic) return false;
2981629816 if (fn_info.is_var_args) return true;
......@@ -29819,7 +29819,7 @@ pub fn fnHasRuntimeBits(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) C
2981929819 .Inline => return false,
2982029820 else => {},
2982129821 }
29822 if (try sema.typeRequiresComptime(block, src, fn_info.return_type)) {
29822 if (try sema.typeRequiresComptime(fn_info.return_type)) {
2982329823 return false;
2982429824 }
2982529825 return true;
src/type.zig+2-2
......@@ -2401,7 +2401,7 @@ pub const Type = extern union {
24012401 } else if (ty.childType().zigTypeTag() == .Fn) {
24022402 return !ty.childType().fnInfo().is_generic;
24032403 } else if (sema_kit) |sk| {
2404 return !(try sk.sema.typeRequiresComptime(sk.block, sk.src, ty));
2404 return !(try sk.sema.typeRequiresComptime(ty));
24052405 } else {
24062406 return !comptimeOnly(ty);
24072407 }
......@@ -2440,7 +2440,7 @@ pub const Type = extern union {
24402440 if (ignore_comptime_only) {
24412441 return true;
24422442 } else if (sema_kit) |sk| {
2443 return !(try sk.sema.typeRequiresComptime(sk.block, sk.src, child_ty));
2443 return !(try sk.sema.typeRequiresComptime(child_ty));
24442444 } else {
24452445 return !comptimeOnly(child_ty);
24462446 }