| ... | @@ -818,6 +818,11 @@ const InferredAlloc = struct { | ... | @@ -818,6 +818,11 @@ const InferredAlloc = struct { |
| 818 | }) = .{}, | 818 | }) = .{}, |
| 819 | }; | 819 | }; |
| 820 | | 820 | |
| | 821 | const NeededComptimeReason = struct { |
| | 822 | needed_comptime_reason: []const u8, |
| | 823 | block_comptime_reason: ?*const Block.ComptimeReason = null, |
| | 824 | }; |
| | 825 | |
| 821 | pub fn deinit(sema: *Sema) void { | 826 | pub fn deinit(sema: *Sema) void { |
| 822 | const gpa = sema.gpa; | 827 | const gpa = sema.gpa; |
| 823 | sema.air_instructions.deinit(gpa); | 828 | sema.air_instructions.deinit(gpa); |
| ... | @@ -1654,10 +1659,10 @@ fn analyzeBodyInner( | ... | @@ -1654,10 +1659,10 @@ fn analyzeBodyInner( |
| 1654 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1659 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1655 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; | 1660 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; |
| 1656 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 1661 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; |
| 1657 | const cond = sema.resolveInstConst(block, cond_src, extra.data.condition, "condition in comptime branch must be comptime-known") catch |err| { | 1662 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{ |
| 1658 | if (err == error.AnalysisFail and block.comptime_reason != null) try block.comptime_reason.?.explain(sema, sema.err); | 1663 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1659 | return err; | 1664 | .block_comptime_reason = block.comptime_reason, |
| 1660 | }; | 1665 | }); |
| 1661 | const inline_body = if (cond.val.toBool()) then_body else else_body; | 1666 | const inline_body = if (cond.val.toBool()) then_body else else_body; |
| 1662 | | 1667 | |
| 1663 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); | 1668 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); |
| ... | @@ -1675,10 +1680,10 @@ fn analyzeBodyInner( | ... | @@ -1675,10 +1680,10 @@ fn analyzeBodyInner( |
| 1675 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1680 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1676 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; | 1681 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; |
| 1677 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 1682 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; |
| 1678 | const cond = sema.resolveInstConst(block, cond_src, extra.data.condition, "condition in comptime branch must be comptime-known") catch |err| { | 1683 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{ |
| 1679 | if (err == error.AnalysisFail and block.comptime_reason != null) try block.comptime_reason.?.explain(sema, sema.err); | 1684 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1680 | return err; | 1685 | .block_comptime_reason = block.comptime_reason, |
| 1681 | }; | 1686 | }); |
| 1682 | const inline_body = if (cond.val.toBool()) then_body else else_body; | 1687 | const inline_body = if (cond.val.toBool()) then_body else else_body; |
| 1683 | | 1688 | |
| 1684 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); | 1689 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); |
| ... | @@ -1708,10 +1713,10 @@ fn analyzeBodyInner( | ... | @@ -1708,10 +1713,10 @@ fn analyzeBodyInner( |
| 1708 | } | 1713 | } |
| 1709 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1714 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1710 | assert(is_non_err != .none); | 1715 | assert(is_non_err != .none); |
| 1711 | const is_non_err_val = sema.resolveConstValue(block, operand_src, is_non_err, "try operand inside comptime block must be comptime-known") catch |err| { | 1716 | const is_non_err_val = try sema.resolveConstValue(block, operand_src, is_non_err, .{ |
| 1712 | if (err == error.AnalysisFail and block.comptime_reason != null) try block.comptime_reason.?.explain(sema, sema.err); | 1717 | .needed_comptime_reason = "try operand inside comptime block must be comptime-known", |
| 1713 | return err; | 1718 | .block_comptime_reason = block.comptime_reason, |
| 1714 | }; | 1719 | }); |
| 1715 | if (is_non_err_val.toBool()) { | 1720 | if (is_non_err_val.toBool()) { |
| 1716 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); | 1721 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); |
| 1717 | } | 1722 | } |
| ... | @@ -1734,10 +1739,10 @@ fn analyzeBodyInner( | ... | @@ -1734,10 +1739,10 @@ fn analyzeBodyInner( |
| 1734 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); | 1739 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1735 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1740 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1736 | assert(is_non_err != .none); | 1741 | assert(is_non_err != .none); |
| 1737 | const is_non_err_val = sema.resolveConstValue(block, operand_src, is_non_err, "try operand inside comptime block must be comptime-known") catch |err| { | 1742 | const is_non_err_val = try sema.resolveConstValue(block, operand_src, is_non_err, .{ |
| 1738 | if (err == error.AnalysisFail and block.comptime_reason != null) try block.comptime_reason.?.explain(sema, sema.err); | 1743 | .needed_comptime_reason = "try operand inside comptime block must be comptime-known", |
| 1739 | return err; | 1744 | .block_comptime_reason = block.comptime_reason, |
| 1740 | }; | 1745 | }); |
| 1741 | if (is_non_err_val.toBool()) { | 1746 | if (is_non_err_val.toBool()) { |
| 1742 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); | 1747 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); |
| 1743 | } | 1748 | } |
| ... | @@ -1831,7 +1836,7 @@ fn resolveConstBool( | ... | @@ -1831,7 +1836,7 @@ fn resolveConstBool( |
| 1831 | block: *Block, | 1836 | block: *Block, |
| 1832 | src: LazySrcLoc, | 1837 | src: LazySrcLoc, |
| 1833 | zir_ref: Zir.Inst.Ref, | 1838 | zir_ref: Zir.Inst.Ref, |
| 1834 | reason: []const u8, | 1839 | reason: NeededComptimeReason, |
| 1835 | ) !bool { | 1840 | ) !bool { |
| 1836 | const air_inst = try sema.resolveInst(zir_ref); | 1841 | const air_inst = try sema.resolveInst(zir_ref); |
| 1837 | const wanted_type = Type.bool; | 1842 | const wanted_type = Type.bool; |
| ... | @@ -1845,7 +1850,7 @@ pub fn resolveConstString( | ... | @@ -1845,7 +1850,7 @@ pub fn resolveConstString( |
| 1845 | block: *Block, | 1850 | block: *Block, |
| 1846 | src: LazySrcLoc, | 1851 | src: LazySrcLoc, |
| 1847 | zir_ref: Zir.Inst.Ref, | 1852 | zir_ref: Zir.Inst.Ref, |
| 1848 | reason: []const u8, | 1853 | reason: NeededComptimeReason, |
| 1849 | ) ![]u8 { | 1854 | ) ![]u8 { |
| 1850 | const air_inst = try sema.resolveInst(zir_ref); | 1855 | const air_inst = try sema.resolveInst(zir_ref); |
| 1851 | const wanted_type = Type.slice_const_u8; | 1856 | const wanted_type = Type.slice_const_u8; |
| ... | @@ -1859,7 +1864,7 @@ pub fn resolveConstStringIntern( | ... | @@ -1859,7 +1864,7 @@ pub fn resolveConstStringIntern( |
| 1859 | block: *Block, | 1864 | block: *Block, |
| 1860 | src: LazySrcLoc, | 1865 | src: LazySrcLoc, |
| 1861 | zir_ref: Zir.Inst.Ref, | 1866 | zir_ref: Zir.Inst.Ref, |
| 1862 | reason: []const u8, | 1867 | reason: NeededComptimeReason, |
| 1863 | ) !InternPool.NullTerminatedString { | 1868 | ) !InternPool.NullTerminatedString { |
| 1864 | const air_inst = try sema.resolveInst(zir_ref); | 1869 | const air_inst = try sema.resolveInst(zir_ref); |
| 1865 | const wanted_type = Type.slice_const_u8; | 1870 | const wanted_type = Type.slice_const_u8; |
| ... | @@ -1931,7 +1936,9 @@ fn analyzeAsType( | ... | @@ -1931,7 +1936,9 @@ fn analyzeAsType( |
| 1931 | ) !Type { | 1936 | ) !Type { |
| 1932 | const wanted_type = Type.type; | 1937 | const wanted_type = Type.type; |
| 1933 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); | 1938 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 1934 | const val = try sema.resolveConstValue(block, src, coerced_inst, "types must be comptime-known"); | 1939 | const val = try sema.resolveConstValue(block, src, coerced_inst, .{ |
| | 1940 | .needed_comptime_reason = "types must be comptime-known", |
| | 1941 | }); |
| 1935 | return val.toType(); | 1942 | return val.toType(); |
| 1936 | } | 1943 | } |
| 1937 | | 1944 | |
| ... | @@ -1984,7 +1991,7 @@ fn resolveValue( | ... | @@ -1984,7 +1991,7 @@ fn resolveValue( |
| 1984 | block: *Block, | 1991 | block: *Block, |
| 1985 | src: LazySrcLoc, | 1992 | src: LazySrcLoc, |
| 1986 | air_ref: Air.Inst.Ref, | 1993 | air_ref: Air.Inst.Ref, |
| 1987 | reason: []const u8, | 1994 | reason: NeededComptimeReason, |
| 1988 | ) CompileError!Value { | 1995 | ) CompileError!Value { |
| 1989 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { | 1996 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 1990 | if (val.isGenericPoison()) return error.GenericPoison; | 1997 | if (val.isGenericPoison()) return error.GenericPoison; |
| ... | @@ -2000,7 +2007,7 @@ fn resolveConstMaybeUndefVal( | ... | @@ -2000,7 +2007,7 @@ fn resolveConstMaybeUndefVal( |
| 2000 | block: *Block, | 2007 | block: *Block, |
| 2001 | src: LazySrcLoc, | 2008 | src: LazySrcLoc, |
| 2002 | inst: Air.Inst.Ref, | 2009 | inst: Air.Inst.Ref, |
| 2003 | reason: []const u8, | 2010 | reason: NeededComptimeReason, |
| 2004 | ) CompileError!Value { | 2011 | ) CompileError!Value { |
| 2005 | if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| { | 2012 | if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| { |
| 2006 | if (val.isGenericPoison()) return error.GenericPoison; | 2013 | if (val.isGenericPoison()) return error.GenericPoison; |
| ... | @@ -2018,7 +2025,7 @@ fn resolveConstValue( | ... | @@ -2018,7 +2025,7 @@ fn resolveConstValue( |
| 2018 | block: *Block, | 2025 | block: *Block, |
| 2019 | src: LazySrcLoc, | 2026 | src: LazySrcLoc, |
| 2020 | air_ref: Air.Inst.Ref, | 2027 | air_ref: Air.Inst.Ref, |
| 2021 | reason: []const u8, | 2028 | reason: NeededComptimeReason, |
| 2022 | ) CompileError!Value { | 2029 | ) CompileError!Value { |
| 2023 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { | 2030 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 2024 | if (val.isGenericPoison()) return error.GenericPoison; | 2031 | if (val.isGenericPoison()) return error.GenericPoison; |
| ... | @@ -2037,7 +2044,7 @@ fn resolveConstLazyValue( | ... | @@ -2037,7 +2044,7 @@ fn resolveConstLazyValue( |
| 2037 | block: *Block, | 2044 | block: *Block, |
| 2038 | src: LazySrcLoc, | 2045 | src: LazySrcLoc, |
| 2039 | air_ref: Air.Inst.Ref, | 2046 | air_ref: Air.Inst.Ref, |
| 2040 | reason: []const u8, | 2047 | reason: NeededComptimeReason, |
| 2041 | ) CompileError!Value { | 2048 | ) CompileError!Value { |
| 2042 | return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason)); | 2049 | return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason)); |
| 2043 | } | 2050 | } |
| ... | @@ -2140,12 +2147,15 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( | ... | @@ -2140,12 +2147,15 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( |
| 2140 | return val; | 2147 | return val; |
| 2141 | } | 2148 | } |
| 2142 | | 2149 | |
| 2143 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: []const u8) CompileError { | 2150 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { |
| 2144 | const msg = msg: { | 2151 | const msg = msg: { |
| 2145 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); | 2152 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); |
| 2146 | errdefer msg.destroy(sema.gpa); | 2153 | errdefer msg.destroy(sema.gpa); |
| | 2154 | try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason}); |
| 2147 | | 2155 | |
| 2148 | try sema.errNote(block, src, msg, "{s}", .{reason}); | 2156 | if (reason.block_comptime_reason) |block_comptime_reason| { |
| | 2157 | try block_comptime_reason.explain(sema, msg); |
| | 2158 | } |
| 2149 | break :msg msg; | 2159 | break :msg msg; |
| 2150 | }; | 2160 | }; |
| 2151 | return sema.failWithOwnedErrorMsg(msg); | 2161 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -2507,7 +2517,9 @@ fn analyzeAsAlign( | ... | @@ -2507,7 +2517,9 @@ fn analyzeAsAlign( |
| 2507 | src: LazySrcLoc, | 2517 | src: LazySrcLoc, |
| 2508 | air_ref: Air.Inst.Ref, | 2518 | air_ref: Air.Inst.Ref, |
| 2509 | ) !Alignment { | 2519 | ) !Alignment { |
| 2510 | const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, "alignment must be comptime-known"); | 2520 | const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, .{ |
| | 2521 | .needed_comptime_reason = "alignment must be comptime-known", |
| | 2522 | }); |
| 2511 | const alignment: u32 = @intCast(alignment_big); // We coerce to u29 in the prev line. | 2523 | const alignment: u32 = @intCast(alignment_big); // We coerce to u29 in the prev line. |
| 2512 | try sema.validateAlign(block, src, alignment); | 2524 | try sema.validateAlign(block, src, alignment); |
| 2513 | return Alignment.fromNonzeroByteUnits(alignment); | 2525 | return Alignment.fromNonzeroByteUnits(alignment); |
| ... | @@ -2543,7 +2555,7 @@ fn resolveInt( | ... | @@ -2543,7 +2555,7 @@ fn resolveInt( |
| 2543 | src: LazySrcLoc, | 2555 | src: LazySrcLoc, |
| 2544 | zir_ref: Zir.Inst.Ref, | 2556 | zir_ref: Zir.Inst.Ref, |
| 2545 | dest_ty: Type, | 2557 | dest_ty: Type, |
| 2546 | reason: []const u8, | 2558 | reason: NeededComptimeReason, |
| 2547 | ) !u64 { | 2559 | ) !u64 { |
| 2548 | const air_ref = try sema.resolveInst(zir_ref); | 2560 | const air_ref = try sema.resolveInst(zir_ref); |
| 2549 | return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason); | 2561 | return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason); |
| ... | @@ -2555,7 +2567,7 @@ fn analyzeAsInt( | ... | @@ -2555,7 +2567,7 @@ fn analyzeAsInt( |
| 2555 | src: LazySrcLoc, | 2567 | src: LazySrcLoc, |
| 2556 | air_ref: Air.Inst.Ref, | 2568 | air_ref: Air.Inst.Ref, |
| 2557 | dest_ty: Type, | 2569 | dest_ty: Type, |
| 2558 | reason: []const u8, | 2570 | reason: NeededComptimeReason, |
| 2559 | ) !u64 { | 2571 | ) !u64 { |
| 2560 | const mod = sema.mod; | 2572 | const mod = sema.mod; |
| 2561 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); | 2573 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); |
| ... | @@ -2570,7 +2582,7 @@ pub fn resolveInstConst( | ... | @@ -2570,7 +2582,7 @@ pub fn resolveInstConst( |
| 2570 | block: *Block, | 2582 | block: *Block, |
| 2571 | src: LazySrcLoc, | 2583 | src: LazySrcLoc, |
| 2572 | zir_ref: Zir.Inst.Ref, | 2584 | zir_ref: Zir.Inst.Ref, |
| 2573 | reason: []const u8, | 2585 | reason: NeededComptimeReason, |
| 2574 | ) CompileError!TypedValue { | 2586 | ) CompileError!TypedValue { |
| 2575 | const air_ref = try sema.resolveInst(zir_ref); | 2587 | const air_ref = try sema.resolveInst(zir_ref); |
| 2576 | const val = try sema.resolveConstValue(block, src, air_ref, reason); | 2588 | const val = try sema.resolveConstValue(block, src, air_ref, reason); |
| ... | @@ -2587,7 +2599,7 @@ pub fn resolveInstValue( | ... | @@ -2587,7 +2599,7 @@ pub fn resolveInstValue( |
| 2587 | block: *Block, | 2599 | block: *Block, |
| 2588 | src: LazySrcLoc, | 2600 | src: LazySrcLoc, |
| 2589 | zir_ref: Zir.Inst.Ref, | 2601 | zir_ref: Zir.Inst.Ref, |
| 2590 | reason: []const u8, | 2602 | reason: NeededComptimeReason, |
| 2591 | ) CompileError!TypedValue { | 2603 | ) CompileError!TypedValue { |
| 2592 | const air_ref = try sema.resolveInst(zir_ref); | 2604 | const air_ref = try sema.resolveInst(zir_ref); |
| 2593 | const val = try sema.resolveValue(block, src, air_ref, reason); | 2605 | const val = try sema.resolveValue(block, src, air_ref, reason); |
| ... | @@ -2972,7 +2984,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2972,7 +2984,7 @@ fn createAnonymousDeclTypeNamed( |
| 2972 | // If not then this is a struct type being returned from a non-generic | 2984 | // If not then this is a struct type being returned from a non-generic |
| 2973 | // function and the name doesn't matter since it will later | 2985 | // function and the name doesn't matter since it will later |
| 2974 | // result in a compile error. | 2986 | // result in a compile error. |
| 2975 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch | 2987 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, undefined) catch |
| 2976 | return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null); | 2988 | return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null); |
| 2977 | | 2989 | |
| 2978 | if (arg_i != 0) try writer.writeByte(','); | 2990 | if (arg_i != 0) try writer.writeByte(','); |
| ... | @@ -3221,13 +3233,15 @@ fn zirEnumDecl( | ... | @@ -3221,13 +3233,15 @@ fn zirEnumDecl( |
| 3221 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 3233 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 3222 | extra_index += 1; | 3234 | extra_index += 1; |
| 3223 | const tag_inst = try sema.resolveInst(tag_val_ref); | 3235 | const tag_inst = try sema.resolveInst(tag_val_ref); |
| 3224 | last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, "") catch |err| switch (err) { | 3236 | last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) { |
| 3225 | error.NeededSourceLocation => { | 3237 | error.NeededSourceLocation => { |
| 3226 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ | 3238 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ |
| 3227 | .index = field_i, | 3239 | .index = field_i, |
| 3228 | .range = .value, | 3240 | .range = .value, |
| 3229 | }).lazy; | 3241 | }).lazy; |
| 3230 | _ = try sema.resolveConstValue(block, value_src, tag_inst, "enum tag value must be comptime-known"); | 3242 | _ = try sema.resolveConstValue(block, value_src, tag_inst, .{ |
| | 3243 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| | 3244 | }); |
| 3231 | unreachable; | 3245 | unreachable; |
| 3232 | }, | 3246 | }, |
| 3233 | else => |e| return e, | 3247 | else => |e| return e, |
| ... | @@ -4611,7 +4625,9 @@ fn validateUnionInit( | ... | @@ -4611,7 +4625,9 @@ fn validateUnionInit( |
| 4611 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); | 4625 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4612 | return; | 4626 | return; |
| 4613 | } else if (try sema.typeRequiresComptime(union_ty)) { | 4627 | } else if (try sema.typeRequiresComptime(union_ty)) { |
| 4614 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only union must be comptime-known"); | 4628 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ |
| | 4629 | .needed_comptime_reason = "initializer of comptime only union must be comptime-known", |
| | 4630 | }); |
| 4615 | } | 4631 | } |
| 4616 | | 4632 | |
| 4617 | const new_tag = Air.internedToRef(tag_val.toIntern()); | 4633 | const new_tag = Air.internedToRef(tag_val.toIntern()); |
| ... | @@ -4806,7 +4822,9 @@ fn validateStructInit( | ... | @@ -4806,7 +4822,9 @@ fn validateStructInit( |
| 4806 | field_values[i] = val.toIntern(); | 4822 | field_values[i] = val.toIntern(); |
| 4807 | } else if (require_comptime) { | 4823 | } else if (require_comptime) { |
| 4808 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; | 4824 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; |
| 4809 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known"); | 4825 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ |
| | 4826 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", |
| | 4827 | }); |
| 4810 | } else { | 4828 | } else { |
| 4811 | struct_is_comptime = false; | 4829 | struct_is_comptime = false; |
| 4812 | } | 4830 | } |
| ... | @@ -5331,13 +5349,17 @@ fn storeToInferredAllocComptime( | ... | @@ -5331,13 +5349,17 @@ fn storeToInferredAllocComptime( |
| 5331 | return; | 5349 | return; |
| 5332 | } | 5350 | } |
| 5333 | | 5351 | |
| 5334 | return sema.failWithNeededComptime(block, src, "value being stored to a comptime variable must be comptime-known"); | 5352 | return sema.failWithNeededComptime(block, src, .{ |
| | 5353 | .needed_comptime_reason = "value being stored to a comptime variable must be comptime-known", |
| | 5354 | }); |
| 5335 | } | 5355 | } |
| 5336 | | 5356 | |
| 5337 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5357 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5338 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 5358 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5339 | const src = inst_data.src(); | 5359 | const src = inst_data.src(); |
| 5340 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, "eval branch quota must be comptime-known")); | 5360 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ |
| | 5361 | .needed_comptime_reason = "eval branch quota must be comptime-known", |
| | 5362 | })); |
| 5341 | sema.branch_quota = @max(sema.branch_quota, quota); | 5363 | sema.branch_quota = @max(sema.branch_quota, quota); |
| 5342 | } | 5364 | } |
| 5343 | | 5365 | |
| ... | @@ -5479,7 +5501,9 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5479,7 +5501,9 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5479 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 5501 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5480 | const src = inst_data.src(); | 5502 | const src = inst_data.src(); |
| 5481 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 5503 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 5482 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, "compile error string must be comptime-known"); | 5504 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| | 5505 | .needed_comptime_reason = "compile error string must be comptime-known", |
| | 5506 | }); |
| 5483 | return sema.fail(block, src, "{s}", .{msg}); | 5507 | return sema.fail(block, src, "{s}", .{msg}); |
| 5484 | } | 5508 | } |
| 5485 | | 5509 | |
| ... | @@ -6001,7 +6025,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6001,7 +6025,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6001 | const src = inst_data.src(); | 6025 | const src = inst_data.src(); |
| 6002 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6026 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6003 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 6027 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 6004 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, "export target must be comptime-known"); | 6028 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{ |
| | 6029 | .needed_comptime_reason = "export target must be comptime-known", |
| | 6030 | }); |
| 6005 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { | 6031 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { |
| 6006 | error.NeededSourceLocation => { | 6032 | error.NeededSourceLocation => { |
| 6007 | _ = try sema.resolveExportOptions(block, options_src, extra.options); | 6033 | _ = try sema.resolveExportOptions(block, options_src, extra.options); |
| ... | @@ -6140,7 +6166,9 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -6140,7 +6166,9 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 6140 | const ip = &mod.intern_pool; | 6166 | const ip = &mod.intern_pool; |
| 6141 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6167 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6142 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6168 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 6143 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, "operand to @setCold must be comptime-known"); | 6169 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{ |
| | 6170 | .needed_comptime_reason = "operand to @setCold must be comptime-known", |
| | 6171 | }); |
| 6144 | if (sema.func_index == .none) return; // does nothing outside a function | 6172 | if (sema.func_index == .none) return; // does nothing outside a function |
| 6145 | ip.funcAnalysis(sema.func_index).is_cold = is_cold; | 6173 | ip.funcAnalysis(sema.func_index).is_cold = is_cold; |
| 6146 | } | 6174 | } |
| ... | @@ -6148,13 +6176,17 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -6148,13 +6176,17 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 6148 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 6176 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6149 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6177 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6150 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6178 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 6151 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", "operand to @setFloatMode must be comptime-known"); | 6179 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ |
| | 6180 | .needed_comptime_reason = "operand to @setFloatMode must be comptime-known", |
| | 6181 | }); |
| 6152 | } | 6182 | } |
| 6153 | | 6183 | |
| 6154 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 6184 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 6155 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 6185 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 6156 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6186 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6157 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, "operand to @setRuntimeSafety must be comptime-known"); | 6187 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ |
| | 6188 | .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known", |
| | 6189 | }); |
| 6158 | } | 6190 | } |
| 6159 | | 6191 | |
| 6160 | fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 6192 | fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| ... | @@ -6162,7 +6194,9 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co | ... | @@ -6162,7 +6194,9 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co |
| 6162 | | 6194 | |
| 6163 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6195 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6164 | const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6196 | const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 6165 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, "atomic order of @fence must be comptime-known"); | 6197 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{ |
| | 6198 | .needed_comptime_reason = "atomic order of @fence must be comptime-known", |
| | 6199 | }); |
| 6166 | | 6200 | |
| 6167 | if (@intFromEnum(order) < @intFromEnum(std.builtin.AtomicOrder.Acquire)) { | 6201 | if (@intFromEnum(order) < @intFromEnum(std.builtin.AtomicOrder.Acquire)) { |
| 6168 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); | 6202 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); |
| ... | @@ -7194,10 +7228,10 @@ fn analyzeCall( | ... | @@ -7194,10 +7228,10 @@ fn analyzeCall( |
| 7194 | } | 7228 | } |
| 7195 | | 7229 | |
| 7196 | const result: Air.Inst.Ref = if (is_inline_call) res: { | 7230 | const result: Air.Inst.Ref = if (is_inline_call) res: { |
| 7197 | const func_val = sema.resolveConstValue(block, func_src, func, "function being called at comptime must be comptime-known") catch |err| { | 7231 | const func_val = try sema.resolveConstValue(block, func_src, func, .{ |
| 7198 | if (err == error.AnalysisFail and comptime_reason != null) try comptime_reason.?.explain(sema, sema.err); | 7232 | .needed_comptime_reason = "function being called at comptime must be comptime-known", |
| 7199 | return err; | 7233 | .block_comptime_reason = comptime_reason, |
| 7200 | }; | 7234 | }); |
| 7201 | const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { | 7235 | const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 7202 | .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{ | 7236 | .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{ |
| 7203 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), | 7237 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| ... | @@ -7451,7 +7485,7 @@ fn analyzeCall( | ... | @@ -7451,7 +7485,7 @@ fn analyzeCall( |
| 7451 | } | 7485 | } |
| 7452 | | 7486 | |
| 7453 | if (should_memoize and is_comptime_call) { | 7487 | if (should_memoize and is_comptime_call) { |
| 7454 | const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, ""); | 7488 | const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, undefined); |
| 7455 | const result_interned = try result_val.intern2(sema.fn_ret_ty, mod); | 7489 | const result_interned = try result_val.intern2(sema.fn_ret_ty, mod); |
| 7456 | | 7490 | |
| 7457 | // Transform ad-hoc inferred error set types into concrete error sets. | 7491 | // Transform ad-hoc inferred error set types into concrete error sets. |
| ... | @@ -7628,20 +7662,22 @@ fn analyzeInlineCallArg( | ... | @@ -7628,20 +7662,22 @@ fn analyzeInlineCallArg( |
| 7628 | } | 7662 | } |
| 7629 | const arg_src = args_info.argSrc(arg_block, arg_i.*); | 7663 | const arg_src = args_info.argSrc(arg_block, arg_i.*); |
| 7630 | if (try ics.callee().typeRequiresComptime(param_ty.toType())) { | 7664 | if (try ics.callee().typeRequiresComptime(param_ty.toType())) { |
| 7631 | _ = ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, "argument to parameter with comptime-only type must be comptime-known") catch |err| { | 7665 | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{ |
| 7632 | if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(ics.caller(), ics.caller().err); | 7666 | .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known", |
| 7633 | return err; | 7667 | .block_comptime_reason = param_block.comptime_reason, |
| 7634 | }; | 7668 | }); |
| 7635 | } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) { | 7669 | } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) { |
| 7636 | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, "parameter is comptime"); | 7670 | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{ |
| | 7671 | .needed_comptime_reason = "parameter is comptime", |
| | 7672 | }); |
| 7637 | } | 7673 | } |
| 7638 | | 7674 | |
| 7639 | if (is_comptime_call) { | 7675 | if (is_comptime_call) { |
| 7640 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg); | 7676 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg); |
| 7641 | const arg_val = ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, "argument to function being called at comptime must be comptime-known") catch |err| { | 7677 | const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{ |
| 7642 | if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(ics.caller(), ics.caller().err); | 7678 | .needed_comptime_reason = "argument to function being called at comptime must be comptime-known", |
| 7643 | return err; | 7679 | .block_comptime_reason = param_block.comptime_reason, |
| 7644 | }; | 7680 | }); |
| 7645 | switch (arg_val.toIntern()) { | 7681 | switch (arg_val.toIntern()) { |
| 7646 | .generic_poison, .generic_poison_type => { | 7682 | .generic_poison, .generic_poison_type => { |
| 7647 | // This function is currently evaluated as part of an as-of-yet unresolvable | 7683 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | @@ -7677,10 +7713,10 @@ fn analyzeInlineCallArg( | ... | @@ -7677,10 +7713,10 @@ fn analyzeInlineCallArg( |
| 7677 | | 7713 | |
| 7678 | if (is_comptime_call) { | 7714 | if (is_comptime_call) { |
| 7679 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); | 7715 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); |
| 7680 | const arg_val = ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to function being called at comptime must be comptime-known") catch |err| { | 7716 | const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{ |
| 7681 | if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(ics.caller(), ics.caller().err); | 7717 | .needed_comptime_reason = "argument to function being called at comptime must be comptime-known", |
| 7682 | return err; | 7718 | .block_comptime_reason = param_block.comptime_reason, |
| 7683 | }; | 7719 | }); |
| 7684 | switch (arg_val.toIntern()) { | 7720 | switch (arg_val.toIntern()) { |
| 7685 | .generic_poison, .generic_poison_type => { | 7721 | .generic_poison, .generic_poison_type => { |
| 7686 | // This function is currently evaluated as part of an as-of-yet unresolvable | 7722 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | @@ -7697,7 +7733,9 @@ fn analyzeInlineCallArg( | ... | @@ -7697,7 +7733,9 @@ fn analyzeInlineCallArg( |
| 7697 | memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod); | 7733 | memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod); |
| 7698 | } else { | 7734 | } else { |
| 7699 | if (zir_tags[inst] == .param_anytype_comptime) { | 7735 | if (zir_tags[inst] == .param_anytype_comptime) { |
| 7700 | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "parameter is comptime"); | 7736 | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{ |
| | 7737 | .needed_comptime_reason = "parameter is comptime", |
| | 7738 | }); |
| 7701 | } | 7739 | } |
| 7702 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); | 7740 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); |
| 7703 | } | 7741 | } |
| ... | @@ -7744,7 +7782,9 @@ fn instantiateGenericCall( | ... | @@ -7744,7 +7782,9 @@ fn instantiateGenericCall( |
| 7744 | const gpa = sema.gpa; | 7782 | const gpa = sema.gpa; |
| 7745 | const ip = &mod.intern_pool; | 7783 | const ip = &mod.intern_pool; |
| 7746 | | 7784 | |
| 7747 | const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known"); | 7785 | const func_val = try sema.resolveConstValue(block, func_src, func, .{ |
| | 7786 | .needed_comptime_reason = "generic function being called must be comptime-known", |
| | 7787 | }); |
| 7748 | const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { | 7788 | const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 7749 | .func => func_val.toIntern(), | 7789 | .func => func_val.toIntern(), |
| 7750 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.toIntern(), | 7790 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.toIntern(), |
| ... | @@ -8146,7 +8186,9 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -8146,7 +8186,9 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8146 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8186 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8147 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 8187 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 8148 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8188 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8149 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime-known")); | 8189 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ |
| | 8190 | .needed_comptime_reason = "vector length must be comptime-known", |
| | 8191 | })); |
| 8150 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); | 8192 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); |
| 8151 | try sema.checkVectorElemType(block, elem_type_src, elem_type); | 8193 | try sema.checkVectorElemType(block, elem_type_src, elem_type); |
| 8152 | const vector_type = try mod.vectorType(.{ | 8194 | const vector_type = try mod.vectorType(.{ |
| ... | @@ -8164,7 +8206,9 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8164,7 +8206,9 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8164 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8206 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8165 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 8207 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; |
| 8166 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 8208 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; |
| 8167 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, "array length must be comptime-known"); | 8209 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ |
| | 8210 | .needed_comptime_reason = "array length must be comptime-known", |
| | 8211 | }); |
| 8168 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); | 8212 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); |
| 8169 | try sema.validateArrayElemType(block, elem_type, elem_src); | 8213 | try sema.validateArrayElemType(block, elem_type, elem_src); |
| 8170 | const array_ty = try sema.mod.arrayType(.{ | 8214 | const array_ty = try sema.mod.arrayType(.{ |
| ... | @@ -8184,12 +8228,16 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8184,12 +8228,16 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8184 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 8228 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; |
| 8185 | const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node }; | 8229 | const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node }; |
| 8186 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 8230 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; |
| 8187 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, "array length must be comptime-known"); | 8231 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ |
| | 8232 | .needed_comptime_reason = "array length must be comptime-known", |
| | 8233 | }); |
| 8188 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); | 8234 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); |
| 8189 | try sema.validateArrayElemType(block, elem_type, elem_src); | 8235 | try sema.validateArrayElemType(block, elem_type, elem_src); |
| 8190 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); | 8236 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); |
| 8191 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); | 8237 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); |
| 8192 | const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, "array sentinel value must be comptime-known"); | 8238 | const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, .{ |
| | 8239 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 8240 | }); |
| 8193 | const array_ty = try sema.mod.arrayType(.{ | 8241 | const array_ty = try sema.mod.arrayType(.{ |
| 8194 | .len = len, | 8242 | .len = len, |
| 8195 | .sentinel = sentinel_val.toIntern(), | 8243 | .sentinel = sentinel_val.toIntern(), |
| ... | @@ -8906,7 +8954,9 @@ fn zirFunc( | ... | @@ -8906,7 +8954,9 @@ fn zirFunc( |
| 8906 | const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len]; | 8954 | const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len]; |
| 8907 | extra_index += ret_ty_body.len; | 8955 | extra_index += ret_ty_body.len; |
| 8908 | | 8956 | |
| 8909 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, "return type must be comptime-known"); | 8957 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{ |
| | 8958 | .needed_comptime_reason = "return type must be comptime-known", |
| | 8959 | }); |
| 8910 | break :blk ret_ty_val.toType(); | 8960 | break :blk ret_ty_val.toType(); |
| 8911 | }, | 8961 | }, |
| 8912 | }; | 8962 | }; |
| ... | @@ -8953,7 +9003,7 @@ fn resolveGenericBody( | ... | @@ -8953,7 +9003,7 @@ fn resolveGenericBody( |
| 8953 | body: []const Zir.Inst.Index, | 9003 | body: []const Zir.Inst.Index, |
| 8954 | func_inst: Zir.Inst.Index, | 9004 | func_inst: Zir.Inst.Index, |
| 8955 | dest_ty: Type, | 9005 | dest_ty: Type, |
| 8956 | reason: []const u8, | 9006 | reason: NeededComptimeReason, |
| 8957 | ) !Value { | 9007 | ) !Value { |
| 8958 | assert(body.len != 0); | 9008 | assert(body.len != 0); |
| 8959 | | 9009 | |
| ... | @@ -9852,7 +9902,9 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -9852,7 +9902,9 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9852 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 9902 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9853 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 9903 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9854 | const object = try sema.resolveInst(extra.lhs); | 9904 | const object = try sema.resolveInst(extra.lhs); |
| 9855 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, "field name must be comptime-known"); | 9905 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ |
| | 9906 | .needed_comptime_reason = "field name must be comptime-known", |
| | 9907 | }); |
| 9856 | return sema.fieldVal(block, src, object, field_name, field_name_src); | 9908 | return sema.fieldVal(block, src, object, field_name, field_name_src); |
| 9857 | } | 9909 | } |
| 9858 | | 9910 | |
| ... | @@ -9865,7 +9917,9 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -9865,7 +9917,9 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9865 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 9917 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9866 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 9918 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9867 | const object_ptr = try sema.resolveInst(extra.lhs); | 9919 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9868 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, "field name must be comptime-known"); | 9920 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ |
| | 9921 | .needed_comptime_reason = "field name must be comptime-known", |
| | 9922 | }); |
| 9869 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); | 9923 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); |
| 9870 | } | 9924 | } |
| 9871 | | 9925 | |
| ... | @@ -10593,7 +10647,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10593,7 +10647,7 @@ const SwitchProngAnalysis = struct { |
| 10593 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset }; | 10647 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset }; |
| 10594 | | 10648 | |
| 10595 | if (inline_case_capture != .none) { | 10649 | if (inline_case_capture != .none) { |
| 10596 | const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, "") catch unreachable; | 10650 | const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, undefined) catch unreachable; |
| 10597 | if (operand_ty.zigTypeTag(mod) == .Union) { | 10651 | if (operand_ty.zigTypeTag(mod) == .Union) { |
| 10598 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?); | 10652 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?); |
| 10599 | const union_obj = mod.typeToUnion(operand_ty).?; | 10653 | const union_obj = mod.typeToUnion(operand_ty).?; |
| ... | @@ -10650,14 +10704,14 @@ const SwitchProngAnalysis = struct { | ... | @@ -10650,14 +10704,14 @@ const SwitchProngAnalysis = struct { |
| 10650 | switch (operand_ty.zigTypeTag(mod)) { | 10704 | switch (operand_ty.zigTypeTag(mod)) { |
| 10651 | .Union => { | 10705 | .Union => { |
| 10652 | const union_obj = mod.typeToUnion(operand_ty).?; | 10706 | const union_obj = mod.typeToUnion(operand_ty).?; |
| 10653 | const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable; | 10707 | const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable; |
| 10654 | | 10708 | |
| 10655 | const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?; | 10709 | const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?; |
| 10656 | const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType(); | 10710 | const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType(); |
| 10657 | | 10711 | |
| 10658 | const field_tys = try sema.arena.alloc(Type, case_vals.len); | 10712 | const field_tys = try sema.arena.alloc(Type, case_vals.len); |
| 10659 | for (case_vals, field_tys) |item, *field_ty| { | 10713 | for (case_vals, field_tys) |item, *field_ty| { |
| 10660 | const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable; | 10714 | const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable; |
| 10661 | const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?; | 10715 | const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?; |
| 10662 | field_ty.* = union_obj.field_types.get(ip)[field_idx].toType(); | 10716 | field_ty.* = union_obj.field_types.get(ip)[field_idx].toType(); |
| 10663 | } | 10717 | } |
| ... | @@ -10906,7 +10960,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10906,7 +10960,7 @@ const SwitchProngAnalysis = struct { |
| 10906 | } | 10960 | } |
| 10907 | | 10961 | |
| 10908 | if (case_vals.len == 1) { | 10962 | if (case_vals.len == 1) { |
| 10909 | const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable; | 10963 | const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable; |
| 10910 | const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?); | 10964 | const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?); |
| 10911 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); | 10965 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); |
| 10912 | } | 10966 | } |
| ... | @@ -10914,7 +10968,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10914,7 +10968,7 @@ const SwitchProngAnalysis = struct { |
| 10914 | var names: InferredErrorSet.NameMap = .{}; | 10968 | var names: InferredErrorSet.NameMap = .{}; |
| 10915 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); | 10969 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); |
| 10916 | for (case_vals) |err| { | 10970 | for (case_vals) |err| { |
| 10917 | const err_val = sema.resolveConstValue(block, .unneeded, err, "") catch unreachable; | 10971 | const err_val = sema.resolveConstValue(block, .unneeded, err, undefined) catch unreachable; |
| 10918 | names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {}); | 10972 | names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {}); |
| 10919 | } | 10973 | } |
| 10920 | const error_ty = try mod.errorSetFromUnsortedNames(names.keys()); | 10974 | const error_ty = try mod.errorSetFromUnsortedNames(names.keys()); |
| ... | @@ -11688,7 +11742,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11688,7 +11742,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11688 | extra_index += info.body_len; | 11742 | extra_index += info.body_len; |
| 11689 | | 11743 | |
| 11690 | const item = case_vals.items[scalar_i]; | 11744 | const item = case_vals.items[scalar_i]; |
| 11691 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable; | 11745 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 11692 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 11746 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 11693 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); | 11747 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); |
| 11694 | return spa.resolveProngComptime( | 11748 | return spa.resolveProngComptime( |
| ... | @@ -11722,7 +11776,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11722,7 +11776,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11722 | | 11776 | |
| 11723 | for (items) |item| { | 11777 | for (items) |item| { |
| 11724 | // Validation above ensured these will succeed. | 11778 | // Validation above ensured these will succeed. |
| 11725 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable; | 11779 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 11726 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 11780 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 11727 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); | 11781 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); |
| 11728 | return spa.resolveProngComptime( | 11782 | return spa.resolveProngComptime( |
| ... | @@ -11746,8 +11800,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11746,8 +11800,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11746 | case_val_idx += 2; | 11800 | case_val_idx += 2; |
| 11747 | | 11801 | |
| 11748 | // Validation above ensured these will succeed. | 11802 | // Validation above ensured these will succeed. |
| 11749 | const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], "") catch unreachable; | 11803 | const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable; |
| 11750 | const last_val = sema.resolveConstValue(&child_block, .unneeded, range_items[1], "") catch unreachable; | 11804 | const last_val = sema.resolveConstValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable; |
| 11751 | if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and | 11805 | if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and |
| 11752 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) | 11806 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) |
| 11753 | { | 11807 | { |
| ... | @@ -11819,10 +11873,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11819,10 +11873,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11819 | } | 11873 | } |
| 11820 | | 11874 | |
| 11821 | if (child_block.is_comptime) { | 11875 | if (child_block.is_comptime) { |
| 11822 | _ = sema.resolveConstValue(&child_block, operand_src, operand, "condition in comptime switch must be comptime-known") catch |err| { | 11876 | _ = try sema.resolveConstValue(&child_block, operand_src, operand, .{ |
| 11823 | if (err == error.AnalysisFail and child_block.comptime_reason != null) try child_block.comptime_reason.?.explain(sema, sema.err); | 11877 | .needed_comptime_reason = "condition in comptime switch must be comptime-known", |
| 11824 | return err; | 11878 | .block_comptime_reason = child_block.comptime_reason, |
| 11825 | }; | 11879 | }); |
| 11826 | unreachable; | 11880 | unreachable; |
| 11827 | } | 11881 | } |
| 11828 | | 11882 | |
| ... | @@ -11857,7 +11911,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11857,7 +11911,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11857 | // `item` is already guaranteed to be constant known. | 11911 | // `item` is already guaranteed to be constant known. |
| 11858 | | 11912 | |
| 11859 | const analyze_body = if (union_originally) blk: { | 11913 | const analyze_body = if (union_originally) blk: { |
| 11860 | const item_val = sema.resolveConstLazyValue(block, .unneeded, item, "") catch unreachable; | 11914 | const item_val = sema.resolveConstLazyValue(block, .unneeded, item, undefined) catch unreachable; |
| 11861 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod); | 11915 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod); |
| 11862 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; | 11916 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| 11863 | } else true; | 11917 | } else true; |
| ... | @@ -12039,7 +12093,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12039,7 +12093,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12039 | | 12093 | |
| 12040 | const analyze_body = if (union_originally) | 12094 | const analyze_body = if (union_originally) |
| 12041 | for (items) |item| { | 12095 | for (items) |item| { |
| 12042 | const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable; | 12096 | const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable; |
| 12043 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod); | 12097 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod); |
| 12044 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; | 12098 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; |
| 12045 | } else false | 12099 | } else false |
| ... | @@ -12539,10 +12593,12 @@ fn resolveSwitchItemVal( | ... | @@ -12539,10 +12593,12 @@ fn resolveSwitchItemVal( |
| 12539 | else => |e| return e, | 12593 | else => |e| return e, |
| 12540 | }; | 12594 | }; |
| 12541 | | 12595 | |
| 12542 | const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, "") catch |err| switch (err) { | 12596 | const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, undefined) catch |err| switch (err) { |
| 12543 | error.NeededSourceLocation => { | 12597 | error.NeededSourceLocation => { |
| 12544 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); | 12598 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); |
| 12545 | _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"); | 12599 | _ = try sema.resolveConstValue(block, src, item, .{ |
| | 12600 | .needed_comptime_reason = "switch prong values must be comptime-known", |
| | 12601 | }); |
| 12546 | unreachable; | 12602 | unreachable; |
| 12547 | }, | 12603 | }, |
| 12548 | else => |e| return e, | 12604 | else => |e| return e, |
| ... | @@ -12860,7 +12916,9 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12860,7 +12916,9 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12860 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 12916 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12861 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 12917 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 12862 | const ty = try sema.resolveType(block, ty_src, extra.lhs); | 12918 | const ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 12863 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, "field name must be comptime-known"); | 12919 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ |
| | 12920 | .needed_comptime_reason = "field name must be comptime-known", |
| | 12921 | }); |
| 12864 | try sema.resolveTypeFields(ty); | 12922 | try sema.resolveTypeFields(ty); |
| 12865 | const ip = &mod.intern_pool; | 12923 | const ip = &mod.intern_pool; |
| 12866 | | 12924 | |
| ... | @@ -12912,7 +12970,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -12912,7 +12970,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 12912 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 12970 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12913 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 12971 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 12914 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 12972 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 12915 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "decl name must be comptime-known"); | 12973 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ |
| | 12974 | .needed_comptime_reason = "decl name must be comptime-known", |
| | 12975 | }); |
| 12916 | | 12976 | |
| 12917 | try sema.checkNamespaceType(block, lhs_src, container_type); | 12977 | try sema.checkNamespaceType(block, lhs_src, container_type); |
| 12918 | | 12978 | |
| ... | @@ -12965,7 +13025,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -12965,7 +13025,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12965 | const mod = sema.mod; | 13025 | const mod = sema.mod; |
| 12966 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 13026 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 12967 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 13027 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12968 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, "file path name must be comptime-known"); | 13028 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| | 13029 | .needed_comptime_reason = "file path name must be comptime-known", |
| | 13030 | }); |
| 12969 | | 13031 | |
| 12970 | if (name.len == 0) { | 13032 | if (name.len == 0) { |
| 12971 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); | 13033 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); |
| ... | @@ -13588,8 +13650,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13588,8 +13650,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13588 | const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern()); | 13650 | const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern()); |
| 13589 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); | 13651 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); |
| 13590 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); | 13652 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 13591 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known"); | 13653 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{ |
| 13592 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known"); | 13654 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 13655 | }); |
| | 13656 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{ |
| | 13657 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 13658 | }); |
| 13593 | if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { | 13659 | if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { |
| 13594 | break :s lhs_sent_casted_val; | 13660 | break :s lhs_sent_casted_val; |
| 13595 | } else { | 13661 | } else { |
| ... | @@ -13597,14 +13663,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13597,14 +13663,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13597 | } | 13663 | } |
| 13598 | } else { | 13664 | } else { |
| 13599 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); | 13665 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); |
| 13600 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known"); | 13666 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{ |
| | 13667 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 13668 | }); |
| 13601 | break :s lhs_sent_casted_val; | 13669 | break :s lhs_sent_casted_val; |
| 13602 | } | 13670 | } |
| 13603 | } else { | 13671 | } else { |
| 13604 | if (rhs_info.sentinel) |rhs_sent_val| { | 13672 | if (rhs_info.sentinel) |rhs_sent_val| { |
| 13605 | const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern()); | 13673 | const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern()); |
| 13606 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); | 13674 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 13607 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known"); | 13675 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{ |
| | 13676 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 13677 | }); |
| 13608 | break :s rhs_sent_casted_val; | 13678 | break :s rhs_sent_casted_val; |
| 13609 | } else { | 13679 | } else { |
| 13610 | break :s null; | 13680 | break :s null; |
| ... | @@ -13662,7 +13732,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13662,7 +13732,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13662 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; | 13732 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; |
| 13663 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); | 13733 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); |
| 13664 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); | 13734 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); |
| 13665 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, ""); | 13735 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined); |
| 13666 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); | 13736 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 13667 | } | 13737 | } |
| 13668 | while (elem_i < result_len) : (elem_i += 1) { | 13738 | while (elem_i < result_len) : (elem_i += 1) { |
| ... | @@ -13671,7 +13741,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13671,7 +13741,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13671 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; | 13741 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; |
| 13672 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); | 13742 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); |
| 13673 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); | 13743 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); |
| 13674 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, ""); | 13744 | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined); |
| 13675 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); | 13745 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 13676 | } | 13746 | } |
| 13677 | return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{ | 13747 | return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{ |
| ... | @@ -13748,7 +13818,9 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins | ... | @@ -13748,7 +13818,9 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins |
| 13748 | // has a sentinel, and this code should compute the length based | 13818 | // has a sentinel, and this code should compute the length based |
| 13749 | // on the sentinel value. | 13819 | // on the sentinel value. |
| 13750 | .Slice, .Many => { | 13820 | .Slice, .Many => { |
| 13751 | const val = try sema.resolveConstValue(block, src, operand, "slice value being concatenated must be comptime-known"); | 13821 | const val = try sema.resolveConstValue(block, src, operand, .{ |
| | 13822 | .needed_comptime_reason = "slice value being concatenated must be comptime-known", |
| | 13823 | }); |
| 13752 | return Type.ArrayInfo{ | 13824 | return Type.ArrayInfo{ |
| 13753 | .elem_type = ptr_info.child.toType(), | 13825 | .elem_type = ptr_info.child.toType(), |
| 13754 | .sentinel = switch (ptr_info.sentinel) { | 13826 | .sentinel = switch (ptr_info.sentinel) { |
| ... | @@ -13868,7 +13940,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13868,7 +13940,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13868 | | 13940 | |
| 13869 | if (lhs_ty.isTuple(mod)) { | 13941 | if (lhs_ty.isTuple(mod)) { |
| 13870 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | 13942 | // In `**` rhs must be comptime-known, but lhs can be runtime-known |
| 13871 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, "array multiplication factor must be comptime-known"); | 13943 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ |
| | 13944 | .needed_comptime_reason = "array multiplication factor must be comptime-known", |
| | 13945 | }); |
| 13872 | const factor_casted = try sema.usizeCast(block, rhs_src, factor); | 13946 | const factor_casted = try sema.usizeCast(block, rhs_src, factor); |
| 13873 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted); | 13947 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted); |
| 13874 | } | 13948 | } |
| ... | @@ -13890,7 +13964,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13890,7 +13964,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13890 | }; | 13964 | }; |
| 13891 | | 13965 | |
| 13892 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | 13966 | // In `**` rhs must be comptime-known, but lhs can be runtime-known |
| 13893 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, "array multiplication factor must be comptime-known"); | 13967 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ |
| | 13968 | .needed_comptime_reason = "array multiplication factor must be comptime-known", |
| | 13969 | }); |
| 13894 | | 13970 | |
| 13895 | const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch | 13971 | const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch |
| 13896 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); | 13972 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); |
| ... | @@ -15976,7 +16052,9 @@ fn zirAsm( | ... | @@ -15976,7 +16052,9 @@ fn zirAsm( |
| 15976 | | 16052 | |
| 15977 | const asm_source: []const u8 = if (tmpl_is_expr) blk: { | 16053 | const asm_source: []const u8 = if (tmpl_is_expr) blk: { |
| 15978 | const tmpl: Zir.Inst.Ref = @enumFromInt(extra.data.asm_source); | 16054 | const tmpl: Zir.Inst.Ref = @enumFromInt(extra.data.asm_source); |
| 15979 | const s: []const u8 = try sema.resolveConstString(block, src, tmpl, "assembly code must be comptime-known"); | 16055 | const s: []const u8 = try sema.resolveConstString(block, src, tmpl, .{ |
| | 16056 | .needed_comptime_reason = "assembly code must be comptime-known", |
| | 16057 | }); |
| 15980 | break :blk s; | 16058 | break :blk s; |
| 15981 | } else sema.code.nullTerminatedString(extra.data.asm_source); | 16059 | } else sema.code.nullTerminatedString(extra.data.asm_source); |
| 15982 | | 16060 | |
| ... | @@ -18736,7 +18814,9 @@ fn analyzeRet( | ... | @@ -18736,7 +18814,9 @@ fn analyzeRet( |
| 18736 | | 18814 | |
| 18737 | if (block.inlining) |inlining| { | 18815 | if (block.inlining) |inlining| { |
| 18738 | if (block.is_comptime) { | 18816 | if (block.is_comptime) { |
| 18739 | _ = try sema.resolveConstMaybeUndefVal(block, src, operand, "value being returned at comptime must be comptime-known"); | 18817 | _ = try sema.resolveConstMaybeUndefVal(block, src, operand, .{ |
| | 18818 | .needed_comptime_reason = "value being returned at comptime must be comptime-known", |
| | 18819 | }); |
| 18740 | inlining.comptime_result = operand; | 18820 | inlining.comptime_result = operand; |
| 18741 | return error.ComptimeReturn; | 18821 | return error.ComptimeReturn; |
| 18742 | } | 18822 | } |
| ... | @@ -18816,7 +18896,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18816,7 +18896,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18816 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); | 18896 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18817 | extra_i += 1; | 18897 | extra_i += 1; |
| 18818 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); | 18898 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); |
| 18819 | const val = try sema.resolveConstValue(block, sentinel_src, coerced, "pointer sentinel value must be comptime-known"); | 18899 | const val = try sema.resolveConstValue(block, sentinel_src, coerced, .{ |
| | 18900 | .needed_comptime_reason = "pointer sentinel value must be comptime-known", |
| | 18901 | }); |
| 18820 | break :blk val.toIntern(); | 18902 | break :blk val.toIntern(); |
| 18821 | } else .none; | 18903 | } else .none; |
| 18822 | | 18904 | |
| ... | @@ -18824,7 +18906,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18824,7 +18906,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18824 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); | 18906 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18825 | extra_i += 1; | 18907 | extra_i += 1; |
| 18826 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); | 18908 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); |
| 18827 | const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known"); | 18909 | const val = try sema.resolveConstValue(block, align_src, coerced, .{ |
| | 18910 | .needed_comptime_reason = "pointer alignment must be comptime-known", |
| | 18911 | }); |
| 18828 | // Check if this happens to be the lazy alignment of our element type, in | 18912 | // Check if this happens to be the lazy alignment of our element type, in |
| 18829 | // which case we can make this 0 without resolving it. | 18913 | // which case we can make this 0 without resolving it. |
| 18830 | switch (mod.intern_pool.indexToKey(val.toIntern())) { | 18914 | switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| ... | @@ -18848,14 +18932,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18848,14 +18932,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18848 | const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: { | 18932 | const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 18849 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); | 18933 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18850 | extra_i += 1; | 18934 | extra_i += 1; |
| 18851 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, "pointer bit-offset must be comptime-known"); | 18935 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, .{ |
| | 18936 | .needed_comptime_reason = "pointer bit-offset must be comptime-known", |
| | 18937 | }); |
| 18852 | break :blk @intCast(bit_offset); | 18938 | break :blk @intCast(bit_offset); |
| 18853 | } else 0; | 18939 | } else 0; |
| 18854 | | 18940 | |
| 18855 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { | 18941 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 18856 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); | 18942 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18857 | extra_i += 1; | 18943 | extra_i += 1; |
| 18858 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, "pointer host size must be comptime-known"); | 18944 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, .{ |
| | 18945 | .needed_comptime_reason = "pointer host size must be comptime-known", |
| | 18946 | }); |
| 18859 | break :blk @intCast(host_size); | 18947 | break :blk @intCast(host_size); |
| 18860 | } else 0; | 18948 | } else 0; |
| 18861 | | 18949 | |
| ... | @@ -18983,7 +19071,9 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -18983,7 +19071,9 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18983 | }; | 19071 | }; |
| 18984 | return sema.failWithOwnedErrorMsg(msg); | 19072 | return sema.failWithOwnedErrorMsg(msg); |
| 18985 | } | 19073 | } |
| 18986 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "name of field being initialized must be comptime-known"); | 19074 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ |
| | 19075 | .needed_comptime_reason = "name of field being initialized must be comptime-known", |
| | 19076 | }); |
| 18987 | const init = try sema.resolveInst(extra.init); | 19077 | const init = try sema.resolveInst(extra.init); |
| 18988 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); | 19078 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); |
| 18989 | } | 19079 | } |
| ... | @@ -19091,7 +19181,9 @@ fn zirStructInit( | ... | @@ -19091,7 +19181,9 @@ fn zirStructInit( |
| 19091 | field_inits[field_index] = try sema.resolveInst(item.data.init); | 19181 | field_inits[field_index] = try sema.resolveInst(item.data.init); |
| 19092 | if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| { | 19182 | if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| { |
| 19093 | const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse { | 19183 | const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse { |
| 19094 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 19184 | return sema.failWithNeededComptime(block, field_src, .{ |
| | 19185 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| | 19186 | }); |
| 19095 | }; | 19187 | }; |
| 19096 | | 19188 | |
| 19097 | if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) { | 19189 | if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) { |
| ... | @@ -19491,7 +19583,9 @@ fn zirArrayInit( | ... | @@ -19491,7 +19583,9 @@ fn zirArrayInit( |
| 19491 | const init_val = try sema.resolveMaybeUndefVal(resolved_args[i]) orelse { | 19583 | const init_val = try sema.resolveMaybeUndefVal(resolved_args[i]) orelse { |
| 19492 | const decl = mod.declPtr(block.src_decl); | 19584 | const decl = mod.declPtr(block.src_decl); |
| 19493 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | 19585 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); |
| 19494 | return sema.failWithNeededComptime(block, elem_src, "value stored in comptime field must be comptime-known"); | 19586 | return sema.failWithNeededComptime(block, elem_src, .{ |
| | 19587 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| | 19588 | }); |
| 19495 | }; | 19589 | }; |
| 19496 | if (!field_val.eql(init_val, elem_ty, mod)) { | 19590 | if (!field_val.eql(init_val, elem_ty, mod)) { |
| 19497 | const decl = mod.declPtr(block.src_decl); | 19591 | const decl = mod.declPtr(block.src_decl); |
| ... | @@ -19699,7 +19793,9 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -19699,7 +19793,9 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 19699 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 19793 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 19700 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 19794 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 19701 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); | 19795 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 19702 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "field name must be comptime-known"); | 19796 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ |
| | 19797 | .needed_comptime_reason = "field name must be comptime-known", |
| | 19798 | }); |
| 19703 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); | 19799 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); |
| 19704 | } | 19800 | } |
| 19705 | | 19801 | |
| ... | @@ -19970,7 +20066,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19970,7 +20066,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19970 | try sema.resolveTypeLayout(operand_ty); | 20066 | try sema.resolveTypeLayout(operand_ty); |
| 19971 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { | 20067 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 19972 | .EnumLiteral => { | 20068 | .EnumLiteral => { |
| 19973 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); | 20069 | const val = try sema.resolveConstValue(block, .unneeded, operand, undefined); |
| 19974 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; | 20070 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 19975 | return sema.addStrLit(block, ip.stringToSlice(tag_name)); | 20071 | return sema.addStrLit(block, ip.stringToSlice(tag_name)); |
| 19976 | }, | 20072 | }, |
| ... | @@ -20043,7 +20139,9 @@ fn zirReify( | ... | @@ -20043,7 +20139,9 @@ fn zirReify( |
| 20043 | const uncasted_operand = try sema.resolveInst(extra.operand); | 20139 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 20044 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 20140 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 20045 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 20141 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 20046 | const val = try sema.resolveConstValue(block, operand_src, type_info, "operand to @Type must be comptime-known"); | 20142 | const val = try sema.resolveConstValue(block, operand_src, type_info, .{ |
| | 20143 | .needed_comptime_reason = "operand to @Type must be comptime-known", |
| | 20144 | }); |
| 20047 | const union_val = ip.indexToKey(val.toIntern()).un; | 20145 | const union_val = ip.indexToKey(val.toIntern()).un; |
| 20048 | const target = mod.getTarget(); | 20146 | const target = mod.getTarget(); |
| 20049 | if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src); | 20147 | if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src); |
| ... | @@ -20935,7 +21033,9 @@ fn reifyStruct( | ... | @@ -20935,7 +21033,9 @@ fn reifyStruct( |
| 20935 | const field_ty = type_val.toType(); | 21033 | const field_ty = type_val.toType(); |
| 20936 | const default_val = if (default_value_val.optionalValue(mod)) |opt_val| | 21034 | const default_val = if (default_value_val.optionalValue(mod)) |opt_val| |
| 20937 | (try sema.pointerDeref(block, src, opt_val, try mod.singleConstPtrType(field_ty)) orelse | 21035 | (try sema.pointerDeref(block, src, opt_val, try mod.singleConstPtrType(field_ty)) orelse |
| 20938 | return sema.failWithNeededComptime(block, src, "struct field default value must be comptime-known")).toIntern() | 21036 | return sema.failWithNeededComptime(block, src, .{ |
| | 21037 | .needed_comptime_reason = "struct field default value must be comptime-known", |
| | 21038 | })).toIntern() |
| 20939 | else | 21039 | else |
| 20940 | .none; | 21040 | .none; |
| 20941 | if (is_comptime_val.toBool() and default_val == .none) { | 21041 | if (is_comptime_val.toBool() and default_val == .none) { |
| ... | @@ -21167,7 +21267,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -21167,7 +21267,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21167 | const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty); | 21267 | const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty); |
| 21168 | return Air.internedToRef(result_val.toIntern()); | 21268 | return Air.internedToRef(result_val.toIntern()); |
| 21169 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) { | 21269 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 21170 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_int' must be comptime-known"); | 21270 | return sema.failWithNeededComptime(block, operand_src, .{ |
| | 21271 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", |
| | 21272 | }); |
| 21171 | } | 21273 | } |
| 21172 | | 21274 | |
| 21173 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); | 21275 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); |
| ... | @@ -21247,7 +21349,9 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -21247,7 +21349,9 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21247 | const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema); | 21349 | const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema); |
| 21248 | return Air.internedToRef(result_val.toIntern()); | 21350 | return Air.internedToRef(result_val.toIntern()); |
| 21249 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) { | 21351 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 21250 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known"); | 21352 | return sema.failWithNeededComptime(block, operand_src, .{ |
| | 21353 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", |
| | 21354 | }); |
| 21251 | } | 21355 | } |
| 21252 | | 21356 | |
| 21253 | try sema.requireRuntimeBlock(block, src, operand_src); | 21357 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -22167,7 +22271,9 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 | ... | @@ -22167,7 +22271,9 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 22167 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22271 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22168 | | 22272 | |
| 22169 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); | 22273 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); |
| 22170 | const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "name of field must be comptime-known"); | 22274 | const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ |
| | 22275 | .needed_comptime_reason = "name of field must be comptime-known", |
| | 22276 | }); |
| 22171 | | 22277 | |
| 22172 | const mod = sema.mod; | 22278 | const mod = sema.mod; |
| 22173 | try sema.resolveTypeLayout(ty); | 22279 | try sema.resolveTypeLayout(ty); |
| ... | @@ -22660,16 +22766,22 @@ fn resolveExportOptions( | ... | @@ -22660,16 +22766,22 @@ fn resolveExportOptions( |
| 22660 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); | 22766 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); |
| 22661 | | 22767 | |
| 22662 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); | 22768 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); |
| 22663 | const name_val = try sema.resolveConstValue(block, name_src, name_operand, "name of exported value must be comptime-known"); | 22769 | const name_val = try sema.resolveConstValue(block, name_src, name_operand, .{ |
| | 22770 | .needed_comptime_reason = "name of exported value must be comptime-known", |
| | 22771 | }); |
| 22664 | const name_ty = Type.slice_const_u8; | 22772 | const name_ty = Type.slice_const_u8; |
| 22665 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod); | 22773 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod); |
| 22666 | | 22774 | |
| 22667 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); | 22775 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); |
| 22668 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known"); | 22776 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, .{ |
| | 22777 | .needed_comptime_reason = "linkage of exported value must be comptime-known", |
| | 22778 | }); |
| 22669 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); | 22779 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 22670 | | 22780 | |
| 22671 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src); | 22781 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src); |
| 22672 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known"); | 22782 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, .{ |
| | 22783 | .needed_comptime_reason = "linksection of exported value must be comptime-known", |
| | 22784 | }); |
| 22673 | const section_ty = Type.slice_const_u8; | 22785 | const section_ty = Type.slice_const_u8; |
| 22674 | const section = if (section_opt_val.optionalValue(mod)) |section_val| | 22786 | const section = if (section_opt_val.optionalValue(mod)) |section_val| |
| 22675 | try section_val.toAllocatedBytes(section_ty, sema.arena, mod) | 22787 | try section_val.toAllocatedBytes(section_ty, sema.arena, mod) |
| ... | @@ -22677,7 +22789,9 @@ fn resolveExportOptions( | ... | @@ -22677,7 +22789,9 @@ fn resolveExportOptions( |
| 22677 | null; | 22789 | null; |
| 22678 | | 22790 | |
| 22679 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src); | 22791 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src); |
| 22680 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known"); | 22792 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, .{ |
| | 22793 | .needed_comptime_reason = "visibility of exported value must be comptime-known", |
| | 22794 | }); |
| 22681 | const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val); | 22795 | const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val); |
| 22682 | | 22796 | |
| 22683 | if (name.len < 1) { | 22797 | if (name.len < 1) { |
| ... | @@ -22704,7 +22818,7 @@ fn resolveBuiltinEnum( | ... | @@ -22704,7 +22818,7 @@ fn resolveBuiltinEnum( |
| 22704 | src: LazySrcLoc, | 22818 | src: LazySrcLoc, |
| 22705 | zir_ref: Zir.Inst.Ref, | 22819 | zir_ref: Zir.Inst.Ref, |
| 22706 | comptime name: []const u8, | 22820 | comptime name: []const u8, |
| 22707 | reason: []const u8, | 22821 | reason: NeededComptimeReason, |
| 22708 | ) CompileError!@field(std.builtin, name) { | 22822 | ) CompileError!@field(std.builtin, name) { |
| 22709 | const mod = sema.mod; | 22823 | const mod = sema.mod; |
| 22710 | const ty = try sema.getBuiltinType(name); | 22824 | const ty = try sema.getBuiltinType(name); |
| ... | @@ -22719,7 +22833,7 @@ fn resolveAtomicOrder( | ... | @@ -22719,7 +22833,7 @@ fn resolveAtomicOrder( |
| 22719 | block: *Block, | 22833 | block: *Block, |
| 22720 | src: LazySrcLoc, | 22834 | src: LazySrcLoc, |
| 22721 | zir_ref: Zir.Inst.Ref, | 22835 | zir_ref: Zir.Inst.Ref, |
| 22722 | reason: []const u8, | 22836 | reason: NeededComptimeReason, |
| 22723 | ) CompileError!std.builtin.AtomicOrder { | 22837 | ) CompileError!std.builtin.AtomicOrder { |
| 22724 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason); | 22838 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason); |
| 22725 | } | 22839 | } |
| ... | @@ -22730,7 +22844,9 @@ fn resolveAtomicRmwOp( | ... | @@ -22730,7 +22844,9 @@ fn resolveAtomicRmwOp( |
| 22730 | src: LazySrcLoc, | 22844 | src: LazySrcLoc, |
| 22731 | zir_ref: Zir.Inst.Ref, | 22845 | zir_ref: Zir.Inst.Ref, |
| 22732 | ) CompileError!std.builtin.AtomicRmwOp { | 22846 | ) CompileError!std.builtin.AtomicRmwOp { |
| 22733 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime-known"); | 22847 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", .{ |
| | 22848 | .needed_comptime_reason = "@atomicRmW operation must be comptime-known", |
| | 22849 | }); |
| 22734 | } | 22850 | } |
| 22735 | | 22851 | |
| 22736 | fn zirCmpxchg( | 22852 | fn zirCmpxchg( |
| ... | @@ -22767,8 +22883,12 @@ fn zirCmpxchg( | ... | @@ -22767,8 +22883,12 @@ fn zirCmpxchg( |
| 22767 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 22883 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 22768 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); | 22884 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 22769 | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); | 22885 | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); |
| 22770 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, "atomic order of cmpxchg success must be comptime-known"); | 22886 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, .{ |
| 22771 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, "atomic order of cmpxchg failure must be comptime-known"); | 22887 | .needed_comptime_reason = "atomic order of cmpxchg success must be comptime-known", |
| | 22888 | }); |
| | 22889 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, .{ |
| | 22890 | .needed_comptime_reason = "atomic order of cmpxchg failure must be comptime-known", |
| | 22891 | }); |
| 22772 | | 22892 | |
| 22773 | if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.Monotonic)) { | 22893 | if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.Monotonic)) { |
| 22774 | return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); | 22894 | return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); |
| ... | @@ -22860,7 +22980,9 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -22860,7 +22980,9 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 22860 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22980 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22861 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22981 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22862 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 22982 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 22863 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", "@reduce operation must be comptime-known"); | 22983 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ |
| | 22984 | .needed_comptime_reason = "@reduce operation must be comptime-known", |
| | 22985 | }); |
| 22864 | const operand = try sema.resolveInst(extra.rhs); | 22986 | const operand = try sema.resolveInst(extra.rhs); |
| 22865 | const operand_ty = sema.typeOf(operand); | 22987 | const operand_ty = sema.typeOf(operand); |
| 22866 | const mod = sema.mod; | 22988 | const mod = sema.mod; |
| ... | @@ -22947,7 +23069,9 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -22947,7 +23069,9 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 22947 | .child = .i32_type, | 23069 | .child = .i32_type, |
| 22948 | }); | 23070 | }); |
| 22949 | mask = try sema.coerce(block, mask_ty, mask, mask_src); | 23071 | mask = try sema.coerce(block, mask_ty, mask, mask_src); |
| 22950 | const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime-known"); | 23072 | const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, .{ |
| | 23073 | .needed_comptime_reason = "shuffle mask must be comptime-known", |
| | 23074 | }); |
| 22951 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len)); | 23075 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len)); |
| 22952 | } | 23076 | } |
| 22953 | | 23077 | |
| ... | @@ -23211,7 +23335,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -23211,7 +23335,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 23211 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 23335 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 23212 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 23336 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 23213 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); | 23337 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); |
| 23214 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicLoad must be comptime-known"); | 23338 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ |
| | 23339 | .needed_comptime_reason = "atomic order of @atomicLoad must be comptime-known", |
| | 23340 | }); |
| 23215 | | 23341 | |
| 23216 | switch (order) { | 23342 | switch (order) { |
| 23217 | .Release, .AcqRel => { | 23343 | .Release, .AcqRel => { |
| ... | @@ -23276,7 +23402,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -23276,7 +23402,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23276 | }, | 23402 | }, |
| 23277 | else => {}, | 23403 | else => {}, |
| 23278 | } | 23404 | } |
| 23279 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicRmW must be comptime-known"); | 23405 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ |
| | 23406 | .needed_comptime_reason = "atomic order of @atomicRmW must be comptime-known", |
| | 23407 | }); |
| 23280 | | 23408 | |
| 23281 | if (order == .Unordered) { | 23409 | if (order == .Unordered) { |
| 23282 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); | 23410 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); |
| ... | @@ -23343,7 +23471,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23343,7 +23471,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23343 | const elem_ty = sema.typeOf(operand); | 23471 | const elem_ty = sema.typeOf(operand); |
| 23344 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 23472 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 23345 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); | 23473 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 23346 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicStore must be comptime-known"); | 23474 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ |
| | 23475 | .needed_comptime_reason = "atomic order of @atomicStore must be comptime-known", |
| | 23476 | }); |
| 23347 | | 23477 | |
| 23348 | const air_tag: Air.Inst.Tag = switch (order) { | 23478 | const air_tag: Air.Inst.Tag = switch (order) { |
| 23349 | .Acquire, .AcqRel => { | 23479 | .Acquire, .AcqRel => { |
| ... | @@ -23444,7 +23574,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23444,7 +23574,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23444 | const modifier_ty = try sema.getBuiltinType("CallModifier"); | 23574 | const modifier_ty = try sema.getBuiltinType("CallModifier"); |
| 23445 | const air_ref = try sema.resolveInst(extra.modifier); | 23575 | const air_ref = try sema.resolveInst(extra.modifier); |
| 23446 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); | 23576 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); |
| 23447 | const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, "call modifier must be comptime-known"); | 23577 | const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, .{ |
| | 23578 | .needed_comptime_reason = "call modifier must be comptime-known", |
| | 23579 | }); |
| 23448 | var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val); | 23580 | var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val); |
| 23449 | switch (modifier) { | 23581 | switch (modifier) { |
| 23450 | // These can be upgraded to comptime or nosuspend calls. | 23582 | // These can be upgraded to comptime or nosuspend calls. |
| ... | @@ -23529,7 +23661,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -23529,7 +23661,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 23529 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 23661 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 23530 | | 23662 | |
| 23531 | const parent_ty = try sema.resolveType(block, ty_src, extra.parent_type); | 23663 | const parent_ty = try sema.resolveType(block, ty_src, extra.parent_type); |
| 23532 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, "field name must be comptime-known"); | 23664 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, .{ |
| | 23665 | .needed_comptime_reason = "field name must be comptime-known", |
| | 23666 | }); |
| 23533 | const field_ptr = try sema.resolveInst(extra.field_ptr); | 23667 | const field_ptr = try sema.resolveInst(extra.field_ptr); |
| 23534 | const field_ptr_ty = sema.typeOf(field_ptr); | 23668 | const field_ptr_ty = sema.typeOf(field_ptr); |
| 23535 | const mod = sema.mod; | 23669 | const mod = sema.mod; |
| ... | @@ -24320,8 +24454,11 @@ fn zirVarExtended( | ... | @@ -24320,8 +24454,11 @@ fn zirVarExtended( |
| 24320 | else | 24454 | else |
| 24321 | uncasted_init; | 24455 | uncasted_init; |
| 24322 | | 24456 | |
| 24323 | break :blk ((try sema.resolveMaybeUndefVal(init)) orelse | 24457 | break :blk ((try sema.resolveMaybeUndefVal(init)) orelse { |
| 24324 | return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime-known")).toIntern(); | 24458 | return sema.failWithNeededComptime(block, init_src, .{ |
| | 24459 | .needed_comptime_reason = "container level variable initializers must be comptime-known", |
| | 24460 | }); |
| | 24461 | }).toIntern(); |
| 24325 | } else .none; | 24462 | } else .none; |
| 24326 | | 24463 | |
| 24327 | try sema.validateVarType(block, ty_src, var_ty, small.is_extern); | 24464 | try sema.validateVarType(block, ty_src, var_ty, small.is_extern); |
| ... | @@ -24376,7 +24513,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24376,7 +24513,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24376 | const body = sema.code.extra[extra_index..][0..body_len]; | 24513 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 24377 | extra_index += body.len; | 24514 | extra_index += body.len; |
| 24378 | | 24515 | |
| 24379 | const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, "alignment must be comptime-known"); | 24516 | const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, .{ |
| | 24517 | .needed_comptime_reason = "alignment must be comptime-known", |
| | 24518 | }); |
| 24380 | if (val.isGenericPoison()) { | 24519 | if (val.isGenericPoison()) { |
| 24381 | break :blk null; | 24520 | break :blk null; |
| 24382 | } | 24521 | } |
| ... | @@ -24390,7 +24529,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24390,7 +24529,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24390 | } else if (extra.data.bits.has_align_ref) blk: { | 24529 | } else if (extra.data.bits.has_align_ref) blk: { |
| 24391 | const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 24530 | const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24392 | extra_index += 1; | 24531 | extra_index += 1; |
| 24393 | const align_tv = sema.resolveInstConst(block, align_src, align_ref, "alignment must be comptime-known") catch |err| switch (err) { | 24532 | const align_tv = sema.resolveInstConst(block, align_src, align_ref, .{ |
| | 24533 | .needed_comptime_reason = "alignment must be comptime-known", |
| | 24534 | }) catch |err| switch (err) { |
| 24394 | error.GenericPoison => { | 24535 | error.GenericPoison => { |
| 24395 | break :blk null; | 24536 | break :blk null; |
| 24396 | }, | 24537 | }, |
| ... | @@ -24412,7 +24553,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24412,7 +24553,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24412 | extra_index += body.len; | 24553 | extra_index += body.len; |
| 24413 | | 24554 | |
| 24414 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); | 24555 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 24415 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime-known"); | 24556 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{ |
| | 24557 | .needed_comptime_reason = "addrspace must be comptime-known", |
| | 24558 | }); |
| 24416 | if (val.isGenericPoison()) { | 24559 | if (val.isGenericPoison()) { |
| 24417 | break :blk null; | 24560 | break :blk null; |
| 24418 | } | 24561 | } |
| ... | @@ -24420,7 +24563,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24420,7 +24563,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24420 | } else if (extra.data.bits.has_addrspace_ref) blk: { | 24563 | } else if (extra.data.bits.has_addrspace_ref) blk: { |
| 24421 | const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 24564 | const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24422 | extra_index += 1; | 24565 | extra_index += 1; |
| 24423 | const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, "addrespace must be comptime-known") catch |err| switch (err) { | 24566 | const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, .{ |
| | 24567 | .needed_comptime_reason = "addrspace must be comptime-known", |
| | 24568 | }) catch |err| switch (err) { |
| 24424 | error.GenericPoison => { | 24569 | error.GenericPoison => { |
| 24425 | break :blk null; | 24570 | break :blk null; |
| 24426 | }, | 24571 | }, |
| ... | @@ -24436,7 +24581,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24436,7 +24581,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24436 | extra_index += body.len; | 24581 | extra_index += body.len; |
| 24437 | | 24582 | |
| 24438 | const ty = Type.slice_const_u8; | 24583 | const ty = Type.slice_const_u8; |
| 24439 | const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, "linksection must be comptime-known"); | 24584 | const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, .{ |
| | 24585 | .needed_comptime_reason = "linksection must be comptime-known", |
| | 24586 | }); |
| 24440 | if (val.isGenericPoison()) { | 24587 | if (val.isGenericPoison()) { |
| 24441 | break :blk .generic; | 24588 | break :blk .generic; |
| 24442 | } | 24589 | } |
| ... | @@ -24444,7 +24591,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24444,7 +24591,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24444 | } else if (extra.data.bits.has_section_ref) blk: { | 24591 | } else if (extra.data.bits.has_section_ref) blk: { |
| 24445 | const section_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 24592 | const section_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24446 | extra_index += 1; | 24593 | extra_index += 1; |
| 24447 | const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) { | 24594 | const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, .{ |
| | 24595 | .needed_comptime_reason = "linksection must be comptime-known", |
| | 24596 | }) catch |err| switch (err) { |
| 24448 | error.GenericPoison => { | 24597 | error.GenericPoison => { |
| 24449 | break :blk .generic; | 24598 | break :blk .generic; |
| 24450 | }, | 24599 | }, |
| ... | @@ -24460,7 +24609,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24460,7 +24609,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24460 | extra_index += body.len; | 24609 | extra_index += body.len; |
| 24461 | | 24610 | |
| 24462 | const cc_ty = try sema.getBuiltinType("CallingConvention"); | 24611 | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 24463 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime-known"); | 24612 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{ |
| | 24613 | .needed_comptime_reason = "calling convention must be comptime-known", |
| | 24614 | }); |
| 24464 | if (val.isGenericPoison()) { | 24615 | if (val.isGenericPoison()) { |
| 24465 | break :blk null; | 24616 | break :blk null; |
| 24466 | } | 24617 | } |
| ... | @@ -24468,7 +24619,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24468,7 +24619,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24468 | } else if (extra.data.bits.has_cc_ref) blk: { | 24619 | } else if (extra.data.bits.has_cc_ref) blk: { |
| 24469 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 24620 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24470 | extra_index += 1; | 24621 | extra_index += 1; |
| 24471 | const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, "calling convention must be comptime-known") catch |err| switch (err) { | 24622 | const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, .{ |
| | 24623 | .needed_comptime_reason = "calling convention must be comptime-known", |
| | 24624 | }) catch |err| switch (err) { |
| 24472 | error.GenericPoison => { | 24625 | error.GenericPoison => { |
| 24473 | break :blk null; | 24626 | break :blk null; |
| 24474 | }, | 24627 | }, |
| ... | @@ -24486,13 +24639,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24486,13 +24639,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24486 | const body = sema.code.extra[extra_index..][0..body_len]; | 24639 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 24487 | extra_index += body.len; | 24640 | extra_index += body.len; |
| 24488 | | 24641 | |
| 24489 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, "return type must be comptime-known"); | 24642 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ |
| | 24643 | .needed_comptime_reason = "return type must be comptime-known", |
| | 24644 | }); |
| 24490 | const ty = val.toType(); | 24645 | const ty = val.toType(); |
| 24491 | break :blk ty; | 24646 | break :blk ty; |
| 24492 | } else if (extra.data.bits.has_ret_ty_ref) blk: { | 24647 | } else if (extra.data.bits.has_ret_ty_ref) blk: { |
| 24493 | const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 24648 | const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24494 | extra_index += 1; | 24649 | extra_index += 1; |
| 24495 | const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime-known") catch |err| switch (err) { | 24650 | const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, .{ |
| | 24651 | .needed_comptime_reason = "return type must be comptime-known", |
| | 24652 | }) catch |err| switch (err) { |
| 24496 | error.GenericPoison => { | 24653 | error.GenericPoison => { |
| 24497 | break :blk Type.generic_poison; | 24654 | break :blk Type.generic_poison; |
| 24498 | }, | 24655 | }, |
| ... | @@ -24547,7 +24704,9 @@ fn zirCUndef( | ... | @@ -24547,7 +24704,9 @@ fn zirCUndef( |
| 24547 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 24704 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 24548 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24705 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 24549 | | 24706 | |
| 24550 | const name = try sema.resolveConstString(block, src, extra.operand, "name of macro being undefined must be comptime-known"); | 24707 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| | 24708 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| | 24709 | }); |
| 24551 | try block.c_import_buf.?.writer().print("#undef {s}\n", .{name}); | 24710 | try block.c_import_buf.?.writer().print("#undef {s}\n", .{name}); |
| 24552 | return .void_value; | 24711 | return .void_value; |
| 24553 | } | 24712 | } |
| ... | @@ -24560,7 +24719,9 @@ fn zirCInclude( | ... | @@ -24560,7 +24719,9 @@ fn zirCInclude( |
| 24560 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 24719 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 24561 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24720 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 24562 | | 24721 | |
| 24563 | const name = try sema.resolveConstString(block, src, extra.operand, "path being included must be comptime-known"); | 24722 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| | 24723 | .needed_comptime_reason = "path being included must be comptime-known", |
| | 24724 | }); |
| 24564 | try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name}); | 24725 | try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name}); |
| 24565 | return .void_value; | 24726 | return .void_value; |
| 24566 | } | 24727 | } |
| ... | @@ -24575,10 +24736,14 @@ fn zirCDefine( | ... | @@ -24575,10 +24736,14 @@ fn zirCDefine( |
| 24575 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24736 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 24576 | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 24737 | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 24577 | | 24738 | |
| 24578 | const name = try sema.resolveConstString(block, name_src, extra.lhs, "name of macro being undefined must be comptime-known"); | 24739 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ |
| | 24740 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| | 24741 | }); |
| 24579 | const rhs = try sema.resolveInst(extra.rhs); | 24742 | const rhs = try sema.resolveInst(extra.rhs); |
| 24580 | if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) { | 24743 | if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) { |
| 24581 | const value = try sema.resolveConstString(block, val_src, extra.rhs, "value of macro being undefined must be comptime-known"); | 24744 | const value = try sema.resolveConstString(block, val_src, extra.rhs, .{ |
| | 24745 | .needed_comptime_reason = "value of macro being undefined must be comptime-known", |
| | 24746 | }); |
| 24582 | try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value }); | 24747 | try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value }); |
| 24583 | } else { | 24748 | } else { |
| 24584 | try block.c_import_buf.?.writer().print("#define {s}\n", .{name}); | 24749 | try block.c_import_buf.?.writer().print("#define {s}\n", .{name}); |
| ... | @@ -24599,7 +24764,9 @@ fn zirWasmMemorySize( | ... | @@ -24599,7 +24764,9 @@ fn zirWasmMemorySize( |
| 24599 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 24764 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| 24600 | } | 24765 | } |
| 24601 | | 24766 | |
| 24602 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, "wasm memory size index must be comptime-known")); | 24767 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, .{ |
| | 24768 | .needed_comptime_reason = "wasm memory size index must be comptime-known", |
| | 24769 | })); |
| 24603 | try sema.requireRuntimeBlock(block, builtin_src, null); | 24770 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 24604 | return block.addInst(.{ | 24771 | return block.addInst(.{ |
| 24605 | .tag = .wasm_memory_size, | 24772 | .tag = .wasm_memory_size, |
| ... | @@ -24624,7 +24791,9 @@ fn zirWasmMemoryGrow( | ... | @@ -24624,7 +24791,9 @@ fn zirWasmMemoryGrow( |
| 24624 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 24791 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| 24625 | } | 24792 | } |
| 24626 | | 24793 | |
| 24627 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, "wasm memory size index must be comptime-known")); | 24794 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{ |
| | 24795 | .needed_comptime_reason = "wasm memory size index must be comptime-known", |
| | 24796 | })); |
| 24628 | const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src); | 24797 | const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src); |
| 24629 | | 24798 | |
| 24630 | try sema.requireRuntimeBlock(block, builtin_src, null); | 24799 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| ... | @@ -24654,13 +24823,19 @@ fn resolvePrefetchOptions( | ... | @@ -24654,13 +24823,19 @@ fn resolvePrefetchOptions( |
| 24654 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); | 24823 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); |
| 24655 | | 24824 | |
| 24656 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src); | 24825 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src); |
| 24657 | const rw_val = try sema.resolveConstValue(block, rw_src, rw, "prefetch read/write must be comptime-known"); | 24826 | const rw_val = try sema.resolveConstValue(block, rw_src, rw, .{ |
| | 24827 | .needed_comptime_reason = "prefetch read/write must be comptime-known", |
| | 24828 | }); |
| 24658 | | 24829 | |
| 24659 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src); | 24830 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src); |
| 24660 | const locality_val = try sema.resolveConstValue(block, locality_src, locality, "prefetch locality must be comptime-known"); | 24831 | const locality_val = try sema.resolveConstValue(block, locality_src, locality, .{ |
| | 24832 | .needed_comptime_reason = "prefetch locality must be comptime-known", |
| | 24833 | }); |
| 24661 | | 24834 | |
| 24662 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src); | 24835 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src); |
| 24663 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known"); | 24836 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, .{ |
| | 24837 | .needed_comptime_reason = "prefetch cache must be comptime-known", |
| | 24838 | }); |
| 24664 | | 24839 | |
| 24665 | return std.builtin.PrefetchOptions{ | 24840 | return std.builtin.PrefetchOptions{ |
| 24666 | .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val), | 24841 | .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val), |
| ... | @@ -24727,18 +24902,26 @@ fn resolveExternOptions( | ... | @@ -24727,18 +24902,26 @@ fn resolveExternOptions( |
| 24727 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); | 24902 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); |
| 24728 | | 24903 | |
| 24729 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); | 24904 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); |
| 24730 | const name_val = try sema.resolveConstValue(block, name_src, name_ref, "name of the extern symbol must be comptime-known"); | 24905 | const name_val = try sema.resolveConstValue(block, name_src, name_ref, .{ |
| | 24906 | .needed_comptime_reason = "name of the extern symbol must be comptime-known", |
| | 24907 | }); |
| 24731 | const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); | 24908 | const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); |
| 24732 | | 24909 | |
| 24733 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src); | 24910 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src); |
| 24734 | const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, "library in which extern symbol is must be comptime-known"); | 24911 | const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, .{ |
| | 24912 | .needed_comptime_reason = "library in which extern symbol is must be comptime-known", |
| | 24913 | }); |
| 24735 | | 24914 | |
| 24736 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); | 24915 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); |
| 24737 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known"); | 24916 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, .{ |
| | 24917 | .needed_comptime_reason = "linkage of the extern symbol must be comptime-known", |
| | 24918 | }); |
| 24738 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); | 24919 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 24739 | | 24920 | |
| 24740 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src); | 24921 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src); |
| 24741 | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, "threadlocality of the extern symbol must be comptime-known"); | 24922 | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, .{ |
| | 24923 | .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known", |
| | 24924 | }); |
| 24742 | | 24925 | |
| 24743 | const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: { | 24926 | const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: { |
| 24744 | const library_name = try payload.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); | 24927 | const library_name = try payload.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); |
| ... | @@ -24863,7 +25046,9 @@ fn zirWorkItem( | ... | @@ -24863,7 +25046,9 @@ fn zirWorkItem( |
| 24863 | }, | 25046 | }, |
| 24864 | } | 25047 | } |
| 24865 | | 25048 | |
| 24866 | const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, "dimension must be comptime-known")); | 25049 | const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, .{ |
| | 25050 | .needed_comptime_reason = "dimension must be comptime-known", |
| | 25051 | })); |
| 24867 | try sema.requireRuntimeBlock(block, builtin_src, null); | 25052 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 24868 | | 25053 | |
| 24869 | return block.addInst(.{ | 25054 | return block.addInst(.{ |
| ... | @@ -25945,7 +26130,7 @@ fn fieldPtr( | ... | @@ -25945,7 +26130,7 @@ fn fieldPtr( |
| 25945 | } | 26130 | } |
| 25946 | }, | 26131 | }, |
| 25947 | .Type => { | 26132 | .Type => { |
| 25948 | _ = try sema.resolveConstValue(block, .unneeded, object_ptr, ""); | 26133 | _ = try sema.resolveConstValue(block, .unneeded, object_ptr, undefined); |
| 25949 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); | 26134 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); |
| 25950 | const inner = if (is_pointer_to) | 26135 | const inner = if (is_pointer_to) |
| 25951 | try sema.analyzeLoad(block, src, result, object_ptr_src) | 26136 | try sema.analyzeLoad(block, src, result, object_ptr_src) |
| ... | @@ -26803,7 +26988,9 @@ fn elemPtr( | ... | @@ -26803,7 +26988,9 @@ fn elemPtr( |
| 26803 | .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety), | 26988 | .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety), |
| 26804 | .Struct => { | 26989 | .Struct => { |
| 26805 | // Tuple field access. | 26990 | // Tuple field access. |
| 26806 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); | 26991 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| | 26992 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| | 26993 | }); |
| 26807 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); | 26994 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| 26808 | return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init); | 26995 | return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init); |
| 26809 | }, | 26996 | }, |
| ... | @@ -26857,7 +27044,9 @@ fn elemPtrOneLayerOnly( | ... | @@ -26857,7 +27044,9 @@ fn elemPtrOneLayerOnly( |
| 26857 | }, | 27044 | }, |
| 26858 | .Struct => { | 27045 | .Struct => { |
| 26859 | assert(child_ty.isTuple(mod)); | 27046 | assert(child_ty.isTuple(mod)); |
| 26860 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); | 27047 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| | 27048 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| | 27049 | }); |
| 26861 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); | 27050 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| 26862 | return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false); | 27051 | return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false); |
| 26863 | }, | 27052 | }, |
| ... | @@ -26932,7 +27121,9 @@ fn elemVal( | ... | @@ -26932,7 +27121,9 @@ fn elemVal( |
| 26932 | }, | 27121 | }, |
| 26933 | .Struct => { | 27122 | .Struct => { |
| 26934 | // Tuple field access. | 27123 | // Tuple field access. |
| 26935 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); | 27124 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| | 27125 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| | 27126 | }); |
| 26936 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); | 27127 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| 26937 | return sema.tupleField(block, indexable_src, indexable, elem_index_src, index); | 27128 | return sema.tupleField(block, indexable_src, indexable, elem_index_src, index); |
| 26938 | }, | 27129 | }, |
| ... | @@ -27446,7 +27637,7 @@ fn coerceExtra( | ... | @@ -27446,7 +27637,7 @@ fn coerceExtra( |
| 27446 | | 27637 | |
| 27447 | // Function body to function pointer. | 27638 | // Function body to function pointer. |
| 27448 | if (inst_ty.zigTypeTag(mod) == .Fn) { | 27639 | if (inst_ty.zigTypeTag(mod) == .Fn) { |
| 27449 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 27640 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 27450 | const fn_decl = fn_val.pointerDecl(mod).?; | 27641 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 27451 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); | 27642 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); |
| 27452 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); | 27643 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); |
| ... | @@ -27735,7 +27926,9 @@ fn coerceExtra( | ... | @@ -27735,7 +27926,9 @@ fn coerceExtra( |
| 27735 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { | 27926 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { |
| 27736 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { | 27927 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 27737 | if (!opts.report_err) return error.NotCoercible; | 27928 | if (!opts.report_err) return error.NotCoercible; |
| 27738 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known"); | 27929 | return sema.failWithNeededComptime(block, inst_src, .{ |
| | 27930 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", |
| | 27931 | }); |
| 27739 | } | 27932 | } |
| 27740 | break :float; | 27933 | break :float; |
| 27741 | }; | 27934 | }; |
| ... | @@ -27766,7 +27959,9 @@ fn coerceExtra( | ... | @@ -27766,7 +27959,9 @@ fn coerceExtra( |
| 27766 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { | 27959 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 27767 | if (!opts.report_err) return error.NotCoercible; | 27960 | if (!opts.report_err) return error.NotCoercible; |
| 27768 | if (opts.no_cast_to_comptime_int) return inst; | 27961 | if (opts.no_cast_to_comptime_int) return inst; |
| 27769 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known"); | 27962 | return sema.failWithNeededComptime(block, inst_src, .{ |
| | 27963 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", |
| | 27964 | }); |
| 27770 | } | 27965 | } |
| 27771 | | 27966 | |
| 27772 | // integer widening | 27967 | // integer widening |
| ... | @@ -27787,7 +27982,7 @@ fn coerceExtra( | ... | @@ -27787,7 +27982,7 @@ fn coerceExtra( |
| 27787 | }, | 27982 | }, |
| 27788 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) { | 27983 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) { |
| 27789 | .ComptimeFloat => { | 27984 | .ComptimeFloat => { |
| 27790 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 27985 | const val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 27791 | const result_val = try val.floatCast(dest_ty, mod); | 27986 | const result_val = try val.floatCast(dest_ty, mod); |
| 27792 | return Air.internedToRef(result_val.toIntern()); | 27987 | return Air.internedToRef(result_val.toIntern()); |
| 27793 | }, | 27988 | }, |
| ... | @@ -27808,7 +28003,9 @@ fn coerceExtra( | ... | @@ -27808,7 +28003,9 @@ fn coerceExtra( |
| 27808 | return Air.internedToRef(result_val.toIntern()); | 28003 | return Air.internedToRef(result_val.toIntern()); |
| 27809 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { | 28004 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 27810 | if (!opts.report_err) return error.NotCoercible; | 28005 | if (!opts.report_err) return error.NotCoercible; |
| 27811 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known"); | 28006 | return sema.failWithNeededComptime(block, inst_src, .{ |
| | 28007 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", |
| | 28008 | }); |
| 27812 | } | 28009 | } |
| 27813 | | 28010 | |
| 27814 | // float widening | 28011 | // float widening |
| ... | @@ -27826,7 +28023,9 @@ fn coerceExtra( | ... | @@ -27826,7 +28023,9 @@ fn coerceExtra( |
| 27826 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { | 28023 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { |
| 27827 | if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { | 28024 | if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 27828 | if (!opts.report_err) return error.NotCoercible; | 28025 | if (!opts.report_err) return error.NotCoercible; |
| 27829 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known"); | 28026 | return sema.failWithNeededComptime(block, inst_src, .{ |
| | 28027 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", |
| | 28028 | }); |
| 27830 | } | 28029 | } |
| 27831 | break :int; | 28030 | break :int; |
| 27832 | }; | 28031 | }; |
| ... | @@ -27851,7 +28050,7 @@ fn coerceExtra( | ... | @@ -27851,7 +28050,7 @@ fn coerceExtra( |
| 27851 | .Enum => switch (inst_ty.zigTypeTag(mod)) { | 28050 | .Enum => switch (inst_ty.zigTypeTag(mod)) { |
| 27852 | .EnumLiteral => { | 28051 | .EnumLiteral => { |
| 27853 | // enum literal to enum | 28052 | // enum literal to enum |
| 27854 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 28053 | const val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 27855 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; | 28054 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 27856 | const field_index = dest_ty.enumFieldIndex(string, mod) orelse { | 28055 | const field_index = dest_ty.enumFieldIndex(string, mod) orelse { |
| 27857 | const msg = msg: { | 28056 | const msg = msg: { |
| ... | @@ -28987,7 +29186,7 @@ fn coerceVarArgParam( | ... | @@ -28987,7 +29186,7 @@ fn coerceVarArgParam( |
| 28987 | .{}, | 29186 | .{}, |
| 28988 | ), | 29187 | ), |
| 28989 | .Fn => blk: { | 29188 | .Fn => blk: { |
| 28990 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 29189 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 28991 | const fn_decl = fn_val.pointerDecl(mod).?; | 29190 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 28992 | break :blk try sema.analyzeDeclRef(fn_decl); | 29191 | break :blk try sema.analyzeDeclRef(fn_decl); |
| 28993 | }, | 29192 | }, |
| ... | @@ -30720,7 +30919,9 @@ fn coerceTupleToStruct( | ... | @@ -30720,7 +30919,9 @@ fn coerceTupleToStruct( |
| 30720 | field_refs[field_index] = coerced; | 30919 | field_refs[field_index] = coerced; |
| 30721 | if (field.is_comptime) { | 30920 | if (field.is_comptime) { |
| 30722 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { | 30921 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 30723 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 30922 | return sema.failWithNeededComptime(block, field_src, .{ |
| | 30923 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| | 30924 | }); |
| 30724 | }; | 30925 | }; |
| 30725 | | 30926 | |
| 30726 | if (!init_val.eql(field.default_val.toValue(), field.ty, sema.mod)) { | 30927 | if (!init_val.eql(field.default_val.toValue(), field.ty, sema.mod)) { |
| ... | @@ -30851,7 +31052,9 @@ fn coerceTupleToTuple( | ... | @@ -30851,7 +31052,9 @@ fn coerceTupleToTuple( |
| 30851 | field_refs[field_index] = coerced; | 31052 | field_refs[field_index] = coerced; |
| 30852 | if (default_val != .none) { | 31053 | if (default_val != .none) { |
| 30853 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { | 31054 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 30854 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 31055 | return sema.failWithNeededComptime(block, field_src, .{ |
| | 31056 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| | 31057 | }); |
| 30855 | }; | 31058 | }; |
| 30856 | | 31059 | |
| 30857 | if (!init_val.eql(default_val.toValue(), field_ty, sema.mod)) { | 31060 | if (!init_val.eql(default_val.toValue(), field_ty, sema.mod)) { |
| ... | @@ -31591,7 +31794,9 @@ fn analyzeSlice( | ... | @@ -31591,7 +31794,9 @@ fn analyzeSlice( |
| 31591 | const sentinel = s: { | 31794 | const sentinel = s: { |
| 31592 | if (sentinel_opt != .none) { | 31795 | if (sentinel_opt != .none) { |
| 31593 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); | 31796 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); |
| 31594 | break :s try sema.resolveConstValue(block, sentinel_src, casted, "slice sentinel must be comptime-known"); | 31797 | break :s try sema.resolveConstValue(block, sentinel_src, casted, .{ |
| | 31798 | .needed_comptime_reason = "slice sentinel must be comptime-known", |
| | 31799 | }); |
| 31595 | } | 31800 | } |
| 31596 | // If we are slicing to the end of something that is sentinel-terminated | 31801 | // If we are slicing to the end of something that is sentinel-terminated |
| 31597 | // then the resulting slice type is also sentinel-terminated. | 31802 | // then the resulting slice type is also sentinel-terminated. |
| ... | @@ -35092,7 +35297,9 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -35092,7 +35297,9 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 35092 | .index = field_i, | 35297 | .index = field_i, |
| 35093 | .range = .value, | 35298 | .range = .value, |
| 35094 | }).lazy; | 35299 | }).lazy; |
| 35095 | return sema.failWithNeededComptime(&block_scope, init_src, "struct field default value must be comptime-known"); | 35300 | return sema.failWithNeededComptime(&block_scope, init_src, .{ |
| | 35301 | .needed_comptime_reason = "struct field default value must be comptime-known", |
| | 35302 | }); |
| 35096 | }; | 35303 | }; |
| 35097 | field.default_val = try default_val.intern(field.ty, mod); | 35304 | field.default_val = try default_val.intern(field.ty, mod); |
| 35098 | } | 35305 | } |
| ... | @@ -35534,7 +35741,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35534,7 +35741,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35534 | | 35741 | |
| 35535 | fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value { | 35742 | fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value { |
| 35536 | const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src); | 35743 | const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src); |
| 35537 | return sema.resolveConstValue(block, src, coerced, "enum tag value must be comptime-known"); | 35744 | return sema.resolveConstValue(block, src, coerced, .{ |
| | 35745 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| | 35746 | }); |
| 35538 | } | 35747 | } |
| 35539 | | 35748 | |
| 35540 | fn generateUnionTagTypeNumbered( | 35749 | fn generateUnionTagTypeNumbered( |
| ... | @@ -36158,7 +36367,9 @@ pub fn analyzeAddressSpace( | ... | @@ -36158,7 +36367,9 @@ pub fn analyzeAddressSpace( |
| 36158 | ctx: AddressSpaceContext, | 36367 | ctx: AddressSpaceContext, |
| 36159 | ) !std.builtin.AddressSpace { | 36368 | ) !std.builtin.AddressSpace { |
| 36160 | const mod = sema.mod; | 36369 | const mod = sema.mod; |
| 36161 | const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, "address space must be comptime-known"); | 36370 | const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, .{ |
| | 36371 | .needed_comptime_reason = "address space must be comptime-known", |
| | 36372 | }); |
| 36162 | const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_tv.val); | 36373 | const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_tv.val); |
| 36163 | const target = sema.mod.getTarget(); | 36374 | const target = sema.mod.getTarget(); |
| 36164 | const arch = target.cpu.arch; | 36375 | const arch = target.cpu.arch; |