| ... | ... | @@ -2865,7 +2865,7 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 2865 | 2865 | const inst_data = sema.code.instructions.items(.data)[inst].node; |
| 2866 | 2866 | const src = LazySrcLoc.nodeOffset(inst_data); |
| 2867 | 2867 | |
| 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)) { |
| 2869 | 2869 | const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty); |
| 2870 | 2870 | return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src); |
| 2871 | 2871 | } |
| ... | ... | @@ -5788,7 +5788,7 @@ fn analyzeCall( |
| 5788 | 5788 | var is_comptime_call = block.is_comptime or modifier == .compile_time; |
| 5789 | 5789 | var comptime_only_ret_ty = false; |
| 5790 | 5790 | 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| { |
| 5792 | 5792 | is_comptime_call = ct; |
| 5793 | 5793 | comptime_only_ret_ty = ct; |
| 5794 | 5794 | } else |err| switch (err) { |
| ... | ... | @@ -6226,7 +6226,7 @@ fn analyzeInlineCallArg( |
| 6226 | 6226 | const param_ty = try sema.analyzeAsType(param_block, param_src, param_ty_inst); |
| 6227 | 6227 | new_fn_info.param_types[arg_i.*] = param_ty; |
| 6228 | 6228 | 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)) { |
| 6230 | 6230 | _ = sema.resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to parameter with comptime only type must be comptime known") catch |err| { |
| 6231 | 6231 | if (err == error.AnalysisFail and sema.err != null) { |
| 6232 | 6232 | try sema.addComptimeReturnTypeNote(arg_block, func, func_src, ret_ty, sema.err.?, comptime_only_ret_ty); |
| ... | ... | @@ -6328,7 +6328,7 @@ fn analyzeGenericCallArg( |
| 6328 | 6328 | ) !void { |
| 6329 | 6329 | const is_runtime = comptime_arg.val.tag() == .generic_poison and |
| 6330 | 6330 | comptime_arg.ty.hasRuntimeBits() and |
| 6331 | | !(try sema.typeRequiresComptime(block, arg_src, comptime_arg.ty)); |
| 6331 | !(try sema.typeRequiresComptime(comptime_arg.ty)); |
| 6332 | 6332 | if (is_runtime) { |
| 6333 | 6333 | const param_ty = new_fn_info.param_types[runtime_i.*]; |
| 6334 | 6334 | const casted_arg = try sema.coerce(block, param_ty, uncasted_arg, arg_src); |
| ... | ... | @@ -6593,7 +6593,7 @@ fn instantiateGenericCall( |
| 6593 | 6593 | } |
| 6594 | 6594 | } else if (is_anytype) { |
| 6595 | 6595 | const arg_ty = sema.typeOf(arg); |
| 6596 | | if (try sema.typeRequiresComptime(block, .unneeded, arg_ty)) { |
| 6596 | if (try sema.typeRequiresComptime(arg_ty)) { |
| 6597 | 6597 | const arg_val = try sema.resolveConstValue(block, .unneeded, arg, undefined); |
| 6598 | 6598 | const child_arg = try child_sema.addConstant(arg_ty, arg_val); |
| 6599 | 6599 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); |
| ... | ... | @@ -6646,7 +6646,7 @@ fn instantiateGenericCall( |
| 6646 | 6646 | const arg = child_sema.inst_map.get(inst).?; |
| 6647 | 6647 | const copied_arg_ty = try child_sema.typeOf(arg).copy(new_decl_arena_allocator); |
| 6648 | 6648 | |
| 6649 | | if (try sema.typeRequiresComptime(block, .unneeded, copied_arg_ty)) { |
| 6649 | if (try sema.typeRequiresComptime(copied_arg_ty)) { |
| 6650 | 6650 | is_comptime = true; |
| 6651 | 6651 | } |
| 6652 | 6652 | |
| ... | ... | @@ -6677,7 +6677,7 @@ fn instantiateGenericCall( |
| 6677 | 6677 | // If the call evaluated to a return type that requires comptime, never mind |
| 6678 | 6678 | // our generic instantiation. Instead we need to perform a comptime call. |
| 6679 | 6679 | 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)) { |
| 6681 | 6681 | return error.ComptimeReturn; |
| 6682 | 6682 | } |
| 6683 | 6683 | // Similarly, if the call evaluated to a generic type we need to instead |
| ... | ... | @@ -7858,7 +7858,7 @@ fn funcCommon( |
| 7858 | 7858 | } |
| 7859 | 7859 | |
| 7860 | 7860 | 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: { |
| 7862 | 7862 | ret_ty_requires_comptime = ret_comptime; |
| 7863 | 7863 | break :rp bare_return_type.tag() == .generic_poison; |
| 7864 | 7864 | } else |err| switch (err) { |
| ... | ... | @@ -8092,7 +8092,7 @@ fn analyzeParameter( |
| 8092 | 8092 | cc: std.builtin.CallingConvention, |
| 8093 | 8093 | has_body: bool, |
| 8094 | 8094 | ) !void { |
| 8095 | | const requires_comptime = try sema.typeRequiresComptime(block, param_src, param.ty); |
| 8095 | const requires_comptime = try sema.typeRequiresComptime(param.ty); |
| 8096 | 8096 | comptime_params[i] = param.is_comptime or requires_comptime; |
| 8097 | 8097 | const this_generic = param.ty.tag() == .generic_poison; |
| 8098 | 8098 | is_generic.* = is_generic.* or this_generic; |
| ... | ... | @@ -8197,7 +8197,7 @@ fn zirParam( |
| 8197 | 8197 | } |
| 8198 | 8198 | }; |
| 8199 | 8199 | const is_comptime = comptime_syntax or |
| 8200 | | try sema.typeRequiresComptime(block, src, param_ty); |
| 8200 | try sema.typeRequiresComptime(param_ty); |
| 8201 | 8201 | if (sema.inst_map.get(inst)) |arg| { |
| 8202 | 8202 | if (is_comptime) { |
| 8203 | 8203 | // We have a comptime value for this parameter so it should be elided from the |
| ... | ... | @@ -8257,7 +8257,7 @@ fn zirParamAnytype( |
| 8257 | 8257 | |
| 8258 | 8258 | if (sema.inst_map.get(inst)) |air_ref| { |
| 8259 | 8259 | 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)) { |
| 8261 | 8261 | // We have a comptime value for this parameter so it should be elided from the |
| 8262 | 8262 | // function type of the function instruction in this block. |
| 8263 | 8263 | return; |
| ... | ... | @@ -20368,7 +20368,7 @@ fn validateRunTimeType( |
| 20368 | 20368 | .Void, |
| 20369 | 20369 | => return true, |
| 20370 | 20370 | |
| 20371 | | .Enum => return !(try sema.typeRequiresComptime(block, src, ty)), |
| 20371 | .Enum => return !(try sema.typeRequiresComptime(ty)), |
| 20372 | 20372 | |
| 20373 | 20373 | .BoundFn, |
| 20374 | 20374 | .ComptimeFloat, |
| ... | ... | @@ -20402,7 +20402,7 @@ fn validateRunTimeType( |
| 20402 | 20402 | |
| 20403 | 20403 | .Struct, .Union => { |
| 20404 | 20404 | 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); |
| 20406 | 20406 | return !needs_comptime; |
| 20407 | 20407 | }, |
| 20408 | 20408 | }; |
| ... | ... | @@ -20510,7 +20510,7 @@ fn explainWhyTypeIsComptimeInner( |
| 20510 | 20510 | .range = .type, |
| 20511 | 20511 | }); |
| 20512 | 20512 | |
| 20513 | | if (try sema.typeRequiresComptime(block, src, field.ty)) { |
| 20513 | if (try sema.typeRequiresComptime(field.ty)) { |
| 20514 | 20514 | try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{}); |
| 20515 | 20515 | try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set); |
| 20516 | 20516 | } |
| ... | ... | @@ -20530,7 +20530,7 @@ fn explainWhyTypeIsComptimeInner( |
| 20530 | 20530 | .range = .type, |
| 20531 | 20531 | }); |
| 20532 | 20532 | |
| 20533 | | if (try sema.typeRequiresComptime(block, src, field.ty)) { |
| 20533 | if (try sema.typeRequiresComptime(field.ty)) { |
| 20534 | 20534 | try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{}); |
| 20535 | 20535 | try sema.explainWhyTypeIsComptimeInner(block, src, msg, field_src_loc, field.ty, type_set); |
| 20536 | 20536 | } |
| ... | ... | @@ -27627,7 +27627,7 @@ pub fn resolveTypeLayout( |
| 27627 | 27627 | // In case of querying the ABI alignment of this optional, we will ask |
| 27628 | 27628 | // for hasRuntimeBits() of the payload type, so we need "requires comptime" |
| 27629 | 27629 | // to be known already before this function returns. |
| 27630 | | _ = try sema.typeRequiresComptime(block, src, payload_ty); |
| 27630 | _ = try sema.typeRequiresComptime(payload_ty); |
| 27631 | 27631 | return sema.resolveTypeLayout(block, src, payload_ty); |
| 27632 | 27632 | }, |
| 27633 | 27633 | .ErrorUnion => { |
| ... | ... | @@ -27682,7 +27682,7 @@ fn resolveStructLayout( |
| 27682 | 27682 | // for hasRuntimeBits() of each field, so we need "requires comptime" |
| 27683 | 27683 | // to be known already before this function returns. |
| 27684 | 27684 | 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) { |
| 27686 | 27686 | error.AnalysisFail => { |
| 27687 | 27687 | const msg = sema.err orelse return err; |
| 27688 | 27688 | try sema.addFieldErrNote(block, ty, i, msg, "while checking this field", .{}); |
| ... | ... | @@ -27914,7 +27914,7 @@ fn resolveStructFully( |
| 27914 | 27914 | } |
| 27915 | 27915 | |
| 27916 | 27916 | // And let's not forget comptime-only status. |
| 27917 | | _ = try sema.typeRequiresComptime(block, src, ty); |
| 27917 | _ = try sema.typeRequiresComptime(ty); |
| 27918 | 27918 | } |
| 27919 | 27919 | |
| 27920 | 27920 | fn resolveUnionFully( |
| ... | ... | @@ -27947,7 +27947,7 @@ fn resolveUnionFully( |
| 27947 | 27947 | } |
| 27948 | 27948 | |
| 27949 | 27949 | // And let's not forget comptime-only status. |
| 27950 | | _ = try sema.typeRequiresComptime(block, src, ty); |
| 27950 | _ = try sema.typeRequiresComptime(ty); |
| 27951 | 27951 | } |
| 27952 | 27952 | |
| 27953 | 27953 | pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type { |
| ... | ... | @@ -29582,7 +29582,7 @@ fn typePtrOrOptionalPtrTy( |
| 29582 | 29582 | /// TODO assert the return value matches `ty.comptimeOnly` |
| 29583 | 29583 | /// TODO merge these implementations together with the "advanced"/sema_kit pattern seen |
| 29584 | 29584 | /// elsewhere in value.zig |
| 29585 | | pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool { |
| 29585 | pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 29586 | 29586 | return switch (ty.tag()) { |
| 29587 | 29587 | .u1, |
| 29588 | 29588 | .u8, |
| ... | ... | @@ -29673,7 +29673,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ |
| 29673 | 29673 | .array, |
| 29674 | 29674 | .array_sentinel, |
| 29675 | 29675 | .vector, |
| 29676 | | => return sema.typeRequiresComptime(block, src, ty.childType()), |
| 29676 | => return sema.typeRequiresComptime(ty.childType()), |
| 29677 | 29677 | |
| 29678 | 29678 | .pointer, |
| 29679 | 29679 | .single_const_pointer, |
| ... | ... | @@ -29689,7 +29689,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ |
| 29689 | 29689 | if (child_ty.zigTypeTag() == .Fn) { |
| 29690 | 29690 | return child_ty.fnInfo().is_generic; |
| 29691 | 29691 | } else { |
| 29692 | | return sema.typeRequiresComptime(block, src, child_ty); |
| 29692 | return sema.typeRequiresComptime(child_ty); |
| 29693 | 29693 | } |
| 29694 | 29694 | }, |
| 29695 | 29695 | |
| ... | ... | @@ -29698,14 +29698,14 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ |
| 29698 | 29698 | .optional_single_const_pointer, |
| 29699 | 29699 | => { |
| 29700 | 29700 | var buf: Type.Payload.ElemType = undefined; |
| 29701 | | return sema.typeRequiresComptime(block, src, ty.optionalChild(&buf)); |
| 29701 | return sema.typeRequiresComptime(ty.optionalChild(&buf)); |
| 29702 | 29702 | }, |
| 29703 | 29703 | |
| 29704 | 29704 | .tuple, .anon_struct => { |
| 29705 | 29705 | const tuple = ty.tupleFields(); |
| 29706 | 29706 | for (tuple.types) |field_ty, i| { |
| 29707 | 29707 | 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)) { |
| 29709 | 29709 | return true; |
| 29710 | 29710 | } |
| 29711 | 29711 | } |
| ... | ... | @@ -29726,7 +29726,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ |
| 29726 | 29726 | struct_obj.requires_comptime = .wip; |
| 29727 | 29727 | for (struct_obj.fields.values()) |field| { |
| 29728 | 29728 | if (field.is_comptime) continue; |
| 29729 | | if (try sema.typeRequiresComptime(block, src, field.ty)) { |
| 29729 | if (try sema.typeRequiresComptime(field.ty)) { |
| 29730 | 29730 | struct_obj.requires_comptime = .yes; |
| 29731 | 29731 | return true; |
| 29732 | 29732 | } |
| ... | ... | @@ -29750,7 +29750,7 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ |
| 29750 | 29750 | |
| 29751 | 29751 | union_obj.requires_comptime = .wip; |
| 29752 | 29752 | for (union_obj.fields.values()) |field| { |
| 29753 | | if (try sema.typeRequiresComptime(block, src, field.ty)) { |
| 29753 | if (try sema.typeRequiresComptime(field.ty)) { |
| 29754 | 29754 | union_obj.requires_comptime = .yes; |
| 29755 | 29755 | return true; |
| 29756 | 29756 | } |
| ... | ... | @@ -29761,18 +29761,18 @@ pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Typ |
| 29761 | 29761 | } |
| 29762 | 29762 | }, |
| 29763 | 29763 | |
| 29764 | | .error_union => return sema.typeRequiresComptime(block, src, ty.errorUnionPayload()), |
| 29764 | .error_union => return sema.typeRequiresComptime(ty.errorUnionPayload()), |
| 29765 | 29765 | .anyframe_T => { |
| 29766 | 29766 | const child_ty = ty.castTag(.anyframe_T).?.data; |
| 29767 | | return sema.typeRequiresComptime(block, src, child_ty); |
| 29767 | return sema.typeRequiresComptime(child_ty); |
| 29768 | 29768 | }, |
| 29769 | 29769 | .enum_numbered => { |
| 29770 | 29770 | const tag_ty = ty.castTag(.enum_numbered).?.data.tag_ty; |
| 29771 | | return sema.typeRequiresComptime(block, src, tag_ty); |
| 29771 | return sema.typeRequiresComptime(tag_ty); |
| 29772 | 29772 | }, |
| 29773 | 29773 | .enum_full, .enum_nonexhaustive => { |
| 29774 | 29774 | 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); |
| 29776 | 29776 | }, |
| 29777 | 29777 | }; |
| 29778 | 29778 | } |
| ... | ... | @@ -29810,7 +29810,7 @@ fn unionFieldAlignment( |
| 29810 | 29810 | } |
| 29811 | 29811 | |
| 29812 | 29812 | /// Synchronize logic with `Type.isFnOrHasRuntimeBits`. |
| 29813 | | pub fn fnHasRuntimeBits(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool { |
| 29813 | pub fn fnHasRuntimeBits(sema: *Sema, ty: Type) CompileError!bool { |
| 29814 | 29814 | const fn_info = ty.fnInfo(); |
| 29815 | 29815 | if (fn_info.is_generic) return false; |
| 29816 | 29816 | if (fn_info.is_var_args) return true; |
| ... | ... | @@ -29819,7 +29819,7 @@ pub fn fnHasRuntimeBits(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) C |
| 29819 | 29819 | .Inline => return false, |
| 29820 | 29820 | else => {}, |
| 29821 | 29821 | } |
| 29822 | | if (try sema.typeRequiresComptime(block, src, fn_info.return_type)) { |
| 29822 | if (try sema.typeRequiresComptime(fn_info.return_type)) { |
| 29823 | 29823 | return false; |
| 29824 | 29824 | } |
| 29825 | 29825 | return true; |